Wrap dyn type with parentheses in suggestion
This commit is contained in:
parent
453ceafce3
commit
31e581ec12
10 changed files with 286 additions and 62 deletions
|
|
@ -12,7 +12,18 @@ impl Foo for S {}
|
|||
impl Bar for S {}
|
||||
|
||||
fn test(foo: impl Foo + Bar) {
|
||||
foo.hello(); //~ ERROR E0599
|
||||
foo.hello(); //~ ERROR no method named `hello` found
|
||||
}
|
||||
|
||||
trait Trait {
|
||||
fn method(&self) {}
|
||||
}
|
||||
|
||||
impl Trait for fn() {}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn test2(f: impl Fn() -> (dyn std::fmt::Debug) + Trait) {
|
||||
f.method(); //~ ERROR no method named `method` found
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,18 @@ impl Foo for S {}
|
|||
impl Bar for S {}
|
||||
|
||||
fn test(foo: impl Foo) {
|
||||
foo.hello(); //~ ERROR E0599
|
||||
foo.hello(); //~ ERROR no method named `hello` found
|
||||
}
|
||||
|
||||
trait Trait {
|
||||
fn method(&self) {}
|
||||
}
|
||||
|
||||
impl Trait for fn() {}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn test2(f: impl Fn() -> dyn std::fmt::Debug) {
|
||||
f.method(); //~ ERROR no method named `method` found
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -12,6 +12,20 @@ help: the following trait defines an item `hello`, perhaps you need to restrict
|
|||
LL | fn test(foo: impl Foo + Bar) {
|
||||
| +++++
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
error[E0599]: no method named `method` found for type parameter `impl Fn() -> dyn std::fmt::Debug` in the current scope
|
||||
--> $DIR/impl-trait-with-missing-trait-bounds-in-arg.rs:26:7
|
||||
|
|
||||
LL | fn test2(f: impl Fn() -> dyn std::fmt::Debug) {
|
||||
| -------------------------------- method `method` not found for this type parameter
|
||||
LL | f.method();
|
||||
| ^^^^^^ method not found in `impl Fn() -> dyn std::fmt::Debug`
|
||||
|
|
||||
= help: items from traits can only be used if the type parameter is bounded by the trait
|
||||
help: the following trait defines an item `method`, perhaps you need to restrict type parameter `impl Fn() -> dyn std::fmt::Debug` with it:
|
||||
|
|
||||
LL | fn test2(f: impl Fn() -> (dyn std::fmt::Debug) + Trait) {
|
||||
| + +++++++++
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0599`.
|
||||
|
|
|
|||
35
tests/ui/suggestions/wrap-dyn-in-suggestion-issue-120223.rs
Normal file
35
tests/ui/suggestions/wrap-dyn-in-suggestion-issue-120223.rs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#![feature(dyn_star)] //~ WARNING the feature `dyn_star` is incomplete
|
||||
|
||||
use std::future::Future;
|
||||
|
||||
pub fn dyn_func<T>(
|
||||
executor: impl FnOnce(T) -> dyn Future<Output = ()>,
|
||||
) -> Box<dyn FnOnce(T) -> dyn Future<Output = ()>> {
|
||||
Box::new(executor) //~ ERROR may not live long enough
|
||||
}
|
||||
|
||||
pub fn dyn_star_func<T>(
|
||||
executor: impl FnOnce(T) -> dyn* Future<Output = ()>,
|
||||
) -> Box<dyn FnOnce(T) -> dyn* Future<Output = ()>> {
|
||||
Box::new(executor) //~ ERROR may not live long enough
|
||||
}
|
||||
|
||||
trait Trait {
|
||||
fn method(&self) {}
|
||||
}
|
||||
|
||||
impl Trait for fn() {}
|
||||
|
||||
pub fn in_ty_param<T: Fn() -> dyn std::fmt::Debug> (t: T) {
|
||||
t.method();
|
||||
//~^ ERROR no method named `method` found for type parameter `T`
|
||||
}
|
||||
|
||||
fn with_sized<T: Fn() -> &'static (dyn std::fmt::Debug) + ?Sized>() {
|
||||
without_sized::<T>();
|
||||
//~^ ERROR the size for values of type `T` cannot be known at compilation time
|
||||
}
|
||||
|
||||
fn without_sized<T: Fn() -> &'static dyn std::fmt::Debug>() {}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
warning: the feature `dyn_star` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/wrap-dyn-in-suggestion-issue-120223.rs:1:12
|
||||
|
|
||||
LL | #![feature(dyn_star)]
|
||||
| ^^^^^^^^
|
||||
|
|
||||
= note: see issue #102425 <https://github.com/rust-lang/rust/issues/102425> for more information
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
|
||||
error[E0599]: no method named `method` found for type parameter `T` in the current scope
|
||||
--> $DIR/wrap-dyn-in-suggestion-issue-120223.rs:24:7
|
||||
|
|
||||
LL | pub fn in_ty_param<T: Fn() -> dyn std::fmt::Debug> (t: T) {
|
||||
| - method `method` not found for this type parameter
|
||||
LL | t.method();
|
||||
| ^^^^^^ method not found in `T`
|
||||
|
|
||||
= help: items from traits can only be used if the type parameter is bounded by the trait
|
||||
help: the following trait defines an item `method`, perhaps you need to restrict type parameter `T` with it:
|
||||
|
|
||||
LL | pub fn in_ty_param<T: Fn() -> (dyn std::fmt::Debug) + Trait> (t: T) {
|
||||
| + +++++++++
|
||||
|
||||
error[E0277]: the size for values of type `T` cannot be known at compilation time
|
||||
--> $DIR/wrap-dyn-in-suggestion-issue-120223.rs:29:21
|
||||
|
|
||||
LL | fn with_sized<T: Fn() -> &'static (dyn std::fmt::Debug) + ?Sized>() {
|
||||
| - this type parameter needs to be `Sized`
|
||||
LL | without_sized::<T>();
|
||||
| ^ doesn't have a size known at compile-time
|
||||
|
|
||||
note: required by an implicit `Sized` bound in `without_sized`
|
||||
--> $DIR/wrap-dyn-in-suggestion-issue-120223.rs:33:18
|
||||
|
|
||||
LL | fn without_sized<T: Fn() -> &'static dyn std::fmt::Debug>() {}
|
||||
| ^ required by the implicit `Sized` requirement on this type parameter in `without_sized`
|
||||
help: consider removing the `?Sized` bound to make the type parameter `Sized`
|
||||
|
|
||||
LL - fn with_sized<T: Fn() -> &'static (dyn std::fmt::Debug) + ?Sized>() {
|
||||
LL + fn with_sized<T: Fn() -> &'static (dyn std::fmt::Debug)>() {
|
||||
|
|
||||
help: consider relaxing the implicit `Sized` restriction
|
||||
|
|
||||
LL | fn without_sized<T: Fn() -> &'static (dyn std::fmt::Debug) + ?Sized>() {}
|
||||
| + ++++++++++
|
||||
|
||||
error[E0310]: the parameter type `impl FnOnce(T) -> dyn Future<Output = ()>` may not live long enough
|
||||
--> $DIR/wrap-dyn-in-suggestion-issue-120223.rs:8:5
|
||||
|
|
||||
LL | Box::new(executor)
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| the parameter type `impl FnOnce(T) -> dyn Future<Output = ()>` must be valid for the static lifetime...
|
||||
| ...so that the type `impl FnOnce(T) -> dyn Future<Output = ()>` will meet its required lifetime bounds
|
||||
|
|
||||
help: consider adding an explicit lifetime bound
|
||||
|
|
||||
LL | executor: impl FnOnce(T) -> (dyn Future<Output = ()>) + 'static,
|
||||
| + +++++++++++
|
||||
|
||||
error[E0310]: the parameter type `impl FnOnce(T) -> Future<Output = ()>` may not live long enough
|
||||
--> $DIR/wrap-dyn-in-suggestion-issue-120223.rs:14:5
|
||||
|
|
||||
LL | Box::new(executor)
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| the parameter type `impl FnOnce(T) -> Future<Output = ()>` must be valid for the static lifetime...
|
||||
| ...so that the type `impl FnOnce(T) -> Future<Output = ()>` will meet its required lifetime bounds
|
||||
|
|
||||
help: consider adding an explicit lifetime bound
|
||||
|
|
||||
LL | executor: impl FnOnce(T) -> (dyn* Future<Output = ()>) + 'static,
|
||||
| + +++++++++++
|
||||
|
||||
error: aborting due to 4 previous errors; 1 warning emitted
|
||||
|
||||
Some errors have detailed explanations: E0277, E0310, E0599.
|
||||
For more information about an error, try `rustc --explain E0277`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue