Add MVP suggestion for unsafe_op_in_unsafe_fn
Nemo157 rebase notes: Migrated the changes to the lint into fluent
This commit is contained in:
parent
a525c7ddba
commit
975152ce30
7 changed files with 105 additions and 11 deletions
|
@ -1,5 +1,6 @@
|
|||
use rustc_errors::{
|
||||
DecorateLint, DiagnosticBuilder, DiagnosticMessage, EmissionGuarantee, Handler, IntoDiagnostic,
|
||||
Applicability, DecorateLint, DiagnosticBuilder, DiagnosticMessage, EmissionGuarantee, Handler,
|
||||
IntoDiagnostic,
|
||||
};
|
||||
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
|
||||
use rustc_middle::mir::{AssertKind, UnsafetyViolationDetails};
|
||||
|
@ -130,6 +131,7 @@ impl RequiresUnsafeDetail {
|
|||
|
||||
pub(crate) struct UnsafeOpInUnsafeFn {
|
||||
pub details: RequiresUnsafeDetail,
|
||||
pub suggest_unsafe_block: Option<(Span, Span)>,
|
||||
}
|
||||
|
||||
impl<'a> DecorateLint<'a, ()> for UnsafeOpInUnsafeFn {
|
||||
|
@ -138,13 +140,20 @@ impl<'a> DecorateLint<'a, ()> for UnsafeOpInUnsafeFn {
|
|||
self,
|
||||
diag: &'b mut DiagnosticBuilder<'a, ()>,
|
||||
) -> &'b mut DiagnosticBuilder<'a, ()> {
|
||||
let desc = diag
|
||||
.handler()
|
||||
.expect("lint should not yet be emitted")
|
||||
.eagerly_translate_to_string(self.details.label(), [].into_iter());
|
||||
let handler = diag.handler().expect("lint should not yet be emitted");
|
||||
let desc = handler.eagerly_translate_to_string(self.details.label(), [].into_iter());
|
||||
diag.set_arg("details", desc);
|
||||
diag.span_label(self.details.span, self.details.label());
|
||||
diag.note(self.details.note());
|
||||
|
||||
if let Some((start, end)) = self.suggest_unsafe_block {
|
||||
diag.multipart_suggestion_verbose(
|
||||
crate::fluent_generated::mir_transform_suggestion,
|
||||
vec![(start, " unsafe {".into()), (end, "}".into())],
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
}
|
||||
|
||||
diag
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue