diag: improve closure/generic parameter mismatch
This commit improves the diagnostic when a type parameter is expected and a closure is found, noting that each closure has a distinct type and therefore could not always match the caller-chosen type of the parameter. Signed-off-by: David Wood <david@davidtw.co>
This commit is contained in:
parent
b5f55b7e15
commit
01f65afa4a
4 changed files with 37 additions and 5 deletions
|
@ -473,6 +473,18 @@ impl<T> Trait<T> for X {
|
|||
#traits-as-parameters",
|
||||
);
|
||||
}
|
||||
(ty::Param(p), ty::Closure(..) | ty::Generator(..)) => {
|
||||
let generics = self.generics_of(body_owner_def_id);
|
||||
let p_span = self.def_span(generics.type_param(p, self).def_id);
|
||||
if !sp.contains(p_span) {
|
||||
db.span_label(p_span, "this type parameter");
|
||||
}
|
||||
db.help(&format!(
|
||||
"every closure has a distinct type and so could not always match the \
|
||||
caller-chosen type of parameter `{}`",
|
||||
p
|
||||
));
|
||||
}
|
||||
(ty::Param(p), _) | (_, ty::Param(p)) => {
|
||||
let generics = self.generics_of(body_owner_def_id);
|
||||
let p_span = self.def_span(generics.type_param(p, self).def_id);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue