19
19
#![ feature( rustc_private) ]
20
20
#![ cfg( feature = "unrooted_must_root_lint" ) ]
21
21
22
- #[ macro_use]
23
- extern crate matches;
24
22
extern crate rustc;
25
23
extern crate rustc_driver;
26
24
extern crate rustc_hir;
@@ -204,12 +202,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnrootedPass {
204
202
for ref field in def. fields ( ) {
205
203
let def_id = cx. tcx . hir ( ) . local_def_id ( field. hir_id ) ;
206
204
if is_unrooted_ty ( & self . symbols , cx, cx. tcx . type_of ( def_id) , false ) {
207
- cx. span_lint (
208
- UNROOTED_MUST_ROOT ,
209
- field. span ,
210
- "Type must be rooted, use #[unrooted_must_root_lint::must_root] \
211
- on the struct definition to propagate",
212
- )
205
+ cx. lint ( UNROOTED_MUST_ROOT , |lint| {
206
+ lint. build (
207
+ "Type must be rooted, use #[unrooted_must_root_lint::must_root] \
208
+ on the struct definition to propagate",
209
+ )
210
+ . set_span ( field. span )
211
+ . emit ( )
212
+ } )
213
213
}
214
214
}
215
215
}
@@ -226,12 +226,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnrootedPass {
226
226
for field in fields {
227
227
let def_id = cx. tcx . hir ( ) . local_def_id ( field. hir_id ) ;
228
228
if is_unrooted_ty ( & self . symbols , cx, cx. tcx . type_of ( def_id) , false ) {
229
- cx. span_lint (
230
- UNROOTED_MUST_ROOT ,
231
- field. ty . span ,
232
- "Type must be rooted, use #[unrooted_must_root_lint::must_root] on \
233
- the enum definition to propagate",
234
- )
229
+ cx. lint ( UNROOTED_MUST_ROOT , |lint| {
230
+ lint. build (
231
+ "Type must be rooted, \
232
+ use #[unrooted_must_root_lint::must_root] \
233
+ on the enum definition to propagate",
234
+ )
235
+ . set_span ( field. ty . span )
236
+ . emit ( )
237
+ } )
235
238
}
236
239
}
237
240
} ,
@@ -262,17 +265,19 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnrootedPass {
262
265
263
266
for ( arg, ty) in decl. inputs . iter ( ) . zip ( sig. inputs ( ) . skip_binder ( ) . iter ( ) ) {
264
267
if is_unrooted_ty ( & self . symbols , cx, ty, false ) {
265
- cx. span_lint ( UNROOTED_MUST_ROOT , arg. span , "Type must be rooted" )
268
+ cx. lint ( UNROOTED_MUST_ROOT , |lint| {
269
+ lint. build ( "Type must be rooted" ) . set_span ( arg. span ) . emit ( )
270
+ } )
266
271
}
267
272
}
268
273
269
274
if !in_new_function {
270
275
if is_unrooted_ty ( & self . symbols , cx, sig. output ( ) . skip_binder ( ) , false ) {
271
- cx. span_lint (
272
- UNROOTED_MUST_ROOT ,
273
- decl. output . span ( ) ,
274
- "Type must be rooted" ,
275
- )
276
+ cx. lint ( UNROOTED_MUST_ROOT , |lint| {
277
+ lint . build ( "Type must be rooted" )
278
+ . set_span ( decl. output . span ( ) )
279
+ . emit ( )
280
+ } )
276
281
}
277
282
}
278
283
}
@@ -301,11 +306,11 @@ impl<'a, 'b, 'tcx> visit::Visitor<'tcx> for FnDefVisitor<'a, 'b, 'tcx> {
301
306
let require_rooted = |cx : & LateContext , in_new_function : bool , subexpr : & hir:: Expr | {
302
307
let ty = cx. tables . expr_ty ( & subexpr) ;
303
308
if is_unrooted_ty ( & self . symbols , cx, ty, in_new_function) {
304
- cx. span_lint (
305
- UNROOTED_MUST_ROOT ,
306
- subexpr. span ,
307
- & format ! ( "Expression of type {:?} must be rooted" , ty ) ,
308
- )
309
+ cx. lint ( UNROOTED_MUST_ROOT , |lint| {
310
+ lint . build ( & format ! ( "Expression of type {:?} must be rooted" , ty ) )
311
+ . set_span ( subexpr. span )
312
+ . emit ( )
313
+ } )
309
314
}
310
315
} ;
311
316
@@ -343,11 +348,11 @@ impl<'a, 'b, 'tcx> visit::Visitor<'tcx> for FnDefVisitor<'a, 'b, 'tcx> {
343
348
hir:: PatKind :: Binding ( hir:: BindingAnnotation :: Mutable , ..) => {
344
349
let ty = cx. tables . pat_ty ( pat) ;
345
350
if is_unrooted_ty ( & self . symbols , cx, ty, self . in_new_function ) {
346
- cx. span_lint (
347
- UNROOTED_MUST_ROOT ,
348
- pat. span ,
349
- & format ! ( "Expression of type {:?} must be rooted" , ty ) ,
350
- )
351
+ cx. lint ( UNROOTED_MUST_ROOT , |lint| {
352
+ lint . build ( & format ! ( "Expression of type {:?} must be rooted" , ty ) )
353
+ . set_span ( pat. span )
354
+ . emit ( )
355
+ } )
351
356
}
352
357
} ,
353
358
_ => { } ,
@@ -388,11 +393,10 @@ fn match_def_path(cx: &LateContext, def_id: DefId, path: &[Symbol]) -> bool {
388
393
}
389
394
390
395
fn in_derive_expn ( span : Span ) -> bool {
391
- if let ExpnKind :: Macro ( MacroKind :: Attr , n) = span. ctxt ( ) . outer_expn_data ( ) . kind {
392
- n. as_str ( ) . contains ( "derive" )
393
- } else {
394
- false
395
- }
396
+ matches ! (
397
+ span. ctxt( ) . outer_expn_data( ) . kind,
398
+ ExpnKind :: Macro ( MacroKind :: Derive , _)
399
+ )
396
400
}
397
401
398
402
macro_rules! symbols {
0 commit comments