Skip to content

Commit 95357c7

Browse files
Check whole Unsize predicate for escaping bound vars
1 parent 4b293d9 commit 95357c7

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -920,11 +920,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
920920
// T: Trait
921921
// so it seems ok if we (conservatively) fail to accept that `Unsize`
922922
// obligation above. Should be possible to extend this in the future.
923-
let Some(source) = obligation.self_ty().no_bound_vars() else {
923+
let Some(trait_pred) = obligation.predicate.no_bound_vars() else {
924924
// Don't add any candidates if there are bound regions.
925925
return;
926926
};
927-
let target = obligation.predicate.skip_binder().trait_ref.args.type_at(1);
927+
let source = trait_pred.self_ty();
928+
let target = trait_pred.trait_ref.args.type_at(1);
928929

929930
debug!(?source, ?target, "assemble_candidates_for_unsizing");
930931

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0277]: the trait bound `for<'a> (): Unsize<(dyn Trait + 'a)>` is not satisfied
2+
--> $DIR/unsize-goal-escaping-bounds.rs:20:5
3+
|
4+
LL | foo();
5+
| ^^^^^ the trait `for<'a> Unsize<(dyn Trait + 'a)>` is not implemented for `()`
6+
|
7+
= note: all implementations of `Unsize` are provided automatically by the compiler, see <https://doc.rust-lang.org/stable/std/marker/trait.Unsize.html> for more information
8+
note: required by a bound in `foo`
9+
--> $DIR/unsize-goal-escaping-bounds.rs:15:17
10+
|
11+
LL | fn foo()
12+
| --- required by a bound in this function
13+
LL | where
14+
LL | for<'a> (): Unsize<dyn Trait + 'a>,
15+
| ^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `foo`
16+
17+
error: aborting due to 1 previous error
18+
19+
For more information about this error, try `rustc --explain E0277`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//@ revisions: current next
2+
//@[next] compile-flags: -Znext-solver
3+
//@[next] check-pass
4+
//@ ignore-compare-mode-next-solver (explicit revisions)
5+
6+
#![feature(unsize)]
7+
8+
use std::marker::Unsize;
9+
10+
trait Trait {}
11+
impl Trait for () {}
12+
13+
fn foo()
14+
where
15+
for<'a> (): Unsize<dyn Trait + 'a>,
16+
{
17+
}
18+
19+
fn main() {
20+
foo();
21+
//[current]~^ ERROR the trait bound `for<'a> (): Unsize<(dyn Trait + 'a)>` is not satisfied
22+
}

0 commit comments

Comments
 (0)