@@ -11,7 +11,7 @@ use rustc_hir::def::{CtorKind, Namespace};
1111use rustc_hir:: CoroutineKind ;
1212use rustc_index:: IndexSlice ;
1313use rustc_infer:: infer:: BoundRegionConversionTime ;
14- use rustc_infer:: traits:: { FulfillmentErrorCode , SelectionError , TraitEngineExt } ;
14+ use rustc_infer:: traits:: { FulfillmentErrorCode , SelectionError , TraitEngine , TraitEngineExt } ;
1515use rustc_middle:: mir:: tcx:: PlaceTy ;
1616use rustc_middle:: mir:: {
1717 AggregateKind , CallSource , ConstOperand , FakeReadCause , Local , LocalInfo , LocalKind , Location ,
@@ -1211,7 +1211,27 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
12111211 . collect :: < Vec < _ > > ( ) ;
12121212 fulfill_cx
12131213 . register_predicate_obligations ( self . infcx , obligations) ;
1214+ // We also register the parent obligation for the type at hand
1215+ // implementing `Clone`, to account for bounds that also need
1216+ // to be evaluated, like ensuring that `Self: Clone`.
1217+ let trait_ref = ty:: TraitRef :: new ( tcx, clone_trait, [ ty] ) ;
1218+ let obligation = Obligation :: new (
1219+ tcx,
1220+ ObligationCause :: dummy ( ) ,
1221+ self . param_env ,
1222+ trait_ref,
1223+ ) ;
1224+ fulfill_cx
1225+ . register_predicate_obligation ( self . infcx , obligation) ;
12141226 let errors = fulfill_cx. select_all_or_error ( self . infcx ) ;
1227+ // We remove the last predicate failure, which corresponds to
1228+ // the top-level obligation, because most of the type we only
1229+ // care about the other ones, *except* when it is the only one.
1230+ // This seems to only be relevant for arbitrary self-types.
1231+ // Look at `tests/ui/moves/move-fn-self-receiver.rs`.
1232+ let errors = match & errors[ ..] {
1233+ errors @ [ ] | errors @ [ _] | [ errors @ .., _] => errors,
1234+ } ;
12151235 let msg = match & errors[ ..] {
12161236 [ ] => "you can `clone` the value and consume it, but this \
12171237 might not be your desired behavior"
0 commit comments