bors [Thu, 4 Oct 2018 03:08:22 +0000 (03:08 +0000)]
Auto merge of #54624 - arielb1:evaluate-outlives, r=nikomatsakis
handle outlives predicates in trait evaluation
This handles higher-ranked outlives predicates in trait evaluation the same way they are handled in projection.
Fixes #54302. I think this is a more correct fix than #54401 because it fixes the root case in evaluation instead of making evaluation used in less cases. However, we might want to go to a direction closer to @nikomatsakis's solution with Chalk.
bors [Wed, 3 Oct 2018 21:46:21 +0000 (21:46 +0000)]
Auto merge of #54391 - davidtwco:issue-54230, r=petrochenkov
suggest `crate::...` for "local" paths in 2018
Fixes #54230.
This commit adds suggestions for unresolved imports in the cases where
there could be a missing `crate::`, `super::`, `self::` or a missing
external crate name before an import.
bors [Wed, 3 Oct 2018 18:12:22 +0000 (18:12 +0000)]
Auto merge of #54605 - petrochenkov:mambig, r=alexcrichton
resolve: Disambiguate a subset of conflicts "macro_rules" vs "macro name in module"
Currently if macro name may refer to both a `macro_rules` macro definition and a macro defined/imported into module we conservatively report an ambiguity error.
Unfortunately, these errors became a source of regressions when macro modularization was enabled - see issue https://github.com/rust-lang/rust/issues/54472.
This PR disambiguates such conflicts in favor of `macro_rules` if both the `macro_rules` item and in-module macro name are defined in the same normal (named) module and `macro_rules` is closer in scope to the point of use (see the tests for examples).
This is a subset of more general approach described in https://github.com/rust-lang/rust/issues/54472#issuecomment-424666659.
The subset is enough to fix all the regressions from https://github.com/rust-lang/rust/issues/54472, but it can be extended to apply to all "macro_rules" vs "macro name in module" conflicts in the future.
To give an analogy, this is equivalent to scoping rules for `let` variables and items defined in blocks (`macro_rules` behaves like "`let` at module level" in general).
```rust
{ // beginning of the block
use xxx::m; // (1)
// Starting from the beginning of the block and until here m!() refers to (1)
macro_rules! m { ... } // (2)
// Starting from here and until the end of the block m!() refers to (2)
} // end of the block
```
More complex examples with `use` and `macro_rules` from different modules still report ambiguity errors, even if equivalent examples with `let` are legal.
David Wood [Wed, 3 Oct 2018 13:20:20 +0000 (15:20 +0200)]
Deterministic external crate suggestion.
This commit ensures that the external crate suggestion is deterministic
by using a `BTreeMap` rather than a `FxHashMap`. This is particularly
useful as `std` and `core` will often contain the same items and
therefore the suggestion would previously suggest either for any given
error - in this case, the suggestion will always prefer `std` now.
David Wood [Fri, 28 Sep 2018 09:30:55 +0000 (11:30 +0200)]
Removed hardcoded crate.
Previously, `meta` crate was hardcoded as attempting to resolve a path
with it would ICE. Now, we attempt to load each extern crate first so
that resolving a path involving that crate doesn't error.
David Wood [Thu, 20 Sep 2018 15:15:52 +0000 (17:15 +0200)]
Add suggestions for unresolved imports.
This commit adds suggestions for unresolved imports in the cases where
there could be a missing `crate::`, `super::`, `self::` or a missing
external crate name before an import.
bors [Wed, 3 Oct 2018 10:49:27 +0000 (10:49 +0000)]
Auto merge of #54720 - davidtwco:issue-51191, r=nikomatsakis
NLL fails to suggest "try removing `&mut` here"
Fixes #51191.
This PR adds ``try removing `&mut` here`` suggestions to functions where a mutable borrow is being taken of a `&mut self` or a `self: &mut Self`. This PR also enables the suggestion for adding a `mut` pattern to by-value implicit self arguments without `mut` patterns already.
bors [Tue, 2 Oct 2018 23:29:58 +0000 (23:29 +0000)]
Auto merge of #54767 - pietroalbini:rollup, r=pietroalbini
Rollup of 10 pull requests
Successful merges:
- #54269 (#53840: Consolidate pattern check errors)
- #54458 (Allow both explicit and elided lifetimes in the same impl header)
- #54603 (Add `crate::` to trait suggestions in Rust 2018.)
- #54648 (Update Cargo's submodule)
- #54680 (make run-pass tests with empty main just compile-pass tests)
- #54687 (Use impl_header_lifetime_elision in libcore)
- #54699 (Re-export `getopts` so custom drivers can reference it.)
- #54702 (do not promote comparing function pointers)
- #54728 (Renumber `proc_macro` tracking issues)
- #54745 (make `CStr::from_bytes_with_nul_unchecked()` a const fn)
Pietro Albini [Tue, 2 Oct 2018 20:54:36 +0000 (22:54 +0200)]
Rollup merge of #54728 - alexcrichton:renumber-issues, r=nikomatsakis
Renumber `proc_macro` tracking issues
Lots of issue links in the compiler still point to https://github.com/rust-lang/rust/issues/38356 which is a bit of a monster issue that isn't serving much purpose any more. I've split the issue into a number of more fine-grained tracking issues to track stabilizations.
Pietro Albini [Tue, 2 Oct 2018 20:54:32 +0000 (22:54 +0200)]
Rollup merge of #54680 - RalfJung:compile-pass, r=pnkfelix
make run-pass tests with empty main just compile-pass tests
Many run-pass tests have an empty main, so there is not actually any point in running them. This makes them `compile-pass` tests instead, saving some time (generating the binary and then running it).
For now I did this only for `run-pass/issues`; if there is interest I can also do it for the other directories. I used `^\s*fn\s+main\(\s*\)\s*\{\s*\}` as regexp to identify these files.
Pietro Albini [Tue, 2 Oct 2018 20:54:29 +0000 (22:54 +0200)]
Rollup merge of #54603 - davidtwco:issue-54559, r=nikomatsakis
Add `crate::` to trait suggestions in Rust 2018.
Fixes #54559.
In the 2018 edition, when suggesting traits to import that implement a
given method that is being invoked, suggestions will now include the
`crate::` prefix if the suggested trait is local to the current crate.
Pietro Albini [Tue, 2 Oct 2018 20:54:28 +0000 (22:54 +0200)]
Rollup merge of #54458 - scottmcm:bug-54456, r=nikomatsakis
Allow both explicit and elided lifetimes in the same impl header
While still prohibiting explicit and in-band in the same header.
Fixes #54456
As usual, I don't know the broader context of the code I'm changing, so please let me know whatever I can do better.
Pre-existing test that mixing explicit and in-band remains an error: https://github.com/rust-lang/rust/blob/master/src/test/ui/in-band-lifetimes/E0688.rs
Pietro Albini [Tue, 2 Oct 2018 20:54:27 +0000 (22:54 +0200)]
Rollup merge of #54269 - PramodBisht:issue/53840, r=estebank
#53840: Consolidate pattern check errors
#53840 on this PR we are aggregating `cannot bind by-move and by-ref in the same pattern` message present on the different lines into one diagnostic message. Here we are first gathering those `spans` on `vector` then we are throwing them with the help of `MultiSpan`
r? @estebank
bors [Tue, 2 Oct 2018 04:22:55 +0000 (04:22 +0000)]
Auto merge of #54701 - arielb1:outlives-later, r=nikomatsakis
normalize param-env type-outlives predicates last
The normalization of type-outlives predicates can depend on misc.
environment predicates, but not the other way around. Inferred lifetime
bounds can propagate type-outlives bounds far and wide, so their
normalization needs to work well.
Fixes #54467
r? @nikomatsakis
beta-nominating because this is required for inferred_outlives_bounds, which is in beta
David Wood [Thu, 27 Sep 2018 22:56:41 +0000 (00:56 +0200)]
Attempt to resolve linking issues.
This commit takes a different approach to add the `crate::` prefix to
item paths than previous commits. Previously, recursion was stopped
after a prelude crate name was pushed to the path. It is theorized that
this was the cause of the linking issues since the same path logic is
used for symbol names and that not recursing meant that details were
being missed that affect symbol names. As of this commit, instead of
ceasing recursion, a flag is passed through to any subsequent recursive
calls so that the same effect can be achieved by checking that flag.
David Wood [Thu, 27 Sep 2018 19:38:11 +0000 (21:38 +0200)]
Move prelude crate names into `Session`.
Avoid hardcoding and special-casing the `std` crate name in the item
path logic by moving the prelude crate name logic into the `Session`
type so it can be reused in the item path logic and resolve module.
David Wood [Wed, 26 Sep 2018 23:17:54 +0000 (01:17 +0200)]
Add `crate::` to trait suggestions in Rust 2018.
In the 2018 edition, when suggesting traits to import that implement a
given method that is being invoked, suggestions will now include the
`crate::` prefix if the suggested trait is local to the current crate.
David Wood [Mon, 1 Oct 2018 17:20:57 +0000 (19:20 +0200)]
Improve mutability error suggestions.
This commit improves mutability error suggestions by suggesting the
removal of `&mut` where a mutable borrow is being taken of a `&mut self`
or a `self: &mut Self`.
David Wood [Mon, 1 Oct 2018 15:46:04 +0000 (17:46 +0200)]
Improve implicit self mutability suggestions.
This commit adds an `ImplicitSelfKind` to the HIR and the MIR that keeps
track of whether a implicit self argument is immutable by-value, mutable
by-value, immutable reference or mutable reference so that the addition
of the `mut` keyword can be suggested for the immutable by-value case.
bors [Mon, 1 Oct 2018 22:32:26 +0000 (22:32 +0000)]
Auto merge of #54693 - RalfJung:ctfe-scalar-pair-undef, r=oli-obk
do not normalize all non-scalar constants to a ConstValue::ScalarPair
We still need `ConstValue::ScalarPair` for match handling (matching slices and strings), but that will never see anything `Undef`. For non-fat-ptr `ScalarPair`, just point to the allocation like larger data structures do.
The normalization of type-outlives predicates can depend on misc.
environment predicates, but not the other way around. Inferred lifetime
bounds can propagate type-outlives bounds far and wide, so their
normalization needs to work well.
bors [Mon, 1 Oct 2018 14:58:24 +0000 (14:58 +0000)]
Auto merge of #54667 - RalfJung:maybe-uninit, r=pnkfelix
Panic when using mem::uninitialized or mem::zeroed on an uninhabited type
All code by @japaric. This re-submits one half of https://github.com/rust-lang/rust/pull/53508. This is likely not the one that introduced the perf regression, but just to be sure I'll do a perf run anyway.
bors [Mon, 1 Oct 2018 10:16:00 +0000 (10:16 +0000)]
Auto merge of #54711 - kennytm:rollup, r=kennytm
Rollup of 13 pull requests
Successful merges:
- #53784 (Document that slices cannot be larger than `isize::MAX` bytes)
- #54308 (Better user experience when attempting to call associated functions with dot notation)
- #54488 (in which we include attributes in unused `extern crate` suggestion spans)
- #54544 (Indicate how to move value out of Box in docs.)
- #54623 (Added help message for `impl_trait_in_bindings` feature gate)
- #54641 (A few cleanups and minor improvements to rustc/infer)
- #54656 (Correct doc for WorkQueue<T>::pop().)
- #54674 (update miri)
- #54676 (Remove `-Z disable_ast_check_for_mutation_in_guard`)
- #54679 (Improve bug! message for impossible case in Relate)
- #54681 (Rename sanitizer runtime libraries on OSX)
- #54708 (Make ./x.py help <cmd> invoke ./x.py <cmd> -h on its own)
- #54713 (Add nightly check for tool_lints warning)
kennytm [Mon, 1 Oct 2018 08:13:04 +0000 (16:13 +0800)]
Rollup merge of #54681 - alexcrichton:san-names, r=kennytm
Rename sanitizer runtime libraries on OSX
Currently we ship sanitizer libraries as they're built, but these names
unfortunately conflict with the names of the sanitizer libraries
installed on the system. If a crate, for example, links in C code that
wants to use the system sanitizer and the Rust code doesn't use
sanitizers at all, then using `cargo` may accidentally pull in the
Rust-installed sanitizer library due to a conflict in names.
This change is intended to be entirely transparent for Rust users of
sanitizers, it should only hopefully improve our story with other users!
kennytm [Mon, 1 Oct 2018 08:13:00 +0000 (16:13 +0800)]
Rollup merge of #54641 - ljedrz:cleanup_rustc_infer, r=estebank
A few cleanups and minor improvements to rustc/infer
- use unwrap_or(_else) where applicable
- convert single-branch matches to if-let
- use to_owned instead of to_string with string literals
- improve vector allocations
- readability improvements
- miscellaneous minor code improvements
bors [Mon, 1 Oct 2018 03:24:02 +0000 (03:24 +0000)]
Auto merge of #54675 - alexcrichton:defaultlibs, r=varkor
rust: Add a `-C default-linker-libraries` option
This commit adds a new codegen option for the compiler which disables
rustc's passing of `-nodefaultlibs` by default on relevant platforms.
Sometimes Rust is linked with C code which fails to link with
`-nodefaultlibs` and is unnecessarily onerous to get linking correctly
with `-nodefaultlibs`.
An example of this is that when you compile C code with sanitizers and
then pass `-fsanitize=address` to the linker, it's incompatible with
`-nodefaultlibs` also being passed to the linker.
In these situations it's easiest to turn off Rust's default passing of
`-nodefaultlibs`, which was more ideological to start with than
anything! Preserving the default is somewhat important but having this
be opt-in shouldn't cause any breakage.
bors [Mon, 1 Oct 2018 00:51:19 +0000 (00:51 +0000)]
Auto merge of #54662 - matklad:once-perf, r=alexcrichton
Fix Once perf regression
Because `call_once` is generic, but `is_completed` is not, we need
`#[inline]` annotation to allow LLVM to inline `is_completed` into
`call_once` in downstream crates.
cc https://github.com/rust-lang/rust/pull/53027/files#r221418859
Auto merge of #53255 - orium:fix-bug-overflow-send, r=arielb1
Add a per-tree error cache to the obligation forest
This implements part of what @nikomatsakis mentioned in https://github.com/rust-lang/rust/pull/30533#issuecomment-170705871:
> 1. If you find that a new obligation is a duplicate of one already in the tree, the proper processing is:
> * if that other location is your parent, you should abort with a cycle error (or accept it, if coinductive)
> * if that other location is not an ancestor, you can safely ignore the new obligation
In particular it implements the "if that other location is your parent accept it, if coinductive" part. This fixes #40827.
I have to say that I'm not 100% confident that this is rock solid. This is my first pull request :tada:, and I didn't know anything about the trait resolver before this. In particular I'm not totally sure that comparing predicates is enough (for instance, do we need to compare `param_env` as well?). Also, I'm not sure what @nikomatsakis mentions [here](https://github.com/rust-lang/rust/issues/30977#issue-127091096), but it might be something that affects this PR:
> In particular, I am wary of getting things wrong around inference variables! We can always add things to the set in their current state, and if unifications occur then the obligation is just kind of out-of-date, but I want to be sure we don't accidentally fail to notice that something is our ancestor. I decided this was subtle enough to merit its own PR.
Anyway, go ahead and review :slightly_smiling_face:.
Ref #30977.
# Performance
We are now copying vectors around, so I decided to do some benchmarking. A simple benchmark shows that this does not seem to affect performance in a measurable way:
I ran `cargo clean && cargo build` 20 times on actix-web (84b27db) and these are the results:
```text
rustc master:
Mean Std.Dev. Min Median Max
real 66.637 2.996 57.220 67.714 69.314
user 307.293 14.741 258.093 312.209 320.702
sys 12.524 0.653 10.499 12.726 13.193
rustc fix-bug-overflow-send:
Mean Std.Dev. Min Median Max
real 66.297 4.310 53.532 67.516 70.348
user 306.812 22.371 236.917 314.748 326.229
sys 12.757 0.952 9.671 13.125 13.544
```
I will do a more comprehensive benchmark (compiling rustc stage1) and post the results.
Auto merge of #53816 - zackmdavis:elided_lifetimes_in_paths_field_day, r=nikomatsakis
don't elide lifetimes in paths in librustc/
In light of the "Apply to rustc" checkbox on #44524 and @nikomatsakis's [recent comment about regularly wanting visual indication of elided lifetimes in types](https://github.com/rust-lang/rust/issues/44524#issuecomment-414663773), I was curious to see what it would look like if we turned the `elided_lifetimes_in_path` lint on in at least one crate in the codebase (I chose librustc). Given that I couldn't figure out how to get `cargo fix` work with the build system, this arguably wasn't a very efficient use of my time, but once I started, the conjunction of moral law and the sunk cost fallacy forced me to continue.
This is mostly applying the `<'_>` suggestions issued by the lint, but there were a few places where I named the lifetimes (_e.g._, `<'a, 'gcx, 'tcx>` on `TyCtxt`) in order to match style with surrounding code.
Zack M. Davis [Thu, 30 Aug 2018 05:02:42 +0000 (22:02 -0700)]
don't elide lifetimes in paths in librustc/
This seemed like a good way to kick the tires on the
elided-lifetimes-in-paths lint (#52069)—seems to work! This was also
pretty tedious—it sure would be nice if `cargo fix` worked on this
codebase (#53896)!