@@ -459,7 +459,7 @@ fn resolve_struct_error<'b, 'a: 'b, 'c>(resolver: &'b Resolver<'a>,
459
459
err
460
460
}
461
461
ResolutionError :: BindingShadowsSomethingUnacceptable ( what_binding, name, binding) => {
462
- let shadows_what = PathResolution :: new ( binding. def ( ) . unwrap ( ) ) . kind_name ( ) ;
462
+ let shadows_what = PathResolution :: new ( binding. def ( ) ) . kind_name ( ) ;
463
463
let mut err = struct_span_err ! ( resolver. session,
464
464
span,
465
465
E0530 ,
@@ -739,7 +739,7 @@ impl<'a> LexicalScopeBinding<'a> {
739
739
fn local_def ( self ) -> LocalDef {
740
740
match self {
741
741
LexicalScopeBinding :: LocalDef ( local_def) => local_def,
742
- LexicalScopeBinding :: Item ( binding) => LocalDef :: from_def ( binding. def ( ) . unwrap ( ) ) ,
742
+ LexicalScopeBinding :: Item ( binding) => LocalDef :: from_def ( binding. def ( ) ) ,
743
743
}
744
744
}
745
745
@@ -877,10 +877,10 @@ impl<'a> NameBinding<'a> {
877
877
}
878
878
}
879
879
880
- fn def ( & self ) -> Option < Def > {
880
+ fn def ( & self ) -> Def {
881
881
match self . kind {
882
- NameBindingKind :: Def ( def) => Some ( def) ,
883
- NameBindingKind :: Module ( module) => module. def ,
882
+ NameBindingKind :: Def ( def) => def,
883
+ NameBindingKind :: Module ( module) => module. def . unwrap ( ) ,
884
884
NameBindingKind :: Import { binding, .. } => binding. def ( ) ,
885
885
}
886
886
}
@@ -916,7 +916,7 @@ impl<'a> NameBinding<'a> {
916
916
}
917
917
918
918
fn is_importable ( & self ) -> bool {
919
- match self . def ( ) . unwrap ( ) {
919
+ match self . def ( ) {
920
920
Def :: AssociatedConst ( ..) | Def :: Method ( ..) | Def :: AssociatedTy ( ..) => false ,
921
921
_ => true ,
922
922
}
@@ -1097,7 +1097,7 @@ impl<'a> hir::lowering::Resolver for Resolver<'a> {
1097
1097
fn resolve_generated_global_path ( & mut self , path : & hir:: Path , is_value : bool ) -> Def {
1098
1098
let namespace = if is_value { ValueNS } else { TypeNS } ;
1099
1099
match self . resolve_crate_relative_path ( path. span , & path. segments , namespace) {
1100
- Ok ( binding) => binding. def ( ) . unwrap ( ) ,
1100
+ Ok ( binding) => binding. def ( ) ,
1101
1101
Err ( true ) => Def :: Err ,
1102
1102
Err ( false ) => {
1103
1103
let path_name = & format ! ( "{}" , path) ;
@@ -1693,7 +1693,7 @@ impl<'a> Resolver<'a> {
1693
1693
& prefix. segments ,
1694
1694
TypeNS ) {
1695
1695
Ok ( binding) => {
1696
- let def = binding. def ( ) . unwrap ( ) ;
1696
+ let def = binding. def ( ) ;
1697
1697
self . record_def ( item. id , PathResolution :: new ( def) ) ;
1698
1698
}
1699
1699
Err ( true ) => self . record_def ( item. id , err_path_resolution ( ) ) ,
@@ -2309,7 +2309,7 @@ impl<'a> Resolver<'a> {
2309
2309
// entity, then fall back to a fresh binding.
2310
2310
let binding = self . resolve_ident_in_lexical_scope ( ident. node , ValueNS , None )
2311
2311
. and_then ( LexicalScopeBinding :: item) ;
2312
- let resolution = binding. and_then ( NameBinding :: def) . and_then ( |def| {
2312
+ let resolution = binding. map ( NameBinding :: def) . and_then ( |def| {
2313
2313
let always_binding = !pat_src. is_refutable ( ) || opt_pat. is_some ( ) ||
2314
2314
bmode != BindingMode :: ByValue ( Mutability :: Immutable ) ;
2315
2315
match def {
@@ -2443,7 +2443,7 @@ impl<'a> Resolver<'a> {
2443
2443
2444
2444
if path. global {
2445
2445
let binding = self . resolve_crate_relative_path ( span, segments, namespace) ;
2446
- return binding. map ( |binding| mk_res ( binding. def ( ) . unwrap ( ) ) ) ;
2446
+ return binding. map ( |binding| mk_res ( binding. def ( ) ) ) ;
2447
2447
}
2448
2448
2449
2449
// Try to find a path to an item in a module.
@@ -2481,7 +2481,7 @@ impl<'a> Resolver<'a> {
2481
2481
let unqualified_def = resolve_identifier_with_fallback ( self , None ) ;
2482
2482
let qualified_binding = self . resolve_module_relative_path ( span, segments, namespace) ;
2483
2483
match ( qualified_binding, unqualified_def) {
2484
- ( Ok ( binding) , Some ( ref ud) ) if binding. def ( ) . unwrap ( ) == ud. def => {
2484
+ ( Ok ( binding) , Some ( ref ud) ) if binding. def ( ) == ud. def => {
2485
2485
self . session
2486
2486
. add_lint ( lint:: builtin:: UNUSED_QUALIFICATIONS ,
2487
2487
id,
@@ -2491,7 +2491,7 @@ impl<'a> Resolver<'a> {
2491
2491
_ => { }
2492
2492
}
2493
2493
2494
- qualified_binding. map ( |binding| mk_res ( binding. def ( ) . unwrap ( ) ) )
2494
+ qualified_binding. map ( |binding| mk_res ( binding. def ( ) ) )
2495
2495
}
2496
2496
2497
2497
// Resolve a single identifier
@@ -3114,15 +3114,15 @@ impl<'a> Resolver<'a> {
3114
3114
let mut collected_traits = Vec :: new ( ) ;
3115
3115
module. for_each_child ( |name, ns, binding| {
3116
3116
if ns != TypeNS { return }
3117
- if let Some ( Def :: Trait ( _) ) = binding. def ( ) {
3117
+ if let Def :: Trait ( _) = binding. def ( ) {
3118
3118
collected_traits. push ( ( name, binding) ) ;
3119
3119
}
3120
3120
} ) ;
3121
3121
* traits = Some ( collected_traits. into_boxed_slice ( ) ) ;
3122
3122
}
3123
3123
3124
3124
for & ( trait_name, binding) in traits. as_ref ( ) . unwrap ( ) . iter ( ) {
3125
- let trait_def_id = binding. def ( ) . unwrap ( ) . def_id ( ) ;
3125
+ let trait_def_id = binding. def ( ) . def_id ( ) ;
3126
3126
if this. trait_item_map . contains_key ( & ( name, trait_def_id) ) {
3127
3127
let mut import_id = None ;
3128
3128
if let NameBindingKind :: Import { directive, .. } = binding. kind {
@@ -3181,8 +3181,8 @@ impl<'a> Resolver<'a> {
3181
3181
if name_binding. is_import ( ) { return ; }
3182
3182
3183
3183
// collect results based on the filter function
3184
- if let Some ( def ) = name_binding . def ( ) {
3185
- if name == lookup_name && ns == namespace && filter_fn ( def) {
3184
+ if name == lookup_name && ns == namespace {
3185
+ if filter_fn ( name_binding . def ( ) ) {
3186
3186
// create the path
3187
3187
let ident = ast:: Ident :: with_empty_ctxt ( name) ;
3188
3188
let params = PathParameters :: none ( ) ;
@@ -3302,7 +3302,7 @@ impl<'a> Resolver<'a> {
3302
3302
let msg = format ! ( "extern crate `{}` is private" , name) ;
3303
3303
self . session . add_lint ( lint:: builtin:: INACCESSIBLE_EXTERN_CRATE , node_id, span, msg) ;
3304
3304
} else {
3305
- let def = binding. def ( ) . unwrap ( ) ;
3305
+ let def = binding. def ( ) ;
3306
3306
self . session . span_err ( span, & format ! ( "{} `{}` is private" , def. kind_name( ) , name) ) ;
3307
3307
}
3308
3308
}
0 commit comments