-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Misleading diagnostic span using trait projections in arguments #60980
Comments
The following is where the obligation could be changed from rust/src/librustc/infer/mod.rs Lines 1528 to 1550 in c20654e
And here is where we could peek at that new obligation and extend it with further information. rust/src/librustc/traits/project.rs Lines 417 to 455 in c20654e
Doing the naïve change
The proper solution would require to track
|
@rust-lang/lang: we could assert well-formedness of
Is this something we would consider doing, even if it is as a warning? I believe this would be effectively a breaking change (code that compiles today would stop compiling) but not "in effect" because the previously compiling code could never be used. This seems to me like an accident to me. For example, there's a test Edit: I see now that because we explicitily do not accept trait bounds on Edit: #69741 has the simplest change that should be safe to introduce based on my current understanding of the situation. |
Start performing a WF-check on `type`s to verify that they will be able to be constructed. Do *not* perform a `Sized` check, as `type T = dyn Trait;` should be allowed. Do *not* WF-check `type`s with type parameters because we currently lint *against* `type T<X: Trait> = K<X>;` because we do not propagate `X: Trait`, which means that we currently allow `type T<X> = <X as Trait>::Foo;`, which would be rejected if we WF-checked it because it would need to be written as `type T<X: Trait> = <X as Trait>::Foo;` to be correct. Instead, we simply don't check it at definition and only do so at use like we do currently. In the future, the alternatives would be to either automatically backpropagate the `X: Trait` obligation when WF-checking the `type` or (my preferred solution) properly propagate the explicit `X: Trait` obligation to the uses, which would likely be a breaking change. Fixes rust-lang#60980 by using a more appropriate span for the error.
I came across an interesting case today where the span for a diagnostic isn't quite leading to the best location. When compiling the example code below
you get:
but it's sort of misleading because neither
A
norIntoWasmAbi
is mentioned in the highlight. It'd be ideal if the error would point to thetype
definition to indicat that's where the source of the error comes from.The text was updated successfully, but these errors were encountered: