1
+ use std:: borrow:: Cow ;
2
+
1
3
use rustc_errors:: {
2
- Applicability , DecorateLint , DiagnosticBuilder , DiagnosticMessage , EmissionGuarantee , Handler ,
3
- IntoDiagnostic ,
4
+ Applicability , DecorateLint , DiagnosticArgValue , DiagnosticBuilder , DiagnosticMessage ,
5
+ EmissionGuarantee , Handler , IntoDiagnostic ,
4
6
} ;
5
7
use rustc_macros:: { Diagnostic , LintDiagnostic , Subdiagnostic } ;
6
8
use rustc_middle:: mir:: { AssertKind , UnsafetyViolationDetails } ;
@@ -9,6 +11,8 @@ use rustc_session::lint::{self, Lint};
9
11
use rustc_span:: def_id:: DefId ;
10
12
use rustc_span:: Span ;
11
13
14
+ use crate :: fluent_generated as fluent;
15
+
12
16
#[ derive( LintDiagnostic ) ]
13
17
pub ( crate ) enum ConstMutate {
14
18
#[ diag( mir_transform_const_modify) ]
@@ -61,72 +65,105 @@ pub(crate) struct RequiresUnsafe {
61
65
impl < ' sess , G : EmissionGuarantee > IntoDiagnostic < ' sess , G > for RequiresUnsafe {
62
66
#[ track_caller]
63
67
fn into_diagnostic ( self , handler : & ' sess Handler ) -> DiagnosticBuilder < ' sess , G > {
64
- let mut diag =
65
- handler. struct_diagnostic ( crate :: fluent_generated:: mir_transform_requires_unsafe) ;
68
+ let mut diag = handler. struct_diagnostic ( fluent:: mir_transform_requires_unsafe) ;
66
69
diag. code ( rustc_errors:: DiagnosticId :: Error ( "E0133" . to_string ( ) ) ) ;
67
70
diag. set_span ( self . span ) ;
68
71
diag. span_label ( self . span , self . details . label ( ) ) ;
69
- diag. note ( self . details . note ( ) ) ;
70
72
let desc = handler. eagerly_translate_to_string ( self . details . label ( ) , [ ] . into_iter ( ) ) ;
71
73
diag. set_arg ( "details" , desc) ;
72
74
diag. set_arg ( "op_in_unsafe_fn_allowed" , self . op_in_unsafe_fn_allowed ) ;
75
+ self . details . add_subdiagnostics ( & mut diag) ;
73
76
if let Some ( sp) = self . enclosing {
74
- diag. span_label ( sp, crate :: fluent_generated :: mir_transform_not_inherited) ;
77
+ diag. span_label ( sp, fluent :: mir_transform_not_inherited) ;
75
78
}
76
79
diag
77
80
}
78
81
}
79
82
80
- #[ derive( Copy , Clone ) ]
83
+ #[ derive( Clone ) ]
81
84
pub ( crate ) struct RequiresUnsafeDetail {
82
85
pub span : Span ,
83
86
pub violation : UnsafetyViolationDetails ,
84
87
}
85
88
86
89
impl RequiresUnsafeDetail {
87
- fn note ( self ) -> DiagnosticMessage {
90
+ fn add_subdiagnostics < G : EmissionGuarantee > ( & self , diag : & mut DiagnosticBuilder < ' _ , G > ) {
88
91
use UnsafetyViolationDetails :: * ;
89
92
match self . violation {
90
- CallToUnsafeFunction => crate :: fluent_generated:: mir_transform_call_to_unsafe_note,
91
- UseOfInlineAssembly => crate :: fluent_generated:: mir_transform_use_of_asm_note,
93
+ CallToUnsafeFunction => {
94
+ diag. note ( fluent:: mir_transform_call_to_unsafe_note) ;
95
+ }
96
+ UseOfInlineAssembly => {
97
+ diag. note ( fluent:: mir_transform_use_of_asm_note) ;
98
+ }
92
99
InitializingTypeWith => {
93
- crate :: fluent_generated:: mir_transform_initializing_valid_range_note
100
+ diag. note ( fluent:: mir_transform_initializing_valid_range_note) ;
101
+ }
102
+ CastOfPointerToInt => {
103
+ diag. note ( fluent:: mir_transform_const_ptr2int_note) ;
104
+ }
105
+ UseOfMutableStatic => {
106
+ diag. note ( fluent:: mir_transform_use_of_static_mut_note) ;
107
+ }
108
+ UseOfExternStatic => {
109
+ diag. note ( fluent:: mir_transform_use_of_extern_static_note) ;
110
+ }
111
+ DerefOfRawPointer => {
112
+ diag. note ( fluent:: mir_transform_deref_ptr_note) ;
113
+ }
114
+ AccessToUnionField => {
115
+ diag. note ( fluent:: mir_transform_union_access_note) ;
94
116
}
95
- CastOfPointerToInt => crate :: fluent_generated:: mir_transform_const_ptr2int_note,
96
- UseOfMutableStatic => crate :: fluent_generated:: mir_transform_use_of_static_mut_note,
97
- UseOfExternStatic => crate :: fluent_generated:: mir_transform_use_of_extern_static_note,
98
- DerefOfRawPointer => crate :: fluent_generated:: mir_transform_deref_ptr_note,
99
- AccessToUnionField => crate :: fluent_generated:: mir_transform_union_access_note,
100
117
MutationOfLayoutConstrainedField => {
101
- crate :: fluent_generated :: mir_transform_mutation_layout_constrained_note
118
+ diag . note ( fluent :: mir_transform_mutation_layout_constrained_note) ;
102
119
}
103
120
BorrowOfLayoutConstrainedField => {
104
- crate :: fluent_generated:: mir_transform_mutation_layout_constrained_borrow_note
121
+ diag. note ( fluent:: mir_transform_mutation_layout_constrained_borrow_note) ;
122
+ }
123
+ CallToFunctionWith { ref missing, ref build_enabled } => {
124
+ diag. help ( fluent:: mir_transform_target_feature_call_help) ;
125
+ diag. set_arg (
126
+ "missing_target_features" ,
127
+ DiagnosticArgValue :: StrListSepByAnd (
128
+ missing. iter ( ) . map ( |feature| Cow :: from ( feature. as_str ( ) ) ) . collect ( ) ,
129
+ ) ,
130
+ ) ;
131
+ diag. set_arg ( "missing_target_features_count" , missing. len ( ) ) ;
132
+ if !build_enabled. is_empty ( ) {
133
+ diag. note ( fluent:: mir_transform_target_feature_call_note) ;
134
+ diag. set_arg (
135
+ "build_target_features" ,
136
+ DiagnosticArgValue :: StrListSepByAnd (
137
+ build_enabled
138
+ . iter ( )
139
+ . map ( |feature| Cow :: from ( feature. as_str ( ) ) )
140
+ . collect ( ) ,
141
+ ) ,
142
+ ) ;
143
+ diag. set_arg ( "build_target_features_count" , build_enabled. len ( ) ) ;
144
+ }
105
145
}
106
- CallToFunctionWith => crate :: fluent_generated:: mir_transform_target_feature_call_note,
107
146
}
108
147
}
109
148
110
- fn label ( self ) -> DiagnosticMessage {
149
+ fn label ( & self ) -> DiagnosticMessage {
111
150
use UnsafetyViolationDetails :: * ;
112
151
match self . violation {
113
- CallToUnsafeFunction => crate :: fluent_generated:: mir_transform_call_to_unsafe_label,
114
- UseOfInlineAssembly => crate :: fluent_generated:: mir_transform_use_of_asm_label,
115
- InitializingTypeWith => {
116
- crate :: fluent_generated:: mir_transform_initializing_valid_range_label
117
- }
118
- CastOfPointerToInt => crate :: fluent_generated:: mir_transform_const_ptr2int_label,
119
- UseOfMutableStatic => crate :: fluent_generated:: mir_transform_use_of_static_mut_label,
120
- UseOfExternStatic => crate :: fluent_generated:: mir_transform_use_of_extern_static_label,
121
- DerefOfRawPointer => crate :: fluent_generated:: mir_transform_deref_ptr_label,
122
- AccessToUnionField => crate :: fluent_generated:: mir_transform_union_access_label,
152
+ CallToUnsafeFunction => fluent:: mir_transform_call_to_unsafe_label,
153
+ UseOfInlineAssembly => fluent:: mir_transform_use_of_asm_label,
154
+ InitializingTypeWith => fluent:: mir_transform_initializing_valid_range_label,
155
+ CastOfPointerToInt => fluent:: mir_transform_const_ptr2int_label,
156
+ UseOfMutableStatic => fluent:: mir_transform_use_of_static_mut_label,
157
+ UseOfExternStatic => fluent:: mir_transform_use_of_extern_static_label,
158
+ DerefOfRawPointer => fluent:: mir_transform_deref_ptr_label,
159
+ AccessToUnionField => fluent:: mir_transform_union_access_label,
123
160
MutationOfLayoutConstrainedField => {
124
- crate :: fluent_generated :: mir_transform_mutation_layout_constrained_label
161
+ fluent :: mir_transform_mutation_layout_constrained_label
125
162
}
126
163
BorrowOfLayoutConstrainedField => {
127
- crate :: fluent_generated :: mir_transform_mutation_layout_constrained_borrow_label
164
+ fluent :: mir_transform_mutation_layout_constrained_borrow_label
128
165
}
129
- CallToFunctionWith => crate :: fluent_generated :: mir_transform_target_feature_call_label,
166
+ CallToFunctionWith { .. } => fluent :: mir_transform_target_feature_call_label,
130
167
}
131
168
}
132
169
}
@@ -151,12 +188,12 @@ impl<'a> DecorateLint<'a, ()> for UnsafeOpInUnsafeFn {
151
188
let desc = handler. eagerly_translate_to_string ( self . details . label ( ) , [ ] . into_iter ( ) ) ;
152
189
diag. set_arg ( "details" , desc) ;
153
190
diag. span_label ( self . details . span , self . details . label ( ) ) ;
154
- diag . note ( self . details . note ( ) ) ;
191
+ self . details . add_subdiagnostics ( diag ) ;
155
192
156
193
if let Some ( ( start, end, fn_sig) ) = self . suggest_unsafe_block {
157
- diag. span_note ( fn_sig, crate :: fluent_generated :: mir_transform_note) ;
194
+ diag. span_note ( fn_sig, fluent :: mir_transform_note) ;
158
195
diag. tool_only_multipart_suggestion (
159
- crate :: fluent_generated :: mir_transform_suggestion,
196
+ fluent :: mir_transform_suggestion,
160
197
vec ! [ ( start, " unsafe {" . into( ) ) , ( end, "}" . into( ) ) ] ,
161
198
Applicability :: MaybeIncorrect ,
162
199
) ;
@@ -166,7 +203,7 @@ impl<'a> DecorateLint<'a, ()> for UnsafeOpInUnsafeFn {
166
203
}
167
204
168
205
fn msg ( & self ) -> DiagnosticMessage {
169
- crate :: fluent_generated :: mir_transform_unsafe_op_in_unsafe_fn
206
+ fluent :: mir_transform_unsafe_op_in_unsafe_fn
170
207
}
171
208
}
172
209
@@ -193,12 +230,8 @@ impl<'a, P: std::fmt::Debug> DecorateLint<'a, ()> for AssertLint<P> {
193
230
194
231
fn msg ( & self ) -> DiagnosticMessage {
195
232
match self {
196
- AssertLint :: ArithmeticOverflow ( ..) => {
197
- crate :: fluent_generated:: mir_transform_arithmetic_overflow
198
- }
199
- AssertLint :: UnconditionalPanic ( ..) => {
200
- crate :: fluent_generated:: mir_transform_operation_will_panic
201
- }
233
+ AssertLint :: ArithmeticOverflow ( ..) => fluent:: mir_transform_arithmetic_overflow,
234
+ AssertLint :: UnconditionalPanic ( ..) => fluent:: mir_transform_operation_will_panic,
202
235
}
203
236
}
204
237
}
@@ -255,19 +288,19 @@ impl<'a> DecorateLint<'a, ()> for MustNotSupend<'_, '_> {
255
288
self ,
256
289
diag : & ' b mut rustc_errors:: DiagnosticBuilder < ' a , ( ) > ,
257
290
) -> & ' b mut rustc_errors:: DiagnosticBuilder < ' a , ( ) > {
258
- diag. span_label ( self . yield_sp , crate :: fluent_generated :: _subdiag:: label) ;
291
+ diag. span_label ( self . yield_sp , fluent :: _subdiag:: label) ;
259
292
if let Some ( reason) = self . reason {
260
293
diag. subdiagnostic ( reason) ;
261
294
}
262
- diag. span_help ( self . src_sp , crate :: fluent_generated :: _subdiag:: help) ;
295
+ diag. span_help ( self . src_sp , fluent :: _subdiag:: help) ;
263
296
diag. set_arg ( "pre" , self . pre ) ;
264
297
diag. set_arg ( "def_path" , self . tcx . def_path_str ( self . def_id ) ) ;
265
298
diag. set_arg ( "post" , self . post ) ;
266
299
diag
267
300
}
268
301
269
302
fn msg ( & self ) -> rustc_errors:: DiagnosticMessage {
270
- crate :: fluent_generated :: mir_transform_must_not_suspend
303
+ fluent :: mir_transform_must_not_suspend
271
304
}
272
305
}
273
306
0 commit comments