Skip suggest impl or dyn when poly trait is not a real trait
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
This commit is contained in:
parent
27b866d59a
commit
12604fa071
2 changed files with 1 additions and 15 deletions
|
@ -86,6 +86,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
||||||
"expected a type, found a trait"
|
"expected a type, found a trait"
|
||||||
);
|
);
|
||||||
if self_ty.span.can_be_used_for_suggestions()
|
if self_ty.span.can_be_used_for_suggestions()
|
||||||
|
&& poly_trait_ref.trait_ref.trait_def_id().is_some()
|
||||||
&& !self.maybe_suggest_impl_trait(self_ty, &mut diag)
|
&& !self.maybe_suggest_impl_trait(self_ty, &mut diag)
|
||||||
&& !self.maybe_suggest_dyn_trait(self_ty, sugg, &mut diag)
|
&& !self.maybe_suggest_dyn_trait(self_ty, sugg, &mut diag)
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,33 +21,18 @@ error[E0782]: expected a type, found a trait
|
||||||
|
|
|
|
||||||
LL | fn f<'a>(x: Box<dyn Fn() -> Option<usize + 'a>>) -> usize {
|
LL | fn f<'a>(x: Box<dyn Fn() -> Option<usize + 'a>>) -> usize {
|
||||||
| ^^^^^^^^^^
|
| ^^^^^^^^^^
|
||||||
|
|
|
||||||
help: you can add the `dyn` keyword if you want a trait object
|
|
||||||
|
|
|
||||||
LL | fn f<'a>(x: Box<dyn Fn() -> Option<dyn usize + 'a>>) -> usize {
|
|
||||||
| +++
|
|
||||||
|
|
||||||
error[E0782]: expected a type, found a trait
|
error[E0782]: expected a type, found a trait
|
||||||
--> $DIR/suggestion-trait-object-issue-139174.rs:9:32
|
--> $DIR/suggestion-trait-object-issue-139174.rs:9:32
|
||||||
|
|
|
|
||||||
LL | fn create_adder<'a>(x: i32) -> usize + 'a {
|
LL | fn create_adder<'a>(x: i32) -> usize + 'a {
|
||||||
| ^^^^^^^^^^
|
| ^^^^^^^^^^
|
||||||
|
|
|
||||||
help: `usize + 'a` is dyn-incompatible, use `impl usize + 'a` to return an opaque type, as long as you return a single underlying type
|
|
||||||
|
|
|
||||||
LL | fn create_adder<'a>(x: i32) -> impl usize + 'a {
|
|
||||||
| ++++
|
|
||||||
|
|
||||||
error[E0782]: expected a type, found a trait
|
error[E0782]: expected a type, found a trait
|
||||||
--> $DIR/suggestion-trait-object-issue-139174.rs:16:8
|
--> $DIR/suggestion-trait-object-issue-139174.rs:16:8
|
||||||
|
|
|
|
||||||
LL | x: usize + 'a,
|
LL | x: usize + 'a,
|
||||||
| ^^^^^^^^^^
|
| ^^^^^^^^^^
|
||||||
|
|
|
||||||
help: you can add the `dyn` keyword if you want a trait object
|
|
||||||
|
|
|
||||||
LL | x: dyn usize + 'a,
|
|
||||||
| +++
|
|
||||||
|
|
||||||
error: aborting due to 6 previous errors
|
error: aborting due to 6 previous errors
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue