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