@@ -398,47 +398,42 @@ impl CheckAttrVisitor<'tcx> {
398
398
target : Target ,
399
399
is_list : bool ,
400
400
) -> bool {
401
+ let tcx = self . tcx ;
402
+ let err_fn = move |span : Span , msg : & str | {
403
+ tcx. sess . span_err (
404
+ span,
405
+ & format ! (
406
+ "`#[doc(alias{})]` {}" ,
407
+ if is_list { "(\" ...\" )" } else { " = \" ...\" " } ,
408
+ msg,
409
+ ) ,
410
+ ) ;
411
+ false
412
+ } ;
401
413
if doc_alias. is_empty ( ) {
402
- self . tcx
403
- . sess
404
- . struct_span_err (
405
- meta. name_value_literal_span ( ) . unwrap_or_else ( || meta. span ( ) ) ,
406
- & format ! (
407
- "`#[doc(alias{})]` attribute cannot have empty value" ,
408
- if is_list { "(\" ...\" )" } else { " = \" ...\" " } ,
409
- ) ,
410
- )
411
- . emit ( ) ;
412
- return false ;
414
+ return err_fn (
415
+ meta. name_value_literal_span ( ) . unwrap_or_else ( || meta. span ( ) ) ,
416
+ "attribute cannot have empty value" ,
417
+ ) ;
413
418
}
414
419
if let Some ( c) =
415
420
doc_alias. chars ( ) . find ( |& c| c == '"' || c == '\'' || ( c. is_whitespace ( ) && c != ' ' ) )
416
421
{
417
- self . tcx
418
- . sess
419
- . struct_span_err (
420
- meta. name_value_literal_span ( ) . unwrap_or_else ( || meta. span ( ) ) ,
421
- & format ! (
422
- "{:?} character isn't allowed in `#[doc(alias{})]`" ,
423
- c,
424
- if is_list { "(\" ...\" )" } else { " = \" ...\" " } ,
425
- ) ,
426
- )
427
- . emit ( ) ;
422
+ self . tcx . sess . span_err (
423
+ meta. name_value_literal_span ( ) . unwrap_or_else ( || meta. span ( ) ) ,
424
+ & format ! (
425
+ "{:?} character isn't allowed in `#[doc(alias{})]`" ,
426
+ c,
427
+ if is_list { "(\" ...\" )" } else { " = \" ...\" " } ,
428
+ ) ,
429
+ ) ;
428
430
return false ;
429
431
}
430
432
if doc_alias. starts_with ( ' ' ) || doc_alias. ends_with ( ' ' ) {
431
- self . tcx
432
- . sess
433
- . struct_span_err (
434
- meta. name_value_literal_span ( ) . unwrap_or_else ( || meta. span ( ) ) ,
435
- & format ! (
436
- "`#[doc(alias{})]` cannot start or end with ' '" ,
437
- if is_list { "(\" ...\" )" } else { " = \" ...\" " } ,
438
- ) ,
439
- )
440
- . emit ( ) ;
441
- return false ;
433
+ return err_fn (
434
+ meta. name_value_literal_span ( ) . unwrap_or_else ( || meta. span ( ) ) ,
435
+ "cannot start or end with ' '" ,
436
+ ) ;
442
437
}
443
438
if let Some ( err) = match target {
444
439
Target :: Impl => Some ( "implementation block" ) ,
@@ -464,32 +459,11 @@ impl CheckAttrVisitor<'tcx> {
464
459
}
465
460
_ => None ,
466
461
} {
467
- self . tcx
468
- . sess
469
- . struct_span_err (
470
- meta. span ( ) ,
471
- & format ! (
472
- "`#[doc(alias{})]` isn't allowed on {}" ,
473
- if is_list { "(\" ...\" )" } else { " = \" ...\" " } ,
474
- err,
475
- ) ,
476
- )
477
- . emit ( ) ;
478
- return false ;
462
+ return err_fn ( meta. span ( ) , & format ! ( "isn't allowed on {}" , err) ) ;
479
463
}
480
464
let item_name = self . tcx . hir ( ) . name ( hir_id) ;
481
465
if & * item_name. as_str ( ) == doc_alias {
482
- self . tcx
483
- . sess
484
- . struct_span_err (
485
- meta. span ( ) ,
486
- & format ! (
487
- "`#[doc(alias{})]` is the same as the item's name" ,
488
- if is_list { "(\" ...\" )" } else { " = \" ...\" " } ,
489
- ) ,
490
- )
491
- . emit ( ) ;
492
- return false ;
466
+ return err_fn ( meta. span ( ) , "is the same as the item's name" ) ;
493
467
}
494
468
true
495
469
}
@@ -510,7 +484,7 @@ impl CheckAttrVisitor<'tcx> {
510
484
. sess
511
485
. struct_span_err (
512
486
v. span ( ) ,
513
- "`#[doc(alias(\" a\" )]` expects string literals" ,
487
+ "`#[doc(alias(\" a\" )) ]` expects string literals" ,
514
488
)
515
489
. emit ( ) ;
516
490
errors += 1 ;
@@ -521,7 +495,7 @@ impl CheckAttrVisitor<'tcx> {
521
495
. sess
522
496
. struct_span_err (
523
497
v. span ( ) ,
524
- "`#[doc(alias(\" a\" )]` expects string literals" ,
498
+ "`#[doc(alias(\" a\" )) ]` expects string literals" ,
525
499
)
526
500
. emit ( ) ;
527
501
errors += 1 ;
@@ -537,7 +511,7 @@ impl CheckAttrVisitor<'tcx> {
537
511
. struct_span_err (
538
512
meta. span ( ) ,
539
513
"doc alias attribute expects a string `#[doc(alias = \" a\" )]` or a list of \
540
- strings: `#[doc(alias(\" a\" , \" b\" )]`",
514
+ strings `#[doc(alias(\" a\" , \" b\" ) )]`",
541
515
)
542
516
. emit ( ) ;
543
517
false
0 commit comments