about summary refs log tree commit diff
path: root/compiler/rustc_resolve/src
AgeCommit message (Collapse)AuthorLines
2024-09-18Rollup merge of #130116 - veera-sivarajan:freeze-suggestions, r=chenyukangMatthias Krüger-11/+17
Implement a Method to Seal `DiagInner`'s Suggestions This PR adds a method on `DiagInner` called `.seal_suggestions()` to prevent new suggestions from being added while preserving existing suggestions. This is useful because currently there is no way to prevent new suggestions from being added to a diagnostic. `.disable_suggestions()` is the closest but it gets rid of all suggestions before and after the call. Therefore, `.seal_suggestions()` can be used when, for example, misspelled keyword is detected and reported. In such cases, we may want to prevent other suggestions from being added to the diagnostic, as they would likely be meaningless once the misspelled keyword is identified. For context: https://github.com/rust-lang/rust/pull/129899#discussion_r1741307132 To store an additional state, the type of the `suggestions` field in `DiagInner` was changed into a three variant enum. While this change affects files across different crates, care was taken to preserve the existing code's semantics. This is validated by the fact that all UI tests pass without any modifications. r? chenyukang
2024-09-16Rollup merge of #130033 - compiler-errors:foreign-fn-types, r=BoxyUwUMatthias Krüger-24/+25
Don't call `fn_arg_names` query for non-`fn` foreign items in resolver Fixes #130015
2024-09-16Introduce distinct error codes for precise capturingMichael Goulet-3/+4
2024-09-16Do precise capturing arg validation in resolveMichael Goulet-9/+46
2024-09-12Implement a Method to Seal `DiagInner`'s SuggestionsVeera-11/+17
2024-09-13Auto merge of #129137 - camelid:lazy-def-macro-const, r=BoxyUwUbors-50/+114
Fix anon const def-creation when macros are involved Fixes #128016. Ever since #125915, some `ast::AnonConst`s turn into `hir::ConstArgKind::Path`s, which don't have associated `DefId`s. To deal with the fact that we don't have resolution information in `DefCollector`, we decided to implement a process where if the anon const *appeared* to be trivial (i.e., `N` or `{ N }`), we would avoid creating a def for it in `DefCollector`. If later, in AST lowering, we realized it turned out to be a unit struct literal, or we were lowering it to something that didn't use `hir::ConstArg`, we'd create its def there. However, let's say we have a macro `m!()` that expands to a reference to a free constant `FOO`. If we use `m!()` in the body of an anon const (e.g., `Foo<{ m!() }>`), then in def collection, it appears to be a nontrivial anon const and we create a def. But the macro expands to something that looks like a trivial const arg, but is not, so in AST lowering we "fix" the mistake we assumed def collection made and create a def for it. This causes a duplicate definition ICE. The long-term fix for this is to delay the creation of defs for all expression-like nodes until AST lowering (see #128844 for an incomplete attempt at this). This would avoid issues like this one that are caused by hacky workarounds. However, doing this uncovers a pre-existing bug with opaque types that is quite involved to fix (see #129023). In the meantime, this PR fixes the bug by delaying def creation for anon consts whose bodies are macro invocations until after we expand the macro and know what is inside it. This is accomplished by adding information to create the anon const's def to the data in `Resolver.invocation_parents`. r? `@BoxyUwU`
2024-09-12Re-enable `ConstArgKind::Path` lowering by defaultNoah Lev-16/+14
...and remove the `const_arg_path` feature gate as a result. It was only a stopgap measure to fix the regression that the new lowering introduced (which should now be fixed by this PR).
2024-09-12Fix anon const def-creation when macros are involvedNoah Lev-44/+110
Ever since #125915, some `ast::AnonConst`s turn into `hir::ConstArgKind::Path`s, which don't have associated `DefId`s. To deal with the fact that we don't have resolution information in `DefCollector`, we decided to implement a process where if the anon const *appeared* to be trivial (i.e., `N` or `{ N }`), we would avoid creating a def for it in `DefCollector`. If later, in AST lowering, we realized it turned out to be a unit struct literal, or we were lowering it to something that didn't use `hir::ConstArg`, we'd create its def there. However, let's say we have a macro `m!()` that expands to a reference to a free constant `FOO`. If we use `m!()` in the body of an anon const (e.g., `Foo<{ m!() }>`), then in def collection, it appears to be a nontrivial anon const and we create a def. But the macro expands to something that looks like a trivial const arg, but is not, so in AST lowering we "fix" the mistake we assumed def collection made and create a def for it. This causes a duplicate definition ICE. The ideal long-term fix for this is a bit unclear. One option is to delay def creation for all expression-like nodes until AST lowering (see #128844 for an incomplete attempt at this). This would avoid issues like this one that are caused by hacky workarounds. However, this approach has some downsides as well, and the best approach is yet to be determined. In the meantime, this PR fixes the bug by delaying def creation for anon consts whose bodies are macro invocations until after we expand the macro and know what is inside it. This is accomplished by adding information to create the anon const's def to the data in `Resolver.invocation_parents`.
2024-09-12Rollup merge of #130208 - nnethercote:rslv-lifetime, r=petrochenkovMatthias Krüger-470/+481
Introduce `'ra` lifetime name. `rustc_resolve` allocates many things in `ResolverArenas`. The lifetime used for references into the arena is mostly `'a`, and sometimes `'b`. This commit changes it to `'rslv`, which is much more descriptive. The commit also changes the order of lifetimes on a couple of structs so that '`rslv` is second last, before `'tcx`, and does other minor renamings such as `'r` to `'a`. r? ``@petrochenkov`` cc ``@oli-obk``
2024-09-12Rollup merge of #130235 - compiler-errors:nested-if, r=michaelwoeristerStuart Cook-111/+99
Simplify some nested `if` statements Applies some but not all instances of `clippy::collapsible_if`. Some ended up looking worse afterwards, though, so I left those out. Also applies instances of `clippy::collapsible_else_if` Review with whitespace disabled please.
2024-09-12Introduce `'ra` lifetime name.Nicholas Nethercote-470/+481
`rustc_resolve` allocates many things in `ResolverArenas`. The lifetime used for references into the arena is mostly `'a`, and sometimes `'b`. This commit changes it to `'ra`, which is much more descriptive. The commit also changes the order of lifetimes on a couple of structs so that '`ra` is second last, before `'tcx`, and does other minor renamings such as `'r` to `'a`.
2024-09-11Also fix if in elseMichael Goulet-26/+18
2024-09-11Simplify some nested if statementsMichael Goulet-85/+81
2024-09-09Remove needless returns detected by clippy in the compilerEduardo Sánchez Muñoz-3/+3
2024-09-07Don't call fn_arg_names for non-fn in resolverMichael Goulet-24/+25
2024-09-06elided_named_lifetimes: unify lint def & pass MissingLifetimeKindPavel Grigorenko-4/+10
2024-09-02Rollup merge of #129877 - Sajjon:sajjon_fix_typos_batch_2, r=fee1-deadMatthias Krüger-5/+5
chore: Fix typos in 'compiler' (batch 2) Batch 2/3: Fixes typos in `compiler` (See [issue](https://github.com/rust-lang/rust/issues/129874) tracking all PRs with typos fixes)
2024-09-02chore: Fix typos in 'compiler' (batch 2)Alexander Cyon-5/+5
2024-09-01Replace walk with visit so we dont skip outermost expr kind in def collectorMichael Goulet-1/+1
2024-09-01Rollup merge of #129493 - cjgillot:early-opaque-def, r=petrochenkovMatthias Krüger-53/+65
Create opaque definitions in resolver. Implementing https://github.com/rust-lang/rust/issues/129023#issuecomment-2306079532 That was easier than I expected. r? `@petrochenkov`
2024-08-31Create opaque definitions in resolver.Camille GILLOT-53/+65
2024-08-31Implement `elided_named_lifetimes` lintPavel Grigorenko-14/+76
2024-08-29Add `warn(unreachable_pub)` to `rustc_resolve`.Nicholas Nethercote-0/+1
2024-08-26Stop using a special inner body for the coroutine by-move body for async ↵Michael Goulet-0/+1
closures
2024-08-26mv `build_reduced_graph_for_external_crate_res` into Resolverbohan-68/+71
2024-08-24Rollup merge of #129246 - BoxyUwU:feature_gate_const_arg_path, r=cjgillotMatthias Krüger-7/+9
Retroactively feature gate `ConstArgKind::Path` This puts the lowering introduced by #125915 under a feature gate until we fix the regressions introduced by it. Alternative to whole sale reverting the PR since it didn't seem like a very clean revert and I think this is generally a step in the right direction and don't want to get stuck landing and reverting the PR over and over :) cc #129137 ``@camelid,`` tests taken from there. beta is branching soon so I think it makes sense to not try and rush that fix through since it wont have much time to bake and if it has issues we can't simply revert it on beta. Fixes #128016
2024-08-21Rollup merge of #129345 - compiler-errors:scratch4, r=jieyouxuMatthias Krüger-1/+1
Use shorthand field initialization syntax more aggressively in the compiler Caught these when cleaning up #129344 and decided to run clippy to find the rest
2024-08-21Rollup merge of #129344 - compiler-errors:less-option-unit-diagnostics, ↵Matthias Krüger-2/+2
r=jieyouxu Use `bool` in favor of `Option<()>` for diagnostics We originally only supported `Option<()>` for optional notes/labels, but we now support `bool`. Let's use that, since it usually leads to more readable code. I'm not removing the support from the derive macro, though I guess we could error on it... 🤔
2024-08-21Simplify some redundant field namesMichael Goulet-1/+1
2024-08-21Use bool in favor of Option<()> for diagnosticsMichael Goulet-2/+2
2024-08-20Rollup merge of #129270 - compiler-errors:inner-generics-shadowing, ↵Matthias Krüger-3/+3
r=petrochenkov Don't consider locals to shadow inner items' generics We don't want to consider the bindings from a `RibKind::Module` itself, because for an inner item that module will contain the local bindings from the function body or wherever else the inner item is being defined. Fixes #129265 r? petrochenkov
2024-08-20skip updating when external binding is existedbohan-5/+13
2024-08-19Don't consider RibKind::Module's bindings when checking generics shadowingMichael Goulet-3/+3
2024-08-19Retroactively feature gate `ConstArgKind::Path`Boxy-7/+9
2024-08-11Rollup merge of #128875 - bvanjoi:cleanup-import-used, r=petrochenkovMatthias Krüger-15/+16
rm `import.used` By the way, `import_used_map` will only be used during `build_reduced_graph` and `finalize`, so it can be split from `Resolver` in the future. r? ``@petrochenkov``
2024-08-11Rollup merge of #128762 - fmease:use-more-slice-pats, r=compiler-errorsMatthias Krüger-23/+20
Use more slice patterns inside the compiler Nothing super noteworthy. Just replacing the common 'fragile' pattern of "length check followed by indexing or unwrap" with slice patterns for legibility and 'robustness'. r? ghost
2024-08-10rm `import.used`bohan-15/+16
2024-08-08rm `declared_features` field in resolverbohan-6/+2
2024-08-08Auto merge of #128550 - compiler-errors:shadowed-params-perf, r=petrochenkovbors-96/+105
Only walk ribs to collect possibly shadowed params if we are adding params in our new rib No need to collect params from parent ribs if we literally have no params to declare in this new rib. Attempt to win back some of the perf in https://github.com/rust-lang/rust/pull/128357#issuecomment-2262677031. Please review with whitespace *off*, the diff should be like 2 lines. r? petrochenkov
2024-08-07make `import.vis` is not mutablebohan-63/+129
2024-08-07Use more slice patterns inside the compilerLeón Orell Valerian Liehr-23/+20
2024-08-04docs(resolve): more explain about `target`bohan-0/+1
2024-08-02Only walk ribs to collect possibly shadowed params if we are adding params ↵Michael Goulet-96/+105
in our new rib
2024-07-31Rollup merge of #123813 - compiler-errors:redundant-lint, r=petrochenkovMatthias Krüger-7/+5
Add `REDUNDANT_IMPORTS` lint for new redundant import detection Defaults to Allow for now. Stacked on #123744 to avoid merge conflict, but much easier to review all as one. r? petrochenkov
2024-07-31Rollup merge of #128151 - estebank:missing-extern-crate, r=petrochenkovMatthias Krüger-4/+13
Structured suggestion for `extern crate foo` when `foo` isn't resolved in import When encountering a name in an import that could have come from a crate that wasn't imported, use a structured suggestion to suggest `extern crate foo;` pointing at the right place in the crate. When encountering `_` in an import, do not suggest `extern crate _;`. ``` error[E0432]: unresolved import `spam` --> $DIR/import-from-missing-star-3.rs:2:9 | LL | use spam::*; | ^^^^ maybe a missing crate `spam`? | help: consider importing the `spam` crate | LL + extern crate spam; | ```
2024-07-31Introduce REDUNDANT_IMPORTS lintMichael Goulet-7/+5
2024-07-29Structured suggestion for `extern crate foo` when `foo` isn't resolved in importEsteban Küber-4/+13
When encountering a name in an import that could have come from a crate that wasn't imported, use a structured suggestion to suggest `extern crate foo;` pointing at the right place in the crate. When encountering `_` in an import, do not suggest `extern crate _;`. ``` error[E0432]: unresolved import `spam` --> $DIR/import-from-missing-star-3.rs:2:9 | LL | use spam::*; | ^^^^ maybe a missing crate `spam`? | help: consider importing the `spam` crate | LL + extern crate spam; | ```
2024-07-29Detect non-lifetime binder params shadowing item paramsMichael Goulet-10/+10
2024-07-29Reformat `use` declarations.Nicholas Nethercote-149/+163
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-26Rollup merge of #127557 - linyihai:issue-126694, r=compiler-errorsTrevor Gross-2/+5
Add a label to point to the lacking macro name definition Fixes https://github.com/rust-lang/rust/issues/126694, but adopts the suggestion from https://github.com/rust-lang/rust/issues/118295 ``` --> src/main.rs:1:14 | 1 | macro_rules! { | ^ put a macro name here ```