@@ -4,11 +4,11 @@ use std::slice;
4
4
use rustc_abi:: FieldIdx ;
5
5
use rustc_data_structures:: fx:: FxHashSet ;
6
6
use rustc_errors:: { Applicability , Diag , ErrorGuaranteed , MultiSpan , StashKey } ;
7
- use rustc_hir as hir;
8
7
use rustc_hir:: def:: { CtorOf , DefKind , Res } ;
9
8
use rustc_hir:: def_id:: DefId ;
9
+ use rustc_hir:: intravisit:: Visitor ;
10
10
use rustc_hir:: lang_items:: LangItem ;
11
- use rustc_hir:: { ExprKind , GenericArg , HirId , Node , QPath } ;
11
+ use rustc_hir:: { self as hir , ExprKind , GenericArg , HirId , Node , QPath , intravisit } ;
12
12
use rustc_hir_analysis:: hir_ty_lowering:: errors:: GenericsArgsErrExtend ;
13
13
use rustc_hir_analysis:: hir_ty_lowering:: generics:: {
14
14
check_generic_arg_count_for_call, lower_generic_args,
@@ -460,8 +460,35 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
460
460
LoweredTy :: from_raw ( self , hir_ty. span , ty)
461
461
}
462
462
463
+ /// Walk a `hir_ty` and collect any clauses that may have come from a type
464
+ /// within the `hir_ty`. These clauses will be canonicalized with a user type
465
+ /// annotation so that we can enforce these bounds in borrowck, too.
466
+ pub ( crate ) fn collect_impl_trait_clauses_from_hir_ty (
467
+ & self ,
468
+ hir_ty : & ' tcx hir:: Ty < ' tcx > ,
469
+ ) -> ty:: Clauses < ' tcx > {
470
+ struct CollectClauses < ' a , ' tcx > {
471
+ clauses : Vec < ty:: Clause < ' tcx > > ,
472
+ fcx : & ' a FnCtxt < ' a , ' tcx > ,
473
+ }
474
+
475
+ impl < ' tcx > intravisit:: Visitor < ' tcx > for CollectClauses < ' _ , ' tcx > {
476
+ fn visit_ty ( & mut self , ty : & ' tcx hir:: Ty < ' tcx > ) {
477
+ if let Some ( clauses) = self . fcx . trait_ascriptions . borrow ( ) . get ( & ty. hir_id . local_id )
478
+ {
479
+ self . clauses . extend ( clauses. iter ( ) . cloned ( ) ) ;
480
+ }
481
+ intravisit:: walk_ty ( self , ty)
482
+ }
483
+ }
484
+
485
+ let mut clauses = CollectClauses { clauses : vec ! [ ] , fcx : self } ;
486
+ clauses. visit_ty ( hir_ty) ;
487
+ self . tcx . mk_clauses ( & clauses. clauses )
488
+ }
489
+
463
490
#[ instrument( level = "debug" , skip_all) ]
464
- pub ( crate ) fn lower_ty_saving_user_provided_ty ( & self , hir_ty : & hir:: Ty < ' tcx > ) -> Ty < ' tcx > {
491
+ pub ( crate ) fn lower_ty_saving_user_provided_ty ( & self , hir_ty : & ' tcx hir:: Ty < ' tcx > ) -> Ty < ' tcx > {
465
492
let ty = self . lower_ty ( hir_ty) ;
466
493
debug ! ( ?ty) ;
467
494
0 commit comments