@@ -398,47 +398,42 @@ impl CheckAttrVisitor<'tcx> {
398398 target : Target ,
399399 is_list : bool ,
400400 ) -> 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+ } ;
401413 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+ ) ;
413418 }
414419 if let Some ( c) =
415420 doc_alias. chars ( ) . find ( |& c| c == '"' || c == '\'' || ( c. is_whitespace ( ) && c != ' ' ) )
416421 {
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+ ) ;
428430 return false ;
429431 }
430432 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+ ) ;
442437 }
443438 if let Some ( err) = match target {
444439 Target :: Impl => Some ( "implementation block" ) ,
@@ -464,32 +459,11 @@ impl CheckAttrVisitor<'tcx> {
464459 }
465460 _ => None ,
466461 } {
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) ) ;
479463 }
480464 let item_name = self . tcx . hir ( ) . name ( hir_id) ;
481465 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" ) ;
493467 }
494468 true
495469 }
@@ -510,7 +484,7 @@ impl CheckAttrVisitor<'tcx> {
510484 . sess
511485 . struct_span_err (
512486 v. span ( ) ,
513- "`#[doc(alias(\" a\" )]` expects string literals" ,
487+ "`#[doc(alias(\" a\" )) ]` expects string literals" ,
514488 )
515489 . emit ( ) ;
516490 errors += 1 ;
@@ -521,7 +495,7 @@ impl CheckAttrVisitor<'tcx> {
521495 . sess
522496 . struct_span_err (
523497 v. span ( ) ,
524- "`#[doc(alias(\" a\" )]` expects string literals" ,
498+ "`#[doc(alias(\" a\" )) ]` expects string literals" ,
525499 )
526500 . emit ( ) ;
527501 errors += 1 ;
@@ -537,7 +511,7 @@ impl CheckAttrVisitor<'tcx> {
537511 . struct_span_err (
538512 meta. span ( ) ,
539513 "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\" ) )]`",
541515 )
542516 . emit ( ) ;
543517 false
0 commit comments