Make impl Trait suggestion in E0746 MachineApplicable
This commit is contained in:
parent
ea7e885204
commit
b4bbe784a9
4 changed files with 23 additions and 3 deletions
|
|
@ -1840,7 +1840,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||
last_ty, trait_obj,
|
||||
),
|
||||
format!("impl {}", trait_obj),
|
||||
Applicability::MaybeIncorrect,
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
err.note(impl_trait_msg);
|
||||
} else {
|
||||
|
|
|
|||
18
src/test/ui/error-codes/E0746.fixed
Normal file
18
src/test/ui/error-codes/E0746.fixed
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
// run-rustfix
|
||||
#![allow(dead_code)]
|
||||
struct Struct;
|
||||
trait Trait {}
|
||||
impl Trait for Struct {}
|
||||
impl Trait for u32 {}
|
||||
|
||||
fn foo() -> impl Trait { Struct }
|
||||
//~^ ERROR E0746
|
||||
|
||||
fn bar() -> impl Trait { //~ ERROR E0746
|
||||
if true {
|
||||
return 0;
|
||||
}
|
||||
42
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
// run-rustfix
|
||||
#![allow(dead_code)]
|
||||
struct Struct;
|
||||
trait Trait {}
|
||||
impl Trait for Struct {}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error[E0746]: return type cannot have a bare trait because it must be `Sized`
|
||||
--> $DIR/E0746.rs:6:13
|
||||
--> $DIR/E0746.rs:8:13
|
||||
|
|
||||
LL | fn foo() -> dyn Trait { Struct }
|
||||
| ^^^^^^^^^ doesn't have a size known at compile-time
|
||||
|
|
@ -11,7 +11,7 @@ LL | fn foo() -> impl Trait { Struct }
|
|||
| ^^^^^^^^^^
|
||||
|
||||
error[E0746]: return type cannot have a bare trait because it must be `Sized`
|
||||
--> $DIR/E0746.rs:9:13
|
||||
--> $DIR/E0746.rs:11:13
|
||||
|
|
||||
LL | fn bar() -> dyn Trait {
|
||||
| ^^^^^^^^^ doesn't have a size known at compile-time
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue