Commit graph

88931 commits

Author SHA1 Message Date
Mazdak Farrokhzad
64eb69b904
Rollup merge of #57573 - Xanewok:querify-entry-fn, r=Zoxc
Querify `entry_fn`

Analogous to https://github.com/rust-lang/rust/pull/57570 but this will also require few fixups in Miri so I decided to separate that (and it seems [CI doesn't let us break tools anymore](https://github.com/rust-lang/rust/pull/57392#issuecomment-453801540)? Or was that because it was a rollup PR?)

r? @nikomatsakis
2019-01-19 09:03:27 +01:00
Mazdak Farrokhzad
b941f290ac
Rollup merge of #57501 - petrochenkov:highvar, r=alexreg
High priority resolutions for associated variants

In https://github.com/rust-lang/rust/pull/56225 variants were assigned lowest priority during name resolution to avoid crater run and potential breakage.

This PR changes the rules to give variants highest priority instead.
Some motivation:
- If variants (and their constructors) are treated as associated items, then they are obviously *inherent* associated items since they don't come from traits.
- Inherent associated items have higher priority during resolution than associated items from traits.
- The reason is that there is a way to disambiguate in favor of trait items (`<Type as Trait>::Ambiguous`), but there's no way to disambiguate in favor of inherent items, so they became unusable in case of ambiguities if they have low priority.
- It's technically problematic to fallback from associated types to anything until lazy normalization (?) is implemented.

Crater found some regressions from this change, but they are all in type positions, e.g.
```rust
fn f() -> Self::Ambiguos { ... } // Variant `Ambiguous` or associated type `Ambiguous`?
```
, so variants are not usable there right now, but they may become usable in the future if https://github.com/rust-lang/rfcs/pull/2593 is accepted.
This PR keeps code like this successfully resolving, but introduces a future-compatibility lint `ambiguous_associated_items` that recommends rewriting it as `<Self as Trait>::Ambiguous`.
2019-01-19 09:03:26 +01:00
Mazdak Farrokhzad
c0ad9429ab
Rollup merge of #57476 - Xanewok:bye-crate-analysis, r=Zoxc
Move glob map use to query and get rid of CrateAnalysis

~Also includes commits from ~https://github.com/rust-lang/rust/pull/57392~ and ~https://github.com/rust-lang/rust/pull/57436~.~

With glob map calculated unconditionally in https://github.com/rust-lang/rust/pull/57392, this PR moves the calculated glob map to `GlobalCtxt` and exposes a relevant query (as we do with other queries which copy precomputed data over from the `Resolver`).

This allows us to get rid of the `CrateAnalysis` struct in an attempt to simplify the compiler interface.
cc @Zoxc

