Skip to content

Commit b7642fb

Browse files
authored
Rollup merge of #102710 - Rageking8:add-test-for-issue-82633, r=estebank
Add test for issue 82633 Fixes #82633 r? `@estebank` The current stderr looks slightly different from [source](https://github.com/rust-lang/rust/pull/83915/files#diff-8c64c576ccaceb816e71d2279a6ee4bf79211bc06f55c46dda3f98a18748ad7a), so I used the latest one from nightly. Do let me know if anything is wrong.
2 parents 0512a06 + 65c0e68 commit b7642fb

File tree

2 files changed

+173
-0
lines changed

2 files changed

+173
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#![feature(unboxed_closures)]
2+
3+
trait A {
4+
fn a() where Self: Sized;
5+
}
6+
7+
mod a {
8+
use crate::A;
9+
10+
pub fn foo<F: FnOnce<()>>() where F::Output: A {
11+
F::Output::a()
12+
}
13+
14+
pub fn bar<F: FnOnce() -> R, R: ?Sized>() {}
15+
16+
pub fn baz<F: FnOnce<()>>() where F::Output: A, F::Output: Sized {
17+
F::Output::a()
18+
}
19+
}
20+
21+
mod b {
22+
use crate::A;
23+
24+
pub fn foo<F: Fn<()>>() where F::Output: A {
25+
F::Output::a()
26+
}
27+
28+
pub fn bar<F: Fn() -> R, R: ?Sized>() {}
29+
30+
pub fn baz<F: Fn<()>>() where F::Output: A, F::Output: Sized {
31+
F::Output::a()
32+
}
33+
}
34+
35+
mod c {
36+
use crate::A;
37+
38+
pub fn foo<F: FnMut<()>>() where F::Output: A {
39+
F::Output::a()
40+
}
41+
42+
pub fn bar<F: FnMut() -> R, R: ?Sized>() {}
43+
44+
pub fn baz<F: FnMut<()>>() where F::Output: A, F::Output: Sized {
45+
F::Output::a()
46+
}
47+
}
48+
49+
impl A for Box<dyn A> {
50+
fn a() {}
51+
}
52+
53+
fn main() {
54+
a::foo::<fn() -> dyn A>(); //~ ERROR E0277
55+
a::bar::<fn() -> dyn A, _>(); //~ ERROR E0277
56+
a::baz::<fn() -> dyn A>(); //~ ERROR E0277
57+
a::foo::<fn() -> Box<dyn A>>(); // ok
58+
a::bar::<fn() -> Box<dyn A>, _>(); // ok
59+
a::baz::<fn() -> Box<dyn A>>(); // ok
60+
61+
b::foo::<fn() -> dyn A>(); //~ ERROR E0277
62+
b::bar::<fn() -> dyn A, _>(); //~ ERROR E0277
63+
b::baz::<fn() -> dyn A>(); //~ ERROR E0277
64+
b::foo::<fn() -> Box<dyn A>>(); // ok
65+
b::bar::<fn() -> Box<dyn A>, _>(); // ok
66+
b::baz::<fn() -> Box<dyn A>>(); // ok
67+
68+
c::foo::<fn() -> dyn A>(); //~ ERROR E0277
69+
c::bar::<fn() -> dyn A, _>(); //~ ERROR E0277
70+
c::baz::<fn() -> dyn A>(); //~ ERROR E0277
71+
c::foo::<fn() -> Box<dyn A>>(); // ok
72+
c::bar::<fn() -> Box<dyn A>, _>(); // ok
73+
c::baz::<fn() -> Box<dyn A>>(); // ok
74+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
error[E0277]: the size for values of type `dyn A` cannot be known at compilation time
2+
--> $DIR/closure-return-type-must-be-sized.rs:54:5
3+
|
4+
LL | a::foo::<fn() -> dyn A>();
5+
| ^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
6+
|
7+
= help: within `fn() -> dyn A`, the trait `Sized` is not implemented for `dyn A`
8+
= note: required because it appears within the type `fn() -> dyn A`
9+
10+
error[E0277]: the size for values of type `dyn A` cannot be known at compilation time
11+
--> $DIR/closure-return-type-must-be-sized.rs:55:14
12+
|
13+
LL | a::bar::<fn() -> dyn A, _>();
14+
| ^^^^^^^^^^^^^ doesn't have a size known at compile-time
15+
|
16+
= help: within `fn() -> dyn A`, the trait `Sized` is not implemented for `dyn A`
17+
= note: required because it appears within the type `fn() -> dyn A`
18+
note: required by a bound in `a::bar`
19+
--> $DIR/closure-return-type-must-be-sized.rs:14:19
20+
|
21+
LL | pub fn bar<F: FnOnce() -> R, R: ?Sized>() {}
22+
| ^^^^^^^^^^^^^ required by this bound in `a::bar`
23+
24+
error[E0277]: the size for values of type `dyn A` cannot be known at compilation time
25+
--> $DIR/closure-return-type-must-be-sized.rs:56:5
26+
|
27+
LL | a::baz::<fn() -> dyn A>();
28+
| ^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
29+
|
30+
= help: within `fn() -> dyn A`, the trait `Sized` is not implemented for `dyn A`
31+
= note: required because it appears within the type `fn() -> dyn A`
32+
33+
error[E0277]: the size for values of type `dyn A` cannot be known at compilation time
34+
--> $DIR/closure-return-type-must-be-sized.rs:61:5
35+
|
36+
LL | b::foo::<fn() -> dyn A>();
37+
| ^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
38+
|
39+
= help: within `fn() -> dyn A`, the trait `Sized` is not implemented for `dyn A`
40+
= note: required because it appears within the type `fn() -> dyn A`
41+
42+
error[E0277]: the size for values of type `dyn A` cannot be known at compilation time
43+
--> $DIR/closure-return-type-must-be-sized.rs:62:14
44+
|
45+
LL | b::bar::<fn() -> dyn A, _>();
46+
| ^^^^^^^^^^^^^ doesn't have a size known at compile-time
47+
|
48+
= help: within `fn() -> dyn A`, the trait `Sized` is not implemented for `dyn A`
49+
= note: required because it appears within the type `fn() -> dyn A`
50+
note: required by a bound in `b::bar`
51+
--> $DIR/closure-return-type-must-be-sized.rs:28:19
52+
|
53+
LL | pub fn bar<F: Fn() -> R, R: ?Sized>() {}
54+
| ^^^^^^^^^ required by this bound in `b::bar`
55+
56+
error[E0277]: the size for values of type `dyn A` cannot be known at compilation time
57+
--> $DIR/closure-return-type-must-be-sized.rs:63:5
58+
|
59+
LL | b::baz::<fn() -> dyn A>();
60+
| ^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
61+
|
62+
= help: within `fn() -> dyn A`, the trait `Sized` is not implemented for `dyn A`
63+
= note: required because it appears within the type `fn() -> dyn A`
64+
65+
error[E0277]: the size for values of type `dyn A` cannot be known at compilation time
66+
--> $DIR/closure-return-type-must-be-sized.rs:68:5
67+
|
68+
LL | c::foo::<fn() -> dyn A>();
69+
| ^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
70+
|
71+
= help: within `fn() -> dyn A`, the trait `Sized` is not implemented for `dyn A`
72+
= note: required because it appears within the type `fn() -> dyn A`
73+
74+
error[E0277]: the size for values of type `dyn A` cannot be known at compilation time
75+
--> $DIR/closure-return-type-must-be-sized.rs:69:14
76+
|
77+
LL | c::bar::<fn() -> dyn A, _>();
78+
| ^^^^^^^^^^^^^ doesn't have a size known at compile-time
79+
|
80+
= help: within `fn() -> dyn A`, the trait `Sized` is not implemented for `dyn A`
81+
= note: required because it appears within the type `fn() -> dyn A`
82+
note: required by a bound in `c::bar`
83+
--> $DIR/closure-return-type-must-be-sized.rs:42:19
84+
|
85+
LL | pub fn bar<F: FnMut() -> R, R: ?Sized>() {}
86+
| ^^^^^^^^^^^^ required by this bound in `c::bar`
87+
88+
error[E0277]: the size for values of type `dyn A` cannot be known at compilation time
89+
--> $DIR/closure-return-type-must-be-sized.rs:70:5
90+
|
91+
LL | c::baz::<fn() -> dyn A>();
92+
| ^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
93+
|
94+
= help: within `fn() -> dyn A`, the trait `Sized` is not implemented for `dyn A`
95+
= note: required because it appears within the type `fn() -> dyn A`
96+
97+
error: aborting due to 9 previous errors
98+
99+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)