summary refs log tree commit diff
path: root/compiler/rustc_resolve/src/diagnostics.rs
AgeCommit message (Collapse)AuthorLines
2024-11-14Use `for_each_child` in a suitable place.Nicholas Nethercote-7/+5
`for_each_child` exists for this exact pattern.
2024-10-06Rename NestedMetaItem to MetaItemInnercodemountains-3/+2
2024-09-29cleanup: don't clone types that are CopyMatthias Krüger-5/+1
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-18/+22
2024-09-12Rollup merge of #130208 - nnethercote:rslv-lifetime, r=petrochenkovMatthias Krüger-26/+26
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-53/+52
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-26/+26
`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-11Simplify some nested if statementsMichael Goulet-53/+52
2024-09-09Remove needless returns detected by clippy in the compilerEduardo Sánchez Muñoz-1/+1
2024-08-21Simplify some redundant field namesMichael Goulet-1/+1
2024-08-07make `import.vis` is not mutablebohan-10/+13
2024-07-29Structured suggestion for `extern crate foo` when `foo` isn't resolved in importEsteban Küber-4/+7
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-29Reformat `use` declarations.Nicholas Nethercote-13/+17
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-1/+4
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 ```
2024-07-26Add a label to point to the lacking macro name definitionLin Yihai-1/+4
2024-07-24Do not use question as labelEsteban Küber-2/+2
We don't want to have questions in the diagnostic output. Instead, we use wording that communicates uncertainty, like "might": ``` error[E0432]: unresolved import `spam` --> $DIR/import-from-missing-star-3.rs:2:9 | LL | use spam::*; | ^^^^ you might be missing crate `spam` | = help: consider adding `extern crate spam` to use the `spam` crate ```
2024-07-19Avoid ref when using format! in compilerYuri Astrakhan-3/+3
Clean up a few minor refs in `format!` macro, as it has a performance cost. Apparently the compiler is unable to inline `format!("{}", &variable)`, and does a run-time double-reference instead (format macro already does one level referencing). Inlining format args prevents accidental `&` misuse.
2024-07-19Rollup merge of #127662 - estebank:gate-span, r=TaKO8KiMatthias Krüger-1/+7
When finding item gated behind a `cfg` flag, point at it Previously we would only mention that the item was gated out, and opportunisitically mention the feature flag name when possible. We now point to the place where the item was gated, which can be behind layers of macro indirection, or in different modules. ``` error[E0433]: failed to resolve: could not find `doesnt_exist` in `inner` --> $DIR/diagnostics-cross-crate.rs:18:23 | LL | cfged_out::inner::doesnt_exist::hello(); | ^^^^^^^^^^^^ could not find `doesnt_exist` in `inner` | note: found an item that was configured out --> $DIR/auxiliary/cfged_out.rs:6:13 | LL | pub mod doesnt_exist { | ^^^^^^^^^^^^ note: the item is gated here --> $DIR/auxiliary/cfged_out.rs:5:5 | LL | #[cfg(FALSE)] | ^^^^^^^^^^^^^ ```
2024-07-18Accurate `use` rename suggestion spanEsteban Küber-8/+10
When suggesting to rename an import with `as`, use a smaller span to render the suggestion with a better format: ``` error[E0252]: the name `baz` is defined multiple times --> $DIR/issue-25396.rs:4:5 | LL | use foo::baz; | -------- previous import of the module `baz` here LL | use bar::baz; | ^^^^^^^^ `baz` reimported here | = note: `baz` must be defined only once in the type namespace of this module help: you can use `as` to change the binding name of the import | LL | use bar::baz as other_baz; | ++++++++++++ ```
2024-07-12Rollup merge of #127310 - chenyukang:yukang-fix-suggest-import-ice, r=estebankJubilee-5/+5
Fix import suggestion ice Fixes #127302 #127302 only crash in edition 2015 #120074 can only reproduced in edition 2021 so I added revisions in test file.
2024-07-12When finding item gated behind a `cfg` flat, point at itEsteban Küber-1/+7
Previously we would only mention that the item was gated out, and opportunisitically mention the feature flag name when possible. We now point to the place where the item was gated, which can be behind layers of macro indirection, or in different modules. ``` error[E0433]: failed to resolve: could not find `doesnt_exist` in `inner` --> $DIR/diagnostics-cross-crate.rs:18:23 | LL | cfged_out::inner::doesnt_exist::hello(); | ^^^^^^^^^^^^ could not find `doesnt_exist` in `inner` | note: found an item that was configured out --> $DIR/auxiliary/cfged_out.rs:6:13 | LL | pub mod doesnt_exist { | ^^^^^^^^^^^^ note: the item is gated here --> $DIR/auxiliary/cfged_out.rs:5:5 | LL | #[cfg(FALSE)] | ^^^^^^^^^^^^^ ```
2024-07-11Account for `let foo = expr`; to suggest `const foo: Ty = expr;`Esteban Küber-1/+7
2024-07-11Use verbose style when suggesting changing `const` with `let`Esteban Küber-2/+3
2024-07-06Use field ident spans directly instead of the full field span in diagnostics ↵Oli Scherer-5/+1
on local fields
2024-07-04Fix import suggestion iceyukang-5/+5
2024-07-01Fix import suggestion error when failed not from startingyukang-1/+11
2024-06-18Remove redundant argument from `subdiagnostic` methodOli Scherer-41/+31
2024-06-18Use a dedicated type instead of a reference for the diagnostic contextOli Scherer-2/+2
This paves the way for tracking more state (e.g. error tainting) in the diagnostic context handle
2024-06-13Tweak output of import suggestionsEsteban Küber-7/+39
When both `std::` and `core::` items are available, only suggest the `std::` ones. We ensure that in `no_std` crates we suggest `core::` items. Ensure that the list of items suggested to be imported are always in the order of local crate items, `std`/`core` items and finally foreign crate items. Tweak wording of import suggestion: if there are multiple items but they are all of the same kind, we use the kind name and not the generic "items". Fix #83564.
2024-05-30Improve renaming suggestion for names with leading underscoresLucas Scharenbroch-14/+24
2024-05-21Rename buffer_lint_with_diagnostic to buffer_lintXiretza-3/+3
2024-05-21Generate lint diagnostic message from BuiltinLintDiagXiretza-6/+0
Translation of the lint message happens when the actual diagnostic is created, not when the lint is buffered. Generating the message from BuiltinLintDiag ensures that all required data to construct the message is preserved in the LintBuffer, eventually allowing the messages to be moved to fluent. Remove the `msg` field from BufferedEarlyLint, it is either generated from the data in the BuiltinLintDiag or stored inside BuiltinLintDiag::Normal.
2024-05-10Remove `ordinalize`.Nicholas Nethercote-14/+0
Some minor (English only) heroics are performed to print error messages like "5th rule of macro `m` is never used". The form "rule #5 of macro `m` is never used" is just as good and much simpler to implement.
2024-05-10Remove `#[macro_use] extern crate tracing` from `rustc_resolve`.Nicholas Nethercote-0/+1
Explicit imports are more standard nowadays and easier to read.
2024-04-29Add raw identifier in a typo suggestionLin Yihai-1/+1
2024-04-13Migrate more diagnosticsJean CASPAR-138/+135
2024-04-13Migrate some diagnosticsJean CASPAR-10/+12
2024-04-13Port build_reduce_graphJeanCASPAR-1/+1
2024-03-27Do not sort `DefId`s in diagnosticsOli Scherer-11/+9
2024-03-12Manual rustfmtOli Scherer-1/+1
2024-03-12Change `DefKind::Static` to a struct variantOli Scherer-1/+1
2024-03-06avoid overlapping privacy suggestion for single nested importsbohan-23/+39
2024-03-05Rename `BuiltinLintDiagnostics` as `BuiltinLintDiag`.Nicholas Nethercote-4/+4
Not the dropping of the trailing `s` -- this type describes a single diagnostic and its name should be singular.
2024-03-05Rename `DiagnosticMode` as `DiagMode`.Nicholas Nethercote-19/+16
2024-03-04Rollup merge of #121130 - chenyukang:yukang-fix-121061-macro-later, ↵Matthias Krüger-1/+22
r=matthiaskrgr Suggest moving definition if non-found macro_rules! is defined later Fixes #121061
2024-02-29Rollup merge of #121792 - GuillaumeGomez:improve-suggestion, r=michaelwoeristerGuillaume Gomez-2/+3
Improve renaming suggestion when item starts with underscore Fixes https://github.com/rust-lang/rust/issues/121776. It goes from: ```terminal error[E0433]: failed to resolve: use of undeclared type `Foo` --> src/foo.rs:6:13 | 6 | let _ = Foo::Bar; | ^^^ use of undeclared type `Foo` | help: an enum with a similar name exists, consider changing it | 1 | enum Foo { | ~~~ ``` to: ```terminal error[E0433]: failed to resolve: use of undeclared type `Foo` --> foo.rs:6:13 | 6 | let _ = Foo::Bar; | ^^^ use of undeclared type `Foo` | help: an enum with a similar name exists, consider renaming `_Foo` into `Foo` | 1 | enum Foo { | ~~~ error: aborting due to 1 previous error ```
2024-02-29Improve suggestion to rename type starting with underscore to make it more ↵Guillaume Gomez-2/+3
obvious what is actually suggested
2024-02-29Suggest moving if non-found macro_rules! is defined lateryukang-1/+22
2024-02-28Auto merge of #121489 - nnethercote:diag-renaming, r=davidtwcobors-10/+10
Diagnostic renaming Renaming various diagnostic types from `Diagnostic*` to `Diag*`. Part of https://github.com/rust-lang/compiler-team/issues/722. There are more to do but this is enough for one PR. r? `@davidtwco`
2024-02-28Rollup merge of #121226 - chenyukang:yukang-fix-import-alias, r=davidtwcoGuillaume Gomez-1/+11
Fix issues in suggesting importing extern crate paths Fixes #121168 r? ``@petrochenkov``