diff options
| -rw-r--r-- | compiler/rustc_resolve/messages.ftl | 3 | ||||
| -rw-r--r-- | compiler/rustc_resolve/src/errors.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_resolve/src/late.rs | 10 |
3 files changed, 16 insertions, 5 deletions
diff --git a/compiler/rustc_resolve/messages.ftl b/compiler/rustc_resolve/messages.ftl index 2952f82e2de..3702f03269e 100644 --- a/compiler/rustc_resolve/messages.ftl +++ b/compiler/rustc_resolve/messages.ftl @@ -265,3 +265,6 @@ resolve_variable_bound_with_different_mode = resolve_change_import_binding = you can use `as` to change the binding name of the import + +resolve_imports_cannot_refer_to = + imports cannot refer to {$what} \ No newline at end of file diff --git a/compiler/rustc_resolve/src/errors.rs b/compiler/rustc_resolve/src/errors.rs index b7b5e9d15bc..a7a8aa8b957 100644 --- a/compiler/rustc_resolve/src/errors.rs +++ b/compiler/rustc_resolve/src/errors.rs @@ -605,3 +605,11 @@ pub(crate) struct ChangeImportBindingSuggestion { pub(crate) span: Span, pub(crate) suggestion: String, } + +#[derive(Diagnostic)] +#[diag(resolve_imports_cannot_refer_to)] +pub(crate) struct ImportsCannotReferTo<'a> { + #[primary_span] + pub(crate) span: Span, + pub(crate) what: &'a str, +} diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index ddd75ea3b33..e700e8c9ce0 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -6,6 +6,7 @@ //! If you wonder why there's no `early.rs`, that's because it's split into three files - //! `build_reduced_graph.rs`, `macros.rs` and `imports.rs`. +use crate::errors::ImportsCannotReferTo; use crate::BindingKey; use crate::{path_names_to_string, rustdoc, BindingError, Finalize, LexicalScopeBinding}; use crate::{Module, ModuleOrUniformRoot, NameBinding, ParentScope, PathResult}; @@ -2244,12 +2245,11 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { _ => &[TypeNS], }; let report_error = |this: &Self, ns| { - let what = if ns == TypeNS { "type parameters" } else { "local variables" }; if this.should_report_errs() { - this.r - .tcx - .sess - .span_err(ident.span, format!("imports cannot refer to {}", what)); + let what = if ns == TypeNS { "type parameters" } else { "local variables" }; + + let err = ImportsCannotReferTo { span: ident.span, what }; + this.r.tcx.sess.create_err(err).emit(); } }; |
