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