Skip to content

Commit 8fa9003

Browse files
committed
Add translatable diagnostic for changing import binding
1 parent 0c2c243 commit 8fa9003

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

compiler/rustc_resolve/messages.ftl

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

compiler/rustc_resolve/src/diagnostics.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use rustc_span::symbol::{kw, sym, Ident, Symbol};
3030
use rustc_span::{BytePos, Span, SyntaxContext};
3131
use thin_vec::ThinVec;
3232

33+
use crate::errors::{ChangeImportBinding, ChangeImportBindingSuggestion};
3334
use crate::imports::{Import, ImportKind};
3435
use crate::late::{PatternSource, Rib};
3536
use crate::path_names_to_string;
@@ -376,16 +377,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
376377
_ => unreachable!(),
377378
}
378379

379-
let rename_msg = "you can use `as` to change the binding name of the import";
380380
if let Some(suggestion) = suggestion {
381-
err.span_suggestion(
382-
binding_span,
383-
rename_msg,
384-
suggestion,
385-
Applicability::MaybeIncorrect,
386-
);
381+
err.subdiagnostic(ChangeImportBindingSuggestion { span: binding_span, suggestion });
387382
} else {
388-
err.span_label(binding_span, rename_msg);
383+
err.subdiagnostic(ChangeImportBinding { span: binding_span });
389384
}
390385
}
391386

compiler/rustc_resolve/src/errors.rs

+19
Original file line numberDiff line numberDiff line change
@@ -586,3 +586,22 @@ pub(crate) enum ParamKindInEnumDiscriminant {
586586
#[note(resolve_lifetime_param_in_enum_discriminant)]
587587
Lifetime,
588588
}
589+
590+
#[derive(Subdiagnostic)]
591+
#[label(resolve_change_import_binding)]
592+
pub(crate) struct ChangeImportBinding {
593+
#[primary_span]
594+
pub(crate) span: Span,
595+
}
596+
597+
#[derive(Subdiagnostic)]
598+
#[suggestion(
599+
resolve_change_import_binding,
600+
code = "{suggestion}",
601+
applicability = "maybe-incorrect"
602+
)]
603+
pub(crate) struct ChangeImportBindingSuggestion {
604+
#[primary_span]
605+
pub(crate) span: Span,
606+
pub(crate) suggestion: String,
607+
}

0 commit comments

Comments
 (0)