7
7
use std:: ops:: ControlFlow ;
8
8
9
9
use rustc_errors:: FatalError ;
10
- use rustc_hir as hir;
11
10
use rustc_hir:: def_id:: DefId ;
11
+ use rustc_hir:: { self as hir, LangItem } ;
12
12
use rustc_middle:: query:: Providers ;
13
13
use rustc_middle:: ty:: {
14
14
self , EarlyBinder , GenericArgs , Ty , TyCtxt , TypeFoldable , TypeFolder , TypeSuperFoldable ,
15
15
TypeSuperVisitable , TypeVisitable , TypeVisitableExt , TypeVisitor , TypingMode , Upcast ,
16
16
elaborate,
17
17
} ;
18
- use rustc_span:: Span ;
18
+ use rustc_span:: { DUMMY_SP , Span } ;
19
19
use smallvec:: SmallVec ;
20
20
use tracing:: { debug, instrument} ;
21
21
@@ -543,11 +543,11 @@ fn receiver_for_self_ty<'tcx>(
543
543
/// In practice, we cannot use `dyn Trait` explicitly in the obligation because it would result in
544
544
/// a new check that `Trait` is dyn-compatible, creating a cycle.
545
545
/// Instead, we emulate a placeholder by introducing a new type parameter `U` such that
546
- /// `Self: Unsize<U>` and `U: Trait + ?Sized `, and use `U` in place of `dyn Trait`.
546
+ /// `Self: Unsize<U>` and `U: Trait + MetaSized `, and use `U` in place of `dyn Trait`.
547
547
///
548
548
/// Written as a chalk-style query:
549
549
/// ```ignore (not-rust)
550
- /// forall (U: Trait + ?Sized ) {
550
+ /// forall (U: Trait + MetaSized ) {
551
551
/// if (Self: Unsize<U>) {
552
552
/// Receiver: DispatchFromDyn<Receiver[Self => U]>
553
553
/// }
@@ -567,9 +567,10 @@ fn receiver_is_dispatchable<'tcx>(
567
567
) -> bool {
568
568
debug ! ( "receiver_is_dispatchable: method = {:?}, receiver_ty = {:?}" , method, receiver_ty) ;
569
569
570
- let traits = ( tcx. lang_items ( ) . unsize_trait ( ) , tcx. lang_items ( ) . dispatch_from_dyn_trait ( ) ) ;
571
- let ( Some ( unsize_did) , Some ( dispatch_from_dyn_did) ) = traits else {
572
- debug ! ( "receiver_is_dispatchable: Missing Unsize or DispatchFromDyn traits" ) ;
570
+ let ( Some ( unsize_did) , Some ( dispatch_from_dyn_did) ) =
571
+ ( tcx. lang_items ( ) . unsize_trait ( ) , tcx. lang_items ( ) . dispatch_from_dyn_trait ( ) )
572
+ else {
573
+ debug ! ( "receiver_is_dispatchable: Missing `Unsize` or `DispatchFromDyn` traits" ) ;
573
574
return false ;
574
575
} ;
575
576
@@ -583,7 +584,7 @@ fn receiver_is_dispatchable<'tcx>(
583
584
receiver_for_self_ty ( tcx, receiver_ty, unsized_self_ty, method. def_id ) ;
584
585
585
586
// create a modified param env, with `Self: Unsize<U>` and `U: Trait` (and all of
586
- // its supertraits) added to caller bounds. `U: ?Sized ` is already implied here.
587
+ // its supertraits) added to caller bounds. `U: MetaSized ` is already implied here.
587
588
let param_env = {
588
589
// N.B. We generally want to emulate the construction of the `unnormalized_param_env`
589
590
// in the param-env query here. The fact that we don't just start with the clauses
@@ -612,6 +613,12 @@ fn receiver_is_dispatchable<'tcx>(
612
613
let trait_predicate = ty:: TraitRef :: new_from_args ( tcx, trait_def_id, args) ;
613
614
predicates. push ( trait_predicate. upcast ( tcx) ) ;
614
615
616
+ let meta_sized_predicate = {
617
+ let meta_sized_did = tcx. require_lang_item ( LangItem :: MetaSized , DUMMY_SP ) ;
618
+ ty:: TraitRef :: new ( tcx, meta_sized_did, [ unsized_self_ty] ) . upcast ( tcx)
619
+ } ;
620
+ predicates. push ( meta_sized_predicate) ;
621
+
615
622
normalize_param_env_or_error (
616
623
tcx,
617
624
ty:: ParamEnv :: new ( tcx. mk_clauses ( & predicates) ) ,
0 commit comments