@@ -443,11 +443,12 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver<'_>,
443
443
err
444
444
}
445
445
ResolutionError :: BindingShadowsSomethingUnacceptable ( what_binding, name, binding) => {
446
- let shadows_what = binding. descr ( ) ;
446
+ let res = binding. res ( ) ;
447
+ let shadows_what = res. descr ( ) ;
447
448
let mut err = struct_span_err ! ( resolver. session, span, E0530 , "{}s cannot shadow {}s" ,
448
449
what_binding, shadows_what) ;
449
450
err. span_label ( span, format ! ( "cannot be named the same as {} {}" ,
450
- binding . article( ) , shadows_what) ) ;
451
+ res . article( ) , shadows_what) ) ;
451
452
let participle = if binding. is_import ( ) { "imported" } else { "defined" } ;
452
453
let msg = format ! ( "the {} `{}` is {} here" , shadows_what, name, participle) ;
453
454
err. span_label ( binding. span , msg) ;
@@ -1242,13 +1243,6 @@ impl<'a> ModuleData<'a> {
1242
1243
}
1243
1244
}
1244
1245
1245
- fn def_kind ( & self ) -> Option < DefKind > {
1246
- match self . kind {
1247
- ModuleKind :: Def ( kind, ..) => Some ( kind) ,
1248
- _ => None ,
1249
- }
1250
- }
1251
-
1252
1246
fn def_id ( & self ) -> Option < DefId > {
1253
1247
match self . kind {
1254
1248
ModuleKind :: Def ( _, def_id, _) => Some ( def_id) ,
@@ -1493,14 +1487,6 @@ impl<'a> NameBinding<'a> {
1493
1487
self . res ( ) . macro_kind ( )
1494
1488
}
1495
1489
1496
- fn descr ( & self ) -> & ' static str {
1497
- if self . is_extern_crate ( ) { "extern crate" } else { self . res ( ) . descr ( ) }
1498
- }
1499
-
1500
- fn article ( & self ) -> & ' static str {
1501
- if self . is_extern_crate ( ) { "an" } else { self . res ( ) . article ( ) }
1502
- }
1503
-
1504
1490
// Suppose that we resolved macro invocation with `invoc_parent_expansion` to binding `binding`
1505
1491
// at some expansion round `max(invoc, binding)` when they both emerged from macros.
1506
1492
// Then this function returns `true` if `self` may emerge from a macro *after* that
@@ -4691,6 +4677,7 @@ impl<'a> Resolver<'a> {
4691
4677
}
4692
4678
4693
4679
fn binding_description ( & self , b : & NameBinding < ' _ > , ident : Ident , from_prelude : bool ) -> String {
4680
+ let res = b. res ( ) ;
4694
4681
if b. span . is_dummy ( ) {
4695
4682
let add_built_in = match b. res ( ) {
4696
4683
// These already contain the "built-in" prefix or look bad with it.
@@ -4708,13 +4695,13 @@ impl<'a> Resolver<'a> {
4708
4695
( "" , "" )
4709
4696
} ;
4710
4697
4711
- let article = if built_in. is_empty ( ) { b . article ( ) } else { "a" } ;
4698
+ let article = if built_in. is_empty ( ) { res . article ( ) } else { "a" } ;
4712
4699
format ! ( "{a}{built_in} {thing}{from}" ,
4713
- a = article, thing = b . descr( ) , built_in = built_in, from = from)
4700
+ a = article, thing = res . descr( ) , built_in = built_in, from = from)
4714
4701
} else {
4715
4702
let introduced = if b. is_import ( ) { "imported" } else { "defined" } ;
4716
4703
format ! ( "the {thing} {introduced} here" ,
4717
- thing = b . descr( ) , introduced = introduced)
4704
+ thing = res . descr( ) , introduced = introduced)
4718
4705
}
4719
4706
}
4720
4707
@@ -4737,6 +4724,7 @@ impl<'a> Resolver<'a> {
4737
4724
let note_msg = format ! ( "`{ident}` could{also} refer to {what}" ,
4738
4725
ident = ident, also = also, what = what) ;
4739
4726
4727
+ let thing = b. res ( ) . descr ( ) ;
4740
4728
let mut help_msgs = Vec :: new ( ) ;
4741
4729
if b. is_glob_import ( ) && ( kind == AmbiguityKind :: GlobVsGlob ||
4742
4730
kind == AmbiguityKind :: GlobVsExpanded ||
@@ -4748,18 +4736,18 @@ impl<'a> Resolver<'a> {
4748
4736
if b. is_extern_crate ( ) && ident. span . rust_2018 ( ) {
4749
4737
help_msgs. push ( format ! (
4750
4738
"use `::{ident}` to refer to this {thing} unambiguously" ,
4751
- ident = ident, thing = b . descr ( ) ,
4739
+ ident = ident, thing = thing ,
4752
4740
) )
4753
4741
}
4754
4742
if misc == AmbiguityErrorMisc :: SuggestCrate {
4755
4743
help_msgs. push ( format ! (
4756
4744
"use `crate::{ident}` to refer to this {thing} unambiguously" ,
4757
- ident = ident, thing = b . descr ( ) ,
4745
+ ident = ident, thing = thing ,
4758
4746
) )
4759
4747
} else if misc == AmbiguityErrorMisc :: SuggestSelf {
4760
4748
help_msgs. push ( format ! (
4761
4749
"use `self::{ident}` to refer to this {thing} unambiguously" ,
4762
- ident = ident, thing = b . descr ( ) ,
4750
+ ident = ident, thing = thing ,
4763
4751
) )
4764
4752
}
4765
4753
@@ -4797,7 +4785,7 @@ impl<'a> Resolver<'a> {
4797
4785
for & PrivacyError ( dedup_span, ident, binding) in & self . privacy_errors {
4798
4786
if reported_spans. insert ( dedup_span) {
4799
4787
span_err ! ( self . session, ident. span, E0603 , "{} `{}` is private" ,
4800
- binding. descr( ) , ident. name) ;
4788
+ binding. res ( ) . descr( ) , ident. name) ;
4801
4789
}
4802
4790
}
4803
4791
}
0 commit comments