-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Perform WF-check on type
s with no type parameters
#69741
Conversation
r? @varkor (rust_highfive has picked a reviewer for you, use r? to override) |
error[E0277]: the trait bound `NoClone: std::clone::Clone` is not satisfied | ||
--> $DIR/struct-path-alias-bounds.rs:9:13 | ||
--> $DIR/struct-path-alias-bounds.rs:6:10 | ||
| | ||
LL | struct S<T: Clone> { a: T } | ||
| ------------------ required by `S` | ||
... | ||
LL | let s = A { a: NoClone }; | ||
| ^ the trait `std::clone::Clone` is not implemented for `NoClone` | ||
LL | type A = S<NoClone>; | ||
| ^^^^^^^^^^ the trait `std::clone::Clone` is not implemented for `NoClone` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the category of errors I wanted to improve.
I would indeed like to make progress on this but I'm a bit nervous about making this change in isolation, without a broader plan in place. We should do a crater run to get an idea of the impact, this may require future compatibility warnings. |
@bors try @craterbot check |
⌛ Trying commit 6d65bc6f491739479c2eb69b7280cf772ece1a4d with merge 89c05fd3cc6404a13e1bd71450c6132a2755fa4b... |
☀️ Try build successful - checks-azure |
@craterbot check |
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
Someone (maybe me later if someone reminds me in PM) should find the late 2018 PRs/issues relevant to this, since it's quite possible we did this exact crater run then. |
@eddyb I'll dig into it, but in the meantime I thought it was a good idea to test again because even if the semantic consequences of this change haven't changed since then, the ecosystem's reliance on the current behavior might have. |
🎉 Experiment
|
|
I reached out to the |
Are we waiting on the lang team to discuss this again, or is this ready for review? |
Probably the former :) |
This distinction is already the case for type param defaults, so the following doesn't error even though the type default isn't wf. struct Foo<T, U = (Vec<[u32]>, T)>(T, U); Have we tried always erroring on eval errors of constants in type aliases? I don't think there is much, if any, code using incorrect constants there. So i personally would be interested in trying that instead of modifying const eval. |
This is what is done right now, and there were no regressions on crater that had const eval errors (I just checked again). |
//pub type Foo = [i32; 0 - 1]; | ||
//^ evaluation of constant value failed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please turn these into error tests (see https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/erroneous.20constants.20in.20type.20alias/near/229492342 for "lang team sign off on making this a hard error since crater is clean")
To be clear, I thought the @rust-lang/lang consensus was that we would be ok with issuing warnings, but not errors. |
Yes, but constants were not discussed. So I brought it up on zulip, and my message got one textual approval and two thumbs-up reactions. |
Perhaps I am missing something. |
I created a workaround that does not hard error in #82700 but it made no one in @rust-lang/wg-const-eval happy (including myself). The main difference between hard erroring on constants and hard erroring on other wf-bounds checks failing is that the latter has crater regressions while the former does not. Other than that, the reasoning about making it hard errors or not is the same. |
Hmm. My problem with hard errors on other wf-bounds checks is not that they have crater regressions, but that it's inconsistent to do so only in narrow cases. I'm not sure what would make constants different from anything else: I guess it's just that we get ICEs sometimes with constants? This seems related to the questions we were discussing in our recent meeting. |
☔ The latest upstream changes (presumably #84556) made this pull request unmergeable. Please resolve the merge conflicts. |
No, the problem is that error reporting on constants happens inside the query that evaluates the constant. We would need to walk up the DefId parents of a constant to see whether it is part of a type alias and then change the behaviour of the error reporting. This is possible, but it complicates our ctfe error reporting machinery further. |
I see, that's interesting. I think my expectation is that we would simply not evaluate the default value in any way until it is used. I guess this is not what we do? |
Wf-check evaluated all constants, because "an array type whose length computation errors is not well formed". At least that was how I understood wfcheck in other places. We could generally stop const evaluating during wfcheck, even in other situations and leave it to the usages, but I'm not sure what the ramnifications of that are |
@oli-obk @nikomatsakis is there any update on this? |
Start performing a WF-check on
type
s without type parameters to verify that they will be able to be constructed.Do not perform a
Sized
check, astype T = dyn Trait;
should be allowed.Do not WF-check
type
s with type parameters because we currently lint againsttype T<X: Trait> = K<X>;
because we do not propagateX: Trait
, which means that we currently allowtype T<X> = <X as Trait>::Foo;
, which would be rejected if we WF-checked it because it would need to be written astype 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 thetype
or (my preferred solution) properly propagate the explicitX: Trait
obligation to the uses, which would likely be a breaking change.Fixes #60980 by using a more appropriate span for the error.