@@ -12,8 +12,8 @@ use rustc_data_structures::stack::ensure_sufficient_stack;
1212use rustc_data_structures:: unord:: UnordMap ;
1313use rustc_errors:: codes:: * ;
1414use rustc_errors:: {
15- Applicability , Diag , ErrorGuaranteed , MultiSpan , StashKey , Subdiagnostic , listify , pluralize ,
16- struct_span_code_err,
15+ Applicability , Diag , ErrorGuaranteed , MultiSpan , StashKey , Subdiagnostic , Suggestions , listify ,
16+ pluralize , struct_span_code_err,
1717} ;
1818use rustc_hir:: attrs:: AttributeKind ;
1919use rustc_hir:: def:: { CtorKind , DefKind , Res } ;
@@ -1830,6 +1830,40 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18301830 fields : & ' tcx [ hir:: ExprField < ' tcx > ] ,
18311831 base_expr : & ' tcx hir:: StructTailExpr < ' tcx > ,
18321832 ) -> Ty < ' tcx > {
1833+ // FIXME(fmease): Move this into separate method.
1834+ // FIXME(fmease): This doesn't get called given `(_ { x: () }).x` (`hir::Field`).
1835+ // Figure out why.
1836+ if let QPath :: Resolved ( None , hir:: Path { res : Res :: Err , segments, .. } ) = qpath
1837+ && let [ segment] = segments
1838+ && segment. ident . name == kw:: Empty
1839+ && let Expectation :: ExpectHasType ( ty) = expected
1840+ && ty. is_adt ( )
1841+ && let Some ( guar) = self . dcx ( ) . try_steal_modify_and_emit_err (
1842+ expr. span ,
1843+ StashKey :: StructLitNoType ,
1844+ |err| {
1845+ // The parser provided a sub-optimal `HasPlaceholders` suggestion for the type.
1846+ // We are typeck and have the real type, so remove that and suggest the actual type.
1847+ if let Suggestions :: Enabled ( suggestions) = & mut err. suggestions {
1848+ suggestions. clear ( ) ;
1849+ }
1850+
1851+ err. span_suggestion (
1852+ qpath. span ( ) ,
1853+ // FIXME(fmease): Make this translatable.
1854+ "replace it with the correct type" ,
1855+ // FIXME(fmease): This doesn't qualify paths within the type appropriately.
1856+ // FIXME(fmease): This doesn't use turbofish when emitting generic args.
1857+ // FIXME(fmease): Make the type suggestable.
1858+ ty. to_string ( ) ,
1859+ Applicability :: MaybeIncorrect ,
1860+ ) ;
1861+ } ,
1862+ )
1863+ {
1864+ return Ty :: new_error ( self . tcx , guar) ;
1865+ }
1866+
18331867 // Find the relevant variant
18341868 let ( variant, adt_ty) = match self . check_struct_path ( qpath, expr. hir_id ) {
18351869 Ok ( data) => data,
0 commit comments