@@ -29,7 +29,7 @@ use rustc_span::Span;
29
29
use smallvec:: { smallvec, SmallVec } ;
30
30
31
31
use rustc_span:: source_map:: { respan, Spanned } ;
32
- use std:: collections:: BTreeSet ;
32
+ use std:: collections:: { hash_map :: Entry , BTreeSet } ;
33
33
use std:: mem:: { replace, take} ;
34
34
use tracing:: debug;
35
35
@@ -953,8 +953,8 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
953
953
} ) ;
954
954
} ;
955
955
956
- for item in trait_items {
957
- this . with_trait_items ( trait_items , |this| {
956
+ this . with_trait_items ( trait_items, |this| {
957
+ for item in trait_items {
958
958
match & item. kind {
959
959
AssocItemKind :: Const ( _, ty, default) => {
960
960
this. visit_ty ( ty) ;
@@ -983,8 +983,8 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
983
983
panic ! ( "unexpanded macro in resolve!" )
984
984
}
985
985
} ;
986
- } ) ;
987
- }
986
+ }
987
+ } ) ;
988
988
} ) ;
989
989
} ) ;
990
990
}
@@ -1060,36 +1060,29 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1060
1060
continue ;
1061
1061
}
1062
1062
1063
- let def_kind = match param. kind {
1064
- GenericParamKind :: Type { .. } => DefKind :: TyParam ,
1065
- GenericParamKind :: Const { .. } => DefKind :: ConstParam ,
1066
- _ => unreachable ! ( ) ,
1067
- } ;
1068
-
1069
1063
let ident = param. ident . normalize_to_macros_2_0 ( ) ;
1070
1064
debug ! ( "with_generic_param_rib: {}" , param. id) ;
1071
1065
1072
- if seen_bindings. contains_key ( & ident) {
1073
- let span = seen_bindings. get ( & ident) . unwrap ( ) ;
1074
- let err = ResolutionError :: NameAlreadyUsedInParameterList ( ident. name , * span) ;
1075
- self . report_error ( param. ident . span , err) ;
1066
+ match seen_bindings. entry ( ident) {
1067
+ Entry :: Occupied ( entry) => {
1068
+ let span = * entry. get ( ) ;
1069
+ let err = ResolutionError :: NameAlreadyUsedInParameterList ( ident. name , span) ;
1070
+ self . report_error ( param. ident . span , err) ;
1071
+ }
1072
+ Entry :: Vacant ( entry) => {
1073
+ entry. insert ( param. ident . span ) ;
1074
+ }
1076
1075
}
1077
- seen_bindings. entry ( ident) . or_insert ( param. ident . span ) ;
1078
1076
1079
1077
// Plain insert (no renaming).
1080
- let res = Res :: Def ( def_kind, self . r . local_def_id ( param. id ) . to_def_id ( ) ) ;
1081
-
1082
- match param. kind {
1083
- GenericParamKind :: Type { .. } => {
1084
- function_type_rib. bindings . insert ( ident, res) ;
1085
- self . r . record_partial_res ( param. id , PartialRes :: new ( res) ) ;
1086
- }
1087
- GenericParamKind :: Const { .. } => {
1088
- function_value_rib. bindings . insert ( ident, res) ;
1089
- self . r . record_partial_res ( param. id , PartialRes :: new ( res) ) ;
1090
- }
1078
+ let ( rib, def_kind) = match param. kind {
1079
+ GenericParamKind :: Type { .. } => ( & mut function_type_rib, DefKind :: TyParam ) ,
1080
+ GenericParamKind :: Const { .. } => ( & mut function_value_rib, DefKind :: ConstParam ) ,
1091
1081
_ => unreachable ! ( ) ,
1092
- }
1082
+ } ;
1083
+ let res = Res :: Def ( def_kind, self . r . local_def_id ( param. id ) . to_def_id ( ) ) ;
1084
+ self . r . record_partial_res ( param. id , PartialRes :: new ( res) ) ;
1085
+ rib. bindings . insert ( ident, res) ;
1093
1086
}
1094
1087
1095
1088
self . ribs [ ValueNS ] . push ( function_value_rib) ;
@@ -1778,7 +1771,6 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1778
1771
path
1779
1772
) ;
1780
1773
let ns = source. namespace ( ) ;
1781
- let is_expected = & |res| source. is_expected ( res) ;
1782
1774
1783
1775
let report_errors = |this : & mut Self , res : Option < Res > | {
1784
1776
if this. should_report_errs ( ) {
@@ -1881,7 +1873,8 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1881
1873
crate_lint,
1882
1874
) {
1883
1875
Ok ( Some ( partial_res) ) if partial_res. unresolved_segments ( ) == 0 => {
1884
- if is_expected ( partial_res. base_res ( ) ) || partial_res. base_res ( ) == Res :: Err {
1876
+ if source. is_expected ( partial_res. base_res ( ) ) || partial_res. base_res ( ) == Res :: Err
1877
+ {
1885
1878
partial_res
1886
1879
} else {
1887
1880
report_errors ( self , Some ( partial_res. base_res ( ) ) )
@@ -1898,11 +1891,11 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1898
1891
self . r . trait_map . insert ( id, traits) ;
1899
1892
}
1900
1893
1901
- let mut std_path = vec ! [ Segment :: from_ident( Ident :: with_dummy_span( sym:: std) ) ] ;
1902
-
1903
- std_path. extend ( path) ;
1904
-
1905
1894
if self . r . primitive_type_table . primitive_types . contains_key ( & path[ 0 ] . ident . name ) {
1895
+ let mut std_path = Vec :: with_capacity ( 1 + path. len ( ) ) ;
1896
+
1897
+ std_path. push ( Segment :: from_ident ( Ident :: with_dummy_span ( sym:: std) ) ) ;
1898
+ std_path. extend ( path) ;
1906
1899
if let PathResult :: Module ( _) | PathResult :: NonModule ( _) =
1907
1900
self . resolve_path ( & std_path, Some ( ns) , false , span, CrateLint :: No )
1908
1901
{
@@ -1983,7 +1976,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1983
1976
) -> Result < Option < PartialRes > , Spanned < ResolutionError < ' a > > > {
1984
1977
let mut fin_res = None ;
1985
1978
1986
- for ( i, ns) in [ primary_ns, TypeNS , ValueNS ] . iter ( ) . cloned ( ) . enumerate ( ) {
1979
+ for ( i, & ns) in [ primary_ns, TypeNS , ValueNS ] . iter ( ) . enumerate ( ) {
1987
1980
if i == 0 || ns != primary_ns {
1988
1981
match self . resolve_qpath ( id, qself, path, ns, span, crate_lint) ? {
1989
1982
Some ( partial_res)
@@ -1993,7 +1986,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1993
1986
}
1994
1987
partial_res => {
1995
1988
if fin_res. is_none ( ) {
1996
- fin_res = partial_res
1989
+ fin_res = partial_res;
1997
1990
}
1998
1991
}
1999
1992
}
0 commit comments