|
1 | 1 | use crate::{errors, structured_errors::StructuredDiagnostic};
|
2 |
| -use rustc_errors::{codes::*, DiagnosticBuilder, ErrCode}; |
| 2 | +use rustc_errors::{codes::*, Applicability, DiagnosticBuilder, ErrCode}; |
3 | 3 | use rustc_middle::ty::{Ty, TypeVisitableExt};
|
4 | 4 | use rustc_session::Session;
|
5 | 5 | use rustc_span::Span;
|
@@ -41,6 +41,28 @@ impl<'tcx> StructuredDiagnostic<'tcx> for MissingCastForVariadicArg<'tcx, '_> {
|
41 | 41 | err.downgrade_to_delayed_bug();
|
42 | 42 | }
|
43 | 43 |
|
| 44 | + if let Ok(snippet) = self.sess.source_map().span_to_snippet(self.span) { |
| 45 | + if self.ty.is_fn() { |
| 46 | + err.span_suggestion( |
| 47 | + self.span, |
| 48 | + "cast the value into a function pointer", |
| 49 | + format!("{} as {}", snippet, self.cast_ty), |
| 50 | + Applicability::MachineApplicable, |
| 51 | + ) |
| 52 | + .help("a function item is zero-sized and needs to be casted into a function pointer to be used in FFI") |
| 53 | + .note("for more information on function items, visit https://doc.rust-lang.org/reference/types/function-item.html"); |
| 54 | + } else { |
| 55 | + err.span_suggestion( |
| 56 | + self.span, |
| 57 | + &format!("cast the value to `{}`", self.cast_ty), |
| 58 | + format!("{} as {}", snippet, self.cast_ty), |
| 59 | + Applicability::MachineApplicable, |
| 60 | + ); |
| 61 | + } |
| 62 | + } else { |
| 63 | + err.help(&format!("cast the value into `{}`", self.cast_ty)); |
| 64 | + } |
| 65 | + |
44 | 66 | err
|
45 | 67 | }
|
46 | 68 |
|
|
0 commit comments