1
1
/// The expansion from a test function to the appropriate test struct for libtest
2
2
/// Ideally, this code would be in libtest but for efficiency and error messages it lives here.
3
3
use crate :: util:: { check_builtin_macro_attribute, warn_on_duplicate_attribute} ;
4
- use rustc_ast as ast;
5
4
use rustc_ast:: ptr:: P ;
5
+ use rustc_ast:: { self as ast, attr} ;
6
6
use rustc_ast_pretty:: pprust;
7
7
use rustc_errors:: Applicability ;
8
8
use rustc_expand:: base:: * ;
9
- use rustc_session:: Session ;
10
9
use rustc_span:: symbol:: { sym, Ident , Symbol } ;
11
10
use rustc_span:: { FileNameDisplayPreference , Span } ;
12
11
use std:: iter;
@@ -291,14 +290,11 @@ pub fn expand_test_or_bench(
291
290
) ,
292
291
) ,
293
292
// ignore: true | false
294
- field(
295
- "ignore" ,
296
- cx. expr_bool( sp, should_ignore( & cx. sess, & item) ) ,
297
- ) ,
293
+ field( "ignore" , cx. expr_bool( sp, should_ignore( & item) ) , ) ,
298
294
// ignore_message: Some("...") | None
299
295
field(
300
296
"ignore_message" ,
301
- if let Some ( msg) = should_ignore_message( cx , & item) {
297
+ if let Some ( msg) = should_ignore_message( & item) {
302
298
cx. expr_some( sp, cx. expr_str( sp, msg) )
303
299
} else {
304
300
cx. expr_none( sp)
@@ -425,12 +421,12 @@ enum ShouldPanic {
425
421
Yes ( Option < Symbol > ) ,
426
422
}
427
423
428
- fn should_ignore ( sess : & Session , i : & ast:: Item ) -> bool {
429
- sess . contains_name ( & i. attrs , sym:: ignore)
424
+ fn should_ignore ( i : & ast:: Item ) -> bool {
425
+ attr :: contains_name ( & i. attrs , sym:: ignore)
430
426
}
431
427
432
- fn should_ignore_message ( cx : & ExtCtxt < ' _ > , i : & ast:: Item ) -> Option < Symbol > {
433
- match cx . sess . find_by_name ( & i. attrs , sym:: ignore) {
428
+ fn should_ignore_message ( i : & ast:: Item ) -> Option < Symbol > {
429
+ match attr :: find_by_name ( & i. attrs , sym:: ignore) {
434
430
Some ( attr) => {
435
431
match attr. meta_item_list ( ) {
436
432
// Handle #[ignore(bar = "foo")]
@@ -444,7 +440,7 @@ fn should_ignore_message(cx: &ExtCtxt<'_>, i: &ast::Item) -> Option<Symbol> {
444
440
}
445
441
446
442
fn should_panic ( cx : & ExtCtxt < ' _ > , i : & ast:: Item ) -> ShouldPanic {
447
- match cx . sess . find_by_name ( & i. attrs , sym:: should_panic) {
443
+ match attr :: find_by_name ( & i. attrs , sym:: should_panic) {
448
444
Some ( attr) => {
449
445
let sd = & cx. sess . parse_sess . span_diagnostic ;
450
446
@@ -510,7 +506,7 @@ fn test_type(cx: &ExtCtxt<'_>) -> TestType {
510
506
}
511
507
512
508
fn has_test_signature ( cx : & ExtCtxt < ' _ > , i : & ast:: Item ) -> bool {
513
- let has_should_panic_attr = cx . sess . contains_name ( & i. attrs , sym:: should_panic) ;
509
+ let has_should_panic_attr = attr :: contains_name ( & i. attrs , sym:: should_panic) ;
514
510
let sd = & cx. sess . parse_sess . span_diagnostic ;
515
511
match & i. kind {
516
512
ast:: ItemKind :: Fn ( box ast:: Fn { sig, generics, .. } ) => {
0 commit comments