@@ -2,7 +2,7 @@ use crate::callee::{self, DeferredCallResolution};
2
2
use crate :: errors:: CtorIsPrivate ;
3
3
use crate :: method:: { self , MethodCallee , SelfSource } ;
4
4
use crate :: rvalue_scopes;
5
- use crate :: { BreakableCtxt , Diverges , Expectation , FnCtxt , RawTy } ;
5
+ use crate :: { BreakableCtxt , Diverges , Expectation , FnCtxt } ;
6
6
use rustc_data_structures:: captures:: Captures ;
7
7
use rustc_data_structures:: fx:: FxHashSet ;
8
8
use rustc_errors:: { Applicability , Diagnostic , ErrorGuaranteed , MultiSpan , StashKey } ;
@@ -324,6 +324,26 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
324
324
)
325
325
}
326
326
327
+ // FIXME(-Ztrait-solver=next): This could be replaced with `try_structurally_resolve`
328
+ // calls after the new trait solver is stable.
329
+ /// TODO: I don't know what to call this.
330
+ pub ( super ) fn structurally_normalize_after_astconv (
331
+ & self ,
332
+ span : Span ,
333
+ value : Ty < ' tcx > ,
334
+ ) -> Ty < ' tcx > {
335
+ match self
336
+ . at ( & self . misc ( span) , self . param_env )
337
+ . structurally_normalize ( value, & mut * * self . inh . fulfillment_cx . borrow_mut ( ) )
338
+ {
339
+ Ok ( ty) => ty,
340
+ Err ( errors) => {
341
+ let guar = self . err_ctxt ( ) . report_fulfillment_errors ( & errors) ;
342
+ Ty :: new_error ( self . tcx , guar)
343
+ }
344
+ }
345
+ }
346
+
327
347
pub fn require_type_meets (
328
348
& self ,
329
349
ty : Ty < ' tcx > ,
@@ -374,37 +394,33 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
374
394
}
375
395
}
376
396
377
- pub fn handle_raw_ty ( & self , span : Span , ty : Ty < ' tcx > ) -> RawTy < ' tcx > {
378
- RawTy { raw : ty, normalized : self . normalize ( span, ty) }
379
- }
380
-
381
- pub fn to_ty ( & self , ast_t : & hir:: Ty < ' _ > ) -> RawTy < ' tcx > {
397
+ pub fn to_ty ( & self , ast_t : & hir:: Ty < ' _ > ) -> Ty < ' tcx > {
382
398
let t = self . astconv ( ) . ast_ty_to_ty ( ast_t) ;
383
399
self . register_wf_obligation ( t. into ( ) , ast_t. span , traits:: WellFormed ( None ) ) ;
384
- self . handle_raw_ty ( ast_t . span , t )
400
+ t
385
401
}
386
402
387
403
pub fn to_ty_saving_user_provided_ty ( & self , ast_ty : & hir:: Ty < ' _ > ) -> Ty < ' tcx > {
388
404
let ty = self . to_ty ( ast_ty) ;
389
405
debug ! ( "to_ty_saving_user_provided_ty: ty={:?}" , ty) ;
390
406
391
- if Self :: can_contain_user_lifetime_bounds ( ty. raw ) {
392
- let c_ty = self . canonicalize_response ( UserType :: Ty ( ty. raw ) ) ;
407
+ if Self :: can_contain_user_lifetime_bounds ( ty) {
408
+ let c_ty = self . canonicalize_response ( UserType :: Ty ( ty) ) ;
393
409
debug ! ( "to_ty_saving_user_provided_ty: c_ty={:?}" , c_ty) ;
394
410
self . typeck_results . borrow_mut ( ) . user_provided_types_mut ( ) . insert ( ast_ty. hir_id , c_ty) ;
395
411
}
396
412
397
- ty . normalized
413
+ self . normalize ( ast_ty . span , ty )
398
414
}
399
415
400
- pub ( super ) fn user_args_for_adt ( ty : RawTy < ' tcx > ) -> UserArgs < ' tcx > {
401
- match ( ty . raw . kind ( ) , ty . normalized . kind ( ) ) {
416
+ pub ( super ) fn user_args_for_adt ( raw : Ty < ' tcx > , normalized : Ty < ' tcx > ) -> UserArgs < ' tcx > {
417
+ match ( raw. kind ( ) , normalized. kind ( ) ) {
402
418
( ty:: Adt ( _, args) , _) => UserArgs { args, user_self_ty : None } ,
403
419
( _, ty:: Adt ( adt, args) ) => UserArgs {
404
420
args,
405
- user_self_ty : Some ( UserSelfTy { impl_def_id : adt. did ( ) , self_ty : ty . raw } ) ,
421
+ user_self_ty : Some ( UserSelfTy { impl_def_id : adt. did ( ) , self_ty : raw } ) ,
406
422
} ,
407
- _ => bug ! ( "non-adt type {:?}" , ty ) ,
423
+ _ => bug ! ( "non-adt type {:?}" , raw ) ,
408
424
}
409
425
}
410
426
@@ -817,7 +833,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
817
833
qpath : & ' tcx QPath < ' tcx > ,
818
834
hir_id : hir:: HirId ,
819
835
span : Span ,
820
- ) -> ( Res , Option < RawTy < ' tcx > > , & ' tcx [ hir:: PathSegment < ' tcx > ] ) {
836
+ ) -> ( Res , Option < Ty < ' tcx > > , & ' tcx [ hir:: PathSegment < ' tcx > ] ) {
821
837
debug ! (
822
838
"resolve_ty_and_res_fully_qualified_call: qpath={:?} hir_id={:?} span={:?}" ,
823
839
qpath, hir_id, span
@@ -841,23 +857,28 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
841
857
// We manually call `register_wf_obligation` in the success path
842
858
// below.
843
859
let ty = self . astconv ( ) . ast_ty_to_ty_in_path ( qself) ;
844
- ( self . handle_raw_ty ( span , ty ) , qself, segment)
860
+ ( ty , qself, segment)
845
861
}
846
862
QPath :: LangItem ( ..) => {
847
863
bug ! ( "`resolve_ty_and_res_fully_qualified_call` called on `LangItem`" )
848
864
}
849
865
} ;
866
+
867
+ // FIXME(-Ztrait-solver=next): Can use `try_structurally_resolve` after migration.
868
+ let normalized =
869
+ if !ty. is_ty_var ( ) { self . structurally_normalize_after_astconv ( span, ty) } else { ty } ;
870
+
850
871
if let Some ( & cached_result) = self . typeck_results . borrow ( ) . type_dependent_defs ( ) . get ( hir_id)
851
872
{
852
- self . register_wf_obligation ( ty. raw . into ( ) , qself. span , traits:: WellFormed ( None ) ) ;
873
+ self . register_wf_obligation ( ty. into ( ) , qself. span , traits:: WellFormed ( None ) ) ;
853
874
// Return directly on cache hit. This is useful to avoid doubly reporting
854
875
// errors with default match binding modes. See #44614.
855
876
let def = cached_result. map_or ( Res :: Err , |( kind, def_id) | Res :: Def ( kind, def_id) ) ;
856
877
return ( def, Some ( ty) , slice:: from_ref ( & * * item_segment) ) ;
857
878
}
858
879
let item_name = item_segment. ident ;
859
880
let result = self
860
- . resolve_fully_qualified_call ( span, item_name, ty . normalized , qself. span , hir_id)
881
+ . resolve_fully_qualified_call ( span, item_name, normalized, qself. span , hir_id)
861
882
. and_then ( |r| {
862
883
// lint bare trait if the method is found in the trait
863
884
if span. edition ( ) . at_least_rust_2021 ( ) && let Some ( mut diag) = self . tcx . sess . diagnostic ( ) . steal_diagnostic ( qself. span , StashKey :: TraitMissingMethod ) {
@@ -876,14 +897,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
876
897
} ;
877
898
878
899
let trait_missing_method =
879
- matches ! ( error, method:: MethodError :: NoMatch ( _) ) && ty . normalized . is_trait ( ) ;
900
+ matches ! ( error, method:: MethodError :: NoMatch ( _) ) && normalized. is_trait ( ) ;
880
901
// If we have a path like `MyTrait::missing_method`, then don't register
881
902
// a WF obligation for `dyn MyTrait` when method lookup fails. Otherwise,
882
903
// register a WF obligation so that we can detect any additional
883
904
// errors in the self type.
884
905
if !trait_missing_method {
885
906
self . register_wf_obligation (
886
- ty. raw . into ( ) ,
907
+ ty. into ( ) ,
887
908
qself. span ,
888
909
traits:: WellFormed ( None ) ,
889
910
) ;
@@ -902,7 +923,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
902
923
if item_name. name != kw:: Empty {
903
924
if let Some ( mut e) = self . report_method_error (
904
925
span,
905
- ty . normalized ,
926
+ normalized,
906
927
item_name,
907
928
SelfSource :: QPath ( qself) ,
908
929
error,
@@ -918,7 +939,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
918
939
} ) ;
919
940
920
941
if result. is_ok ( ) {
921
- self . register_wf_obligation ( ty. raw . into ( ) , qself. span , traits:: WellFormed ( None ) ) ;
942
+ self . register_wf_obligation ( ty. into ( ) , qself. span , traits:: WellFormed ( None ) ) ;
922
943
}
923
944
924
945
// Write back the new resolution.
@@ -1082,7 +1103,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1082
1103
pub fn instantiate_value_path (
1083
1104
& self ,
1084
1105
segments : & [ hir:: PathSegment < ' _ > ] ,
1085
- self_ty : Option < RawTy < ' tcx > > ,
1106
+ self_ty : Option < Ty < ' tcx > > ,
1086
1107
res : Res ,
1087
1108
span : Span ,
1088
1109
hir_id : hir:: HirId ,
@@ -1093,7 +1114,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1093
1114
Res :: Local ( _) | Res :: SelfCtor ( _) => vec ! [ ] ,
1094
1115
Res :: Def ( kind, def_id) => self . astconv ( ) . def_ids_for_value_path_segments (
1095
1116
segments,
1096
- self_ty. map ( |ty| ty. raw ) ,
1117
+ self_ty. map ( |ty| ty) ,
1097
1118
kind,
1098
1119
def_id,
1099
1120
span,
@@ -1107,8 +1128,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1107
1128
Res :: Def ( DefKind :: Ctor ( CtorOf :: Variant , _) , _)
1108
1129
if let Some ( self_ty) = self_ty =>
1109
1130
{
1110
- let adt_def = self_ty . normalized . ty_adt_def ( ) . unwrap ( ) ;
1111
- user_self_ty = Some ( UserSelfTy { impl_def_id : adt_def. did ( ) , self_ty : self_ty . raw } ) ;
1131
+ let adt_def = self . structurally_normalize_after_astconv ( span , self_ty ) . ty_adt_def ( ) . unwrap ( ) ;
1132
+ user_self_ty = Some ( UserSelfTy { impl_def_id : adt_def. did ( ) , self_ty } ) ;
1112
1133
is_alias_variant_ctor = true ;
1113
1134
}
1114
1135
Res :: Def ( DefKind :: AssocFn | DefKind :: AssocConst , def_id) => {
@@ -1127,7 +1148,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1127
1148
// inherent impl, we need to record the
1128
1149
// `T` for posterity (see `UserSelfTy` for
1129
1150
// details).
1130
- let self_ty = self_ty. expect ( "UFCS sugared assoc missing Self" ) . raw ;
1151
+ let self_ty = self_ty. expect ( "UFCS sugared assoc missing Self" ) ;
1131
1152
user_self_ty = Some ( UserSelfTy { impl_def_id : container_id, self_ty } ) ;
1132
1153
}
1133
1154
}
@@ -1206,9 +1227,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1206
1227
path_segs. last ( ) . is_some_and ( |PathSeg ( def_id, _) | tcx. generics_of ( * def_id) . has_self ) ;
1207
1228
1208
1229
let ( res, self_ctor_args) = if let Res :: SelfCtor ( impl_def_id) = res {
1209
- let ty =
1210
- self . handle_raw_ty ( span, tcx . at ( span ) . type_of ( impl_def_id ) . instantiate_identity ( ) ) ;
1211
- match ty . normalized . ty_adt_def ( ) {
1230
+ let ty = tcx . at ( span ) . type_of ( impl_def_id ) . instantiate_identity ( ) ;
1231
+ let normalized = self . structurally_normalize_after_astconv ( span, ty ) ;
1232
+ match normalized. ty_adt_def ( ) {
1212
1233
Some ( adt_def) if adt_def. has_ctor ( ) => {
1213
1234
let ( ctor_kind, ctor_def_id) = adt_def. non_enum_variant ( ) . ctor . unwrap ( ) ;
1214
1235
// Check the visibility of the ctor.
@@ -1218,7 +1239,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1218
1239
. emit_err ( CtorIsPrivate { span, def : tcx. def_path_str ( adt_def. did ( ) ) } ) ;
1219
1240
}
1220
1241
let new_res = Res :: Def ( DefKind :: Ctor ( CtorOf :: Struct , ctor_kind) , ctor_def_id) ;
1221
- let user_args = Self :: user_args_for_adt ( ty) ;
1242
+ let user_args = Self :: user_args_for_adt ( ty, normalized ) ;
1222
1243
user_self_ty = user_args. user_self_ty ;
1223
1244
( new_res, Some ( user_args. args ) )
1224
1245
}
@@ -1227,7 +1248,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1227
1248
span,
1228
1249
"the `Self` constructor can only be used with tuple or unit structs" ,
1229
1250
) ;
1230
- if let Some ( adt_def) = ty . normalized . ty_adt_def ( ) {
1251
+ if let Some ( adt_def) = normalized. ty_adt_def ( ) {
1231
1252
match adt_def. adt_kind ( ) {
1232
1253
AdtKind :: Enum => {
1233
1254
err. help ( "did you mean to use one of the enum's variants?" ) ;
@@ -1299,7 +1320,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1299
1320
self . fcx . astconv ( ) . ast_region_to_region ( lt, Some ( param) ) . into ( )
1300
1321
}
1301
1322
( GenericParamDefKind :: Type { .. } , GenericArg :: Type ( ty) ) => {
1302
- self . fcx . to_ty ( ty) . raw . into ( )
1323
+ self . fcx . to_ty ( ty) . into ( )
1303
1324
}
1304
1325
( GenericParamDefKind :: Const { .. } , GenericArg :: Const ( ct) ) => {
1305
1326
self . fcx . const_arg_to_const ( & ct. value , param. def_id ) . into ( )
@@ -1367,7 +1388,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
1367
1388
def_id,
1368
1389
& [ ] ,
1369
1390
has_self,
1370
- self_ty. map ( |s| s. raw ) ,
1391
+ self_ty. map ( |s| s) ,
1371
1392
& arg_count,
1372
1393
& mut CreateCtorSubstsContext {
1373
1394
fcx : self ,
0 commit comments