@@ -2,7 +2,7 @@ use crate::callee::{self, DeferredCallResolution};
22use crate :: errors:: CtorIsPrivate ;
33use crate :: method:: { self , MethodCallee , SelfSource } ;
44use crate :: rvalue_scopes;
5- use crate :: { BreakableCtxt , Diverges , Expectation , FnCtxt , RawTy } ;
5+ use crate :: { BreakableCtxt , Diverges , Expectation , FnCtxt } ;
66use rustc_data_structures:: captures:: Captures ;
77use rustc_data_structures:: fx:: FxHashSet ;
88use rustc_errors:: { Applicability , Diagnostic , ErrorGuaranteed , MultiSpan , StashKey } ;
@@ -324,6 +324,26 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
324324 )
325325 }
326326
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+
327347 pub fn require_type_meets (
328348 & self ,
329349 ty : Ty < ' tcx > ,
@@ -374,37 +394,33 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
374394 }
375395 }
376396
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 > {
382398 let t = self . astconv ( ) . ast_ty_to_ty ( ast_t) ;
383399 self . register_wf_obligation ( t. into ( ) , ast_t. span , traits:: WellFormed ( None ) ) ;
384- self . handle_raw_ty ( ast_t . span , t )
400+ t
385401 }
386402
387403 pub fn to_ty_saving_user_provided_ty ( & self , ast_ty : & hir:: Ty < ' _ > ) -> Ty < ' tcx > {
388404 let ty = self . to_ty ( ast_ty) ;
389405 debug ! ( "to_ty_saving_user_provided_ty: ty={:?}" , ty) ;
390406
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) ) ;
393409 debug ! ( "to_ty_saving_user_provided_ty: c_ty={:?}" , c_ty) ;
394410 self . typeck_results . borrow_mut ( ) . user_provided_types_mut ( ) . insert ( ast_ty. hir_id , c_ty) ;
395411 }
396412
397- ty . normalized
413+ self . normalize ( ast_ty . span , ty )
398414 }
399415
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 ( ) ) {
402418 ( ty:: Adt ( _, args) , _) => UserArgs { args, user_self_ty : None } ,
403419 ( _, ty:: Adt ( adt, args) ) => UserArgs {
404420 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 } ) ,
406422 } ,
407- _ => bug ! ( "non-adt type {:?}" , ty ) ,
423+ _ => bug ! ( "non-adt type {:?}" , raw ) ,
408424 }
409425 }
410426
@@ -817,7 +833,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
817833 qpath : & ' tcx QPath < ' tcx > ,
818834 hir_id : hir:: HirId ,
819835 span : Span ,
820- ) -> ( Res , Option < RawTy < ' tcx > > , & ' tcx [ hir:: PathSegment < ' tcx > ] ) {
836+ ) -> ( Res , Option < Ty < ' tcx > > , & ' tcx [ hir:: PathSegment < ' tcx > ] ) {
821837 debug ! (
822838 "resolve_ty_and_res_fully_qualified_call: qpath={:?} hir_id={:?} span={:?}" ,
823839 qpath, hir_id, span
@@ -841,23 +857,28 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
841857 // We manually call `register_wf_obligation` in the success path
842858 // below.
843859 let ty = self . astconv ( ) . ast_ty_to_ty_in_path ( qself) ;
844- ( self . handle_raw_ty ( span , ty ) , qself, segment)
860+ ( ty , qself, segment)
845861 }
846862 QPath :: LangItem ( ..) => {
847863 bug ! ( "`resolve_ty_and_res_fully_qualified_call` called on `LangItem`" )
848864 }
849865 } ;
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+
850871 if let Some ( & cached_result) = self . typeck_results . borrow ( ) . type_dependent_defs ( ) . get ( hir_id)
851872 {
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 ) ) ;
853874 // Return directly on cache hit. This is useful to avoid doubly reporting
854875 // errors with default match binding modes. See #44614.
855876 let def = cached_result. map_or ( Res :: Err , |( kind, def_id) | Res :: Def ( kind, def_id) ) ;
856877 return ( def, Some ( ty) , slice:: from_ref ( & * * item_segment) ) ;
857878 }
858879 let item_name = item_segment. ident ;
859880 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)
861882 . and_then ( |r| {
862883 // lint bare trait if the method is found in the trait
863884 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> {
876897 } ;
877898
878899 let trait_missing_method =
879- matches ! ( error, method:: MethodError :: NoMatch ( _) ) && ty . normalized . is_trait ( ) ;
900+ matches ! ( error, method:: MethodError :: NoMatch ( _) ) && normalized. is_trait ( ) ;
880901 // If we have a path like `MyTrait::missing_method`, then don't register
881902 // a WF obligation for `dyn MyTrait` when method lookup fails. Otherwise,
882903 // register a WF obligation so that we can detect any additional
883904 // errors in the self type.
884905 if !trait_missing_method {
885906 self . register_wf_obligation (
886- ty. raw . into ( ) ,
907+ ty. into ( ) ,
887908 qself. span ,
888909 traits:: WellFormed ( None ) ,
889910 ) ;
@@ -902,7 +923,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
902923 if item_name. name != kw:: Empty {
903924 if let Some ( mut e) = self . report_method_error (
904925 span,
905- ty . normalized ,
926+ normalized,
906927 item_name,
907928 SelfSource :: QPath ( qself) ,
908929 error,
@@ -918,7 +939,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
918939 } ) ;
919940
920941 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 ) ) ;
922943 }
923944
924945 // Write back the new resolution.
@@ -1082,7 +1103,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10821103 pub fn instantiate_value_path (
10831104 & self ,
10841105 segments : & [ hir:: PathSegment < ' _ > ] ,
1085- self_ty : Option < RawTy < ' tcx > > ,
1106+ self_ty : Option < Ty < ' tcx > > ,
10861107 res : Res ,
10871108 span : Span ,
10881109 hir_id : hir:: HirId ,
@@ -1093,7 +1114,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10931114 Res :: Local ( _) | Res :: SelfCtor ( _) => vec ! [ ] ,
10941115 Res :: Def ( kind, def_id) => self . astconv ( ) . def_ids_for_value_path_segments (
10951116 segments,
1096- self_ty. map ( |ty| ty. raw ) ,
1117+ self_ty. map ( |ty| ty) ,
10971118 kind,
10981119 def_id,
10991120 span,
@@ -1107,8 +1128,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11071128 Res :: Def ( DefKind :: Ctor ( CtorOf :: Variant , _) , _)
11081129 if let Some ( self_ty) = self_ty =>
11091130 {
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 } ) ;
11121133 is_alias_variant_ctor = true ;
11131134 }
11141135 Res :: Def ( DefKind :: AssocFn | DefKind :: AssocConst , def_id) => {
@@ -1127,7 +1148,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11271148 // inherent impl, we need to record the
11281149 // `T` for posterity (see `UserSelfTy` for
11291150 // 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" ) ;
11311152 user_self_ty = Some ( UserSelfTy { impl_def_id : container_id, self_ty } ) ;
11321153 }
11331154 }
@@ -1206,9 +1227,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12061227 path_segs. last ( ) . is_some_and ( |PathSeg ( def_id, _) | tcx. generics_of ( * def_id) . has_self ) ;
12071228
12081229 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 ( ) {
12121233 Some ( adt_def) if adt_def. has_ctor ( ) => {
12131234 let ( ctor_kind, ctor_def_id) = adt_def. non_enum_variant ( ) . ctor . unwrap ( ) ;
12141235 // Check the visibility of the ctor.
@@ -1218,7 +1239,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12181239 . emit_err ( CtorIsPrivate { span, def : tcx. def_path_str ( adt_def. did ( ) ) } ) ;
12191240 }
12201241 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 ) ;
12221243 user_self_ty = user_args. user_self_ty ;
12231244 ( new_res, Some ( user_args. args ) )
12241245 }
@@ -1227,7 +1248,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12271248 span,
12281249 "the `Self` constructor can only be used with tuple or unit structs" ,
12291250 ) ;
1230- if let Some ( adt_def) = ty . normalized . ty_adt_def ( ) {
1251+ if let Some ( adt_def) = normalized. ty_adt_def ( ) {
12311252 match adt_def. adt_kind ( ) {
12321253 AdtKind :: Enum => {
12331254 err. help ( "did you mean to use one of the enum's variants?" ) ;
@@ -1299,7 +1320,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12991320 self . fcx . astconv ( ) . ast_region_to_region ( lt, Some ( param) ) . into ( )
13001321 }
13011322 ( GenericParamDefKind :: Type { .. } , GenericArg :: Type ( ty) ) => {
1302- self . fcx . to_ty ( ty) . raw . into ( )
1323+ self . fcx . to_ty ( ty) . into ( )
13031324 }
13041325 ( GenericParamDefKind :: Const { .. } , GenericArg :: Const ( ct) ) => {
13051326 self . fcx . const_arg_to_const ( & ct. value , param. def_id ) . into ( )
@@ -1367,7 +1388,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13671388 def_id,
13681389 & [ ] ,
13691390 has_self,
1370- self_ty. map ( |s| s. raw ) ,
1391+ self_ty. map ( |s| s) ,
13711392 & arg_count,
13721393 & mut CreateCtorSubstsContext {
13731394 fcx : self ,
0 commit comments