Skip to content

Commit 40b99a9

Browse files
Fix test case
1 parent f0114a1 commit 40b99a9

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

tests/ui/suggestions/wrap-dyn-in-suggestion-issue-120223.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,15 @@ pub fn dyn_star_func<T>(
1414
Box::new(executor) //~ ERROR may not live long enough
1515
}
1616

17-
pub fn in_ty_param<F: FnOnce() -> &'static dyn std::fmt::Debug>(f: F) {
18-
f();
19-
f(); //~ ERROR use of moved value
17+
trait Trait {
18+
fn method(&self) {}
19+
}
20+
21+
impl Trait for fn() {}
22+
23+
pub fn in_ty_param<T: Fn() -> dyn std::fmt::Debug> (t: T) {
24+
t.method();
25+
//~^ ERROR no method named `method` found for type parameter `T`
2026
}
2127

2228
fn with_sized<T: Fn() -> &'static (dyn std::fmt::Debug) + ?Sized>() {

tests/ui/suggestions/wrap-dyn-in-suggestion-issue-120223.stderr

+18-24
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,30 @@ LL | #![feature(dyn_star)]
77
= note: see issue #102425 <https://github.com/rust-lang/rust/issues/102425> for more information
88
= note: `#[warn(incomplete_features)]` on by default
99

10+
error[E0599]: no method named `method` found for type parameter `T` in the current scope
11+
--> $DIR/wrap-dyn-in-suggestion-issue-120223.rs:24:7
12+
|
13+
LL | pub fn in_ty_param<T: Fn() -> dyn std::fmt::Debug> (t: T) {
14+
| - method `method` not found for this type parameter
15+
LL | t.method();
16+
| ^^^^^^ method not found in `T`
17+
|
18+
= help: items from traits can only be used if the type parameter is bounded by the trait
19+
help: the following trait defines an item `method`, perhaps you need to restrict type parameter `T` with it:
20+
|
21+
LL | pub fn in_ty_param<T: Fn() -> (dyn std::fmt::Debug) + Trait> (t: T) {
22+
| + +++++++++
23+
1024
error[E0277]: the size for values of type `T` cannot be known at compilation time
11-
--> $DIR/wrap-dyn-in-suggestion-issue-120223.rs:23:21
25+
--> $DIR/wrap-dyn-in-suggestion-issue-120223.rs:29:21
1226
|
1327
LL | fn with_sized<T: Fn() -> &'static (dyn std::fmt::Debug) + ?Sized>() {
1428
| - this type parameter needs to be `Sized`
15-
LL | without_sized::<T>();
29+
LL | without_sized::<T>();
1630
| ^ doesn't have a size known at compile-time
1731
|
1832
note: required by an implicit `Sized` bound in `without_sized`
19-
--> $DIR/wrap-dyn-in-suggestion-issue-120223.rs:27:18
33+
--> $DIR/wrap-dyn-in-suggestion-issue-120223.rs:33:18
2034
|
2135
LL | fn without_sized<T: Fn() -> &'static dyn std::fmt::Debug>() {}
2236
| ^ required by the implicit `Sized` requirement on this type parameter in `without_sized`
@@ -58,27 +72,7 @@ help: consider adding an explicit lifetime bound
5872
LL | executor: impl FnOnce(T) -> (dyn* Future<Output = ()>) + 'static,
5973
| + +++++++++++
6074

61-
error[E0382]: use of moved value: `f`
62-
--> $DIR/wrap-dyn-in-suggestion-issue-120223.rs:19:5
63-
|
64-
LL | pub fn in_ty_param<F: FnOnce() -> &'static dyn std::fmt::Debug>(f: F) {
65-
| - move occurs because `f` has type `F`, which does not implement the `Copy` trait
66-
LL | f();
67-
| --- `f` moved due to this call
68-
LL | f();
69-
| ^ value used here after move
70-
|
71-
note: this value implements `FnOnce`, which causes it to be moved when called
72-
--> $DIR/wrap-dyn-in-suggestion-issue-120223.rs:18:5
73-
|
74-
LL | f();
75-
| ^
76-
help: consider restricting type parameters
77-
|
78-
LL | pub fn in_ty_param<F: FnOnce() -> &'static (dyn std::fmt::Debug) + Copy>(f: F) {
79-
| + ++++++++
80-
8175
error: aborting due to 4 previous errors; 1 warning emitted
8276

83-
Some errors have detailed explanations: E0277, E0310, E0382.
77+
Some errors have detailed explanations: E0277, E0310, E0599.
8478
For more information about an error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)