Add translatable diagnostic for invalid imports
This commit is contained in:
parent
8fa9003621
commit
50c971a0b7
3 changed files with 16 additions and 5 deletions
|
@ -265,3 +265,6 @@ resolve_variable_bound_with_different_mode =
|
||||||
|
|
||||||
resolve_change_import_binding =
|
resolve_change_import_binding =
|
||||||
you can use `as` to change the binding name of the import
|
you can use `as` to change the binding name of the import
|
||||||
|
|
||||||
|
resolve_imports_cannot_refer_to =
|
||||||
|
imports cannot refer to {$what}
|
|
@ -605,3 +605,11 @@ pub(crate) struct ChangeImportBindingSuggestion {
|
||||||
pub(crate) span: Span,
|
pub(crate) span: Span,
|
||||||
pub(crate) suggestion: String,
|
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,
|
||||||
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
//! If you wonder why there's no `early.rs`, that's because it's split into three files -
|
//! 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`.
|
//! `build_reduced_graph.rs`, `macros.rs` and `imports.rs`.
|
||||||
|
|
||||||
|
use crate::errors::ImportsCannotReferTo;
|
||||||
use crate::BindingKey;
|
use crate::BindingKey;
|
||||||
use crate::{path_names_to_string, rustdoc, BindingError, Finalize, LexicalScopeBinding};
|
use crate::{path_names_to_string, rustdoc, BindingError, Finalize, LexicalScopeBinding};
|
||||||
use crate::{Module, ModuleOrUniformRoot, NameBinding, ParentScope, PathResult};
|
use crate::{Module, ModuleOrUniformRoot, NameBinding, ParentScope, PathResult};
|
||||||
|
@ -2244,12 +2245,11 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
_ => &[TypeNS],
|
_ => &[TypeNS],
|
||||||
};
|
};
|
||||||
let report_error = |this: &Self, ns| {
|
let report_error = |this: &Self, ns| {
|
||||||
let what = if ns == TypeNS { "type parameters" } else { "local variables" };
|
|
||||||
if this.should_report_errs() {
|
if this.should_report_errs() {
|
||||||
this.r
|
let what = if ns == TypeNS { "type parameters" } else { "local variables" };
|
||||||
.tcx
|
|
||||||
.sess
|
let err = ImportsCannotReferTo { span: ident.span, what };
|
||||||
.span_err(ident.span, format!("imports cannot refer to {}", what));
|
this.r.tcx.sess.create_err(err).emit();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue