Don't suggest cyclic associated type constraint
This commit is contained in:
parent
acf257e62c
commit
c92140e838
3 changed files with 29 additions and 0 deletions
|
@ -374,12 +374,18 @@ impl<T> Trait<T> for X {
|
||||||
) {
|
) {
|
||||||
let tcx = self.tcx;
|
let tcx = self.tcx;
|
||||||
|
|
||||||
|
// Don't suggest constraining a projection to something containing itself
|
||||||
|
if self.tcx.erase_regions(values.found).contains(self.tcx.erase_regions(values.expected)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let msg = || {
|
let msg = || {
|
||||||
format!(
|
format!(
|
||||||
"consider constraining the associated type `{}` to `{}`",
|
"consider constraining the associated type `{}` to `{}`",
|
||||||
values.expected, values.found
|
values.expected, values.found
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
let body_owner = tcx.hir().get_if_local(body_owner_def_id);
|
let body_owner = tcx.hir().get_if_local(body_owner_def_id);
|
||||||
let current_method_ident = body_owner.and_then(|n| n.ident()).map(|i| i.name);
|
let current_method_ident = body_owner.and_then(|n| n.ident()).map(|i| i.name);
|
||||||
|
|
||||||
|
|
11
tests/ui/associated-types/dont-suggest-cyclic-constraint.rs
Normal file
11
tests/ui/associated-types/dont-suggest-cyclic-constraint.rs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
use std::fmt::Debug;
|
||||||
|
|
||||||
|
fn foo<I: Iterator>(mut iter: I, value: &I::Item)
|
||||||
|
where
|
||||||
|
I::Item: Eq + Debug,
|
||||||
|
{
|
||||||
|
debug_assert_eq!(iter.next(), Some(value));
|
||||||
|
//~^ ERROR mismatched types
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
|
@ -0,0 +1,12 @@
|
||||||
|
error[E0308]: mismatched types
|
||||||
|
--> $DIR/dont-suggest-cyclic-constraint.rs:7:35
|
||||||
|
|
|
||||||
|
LL | debug_assert_eq!(iter.next(), Some(value));
|
||||||
|
| ^^^^^^^^^^^ expected `Option<<I as Iterator>::Item>`, found `Option<&<I as Iterator>::Item>`
|
||||||
|
|
|
||||||
|
= note: expected enum `Option<<I as Iterator>::Item>`
|
||||||
|
found enum `Option<&<I as Iterator>::Item>`
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0308`.
|
Loading…
Add table
Add a link
Reference in a new issue