@@ -2236,7 +2236,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
2236
2236
hir_id, def_id, substs, user_self_ty, self . tag( ) ,
2237
2237
) ;
2238
2238
2239
- if !substs . is_noop ( ) {
2239
+ if Self :: can_contain_user_lifetime_bounds ( ( substs , user_self_ty ) ) {
2240
2240
let canonicalized = self . infcx . canonicalize_user_type_annotation (
2241
2241
& UserType :: TypeOf ( def_id, UserSubsts {
2242
2242
substs,
@@ -2431,15 +2431,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
2431
2431
let ty = self . to_ty ( ast_ty) ;
2432
2432
debug ! ( "to_ty_saving_user_provided_ty: ty={:?}" , ty) ;
2433
2433
2434
- // If the type given by the user has free regions, save it for
2435
- // later, since NLL would like to enforce those. Also pass in
2436
- // types that involve projections, since those can resolve to
2437
- // `'static` bounds (modulo #54940, which hopefully will be
2438
- // fixed by the time you see this comment, dear reader,
2439
- // although I have my doubts). Also pass in types with inference
2440
- // types, because they may be repeated. Other sorts of things
2441
- // are already sufficiently enforced with erased regions. =)
2442
- if ty. has_free_regions ( ) || ty. has_projections ( ) || ty. has_infer_types ( ) {
2434
+ if Self :: can_contain_user_lifetime_bounds ( ty) {
2443
2435
let c_ty = self . infcx . canonicalize_response ( & UserType :: Ty ( ty) ) ;
2444
2436
debug ! ( "to_ty_saving_user_provided_ty: c_ty={:?}" , c_ty) ;
2445
2437
self . tables . borrow_mut ( ) . user_provided_types_mut ( ) . insert ( ast_ty. hir_id , c_ty) ;
@@ -2448,6 +2440,20 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
2448
2440
ty
2449
2441
}
2450
2442
2443
+ // If the type given by the user has free regions, save it for later, since
2444
+ // NLL would like to enforce those. Also pass in types that involve
2445
+ // projections, since those can resolve to `'static` bounds (modulo #54940,
2446
+ // which hopefully will be fixed by the time you see this comment, dear
2447
+ // reader, although I have my doubts). Also pass in types with inference
2448
+ // types, because they may be repeated. Other sorts of things are already
2449
+ // sufficiently enforced with erased regions. =)
2450
+ fn can_contain_user_lifetime_bounds < T > ( t : T ) -> bool
2451
+ where
2452
+ T : TypeFoldable < ' tcx >
2453
+ {
2454
+ t. has_free_regions ( ) || t. has_projections ( ) || t. has_infer_types ( )
2455
+ }
2456
+
2451
2457
pub fn node_ty ( & self , id : hir:: HirId ) -> Ty < ' tcx > {
2452
2458
match self . tables . borrow ( ) . node_types ( ) . get ( id) {
2453
2459
Some ( & t) => t,
0 commit comments