@@ -20,7 +20,7 @@ use rustc_session::lint::builtin::{
20
20
CONFLICTING_REPR_HINTS , INVALID_DOC_ATTRIBUTES , UNUSED_ATTRIBUTES ,
21
21
} ;
22
22
use rustc_session:: parse:: feature_err;
23
- use rustc_span:: symbol:: { sym, Symbol } ;
23
+ use rustc_span:: symbol:: { kw , sym, Symbol } ;
24
24
use rustc_span:: { Span , DUMMY_SP } ;
25
25
use std:: collections:: hash_map:: Entry ;
26
26
@@ -536,7 +536,7 @@ impl CheckAttrVisitor<'_> {
536
536
fn check_doc_alias_value (
537
537
& self ,
538
538
meta : & NestedMetaItem ,
539
- doc_alias : & str ,
539
+ doc_alias : Symbol ,
540
540
hir_id : HirId ,
541
541
target : Target ,
542
542
is_list : bool ,
@@ -554,14 +554,17 @@ impl CheckAttrVisitor<'_> {
554
554
) ;
555
555
false
556
556
} ;
557
- if doc_alias. is_empty ( ) {
557
+ if doc_alias == kw :: Empty {
558
558
return err_fn (
559
559
meta. name_value_literal_span ( ) . unwrap_or_else ( || meta. span ( ) ) ,
560
560
"attribute cannot have empty value" ,
561
561
) ;
562
562
}
563
- if let Some ( c) =
564
- doc_alias. chars ( ) . find ( |& c| c == '"' || c == '\'' || ( c. is_whitespace ( ) && c != ' ' ) )
563
+
564
+ let doc_alias_str = doc_alias. as_str ( ) ;
565
+ if let Some ( c) = doc_alias_str
566
+ . chars ( )
567
+ . find ( |& c| c == '"' || c == '\'' || ( c. is_whitespace ( ) && c != ' ' ) )
565
568
{
566
569
self . tcx . sess . span_err (
567
570
meta. name_value_literal_span ( ) . unwrap_or_else ( || meta. span ( ) ) ,
@@ -573,7 +576,7 @@ impl CheckAttrVisitor<'_> {
573
576
) ;
574
577
return false ;
575
578
}
576
- if doc_alias . starts_with ( ' ' ) || doc_alias . ends_with ( ' ' ) {
579
+ if doc_alias_str . starts_with ( ' ' ) || doc_alias_str . ends_with ( ' ' ) {
577
580
return err_fn (
578
581
meta. name_value_literal_span ( ) . unwrap_or_else ( || meta. span ( ) ) ,
579
582
"cannot start or end with ' '" ,
@@ -608,11 +611,11 @@ impl CheckAttrVisitor<'_> {
608
611
return err_fn ( meta. span ( ) , & format ! ( "isn't allowed on {}" , err) ) ;
609
612
}
610
613
let item_name = self . tcx . hir ( ) . name ( hir_id) ;
611
- if item_name. as_str ( ) == doc_alias {
614
+ if item_name == doc_alias {
612
615
return err_fn ( meta. span ( ) , "is the same as the item's name" ) ;
613
616
}
614
617
let span = meta. span ( ) ;
615
- if let Err ( entry) = aliases. try_insert ( doc_alias . to_owned ( ) , span) {
618
+ if let Err ( entry) = aliases. try_insert ( doc_alias_str . to_owned ( ) , span) {
616
619
self . tcx . struct_span_lint_hir ( UNUSED_ATTRIBUTES , hir_id, span, |lint| {
617
620
lint. build ( "doc alias is duplicated" )
618
621
. span_label ( * entry. entry . get ( ) , "first defined here" )
@@ -635,14 +638,7 @@ impl CheckAttrVisitor<'_> {
635
638
match v. literal ( ) {
636
639
Some ( l) => match l. kind {
637
640
LitKind :: Str ( s, _) => {
638
- if !self . check_doc_alias_value (
639
- v,
640
- s. as_str ( ) ,
641
- hir_id,
642
- target,
643
- true ,
644
- aliases,
645
- ) {
641
+ if !self . check_doc_alias_value ( v, s, hir_id, target, true , aliases) {
646
642
errors += 1 ;
647
643
}
648
644
}
@@ -670,8 +666,8 @@ impl CheckAttrVisitor<'_> {
670
666
}
671
667
}
672
668
errors == 0
673
- } else if let Some ( doc_alias) = meta. value_str ( ) . map ( |s| s . to_string ( ) ) {
674
- self . check_doc_alias_value ( meta, & doc_alias, hir_id, target, false , aliases)
669
+ } else if let Some ( doc_alias) = meta. value_str ( ) {
670
+ self . check_doc_alias_value ( meta, doc_alias, hir_id, target, false , aliases)
675
671
} else {
676
672
self . tcx
677
673
. sess
@@ -686,8 +682,8 @@ impl CheckAttrVisitor<'_> {
686
682
}
687
683
688
684
fn check_doc_keyword ( & self , meta : & NestedMetaItem , hir_id : HirId ) -> bool {
689
- let doc_keyword = meta. value_str ( ) . map ( |s| s . to_string ( ) ) . unwrap_or_else ( String :: new ) ;
690
- if doc_keyword. is_empty ( ) {
685
+ let doc_keyword = meta. value_str ( ) . unwrap_or ( kw :: Empty ) ;
686
+ if doc_keyword == kw :: Empty {
691
687
self . doc_attr_str_error ( meta, "keyword" ) ;
692
688
return false ;
693
689
}
@@ -718,7 +714,7 @@ impl CheckAttrVisitor<'_> {
718
714
return false ;
719
715
}
720
716
}
721
- if !rustc_lexer:: is_ident ( & doc_keyword) {
717
+ if !rustc_lexer:: is_ident ( doc_keyword. as_str ( ) ) {
722
718
self . tcx
723
719
. sess
724
720
. struct_span_err (
@@ -911,20 +907,20 @@ impl CheckAttrVisitor<'_> {
911
907
) -> bool {
912
908
let mut is_valid = true ;
913
909
914
- if let Some ( list ) = attr. meta ( ) . and_then ( |mi| mi. meta_item_list ( ) . map ( |l| l . to_vec ( ) ) ) {
915
- for meta in & list {
910
+ if let Some ( mi ) = attr. meta ( ) && let Some ( list ) = mi. meta_item_list ( ) {
911
+ for meta in list {
916
912
if let Some ( i_meta) = meta. meta_item ( ) {
917
913
match i_meta. name_or_empty ( ) {
918
914
sym:: alias
919
- if !self . check_attr_not_crate_level ( & meta, hir_id, "alias" )
920
- || !self . check_doc_alias ( & meta, hir_id, target, aliases) =>
915
+ if !self . check_attr_not_crate_level ( meta, hir_id, "alias" )
916
+ || !self . check_doc_alias ( meta, hir_id, target, aliases) =>
921
917
{
922
918
is_valid = false
923
919
}
924
920
925
921
sym:: keyword
926
- if !self . check_attr_not_crate_level ( & meta, hir_id, "keyword" )
927
- || !self . check_doc_keyword ( & meta, hir_id) =>
922
+ if !self . check_attr_not_crate_level ( meta, hir_id, "keyword" )
923
+ || !self . check_doc_keyword ( meta, hir_id) =>
928
924
{
929
925
is_valid = false
930
926
}
@@ -936,15 +932,15 @@ impl CheckAttrVisitor<'_> {
936
932
| sym:: html_root_url
937
933
| sym:: html_no_source
938
934
| sym:: test
939
- if !self . check_attr_crate_level ( & attr, & meta, hir_id) =>
935
+ if !self . check_attr_crate_level ( attr, meta, hir_id) =>
940
936
{
941
937
is_valid = false ;
942
938
}
943
939
944
940
sym:: inline | sym:: no_inline
945
941
if !self . check_doc_inline (
946
- & attr,
947
- & meta,
942
+ attr,
943
+ meta,
948
944
hir_id,
949
945
target,
950
946
specified_inline,
@@ -976,7 +972,7 @@ impl CheckAttrVisitor<'_> {
976
972
| sym:: plugins => { }
977
973
978
974
sym:: test => {
979
- if !self . check_test_attr ( & meta, hir_id) {
975
+ if !self . check_test_attr ( meta, hir_id) {
980
976
is_valid = false ;
981
977
}
982
978
}
0 commit comments