@@ -1991,18 +1991,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1991
1991
adt_ty : Ty < ' tcx > ,
1992
1992
expected : Expectation < ' tcx > ,
1993
1993
expr : & hir:: Expr < ' _ > ,
1994
- span : Span ,
1994
+ path_span : Span ,
1995
1995
variant : & ' tcx ty:: VariantDef ,
1996
1996
hir_fields : & ' tcx [ hir:: ExprField < ' tcx > ] ,
1997
1997
base_expr : & ' tcx hir:: StructTailExpr < ' tcx > ,
1998
1998
) {
1999
1999
let tcx = self . tcx ;
2000
2000
2001
- let adt_ty = self . try_structurally_resolve_type ( span , adt_ty) ;
2001
+ let adt_ty = self . try_structurally_resolve_type ( path_span , adt_ty) ;
2002
2002
let adt_ty_hint = expected. only_has_type ( self ) . and_then ( |expected| {
2003
2003
self . fudge_inference_if_ok ( || {
2004
2004
let ocx = ObligationCtxt :: new ( self ) ;
2005
- ocx. sup ( & self . misc ( span ) , self . param_env , expected, adt_ty) ?;
2005
+ ocx. sup ( & self . misc ( path_span ) , self . param_env , expected, adt_ty) ?;
2006
2006
if !ocx. select_where_possible ( ) . is_empty ( ) {
2007
2007
return Err ( TypeError :: Mismatch ) ;
2008
2008
}
@@ -2012,11 +2012,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2012
2012
} ) ;
2013
2013
if let Some ( adt_ty_hint) = adt_ty_hint {
2014
2014
// re-link the variables that the fudging above can create.
2015
- self . demand_eqtype ( span , adt_ty_hint, adt_ty) ;
2015
+ self . demand_eqtype ( path_span , adt_ty_hint, adt_ty) ;
2016
2016
}
2017
2017
2018
2018
let ty:: Adt ( adt, args) = adt_ty. kind ( ) else {
2019
- span_bug ! ( span , "non-ADT passed to check_expr_struct_fields" ) ;
2019
+ span_bug ! ( path_span , "non-ADT passed to check_expr_struct_fields" ) ;
2020
2020
} ;
2021
2021
let adt_kind = adt. adt_kind ( ) ;
2022
2022
@@ -2107,7 +2107,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2107
2107
if adt_kind == AdtKind :: Union && hir_fields. len ( ) != 1 {
2108
2108
struct_span_code_err ! (
2109
2109
self . dcx( ) ,
2110
- span ,
2110
+ path_span ,
2111
2111
E0784 ,
2112
2112
"union expressions should have exactly one field" ,
2113
2113
)
@@ -2167,6 +2167,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2167
2167
} ) ;
2168
2168
return ;
2169
2169
}
2170
+ if variant. fields . is_empty ( ) {
2171
+ let mut err = self . dcx ( ) . struct_span_err (
2172
+ span,
2173
+ format ! (
2174
+ "`{adt_ty}` has no fields, `..` needs at least one default field in the \
2175
+ struct definition",
2176
+ ) ,
2177
+ ) ;
2178
+ err. span_label ( path_span, "this type has no fields" ) ;
2179
+ err. emit ( ) ;
2180
+ }
2170
2181
if !missing_mandatory_fields. is_empty ( ) {
2171
2182
let s = pluralize ! ( missing_mandatory_fields. len( ) ) ;
2172
2183
let fields: Vec < _ > =
@@ -2316,11 +2327,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2316
2327
. collect ( ) ;
2317
2328
2318
2329
if !private_fields. is_empty ( ) {
2319
- self . report_private_fields ( adt_ty, span, expr. span , private_fields, hir_fields) ;
2330
+ self . report_private_fields (
2331
+ adt_ty,
2332
+ path_span,
2333
+ expr. span ,
2334
+ private_fields,
2335
+ hir_fields,
2336
+ ) ;
2320
2337
} else {
2321
2338
self . report_missing_fields (
2322
2339
adt_ty,
2323
- span ,
2340
+ path_span ,
2324
2341
remaining_fields,
2325
2342
variant,
2326
2343
hir_fields,
0 commit comments