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

unconstrained type parameter makes no suggestions as to how to fix #107295

Open
gilescope opened this issue Jan 25, 2023 · 11 comments · May be fixed by #134270
Open

unconstrained type parameter makes no suggestions as to how to fix #107295

gilescope opened this issue Jan 25, 2023 · 11 comments · May be fixed by #134270
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-papercut Diagnostics: An error or lint that needs small tweaks. 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

@gilescope
Copy link
Contributor

gilescope commented Jan 25, 2023

Code

trait MyTrait {}

struct S;

impl <U> MyTrait for S {}

Current output

error[E0207]: the type parameter `U` is not constrained by the impl trait, self type, or predicates
 --> src/lib.rs:5:7
  |
5 | impl <U> MyTrait for S {}
  |       ^ unconstrained type parameter

For more information about this error, try `rustc --explain E0207`.
error: could not compile `playground` due to previous error

Desired output

error[E0207]: the type parameter `U` is not constrained by the impl trait, self type, or predicates
 --> src/lib.rs:5:7
  |
5 | impl <U> MyTrait for S {}
  |       ^ unconstrained type parameter

Either remove the type parameter (<U>) or make use of it, for example ` for S<U>`.

For more information about this error, try `rustc --explain E0207`.
error: could not compile `playground` due to previous error

Rationale and extra context

If we have an unconstrained type parameter, we get an error stating that it is unconstrained, but no suggestions on what to do about it and force the user to google.

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=3ca555fca7f8220aaab497f87c26225b

Is there room to reduce the learning curve here with better diagnostics?

Other cases

No response

Anything else?

No response

@gilescope gilescope added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 25, 2023
@gilescope
Copy link
Contributor Author

(btw the diagnostics is really coming on - it must be many months since I've come across something that really could do with improvement. rustc has improved so much over these past few years.)

@Noratrieb
Copy link
Member

I think this diagnostics should explain all places where a type parameter can be constrained. I have definitely found this a little confusing before :)
It should also link to an explanation why this error exists in the first place, I think it can be a little confusing why the code isn't just accepted.

@chenyukang
Copy link
Member

@rustbot claim

@chenyukang chenyukang added the E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. label Feb 18, 2023
@chenyukang chenyukang removed their assignment Feb 18, 2023
@chenyukang chenyukang added the D-papercut Diagnostics: An error or lint that needs small tweaks. label Feb 18, 2023
@chenyukang
Copy link
Member

I don't have enough buffer to fix it, for anyone who would want to pick it up,
add a help message in this function:

fn report_unused_parameter(tcx: TyCtxt<'_>, span: Span, kind: &str, name: Symbol) {

need to take care the scenarios of different number of parameters.

@jkvargas
Copy link

@rustbot claim

@Haramaty
Copy link

@rustbot claim

@Lol3rrr
Copy link

Lol3rrr commented Aug 25, 2023

I am not sure if this would be a good first issue for me, but I would like to try my hand if no else is currently working on this.
@Dylan-DPC is this issue now available for me?

@Dylan-DPC
Copy link
Member

@Lol3rrr sure, if you wanna give it a try, go ahead and claim it and it's yours :)

@Lol3rrr
Copy link

Lol3rrr commented Aug 25, 2023

@rustbot claim

@LlewVallis
Copy link

Seems this has gone inactive again. I'm keen to take a look.

@rustbot claim

@kei519
Copy link
Contributor

kei519 commented Dec 9, 2024

@rustbot claim

kei519 added a commit to kei519/rust that referenced this issue Dec 13, 2024
Unconstrained type parameters made no suggestion and it makes difficult
to know how to fix (rust-lang#107295).

To make fixing easier, we output suggestions how to fix.
kei519 added a commit to kei519/rust that referenced this issue Dec 22, 2024
Unconstrained type parameters made no suggestion and it makes difficult
to know how to fix (rust-lang#107295).

To make fixing easier, we output suggestions how to fix.
kei519 added a commit to kei519/rust that referenced this issue Dec 22, 2024
kei519 added a commit to kei519/rust that referenced this issue Dec 23, 2024
kei519 added a commit to kei519/rust that referenced this issue Jan 4, 2025
Unconstrained type parameters made no suggestion and it makes difficult
to know how to fix (rust-lang#107295).

To make fixing easier, we output suggestions how to fix.
kei519 added a commit to kei519/rust that referenced this issue Jan 4, 2025
kei519 added a commit to kei519/rust that referenced this issue Jan 4, 2025
kei519 added a commit to kei519/rust that referenced this issue Jan 12, 2025
Unconstrained type parameters made no suggestion and it makes difficult
to know how to fix (rust-lang#107295).

To make fixing easier, we output suggestions how to fix.
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 D-papercut Diagnostics: An error or lint that needs small tweaks. 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
9 participants