Skip to content

Commit

Permalink
Implement suggestion
Browse files Browse the repository at this point in the history
Co-authored-by: Esteban Kuber <estebank@users.noreply.github.com>
  • Loading branch information
HTGAzureX1212 and estebank committed Feb 8, 2024
1 parent 852a971 commit e4a6aa3
Showing 1 changed file with 11 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,19 @@ impl<'tcx> StructuredDiagnostic<'tcx> for MissingCastForVariadicArg<'tcx, '_> {
err.downgrade_to_delayed_bug();
}

if let Ok(snippet) = self.sess.source_map().span_to_snippet(self.span) {
if self.ty.is_fn() {
err.span_suggestion(
self.span,
"cast the value into a function pointer",
format!("{} as {}", snippet, self.cast_ty),
Applicability::MachineApplicable,
)
.help("a function item is zero-sized and needs to be casted into a function pointer to be used in FFI")
let msg = if self.ty.is_fn() {
err.help("a function item is zero-sized and needs to be casted into a function pointer to be used in FFI")
.note("for more information on function items, visit https://doc.rust-lang.org/reference/types/function-item.html");
"cast the value into a function pointer".to_string()
} else {
err.span_suggestion(
self.span,
format!("cast the value to `{}`", self.cast_ty),
format!("{} as {}", snippet, self.cast_ty),
Applicability::MachineApplicable,
);
}
} else {
err.help(format!("cast the value into `{}`", self.cast_ty));
}
format!("cast the value to `{}`", self.cast_ty)
};
err.span_suggestion_verbose(
self.span.shrink_to_hi(),
msg,
format!(" as {}", snippet, self.cast_ty),
Applicability::MachineApplicable,
);

err
}
Expand Down

0 comments on commit e4a6aa3

Please sign in to comment.