@@ -1408,19 +1408,38 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
14081408 self . suggest_using_enum_variant ( err, source, def_id, span) ;
14091409 }
14101410 ( Res :: Def ( DefKind :: Struct , def_id) , source) if ns == ValueNS => {
1411- let ( ctor_def, ctor_vis, fields) =
1412- if let Some ( struct_ctor) = self . r . struct_constructors . get ( & def_id) . cloned ( ) {
1413- if let PathSource :: Expr ( Some ( parent) ) = source {
1414- if let ExprKind :: Field ( ..) | ExprKind :: MethodCall ( ..) = parent. kind {
1415- bad_struct_syntax_suggestion ( def_id) ;
1416- return true ;
1417- }
1411+ let struct_ctor = match def_id. as_local ( ) {
1412+ Some ( def_id) => self . r . struct_constructors . get ( & def_id) . cloned ( ) ,
1413+ None => {
1414+ let ctor = self . r . cstore ( ) . ctor_untracked ( def_id) ;
1415+ ctor. map ( |( ctor_kind, ctor_def_id) | {
1416+ let ctor_res =
1417+ Res :: Def ( DefKind :: Ctor ( CtorOf :: Struct , ctor_kind) , ctor_def_id) ;
1418+ let ctor_vis = self . r . tcx . visibility ( ctor_def_id) ;
1419+ let field_visibilities = self
1420+ . r
1421+ . tcx
1422+ . associated_item_def_ids ( def_id)
1423+ . iter ( )
1424+ . map ( |field_id| self . r . tcx . visibility ( field_id) )
1425+ . collect ( ) ;
1426+ ( ctor_res, ctor_vis, field_visibilities)
1427+ } )
1428+ }
1429+ } ;
1430+
1431+ let ( ctor_def, ctor_vis, fields) = if let Some ( struct_ctor) = struct_ctor {
1432+ if let PathSource :: Expr ( Some ( parent) ) = source {
1433+ if let ExprKind :: Field ( ..) | ExprKind :: MethodCall ( ..) = parent. kind {
1434+ bad_struct_syntax_suggestion ( def_id) ;
1435+ return true ;
14181436 }
1419- struct_ctor
1420- } else {
1421- bad_struct_syntax_suggestion ( def_id) ;
1422- return true ;
1423- } ;
1437+ }
1438+ struct_ctor
1439+ } else {
1440+ bad_struct_syntax_suggestion ( def_id) ;
1441+ return true ;
1442+ } ;
14241443
14251444 let is_accessible = self . r . is_accessible_from ( ctor_vis, self . parent_scope . module ) ;
14261445 if !is_expected ( ctor_def) || is_accessible {
0 commit comments