r? @nikomatsakis @Zoxc @petrochenkov
2019-01-19 09:03:24 +01:00
Mazdak Farrokhzad
1dc54b7319
Rollup merge of #57268 - peterhj:peterhj-optmergefunc, r=nagisa
Add a target option "merge-functions", and a corresponding -Z flag (works around #57356)

This commit adds a target option "merge-functions", which takes values in ("disabled", "trampolines", or "aliases" (default is "aliases")), to allow targets to opt out of the MergeFunctions LLVM pass. Additionally, the latest commit also adds an optional -Z flag, "merge-functions", which takes the same values and has precedence over the target option when both are specified.

This works around https://github.com/rust-lang/rust/issues/57356.

cc @eddyb @japaric @oli-obk @nox @nagisa

Also thanks to @denzp and @gnzlbg for discussing this on rust-cuda!

### Motivation

Basically, the problem is that the MergeFunctions pass, which rustc currently enables by default at -O2 and -O3 [1], and `extern "ptx-kernel"` functions (specific to the NVPTX target) are currently not compatible with each other. If the MergeFunctions pass is allowed to run, rustc can generate invalid PTX assembly (i.e. a PTX file that is not accepted by the native PTX assembler `ptxas`). Therefore we would like a way to opt out of the MergeFunctions pass, which is what our target option does.

### Related work

The current behavior of rustc is to enable MergeFunctions at -O2 and -O3 [1], and also to enable the use of function aliases within MergeFunctions [2] [3]. MergeFunctions seems to have some benefits, such as reducing code size and fixing a crash [4], which is why it is enabled. However, MergeFunctions both with and without function aliases is incompatible with the NVPTX target; a more detailed example for both cases is given below.

clang's "solution" is to have a "-fmerge-functions" flag that opts in to the MergeFunctions pass, but it is not enabled by default.

### Examples/more details

Consider an example Rust lib using `extern "ptx-kernel"` functions: https://github.com/peterhj/nvptx-mergefunc-bug/blob/master/nocore.rs. If we try to compile this with nightly rustc, we get the following compiler error:

    LLVM ERROR: Module has aliases, which NVPTX does not support.

This error happens because: (1) functions `foo` and `bar` have the same body, so are candidates to be merged by MergeFunctions; and (2) rustc configures MergeFunctions to generate function aliases using the "mergefunc-use-aliases" LLVM option [2] [3], but the NVPTX backend does not support those aliases.

Okay, so we can try omitting "mergefunc-use-aliases", and then rustc will happily emit PTX assembly: https://github.com/peterhj/nvptx-mergefunc-bug/blob/master/nocore-mergefunc-nousealiases-bad.ptx. However, this PTX is invalid! When we try to assemble it with `ptxas` (I'm on the CUDA 9.2 toolchain), we get an assembler error:

    ptxas nocore-mergefunc-nousealiases-bad.ptx, line 38; error   : Illegal call target, device function expected
    ptxas fatal   : Ptx assembly aborted due to errors

What's happening is that MergeFunctions rewrites the `bar` function to call `foo`. However, directly calling an `extern "ptx-kernel"` function from another `extern "ptx-kernel"` is wrong.

If we disable the MergeFunctions pass from running at all, rustc generates correct PTX assembly: https://github.com/peterhj/nvptx-mergefunc-bug/blob/master/nocore-nomergefunc-ok.ptx

[1] a36b960df6/src/librustc_codegen_ssa/back/write.rs (L155)
[2] a36b960df6/src/librustc_codegen_llvm/llvm_util.rs (L64)
[3] https://github.com/rust-lang/rust/pull/56358
[4] https://github.com/rust-lang/rust/pull/49479
2019-01-19 09:03:23 +01:00
bors
1bc6baec76 Auto merge of #57253 - Zoxc:incr-passes2, r=michaelwoerister
Make privacy checking, intrinsic checking and liveness checking incremental

Blocked on https://github.com/rust-lang/rust/pull/51487

r? @michaelwoerister
2019-01-19 07:42:43 +00:00
John Kåre Alsaker
9b5535a6f3 Fix lints in tests 2019-01-19 08:10:01 +01:00
bors
af73e64423 Auto merge of #56722 - Aaron1011:fix/blanket-eval-overflow, r=nikomatsakis
Fix stack overflow when finding blanket impls

Currently, SelectionContext tries to prevent stack overflow by keeping
track of the current recursion depth. However, this depth tracking is
only used when performing normal section (which includes confirmation).
No such tracking is performed for evaluate_obligation_recursively, which
can allow a stack overflow to occur.

To fix this, this commit tracks the current predicate evaluation depth.
This is done separately from the existing obligation depth tracking:
an obligation overflow can occur across multiple calls to 'select' (e.g.
when fulfilling a trait), while a predicate evaluation overflow can only
happen as a result of a deep recursive call stack.

Fixes #56701

I've re-used `tcx.sess.recursion_limit` when checking for predication evaluation overflows. This is such a weird corner case that I don't believe it's necessary to have a separate setting controlling the maximum depth.
2019-01-19 05:05:48 +00:00
John Kåre Alsaker
beb0c74950 Combine all builtin early lints and use a separate walk for plugin lints. Add a -Z no-interleave-lints option to allow benchmarking lints 2019-01-19 05:01:29 +01:00
John Kåre Alsaker
a5d4aeddc8 Address some comments 2019-01-19 04:29:26 +01:00
bors
53b622a48a Auto merge of #56479 - mark-i-m:unsat, r=nikomatsakis
Better lifetime error message

I propose the following error message as more user-friendly

r? @nikomatsakis
2019-01-19 02:25:38 +00:00
bors
f001287c90 Auto merge of #57747 - Centril:rollup, r=Centril
Rollup of 11 pull requests

Successful merges:

 - #57107 (Add a regression test for mutating a non-mut #[thread_local])
 - #57132 (Document that `-C opt-level=0` implies `-C debug-assertions`.)
 - #57212 (docs(rustc): Link to the book's source in rustc)
 - #57302 (Fix unused_assignments false positive)
 - #57350 (Better error note on unimplemented Index trait for string)
 - #57635 (use structured macro and path resolve suggestions)
 - #57650 (librustc_metadata: Pass a default value when unwrapping a span)
 - #57657 (Add regression test to close #53787)
 - #57658 (Two HIR tweaks)
 - #57720 (Fix suggestions given mulitple bad lifetimes)
 - #57725 (Use structured suggestion to surround struct literal with parenthesis)

Failed merges:

r? @ghost
2019-01-18 23:40:14 +00:00
Mazdak Farrokhzad
2a830e47e1
Rollup merge of #57725 - estebank:parens, r=michaelwoerister
Use structured suggestion to surround struct literal with parenthesis
2019-01-18 22:56:48 +01:00
Mazdak Farrokhzad
42accf06dc
Rollup merge of #57720 - dlrobertson:fix_57521, r=estebank
Fix suggestions given mulitple bad lifetimes

When given multiple lifetimes prior to type parameters in generic
parameters, do not ICE and print the correct suggestion.

r? @estebank

CC @pnkfelix

Fixes: #57521
2019-01-18 22:56:47 +01:00
Mazdak Farrokhzad
857d27fb14
Rollup merge of #57658 - nnethercote:rm-hir-P-Lit, r=michaelwoerister
Two HIR tweaks

Two HIR tweaks that make things slightly simpler and faster.
2019-01-18 22:56:45 +01:00
Mazdak Farrokhzad
0eb4bdc5f1
Rollup merge of #57657 - AB1908:regression-test-case, r=nikomatsakis
Add regression test to close #53787

Fixes #53787
2019-01-18 22:56:44 +01:00
Mazdak Farrokhzad
d2300afd66
Rollup merge of #57650 - AB1908:master, r=petrochenkov
librustc_metadata: Pass a default value when unwrapping a span

Fixes #57323.

When compiling with `static-nobundle` a-la

`rustc -l static-nobundle=nonexistent main.rs`

we now get a neat output in the form of:

```
error[E0658]: kind="static-nobundle" is feature gated (see issue #37403)
  |
  = help: add #![feature(static_nobundle)] to the crate attributes to enable

error: aborting due to previous error

For more information about this error, try `rustc --explain E0658`.
```
The build and tests completed successfully on my machine. Should I be adding a new test?
2019-01-18 22:56:43 +01:00
Mazdak Farrokhzad
f63e3d2ef4
Rollup merge of #57635 - euclio:path-separators, r=michaelwoerister
use structured macro and path resolve suggestions
2019-01-18 22:56:42 +01:00
Mazdak Farrokhzad
49c74e4c85
Rollup merge of #57350 - folex:master, r=estebank
Better error note on unimplemented Index trait for string

fixes #56740

I've tried to compile suggestion from comments in the issue #56740, but unsure of it. So I'm open to advice :)

