@@ -2330,6 +2330,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2330
2330
let base_ty = self . structurally_resolve_type ( base. span , base_ty) ;
2331
2331
let mut private_candidate = None ;
2332
2332
let mut autoderef = self . autoderef ( expr. span , base_ty) ;
2333
+ let mut recovered_variant = None ;
2333
2334
while let Some ( ( deref_base_ty, _) ) = autoderef. next ( ) {
2334
2335
debug ! ( "deref_base_ty: {:?}" , deref_base_ty) ;
2335
2336
match deref_base_ty. kind ( ) {
@@ -2342,6 +2343,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2342
2343
let mut last_ty = None ;
2343
2344
let mut nested_fields = Vec :: new ( ) ;
2344
2345
let mut index = None ;
2346
+ if let Err ( guard) = adt_def. non_enum_variant ( ) . has_errors ( ) {
2347
+ recovered_variant = Some ( guard) ;
2348
+ break ;
2349
+ }
2345
2350
while let Some ( idx) = self . tcx . find_field ( ( adt_def. did ( ) , ident) ) {
2346
2351
let & mut first_idx = index. get_or_insert ( idx) ;
2347
2352
let field = & adt_def. non_enum_variant ( ) . fields [ idx] ;
@@ -2420,7 +2425,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2420
2425
) {
2421
2426
self . ban_take_value_of_method ( expr, base_ty, field)
2422
2427
} else if !base_ty. is_primitive_ty ( ) {
2423
- self . ban_nonexisting_field ( field, base, expr, base_ty)
2428
+ recovered_variant
2429
+ . unwrap_or_else ( || self . ban_nonexisting_field ( field, base, expr, base_ty) )
2424
2430
} else {
2425
2431
let field_name = field. to_string ( ) ;
2426
2432
let mut err = type_error_struct ! (
@@ -2545,17 +2551,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2545
2551
ident, base, expr, base_ty
2546
2552
) ;
2547
2553
2548
- for ( ty, _) in self . autoderef ( expr. span , base_ty) {
2549
- if let ty:: Adt ( def, _) = ty. kind ( )
2550
- && !def. is_enum ( )
2551
- {
2552
- let variant = def. non_enum_variant ( ) ;
2553
- if let Err ( taint) = variant. has_errors ( ) {
2554
- return taint;
2555
- }
2556
- }
2557
- }
2558
-
2559
2554
let mut err = self . no_such_field_err ( ident, base_ty, base. hir_id ) ;
2560
2555
2561
2556
match * base_ty. peel_refs ( ) . kind ( ) {
0 commit comments