Skip to content

Commit 355a689

Browse files
committed
Add translatable diagnostic for cannot find in this scope
1 parent 50c971a commit 355a689

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

compiler/rustc_resolve/messages.ftl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,4 +267,7 @@ resolve_change_import_binding =
267267
you can use `as` to change the binding name of the import
268268
269269
resolve_imports_cannot_refer_to =
270-
imports cannot refer to {$what}
270+
imports cannot refer to {$what}
271+
272+
resolve_cannot_find_ident_in_this_scope =
273+
cannot find {$expected} `{$ident}` in this scope

compiler/rustc_resolve/src/errors.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,3 +613,12 @@ pub(crate) struct ImportsCannotReferTo<'a> {
613613
pub(crate) span: Span,
614614
pub(crate) what: &'a str,
615615
}
616+
617+
#[derive(Diagnostic)]
618+
#[diag(resolve_cannot_find_ident_in_this_scope)]
619+
pub(crate) struct CannotFindIdentInThisScope<'a> {
620+
#[primary_span]
621+
pub(crate) span: Span,
622+
pub(crate) expected: &'a str,
623+
pub(crate) ident: Ident,
624+
}

compiler/rustc_resolve/src/macros.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
//! A bunch of methods and structures more or less related to resolving macros and
22
//! interface provided by `Resolver` to macro expander.
33
4-
use crate::errors::{self, AddAsNonDerive, MacroExpectedFound, RemoveSurroundingDerive};
4+
use crate::errors::{
5+
self, AddAsNonDerive, CannotFindIdentInThisScope, MacroExpectedFound, RemoveSurroundingDerive,
6+
};
57
use crate::Namespace::*;
68
use crate::{BuiltinMacroState, Determinacy};
79
use crate::{DeriveData, Finalize, ParentScope, ResolutionError, Resolver, ScopeSet};
@@ -793,8 +795,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
793795
}
794796
Err(..) => {
795797
let expected = kind.descr_expected();
796-
let msg = format!("cannot find {} `{}` in this scope", expected, ident);
797-
let mut err = self.tcx.sess.struct_span_err(ident.span, msg);
798+
799+
let mut err = self.tcx.sess.create_err(CannotFindIdentInThisScope {
800+
span: ident.span,
801+
expected,
802+
ident,
803+
});
804+
798805
self.unresolved_macro_suggestions(&mut err, kind, &parent_scope, ident, krate);
799806
err.emit();
800807
}

0 commit comments

Comments
 (0)