Commit graph

8314 commits

Author SHA1 Message Date
bors
8a12be7412 Auto merge of #89249 - Aaron1011:higher-ranked-cause, r=estebank
Improve cause information for NLL higher-ranked errors

This PR has several interconnected pieces:

1. In some of the NLL region error code, we now pass
   around an `ObligationCause`, instead of just a plain `Span`.
   This gets forwarded into `fulfill_cx.register_predicate_obligation`
   during error reporting.
2. The general InferCtxt error reporting code is extended to
   handle `ObligationCauseCode::BindingObligation`
3. A new enum variant `ConstraintCategory::Predicate` is added.
   We try to avoid using this as the 'best blame constraint' - instead,
   we use it to enhance the `ObligationCause` of the `BlameConstraint`
   that we do end up choosing.

As a result, several NLL error messages now contain the same
"the lifetime requirement is introduced here" message as non-NLL
errors.

Having an `ObligationCause` available will likely prove useful
for future improvements to NLL error messages.
2021-09-27 21:29:19 +00:00
bors
98c8619502 Auto merge of #89214 - smoelius:register_tool, r=petrochenkov
Pass real crate-level attributes to `pre_expansion_lint`

The PR concerns the unstable feature `register_tool` (#66079).

The feature's implementation requires the attributes of the crate being compiled, so that when attributes like `allow(foo::bar)` are encountered, it can be verified that `register_tool(foo)` appears in the crate root.

However, the crate's attributes are not readily available during early lint passes. Specifically, on this line, `krate.attrs` appears to be the attributes of the current source file, not the attributes of the whole crate: bf642323d6/compiler/rustc_lint/src/context.rs (L815)

Consequently, "unknown tool" errors were being produced when `allow(foo::bar)` appeared in a submodule, even though `register_tool(foo)` appeared in the crate root.

EDITED: The proposed fix is to obtain the real crate-level attributes in `configure_and_expand` and pass them to `pre_expansion_lint`. (See `@petrochenkov's` [comment](https://github.com/rust-lang/rust/pull/89214#issuecomment-926927072) below.)

The original "prosed fix" text follows.

---

The proposed fix is to add an `error_on_unknown_tool` flag to `LintLevelsBuilder`. The flag controls whether "unknown tool" errors are emitted. The flag is set during late passes, but not earlier.

More specifically, this PR contains two commits:

* The first adds a `known-tool-in-submodule` UI test that does not currently pass.
* The second adds the `error_on_unknown_tool` flag. The new test passes with the addition of this flag.

This change has the added benefit of eliminating some errors that were duplicated in existing tests.

To the reviewer: please check that I implemented the UI test correctly.
2021-09-27 18:21:14 +00:00
Aaron Hill
41ad383e11
Remove DefId from ConstraintCategory::Predicate
This shirnks the size of `ConstraintCategory`, hopefully
fixing a performance regression.
2021-09-27 10:45:34 -05:00
Aaron Hill
93ab12eeab
Improve cause information for NLL higher-ranked errors
This PR has several interconnected pieces:

1. In some of the NLL region error code, we now pass
   around an `ObligationCause`, instead of just a plain `Span`.
   This gets forwarded into `fulfill_cx.register_predicate_obligation`
   during error reporting.
2. The general InferCtxt error reporting code is extended to
   handle `ObligationCauseCode::BindingObligation`
3. A new enum variant `ConstraintCategory::Predicate` is added.
   We try to avoid using this as the 'best blame constraint' - instead,
   we use it to enhance the `ObligationCause` of the `BlameConstraint`
   that we do end up choosing.

As a result, several NLL error messages now contain the same
"the lifetime requirement is introduced here" message as non-NLL
errors.

Having an `ObligationCause` available will likely prove useful
for future improvements to NLL error messages.
2021-09-27 10:23:45 -05:00
bors
2b6ed3b675 Auto merge of #89285 - jackh726:issue-88862, r=nikomatsakis
Don't normalize opaque types with escaping late-bound regions

Fixes #88862

Turns out, this has some really bad perf implications in large types (issue #88862). While we technically can handle them fine, it doesn't change test output either way. For now, revert with an added benchmark. Future attempts to change this back will have to consider perf.

Needs a perf run once https://github.com/rust-lang/rustc-perf/pull/1033 is merged

r? `@nikomatsakis`
2021-09-27 14:08:13 +00:00
bors
3e8f32e1c5 Auto merge of #89263 - TaKO8Ki:suggest-both-immutable-and-mutable-trait-implementations, r=estebank
Suggest both of immutable and mutable trait implementations

closes #85865
2021-09-27 11:10:40 +00:00
bors
b2804655f5 Auto merge of #89092 - bjorn3:sync_cg_clif-2021-09-19, r=bjorn3
Sync rustc_codegen_cranelift

Nothing exciting this time. Mostly internal refactorings.

r? `@ghost`

`@rustbot` label +A-codegen +A-cranelift +T-compiler
2021-09-26 23:31:01 +00:00
Samuel Moelius
1e15bbe552 Pass real crate-level attributes to pre_expansion_lint 2021-09-26 21:50:50 +00:00
jackh726
a84e3fab30 Don't normalize opaque types with escaping late-bound regions.
Turns out, this has some really bad perf implications in large types (issue #88862). While we technically can handle them fine, it doesn't change test output either way. For now, revert with an added benchmark. Future attempts to change this back will have to consider perf.
2021-09-26 15:58:24 -04:00
bors
05044c2e6c Auto merge of #89144 - sexxi-goose:insig_stdlib, r=nikomatsakis
2229: Mark insignificant dtor in stdlib

I looked at all public [stdlib Drop implementations](https://doc.rust-lang.org/stable/std/ops/trait.Drop.html#implementors) and categorized them into Insigificant/Maybe/Significant Drop.

Reasons are noted here: https://docs.google.com/spreadsheets/d/19edb9r5lo2UqMrCOVjV0fwcSdS-R7qvKNL76q7tO8VA/edit#gid=1838773501

One thing missing from this PR is tagging HashMap as insigificant destructor as that needs some discussion.

r? `@Mark-Simulacrum`

cc `@nikomatsakis`
2021-09-26 19:36:00 +00:00
Takayuki Maeda
620f480e64 better suggestions 2021-09-27 00:30:39 +09:00
Takayuki Maeda
0661c2de24 suggest both immutable and mutable trait implementations 2021-09-26 16:43:44 +09:00
bors
f6e6ddc09d Auto merge of #88680 - ehuss:more-attr-validation, r=petrochenkov
Validate builtin attributes for macro args.

This adds some validation for `path`, `crate_type`, and `recursion_limit` attributes so that they will now return an error if you attempt to pass a macro into them (such as `#[path = foo!()]`). Previously, the attribute would be completely ignored. These attributes are special because their values need to be known before/during expansion.

cc #87681
2021-09-26 05:15:11 +00:00
Manish Goregaokar
04d3f93a2b
Rollup merge of #89224 - TaKO8Ki:change-the-order-of-suggestions, r=joshtriplett
Change the order of imports suggestions

closes #83564
2021-09-25 18:22:21 -07:00
Manish Goregaokar
653dcaac2b
Rollup merge of #89216 - r00ster91:bigo, r=dtolnay
Consistent big O notation

This makes the big O time complexity notation in places with markdown support more consistent.
Inspired by #89210
2021-09-25 18:22:20 -07:00
Eric Huss
75f058dbfd Check for macros in built-in attributes that don't support them. 2021-09-25 09:03:15 -07:00
Eric Huss
5f8c571e50 Move malformed attribute code to a function and fix inner attribute suggestion.
Moving to a dedicated function in preparation for other validation.

The suggestion given didn't consider if it was an inner attribute.
2021-09-25 08:11:10 -07:00
bors
63cc2bb3d0 Auto merge of #88243 - nikic:newpm-2, r=nagisa
Enable new pass manager with LLVM 13

The new pass manager is enabled by default in clang since Clang/LLVM 13. Per the recent discussion on llvm-dev (https://lists.llvm.org/pipermail/llvm-dev/2021-August/152305.html) the legacy pass manager will be unmaintained in LLVM 14 and removed entirely in LLVM 15.

This switches us to use the new pass manager if LLVM >= 13 is used. It's possible to still use the old pass manager using `-Z new-llvm-pass-manager=no`.
2021-09-25 13:43:52 +00:00
bors
e9f29a8519 Auto merge of #89030 - nbdd0121:box2, r=jonas-schievink
Introduce `Rvalue::ShallowInitBox`

Polished version of #88700.

Implements MCP rust-lang/compiler-team#460, and should allow #43596 to go forward.

In short, creating an empty box is split from a nullary-op `NullOp::Box` into two steps, first a call to `exchange_malloc`, then a `Rvalue::ShallowInitBox` which transmutes `*mut u8` to a shallow-initialized `Box<T>`. This allows the `exchange_malloc` call to unwind. Details can be found in the MCP.

`NullOp::Box` is not yet removed, purely to make reverting easier in case anything goes wrong as the result of this PR. If revert is needed a reversion of "Use Rvalue::ShallowInitBox for box expression" commit followed by a test bless should be sufficient.

Experiments in #88700 showed a very slight compile-time perf regression due to (supposedly) slightly more time spent in LLVM. We could omit unwind edge generation (in non-`oom=panic` case) in box expression MIR construction to restore perf; but I don't think it's necessary since runtime perf isn't affected and perf difference is rather small.
2021-09-25 11:01:13 +00:00
Nikita Popov
074bbc6b87 Use correct pipeline for LTO at O0
Unlike the pre-link piplines, the LTO pipelines do support O0,
and using them is required to avoid leaving behind undefined
references for the linker.
2021-09-25 11:24:23 +02:00
Nikita Popov
be01f42f73 Enable new pass manager on LLVM 13
The new pass manager is enabled by default in clang since
Clang/LLVM 13. While the discussion about this is still ongoing
(https://lists.llvm.org/pipermail/llvm-dev/2021-August/152305.html)
it's expected that support for the legacy pass manager will be
dropped either in LLVM 14 or 15.

This switches us to use the new pass manager if LLVM >= 13 is used.
2021-09-25 11:24:23 +02:00
bors
218a96cae0 Auto merge of #89237 - BoxyUwU:trackersMcCaller, r=eddyb
make `#[track_caller]` actually do stuff in `Steal::borrow`

makes this ICE message useful:
``thread 'rustc' panicked at 'attempted to read from stolen value', /rustc/ac2d9fc509e36d1b32513744adf58c34bcc4f43c\compiler\rustc_data_structures\src\steal.rs:37:21``
2021-09-25 07:33:25 +00:00
bors
60fe8b3a65 Auto merge of #87220 - petrochenkov:derivecfglimit2, r=Aaron1011
Make `#[derive(A, B, ...)]` cfg-eval its input only for `A, B, ...` and stabilize `feature(macro_attributes_in_derive_output)`

Stabilization report: https://github.com/rust-lang/rust/pull/87220#issuecomment-881923657

Closes #81119
r? `@Aaron1011`
2021-09-25 04:35:59 +00:00
Takayuki Maeda
4c23905515 use drain_filter instead of filter and retain 2021-09-25 11:33:53 +09:00
bors
6867dd2c01 Auto merge of #89230 - workingjubilee:rollup-1swktdq, r=workingjubilee
Rollup of 8 pull requests

Successful merges:

 - #88893 (Add 1.56.0 release notes)
 - #89001 (Be explicit about using Binder::dummy)
 - #89072 (Avoid a couple of Symbol::as_str calls in cg_llvm )
 - #89104 (Simplify scoped_thread)
 - #89208 ([rfc 2229] Drop fully captured upvars in the same order as the regular drop code)
 - #89210 (Add missing time complexities to linked_list.rs)
 - #89217 (Enable "generate-link-to-definition" option on rust tools docs as well)
 - #89221 (Give better error for `macro_rules! name!`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-09-25 00:20:28 +00:00
Gary Guo
19eaee2c32 Report heap allocation instead of non-const fn for exchange_malloc call 2021-09-25 01:08:41 +01:00
Gary Guo
511333fcc4 Use Rvalue::ShallowInitBox for box expression 2021-09-25 01:08:41 +01:00
Gary Guo
c38da2e0a3 Introduce Rvalue::ShallowInitBox 2021-09-25 01:08:41 +01:00
Ellen
f1e71a5b41 arrr caught ya caller
awd
2021-09-25 00:34:02 +01:00
bors
043972f152 Auto merge of #86246 - FabianWolff:issue-83471, r=estebank
Add basic checks for well-formedness of `fn`/`fn_mut` lang items

This pull request fixes #83471. Lang items are never actually checked for well-formedness (#9307). This means that one can get an ICE quite easily, e.g. as follows:
```rust
#![feature(lang_items)]
#[lang = "fn"]
trait MyFn {
    const call: i32 = 42;
}

fn main() {
    (|| 42)();
}
```
or this:
```rust
#![feature(lang_items)]
#[lang = "fn"]
trait MyFn {
    fn call(i: i32, j: i32);
}

fn main() {
    (|| 42)();
}
```
Ideally, there should probably be a more comprehensive strategy for checking lang items for well-formedness, but for the time being, I have added some rudimentary well-formedness checks that prevent #83471 and similar issues.
2021-09-24 21:30:35 +00:00
Vadim Petrochenkov
85f02901a3 Stabilize feature(macro_attributes_in_derive_output) 2021-09-24 21:48:30 +03:00
Vadim Petrochenkov
92804cd490 derive: Do not configure or clone items unless necessary 2021-09-24 21:45:51 +03:00
Vadim Petrochenkov
c993984e4d builtin_macros: Make #[derive(A, B, ...)] cfg-eval its input only for A, B, ... 2021-09-24 21:45:51 +03:00
Jubilee
6f31fa58fd
Rollup merge of #89221 - aDotInTheVoid:macro-error-1, r=estebank
Give better error for `macro_rules! name!`

r? ``@estebank``

``@rustbot`` modify labels: +A-diagnostics +A-parser
2021-09-24 11:40:17 -07:00
Jubilee
7ade6ed48e
Rollup merge of #89208 - wesleywiser:rfc_2229_droporder, r=nikomatsakis
[rfc 2229] Drop fully captured upvars in the same order as the regular drop code

Currently, with the new 2021 edition, if a closure captures all of the
fields of an upvar, we'll drop those fields in the order they are used
within the closure instead of the normal drop order (the definition
order of the fields in the type).

This changes that so we sort the captured fields by the definition order
which causes them to drop in that same order as well.

Fixes rust-lang/project-rfc-2229#42

r? `@nikomatsakis`
2021-09-24 11:40:14 -07:00
Jubilee
80d9886e4c
Rollup merge of #89104 - Mark-Simulacrum:spawn-unchecked, r=nagisa,bjorn3
Simplify scoped_thread

Avoids a bunch of manual pointer manipulation in favor of using the appropriate std API.
2021-09-24 11:40:13 -07:00
Jubilee
8a454f8101
Rollup merge of #89072 - bjorn3:less_symbol_as_str, r=michaelwoerister
Avoid a couple of Symbol::as_str calls in cg_llvm

This should improve performance a tiny bit. Also remove `Symbol::len` and make `SymbolIndex` private.
2021-09-24 11:40:12 -07:00
Jubilee
ee2e97c416
Rollup merge of #89001 - jackh726:binder-cleanup, r=nikomatsakis
Be explicit about using Binder::dummy

This is somewhat of a late followup to the binder refactor PR. It removes `ToPredicate` and `ToPolyTraitImpls` that hide the use of `Binder::dummy`. While this does make code a bit more verbose, it allows us be more careful about where we create binders.

Another alternative here might be to add a new trait `ToBinder` or something with a `dummy()` fn. Which could still allow grepping but allows doing something like `trait_ref.dummy()` (but I also wonder if longer-term, it would be better to be even more explicit with a `bind_with_vars(ty::List::empty())` *but* that's not clear yet.

r? ``@nikomatsakis``
2021-09-24 11:40:11 -07:00
Fabian Wolff
cb6c13977a Make error message for malformed fn/fn_mut lang item more specific 2021-09-24 20:15:19 +02:00
Fabian Wolff
4337089098 Add basic checks for well-formedness of fn/fn_mut lang items 2021-09-24 18:26:27 +02:00
Vadim Petrochenkov
ab834e5ea9 resolve: Refactor obtaining Module from its DefId
The `Option<Module>` version is supported for the case where we don't know whether the `DefId` refers to a module or not.
Non-local traits and enums are also correctly found now.
2021-09-24 18:57:15 +03:00
Vadim Petrochenkov
a8021888c8 resolve: Use a single common map for local and foreign modules 2021-09-24 18:57:15 +03:00
Vadim Petrochenkov
1a23858983 resolve: Rename some expansion def scope methods 2021-09-24 18:57:15 +03:00
Vadim Petrochenkov
6e9adcbd82 resolve: Cleanup module allocation
Construction of all modules is now centralized and performed by `fn new_module`.
2021-09-24 18:57:15 +03:00
Vadim Petrochenkov
fd58eea4e1 resolve: Do not cache nearest parent mod in ModuleData 2021-09-24 18:57:14 +03:00
Takayuki Maeda
353d6373ff change the order of path suggestions 2021-09-25 00:22:59 +09:00
Nixon Enraght-Moony
ed3b751799 Give better error for macro_rules! name! 2021-09-24 16:21:34 +01:00
bors
a0648eab36 Auto merge of #88835 - FabianWolff:issue-88770, r=petrochenkov
Fix error recovery in format macro parsing

Fixes #88770. Basically, the assumption in the following comment is incorrect:
b69fe57261/compiler/rustc_builtin_macros/src/format.rs (L167-L172)

This is only true in the first iteration of the loop, when [`p.clear_expected_tokens()`](b69fe57261/compiler/rustc_builtin_macros/src/format.rs (L164)) is called. In subsequent iterations, `p.expected_tokens` won't be empty, so `p.expect()` won't actually call `unexpected_try_recover()`:
b69fe57261/compiler/rustc_parse/src/parser/mod.rs (L487-L498)

Instead, it will call `expect_one_of()`, which _can_ recover and return `Ok()`. This PR handles this case to fix the ICE in #88770.
2021-09-24 11:54:29 +00:00
r00ster91
956f87fb04 consistent big O notation 2021-09-24 12:44:28 +02:00
bors
197fc8591e Auto merge of #89120 - In-line:remove_unneded_visible_parents_map, r=estebank
Disable visible path calculation for PrettyPrinter in Ok path of compiler
2021-09-24 05:29:49 +00:00