@@ -444,11 +444,12 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver<'_>,
444
444
err
445
445
}
446
446
ResolutionError :: BindingShadowsSomethingUnacceptable ( what_binding, name, binding) => {
447
- let shadows_what = binding. descr ( ) ;
447
+ let res = binding. res ( ) ;
448
+ let shadows_what = res. descr ( ) ;
448
449
let mut err = struct_span_err ! ( resolver. session, span, E0530 , "{}s cannot shadow {}s" ,
449
450
what_binding, shadows_what) ;
450
451
err. span_label ( span, format ! ( "cannot be named the same as {} {}" ,
451
- binding . article( ) , shadows_what) ) ;
452
+ res . article( ) , shadows_what) ) ;
452
453
let participle = if binding. is_import ( ) { "imported" } else { "defined" } ;
453
454
let msg = format ! ( "the {} `{}` is {} here" , shadows_what, name, participle) ;
454
455
err. span_label ( binding. span , msg) ;
@@ -1243,13 +1244,6 @@ impl<'a> ModuleData<'a> {
1243
1244
}
1244
1245
}
1245
1246
1246
- fn def_kind ( & self ) -> Option < DefKind > {
1247
- match self . kind {
1248
- ModuleKind :: Def ( kind, ..) => Some ( kind) ,
1249
- _ => None ,
1250
- }
1251
- }
1252
-
1253
1247
fn def_id ( & self ) -> Option < DefId > {
1254
1248
match self . kind {
1255
1249
ModuleKind :: Def ( _, def_id, _) => Some ( def_id) ,
@@ -1494,14 +1488,6 @@ impl<'a> NameBinding<'a> {
1494
1488
self . res ( ) . macro_kind ( )
1495
1489
}
1496
1490
1497
- fn descr ( & self ) -> & ' static str {
1498
- if self . is_extern_crate ( ) { "extern crate" } else { self . res ( ) . descr ( ) }
1499
- }
1500
-
1501
- fn article ( & self ) -> & ' static str {
1502
- if self . is_extern_crate ( ) { "an" } else { self . res ( ) . article ( ) }
1503
- }
1504
-
1505
1491
// Suppose that we resolved macro invocation with `invoc_parent_expansion` to binding `binding`
1506
1492
// at some expansion round `max(invoc, binding)` when they both emerged from macros.
1507
1493
// Then this function returns `true` if `self` may emerge from a macro *after* that
@@ -4675,6 +4661,7 @@ impl<'a> Resolver<'a> {
4675
4661
}
4676
4662
4677
4663
fn binding_description ( & self , b : & NameBinding < ' _ > , ident : Ident , from_prelude : bool ) -> String {
4664
+ let res = b. res ( ) ;
4678
4665
if b. span . is_dummy ( ) {
4679
4666
let add_built_in = match b. res ( ) {
4680
4667
// These already contain the "built-in" prefix or look bad with it.
@@ -4692,13 +4679,13 @@ impl<'a> Resolver<'a> {
4692
4679
( "" , "" )
4693
4680
} ;
4694
4681
4695
- let article = if built_in. is_empty ( ) { b . article ( ) } else { "a" } ;
4682
+ let article = if built_in. is_empty ( ) { res . article ( ) } else { "a" } ;
4696
4683
format ! ( "{a}{built_in} {thing}{from}" ,
4697
- a = article, thing = b . descr( ) , built_in = built_in, from = from)
4684
+ a = article, thing = res . descr( ) , built_in = built_in, from = from)
4698
4685
} else {
4699
4686
let introduced = if b. is_import ( ) { "imported" } else { "defined" } ;
4700
4687
format ! ( "the {thing} {introduced} here" ,
4701
- thing = b . descr( ) , introduced = introduced)
4688
+ thing = res . descr( ) , introduced = introduced)
4702
4689
}
4703
4690
}
4704
4691
@@ -4721,6 +4708,7 @@ impl<'a> Resolver<'a> {
4721
4708
let note_msg = format ! ( "`{ident}` could{also} refer to {what}" ,
4722
4709
ident = ident, also = also, what = what) ;
4723
4710
4711
+ let thing = b. res ( ) . descr ( ) ;
4724
4712
let mut help_msgs = Vec :: new ( ) ;
4725
4713
if b. is_glob_import ( ) && ( kind == AmbiguityKind :: GlobVsGlob ||
4726
4714
kind == AmbiguityKind :: GlobVsExpanded ||
@@ -4732,18 +4720,18 @@ impl<'a> Resolver<'a> {
4732
4720
if b. is_extern_crate ( ) && ident. span . rust_2018 ( ) {
4733
4721
help_msgs. push ( format ! (
4734
4722
"use `::{ident}` to refer to this {thing} unambiguously" ,
4735
- ident = ident, thing = b . descr ( ) ,
4723
+ ident = ident, thing = thing ,
4736
4724
) )
4737
4725
}
4738
4726
if misc == AmbiguityErrorMisc :: SuggestCrate {
4739
4727
help_msgs. push ( format ! (
4740
4728
"use `crate::{ident}` to refer to this {thing} unambiguously" ,
4741
- ident = ident, thing = b . descr ( ) ,
4729
+ ident = ident, thing = thing ,
4742
4730
) )
4743
4731
} else if misc == AmbiguityErrorMisc :: SuggestSelf {
4744
4732
help_msgs. push ( format ! (
4745
4733
"use `self::{ident}` to refer to this {thing} unambiguously" ,
4746
- ident = ident, thing = b . descr ( ) ,
4734
+ ident = ident, thing = thing ,
4747
4735
) )
4748
4736
}
4749
4737
@@ -4781,7 +4769,7 @@ impl<'a> Resolver<'a> {
4781
4769
for & PrivacyError ( dedup_span, ident, binding) in & self . privacy_errors {
4782
4770
if reported_spans. insert ( dedup_span) {
4783
4771
span_err ! ( self . session, ident. span, E0603 , "{} `{}` is private" ,
4784
- binding. descr( ) , ident. name) ;
4772
+ binding. res ( ) . descr( ) , ident. name) ;
4785
4773
}
4786
4774
}
4787
4775
}
0 commit comments