Make structured suggestion for fn casting verbose
This commit is contained in:
parent
6c2c8edac3
commit
d86835769c
5 changed files with 36 additions and 25 deletions
|
@ -404,7 +404,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
(msg, sug)
|
(msg, sug)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
diag.span_suggestion(span, msg, sug, Applicability::MaybeIncorrect);
|
diag.span_suggestion_verbose(span, msg, sug, Applicability::MaybeIncorrect);
|
||||||
}
|
}
|
||||||
(ty::FnDef(did1, substs1), ty::FnDef(did2, substs2)) => {
|
(ty::FnDef(did1, substs1), ty::FnDef(did2, substs2)) => {
|
||||||
let expected_sig =
|
let expected_sig =
|
||||||
|
|
|
@ -43,42 +43,48 @@ error[E0308]: mismatched types
|
||||||
--> $DIR/fn-pointer-mismatch.rs:36:29
|
--> $DIR/fn-pointer-mismatch.rs:36:29
|
||||||
|
|
|
|
||||||
LL | let c: fn(u32) -> u32 = &foo;
|
LL | let c: fn(u32) -> u32 = &foo;
|
||||||
| -------------- ^^^^
|
| -------------- ^^^^ expected fn pointer, found `&fn(u32) -> u32 {foo}`
|
||||||
| | |
|
| |
|
||||||
| | expected fn pointer, found `&fn(u32) -> u32 {foo}`
|
|
||||||
| | help: consider removing the reference: `foo`
|
|
||||||
| expected due to this
|
| expected due to this
|
||||||
|
|
|
|
||||||
= note: expected fn pointer `fn(u32) -> u32`
|
= note: expected fn pointer `fn(u32) -> u32`
|
||||||
found reference `&fn(u32) -> u32 {foo}`
|
found reference `&fn(u32) -> u32 {foo}`
|
||||||
|
help: consider removing the reference
|
||||||
|
|
|
||||||
|
LL | let c: fn(u32) -> u32 = foo;
|
||||||
|
| ~~~
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
error[E0308]: mismatched types
|
||||||
--> $DIR/fn-pointer-mismatch.rs:42:30
|
--> $DIR/fn-pointer-mismatch.rs:42:30
|
||||||
|
|
|
|
||||||
LL | let d: &fn(u32) -> u32 = foo;
|
LL | let d: &fn(u32) -> u32 = foo;
|
||||||
| --------------- ^^^
|
| --------------- ^^^ expected `&fn(u32) -> u32`, found fn item
|
||||||
| | |
|
| |
|
||||||
| | expected `&fn(u32) -> u32`, found fn item
|
|
||||||
| | help: consider using a reference: `&foo`
|
|
||||||
| expected due to this
|
| expected due to this
|
||||||
|
|
|
|
||||||
= note: expected reference `&fn(u32) -> u32`
|
= note: expected reference `&fn(u32) -> u32`
|
||||||
found fn item `fn(u32) -> u32 {foo}`
|
found fn item `fn(u32) -> u32 {foo}`
|
||||||
|
help: consider using a reference
|
||||||
|
|
|
||||||
|
LL | let d: &fn(u32) -> u32 = &foo;
|
||||||
|
| ~~~~
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
error[E0308]: mismatched types
|
||||||
--> $DIR/fn-pointer-mismatch.rs:48:30
|
--> $DIR/fn-pointer-mismatch.rs:48:30
|
||||||
|
|
|
|
||||||
LL | let e: &fn(u32) -> u32 = &foo;
|
LL | let e: &fn(u32) -> u32 = &foo;
|
||||||
| --------------- ^^^^
|
| --------------- ^^^^ expected `&fn(u32) -> u32`, found `&fn(u32) -> u32 {foo}`
|
||||||
| | |
|
| |
|
||||||
| | expected `&fn(u32) -> u32`, found `&fn(u32) -> u32 {foo}`
|
|
||||||
| | help: consider casting to a fn pointer: `&(foo as fn(u32) -> u32)`
|
|
||||||
| expected due to this
|
| expected due to this
|
||||||
|
|
|
|
||||||
= note: expected reference `&fn(u32) -> u32`
|
= note: expected reference `&fn(u32) -> u32`
|
||||||
found reference `&fn(u32) -> u32 {foo}`
|
found reference `&fn(u32) -> u32 {foo}`
|
||||||
= note: fn items are distinct from fn pointers
|
= note: fn items are distinct from fn pointers
|
||||||
= note: when the arguments and return types match, functions can be coerced to function 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
|
error: aborting due to 6 previous errors
|
||||||
|
|
||||||
|
|
|
@ -5,10 +5,8 @@ LL | #[target_feature(enable = "sse2")]
|
||||||
| ---------------------------------- `#[target_feature]` added here
|
| ---------------------------------- `#[target_feature]` added here
|
||||||
...
|
...
|
||||||
LL | let foo: fn() = foo;
|
LL | let foo: fn() = foo;
|
||||||
| ---- ^^^
|
| ---- ^^^ cannot coerce functions with `#[target_feature]` to safe function pointers
|
||||||
| | |
|
| |
|
||||||
| | cannot coerce functions with `#[target_feature]` to safe function pointers
|
|
||||||
| | help: consider casting to a fn pointer: `foo as fn()`
|
|
||||||
| expected due to this
|
| expected due to this
|
||||||
|
|
|
|
||||||
= note: expected fn pointer `fn()`
|
= note: expected fn pointer `fn()`
|
||||||
|
@ -16,6 +14,10 @@ LL | let foo: fn() = foo;
|
||||||
= note: fn items are distinct from fn pointers
|
= note: fn items are distinct from fn pointers
|
||||||
= note: functions with `#[target_feature]` can only be coerced to `unsafe` function pointers
|
= note: functions with `#[target_feature]` can only be coerced to `unsafe` function pointers
|
||||||
= note: when the arguments and return types match, functions can be coerced to function 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 foo: fn() = foo as fn();
|
||||||
|
| ~~~~~~~~~~~
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -5,10 +5,8 @@ LL | #[target_feature(enable = "sse2")]
|
||||||
| ---------------------------------- `#[target_feature]` added here
|
| ---------------------------------- `#[target_feature]` added here
|
||||||
...
|
...
|
||||||
LL | let foo: fn() = foo;
|
LL | let foo: fn() = foo;
|
||||||
| ---- ^^^
|
| ---- ^^^ cannot coerce functions with `#[target_feature]` to safe function pointers
|
||||||
| | |
|
| |
|
||||||
| | cannot coerce functions with `#[target_feature]` to safe function pointers
|
|
||||||
| | help: consider casting to a fn pointer: `foo as fn()`
|
|
||||||
| expected due to this
|
| expected due to this
|
||||||
|
|
|
|
||||||
= note: expected fn pointer `fn()`
|
= note: expected fn pointer `fn()`
|
||||||
|
@ -16,6 +14,10 @@ LL | let foo: fn() = foo;
|
||||||
= note: fn items are distinct from fn pointers
|
= note: fn items are distinct from fn pointers
|
||||||
= note: functions with `#[target_feature]` can only be coerced to `unsafe` function pointers
|
= note: functions with `#[target_feature]` can only be coerced to `unsafe` function pointers
|
||||||
= note: when the arguments and return types match, functions can be coerced to function 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 foo: fn() = foo as fn();
|
||||||
|
| ~~~~~~~~~~~
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
|
@ -2,15 +2,16 @@ error[E0308]: mismatched types
|
||||||
--> $DIR/static-reference-to-fn-1.rs:17:15
|
--> $DIR/static-reference-to-fn-1.rs:17:15
|
||||||
|
|
|
|
||||||
LL | func: &foo,
|
LL | func: &foo,
|
||||||
| ^^^^
|
| ^^^^ expected `&fn() -> Option<isize>`, found `&fn() -> Option<isize> {foo}`
|
||||||
| |
|
|
||||||
| expected `&fn() -> Option<isize>`, found `&fn() -> Option<isize> {foo}`
|
|
||||||
| help: consider casting to a fn pointer: `&(foo as fn() -> Option<isize>)`
|
|
||||||
|
|
|
|
||||||
= note: expected reference `&fn() -> Option<isize>`
|
= note: expected reference `&fn() -> Option<isize>`
|
||||||
found reference `&fn() -> Option<isize> {foo}`
|
found reference `&fn() -> Option<isize> {foo}`
|
||||||
= note: fn items are distinct from fn pointers
|
= note: fn items are distinct from fn pointers
|
||||||
= note: when the arguments and return types match, functions can be coerced to function pointers
|
= note: when the arguments and return types match, functions can be coerced to function pointers
|
||||||
|
help: consider casting to a fn pointer
|
||||||
|
|
|
||||||
|
LL | func: &(foo as fn() -> Option<isize>),
|
||||||
|
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue