]> git.lizzy.rs Git - rust.git/commit - src/tools/miri
Rollup merge of #86843 - FabianWolff:issue-86820, r=lcnr
authorYuki Okushi <jtitor@2k36.org>
Sun, 18 Jul 2021 05:21:54 +0000 (14:21 +0900)
committerGitHub <noreply@github.com>
Sun, 18 Jul 2021 05:21:54 +0000 (14:21 +0900)
commit783efd29ae71fccc7dcc220fbca37765423f6e58
tree2aad8fac8f1dd8b69e4eea0ca434b4c99d37f03b
parent469935f7a46e1e3f33b2c70919c70570acaeeed7
parent9b874c400388a2158b6575e139752b3d0a27645b
Rollup merge of #86843 - FabianWolff:issue-86820, r=lcnr

Check that const parameters of trait methods have compatible types

This PR fixes #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 #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`