Add translatable diagnostic for changing import binding

This commit is contained in:
Tom Martin 2023-06-18 07:19:19 +01:00
parent 0c2c243342
commit 8fa9003621
No known key found for this signature in database
GPG Key ID: 73A733F9629F5AC5
3 changed files with 25 additions and 8 deletions

View File

@ -262,3 +262,6 @@ resolve_variable_bound_with_different_mode =
variable `{$variable_name}` is bound inconsistently across alternatives separated by `|`
.label = bound in different ways
.first_binding_span = first binding
resolve_change_import_binding =
you can use `as` to change the binding name of the import

View File

@ -30,6 +30,7 @@ use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::{BytePos, Span, SyntaxContext};
use thin_vec::ThinVec;
use crate::errors::{ChangeImportBinding, ChangeImportBindingSuggestion};
use crate::imports::{Import, ImportKind};
use crate::late::{PatternSource, Rib};
use crate::path_names_to_string;
@ -376,16 +377,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
_ => unreachable!(),
}
let rename_msg = "you can use `as` to change the binding name of the import";
if let Some(suggestion) = suggestion {
err.span_suggestion(
binding_span,
rename_msg,
suggestion,
Applicability::MaybeIncorrect,
);
err.subdiagnostic(ChangeImportBindingSuggestion { span: binding_span, suggestion });
} else {
err.span_label(binding_span, rename_msg);
err.subdiagnostic(ChangeImportBinding { span: binding_span });
}
}

View File

@ -586,3 +586,22 @@ pub(crate) enum ParamKindInEnumDiscriminant {
#[note(resolve_lifetime_param_in_enum_discriminant)]
Lifetime,
}
#[derive(Subdiagnostic)]
#[label(resolve_change_import_binding)]
pub(crate) struct ChangeImportBinding {
#[primary_span]
pub(crate) span: Span,
}
#[derive(Subdiagnostic)]
#[suggestion(
resolve_change_import_binding,
code = "{suggestion}",
applicability = "maybe-incorrect"
)]
pub(crate) struct ChangeImportBindingSuggestion {
#[primary_span]
pub(crate) span: Span,
pub(crate) suggestion: String,
}