-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Make generic const type mismatches not hide trait impls from the trait solver #120059
Conversation
r? @wesleywiser (rustbot has picked a reviewer for you, use r? to override) |
Why aren't you happy with this change? It doesn't seem to make diagnostics much worse -- the only material change is that we flip a type error into a coherence overlap error, but both of them are valid errors, so the choice seems a bit arbitrary. I'm happy to approve this if you want to actually give it a real description and title and stuff. Otherwise, I'd like to hear more about your reservations with this change. |
error: the constant `13` is not of type `u64` | ||
--> $DIR/bad-subst-const-kind.rs:13:24 | ||
| | ||
LL | pub fn test() -> [u8; <[u8; 13] as Q>::ASSOC] { todo!() } | ||
| ^^^^^^^^ expected `u64`, found `usize` |
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.
the compiler suggests using a u64
as an array length
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.
yeah we have bad spans for this in general
error[E0308]: mismatched types | ||
--> $DIR/bad-subst-const-kind.rs:8:31 | ||
| | ||
LL | impl<const N: u64> Q for [u8; N] { | ||
| ^ expected `usize`, found `u64` | ||
|
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 only diagnostic I would expect to see. But I haven't figured out yet how to poison the impl so it doesn't get picked up
error[E0308]: mismatched types | ||
--> $DIR/type_mismatch.rs:8:31 | ||
| | ||
LL | impl<const N: u64> Q for [u8; N] {} | ||
| ^ expected `usize`, found `u64` | ||
|
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 good, I want this error. But now we also got a bunch of "follow-up" errors happening before. Maybe we can move whatever causes this error into a query that is guaranteed to be called before impl overlap checking
tests/ui/specialization/min_specialization/bad-const-wf-doesnt-specialize.rs
Show resolved
Hide resolved
Type relation code was changed |
9265e13
to
2040c1c
Compare
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.
I'm ok w the state of these errors right now.
r=me unless you want to continue to iterate on this, though I guess you could/should probably file a follow-up diagnostic issue for the really bad case of tests/ui/const-generics/bad-subst-const-kind.rs
since I agree that one is particularly confusing.
@bors r=compiler-errors I have tried a few things, but it's very hard to improve the span here. All we have is the span of the array, and it's a ty::Array with an already evaluated length const. I'll keep digging |
…=compiler-errors Make generic const type mismatches not hide trait impls from the trait solver pulled out of rust-lang#119895 It does improve diagnostics somewhat, but also causes some extraneous diagnostics in potentially misleading order. The issue was that a const type mismatch, instead of reporting an error, would silently poison the constant, only for that information to be thrown away and the impl to be treated as "not matching". In rust-lang#119895 this would cause ICEs as well as errors on impls stating that the impl needs to exist for itself to be valid.
2040c1c
to
9454b51
Compare
…=compiler-errors Make generic const type mismatches not hide trait impls from the trait solver pulled out of rust-lang#119895 It does improve diagnostics somewhat, but also causes some extraneous diagnostics in potentially misleading order. The issue was that a const type mismatch, instead of reporting an error, would silently poison the constant, only for that information to be thrown away and the impl to be treated as "not matching". In rust-lang#119895 this would cause ICEs as well as errors on impls stating that the impl needs to exist for itself to be valid.
…iaskrgr Rollup of 11 pull requests Successful merges: - rust-lang#117910 (Refactor uses of `objc_msgSend` to no longer have clashing definitions) - rust-lang#118639 (Undeprecate lint `unstable_features` and make use of it in the compiler) - rust-lang#119801 (Fix deallocation with wrong allocator in (A)Rc::from_box_in) - rust-lang#120058 (bootstrap: improvements for compiler builds) - rust-lang#120059 (Make generic const type mismatches not hide trait impls from the trait solver) - rust-lang#120097 (Report unreachable subpatterns consistently) - rust-lang#120137 (Validate AggregateKind types in MIR) - rust-lang#120164 (`maybe_lint_impl_trait`: separate `is_downgradable` from `is_object_safe`) - rust-lang#120181 (Allow any `const` expression blocks in `thread_local!`) - rust-lang#120204 (Builtin macros effectively have implicit #[collapse_debuginfo(yes)]) - rust-lang#120218 (rustfmt: Check that a token can begin a nonterminal kind before parsing it as a macro arg) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 10 pull requests Successful merges: - rust-lang#117910 (Refactor uses of `objc_msgSend` to no longer have clashing definitions) - rust-lang#118639 (Undeprecate lint `unstable_features` and make use of it in the compiler) - rust-lang#119801 (Fix deallocation with wrong allocator in (A)Rc::from_box_in) - rust-lang#120058 (bootstrap: improvements for compiler builds) - rust-lang#120059 (Make generic const type mismatches not hide trait impls from the trait solver) - rust-lang#120097 (Report unreachable subpatterns consistently) - rust-lang#120137 (Validate AggregateKind types in MIR) - rust-lang#120164 (`maybe_lint_impl_trait`: separate `is_downgradable` from `is_object_safe`) - rust-lang#120181 (Allow any `const` expression blocks in `thread_local!`) - rust-lang#120218 (rustfmt: Check that a token can begin a nonterminal kind before parsing it as a macro arg) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#120059 - oli-obk:const_arg_type_mismatch, r=compiler-errors Make generic const type mismatches not hide trait impls from the trait solver pulled out of rust-lang#119895 It does improve diagnostics somewhat, but also causes some extraneous diagnostics in potentially misleading order. The issue was that a const type mismatch, instead of reporting an error, would silently poison the constant, only for that information to be thrown away and the impl to be treated as "not matching". In rust-lang#119895 this would cause ICEs as well as errors on impls stating that the impl needs to exist for itself to be valid.
pulled out of #119895
It does improve diagnostics somewhat, but also causes some extraneous diagnostics in potentially misleading order.
The issue was that a const type mismatch, instead of reporting an error, would silently poison the constant, only for that information to be thrown away and the impl to be treated as "not matching". In #119895 this would cause ICEs as well as errors on impls stating that the impl needs to exist for itself to be valid.