@@ -11,7 +11,7 @@ use rustc_hir::def::{CtorKind, Namespace};
11
11
use rustc_hir:: CoroutineKind ;
12
12
use rustc_index:: IndexSlice ;
13
13
use rustc_infer:: infer:: BoundRegionConversionTime ;
14
- use rustc_infer:: traits:: { FulfillmentErrorCode , SelectionError , TraitEngineExt } ;
14
+ use rustc_infer:: traits:: { FulfillmentErrorCode , SelectionError , TraitEngine , TraitEngineExt } ;
15
15
use rustc_middle:: mir:: tcx:: PlaceTy ;
16
16
use rustc_middle:: mir:: {
17
17
AggregateKind , CallSource , ConstOperand , FakeReadCause , Local , LocalInfo , LocalKind , Location ,
@@ -1211,7 +1211,27 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
1211
1211
. collect :: < Vec < _ > > ( ) ;
1212
1212
fulfill_cx
1213
1213
. 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) ;
1214
1226
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
+ } ;
1215
1235
let msg = match & errors[ ..] {
1216
1236
[ ] => "you can `clone` the value and consume it, but this \
1217
1237
might not be your desired behavior"
0 commit comments