@@ -1875,24 +1875,15 @@ fn check_variances_for_type_defn<'tcx>(
1875
1875
item : & ' tcx hir:: Item < ' tcx > ,
1876
1876
hir_generics : & hir:: Generics < ' tcx > ,
1877
1877
) {
1878
- let identity_args = ty:: GenericArgs :: identity_for_item ( tcx, item. owner_id ) ;
1879
-
1880
1878
match item. kind {
1881
1879
ItemKind :: Enum ( ..) | ItemKind :: Struct ( ..) | ItemKind :: Union ( ..) => {
1882
- for field in tcx. adt_def ( item. owner_id ) . all_fields ( ) {
1883
- if field. ty ( tcx, identity_args) . references_error ( ) {
1884
- return ;
1885
- }
1886
- }
1880
+ // Ok
1887
1881
}
1888
1882
ItemKind :: TyAlias ( ..) => {
1889
1883
assert ! (
1890
1884
tcx. type_alias_is_lazy( item. owner_id) ,
1891
1885
"should not be computing variance of non-weak type alias"
1892
1886
) ;
1893
- if tcx. type_of ( item. owner_id ) . skip_binder ( ) . references_error ( ) {
1894
- return ;
1895
- }
1896
1887
}
1897
1888
kind => span_bug ! ( item. span, "cannot compute the variances of {kind:?}" ) ,
1898
1889
}
@@ -1955,6 +1946,15 @@ fn check_variances_for_type_defn<'tcx>(
1955
1946
continue ;
1956
1947
}
1957
1948
1949
+ // Look for `ErrorGuaranteed` deeply within this type.
1950
+ if let ControlFlow :: Break ( ErrorGuaranteed { .. } ) = tcx
1951
+ . type_of ( item. owner_id )
1952
+ . instantiate_identity ( )
1953
+ . visit_with ( & mut HasErrorDeep { tcx, seen : Default :: default ( ) } )
1954
+ {
1955
+ continue ;
1956
+ }
1957
+
1958
1958
match hir_param. name {
1959
1959
hir:: ParamName :: Error => { }
1960
1960
_ => {
@@ -1965,6 +1965,46 @@ fn check_variances_for_type_defn<'tcx>(
1965
1965
}
1966
1966
}
1967
1967
1968
+ /// Look for `ErrorGuaranteed` deeply within structs' (unsubstituted) fields.
1969
+ struct HasErrorDeep < ' tcx > {
1970
+ tcx : TyCtxt < ' tcx > ,
1971
+ seen : FxHashSet < DefId > ,
1972
+ }
1973
+ impl < ' tcx > TypeVisitor < TyCtxt < ' tcx > > for HasErrorDeep < ' tcx > {
1974
+ type Result = ControlFlow < ErrorGuaranteed > ;
1975
+
1976
+ fn visit_ty ( & mut self , ty : Ty < ' tcx > ) -> Self :: Result {
1977
+ match * ty. kind ( ) {
1978
+ ty:: Adt ( def, _) => {
1979
+ if self . seen . insert ( def. did ( ) ) {
1980
+ for field in def. all_fields ( ) {
1981
+ self . tcx . type_of ( field. did ) . instantiate_identity ( ) . visit_with ( self ) ?;
1982
+ }
1983
+ }
1984
+ }
1985
+ ty:: Error ( guar) => return ControlFlow :: Break ( guar) ,
1986
+ _ => { }
1987
+ }
1988
+ ty. super_visit_with ( self )
1989
+ }
1990
+
1991
+ fn visit_region ( & mut self , r : ty:: Region < ' tcx > ) -> Self :: Result {
1992
+ if let Err ( guar) = r. error_reported ( ) {
1993
+ ControlFlow :: Break ( guar)
1994
+ } else {
1995
+ ControlFlow :: Continue ( ( ) )
1996
+ }
1997
+ }
1998
+
1999
+ fn visit_const ( & mut self , c : ty:: Const < ' tcx > ) -> Self :: Result {
2000
+ if let Err ( guar) = c. error_reported ( ) {
2001
+ ControlFlow :: Break ( guar)
2002
+ } else {
2003
+ ControlFlow :: Continue ( ( ) )
2004
+ }
2005
+ }
2006
+ }
2007
+
1968
2008
fn report_bivariance < ' tcx > (
1969
2009
tcx : TyCtxt < ' tcx > ,
1970
2010
param : & ' tcx hir:: GenericParam < ' tcx > ,
0 commit comments