Print closure signatures when reporting placeholder errors
This commit is contained in:
parent
94c11dfe78
commit
9337d4fde8
5 changed files with 38 additions and 12 deletions
|
@ -386,12 +386,38 @@ impl NiceRegionError<'me, 'tcx> {
|
||||||
let mut note = if same_self_type {
|
let mut note = if same_self_type {
|
||||||
let mut self_ty = expected_trait_ref.map(|tr| tr.self_ty());
|
let mut self_ty = expected_trait_ref.map(|tr| tr.self_ty());
|
||||||
self_ty.highlight.maybe_highlighting_region(vid, actual_has_vid);
|
self_ty.highlight.maybe_highlighting_region(vid, actual_has_vid);
|
||||||
|
|
||||||
|
if self_ty.value.is_closure()
|
||||||
|
&& self
|
||||||
|
.tcx()
|
||||||
|
.fn_trait_kind_from_lang_item(expected_trait_ref.value.def_id)
|
||||||
|
.is_some()
|
||||||
|
{
|
||||||
|
let closure_sig = self_ty.map(|closure| {
|
||||||
|
if let ty::Closure(_, substs) = closure.kind() {
|
||||||
|
self.tcx().signature_unclosure(
|
||||||
|
substs.as_closure().sig(),
|
||||||
|
rustc_hir::Unsafety::Normal,
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
bug!("type is not longer closure");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
format!(
|
||||||
|
"{}closure with signature `{}` must implement `{}`",
|
||||||
|
if leading_ellipsis { "..." } else { "" },
|
||||||
|
closure_sig,
|
||||||
|
expected_trait_ref.map(|tr| tr.print_only_trait_path()),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
format!(
|
format!(
|
||||||
"{}`{}` must implement `{}`",
|
"{}`{}` must implement `{}`",
|
||||||
if leading_ellipsis { "..." } else { "" },
|
if leading_ellipsis { "..." } else { "" },
|
||||||
self_ty,
|
self_ty,
|
||||||
expected_trait_ref.map(|tr| tr.print_only_trait_path()),
|
expected_trait_ref.map(|tr| tr.print_only_trait_path()),
|
||||||
)
|
)
|
||||||
|
}
|
||||||
} else if passive_voice {
|
} else if passive_voice {
|
||||||
format!(
|
format!(
|
||||||
"{}`{}` would have to be implemented for the type `{}`",
|
"{}`{}` would have to be implemented for the type `{}`",
|
||||||
|
|
|
@ -4,7 +4,7 @@ error: implementation of `FnOnce` is not general enough
|
||||||
LL | Foo(Box::new(|_| ()));
|
LL | Foo(Box::new(|_| ()));
|
||||||
| ^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
|
| ^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
|
||||||
|
|
|
|
||||||
= note: `[closure@$DIR/issue-57843.rs:25:18: 25:24]` must implement `FnOnce<(&'1 bool,)>`, for any lifetime `'1`...
|
= note: closure with signature `fn(&'2 bool)` must implement `FnOnce<(&'1 bool,)>`, for any lifetime `'1`...
|
||||||
= note: ...but it actually implements `FnOnce<(&'2 bool,)>`, for some specific lifetime `'2`
|
= note: ...but it actually implements `FnOnce<(&'2 bool,)>`, for some specific lifetime `'2`
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
|
@ -4,7 +4,7 @@ error: implementation of `FnOnce` is not general enough
|
||||||
LL | thing(f);
|
LL | thing(f);
|
||||||
| ^^^^^ implementation of `FnOnce` is not general enough
|
| ^^^^^ implementation of `FnOnce` is not general enough
|
||||||
|
|
|
|
||||||
= note: `[closure@$DIR/issue-79187.rs:4:13: 4:19]` must implement `FnOnce<(&'1 u32,)>`, for any lifetime `'1`...
|
= note: closure with signature `fn(&'2 u32)` must implement `FnOnce<(&'1 u32,)>`, for any lifetime `'1`...
|
||||||
= note: ...but it actually implements `FnOnce<(&'2 u32,)>`, for some specific lifetime `'2`
|
= note: ...but it actually implements `FnOnce<(&'2 u32,)>`, for some specific lifetime `'2`
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
|
@ -30,7 +30,7 @@ error: implementation of `FnOnce` is not general enough
|
||||||
LL | type Bar = impl Baz<Self, Self>;
|
LL | type Bar = impl Baz<Self, Self>;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
|
| ^^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
|
||||||
|
|
|
|
||||||
= note: `[closure@$DIR/issue-57611-trait-alias.rs:25:9: 25:14]` must implement `FnOnce<(&'1 X,)>`, for any lifetime `'1`...
|
= note: closure with signature `fn(&'2 X) -> &'2 X` must implement `FnOnce<(&'1 X,)>`, for any lifetime `'1`...
|
||||||
= note: ...but it actually implements `FnOnce<(&'2 X,)>`, for some specific lifetime `'2`
|
= note: ...but it actually implements `FnOnce<(&'2 X,)>`, for some specific lifetime `'2`
|
||||||
|
|
||||||
error: aborting due to 4 previous errors
|
error: aborting due to 4 previous errors
|
||||||
|
|
|
@ -4,7 +4,7 @@ error: implementation of `FnOnce` is not general enough
|
||||||
LL | type Bar = impl Baz<Self, Self>;
|
LL | type Bar = impl Baz<Self, Self>;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
|
| ^^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
|
||||||
|
|
|
|
||||||
= note: `[closure@$DIR/issue-57611-trait-alias.rs:25:9: 25:14]` must implement `FnOnce<(&'1 X,)>`, for any lifetime `'1`...
|
= note: closure with signature `fn(&'2 X) -> &X` must implement `FnOnce<(&'1 X,)>`, for any lifetime `'1`...
|
||||||
= note: ...but it actually implements `FnOnce<(&'2 X,)>`, for some specific lifetime `'2`
|
= note: ...but it actually implements `FnOnce<(&'2 X,)>`, for some specific lifetime `'2`
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
error[E0308]: mismatched types
|
||||||
|
@ -27,7 +27,7 @@ error: implementation of `FnOnce` is not general enough
|
||||||
LL | type Bar = impl Baz<Self, Self>;
|
LL | type Bar = impl Baz<Self, Self>;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
|
| ^^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
|
||||||
|
|
|
|
||||||
= note: `[closure@$DIR/issue-57611-trait-alias.rs:25:9: 25:14]` must implement `FnOnce<(&'1 X,)>`, for any lifetime `'1`...
|
= note: closure with signature `fn(&'2 X) -> &'2 X` must implement `FnOnce<(&'1 X,)>`, for any lifetime `'1`...
|
||||||
= note: ...but it actually implements `FnOnce<(&'2 X,)>`, for some specific lifetime `'2`
|
= note: ...but it actually implements `FnOnce<(&'2 X,)>`, for some specific lifetime `'2`
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
error[E0308]: mismatched types
|
||||||
|
@ -50,7 +50,7 @@ error: implementation of `FnOnce` is not general enough
|
||||||
LL | type Bar = impl Baz<Self, Self>;
|
LL | type Bar = impl Baz<Self, Self>;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
|
| ^^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
|
||||||
|
|
|
|
||||||
= note: `[closure@$DIR/issue-57611-trait-alias.rs:25:9: 25:14]` must implement `FnOnce<(&'1 X,)>`, for any lifetime `'1`...
|
= note: closure with signature `fn(&'2 X) -> &'2 X` must implement `FnOnce<(&'1 X,)>`, for any lifetime `'1`...
|
||||||
= note: ...but it actually implements `FnOnce<(&'2 X,)>`, for some specific lifetime `'2`
|
= note: ...but it actually implements `FnOnce<(&'2 X,)>`, for some specific lifetime `'2`
|
||||||
|
|
||||||
error: aborting due to 5 previous errors
|
error: aborting due to 5 previous errors
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue