diff options
| author | Tom Martin <tom.martin1239@gmail.com> | 2023-06-18 12:15:17 +0100 |
|---|---|---|
| committer | Tom Martin <tom.martin1239@gmail.com> | 2023-06-18 12:28:17 +0100 |
| commit | 355a6895425354ee2caf5df99fbe4ec9d136a460 (patch) | |
| tree | 12de627dc7448082b6e4f629de3e0176d1acc71d /compiler/rustc_resolve/src | |
| parent | 50c971a0b7e645754e758709b399c6da0205167a (diff) | |
| download | rust-355a6895425354ee2caf5df99fbe4ec9d136a460.tar.gz rust-355a6895425354ee2caf5df99fbe4ec9d136a460.zip | |
Add translatable diagnostic for cannot find in this scope
Diffstat (limited to 'compiler/rustc_resolve/src')
| -rw-r--r-- | compiler/rustc_resolve/src/errors.rs | 9 | ||||
| -rw-r--r-- | compiler/rustc_resolve/src/macros.rs | 13 |
2 files changed, 19 insertions, 3 deletions
diff --git a/compiler/rustc_resolve/src/errors.rs b/compiler/rustc_resolve/src/errors.rs index a7a8aa8b957..0f9039912ed 100644 --- a/compiler/rustc_resolve/src/errors.rs +++ b/compiler/rustc_resolve/src/errors.rs @@ -613,3 +613,12 @@ pub(crate) struct ImportsCannotReferTo<'a> { pub(crate) span: Span, pub(crate) what: &'a str, } + +#[derive(Diagnostic)] +#[diag(resolve_cannot_find_ident_in_this_scope)] +pub(crate) struct CannotFindIdentInThisScope<'a> { + #[primary_span] + pub(crate) span: Span, + pub(crate) expected: &'a str, + pub(crate) ident: Ident, +} diff --git a/compiler/rustc_resolve/src/macros.rs b/compiler/rustc_resolve/src/macros.rs index ca4f3331b9a..4dcef8f6efd 100644 --- a/compiler/rustc_resolve/src/macros.rs +++ b/compiler/rustc_resolve/src/macros.rs @@ -1,7 +1,9 @@ //! A bunch of methods and structures more or less related to resolving macros and //! interface provided by `Resolver` to macro expander. -use crate::errors::{self, AddAsNonDerive, MacroExpectedFound, RemoveSurroundingDerive}; +use crate::errors::{ + self, AddAsNonDerive, CannotFindIdentInThisScope, MacroExpectedFound, RemoveSurroundingDerive, +}; use crate::Namespace::*; use crate::{BuiltinMacroState, Determinacy}; use crate::{DeriveData, Finalize, ParentScope, ResolutionError, Resolver, ScopeSet}; @@ -793,8 +795,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { } Err(..) => { let expected = kind.descr_expected(); - let msg = format!("cannot find {} `{}` in this scope", expected, ident); - let mut err = self.tcx.sess.struct_span_err(ident.span, msg); + + let mut err = self.tcx.sess.create_err(CannotFindIdentInThisScope { + span: ident.span, + expected, + ident, + }); + self.unresolved_macro_suggestions(&mut err, kind, &parent_scope, ident, krate); err.emit(); } |
