Skip to content

Confusing suggestion when E0719 and E0191 occur at the same time. #100109

Closed
@jendrikw

Description

@jendrikw
Contributor

Given the following code: play

trait A {
    type X;
}

trait B: A {
    type X; // note: this is legal
}

impl<X> Clone for Box<dyn B<X=X, X=X>> {
    fn clone(&self) -> Self {
        todo!()
    }
}

The current output is:

error[E0719]: the value of the associated type `X` (from trait `B`) is already specified
 --> src/lib.rs:9:34
  |
9 | impl<X> Clone for Box<dyn B<X=X, X=X>> {
  |                             ---  ^^^ re-bound here
  |                             |
  |                             `X` bound here first

error[E0191] the value of the associated type `X` (from trait `A`) must be specified
 --> src/lib.rs:9:27
  |
2 |     type X;
  |     ------- `X` defined here
...
9 | impl<X> Clone for Box<dyn B<X=X, X=X>> {
  |                           ^^^^^^^^^^^ help: specify the associated type: `B<X=X, X=X, X = Type>`

B<X=X, X=X, X = Type> is wrong, specifying another X=Type isn't going to fix the problem.

Writing just dyn B has a suggestion consider introducing a new type parameter, adding `where` constraints using the fully-qualified path to the associated types, which is good, but the concrete syntax would be nice.

Activity

added
A-diagnosticsArea: Messages for errors, warnings, and lints
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Aug 3, 2022
compiler-errors

compiler-errors commented on Aug 3, 2022

@compiler-errors
Member

We probably should modify E0191 to hint that an supertrait's associated type is shadowed. I think E0719 here is fine to keep as-is, imo.

added
E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
on Aug 3, 2022
jendrikw

jendrikw commented on Aug 3, 2022

@jendrikw
ContributorAuthor

I agree the message for E0719 is good as-is.

Abhicodes-crypto

Abhicodes-crypto commented on Dec 5, 2022

@Abhicodes-crypto

Is this issue fixed ? If not can I take this up, please.
Also how exactly should E0191 be modified. Imo, I don't think E0191 should pop up in this case as E0719 conveys the message. @compiler-errors

removed their assignment
on Dec 6, 2022
Abhicodes-crypto

Abhicodes-crypto commented on Dec 6, 2022

@Abhicodes-crypto

@rustbot claim

LittleFall

LittleFall commented on Feb 22, 2023

@LittleFall
Contributor

@rustbot claim

LittleFall

LittleFall commented on Feb 26, 2023

@LittleFall
Contributor

Ask for help:
How do I specify the association type of supertrait with the same name? In other words, is there an easy way to modify the code in the issue to make it pass compilation?

Here's my clumsy way of creating a new trait.

trait A {
    type X;
}

trait B: A {
    type X; // note: this is legal
}

trait BP<P, Q>: A<X = P> + B<X = Q> {}

impl<T> Clone for Box<dyn BP<T, T>> {
    fn clone(&self) -> Self {
        todo!()
    }
}

fn main() {
    let v: Box<dyn BP<(), ()>>;
}

14 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @compiler-errors@jendrikw@fmease@LittleFall@rustbot

      Issue actions

        Confusing suggestion when E0719 and E0191 occur at the same time. · Issue #100109 · rust-lang/rust