about summary refs log tree commit diff
path: root/compiler/rustc_resolve/src/late/diagnostics.rs
AgeCommit message (Collapse)AuthorLines
2025-09-28Detect unconstructable re-exported tuple structsEsteban Küber-33/+66
When a tuple-struct is re-exported that has inaccessible fields at the `use` scope, the type's constructor cannot be accessed through that re-export. We now account for this case and extend the resulting resolution error. We also check if the constructor would be accessible directly, not through the re-export, and if so, we suggest using the full path instead. ``` error[E0423]: cannot initialize a tuple struct which contains private fields --> $DIR/ctor-not-accessible-due-to-inaccessible-field-in-reexport.rs:12:33 | LL | let crate::Foo(x) = crate::Foo(42); | ^^^^^^^^^^ | note: the type is accessed through this re-export, but the type's constructor is not visible in this import's scope due to private fields --> $DIR/ctor-not-accessible-due-to-inaccessible-field-in-reexport.rs:3:9 | LL | pub use my_mod::Foo; | ^^^^^^^^^^^ help: the type can be constructed directly, because its fields are available from the current scope | LL | let crate::Foo(x) = crate::my_mod::Foo(42); | ~~~~~~~~~~~~~~~~~~ ``` Fix #133343.
2025-09-05remove couple of clonesMatthias Krüger-1/+1
2025-08-22Rollup merge of #145597 - petrochenkov:nolateset, r=b-naberJacob Pratt-4/+5
resolve: Remove `ScopeSet::Late` It's better to decouple the late/early stage from scope set, because in https://github.com/rust-lang/rust/pull/144131#discussion_r2283200511 we'll need the stage for `ScopeSet::Module` as well. See individual commits for the refactoring details. r? ``@b-naber``
2025-08-22resolve: Remove `ScopeSet::Late`Vadim Petrochenkov-1/+1
The difference between `Late` and `All` only matters when `finalize` is enabled. So add a `stage` field to `Finalize` and use it instead.
2025-08-22resolve: Remove derive fallback lint id from `ScopeSet::Late`Vadim Petrochenkov-1/+1
2025-08-22resolve: Remove `Module` from `ScopeSet::Late`Vadim Petrochenkov-4/+5
It can be passed in a more usual way through `ParentScope`
2025-08-22print raw lifetime idents with `r#`Deadbeef-15/+11
2025-08-14resolve: Introduce `RibKind::Block`Vadim Petrochenkov-7/+3
to avoid confusing module items, blocks with items, and blocks without items.
2025-08-14resolve: Improve code reuse in typo candidate collectionVadim Petrochenkov-33/+18
2025-08-12Switch to a bitflags `MacroKinds` to support macros with more than one kindJosh Triplett-5/+4
Review everything that uses `MacroKind`, and switch anything that could refer to more than one kind to use `MacroKinds`. Add a new `SyntaxExtensionKind::MacroRules` for `macro_rules!` macros, using the concrete `MacroRulesMacroExpander` type, and have it track which kinds it can handle. Eliminate the separate optional `attr_ext`, now that a `SyntaxExtension` can handle multiple macro kinds. This also avoids the need to downcast when calling methods on `MacroRulesMacroExpander`, such as `get_unused_rule`. Integrate macro kind checking into name resolution's `sub_namespace_match`, so that we only find a macro if it's the right type, and eliminate the special-case hack for attributes.
2025-08-10Detect struct construction with private field in field with defaultEsteban Küber-11/+16
When trying to construct a struct that has a public field of a private type, suggest using `..` if that field has a default value. ``` error[E0603]: struct `Priv1` is private --> $DIR/non-exhaustive-ctor.rs:25:39 | LL | let _ = S { field: (), field1: m::Priv1 {} }; | ------ ^^^^^ private struct | | | while setting this field | note: the struct `Priv1` is defined here --> $DIR/non-exhaustive-ctor.rs:14:4 | LL | struct Priv1 {} | ^^^^^^^^^^^^ help: the field `field1` you're trying to set has a default value, you can use `..` to use it | LL | let _ = S { field: (), .. }; | ~~ ```
2025-08-09remove `P`Deadbeef-5/+4
2025-08-08Rollup merge of #144912 - LorrensP-2158466:smart-resolver, r=petrochenkovStuart Cook-1/+1
Resolver: introduce a conditionally mutable Resolver for (non-)speculative resolution. This pr introduces a `CmResolver`, a wrapper around the main resolver which gives out mutable access given a condition. `CmResolver` only allows mutation when we’re not in speculative import resolution. This ensures we can’t accidentally mutate the resolver during this process, which is important as we move towards a batched resolution algorithm. This also changes functions that are used during speculative import resolution to take a `CmResolver` instead of a `&mut Resolver`. Also introduces a new kind of "smart pointer" which has the behaviour described above: ```rust /// A wrapper around a mutable reference that conditionally allows mutable access. pub(crate) struct RefOrMut<'a, T> { p: &'a mut T, mutable: bool, } type CmResolver<'r, 'ra, 'tcx> = RefOrMut<'r, Resolver<'ra, 'tcx>>; ``` r? petrochenkov
2025-08-07Introduce, implement and use CmResolver.LorrensP-2158466-1/+1
2025-08-06Introduce ModernIdent type to unify macro 2.0 hygiene handlingxizheyin-4/+7
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-08-04Rollup merge of #144746 - petrochenkov:extpreltidy, r=b-naberStuart Cook-13/+4
resolve: Cleanups and micro-optimizations to extern prelude This is what can be done without changing the structure of `ExternPreludeEntry`, like in https://github.com/rust-lang/rust/pull/144737. See individual commits for details.
2025-08-01Detect more `cfg`d out items in resolution errorsEsteban Küber-3/+2
Use a visitor to collect *all* items (including those nested) that were stripped behind a `cfg` condition. ``` error[E0425]: cannot find function `f` in this scope --> $DIR/nested-cfg-attrs.rs:4:13 | LL | fn main() { f() } | ^ not found in this scope | note: found an item that was configured out --> $DIR/nested-cfg-attrs.rs:2:4 | LL | fn f() {} | ^ note: the item is gated here --> $DIR/nested-cfg-attrs.rs:1:35 | LL | #[cfg_attr(all(), cfg_attr(all(), cfg(FALSE)))] | ^^^^^^^^^^ ```
2025-07-31resolve: Cleanup some uses of extern prelude in diagnosticsVadim Petrochenkov-13/+4
2025-07-28Auto merge of #144469 - Kivooeo:chains-cleanup, r=SparrowLiibors-106/+98
Some `let chains` clean-up Not sure if this kind of clean-up is welcoming because of size, but I decided to try out one r? compiler
2025-07-28use let chains in mir, resolve, targetKivooeo-106/+98
2025-07-27split up define into define_extern and define_localLorrensP-2158466-3/+3
2025-07-26resolve: Minimize borrow scopes for `resolutions`Vadim Petrochenkov-5/+8
2025-07-18inline CrateLoader inside of CStoreLorrensP-2158466-1/+2
2025-07-17resolve: Change `&mut Resolver` to `&Resolver` when possibleVadim Petrochenkov-14/+10
2025-07-17resolve: Use `module_map` and `get_module` lessVadim Petrochenkov-11/+9
2025-07-16resolve: Merge `NameBindingKind::Module` into `NameBindingKind::Res`Vadim Petrochenkov-3/+3
2025-07-12replace binding and shadowed_glob on NameResolution with non_glob_binding ↵b-naber-12/+17
and glob_binding
2025-07-10Remove uncessary parens in closure body with unused lintyukang-2/+1
2025-07-08Rollup merge of #143177 - xizheyin:143134, r=lcnrTrevor Gross-4/+12
Remove false label when `self` resolve failure does not relate to macro Fixes rust-lang/rust#143134 In the first commit, I did some code-clean, moving `suggest*` to `suggestions/` dir. In the second, commit, I added ui test. In the third, I change the code, and present the test result. r? compiler
2025-07-06compiler: rename {ast,hir}::BareFn* to FnPtr*Jubilee Young-1/+1
Fix some comments and related types and locals where it is obvious, e.g. - bare_fn -> fn_ptr - LifetimeBinderKind::BareFnType -> LifetimeBinderKind::FnPtrType Co-authored-by: León Orell Valerian Liehr <me@fmease.dev>
2025-07-03Return early when `self` resolve failure because of `let self = ...`xizheyin-4/+12
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-07-03Replace kw_span by full span.Camille GILLOT-1/+1
2025-07-01Detect more cases of unused_parens around typesBenjamin Schulz-0/+1
2025-06-24Make missing lifetime suggestion verboseMichael Goulet-6/+1
2025-06-16Fix `PathSource` lifetimes.Nicholas Nethercote-21/+21
It currently has two, which don't accurately capture what's happening -- the `TupleStruct` spans are allocated in `ResolverArenas`, which is different to where the `Expr` is allocated -- and require some "outlives" constraints to be used. This commit adds another lifetime, renames the existing ones, and removes the "outlives" constraints.
2025-06-04Replace `elided_named_lifetimes` with `mismatched_lifetime_syntaxes`Jake Goulding-2/+2
2025-06-01Rollup merge of #140370 - WaffleLapkin:unqualified, r=jdonszelmannGuillaume Gomez-23/+101
Improve diagnostics for usage of qualified paths within tuple struct exprs/pats For patterns the old diagnostic was just incorrect, but I also added machine applicable suggestions. For context, this special cases errors for `<T as Trait>::Assoc(..)` patterns and expressions (latter is just a call). Tuple struct patterns and expressions both live in the value namespace, so they are not forwarded through associated *types*. r? ``@jdonszelmann`` cc ``@petrochenkov`` in https://github.com/rust-lang/rust/pull/80080#issuecomment-800630582 you were wondering why it doesn't work for types, that's why — tuple patterns are resolved in the value namespace.
2025-05-21Rollup merge of #141213 - xizheyin:issue-141136, r=nnethercoteMatthias Krüger-6/+18
Suggest use "{}", self.x instead of {self.x} when resolve x as field of `self` Fixes #141136 Changes can be seen in the second commit: https://github.com/rust-lang/rust/commit/9de7fff0d8ab72fb57dea6255fc10fe35219db72 r? compiler
2025-05-21Downgrade the confident of suggestion `available field in format string` and ↵xizheyin-10/+4
optimize expression Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-05-21collect doc alias as tips during resolutionbohan-1/+74
2025-05-18Suggest use `"{}", self.x` instead of `{self.x}` when resolve `x` as field ↵xizheyin-6/+24
of `self` Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-05-09Suggest stable candidates rather than unstable onesmu001999-0/+1
2025-04-27Make error for tuple struct pat/expr w/ FQS clearerWaffle Lapkin-23/+101
1. Fix "expected" and the note for the pattern case 2. Add suggestions
2025-04-15Move `name` field from `AssocItem` to `AssocKind` variants.Nicholas Nethercote-2/+3
To accurately reflect that RPITIT assoc items don't have a name. This avoids the use of `kw::Empty` to mean "no name", which is error prone. Helps with #137978.
2025-04-14Move `has_self` field to `hir::AssocKind::Fn`.Nicholas Nethercote-1/+1
`hir::AssocItem` currently has a boolean `fn_has_self_parameter` field, which is misplaced, because it's only relevant for associated fns, not for associated consts or types. This commit moves it (and renames it) to the `AssocKind::Fn` variant, where it belongs. This requires introducing a new C-style enum, `AssocTag`, which is like `AssocKind` but without the fields. This is because `AssocKind` values are passed to various functions like `find_by_ident_and_kind` to indicate what kind of associated item should be searched for, and having to specify `has_self` isn't relevant there. New methods: - Predicates `AssocItem::is_fn` and `AssocItem::is_method`. - `AssocItem::as_tag` which converts `AssocItem::kind` to `AssocTag`. Removed `find_by_name_and_kinds`, which is unused. `AssocItem::descr` can now distinguish between methods and associated functions, which slightly improves some error messages.
2025-04-10Rename some `name` variables as `ident`.Nicholas Nethercote-1/+1
It bugs me when variables of type `Ident` are called `name`. It leads to silly things like `name.name`. `Ident` variables should be called `ident`, and `name` should be used for variables of type `Symbol`. This commit improves things by by doing `s/name/ident/` on a bunch of `Ident` variables. Not all of them, but a decent chunk.
2025-04-01Address review comments.Nicholas Nethercote-7/+3
2025-04-01Move `ast::Item::ident` into `ast::ItemKind`.Nicholas Nethercote-28/+28
`ast::Item` has an `ident` field. - It's always non-empty for these item kinds: `ExternCrate`, `Static`, `Const`, `Fn`, `Mod`, `TyAlias`, `Enum`, `Struct`, `Union`, `Trait`, `TraitAlias`, `MacroDef`, `Delegation`. - It's always empty for these item kinds: `Use`, `ForeignMod`, `GlobalAsm`, `Impl`, `MacCall`, `DelegationMac`. There is a similar story for `AssocItemKind` and `ForeignItemKind`. Some sites that handle items check for an empty ident, some don't. This is a very C-like way of doing things, but this is Rust, we have sum types, we can do this properly and never forget to check for the exceptional case and never YOLO possibly empty identifiers (or possibly dummy spans) around and hope that things will work out. The commit is large but it's mostly obvious plumbing work. Some notable things. - `ast::Item` got 8 bytes bigger. This could be avoided by boxing the fields within some of the `ast::ItemKind` variants (specifically: `Struct`, `Union`, `Enum`). I might do that in a follow-up; this commit is big enough already. - For the visitors: `FnKind` no longer needs an `ident` field because the `Fn` within how has one. - In the parser, the `ItemInfo` typedef is no longer needed. It was used in various places to return an `Ident` alongside an `ItemKind`, but now the `Ident` (if present) is within the `ItemKind`. - In a few places I renamed identifier variables called `name` (or `foo_name`) as `ident` (or `foo_ident`), to better match the type, and because `name` is normally used for `Symbol`s. It's confusing to see something like `foo_name.name`.
2025-03-27Rollup merge of #139014 - xizheyin:issue-138931, r=oli-obkJacob Pratt-34/+74
Improve suggest construct with literal syntax instead of calling Closing #138931 When constructing a structure through a format similar to calling a constructor, we can use verbose suggestions to hint at using literal syntax for clearer advice. The case of multiple fields is also considered here, provided that the field has the same number of arguments as CallExpr. r? compiler
2025-03-27Improve suggest construct with literal syntax instead of callingxizheyin-34/+74
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>