-
Couldn't load subscription status.
- Fork 13.9k
Check that const parameters of trait methods have compatible types #86843
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
Conversation
|
(rust-highfive has picked a reviewer for you, use r? to override) |
|
Maybe r? @jackh726 |
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 PR is looking good, some nits but after that r=me
|
r? @lcnr |
|
thx @bors r+ rollup |
|
📌 Commit 9b874c4 has been approved by |
Check that const parameters of trait methods have compatible types This PR fixes rust-lang#86820. The problem is that this currently passes the type checker: ```rust trait Tr { fn foo<const N: u8>(self) -> u8; } impl Tr for f32 { fn foo<const N: bool>(self) -> u8 { 42 } } ``` i.e. the type checker fails to check whether const parameters in `impl` methods have the same type as the corresponding declaration in the trait. With my changes, I get, for the above code: ``` error[E0053]: method `foo` has an incompatible const parameter type for trait --> test.rs:6:18 | 6 | fn foo<const N: bool>(self) -> u8 { 42 } | ^ | note: the const parameter `N` has type `bool`, but the declaration in trait `Tr::foo` has type `u8` --> test.rs:2:18 | 2 | fn foo<const N: u8>(self) -> u8; | ^ error: aborting due to previous error ``` This fixes rust-lang#86820, where an ICE happens later on because the trait method is declared with a const parameter of type `u8`, but the `impl` uses one of type `usize`: > `expected int of size 8, but got size 1`
Rollup of 8 pull requests Successful merges: - rust-lang#86763 (Add a regression test for issue-63355) - rust-lang#86814 (Recover from a misplaced inner doc comment) - rust-lang#86843 (Check that const parameters of trait methods have compatible types) - rust-lang#86889 (rustdoc: Cleanup ExternalCrate) - rust-lang#87092 (Remove nondeterminism in multiple-definitions test) - rust-lang#87170 (Add diagnostic items for Clippy) - rust-lang#87183 (fix typo in compile_fail doctest) - rust-lang#87205 (rustc_middle: remove redundant clone) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This PR fixes #86820. The problem is that this currently passes the type checker:
i.e. the type checker fails to check whether const parameters in
implmethods have the same type as the corresponding declaration in the trait. With my changes, I get, for the above code:This fixes #86820, where an ICE happens later on because the trait method is declared with a const parameter of type
u8, but theimpluses one of typeusize: