Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -418,15 +418,17 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
};

let sugg = match (expected.is_ref(), found.is_ref()) {
(true, false) => FunctionPointerSuggestion::UseRef { span, fn_name },
(true, false) => {
FunctionPointerSuggestion::UseRef { span: span.shrink_to_lo() }
}
(false, true) => FunctionPointerSuggestion::RemoveRef { span, fn_name },
(true, true) => {
diag.subdiagnostic(FnItemsAreDistinct);
FunctionPointerSuggestion::CastRef { span, fn_name, sig }
}
(false, false) => {
diag.subdiagnostic(FnItemsAreDistinct);
FunctionPointerSuggestion::Cast { span, fn_name, sig }
FunctionPointerSuggestion::Cast { span: span.shrink_to_hi(), sig }
}
};
diag.subdiagnostic(sugg);
Expand Down Expand Up @@ -466,8 +468,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
}
} else {
FunctionPointerSuggestion::CastBoth {
span,
fn_name,
span: span.shrink_to_hi(),
found_sig: *found_sig,
expected_sig: *expected_sig,
}
Expand Down
12 changes: 3 additions & 9 deletions compiler/rustc_trait_selection/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1391,15 +1391,13 @@ pub struct OpaqueCapturesLifetime<'tcx> {
pub enum FunctionPointerSuggestion<'a> {
#[suggestion(
trait_selection_fps_use_ref,
code = "&{fn_name}",
code = "&",
style = "verbose",
applicability = "maybe-incorrect"
)]
UseRef {
#[primary_span]
span: Span,
#[skip_arg]
fn_name: String,
},
#[suggestion(
trait_selection_fps_remove_ref,
Expand Down Expand Up @@ -1429,30 +1427,26 @@ pub enum FunctionPointerSuggestion<'a> {
},
#[suggestion(
trait_selection_fps_cast,
code = "{fn_name} as {sig}",
code = " as {sig}",
style = "verbose",
applicability = "maybe-incorrect"
)]
Cast {
#[primary_span]
span: Span,
#[skip_arg]
fn_name: String,
#[skip_arg]
sig: Binder<'a, FnSig<'a>>,
},
#[suggestion(
trait_selection_fps_cast_both,
code = "{fn_name} as {found_sig}",
code = " as {found_sig}",
style = "hidden",
applicability = "maybe-incorrect"
)]
CastBoth {
#[primary_span]
span: Span,
#[skip_arg]
fn_name: String,
#[skip_arg]
found_sig: Binder<'a, FnSig<'a>>,
expected_sig: Binder<'a, FnSig<'a>>,
},
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/fn/fn-pointer-mismatch.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ LL | let d: &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
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/force-inlining/cast.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ LL | let _: fn(isize) -> usize = callee;
help: consider casting to a fn pointer
|
LL | let _: fn(isize) -> usize = callee as fn(isize) -> usize;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| +++++++++++++++++++++

error[E0605]: non-primitive cast: `fn(isize) -> usize {callee}` as `fn(isize) -> usize`
--> $DIR/cast.rs:15:13
Expand All @@ -32,7 +32,7 @@ LL | callee,
help: consider casting to a fn pointer
|
LL | callee as fn(isize) -> usize,
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| +++++++++++++++++++++

error: aborting due to 3 previous errors

Expand Down
Loading