forked from rust-lang/rust
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#87348 - SkiFire13:fix-87261, r=oli-obk
Fix span when suggesting to add an associated type bound Fixes rust-lang#87261 Note that this fix is not perfect, it ~~will still give incorrect~~ won't give suggestions in some situations: - If the associated type is defined on a supertrait of those contained in the opaque type, it will fallback to the previous behaviour, e.g. if `AssocTy` is defined on the trait `Foo`, `Bar` has `Foo` as supertrait and the opaque type is a `impl Bar + Baz`. - If the the associated type is defined on a generic trait and the opaque type includes two versions of that generic trait, e.g. the opaque type is `impl Foo<A> + Foo<B>`
- Loading branch information
Showing
3 changed files
with
382 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
trait Foo {} | ||
|
||
trait Trait { | ||
type Associated; | ||
} | ||
trait DerivedTrait: Trait {} | ||
trait GenericTrait<A> { | ||
type Associated; | ||
} | ||
|
||
struct Impl; | ||
impl Foo for Impl {} | ||
impl Trait for Impl { | ||
type Associated = (); | ||
} | ||
impl DerivedTrait for Impl {} | ||
impl<A> GenericTrait<A> for Impl { | ||
type Associated = (); | ||
} | ||
|
||
fn returns_opaque() -> impl Trait + 'static { | ||
Impl | ||
} | ||
fn returns_opaque_derived() -> impl DerivedTrait + 'static { | ||
Impl | ||
} | ||
fn returns_opaque_foo() -> impl Trait + Foo { | ||
Impl | ||
} | ||
fn returns_opaque_derived_foo() -> impl DerivedTrait + Foo { | ||
Impl | ||
} | ||
fn returns_opaque_generic() -> impl GenericTrait<()> + 'static { | ||
Impl | ||
} | ||
fn returns_opaque_generic_foo() -> impl GenericTrait<()> + Foo { | ||
Impl | ||
} | ||
fn returns_opaque_generic_duplicate() -> impl GenericTrait<()> + GenericTrait<u8> { | ||
Impl | ||
} | ||
|
||
fn accepts_trait<T: Trait<Associated = ()>>(_: T) {} | ||
fn accepts_generic_trait<T: GenericTrait<(), Associated = ()>>(_: T) {} | ||
|
||
fn check_generics<A, B, C, D, E, F, G>(a: A, b: B, c: C, d: D, e: E, f: F, g: G) | ||
where | ||
A: Trait + 'static, | ||
B: DerivedTrait + 'static, | ||
C: Trait + Foo, | ||
D: DerivedTrait + Foo, | ||
E: GenericTrait<()> + 'static, | ||
F: GenericTrait<()> + Foo, | ||
G: GenericTrait<()> + GenericTrait<u8>, | ||
{ | ||
accepts_trait(a); | ||
//~^ ERROR type mismatch resolving `<A as Trait>::Associated == ()` | ||
|
||
accepts_trait(b); | ||
//~^ ERROR type mismatch resolving `<B as Trait>::Associated == ()` | ||
|
||
accepts_trait(c); | ||
//~^ ERROR type mismatch resolving `<C as Trait>::Associated == ()` | ||
|
||
accepts_trait(d); | ||
//~^ ERROR type mismatch resolving `<D as Trait>::Associated == ()` | ||
|
||
accepts_generic_trait(e); | ||
//~^ ERROR type mismatch resolving `<E as GenericTrait<()>>::Associated == ()` | ||
|
||
accepts_generic_trait(f); | ||
//~^ ERROR type mismatch resolving `<F as GenericTrait<()>>::Associated == ()` | ||
|
||
accepts_generic_trait(g); | ||
//~^ ERROR type mismatch resolving `<G as GenericTrait<()>>::Associated == ()` | ||
} | ||
|
||
fn main() { | ||
accepts_trait(returns_opaque()); | ||
//~^ ERROR type mismatch resolving `<impl Trait as Trait>::Associated == ()` | ||
|
||
accepts_trait(returns_opaque_derived()); | ||
//~^ ERROR type mismatch resolving `<impl DerivedTrait as Trait>::Associated == ()` | ||
|
||
accepts_trait(returns_opaque_foo()); | ||
//~^ ERROR type mismatch resolving `<impl Trait+Foo as Trait>::Associated == ()` | ||
|
||
accepts_trait(returns_opaque_derived_foo()); | ||
//~^ ERROR type mismatch resolving `<impl DerivedTrait+Foo as Trait>::Associated == ()` | ||
|
||
accepts_generic_trait(returns_opaque_generic()); | ||
//~^ ERROR type mismatch resolving `<impl GenericTrait<()> as GenericTrait<()>>::Associated == ()` | ||
|
||
accepts_generic_trait(returns_opaque_generic_foo()); | ||
//~^ ERROR type mismatch resolving `<impl GenericTrait<()>+Foo as GenericTrait<()>>::Associated == ()` | ||
|
||
accepts_generic_trait(returns_opaque_generic_duplicate()); | ||
//~^ ERROR type mismatch resolving `<impl GenericTrait<()>+GenericTrait<u8> as GenericTrait<()>>::Associated == ()` | ||
} |
Oops, something went wrong.