about summary refs log tree commit diff
path: root/compiler
AgeCommit message (Collapse)AuthorLines
2024-04-27Rollup merge of #124382 - petrochenkov:itemvisit, r=lcnrMatthias Krüger-336/+364
ast: Generalize item kind visiting And avoid duplicating logic for visiting `Item`s with different kinds (regular, associated, foreign). The diff is better viewed with whitespace ignored.
2024-04-26Rollup merge of #124391 - nnethercote:builtin_macros-cleanups, r=fee1-deadJacob Pratt-341/+352
`rustc_builtin_macros` cleanups Some improvements I found while looking over this code. r? ``@fee1-dead``
2024-04-26Rollup merge of #124341 - petrochenkov:nomacvisit, r=compiler-errorsJacob Pratt-12/+3
resolve: Remove two cases of misleading macro call visiting Macro calls are ephemeral, they should not add anything to the definition tree, even if their AST could contains something with identity. Thankfully, macro call AST cannot contain anything like that, so these walks are just noops. In majority of other places in def_collector / build_reduced_graph they are already not visited. (Also, a minor match reformatting is included.)
2024-04-26Auto merge of #122385 - lcnr:analyze-obligations-for-infer, r=compiler-errorsbors-321/+589
`obligations_for_self_ty`: use `ProofTreeVisitor` for nested goals As always, dealing with proof trees continues to be a hacked together mess. After this PR and #124380 the only remaining blocker for core is https://github.com/rust-lang/trait-system-refactor-initiative/issues/90. There is also a `ProofTreeVisitor` issue causing an ICE when compiling `alloc` which I will handle in a separate PR. This issue likely affects coherence diagnostics more generally. The core idea is to extend the proof tree visitor to support visiting nested candidates without using a `probe`. We then simply recurse into nested candidates if they are the only potentially applicable candidate for a given goal and check whether the self type matches the expected one. For that to work, we need to improve `CanonicalState` to also handle unconstrained inference variables created inside of the trait solver. This is done by extending the `var_values` of `CanoncalState` with each fresh inference variables. Furthermore, we also store the state of all inference variables at the end of each probe. When recursing into `InspectCandidates` we then unify the values of all these states. r? `@compiler-errors`
2024-04-26Adjust some `pub`s.Nicholas Nethercote-81/+81
2024-04-26Auto merge of #120845 - petrochenkov:debmac, r=oli-obkbors-122/+78
debuginfo: Stabilize `-Z debug-macros`, `-Z collapse-macro-debuginfo` and `#[collapse_debuginfo]` `-Z debug-macros` is "stabilized" by enabling it by default and removing. `-Z collapse-macro-debuginfo` is stabilized as `-C collapse-macro-debuginfo`. It now supports all typical boolean values (`parse_opt_bool`) in addition to just yes/no. Default value of `collapse_debuginfo` was changed from `false` to `external` (i.e. collapsed if external, not collapsed if local) - https://github.com/rust-lang/rust/issues/100758#issuecomment-1935815625 describes some debugging scenarios that motivate this default as reasonable. `#[collapse_debuginfo]` attribute without a value is no longer supported to avoid guessing the default. Stabilization report: https://github.com/rust-lang/rust/pull/120845#issuecomment-1939145242 Closes https://github.com/rust-lang/rust/issues/100758 Closes https://github.com/rust-lang/rust/issues/41743 Closes https://github.com/rust-lang/rust/issues/39153
2024-04-25Rollup merge of #124381 - compiler-errors:derived-for-wf, r=lcnrMichael Goulet-6/+11
Renamed `DerivedObligation` to `WellFormedDeriveObligation` It's used when computing `WellFormed` obligations, so let's give it a less ambiguous name.
2024-04-25Rollup merge of #124379 - compiler-errors:remove-new-solver-lookup-behavior, ↵Michael Goulet-63/+18
r=lcnr Remove special-casing for `SimplifiedType` for next solver It's unnecessary due to the way that we fully normalize the self type before assembly begins. r? lcnr
2024-04-26Move some functions from `rustc_expand` to `rustc_builtin_macros`.Nicholas Nethercote-237/+234
These functions are only used in `rustc_builtin_macros`, so it makes sense for them to live there. This allows them to be changed from `pub` to `pub(crate)`.
2024-04-26Introduce `DeriveResolution`.Nicholas Nethercote-20/+32
Making this a proper struct, and giving its fields names, makes things easier to understand.
2024-04-25Renamed DerivedObligation to WellFormedDeriveObligationMichael Goulet-6/+11
2024-04-25Auto merge of #124386 - matthiaskrgr:rollup-0a6yr00, r=matthiaskrgrbors-30/+109
Rollup of 3 pull requests Successful merges: - #124313 (Detect borrow error involving sub-slices and suggest `split_at_mut`) - #124374 (Don't ICE when `codegen_select_candidate` returns ambiguity in new solver) - #124380 (`Range` iteration specialization: remove trivial bounds) r? `@ghost` `@rustbot` modify labels: rollup
2024-04-25use `EagerResolver`lcnr-1/+3
2024-04-25ast: Visit item components in "natural" orderVadim Petrochenkov-4/+4
2024-04-25ast: Generalize item kind visitingVadim Petrochenkov-333/+361
And avoid duplicating logic for visiting `Item`s with different kinds (regular, associated, foreign).
2024-04-25hir typeck: look into nested goalslcnr-288/+548
uses a `ProofTreeVisitor` to look into nested goals when looking at the pending obligations during hir typeck. Used by closure signature inference, coercion, and for async functions.
2024-04-25debuginfo: Stabilize `-Z debug-macros`, `-Z collapse-macro-debuginfo` and ↵Vadim Petrochenkov-122/+78
`#[collapse_debuginfo]` `-Z debug-macros` is "stabilized" by enabling it by default and removing. `-Z collapse-macro-debuginfo` is stabilized as `-C collapse-macro-debuginfo`. It now supports all typical boolean values (`parse_opt_bool`) in addition to just yes/no. Default value of `collapse_debuginfo` was changed from `false` to `external` (i.e. collapsed if external, not collapsed if local). `#[collapse_debuginfo]` attribute without a value is no longer supported to avoid guessing the default.
2024-04-25Rollup merge of #124374 - compiler-errors:fix-ambiguity-ice, r=lcnrMatthias Krüger-12/+5
Don't ICE when `codegen_select_candidate` returns ambiguity in new solver Because we merge identical candidates, we may have >1 impl candidate to in `codegen_select_error` but *not* have a trait error. r? lcnr
2024-04-25Rollup merge of #124313 - estebank:split-at-mut, r=fee1-deadMatthias Krüger-18/+104
Detect borrow error involving sub-slices and suggest `split_at_mut` ``` error[E0499]: cannot borrow `foo` as mutable more than once at a time --> $DIR/suggest-split-at-mut.rs:13:18 | LL | let a = &mut foo[..2]; | --- first mutable borrow occurs here LL | let b = &mut foo[2..]; | ^^^ second mutable borrow occurs here LL | a[0] = 5; | ---- first borrow later used here | = help: use `.split_at_mut(position)` or similar method to obtain two mutable non-overlapping sub-slices ``` Address most of #58792. For follow up work, we should emit a structured suggestion for cases where we can identify the exact `let (a, b) = foo.split_at_mut(2);` call that is needed.
2024-04-25Remove special-casing for SimplifiedType for next solverMichael Goulet-63/+18
2024-04-25review comment: rename methodEsteban Küber-5/+8
2024-04-25Auto merge of #124377 - matthiaskrgr:rollup-ajxjq35, r=matthiaskrgrbors-7/+7
Rollup of 2 pull requests Successful merges: - #124287 (Improved code with clippy) - #124326 (tests: remove few ignore-stage2) r? `@ghost` `@rustbot` modify labels: rollup
2024-04-25Rollup merge of #124287 - 41Leahcim:master, r=fmeaseMatthias Krüger-7/+7
Improved code with clippy I haven't used the bootstrapped compiler, but I think I have made some improvements using clippy. I have already made the following changes to the compiler: Replaced `self.first().is_digit(10)` with `self.first().is_ascii_digit()` on lines 633, 664, and 680 of compiler/rust_lexer/src/lib.rs. Removed unnecessary cast on line 262 of compiler/rustc_lexer/src/unescape.rs Replaced ok_or_else with ok_or on line 303 of compiler/rustc_lexer/src/unescape.rs Replaced `!std::env::var("RUSTC_BOOTSTRAP").is_ok()` with `std::env::var("RUSTC_BOOTSTRAP").is_err()` on line 4 of compiler/rustc_macros/build.rs Removed needless borrow for generic argument `env`on line 53 of compiler/rust_llvm/build.rs
2024-04-25Check equivalence of indices in more casesEsteban Küber-1/+7
2024-04-25Don't suggest `split_at_mut` when the multiple borrows have the same indexEsteban Küber-2/+41
2024-04-25Mention `split_at_mut` when mixing mutability in indexing opsEsteban Küber-2/+17
Emit suggestion when encountering ```rust let a = &mut foo[0]; let b = &foo[1]; a.use_mut(); ```
2024-04-25Only suggest `split_at_mut` on indexing borrowck errors for std typesEsteban Küber-8/+22
2024-04-25Detect borrow error involving sub-slices and suggest `split_at_mut`Esteban Küber-16/+25
``` error[E0499]: cannot borrow `foo` as mutable more than once at a time --> $DIR/suggest-split-at-mut.rs:13:18 | LL | let a = &mut foo[..2]; | --- first mutable borrow occurs here LL | let b = &mut foo[2..]; | ^^^ second mutable borrow occurs here LL | a[0] = 5; | ---- first borrow later used here | = help: use `.split_at_mut(position)` or similar method to obtain two mutable non-overlapping sub-slices ``` Address most of #58792. For follow up work, we should emit a structured suggestion for cases where we can identify the exact `let (a, b) = foo.split_at_mut(2);` call that is needed.
2024-04-25Don't ICE when codegen_select returns ambiguity in new solverMichael Goulet-12/+5
2024-04-25`pub(in super::super)` to `pub(crate)`lcnr-21/+21
`super::super` of `rustc_hir_typeck::fn_ctxt::_impl` is just `rustc_hir_typeck`.
2024-04-25`obligations_for_self_ty` to sub modulelcnr-59/+65
2024-04-25Auto merge of #123531 - compiler-errors:closure-wf, r=oli-obkbors-3/+22
Enforce closure args + return type are WF I found this out when investigating https://github.com/rust-lang/rust/issues/123461#issuecomment-2040894359. Turns out we don't register WF obligations for closure args and return types, leading to the ICE. ~~I think this is a useful thing to check for, but I'd like to check what the fallout is.~~ crater is complete. ~~Worst case, I think we should enforce this across an edition boundary (and possibly eventually migrate this for all editions) -- this should be super easy to do, since this is a check in HIR wfcheck, so it can be made edition dependent.~~ I believe the regressions are manageable enough to not necessitate edition-specific behavior. Fixes #123461
2024-04-25Check closure args and returns are WFMichael Goulet-1/+20
2024-04-25Format stash message correctlyMichael Goulet-2/+2
2024-04-25Auto merge of #124058 - TechVest:master, r=fmeasebors-1/+1
Fix some typos in comments
2024-04-25Auto merge of #119650 - chenyukang:yukang-fix-118596-ref-mut, r=wesleywiserbors-1/+16
Suggest ref mut for pattern matching assignment Fixes #118596
2024-04-25Auto merge of #124360 - matthiaskrgr:rollup-k6bffhd, r=matthiaskrgrbors-90/+79
Rollup of 3 pull requests Successful merges: - #124257 (Rewrite the `no-input-file.stderr` test in Rust and support diff) - #124324 (Minor AST cleanups) - #124327 (CI: implement job skipping in Python matrix calculation) r? `@ghost` `@rustbot` modify labels: rollup
2024-04-25Name the field in `Expander`.Nicholas Nethercote-4/+6
For code clarity.
2024-04-25Auto merge of #121298 - nikic:writable, r=cuviperbors-0/+27
Set writable and dead_on_unwind attributes for sret arguments Set the `writable` and `dead_on_unwind` attributes for `sret` arguments. This allows call slot optimization to remove more memcpy's. See https://llvm.org/docs/LangRef.html#parameter-attributes for the specification of these attributes. In short, the statement we're making here is that: * The return slot is writable. * The return slot will not be read if the function unwinds. Fixes https://github.com/rust-lang/rust/issues/90595.
2024-04-25Rollup merge of #124324 - nnethercote:minor-ast-cleanups, r=estebankMatthias Krüger-90/+79
Minor AST cleanups r? ``@estebank``
2024-04-25Fix some typos in commentsTechVest-1/+1
Signed-off-by: TechVest <techdashen@qq.com>
2024-04-25Set writable and dead_on_unwind attributes for sret argumentsNikita Popov-0/+27
2024-04-25Auto merge of #124136 - estebank:clone-o-rama-2, r=nnethercotebors-26/+213
Provide more context and suggestions in borrowck errors involving closures Start pointing to where bindings where declared when they are captured in closures: ``` error[E0597]: `x` does not live long enough --> $DIR/suggest-return-closure.rs:23:9 | LL | let x = String::new(); | - binding `x` declared here ... LL | |c| { | --- value captured here LL | x.push(c); | ^ borrowed value does not live long enough ... LL | } | -- borrow later used here | | | `x` dropped here while still borrowed ``` Suggest cloning in more cases involving closures: ``` error[E0507]: cannot move out of `foo` in pattern guard --> $DIR/issue-27282-move-ref-mut-into-guard.rs:11:19 | LL | if { (|| { let mut bar = foo; bar.take() })(); false } => {}, | ^^ --- move occurs because `foo` has type `&mut Option<&i32>`, which does not implement the `Copy` trait | | | `foo` is moved here | = note: variables bound in patterns cannot be moved from until after the end of the pattern guard help: consider cloning the value if the performance cost is acceptable | LL | if { (|| { let mut bar = foo.clone(); bar.take() })(); false } => {}, | ++++++++ ``` Mention when type parameter could be Clone ``` error[E0382]: use of moved value: `t` --> $DIR/use_of_moved_value_copy_suggestions.rs:7:9 | LL | fn duplicate_t<T>(t: T) -> (T, T) { | - move occurs because `t` has type `T`, which does not implement the `Copy` trait ... LL | (t, t) | - ^ value used here after move | | | value moved here | help: if `T` implemented `Clone`, you could clone the value --> $DIR/use_of_moved_value_copy_suggestions.rs:4:16 | LL | fn duplicate_t<T>(t: T) -> (T, T) { | ^ consider constraining this type parameter with `Clone` ... LL | (t, t) | - you could clone this value help: consider restricting type parameter `T` | LL | fn duplicate_t<T: Copy>(t: T) -> (T, T) { | ++++++ ``` The `help` is new. On ADTs, we also extend the output with span labels: ``` error[E0507]: cannot move out of static item `FOO` --> $DIR/issue-17718-static-move.rs:6:14 | LL | let _a = FOO; | ^^^ move occurs because `FOO` has type `Foo`, which does not implement the `Copy` trait | note: if `Foo` implemented `Clone`, you could clone the value --> $DIR/issue-17718-static-move.rs:1:1 | LL | struct Foo; | ^^^^^^^^^^ consider implementing `Clone` for this type ... LL | let _a = FOO; | --- you could clone this value help: consider borrowing here | LL | let _a = &FOO; | + ``` Suggest cloning captured binding in move closure ``` error[E0507]: cannot move out of `bar`, a captured variable in an `FnMut` closure --> $DIR/borrowck-move-by-capture.rs:9:29 | LL | let bar: Box<_> = Box::new(3); | --- captured outer variable LL | let _g = to_fn_mut(|| { | -- captured by this `FnMut` closure LL | let _h = to_fn_once(move || -> isize { *bar }); | ^^^^^^^^^^^^^^^^ ---- | | | | | variable moved due to use in closure | | move occurs because `bar` has type `Box<isize>`, which does not implement the `Copy` trait | `bar` is moved here | help: clone the value before moving it into the closure 1 | LL ~ let value = bar.clone(); LL ~ let _h = to_fn_once(move || -> isize { value }); | ```
2024-04-25Add comments about attribute tokens.Nicholas Nethercote-0/+2
This clarifies something that has puzzled me for some time.
2024-04-24Suggest cloning captured binding in `move` closureEsteban Küber-9/+146
``` error[E0507]: cannot move out of `bar`, a captured variable in an `FnMut` closure --> $DIR/borrowck-move-by-capture.rs:9:29 | LL | let bar: Box<_> = Box::new(3); | --- captured outer variable LL | let _g = to_fn_mut(|| { | -- captured by this `FnMut` closure LL | let _h = to_fn_once(move || -> isize { *bar }); | ^^^^^^^^^^^^^^^^ ---- | | | | | variable moved due to use in closure | | move occurs because `bar` has type `Box<isize>`, which does not implement the `Copy` trait | `bar` is moved here | help: clone the value before moving it into the closure | LL ~ let value = bar.clone(); LL ~ let _h = to_fn_once(move || -> isize { value }); | ```
2024-04-24Mention when type parameter could be `Clone`Esteban Küber-8/+51
``` error[E0382]: use of moved value: `t` --> $DIR/use_of_moved_value_copy_suggestions.rs:7:9 | LL | fn duplicate_t<T>(t: T) -> (T, T) { | - move occurs because `t` has type `T`, which does not implement the `Copy` trait ... LL | (t, t) | - ^ value used here after move | | | value moved here | help: if `T` implemented `Clone`, you could clone the value --> $DIR/use_of_moved_value_copy_suggestions.rs:4:16 | LL | fn duplicate_t<T>(t: T) -> (T, T) { | ^ consider constraining this type parameter with `Clone` ... LL | (t, t) | - you could clone this value help: consider restricting type parameter `T` | LL | fn duplicate_t<T: Copy>(t: T) -> (T, T) { | ++++++ ``` The `help` is new. On ADTs, we also extend the output with span labels: ``` error[E0507]: cannot move out of static item `FOO` --> $DIR/issue-17718-static-move.rs:6:14 | LL | let _a = FOO; | ^^^ move occurs because `FOO` has type `Foo`, which does not implement the `Copy` trait | note: if `Foo` implemented `Clone`, you could clone the value --> $DIR/issue-17718-static-move.rs:1:1 | LL | struct Foo; | ^^^^^^^^^^ consider implementing `Clone` for this type ... LL | let _a = FOO; | --- you could clone this value help: consider borrowing here | LL | let _a = &FOO; | + ```
2024-04-24Modify `find_expr` from `Span` to better account for closuresEsteban Küber-10/+17
Start pointing to where bindings were declared when they are captured in closures: ``` error[E0597]: `x` does not live long enough --> $DIR/suggest-return-closure.rs:23:9 | LL | let x = String::new(); | - binding `x` declared here ... LL | |c| { | --- value captured here LL | x.push(c); | ^ borrowed value does not live long enough ... LL | } | -- borrow later used here | | | `x` dropped here while still borrowed ``` Suggest cloning in more cases involving closures: ``` error[E0507]: cannot move out of `foo` in pattern guard --> $DIR/issue-27282-move-ref-mut-into-guard.rs:11:19 | LL | if { (|| { let mut bar = foo; bar.take() })(); false } => {}, | ^^ --- move occurs because `foo` has type `&mut Option<&i32>`, which does not implement the `Copy` trait | | | `foo` is moved here | = note: variables bound in patterns cannot be moved from until after the end of the pattern guard help: consider cloning the value if the performance cost is acceptable | LL | if { (|| { let mut bar = foo.clone(); bar.take() })(); false } => {}, | ++++++++ ```
2024-04-25Rollup merge of #124335 - ChrisDenton:stabilize-absolute, r=dtolnayMatthias Krüger-2/+0
Stabilize `std::path::absolute` FCP complete in https://github.com/rust-lang/rust/issues/92750#issuecomment-2075046985
2024-04-25Rollup merge of #124333 - Urgau:better-bad-print, r=fmeaseMatthias Krüger-3/+6
Improve diagnostic for unknown `--print` request This PR improves the diagnostic when encountering a unknown `--print` request. It also moves the run-make test to a simple UI test.
2024-04-25Rollup merge of #124322 - whosehang:master, r=NilstriebMatthias Krüger-2/+2
chore: fix some typos in comments