Skip to content

Commit 90db536

Browse files
committed
Tweak output on specific case
1 parent 98cfed7 commit 90db536

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

compiler/rustc_borrowck/src/diagnostics/mod.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_hir::def::{CtorKind, Namespace};
1111
use rustc_hir::CoroutineKind;
1212
use rustc_index::IndexSlice;
1313
use rustc_infer::infer::BoundRegionConversionTime;
14-
use rustc_infer::traits::{FulfillmentErrorCode, SelectionError, TraitEngineExt};
14+
use rustc_infer::traits::{FulfillmentErrorCode, SelectionError, TraitEngine, TraitEngineExt};
1515
use rustc_middle::mir::tcx::PlaceTy;
1616
use 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"

tests/ui/moves/move-fn-self-receiver.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ note: `Foo::use_box_self` takes ownership of the receiver `self`, which moves `b
5555
|
5656
LL | fn use_box_self(self: Box<Self>) {}
5757
| ^^^^
58-
help: you can `clone` the value and consume it, but this might not be your desired behavior
58+
help: you could `clone` the value and consume it, if the `Box<Foo>: Clone` trait bound could be satisfied
5959
|
6060
LL | boxed_foo.clone().use_box_self();
6161
| ++++++++

0 commit comments

Comments
 (0)