Current output will be like this:
```rust
error[E0277]: the type `str` cannot be indexed by `{integer}`
  --> $DIR/str-idx.rs:3:17
   |
LL |     let c: u8 = s[4]; //~ ERROR the type `str` cannot be indexed by `{integer}`
   |                 ^^^^ `str` cannot be indexed by `{integer}`
   |
   = help: the trait `std::ops::Index<{integer}>` is not implemented for `str`
   = note: you can use `.chars().nth()` or `.bytes().nth()`
           see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>

error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
```

`x.py test src/test/ui` succeeded and I've also tested output manually by compiling the following code:
```rust
fn _f() {
    let s = std::string::String::from("hello");
    let _c = s[0];

    let s = std::string::String::from("hello");
    let mut _c = s[0];

    let s = "hello";
    let _c = s[0];

    let s = "hello";
    let mut _c = &s[0];
}
```

Not sure if some docs should be changed too. I will also fix error message in the [Book :: Indexing into Strings](db53e2e3cd/src/ch08-02-strings.md (indexing-into-strings)) if that PR will get approved :)
2019-01-18 22:56:40 +01:00
Mazdak Farrokhzad
0dd4bfa356
Rollup merge of #57302 - sinkuu:unused_assignments_fp, r=estebank
Fix unused_assignments false positive

