1
1
use rustc_errors:: {
2
- DecorateLint , DiagnosticBuilder , DiagnosticMessage , EmissionGuarantee , Handler , IntoDiagnostic ,
2
+ Applicability , DecorateLint , DiagnosticBuilder , DiagnosticMessage , EmissionGuarantee , Handler ,
3
+ IntoDiagnostic ,
3
4
} ;
4
5
use rustc_macros:: { Diagnostic , LintDiagnostic , Subdiagnostic } ;
5
6
use rustc_middle:: mir:: { AssertKind , UnsafetyViolationDetails } ;
@@ -130,6 +131,7 @@ impl RequiresUnsafeDetail {
130
131
131
132
pub ( crate ) struct UnsafeOpInUnsafeFn {
132
133
pub details : RequiresUnsafeDetail ,
134
+ pub suggest_unsafe_block : Option < ( Span , Span ) > ,
133
135
}
134
136
135
137
impl < ' a > DecorateLint < ' a , ( ) > for UnsafeOpInUnsafeFn {
@@ -138,13 +140,20 @@ impl<'a> DecorateLint<'a, ()> for UnsafeOpInUnsafeFn {
138
140
self ,
139
141
diag : & ' b mut DiagnosticBuilder < ' a , ( ) > ,
140
142
) -> & ' 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 ( ) ) ;
145
145
diag. set_arg ( "details" , desc) ;
146
146
diag. span_label ( self . details . span , self . details . label ( ) ) ;
147
147
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
+
148
157
diag
149
158
}
150
159
0 commit comments