@@ -30,7 +30,7 @@ use rustc::hir::def::{self, DefKind, PartialRes, CtorKind, CtorOf, NonMacroAttrK
3030use rustc:: hir:: def:: Namespace :: * ;
3131use rustc:: hir:: def_id:: { CRATE_DEF_INDEX , LOCAL_CRATE , DefId } ;
3232use rustc:: hir:: { TraitMap , GlobMap } ;
33- use rustc:: ty;
33+ use rustc:: ty:: { self , DefIdTree } ;
3434use rustc:: util:: nodemap:: { NodeMap , NodeSet , FxHashMap , FxHashSet , DefIdMap } ;
3535use rustc:: span_bug;
3636
@@ -1006,7 +1006,7 @@ impl<'a> AsMut<Resolver<'a>> for Resolver<'a> {
10061006 fn as_mut ( & mut self ) -> & mut Resolver < ' a > { self }
10071007}
10081008
1009- impl < ' a , ' b > ty :: DefIdTree for & ' a Resolver < ' b > {
1009+ impl < ' a , ' b > DefIdTree for & ' a Resolver < ' b > {
10101010 fn parent ( self , id : DefId ) -> Option < DefId > {
10111011 match id. krate {
10121012 LOCAL_CRATE => self . definitions . def_key ( id. index ) . parent ,
@@ -2391,23 +2391,17 @@ impl<'a> Resolver<'a> {
23912391 binding. res( ) . descr( ) ,
23922392 ident. name,
23932393 ) ;
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+ ) ;
24092404 }
2410- _ => { }
24112405 }
24122406 err. emit ( ) ;
24132407 }
0 commit comments