Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type mismatch mentioning trait as type #72217

Closed
lcnr opened this issue May 14, 2020 · 6 comments · Fixed by #74698
Closed

Type mismatch mentioning trait as type #72217

lcnr opened this issue May 14, 2020 · 6 comments · Fixed by #74698
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@lcnr
Copy link
Contributor

lcnr commented May 14, 2020

trait DynEq {}

impl<'a> PartialEq for &'a (dyn DynEq + 'static) {
    fn eq(&self, _other: &Self) -> bool {
        true
    }
}

impl Eq for &dyn DynEq {}

Causes the following error:

error[E0308]: mismatched types
 --> src/lib.rs:9:6
  |
9 | impl Eq for &dyn DynEq {}
  |      ^^ lifetime mismatch
  |
  = note: expected type `std::cmp::PartialEq`
             found type `std::cmp::PartialEq`
note: the lifetime `'_` as defined on the impl at 9:13...
 --> src/lib.rs:9:13
  |
9 | impl Eq for &dyn DynEq {}
  |             ^
  = note: ...does not necessarily outlive the static lifetime

This is somewhat confusing, especially since std::cmp::PartialEq is not a type.

This issue has been assigned to @ayrtonm via this comment.

@lcnr lcnr added C-bug Category: This is a bug. A-diagnostics Area: Messages for errors, warnings, and lints D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. labels May 14, 2020
@jonas-schievink jonas-schievink added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label May 14, 2020
@rodrimati1992
Copy link
Contributor

This looks similar to what I reported in #59865

@estebank
Copy link
Contributor

Here we don't account for anything other than type mismatches

let (expected_found, exp_found, is_simple_error) = match values {
None => (None, None, false),
Some(values) => {
let (is_simple_error, exp_found) = match values {
ValuePairs::Types(exp_found) => {
let is_simple_err =
exp_found.expected.is_simple_text() && exp_found.found.is_simple_text();
OpaqueTypesVisitor::visit_expected_found(
self.tcx,
exp_found.expected,
exp_found.found,
span,
)
.report(diag);
(is_simple_err, Some(exp_found))
}
_ => (false, None),
};
let vals = match self.values_str(&values) {
Some((expected, found)) => Some((expected, found)),
None => {
// Derived error. Cancel the emitter.
diag.cancel();
return;
}
};
(vals, exp_found, is_simple_error)
}
};

which means that later we use the generic "type" prefix

let expected_label = exp_found.map_or("type".into(), |ef| ef.expected.prefix_string());
let found_label = exp_found.map_or("type".into(), |ef| ef.found.prefix_string());

We need to account for ValuePairs::TraitRefs in the first snippet and ferry the prefix strings from there to the later (instead of what we do now).

@estebank estebank added the E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. label Jul 14, 2020
@ayrtonm
Copy link
Contributor

ayrtonm commented Jul 23, 2020

I'd like to work on this
@rustbot claim

@rustbot rustbot self-assigned this Jul 23, 2020
@estebank
Copy link
Contributor

@ayrtonm do not hesitate to reach out if you need help!

@ayrtonm
Copy link
Contributor

ayrtonm commented Jul 23, 2020

Do we need to get the correct prefix strings from the contents of ValuePairs::TraitRefs or are they just "trait"?

@estebank
Copy link
Contributor

I believe they can be just "trait".

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Jul 24, 2020
…=estebank

fixed error reporting for mismatched traits

mismatched traits were previously referred to as types

closes rust-lang#72217
@bors bors closed this as completed in 7f24c7d Jul 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants