Skip to content

Commit 8f23779

Browse files
committed
Inference
1 parent 83a1834 commit 8f23779

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#![feature(const_generics_defaults)]
2+
3+
// test that defaulted const params are not used to help type inference
4+
5+
struct Foo<const N: u32 = 2>;
6+
7+
impl<const N: u32> Foo<N> {
8+
fn foo() -> Self { loop {} }
9+
}
10+
11+
fn main() {
12+
let foo = Foo::<1>::foo();
13+
let foo = Foo::foo();
14+
//~^ error: type annotations needed for `Foo<{_: u32}>`
15+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0282]: type annotations needed for `Foo<{_: u32}>`
2+
--> $DIR/doesnt_infer.rs:13:15
3+
|
4+
LL | let foo = Foo::foo();
5+
| --- ^^^^^^^^ cannot infer the value of const parameter `N`
6+
| |
7+
| consider giving `foo` the explicit type `Foo<{_: u32}>`, where the type parameter `N` is specified
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0282`.

0 commit comments

Comments
 (0)