@@ -30,7 +30,7 @@ use rustc::hir::def::{self, DefKind, PartialRes, CtorKind, CtorOf, NonMacroAttrK
30
30
use rustc:: hir:: def:: Namespace :: * ;
31
31
use rustc:: hir:: def_id:: { CRATE_DEF_INDEX , LOCAL_CRATE , DefId } ;
32
32
use rustc:: hir:: { TraitMap , GlobMap } ;
33
- use rustc:: ty;
33
+ use rustc:: ty:: { self , DefIdTree } ;
34
34
use rustc:: util:: nodemap:: { NodeMap , NodeSet , FxHashMap , FxHashSet , DefIdMap } ;
35
35
use rustc:: span_bug;
36
36
@@ -1006,7 +1006,7 @@ impl<'a> AsMut<Resolver<'a>> for Resolver<'a> {
1006
1006
fn as_mut ( & mut self ) -> & mut Resolver < ' a > { self }
1007
1007
}
1008
1008
1009
- impl < ' a , ' b > ty :: DefIdTree for & ' a Resolver < ' b > {
1009
+ impl < ' a , ' b > DefIdTree for & ' a Resolver < ' b > {
1010
1010
fn parent ( self , id : DefId ) -> Option < DefId > {
1011
1011
match id. krate {
1012
1012
LOCAL_CRATE => self . definitions . def_key ( id. index ) . parent ,
@@ -2391,23 +2391,17 @@ impl<'a> Resolver<'a> {
2391
2391
binding. res( ) . descr( ) ,
2392
2392
ident. name,
2393
2393
) ;
2394
- // FIXME: use the ctor's `def_id` to check wether any of the fields is not visible
2395
- match binding. kind {
2396
- NameBindingKind :: Res ( Res :: Def ( DefKind :: Ctor (
2397
- CtorOf :: Struct ,
2398
- CtorKind :: Fn ,
2399
- ) , _def_id) , _) => {
2400
- err. note ( "a tuple struct constructor is private if any of its fields \
2401
- is private") ;
2402
- }
2403
- NameBindingKind :: Res ( Res :: Def ( DefKind :: Ctor (
2404
- CtorOf :: Variant ,
2405
- CtorKind :: Fn ,
2406
- ) , _def_id) , _) => {
2407
- err. note ( "a tuple variant constructor is private if any of its fields \
2408
- is private") ;
2394
+ if let NameBindingKind :: Res (
2395
+ Res :: Def ( DefKind :: Ctor ( CtorOf :: Struct , CtorKind :: Fn ) , ctor_def_id) , _
2396
+ ) = binding. kind {
2397
+ let def_id = ( & * self ) . parent ( ctor_def_id) . expect ( "no parent for a constructor" ) ;
2398
+ if let Some ( fields) = self . field_names . get ( & def_id) {
2399
+ let first_field = fields. first ( ) . expect ( "empty field list in the map" ) ;
2400
+ err. span_label (
2401
+ fields. iter ( ) . fold ( first_field. span , |acc, field| acc. to ( field. span ) ) ,
2402
+ "a tuple struct constructor is private if any of its fields is private" ,
2403
+ ) ;
2409
2404
}
2410
- _ => { }
2411
2405
}
2412
2406
err. emit ( ) ;
2413
2407
}
0 commit comments