8
8
//! Thank you!
9
9
//! ~The `INTERNAL_METADATA_COLLECTOR` lint
10
10
11
- use rustc_errors:: { Applicability , Diag , MultiSpan } ;
11
+ use rustc_errors:: { Applicability , Diag , DiagMessage , MultiSpan , SubdiagMessage } ;
12
12
use rustc_hir:: HirId ;
13
13
use rustc_lint:: { LateContext , Lint , LintContext } ;
14
14
use rustc_span:: Span ;
@@ -59,9 +59,9 @@ fn docs_link(diag: &mut Diag<'_, ()>, lint: &'static Lint) {
59
59
/// 17 | std::mem::forget(seven);
60
60
/// | ^^^^^^^^^^^^^^^^^^^^^^^
61
61
/// ```
62
- pub fn span_lint < T : LintContext > ( cx : & T , lint : & ' static Lint , sp : impl Into < MultiSpan > , msg : & str ) {
62
+ pub fn span_lint < T : LintContext > ( cx : & T , lint : & ' static Lint , sp : impl Into < MultiSpan > , msg : impl Into < DiagMessage > ) {
63
63
#[ expect( clippy:: disallowed_methods) ]
64
- cx. span_lint ( lint, sp, msg. to_string ( ) , |diag| {
64
+ cx. span_lint ( lint, sp, msg. into ( ) , |diag| {
65
65
docs_link ( diag, lint) ;
66
66
} ) ;
67
67
}
@@ -104,17 +104,16 @@ pub fn span_lint_and_help<T: LintContext>(
104
104
cx : & T ,
105
105
lint : & ' static Lint ,
106
106
span : impl Into < MultiSpan > ,
107
- msg : & str ,
107
+ msg : impl Into < DiagMessage > ,
108
108
help_span : Option < Span > ,
109
- help : & str ,
109
+ help : impl Into < SubdiagMessage > ,
110
110
) {
111
111
#[ expect( clippy:: disallowed_methods) ]
112
- cx. span_lint ( lint, span, msg. to_string ( ) , |diag| {
113
- let help = help. to_string ( ) ;
112
+ cx. span_lint ( lint, span, msg. into ( ) , |diag| {
114
113
if let Some ( help_span) = help_span {
115
- diag. span_help ( help_span, help) ;
114
+ diag. span_help ( help_span, help. into ( ) ) ;
116
115
} else {
117
- diag. help ( help) ;
116
+ diag. help ( help. into ( ) ) ;
118
117
}
119
118
docs_link ( diag, lint) ;
120
119
} ) ;
@@ -161,17 +160,16 @@ pub fn span_lint_and_note<T: LintContext>(
161
160
cx : & T ,
162
161
lint : & ' static Lint ,
163
162
span : impl Into < MultiSpan > ,
164
- msg : & str ,
163
+ msg : impl Into < DiagMessage > ,
165
164
note_span : Option < Span > ,
166
- note : & str ,
165
+ note : impl Into < SubdiagMessage > ,
167
166
) {
168
167
#[ expect( clippy:: disallowed_methods) ]
169
- cx. span_lint ( lint, span, msg. to_string ( ) , |diag| {
170
- let note = note. to_string ( ) ;
168
+ cx. span_lint ( lint, span, msg. into ( ) , |diag| {
171
169
if let Some ( note_span) = note_span {
172
- diag. span_note ( note_span, note) ;
170
+ diag. span_note ( note_span, note. into ( ) ) ;
173
171
} else {
174
- diag. note ( note) ;
172
+ diag. note ( note. into ( ) ) ;
175
173
}
176
174
docs_link ( diag, lint) ;
177
175
} ) ;
@@ -195,14 +193,15 @@ pub fn span_lint_and_note<T: LintContext>(
195
193
/// If you're unsure which function you should use, you can test if the `#[allow]` attribute works
196
194
/// where you would expect it to.
197
195
/// If it doesn't, you likely need to use [`span_lint_hir_and_then`] instead.
198
- pub fn span_lint_and_then < C , S , F > ( cx : & C , lint : & ' static Lint , sp : S , msg : & str , f : F )
196
+ pub fn span_lint_and_then < C , S , M , F > ( cx : & C , lint : & ' static Lint , sp : S , msg : M , f : F )
199
197
where
200
198
C : LintContext ,
201
199
S : Into < MultiSpan > ,
200
+ M : Into < DiagMessage > ,
202
201
F : FnOnce ( & mut Diag < ' _ , ( ) > ) ,
203
202
{
204
203
#[ expect( clippy:: disallowed_methods) ]
205
- cx. span_lint ( lint, sp, msg. to_string ( ) , |diag| {
204
+ cx. span_lint ( lint, sp, msg, |diag| {
206
205
f ( diag) ;
207
206
docs_link ( diag, lint) ;
208
207
} ) ;
@@ -232,9 +231,9 @@ where
232
231
/// Instead, use this function and also pass the `HirId` of `<expr_1>`, which will let
233
232
/// the compiler check lint level attributes at the place of the expression and
234
233
/// the `#[allow]` will work.
235
- pub fn span_lint_hir ( cx : & LateContext < ' _ > , lint : & ' static Lint , hir_id : HirId , sp : Span , msg : & str ) {
234
+ pub fn span_lint_hir ( cx : & LateContext < ' _ > , lint : & ' static Lint , hir_id : HirId , sp : Span , msg : impl Into < DiagMessage > ) {
236
235
#[ expect( clippy:: disallowed_methods) ]
237
- cx. tcx . node_span_lint ( lint, hir_id, sp, msg. to_string ( ) , |diag| {
236
+ cx. tcx . node_span_lint ( lint, hir_id, sp, msg. into ( ) , |diag| {
238
237
docs_link ( diag, lint) ;
239
238
} ) ;
240
239
}
@@ -268,11 +267,11 @@ pub fn span_lint_hir_and_then(
268
267
lint : & ' static Lint ,
269
268
hir_id : HirId ,
270
269
sp : impl Into < MultiSpan > ,
271
- msg : & str ,
270
+ msg : impl Into < DiagMessage > ,
272
271
f : impl FnOnce ( & mut Diag < ' _ , ( ) > ) ,
273
272
) {
274
273
#[ expect( clippy:: disallowed_methods) ]
275
- cx. tcx . node_span_lint ( lint, hir_id, sp, msg. to_string ( ) , |diag| {
274
+ cx. tcx . node_span_lint ( lint, hir_id, sp, msg. into ( ) , |diag| {
276
275
f ( diag) ;
277
276
docs_link ( diag, lint) ;
278
277
} ) ;
@@ -316,13 +315,13 @@ pub fn span_lint_and_sugg<T: LintContext>(
316
315
cx : & T ,
317
316
lint : & ' static Lint ,
318
317
sp : Span ,
319
- msg : & str ,
320
- help : & str ,
318
+ msg : impl Into < DiagMessage > ,
319
+ help : impl Into < SubdiagMessage > ,
321
320
sugg : String ,
322
321
applicability : Applicability ,
323
322
) {
324
- span_lint_and_then ( cx, lint, sp, msg, |diag| {
325
- diag. span_suggestion ( sp, help. to_string ( ) , sugg, applicability) ;
323
+ span_lint_and_then ( cx, lint, sp, msg. into ( ) , |diag| {
324
+ diag. span_suggestion ( sp, help. into ( ) , sugg, applicability) ;
326
325
} ) ;
327
326
}
328
327
@@ -332,7 +331,7 @@ pub fn span_lint_and_sugg<T: LintContext>(
332
331
/// appear once per
333
332
/// replacement. In human-readable format though, it only appears once before
334
333
/// the whole suggestion.
335
- pub fn multispan_sugg < I > ( diag : & mut Diag < ' _ , ( ) > , help_msg : & str , sugg : I )
334
+ pub fn multispan_sugg < I > ( diag : & mut Diag < ' _ , ( ) > , help_msg : impl Into < SubdiagMessage > , sugg : I )
336
335
where
337
336
I : IntoIterator < Item = ( Span , String ) > ,
338
337
{
@@ -346,11 +345,11 @@ where
346
345
/// Suggestions with multiple spans will be silently ignored.
347
346
pub fn multispan_sugg_with_applicability < I > (
348
347
diag : & mut Diag < ' _ , ( ) > ,
349
- help_msg : & str ,
348
+ help_msg : impl Into < SubdiagMessage > ,
350
349
applicability : Applicability ,
351
350
sugg : I ,
352
351
) where
353
352
I : IntoIterator < Item = ( Span , String ) > ,
354
353
{
355
- diag. multipart_suggestion ( help_msg. to_string ( ) , sugg. into_iter ( ) . collect ( ) , applicability) ;
354
+ diag. multipart_suggestion ( help_msg. into ( ) , sugg. into_iter ( ) . collect ( ) , applicability) ;
356
355
}
0 commit comments