Skip to content

Commit 18830bb

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 cd7eb8f commit 18830bb

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
@@ -604,7 +604,8 @@ lint_opaque_hidden_inferred_bound_sugg = add this bound
604604
lint_or_patterns_back_compat = the meaning of the `pat` fragment specifier is changing in Rust 2021, which may affect this macro
605605
.suggestion = use pat_param to preserve semantics
606606
607-
lint_out_of_scope_macro_calls = cannot find macro `{$path}` in this scope
607+
lint_out_of_scope_macro_calls = cannot find macro `{$path}`
608+
.label = not found in this scope
608609
.help = import `macro_rules` with `use` to make it callable above its definition
609610
610611
lint_overflowing_bin_hex = literal out of range for `{$ty}`
@@ -645,7 +646,7 @@ lint_pattern_in_foreign = patterns aren't allowed in foreign function declaratio
645646
lint_private_extern_crate_reexport = extern crate `{$ident}` is private and cannot be re-exported
646647
.suggestion = consider making the `extern crate` item publicly accessible
647648
648-
lint_proc_macro_derive_resolution_fallback = cannot find {$ns} `{$ident}` in this scope
649+
lint_proc_macro_derive_resolution_fallback = cannot find {$ns} `{$ident}`
649650
.label = names from parent modules are not accessible without an explicit import
650651
651652
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
@@ -2916,5 +2916,7 @@ pub struct UnsafeAttrOutsideUnsafeSuggestion {
29162916
#[diag(lint_out_of_scope_macro_calls)]
29172917
#[help]
29182918
pub struct OutOfScopeMacroCalls {
2919+
#[label]
2920+
pub span: Span,
29192921
pub path: String,
29202922
}

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
@@ -3917,7 +3917,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
39173917

39183918
// There are two different error messages user might receive at
39193919
// this point:
3920-
// - E0412 cannot find type `{}` in this scope
3920+
// - E0412 cannot find type `{}`
39213921
// - E0433 failed to resolve: use of undeclared type or module `{}`
39223922
//
39233923
// 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
@@ -2528,7 +2528,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
25282528
if let Some(generics) = kind.generics() {
25292529
if span.overlaps(generics.span) {
25302530
// Avoid the following:
2531-
// error[E0405]: cannot find trait `A` in this scope
2531+
// error[E0405]: cannot find trait `A`
25322532
// --> $DIR/typo-suggestion-named-underscore.rs:CC:LL
25332533
// |
25342534
// 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
@@ -1070,7 +1070,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
10701070
OUT_OF_SCOPE_MACRO_CALLS,
10711071
path.span,
10721072
node_id,
1073-
BuiltinLintDiag::OutOfScopeMacroCalls { path: pprust::path_to_string(path) },
1073+
BuiltinLintDiag::OutOfScopeMacroCalls {
1074+
span: path.span,
1075+
path: pprust::path_to_string(path),
1076+
},
10741077
);
10751078
}
10761079
}

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)