Skip to content

Commit 870ed4b

Browse files
Add test
1 parent b2fea55 commit 870ed4b

File tree

5 files changed

+51
-5
lines changed

5 files changed

+51
-5
lines changed

tests/crashes/123461.rs

-5
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Minimized test for <https://github.com/rust-lang/rust/issues/123461>.
2+
3+
struct Unconstrained<T>(T);
4+
5+
fn main() {
6+
unsafe { std::mem::transmute::<_, ()>(|o_b: Unconstrained<_>| {}) };
7+
//~^ ERROR type annotations needed
8+
// We unfortunately don't check `Wf(Unconstrained<_>)`, so we won't
9+
// hit an ambiguity error before checking the transmute. That means
10+
// we still may have inference variables in our transmute src.
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/ambiguity-in-closure-arg.rs:6:44
3+
|
4+
LL | unsafe { std::mem::transmute::<_, ()>(|o_b: Unconstrained<_>| {}) };
5+
| ^^^^^^^^^^^^^^^^^^^^^ cannot infer type
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0282`.

tests/ui/wf/closure-wf.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
trait Bound {}
2+
struct NeedsBound<T: Bound>(T);
3+
4+
// Checks that we enforce that closure args are WF.
5+
6+
fn constrain_inner<T, F: for<'a> FnOnce(&'a (), NeedsBound<T>)>(_: T, _: F) {}
7+
8+
fn main() {
9+
constrain_inner(1u32, |&(), _| ());
10+
//~^ ERROR the trait bound `u32: Bound` is not satisfied
11+
}

tests/ui/wf/closure-wf.stderr

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0277]: the trait bound `u32: Bound` is not satisfied
2+
--> $DIR/closure-wf.rs:9:33
3+
|
4+
LL | constrain_inner(1u32, |&(), _| ());
5+
| ^ the trait `Bound` is not implemented for `u32`
6+
|
7+
help: this trait has no implementations, consider adding one
8+
--> $DIR/closure-wf.rs:1:1
9+
|
10+
LL | trait Bound {}
11+
| ^^^^^^^^^^^
12+
note: required by a bound in `NeedsBound`
13+
--> $DIR/closure-wf.rs:2:22
14+
|
15+
LL | struct NeedsBound<T: Bound>(T);
16+
| ^^^^^ required by this bound in `NeedsBound`
17+
18+
error: aborting due to 1 previous error
19+
20+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)