about summary refs log tree commit diff
path: root/compiler
AgeCommit message (Collapse)AuthorLines
2021-09-26Cleanup the reporting of unreachable patternsNadrieril-20/+14
2021-09-26Always report reachability for user-supplied patternsNadrieril-8/+3
2021-09-26Remove some unreachable codeNadrieril-20/+11
2021-09-26Remove premature shortcuttingNadrieril-26/+12
2021-09-25Fix incorrect disambiguation suggestion for associated itemsFabian Wolff-1/+9
2021-09-25Don't anonymize bound region names during typeckAaron Hill-1/+27
Once this anonymization has performed, we have no way of recovering the original names during NLL borrow checking. Keeping the original names allows error messages in full NLL mode to contain the original bound region names. As a result, the typeck results may contain types that differ only in the names used for their bound regions. However, anonimization of bound regions does not guarantee that all distinct types are unqual (e.g. not subtypes of each other). For example, `for<'a> fn(&'a u32, &'a u32)` and `for<'b, 'c> fn(&'b u32, &'c u32)` are subtypes of each other, as explained here: https://github.com/rust-lang/rust/blob/63cc2bb3d07d6c726dfcdc5f95cbe5ed4760641a/compiler/rustc_infer/src/infer/nll_relate/mod.rs#L682-L690 Therefore, any code handling types with higher-ranked regions already needs to handle the case where two distinct `Ty`s are 'actually' equal.
2021-09-25Check for macros in built-in attributes that don't support them.Eric Huss-8/+73
2021-09-25Move malformed attribute code to a function and fix inner attribute suggestion.Eric Huss-59/+60
Moving to a dedicated function in preparation for other validation. The suggestion given didn't consider if it was an inner attribute.
2021-09-25Use larger span for adjustments on method callsAaron Hill-2/+27
Currently, we use a relatively 'small' span for THIR expressions generated by an 'adjustment' (e.g. an autoderef, autoborrow, unsizing). As a result, if a borrow generated by an adustment ends up causing a borrowcheck error, for example: ```rust let mut my_var = String::new(); let my_ref = &my_var my_var.push('a'); my_ref; ``` then the span for the mutable borrow may end up referring to only the base expression (e.g. `my_var`), rather than the method call which triggered the mutable borrow (e.g. `my_var.push('a')`) Due to a quirk of the MIR borrowck implementation, this doesn't always get exposed in migration mode, but it does in many cases. This commit makes THIR building consistently use 'larger' spans for adjustment expressions The intent of this change it make it clearer to users when it's the specific way in which a variable is used (for example, in a method call) that produdes a borrowcheck error. For example, an error message claiming that a 'mutable borrow occurs here' might be confusing if it just points at a usage of a variable (e.g. `my_var`), when no `&mut` is in sight. Pointing at the entire expression should help to emphasize that the method call itself is responsible for the mutable borrow. In several cases, this makes the `#![feature(nll)]` diagnostic output match up exactly with the default (migration mode) output. As a result, several `.nll.stderr` files end up getting removed entirely.
2021-09-25Auto merge of #88243 - nikic:newpm-2, r=nagisabors-3/+7
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-25Auto merge of #89030 - nbdd0121:box2, r=jonas-schievinkbors-13/+125
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-25Use correct pipeline for LTO at O0Nikita Popov-1/+4
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-25Enable new pass manager on LLVM 13Nikita Popov-2/+3
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-25Auto merge of #89237 - BoxyUwU:trackersMcCaller, r=eddybbors-4/+5
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-25Auto merge of #87220 - petrochenkov:derivecfglimit2, r=Aaron1011bors-57/+49
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-25use `drain_filter` instead of `filter` and `retain`Takayuki Maeda-4/+2
2021-09-25Auto merge of #89230 - workingjubilee:rollup-1swktdq, r=workingjubileebors-148/+221
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-25Report heap allocation instead of non-const fn for exchange_malloc callGary Guo-0/+5
2021-09-25Use Rvalue::ShallowInitBox for box expressionGary Guo-2/+53
2021-09-25Introduce `Rvalue::ShallowInitBox`Gary Guo-11/+67
2021-09-25arrr caught ya callerEllen-4/+5
awd
2021-09-24Auto merge of #86246 - FabianWolff:issue-83471, r=estebankbors-6/+65
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-24Hide `<...> defined here` note if the source is not availableFabian Wolff-1/+5
2021-09-24Stabilize `feature(macro_attributes_in_derive_output)`Vadim Petrochenkov-35/+2
2021-09-24derive: Do not configure or clone items unless necessaryVadim Petrochenkov-22/+47
2021-09-24builtin_macros: Make #[derive(A, B, ...)] cfg-eval its input only for `A, B, ↵Vadim Petrochenkov-2/+2
...`
2021-09-24Rollup merge of #89221 - aDotInTheVoid:macro-error-1, r=estebankJubilee-0/+14
Give better error for `macro_rules! name!` r? ``@estebank`` ``@rustbot`` modify labels: +A-diagnostics +A-parser
2021-09-24Rollup merge of #89208 - wesleywiser:rfc_2229_droporder, r=nikomatsakisJubilee-1/+72
[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-24Rollup merge of #89104 - Mark-Simulacrum:spawn-unchecked, r=nagisa,bjorn3Jubilee-19/+6
Simplify scoped_thread Avoids a bunch of manual pointer manipulation in favor of using the appropriate std API.
2021-09-24Rollup merge of #89072 - bjorn3:less_symbol_as_str, r=michaelwoeristerJubilee-12/+11
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-24Rollup merge of #89001 - jackh726:binder-cleanup, r=nikomatsakisJubilee-116/+118
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-24Make error message for malformed `fn`/`fn_mut` lang item more specificFabian Wolff-11/+30
2021-09-24Add basic checks for well-formedness of `fn`/`fn_mut` lang itemsFabian Wolff-6/+46
2021-09-24resolve: Refactor obtaining `Module` from its `DefId`Vadim Petrochenkov-77/+75
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-24resolve: Use a single common map for local and foreign modulesVadim Petrochenkov-20/+13
2021-09-24resolve: Rename some expansion def scope methodsVadim Petrochenkov-23/+19
2021-09-24resolve: Cleanup module allocationVadim Petrochenkov-56/+73
Construction of all modules is now centralized and performed by `fn new_module`.
2021-09-24resolve: Do not cache nearest parent mod in `ModuleData`Vadim Petrochenkov-57/+36
2021-09-25change the order of path suggestionsTakayuki Maeda-0/+6
2021-09-24Give better error for `macro_rules! name!`Nixon Enraght-Moony-0/+14
2021-09-24Auto merge of #88835 - FabianWolff:issue-88770, r=petrochenkovbors-18/+17
Fix error recovery in format macro parsing Fixes #88770. Basically, the assumption in the following comment is incorrect: https://github.com/rust-lang/rust/blob/b69fe57261086e70aea9d5b58819a1794bf7c121/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()`](https://github.com/rust-lang/rust/blob/b69fe57261086e70aea9d5b58819a1794bf7c121/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()`: https://github.com/rust-lang/rust/blob/b69fe57261086e70aea9d5b58819a1794bf7c121/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-24consistent big O notationr00ster91-2/+2
2021-09-24Auto merge of #89120 - In-line:remove_unneded_visible_parents_map, r=estebankbors-14/+38
Disable visible path calculation for PrettyPrinter in Ok path of compiler
2021-09-23Fix tidy and respond to some feedbackWesley Wiser-1/+32
2021-09-24Auto merge of #89211 - workingjubilee:rollup-fj4eduk, r=workingjubileebors-3/+36
Rollup of 7 pull requests Successful merges: - #88612 (Add a better error message for #39364) - #89023 (Resolve issue : Somewhat confusing error with extended_key_value_attributes) - #89148 (Suggest `_` in turbofish if param will be inferred from fn argument) - #89171 (Run `no_core` rustdoc tests only on Linux) - #89176 (Change singular to plural) - #89184 (Temporarily rename int_roundings functions to avoid conflicts) - #89200 (Fix typo) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2021-09-23Rollup merge of #89200 - hkmatsumoto:patch, r=workingjubileeJubilee-1/+1
Fix typo
2021-09-23Rollup merge of #89176 - TaKO8Ki:change-singular-to-plural, r=lcnrJubilee-1/+1
Change singular to plural
2021-09-23Rollup merge of #89148 - estebank:used-type-param, r=oli-obkJubilee-1/+20
Suggest `_` in turbofish if param will be inferred from fn argument
2021-09-23Rollup merge of #89023 - Wardenfar:issue-85066, r=nagisaJubilee-0/+14
Resolve issue : Somewhat confusing error with extended_key_value_attributes Fixes #85066
2021-09-23Auto merge of #88804 - Mark-Simulacrum:never-algo-v2, r=nikomatsakis,jackh726bors-138/+508
Revise never type fallback algorithm This is a rebase of https://github.com/rust-lang/rust/pull/84573, but dropping the stabilization of never type (and the accompanying large test diff). Each commit builds & has tests updated alongside it, and could be reviewed in a more or less standalone fashion. But it may make more sense to review the PR as a whole, I'm not sure. It should be noted that tests being updated isn't really a good indicator of final behavior -- never_type_fallback is not enabled by default in this PR, so we can't really see the full effects of the commits here. This combines the work by Niko, which is [documented in this gist](https://gist.github.com/nikomatsakis/7a07b265dc12f5c3b3bd0422018fa660), with some additional rules largely derived to target specific known patterns that regress with the algorithm solely derived by Niko. We build these from an intuition that: * In general, fallback to `()` is *sound* in all cases * But, in general, we *prefer* fallback to `!` as it accepts more code, particularly that written to intentionally use `!` (e.g., Result's with a Infallible/! variant). When evaluating Niko's proposed algorithm, we find that there are certain cases where fallback to `!` leads to compilation failures in real-world code, and fallback to `()` fixes those errors. In order to allow for stabilization, we need to fix a good portion of these patterns. The final rule set this PR proposes is that, by default, we fallback from `?T` to `!`, with the following exceptions: 1. `?T: Foo` and `Bar::Baz = ?T` and `(): Foo`, then fallback to `()` 2. Per [Niko's algorithm](https://gist.github.com/nikomatsakis/7a07b265dc12f5c3b3bd0422018fa660#proposal-fallback-chooses-between--and--based-on-the-coercion-graph), the "live" `?T` also fallback to `()`. The first rule is necessary to address a fairly common pattern which boils down to something like the snippet below. Without rule 1, we do not see the closure's return type as needing a () fallback, which leads to compilation failure. ```rust #![feature(never_type_fallback)] trait Bar { } impl Bar for () { } impl Bar for u32 { } fn foo<R: Bar>(_: impl Fn() -> R) {} fn main() { foo(|| panic!()); } ``` r? `@jackh726`