@@ -1714,9 +1714,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1714
1714
match self . resolve_crate_relative_path ( prefix. span ,
1715
1715
& prefix. segments ,
1716
1716
TypeNS ) {
1717
- Some ( def) =>
1717
+ Ok ( def) =>
1718
1718
self . record_def ( item. id , PathResolution :: new ( def, 0 ) ) ,
1719
- None => {
1719
+ Err ( true ) => self . record_def ( item. id , err_path_resolution ( ) ) ,
1720
+ Err ( false ) => {
1720
1721
resolve_error ( self ,
1721
1722
prefix. span ,
1722
1723
ResolutionError :: FailedToResolve (
@@ -1835,7 +1836,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1835
1836
trait_path : & Path ,
1836
1837
path_depth : usize )
1837
1838
-> Result < PathResolution , ( ) > {
1838
- if let Some ( path_res ) = self . resolve_path ( id, trait_path, path_depth, TypeNS ) {
1839
+ self . resolve_path ( id, trait_path, path_depth, TypeNS ) . and_then ( |path_res| {
1839
1840
if let Def :: Trait ( _) = path_res. base_def {
1840
1841
debug ! ( "(resolving trait) found trait def: {:?}" , path_res) ;
1841
1842
Ok ( path_res)
@@ -1855,9 +1856,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1855
1856
}
1856
1857
}
1857
1858
err. emit ( ) ;
1858
- Err ( ( ) )
1859
+ Err ( true )
1859
1860
}
1860
- } else {
1861
+ } ) . map_err ( |error_reported| {
1862
+ if error_reported { return }
1861
1863
1862
1864
// find possible candidates
1863
1865
let trait_name = trait_path. segments . last ( ) . unwrap ( ) . identifier . name ;
@@ -1880,8 +1882,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1880
1882
) ;
1881
1883
1882
1884
resolve_error ( self , trait_path. span , error) ;
1883
- Err ( ( ) )
1884
- }
1885
+ } )
1885
1886
}
1886
1887
1887
1888
fn resolve_generics ( & mut self , generics : & Generics ) {
@@ -1890,15 +1891,18 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
1890
1891
& hir:: WherePredicate :: BoundPredicate ( _) |
1891
1892
& hir:: WherePredicate :: RegionPredicate ( _) => { }
1892
1893
& hir:: WherePredicate :: EqPredicate ( ref eq_pred) => {
1893
- let path_res = self . resolve_path ( eq_pred. id , & eq_pred. path , 0 , TypeNS ) ;
1894
- if let Some ( PathResolution { base_def : Def :: TyParam ( ..) , .. } ) = path_res {
1895
- self . record_def ( eq_pred. id , path_res. unwrap ( ) ) ;
1896
- } else {
1897
- resolve_error ( self ,
1898
- eq_pred . span ,
1899
- ResolutionError :: UndeclaredAssociatedType ) ;
1894
+ self . resolve_path ( eq_pred. id , & eq_pred. path , 0 , TypeNS ) . and_then ( |path_res| {
1895
+ if let PathResolution { base_def : Def :: TyParam ( ..) , .. } = path_res {
1896
+ Ok ( self . record_def ( eq_pred. id , path_res) )
1897
+ } else {
1898
+ Err ( false )
1899
+ }
1900
+ } ) . map_err ( |error_reported| {
1900
1901
self . record_def ( eq_pred. id , err_path_resolution ( ) ) ;
1901
- }
1902
+ if error_reported { return }
1903
+ let error_variant = ResolutionError :: UndeclaredAssociatedType ;
1904
+ resolve_error ( self , eq_pred. span , error_variant) ;
1905
+ } ) . unwrap_or ( ( ) ) ;
1902
1906
}
1903
1907
}
1904
1908
}
@@ -2168,21 +2172,18 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2168
2172
2169
2173
// This is a path in the type namespace. Walk through scopes
2170
2174
// looking for it.
2171
- match resolution {
2172
- Some ( def) => {
2173
- // Write the result into the def map.
2174
- debug ! ( "(resolving type) writing resolution for `{}` (id {}) = {:?}" ,
2175
- path_names_to_string( path, 0 ) ,
2176
- ty. id,
2177
- def) ;
2178
- self . record_def ( ty. id , def) ;
2179
- }
2180
- None => {
2181
- self . record_def ( ty. id , err_path_resolution ( ) ) ;
2182
-
2183
- // Keep reporting some errors even if they're ignored above.
2184
- self . resolve_path ( ty. id , path, 0 , TypeNS ) ;
2175
+ if let Some ( def) = resolution {
2176
+ // Write the result into the def map.
2177
+ debug ! ( "(resolving type) writing resolution for `{}` (id {}) = {:?}" ,
2178
+ path_names_to_string( path, 0 ) , ty. id, def) ;
2179
+ self . record_def ( ty. id , def) ;
2180
+ } else {
2181
+ self . record_def ( ty. id , err_path_resolution ( ) ) ;
2185
2182
2183
+ // Keep reporting some errors even if they're ignored above.
2184
+ if let Err ( true ) = self . resolve_path ( ty. id , path, 0 , TypeNS ) {
2185
+ // `resolve_path` already reported the error
2186
+ } else {
2186
2187
let kind = if maybe_qself. is_some ( ) {
2187
2188
"associated type"
2188
2189
} else {
@@ -2481,11 +2482,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2481
2482
2482
2483
PatKind :: Struct ( ref path, _, _) => {
2483
2484
match self . resolve_path ( pat_id, path, 0 , TypeNS ) {
2484
- Some ( definition) => {
2485
+ Ok ( definition) => {
2485
2486
self . record_def ( pattern. id , definition) ;
2486
2487
}
2487
- result => {
2488
- debug ! ( "(resolving pattern) didn't find struct def: {:?}" , result ) ;
2488
+ Err ( true ) => self . record_def ( pattern . id , err_path_resolution ( ) ) ,
2489
+ Err ( false ) => {
2489
2490
resolve_error (
2490
2491
self ,
2491
2492
path. span ,
@@ -2552,14 +2553,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2552
2553
}
2553
2554
2554
2555
let mut resolution = self . with_no_errors ( |this| {
2555
- this. resolve_path ( id, path, 0 , namespace)
2556
+ this. resolve_path ( id, path, 0 , namespace) . ok ( )
2556
2557
} ) ;
2557
2558
for depth in 1 ..max_assoc_types {
2558
2559
if resolution. is_some ( ) {
2559
2560
break ;
2560
2561
}
2561
2562
self . with_no_errors ( |this| {
2562
- resolution = this. resolve_path ( id, path, depth, TypeNS ) ;
2563
+ resolution = this. resolve_path ( id, path, depth, TypeNS ) . ok ( ) ;
2563
2564
} ) ;
2564
2565
}
2565
2566
if let Some ( Def :: Mod ( _) ) = resolution. map ( |r| r. base_def ) {
@@ -2572,7 +2573,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2572
2573
/// Skips `path_depth` trailing segments, which is also reflected in the
2573
2574
/// returned value. See `hir::def::PathResolution` for more info.
2574
2575
fn resolve_path ( & mut self , id : NodeId , path : & Path , path_depth : usize , namespace : Namespace )
2575
- -> Option < PathResolution > {
2576
+ -> Result < PathResolution , bool /* true if an error was reported */ > {
2576
2577
let span = path. span ;
2577
2578
let segments = & path. segments [ ..path. segments . len ( ) - path_depth] ;
2578
2579
@@ -2611,14 +2612,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2611
2612
//
2612
2613
// Such behavior is required for backward compatibility.
2613
2614
// The same fallback is used when `a` resolves to nothing.
2614
- let unqualified_def = resolve_identifier_with_fallback ( self , true ) ;
2615
- return unqualified_def . and_then ( |def| self . adjust_local_def ( def, span) ) . map ( mk_res) ;
2615
+ let def = resolve_identifier_with_fallback ( self , true ) . ok_or ( false ) ;
2616
+ return def . and_then ( |def| self . adjust_local_def ( def, span) . ok_or ( true ) ) . map ( mk_res) ;
2616
2617
}
2617
2618
2618
2619
let unqualified_def = resolve_identifier_with_fallback ( self , false ) ;
2619
2620
let def = self . resolve_module_relative_path ( span, segments, namespace) ;
2620
2621
match ( def, unqualified_def) {
2621
- ( Some ( d) , Some ( ref ud) ) if d == ud. def => {
2622
+ ( Ok ( d) , Some ( ref ud) ) if d == ud. def => {
2622
2623
self . session
2623
2624
. add_lint ( lint:: builtin:: UNUSED_QUALIFICATIONS ,
2624
2625
id,
@@ -2739,7 +2740,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2739
2740
span : Span ,
2740
2741
segments : & [ hir:: PathSegment ] ,
2741
2742
namespace : Namespace )
2742
- -> Option < Def > {
2743
+ -> Result < Def , bool /* true if an error was reported */ > {
2743
2744
let module_path = segments. split_last ( )
2744
2745
. unwrap ( )
2745
2746
. 1
@@ -2760,9 +2761,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2760
2761
} ;
2761
2762
2762
2763
resolve_error ( self , span, ResolutionError :: FailedToResolve ( & msg) ) ;
2763
- return None ;
2764
+ return Err ( true ) ;
2764
2765
}
2765
- Indeterminate => return None ,
2766
+ Indeterminate => return Err ( false ) ,
2766
2767
Success ( resulting_module) => {
2767
2768
containing_module = resulting_module;
2768
2769
}
@@ -2773,7 +2774,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2773
2774
result. success ( ) . map ( |binding| {
2774
2775
self . check_privacy ( containing_module, name, binding, span) ;
2775
2776
binding. def ( ) . unwrap ( )
2776
- } )
2777
+ } ) . ok_or ( false )
2777
2778
}
2778
2779
2779
2780
/// Invariant: This must be called only during main resolution, not during
@@ -2782,7 +2783,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2782
2783
span : Span ,
2783
2784
segments : & [ hir:: PathSegment ] ,
2784
2785
namespace : Namespace )
2785
- -> Option < Def > {
2786
+ -> Result < Def , bool /* true if an error was reported */ > {
2786
2787
let module_path = segments. split_last ( )
2787
2788
. unwrap ( )
2788
2789
. 1
@@ -2808,10 +2809,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2808
2809
} ;
2809
2810
2810
2811
resolve_error ( self , span, ResolutionError :: FailedToResolve ( & msg) ) ;
2811
- return None ;
2812
+ return Err ( true ) ;
2812
2813
}
2813
2814
2814
- Indeterminate => return None ,
2815
+ Indeterminate => return Err ( false ) ,
2815
2816
2816
2817
Success ( resulting_module) => {
2817
2818
containing_module = resulting_module;
@@ -2823,7 +2824,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2823
2824
result. success ( ) . map ( |binding| {
2824
2825
self . check_privacy ( containing_module, name, binding, span) ;
2825
2826
binding. def ( ) . unwrap ( )
2826
- } )
2827
+ } ) . ok_or ( false )
2827
2828
}
2828
2829
2829
2830
fn with_no_errors < T , F > ( & mut self , f : F ) -> T
@@ -3038,25 +3039,26 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
3038
3039
} ) ;
3039
3040
3040
3041
self . record_def ( expr. id , err_path_resolution ( ) ) ;
3041
- match type_res. map ( |r| r. base_def ) {
3042
- Some ( Def :: Struct ( ..) ) => {
3043
- let mut err = resolve_struct_error ( self ,
3044
- expr. span ,
3045
- ResolutionError :: StructVariantUsedAsFunction ( & path_name) ) ;
3046
-
3047
- let msg = format ! ( "did you mean to write: `{} {{ /* fields */ }}`?" ,
3048
- path_name) ;
3049
- if self . emit_errors {
3050
- err. fileline_help ( expr. span , & msg) ;
3051
- } else {
3052
- err. span_help ( expr. span , & msg) ;
3053
- }
3054
- err. emit ( ) ;
3055
- }
3056
- _ => {
3057
- // Keep reporting some errors even if they're ignored above.
3058
- self . resolve_path ( expr. id , path, 0 , ValueNS ) ;
3059
3042
3043
+ if let Ok ( Def :: Struct ( ..) ) = type_res. map ( |r| r. base_def ) {
3044
+ let error_variant =
3045
+ ResolutionError :: StructVariantUsedAsFunction ( & path_name) ;
3046
+ let mut err = resolve_struct_error ( self , expr. span , error_variant) ;
3047
+
3048
+ let msg = format ! ( "did you mean to write: `{} {{ /* fields */ }}`?" ,
3049
+ path_name) ;
3050
+
3051
+ if self . emit_errors {
3052
+ err. fileline_help ( expr. span , & msg) ;
3053
+ } else {
3054
+ err. span_help ( expr. span , & msg) ;
3055
+ }
3056
+ err. emit ( ) ;
3057
+ } else {
3058
+ // Keep reporting some errors even if they're ignored above.
3059
+ if let Err ( true ) = self . resolve_path ( expr. id , path, 0 , ValueNS ) {
3060
+ // `resolve_path` already reported the error
3061
+ } else {
3060
3062
let mut method_scope = false ;
3061
3063
self . value_ribs . iter ( ) . rev ( ) . all ( |rib| {
3062
3064
method_scope = match rib. kind {
@@ -3130,8 +3132,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
3130
3132
// check to ensure that the path is actually a structure; that
3131
3133
// is checked later during typeck.
3132
3134
match self . resolve_path ( expr. id , path, 0 , TypeNS ) {
3133
- Some ( definition) => self . record_def ( expr. id , definition) ,
3134
- None => {
3135
+ Ok ( definition) => self . record_def ( expr. id , definition) ,
3136
+ Err ( true ) => self . record_def ( expr. id , err_path_resolution ( ) ) ,
3137
+ Err ( false ) => {
3135
3138
debug ! ( "(resolving expression) didn't find struct def" , ) ;
3136
3139
3137
3140
resolve_error ( self ,
0 commit comments