Skip to content

Commit 3abad14

Browse files
committed
Unify output of the different "cannot find X" errors
Do not mention the scope where an ident couldn't be resolved (particularly for macros), and add a primary span label mentioning "this scope" (ideally we would replace the text with the actual scope name in the future): ``` error: cannot find derive macro `rustfmt` --> $DIR/tool-attributes-misplaced-1.rs:4:10 | LL | #[derive(rustfmt)] | ^^^^^^^ not found in this scope ```
1 parent 86f8aae commit 3abad14

File tree

88 files changed

+526
-428
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+526
-428
lines changed

compiler/rustc_lint/messages.ftl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,8 @@ lint_opaque_hidden_inferred_bound_sugg = add this bound
609609
lint_or_patterns_back_compat = the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro
610610
.suggestion = use pat_param to preserve semantics
611611
612-
lint_out_of_scope_macro_calls = cannot find macro `{$path}` in this scope
612+
lint_out_of_scope_macro_calls = cannot find macro `{$path}`
613+
.label = not found in this scope
613614
.help = import `macro_rules` with `use` to make it callable above its definition
614615
615616
lint_overflowing_bin_hex = literal out of range for `{$ty}`
@@ -650,7 +651,7 @@ lint_pattern_in_foreign = patterns aren't allowed in foreign function declaratio
650651
lint_private_extern_crate_reexport = extern crate `{$ident}` is private and cannot be re-exported
651652
.suggestion = consider making the `extern crate` item publicly accessible
652653
653-
lint_proc_macro_derive_resolution_fallback = cannot find {$ns} `{$ident}` in this scope
654+
lint_proc_macro_derive_resolution_fallback = cannot find {$ns} `{$ident}`
654655
.label = names from parent modules are not accessible without an explicit import
655656
656657
lint_ptr_null_checks_fn_ptr = function pointers are not nullable, so checking them for null will always return false

compiler/rustc_lint/src/context/diagnostics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,8 @@ pub(super) fn decorate_lint(sess: &Session, diagnostic: BuiltinLintDiag, diag: &
434434
lints::InnerAttributeUnstable::CustomInnerAttribute
435435
}
436436
.decorate_lint(diag),
437-
BuiltinLintDiag::OutOfScopeMacroCalls { path } => {
438-
lints::OutOfScopeMacroCalls { path }.decorate_lint(diag)
437+
BuiltinLintDiag::OutOfScopeMacroCalls { span, path } => {
438+
lints::OutOfScopeMacroCalls { span, path }.decorate_lint(diag)
439439
}
440440
}
441441
}

compiler/rustc_lint/src/lints.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2917,5 +2917,7 @@ pub struct UnsafeAttrOutsideUnsafeSuggestion {
29172917
#[diag(lint_out_of_scope_macro_calls)]
29182918
#[help]
29192919
pub struct OutOfScopeMacroCalls {
2920+
#[label]
2921+
pub span: Span,
29202922
pub path: String,
29212923
}

compiler/rustc_lint_defs/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,7 @@ pub enum BuiltinLintDiag {
745745
is_macro: bool,
746746
},
747747
OutOfScopeMacroCalls {
748+
span: Span,
748749
path: String,
749750
},
750751
}

compiler/rustc_resolve/messages.ftl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ resolve_cannot_determine_macro_resolution =
8080
resolve_cannot_find_builtin_macro_with_name =
8181
cannot find a built-in macro with name `{$ident}`
8282
83-
resolve_cannot_find_ident_in_this_scope =
84-
cannot find {$expected} `{$ident}` in this scope
83+
resolve_cannot_find_ident_in_this_scope = cannot find {$expected} `{$ident}`
84+
.label = not found in this scope
8585
8686
resolve_cannot_glob_import_possible_crates =
8787
cannot glob-import all possible crates

compiler/rustc_resolve/src/errors.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ pub(crate) struct ImportsCannotReferTo<'a> {
635635
#[diag(resolve_cannot_find_ident_in_this_scope)]
636636
pub(crate) struct CannotFindIdentInThisScope<'a> {
637637
#[primary_span]
638+
#[label]
638639
pub(crate) span: Span,
639640
pub(crate) expected: &'a str,
640641
pub(crate) ident: Ident,

compiler/rustc_resolve/src/late.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3918,7 +3918,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
39183918

39193919
// There are two different error messages user might receive at
39203920
// this point:
3921-
// - E0412 cannot find type `{}` in this scope
3921+
// - E0412 cannot find type `{}`
39223922
// - E0433 failed to resolve: use of undeclared type or module `{}`
39233923
//
39243924
// The first one is emitted for paths in type-position, and the

compiler/rustc_resolve/src/late/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2522,7 +2522,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
25222522
if let Some(generics) = kind.generics() {
25232523
if span.overlaps(generics.span) {
25242524
// Avoid the following:
2525-
// error[E0405]: cannot find trait `A` in this scope
2525+
// error[E0405]: cannot find trait `A`
25262526
// --> $DIR/typo-suggestion-named-underscore.rs:CC:LL
25272527
// |
25282528
// L | fn foo<T: A>(x: T) {} // Shouldn't suggest underscore

compiler/rustc_resolve/src/macros.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
10711071
OUT_OF_SCOPE_MACRO_CALLS,
10721072
path.span,
10731073
node_id,
1074-
BuiltinLintDiag::OutOfScopeMacroCalls { path: pprust::path_to_string(path) },
1074+
BuiltinLintDiag::OutOfScopeMacroCalls {
1075+
span: path.span,
1076+
path: pprust::path_to_string(path),
1077+
},
10751078
);
10761079
}
10771080
}

tests/rustdoc-ui/impl-fn-nesting.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: cannot find macro `unknown_macro` in this scope
1+
error: cannot find macro `unknown_macro`
22
--> $DIR/impl-fn-nesting.rs:32:13
33
|
44
LL | unknown_macro!();
5-
| ^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^ not found in this scope
66

77
error[E0405]: cannot find trait `UnknownBound`
88
--> $DIR/impl-fn-nesting.rs:11:13

0 commit comments

Comments
 (0)