diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:50 +0000 |
commit | 2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35 (patch) | |
tree | d325add32978dbdc1db975a438b3a77d571b1ab8 /tests/ui/fn/fn-pointer-mismatch.stderr | |
parent | Releasing progress-linux version 1.68.2+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35.tar.xz rustc-2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35.zip |
Merging upstream version 1.69.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/fn/fn-pointer-mismatch.stderr')
-rw-r--r-- | tests/ui/fn/fn-pointer-mismatch.stderr | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/tests/ui/fn/fn-pointer-mismatch.stderr b/tests/ui/fn/fn-pointer-mismatch.stderr new file mode 100644 index 000000000..a674babcb --- /dev/null +++ b/tests/ui/fn/fn-pointer-mismatch.stderr @@ -0,0 +1,91 @@ +error[E0308]: `if` and `else` have incompatible types + --> $DIR/fn-pointer-mismatch.rs:11:43 + | +LL | let g = if n % 2 == 0 { &foo } else { &bar }; + | ---- ^^^^ expected `&fn(u32) -> u32 {foo}`, found `&fn(u32) -> u32 {bar}` + | | + | expected because of this + | + = note: expected reference `&fn(u32) -> u32 {foo}` + found reference `&fn(u32) -> u32 {bar}` + = note: different fn items have unique types, even if their signatures are the same + = help: consider casting both fn items to fn pointers using `as fn(u32) -> u32` + +error[E0308]: mismatched types + --> $DIR/fn-pointer-mismatch.rs:23:9 + | +LL | let mut a = foo; + | --- expected due to this value +LL | a = bar; + | ^^^ expected fn item, found a different fn item + | + = note: expected fn item `fn(_) -> _ {foo}` + found fn item `fn(_) -> _ {bar}` + = note: different fn items have unique types, even if their signatures are the same + = help: consider casting both fn items to fn pointers using `as fn(u32) -> u32` + +error[E0308]: mismatched types + --> $DIR/fn-pointer-mismatch.rs:31:18 + | +LL | b = Box::new(bar); + | -------- ^^^ expected fn item, found a different fn item + | | + | arguments to this function are incorrect + | + = note: expected fn item `fn(_) -> _ {foo}` + found fn item `fn(_) -> _ {bar}` + = note: different fn items have unique types, even if their signatures are the same +note: associated function defined here + --> $SRC_DIR/alloc/src/boxed.rs:LL:COL + = help: consider casting both fn items to fn pointers using `as fn(u32) -> u32` + +error[E0308]: mismatched types + --> $DIR/fn-pointer-mismatch.rs:36:29 + | +LL | let c: fn(u32) -> u32 = &foo; + | -------------- ^^^^ expected fn pointer, found `&fn(u32) -> u32 {foo}` + | | + | expected due to this + | + = note: expected fn pointer `fn(u32) -> u32` + found reference `&fn(u32) -> u32 {foo}` +help: consider removing the reference + | +LL | let c: fn(u32) -> u32 = foo; + | ~~~ + +error[E0308]: mismatched types + --> $DIR/fn-pointer-mismatch.rs:42:30 + | +LL | let d: &fn(u32) -> u32 = foo; + | --------------- ^^^ expected `&fn(u32) -> u32`, found fn item + | | + | expected due to this + | + = note: expected reference `&fn(u32) -> u32` + found fn item `fn(u32) -> u32 {foo}` +help: consider using a reference + | +LL | let d: &fn(u32) -> u32 = &foo; + | ~~~~ + +error[E0308]: mismatched types + --> $DIR/fn-pointer-mismatch.rs:48:30 + | +LL | let e: &fn(u32) -> u32 = &foo; + | --------------- ^^^^ expected `&fn(u32) -> u32`, found `&fn(u32) -> u32 {foo}` + | | + | expected due to this + | + = note: expected reference `&fn(u32) -> u32` + found reference `&fn(u32) -> u32 {foo}` + = note: fn items are distinct from fn pointers + = note: when the arguments and return types match, functions can be coerced to function pointers +help: consider casting to a fn pointer + | +LL | let e: &fn(u32) -> u32 = &(foo as fn(u32) -> u32); + | ~~~~~~~~~~~~~~~~~~~~~~~~ + +error: aborting due to 6 previous errors + +For more information about this error, try `rustc --explain E0308`. |