@@ -6,7 +6,6 @@ use std::fmt;
6
6
use std:: iter;
7
7
8
8
use if_chain:: if_chain;
9
- use lazy_static:: lazy_static;
10
9
use matches:: matches;
11
10
use rustc:: hir;
12
11
use rustc:: hir:: def:: { DefKind , Res } ;
@@ -17,7 +16,7 @@ use rustc::{declare_lint_pass, declare_tool_lint};
17
16
use rustc_errors:: Applicability ;
18
17
use syntax:: ast;
19
18
use syntax:: source_map:: { BytePos , Span } ;
20
- use syntax:: symbol:: { LocalInternedString , Symbol } ;
19
+ use syntax:: symbol:: LocalInternedString ;
21
20
22
21
use crate :: utils:: paths;
23
22
use crate :: utils:: sugg;
@@ -914,8 +913,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
914
913
915
914
match self_ty. sty {
916
915
ty:: Ref ( _, ty, _) if ty. sty == ty:: Str => {
917
- for & ( method, pos) in PATTERN_METHODS . iter ( ) {
918
- if method_call. ident . name == method && args. len ( ) > pos {
916
+ for & ( method, pos) in & PATTERN_METHODS {
917
+ if method_call. ident . name . as_str ( ) == method && args. len ( ) > pos {
919
918
lint_single_char_pattern ( cx, expr, & args[ pos] ) ;
920
919
}
921
920
}
@@ -945,7 +944,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
945
944
if in_external_macro ( cx. sess ( ) , implitem. span ) {
946
945
return ;
947
946
}
948
- let name = implitem. ident . name ;
947
+ let name = implitem. ident . name . as_str ( ) ;
949
948
let parent = cx. tcx . hir ( ) . get_parent_item ( implitem. hir_id ) ;
950
949
let item = cx. tcx . hir ( ) . expect_item_by_hir_id ( parent) ;
951
950
let def_id = cx. tcx . hir ( ) . local_def_id_from_hir_id ( item. hir_id ) ;
@@ -958,7 +957,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
958
957
then {
959
958
if cx. access_levels. is_exported( implitem. hir_id) {
960
959
// check missing trait implementations
961
- for & ( method_name, n_args, self_kind, out_type, trait_name) in TRAIT_METHODS . iter ( ) {
960
+ for & ( method_name, n_args, self_kind, out_type, trait_name) in & TRAIT_METHODS {
962
961
if name == method_name &&
963
962
sig. decl. inputs. len( ) == n_args &&
964
963
out_type. matches( cx, & sig. decl. output) &&
@@ -973,7 +972,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
973
972
// check conventions w.r.t. conversion method names and predicates
974
973
let is_copy = is_copy( cx, ty) ;
975
974
for & ( ref conv, self_kinds) in & CONVENTIONS {
976
- if conv. check( & name. as_str ( ) ) {
975
+ if conv. check( & name) {
977
976
if !self_kinds
978
977
. iter( )
979
978
. any( |k| k. matches( cx, first_arg_ty, first_arg, self_ty, is_copy, & implitem. generics) ) {
@@ -1032,7 +1031,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Methods {
1032
1031
}
1033
1032
}
1034
1033
1035
- if name == sym ! ( new) && !same_tys ( cx, ret_ty, ty) {
1034
+ if name == " new" && !same_tys ( cx, ret_ty, ty) {
1036
1035
span_lint (
1037
1036
cx,
1038
1037
NEW_RET_NO_SELF ,
@@ -2407,63 +2406,59 @@ const CONVENTIONS: [(Convention, &[SelfKind]); 7] = [
2407
2406
] ;
2408
2407
2409
2408
#[ rustfmt:: skip]
2410
- lazy_static ! {
2411
- static ref TRAIT_METHODS : [ ( Symbol , usize , SelfKind , OutType , & ' static str ) ; 30 ] = [
2412
- ( sym!( add) , 2 , SelfKind :: Value , OutType :: Any , "std::ops::Add" ) ,
2413
- ( sym!( as_mut) , 1 , SelfKind :: RefMut , OutType :: Ref , "std::convert::AsMut" ) ,
2414
- ( sym!( as_ref) , 1 , SelfKind :: Ref , OutType :: Ref , "std::convert::AsRef" ) ,
2415
- ( sym!( bitand) , 2 , SelfKind :: Value , OutType :: Any , "std::ops::BitAnd" ) ,
2416
- ( sym!( bitor) , 2 , SelfKind :: Value , OutType :: Any , "std::ops::BitOr" ) ,
2417
- ( sym!( bitxor) , 2 , SelfKind :: Value , OutType :: Any , "std::ops::BitXor" ) ,
2418
- ( sym!( borrow) , 1 , SelfKind :: Ref , OutType :: Ref , "std::borrow::Borrow" ) ,
2419
- ( sym!( borrow_mut) , 1 , SelfKind :: RefMut , OutType :: Ref , "std::borrow::BorrowMut" ) ,
2420
- ( sym!( clone) , 1 , SelfKind :: Ref , OutType :: Any , "std::clone::Clone" ) ,
2421
- ( sym!( cmp) , 2 , SelfKind :: Ref , OutType :: Any , "std::cmp::Ord" ) ,
2422
- ( sym!( default ) , 0 , SelfKind :: No , OutType :: Any , "std::default::Default" ) ,
2423
- ( sym!( deref) , 1 , SelfKind :: Ref , OutType :: Ref , "std::ops::Deref" ) ,
2424
- ( sym!( deref_mut) , 1 , SelfKind :: RefMut , OutType :: Ref , "std::ops::DerefMut" ) ,
2425
- ( sym!( div) , 2 , SelfKind :: Value , OutType :: Any , "std::ops::Div" ) ,
2426
- ( sym!( drop) , 1 , SelfKind :: RefMut , OutType :: Unit , "std::ops::Drop" ) ,
2427
- ( sym!( eq) , 2 , SelfKind :: Ref , OutType :: Bool , "std::cmp::PartialEq" ) ,
2428
- ( sym!( from_iter) , 1 , SelfKind :: No , OutType :: Any , "std::iter::FromIterator" ) ,
2429
- ( sym!( from_str) , 1 , SelfKind :: No , OutType :: Any , "std::str::FromStr" ) ,
2430
- ( sym!( hash) , 2 , SelfKind :: Ref , OutType :: Unit , "std::hash::Hash" ) ,
2431
- ( sym!( index) , 2 , SelfKind :: Ref , OutType :: Ref , "std::ops::Index" ) ,
2432
- ( sym!( index_mut) , 2 , SelfKind :: RefMut , OutType :: Ref , "std::ops::IndexMut" ) ,
2433
- ( sym!( into_iter) , 1 , SelfKind :: Value , OutType :: Any , "std::iter::IntoIterator" ) ,
2434
- ( sym!( mul) , 2 , SelfKind :: Value , OutType :: Any , "std::ops::Mul" ) ,
2435
- ( sym!( neg) , 1 , SelfKind :: Value , OutType :: Any , "std::ops::Neg" ) ,
2436
- ( sym!( next) , 1 , SelfKind :: RefMut , OutType :: Any , "std::iter::Iterator" ) ,
2437
- ( sym!( not) , 1 , SelfKind :: Value , OutType :: Any , "std::ops::Not" ) ,
2438
- ( sym!( rem) , 2 , SelfKind :: Value , OutType :: Any , "std::ops::Rem" ) ,
2439
- ( sym!( shl) , 2 , SelfKind :: Value , OutType :: Any , "std::ops::Shl" ) ,
2440
- ( sym!( shr) , 2 , SelfKind :: Value , OutType :: Any , "std::ops::Shr" ) ,
2441
- ( sym!( sub) , 2 , SelfKind :: Value , OutType :: Any , "std::ops::Sub" ) ,
2409
+ const TRAIT_METHODS : [ ( & str , usize , SelfKind , OutType , & str ) ; 30 ] = [
2410
+ ( "add" , 2 , SelfKind :: Value , OutType :: Any , "std::ops::Add" ) ,
2411
+ ( "as_mut" , 1 , SelfKind :: RefMut , OutType :: Ref , "std::convert::AsMut" ) ,
2412
+ ( "as_ref" , 1 , SelfKind :: Ref , OutType :: Ref , "std::convert::AsRef" ) ,
2413
+ ( "bitand" , 2 , SelfKind :: Value , OutType :: Any , "std::ops::BitAnd" ) ,
2414
+ ( "bitor" , 2 , SelfKind :: Value , OutType :: Any , "std::ops::BitOr" ) ,
2415
+ ( "bitxor" , 2 , SelfKind :: Value , OutType :: Any , "std::ops::BitXor" ) ,
2416
+ ( "borrow" , 1 , SelfKind :: Ref , OutType :: Ref , "std::borrow::Borrow" ) ,
2417
+ ( "borrow_mut" , 1 , SelfKind :: RefMut , OutType :: Ref , "std::borrow::BorrowMut" ) ,
2418
+ ( "clone" , 1 , SelfKind :: Ref , OutType :: Any , "std::clone::Clone" ) ,
2419
+ ( "cmp" , 2 , SelfKind :: Ref , OutType :: Any , "std::cmp::Ord" ) ,
2420
+ ( "default" , 0 , SelfKind :: No , OutType :: Any , "std::default::Default" ) ,
2421
+ ( "deref" , 1 , SelfKind :: Ref , OutType :: Ref , "std::ops::Deref" ) ,
2422
+ ( "deref_mut" , 1 , SelfKind :: RefMut , OutType :: Ref , "std::ops::DerefMut" ) ,
2423
+ ( "div" , 2 , SelfKind :: Value , OutType :: Any , "std::ops::Div" ) ,
2424
+ ( "drop" , 1 , SelfKind :: RefMut , OutType :: Unit , "std::ops::Drop" ) ,
2425
+ ( "eq" , 2 , SelfKind :: Ref , OutType :: Bool , "std::cmp::PartialEq" ) ,
2426
+ ( "from_iter" , 1 , SelfKind :: No , OutType :: Any , "std::iter::FromIterator" ) ,
2427
+ ( "from_str" , 1 , SelfKind :: No , OutType :: Any , "std::str::FromStr" ) ,
2428
+ ( "hash" , 2 , SelfKind :: Ref , OutType :: Unit , "std::hash::Hash" ) ,
2429
+ ( "index" , 2 , SelfKind :: Ref , OutType :: Ref , "std::ops::Index" ) ,
2430
+ ( "index_mut" , 2 , SelfKind :: RefMut , OutType :: Ref , "std::ops::IndexMut" ) ,
2431
+ ( "into_iter" , 1 , SelfKind :: Value , OutType :: Any , "std::iter::IntoIterator" ) ,
2432
+ ( "mul" , 2 , SelfKind :: Value , OutType :: Any , "std::ops::Mul" ) ,
2433
+ ( "neg" , 1 , SelfKind :: Value , OutType :: Any , "std::ops::Neg" ) ,
2434
+ ( "next" , 1 , SelfKind :: RefMut , OutType :: Any , "std::iter::Iterator" ) ,
2435
+ ( "not" , 1 , SelfKind :: Value , OutType :: Any , "std::ops::Not" ) ,
2436
+ ( "rem" , 2 , SelfKind :: Value , OutType :: Any , "std::ops::Rem" ) ,
2437
+ ( "shl" , 2 , SelfKind :: Value , OutType :: Any , "std::ops::Shl" ) ,
2438
+ ( "shr" , 2 , SelfKind :: Value , OutType :: Any , "std::ops::Shr" ) ,
2439
+ ( "sub" , 2 , SelfKind :: Value , OutType :: Any , "std::ops::Sub" ) ,
2442
2440
] ;
2443
- }
2444
2441
2445
2442
#[ rustfmt:: skip]
2446
- lazy_static ! {
2447
- static ref PATTERN_METHODS : [ ( Symbol , usize ) ; 17 ] = [
2448
- ( sym!( contains) , 1 ) ,
2449
- ( sym!( starts_with) , 1 ) ,
2450
- ( sym!( ends_with) , 1 ) ,
2451
- ( sym!( find) , 1 ) ,
2452
- ( sym!( rfind) , 1 ) ,
2453
- ( sym!( split) , 1 ) ,
2454
- ( sym!( rsplit) , 1 ) ,
2455
- ( sym!( split_terminator) , 1 ) ,
2456
- ( sym!( rsplit_terminator) , 1 ) ,
2457
- ( sym!( splitn) , 2 ) ,
2458
- ( sym!( rsplitn) , 2 ) ,
2459
- ( sym!( matches) , 1 ) ,
2460
- ( sym!( rmatches) , 1 ) ,
2461
- ( sym!( match_indices) , 1 ) ,
2462
- ( sym!( rmatch_indices) , 1 ) ,
2463
- ( sym!( trim_start_matches) , 1 ) ,
2464
- ( sym!( trim_end_matches) , 1 ) ,
2443
+ const PATTERN_METHODS : [ ( & str , usize ) ; 17 ] = [
2444
+ ( "contains" , 1 ) ,
2445
+ ( "starts_with" , 1 ) ,
2446
+ ( "ends_with" , 1 ) ,
2447
+ ( "find" , 1 ) ,
2448
+ ( "rfind" , 1 ) ,
2449
+ ( "split" , 1 ) ,
2450
+ ( "rsplit" , 1 ) ,
2451
+ ( "split_terminator" , 1 ) ,
2452
+ ( "rsplit_terminator" , 1 ) ,
2453
+ ( "splitn" , 2 ) ,
2454
+ ( "rsplitn" , 2 ) ,
2455
+ ( "matches" , 1 ) ,
2456
+ ( "rmatches" , 1 ) ,
2457
+ ( "match_indices" , 1 ) ,
2458
+ ( "rmatch_indices" , 1 ) ,
2459
+ ( "trim_start_matches" , 1 ) ,
2460
+ ( "trim_end_matches" , 1 ) ,
2465
2461
] ;
2466
- }
2467
2462
2468
2463
#[ derive( Clone , Copy , PartialEq , Debug ) ]
2469
2464
enum SelfKind {
0 commit comments