@@ -1633,19 +1633,17 @@ impl<'a, 'crateloader> Resolver<'a, 'crateloader> {
1633
1633
* def = module. def ( ) . unwrap ( ) ,
1634
1634
PathResult :: NonModule ( path_res) if path_res. unresolved_segments ( ) == 0 =>
1635
1635
* def = path_res. base_def ( ) ,
1636
- PathResult :: NonModule ( ..) => match self . resolve_path (
1637
- None ,
1638
- & path ,
1639
- None ,
1640
- true ,
1641
- span ,
1642
- CrateLint :: No ,
1643
- ) {
1644
- PathResult :: Failed ( span , msg , _ ) => {
1636
+ PathResult :: NonModule ( ..) =>
1637
+ if let PathResult :: Failed ( span , msg , _ ) = self . resolve_path (
1638
+ None ,
1639
+ & path ,
1640
+ None ,
1641
+ true ,
1642
+ span ,
1643
+ CrateLint :: No ,
1644
+ ) {
1645
1645
error_callback ( self , span, ResolutionError :: FailedToResolve ( & msg) ) ;
1646
- }
1647
- _ => { }
1648
- } ,
1646
+ } ,
1649
1647
PathResult :: Module ( ModuleOrUniformRoot :: UniformRoot ( _) ) |
1650
1648
PathResult :: Indeterminate => unreachable ! ( ) ,
1651
1649
PathResult :: Failed ( span, msg, _) => {
@@ -2357,7 +2355,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
2357
2355
span : prefix. span . to ( use_tree. prefix . span ) ,
2358
2356
} ;
2359
2357
2360
- if items. len ( ) == 0 {
2358
+ if items. is_empty ( ) {
2361
2359
// Resolve prefix of an import with empty braces (issue #28388).
2362
2360
self . smart_resolve_path_with_crate_lint (
2363
2361
id,
@@ -2696,7 +2694,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
2696
2694
2697
2695
let map_j = self . binding_mode_map ( & q) ;
2698
2696
for ( & key, & binding_i) in & map_i {
2699
- if map_j. len ( ) == 0 { // Account for missing bindings when
2697
+ if map_j. is_empty ( ) { // Account for missing bindings when
2700
2698
let binding_error = missing_vars // map_j has none.
2701
2699
. entry ( key. name )
2702
2700
. or_insert ( BindingError {
@@ -2757,9 +2755,8 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
2757
2755
// This has to happen *after* we determine which pat_idents are variants
2758
2756
self . check_consistent_bindings ( & arm. pats ) ;
2759
2757
2760
- match arm. guard {
2761
- Some ( ast:: Guard :: If ( ref expr) ) => self . visit_expr ( expr) ,
2762
- _ => { }
2758
+ if let Some ( ast:: Guard :: If ( ref expr) ) = arm. guard {
2759
+ self . visit_expr ( expr)
2763
2760
}
2764
2761
self . visit_expr ( & arm. body ) ;
2765
2762
@@ -3000,14 +2997,14 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
3000
2997
// Make the base error.
3001
2998
let expected = source. descr_expected ( ) ;
3002
2999
let path_str = names_to_string ( path) ;
3003
- let item_str = path[ path . len ( ) - 1 ] ;
3000
+ let item_str = path. last ( ) . unwrap ( ) ;
3004
3001
let code = source. error_code ( def. is_some ( ) ) ;
3005
3002
let ( base_msg, fallback_label, base_span) = if let Some ( def) = def {
3006
3003
( format ! ( "expected {}, found {} `{}`" , expected, def. kind_name( ) , path_str) ,
3007
3004
format ! ( "not a {}" , expected) ,
3008
3005
span)
3009
3006
} else {
3010
- let item_span = path[ path . len ( ) - 1 ] . span ;
3007
+ let item_span = path. last ( ) . unwrap ( ) . span ;
3011
3008
let ( mod_prefix, mod_str) = if path. len ( ) == 1 {
3012
3009
( String :: new ( ) , "this scope" . to_string ( ) )
3013
3010
} else if path. len ( ) == 2 && path[ 0 ] . name == keywords:: CrateRoot . name ( ) {
@@ -3030,10 +3027,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
3030
3027
let mut err = this. session . struct_span_err_with_code ( base_span, & base_msg, code) ;
3031
3028
3032
3029
// Emit help message for fake-self from other languages like `this`(javascript)
3033
- let fake_self: Vec < Ident > = [ "this" , "my" ] . iter ( ) . map (
3034
- |s| Ident :: from_str ( * s)
3035
- ) . collect ( ) ;
3036
- if fake_self. contains ( & item_str)
3030
+ if [ "this" , "my" ] . contains ( & & * item_str. as_str ( ) )
3037
3031
&& this. self_value_is_available ( path[ 0 ] . span , span) {
3038
3032
err. span_suggestion_with_applicability (
3039
3033
span,
@@ -3374,7 +3368,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
3374
3368
) ;
3375
3369
}
3376
3370
break ;
3377
- } else if snippet. trim ( ) . len ( ) != 0 {
3371
+ } else if ! snippet. trim ( ) . is_empty ( ) {
3378
3372
debug ! ( "tried to find type ascription `:` token, couldn't find it" ) ;
3379
3373
break ;
3380
3374
}
@@ -3936,7 +3930,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
3936
3930
}
3937
3931
_ => { }
3938
3932
}
3939
- return def;
3933
+ def
3940
3934
}
3941
3935
3942
3936
fn lookup_assoc_candidate < FilterFn > ( & mut self ,
@@ -4386,10 +4380,9 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
4386
4380
where FilterFn : Fn ( Def ) -> bool
4387
4381
{
4388
4382
let mut candidates = Vec :: new ( ) ;
4389
- let mut worklist = Vec :: new ( ) ;
4390
4383
let mut seen_modules = FxHashSet ( ) ;
4391
4384
let not_local_module = crate_name != keywords:: Crate . ident ( ) ;
4392
- worklist. push ( ( start_module, Vec :: < ast:: PathSegment > :: new ( ) , not_local_module) ) ;
4385
+ let mut worklist = vec ! [ ( start_module, Vec :: <ast:: PathSegment >:: new( ) , not_local_module) ] ;
4393
4386
4394
4387
while let Some ( ( in_module,
4395
4388
path_segments,
@@ -4476,33 +4469,24 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
4476
4469
-> Vec < ImportSuggestion >
4477
4470
where FilterFn : Fn ( Def ) -> bool
4478
4471
{
4479
- let mut suggestions = vec ! [ ] ;
4480
-
4481
- suggestions. extend (
4482
- self . lookup_import_candidates_from_module (
4483
- lookup_name, namespace, self . graph_root , keywords:: Crate . ident ( ) , & filter_fn
4484
- )
4485
- ) ;
4472
+ let mut suggestions = self . lookup_import_candidates_from_module (
4473
+ lookup_name, namespace, self . graph_root , keywords:: Crate . ident ( ) , & filter_fn) ;
4486
4474
4487
4475
if self . session . rust_2018 ( ) {
4488
4476
let extern_prelude_names = self . extern_prelude . clone ( ) ;
4489
4477
for & name in extern_prelude_names. iter ( ) {
4490
4478
let ident = Ident :: with_empty_ctxt ( name) ;
4491
- match self . crate_loader . maybe_process_path_extern ( name, ident. span ) {
4492
- Some ( crate_id) => {
4493
- let crate_root = self . get_module ( DefId {
4494
- krate : crate_id,
4495
- index : CRATE_DEF_INDEX ,
4496
- } ) ;
4497
- self . populate_module_if_necessary ( & crate_root) ;
4479
+ if let Some ( crate_id) = self . crate_loader . maybe_process_path_extern ( name,
4480
+ ident. span )
4481
+ {
4482
+ let crate_root = self . get_module ( DefId {
4483
+ krate : crate_id,
4484
+ index : CRATE_DEF_INDEX ,
4485
+ } ) ;
4486
+ self . populate_module_if_necessary ( & crate_root) ;
4498
4487
4499
- suggestions. extend (
4500
- self . lookup_import_candidates_from_module (
4501
- lookup_name, namespace, crate_root, ident, & filter_fn
4502
- )
4503
- ) ;
4504
- }
4505
- None => { }
4488
+ suggestions. extend ( self . lookup_import_candidates_from_module (
4489
+ lookup_name, namespace, crate_root, ident, & filter_fn) ) ;
4506
4490
}
4507
4491
}
4508
4492
}
@@ -4515,9 +4499,8 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
4515
4499
-> Option < ( Module < ' a > , ImportSuggestion ) >
4516
4500
{
4517
4501
let mut result = None ;
4518
- let mut worklist = Vec :: new ( ) ;
4519
4502
let mut seen_modules = FxHashSet ( ) ;
4520
- worklist. push ( ( self . graph_root , Vec :: new ( ) ) ) ;
4503
+ let mut worklist = vec ! [ ( self . graph_root, Vec :: new( ) ) ] ;
4521
4504
4522
4505
while let Some ( ( in_module, path_segments) ) = worklist. pop ( ) {
4523
4506
// abort if the module is already found
0 commit comments