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