Fixes #22630.

In liveness analysis, make `continue` jump to the loop condition's `LiveNode` (`cond` as in comment) instead of the loop's one (`expr`).

069b0c4108/src/librustc/middle/liveness.rs (L1358-L1370)
2019-01-18 22:56:39 +01:00
Mazdak Farrokhzad
bb683b9f3a
Rollup merge of #57212 - phansch:improve_rustc_book_contributing, r=steveklabnik
docs(rustc): Link to the book's source in rustc

This makes the source of [the rustc book](https://doc.rust-lang.org/rustc/what-is-rustc.html) book a bit more discoverable.
2019-01-18 22:56:37 +01:00
Mazdak Farrokhzad
04a2cbd1c8
Rollup merge of #57132 - daxpedda:master, r=steveklabnik
Document that `-C opt-level=0` implies `-C debug-assertions`.

I couldn't find it stated anywhere else (https://doc.rust-lang.org/nightly/rustc/codegen-options/index.html#opt-level).
It was a problem before here: https://github.com/rust-lang/rust/issues/39449, it got lost in the migration to the new documentation I assume.

On a sidenote: I think that `-C opt-level=0` having a sideeffect on another flag should be changed. Having compiler flags affecting others doesn't make much sense to me, they are used to fine tune anyway.
In any case, this plays no role in this PR.
2019-01-18 22:56:35 +01:00
Mazdak Farrokhzad
b9cb5db5e8
Rollup merge of #57107 - mjbshaw:thread_local_test, r=nikomatsakis
Add a regression test for mutating a non-mut #[thread_local]

This should close #54901 since the regression has since been fixed.
2019-01-18 22:56:34 +01:00
Who? Me?!
0c4602aaef
Update README.md
Point contributors to the rustc-guide...
2019-01-18 15:28:23 -06:00
mark
dcd56d11da remove more old readmes 2019-01-18 14:10:45 -06:00
bors
c76f3c374f Auto merge of #57737 - Centril:rollup, r=Centril
Rollup of 10 pull requests

Successful merges:

 - #56594 (Remove confusing comment about ideally using `!` for `c_void`)
 - #57340 (Use correct tracking issue for c_variadic)
 - #57357 (Cleanup PartialEq docs.)
 - #57551 (resolve: Add a test for issue #57539)
 - #57636 (Fix sources sidebar not showing up)
 - #57646 (Fixes text becoming invisible when element targetted)
 - #57654 (Add some links in std::fs.)
 - #57683 (Document Unpin in std::prelude documentation)
 - #57685 (Enhance `Pin` impl applicability for `PartialEq` and `PartialOrd`.)
 - #57710 (Fix non-clickable urls)

Failed merges:

r? @ghost
2019-01-18 19:08:20 +00:00
Mazdak Farrokhzad
ff583ac484
Rollup merge of #57710 - GuillaumeGomez:non-clickable, r=QuietMisdreavus
Fix non-clickable urls

Fixes #57695

I didn't find anywhere where this rule was useful. Why did you add it @JohnHeitmann?

r? @QuietMisdreavus
2019-01-18 18:06:40 +01:00
Mazdak Farrokhzad
25ea20dfeb
Rollup merge of #57685 - pthariensflame:enhancement/pin-impl-applicability, r=withoutboats
Enhance `Pin` impl applicability for `PartialEq` and `PartialOrd`.

This allows for comparing for equality or ordering a `Pin<P>` and a `Pin<Q>` as long as `P` and `Q` are correspondingly comparable themselves *even when `P` and `Q` are different types*.
An example might be comparing a `Pin<&mut OsString>` to a `Pin<&mut PathBuf>`, which might arise from pin projections from a pair of larger contexts that aren't `Unpin`.
2019-01-18 18:06:38 +01:00
Mazdak Farrokhzad
b0563fdb44
Rollup merge of #57683 - xfix:patch-15, r=QuietMisdreavus
Document Unpin in std::prelude documentation
2019-01-18 18:06:37 +01:00
Mazdak Farrokhzad
b12397fad1
Rollup merge of #57654 - ehuss:fs-links, r=alexcrichton
Add some links in std::fs.

A few items were referenced, but did not have links.
2019-01-18 18:06:36 +01:00
Mazdak Farrokhzad
b9e940c2e6
Rollup merge of #57646 - GuillaumeGomez:fix-css, r=QuietMisdreavus
Fixes text becoming invisible when element targetted

Fixes #57628.

r? @QuietMisdreavus
2019-01-18 18:06:34 +01:00
Mazdak Farrokhzad
e26498026f
Rollup merge of #57636 - GuillaumeGomez:fix-sources-sidebar, r=QuietMisdreavus
Fix sources sidebar not showing up

Fixes #57601.

The order of imports made it so that the sidebar creation was called before the sidebar sources were created. Like this, when the sources are loaded, they create the sidebar as expected.

r? @QuietMisdreavus
2019-01-18 18:06:33 +01:00
Mazdak Farrokhzad
4091ca0183
Rollup merge of #57551 - petrochenkov:regrtest, r=nikomatsakis
resolve: Add a test for issue #57539

Add a test for the bugfix regression reported in https://github.com/rust-lang/rust/issues/57539

Closes https://github.com/rust-lang/rust/issues/57539
2019-01-18 18:06:32 +01:00
Mazdak Farrokhzad
bca490808f
Rollup merge of #57357 - frewsxcv:frewsxcv-partial-eq, r=QuietMisdreavus
Cleanup PartialEq docs.

- Cleanup the `impl PartialEq<BookFormat> for Book` implementation
- Implement `impl PartialEq<Book> for BookFormat` so it’s symmetric
  - Fixes https://github.com/rust-lang/rust/issues/53844.
- Removes the last example since it appears to be redundant with the
  previous two examples.
2019-01-18 18:06:30 +01:00
Mazdak Farrokhzad
76cdccb2c2
Rollup merge of #57340 - eqrion:doc/c_variadic, r=Mark-Simulacrum
Use correct tracking issue for c_variadic

Fixes #57306
2019-01-18 18:06:29 +01:00
Mazdak Farrokhzad
9e78bc5d4f
Rollup merge of #56594 - sdroege:c_void-is-not-never, r=TimNN
Remove confusing comment about ideally using `!` for `c_void`

Using `!` for `c_void` would have the problem that pointers and
potentially references to an uninhabited type would be created, and at
least for references this is UB.

In addition document that newtype wrappers around `c_void` can be used
safely in place of `extern type` until the latter is stabilized.

----

I'm not 100% sure about the usage for opaque types as the [nomicon](https://doc.rust-lang.org/nomicon/ffi.html#representing-opaque-structs) still recommends using `#[repr(C)] pub struct Foo { _private: [u8; 0] }` but it seems like these two should be equivalent in the end? Also the `#[repr(C)]` (in both cases) should be unneeded because such types never being passed by value, never being dereferenced but only passed around as pointer or reference, so the representation of (*values* of) the type itself should not matter at all?

Also in context of `c_void` and `!` the second unresolved question in the [`extern type`](https://github.com/rust-lang/rust/issues/43467) stabilization ticket seems relevant

> In [std's](164619a8cf/src/libstd/os/raw.rs (L59-L64)) source, it is mentioned that LLVM expects i8* for C's void*.
> We'd need to continue to hack this for the two c_voids in std and libc.
> But perhaps this should be done across-the-board for all extern types?
> Somebody should check what Clang does.

Please correct me if my understanding is wrong and everything's actually fine as is.
2019-01-18 18:06:26 +01:00
bors
f613dc138b Auto merge of #56189 - rep-nop:keep_doc_test_executable, r=QuietMisdreavus
rustdoc: Add option to persist doc test executables

Fixes #37048.

This is the initial version of the code so the doctest executables can be used for stuff like code coverage (specifically https://github.com/xd009642/tarpaulin/issues/13) the folders it goes into were just a first idea, so any better ones are welcome.

Right now it creates a directory structure like:
```
  given_path/
          |_____ <filename>_rs_<linenum>/
          |_____ ...
          |_____ <filename>_rs_<linenum>/
                 |_____ rust_out

```
I couldn't figure out where it actually outputs the file w/ the name, I suspect its somewhere deeper in the compiler.

It also adds the unstable `--persist-doctests` flag to `rustdoc` that enables this behavior.
2019-01-18 16:18:11 +00:00
Philipp Hansch
79ef9718bb
Remove delay_span_bug from qualify_min_const_fn
This is causing issues with a new Clippy lint that will be able to
detect possible const functions.

As per https://github.com/rust-lang/rust-clippy/pull/3648#discussion_r247927450
2019-01-18 16:46:51 +01:00
Oliver Scherer
efda6816bd Allow evaluating trivial drop glue in constants 2019-01-18 13:31:05 +01:00
John Kåre Alsaker
13dc584db3 Merge visitors in AST validation 2019-01-18 13:11:54 +01:00
bors
527b8d4243 Auto merge of #57065 - Zoxc:graph-tweaks, r=michaelwoerister
Optimize try_mark_green and eliminate the lock on dep node colors

Blocked on https://github.com/rust-lang/rust/pull/56614

r? @michaelwoerister
2019-01-18 11:34:11 +00:00
Oliver Scherer
1dc4e417fa Manually inline a function that was only used once 2019-01-18 11:40:53 +01:00
Esteban Küber
2e06d9c91b Point at return type when appropriate 2019-01-18 00:12:09 -08:00
bors
38650b69ca Auto merge of #56996 - clarcharr:spin_loop_hint, r=KodrAus
Move spin_loop_hint to core::hint module

As mentioned in #55002. The new name is kept unstable to decide whether the function should have `_hint` in its name.
2019-01-18 07:36:13 +00:00
Esteban Küber
954769e2ed Fix test after rebase 2019-01-17 22:51:01 -08:00
Kevin Leimkuhler
b4766f8077 Correct error location indicated by comments 2019-01-17 22:37:12 -08:00
Lukas Kalbertodt
54f11240b7 Override Iterator::is_sorted_by in slice::Iter impl
Additionally, the root implementation was changed a bit: it now uses
`all` instead of coding that logic manually.

To avoid duplicate code, the inherent `[T]::is_sorted_by` method now
calls `self.iter().is_sorted_by(...)`. This should always be inlined
and not result in overhead.
2019-01-17 22:34:43 -08:00
Kevin Leimkuhler
67729b4040 Compare pairs with slice::windows 2019-01-17 22:34:43 -08:00
Kevin Leimkuhler
ccc027eff7 Improve documentation and slice impl 2019-01-17 22:34:43 -08:00
Kevin Leimkuhler
ce47dde59f Add is_sorted unstable documentation 2019-01-17 22:34:43 -08:00
Kevin Leimkuhler
02477f6f99 Add is_sorted impl for [T] 2019-01-17 22:34:43 -08:00