11use rustc_errors:: {
2- DecorateLint , DiagnosticBuilder , DiagnosticMessage , EmissionGuarantee , Handler , IntoDiagnostic ,
2+ Applicability , DecorateLint , DiagnosticBuilder , DiagnosticMessage , EmissionGuarantee , Handler ,
3+ IntoDiagnostic ,
34} ;
45use rustc_macros:: { Diagnostic , LintDiagnostic , Subdiagnostic } ;
56use rustc_middle:: mir:: { AssertKind , UnsafetyViolationDetails } ;
@@ -130,6 +131,7 @@ impl RequiresUnsafeDetail {
130131
131132pub ( crate ) struct UnsafeOpInUnsafeFn {
132133 pub details : RequiresUnsafeDetail ,
134+ pub suggest_unsafe_block : Option < ( Span , Span ) > ,
133135}
134136
135137impl < ' a > DecorateLint < ' a , ( ) > for UnsafeOpInUnsafeFn {
@@ -138,13 +140,20 @@ impl<'a> DecorateLint<'a, ()> for UnsafeOpInUnsafeFn {
138140 self ,
139141 diag : & ' b mut DiagnosticBuilder < ' a , ( ) > ,
140142 ) -> & ' b mut DiagnosticBuilder < ' a , ( ) > {
141- let desc = diag
142- . handler ( )
143- . expect ( "lint should not yet be emitted" )
144- . eagerly_translate_to_string ( self . details . label ( ) , [ ] . into_iter ( ) ) ;
143+ let handler = diag. handler ( ) . expect ( "lint should not yet be emitted" ) ;
144+ let desc = handler. eagerly_translate_to_string ( self . details . label ( ) , [ ] . into_iter ( ) ) ;
145145 diag. set_arg ( "details" , desc) ;
146146 diag. span_label ( self . details . span , self . details . label ( ) ) ;
147147 diag. note ( self . details . note ( ) ) ;
148+
149+ if let Some ( ( start, end) ) = self . suggest_unsafe_block {
150+ diag. multipart_suggestion_verbose (
151+ crate :: fluent_generated:: mir_transform_suggestion,
152+ vec ! [ ( start, " unsafe {" . into( ) ) , ( end, "}" . into( ) ) ] ,
153+ Applicability :: MaybeIncorrect ,
154+ ) ;
155+ }
156+
148157 diag
149158 }
150159
0 commit comments