Fix calling function pointer const parameters. Also fixes inference of
function pointer const parameters.
This commit is contained in:
parent
ec557aa818
commit
2afd277bc3
6 changed files with 145 additions and 30 deletions
20
src/test/ui/const-generics/fn-const-param-call.rs
Normal file
20
src/test/ui/const-generics/fn-const-param-call.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
// run-pass
|
||||
|
||||
#![feature(const_generics)]
|
||||
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
|
||||
|
||||
fn function() -> u32 {
|
||||
17
|
||||
}
|
||||
|
||||
struct Wrapper<const F: fn() -> u32>;
|
||||
|
||||
impl<const F: fn() -> u32> Wrapper<{F}> {
|
||||
fn call() -> u32 {
|
||||
F()
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
assert_eq!(Wrapper::<{function}>::call(), 17);
|
||||
}
|
||||
8
src/test/ui/const-generics/fn-const-param-call.stderr
Normal file
8
src/test/ui/const-generics/fn-const-param-call.stderr
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
|
||||
--> $DIR/fn-const-param-call.rs:3:12
|
||||
|
|
||||
LL | #![feature(const_generics)]
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
|
||||
26
src/test/ui/const-generics/fn-const-param-infer.rs
Normal file
26
src/test/ui/const-generics/fn-const-param-infer.rs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#![feature(const_generics)]
|
||||
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
|
||||
|
||||
struct Checked<const F: fn(usize) -> bool>;
|
||||
|
||||
fn not_one(val: usize) -> bool { val != 1 }
|
||||
fn not_two(val: usize) -> bool { val != 2 }
|
||||
|
||||
fn generic_arg<T>(val: T) -> bool { true }
|
||||
|
||||
fn generic<T>(val: usize) -> bool { val != 1 }
|
||||
|
||||
fn main() {
|
||||
let _: Option<Checked<{not_one}>> = None;
|
||||
let _: Checked<{not_one}> = Checked::<{not_one}>;
|
||||
let _: Checked<{not_one}> = Checked::<{not_two}>; //~ mismatched types
|
||||
|
||||
let _ = Checked::<{generic_arg}>;
|
||||
let _ = Checked::<{generic_arg::<usize>}>;
|
||||
let _ = Checked::<{generic_arg::<u32>}>; //~ mismatched types
|
||||
|
||||
let _ = Checked::<{generic}>; //~ type annotations needed
|
||||
let _ = Checked::<{generic::<u16>}>;
|
||||
let _: Checked<{generic::<u16>}> = Checked::<{generic::<u16>}>;
|
||||
let _: Checked<{generic::<u32>}> = Checked::<{generic::<u16>}>; //~ mismatched types
|
||||
}
|
||||
45
src/test/ui/const-generics/fn-const-param-infer.stderr
Normal file
45
src/test/ui/const-generics/fn-const-param-infer.stderr
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
|
||||
--> $DIR/fn-const-param-infer.rs:1:12
|
||||
|
|
||||
LL | #![feature(const_generics)]
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/fn-const-param-infer.rs:16:33
|
||||
|
|
||||
LL | let _: Checked<{not_one}> = Checked::<{not_two}>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^ expected `Scalar(AllocId(1).0x0) : fn(usize) -> bool`, found `Scalar(AllocId(10).0x0) : fn(usize) -> bool`
|
||||
|
|
||||
= note: expected type `Checked<>`
|
||||
found type `Checked<>`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/fn-const-param-infer.rs:20:24
|
||||
|
|
||||
LL | let _ = Checked::<{generic_arg::<u32>}>;
|
||||
| ^^^^^^^^^^^^^^^^^^ expected usize, found u32
|
||||
|
|
||||
= note: expected type `fn(usize) -> bool`
|
||||
found type `fn(u32) -> bool {generic_arg::<u32>}`
|
||||
|
||||
error[E0282]: type annotations needed
|
||||
--> $DIR/fn-const-param-infer.rs:22:24
|
||||
|
|
||||
LL | let _ = Checked::<{generic}>;
|
||||
| ^^^^^^^ cannot infer type for `T`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/fn-const-param-infer.rs:25:40
|
||||
|
|
||||
LL | let _: Checked<{generic::<u32>}> = Checked::<{generic::<u16>}>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Scalar(AllocId(7).0x0) : fn(usize) -> bool`, found `Scalar(AllocId(20).0x0) : fn(usize) -> bool`
|
||||
|
|
||||
= note: expected type `Checked<>`
|
||||
found type `Checked<>`
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0282, E0308.
|
||||
For more information about an error, try `rustc --explain E0282`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue