diff options
| author | Nadrieril <nadrieril+git@gmail.com> | 2024-01-09 17:04:20 +0100 |
|---|---|---|
| committer | Nadrieril <nadrieril+git@gmail.com> | 2024-01-09 17:06:14 +0100 |
| commit | 223cda41071416c20d3d1db458ce7c6c789e2b08 (patch) | |
| tree | c01fbc17744f3ad61458c5b839d5eed62c7e52fe | |
| parent | 807d618676052befa3e621dc42e7be0b4c5f1576 (diff) | |
| download | rust-223cda41071416c20d3d1db458ce7c6c789e2b08.tar.gz rust-223cda41071416c20d3d1db458ce7c6c789e2b08.zip | |
Use `Result<_, IsNeverPattern>` consistently
| -rw-r--r-- | compiler/rustc_resolve/src/late.rs | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 2a8bf1fe2d3..5c246893d87 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -3213,9 +3213,10 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { PatKind::Or(ref ps) => { // Check the consistency of this or-pattern and // then add all bindings to the larger map. - let (bm, np) = self.compute_and_check_or_pat_binding_map(ps); - binding_map.extend(bm); - is_never_pat |= np; + match self.compute_and_check_or_pat_binding_map(ps) { + Ok(bm) => binding_map.extend(bm), + Err(IsNeverPattern) => is_never_pat = true, + } return false; } PatKind::Never => is_never_pat = true, @@ -3249,7 +3250,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { fn compute_and_check_or_pat_binding_map( &mut self, pats: &[P<Pat>], - ) -> (FxIndexMap<Ident, BindingInfo>, bool) { + ) -> Result<FxIndexMap<Ident, BindingInfo>, IsNeverPattern> { let mut missing_vars = FxIndexMap::default(); let mut inconsistent_vars = FxIndexMap::default(); @@ -3314,12 +3315,16 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { } // 5) Bubble up the final binding map. - let is_never_pat = not_never_pats.is_empty(); - let mut binding_map = FxIndexMap::default(); - for (bm, _) in not_never_pats { - binding_map.extend(bm); + if not_never_pats.is_empty() { + // All the patterns are never patterns, so the whole or-pattern is one too. + Err(IsNeverPattern) + } else { + let mut binding_map = FxIndexMap::default(); + for (bm, _) in not_never_pats { + binding_map.extend(bm); + } + Ok(binding_map) } - (binding_map, is_never_pat) } /// Check the consistency of bindings wrt or-patterns and never patterns. |
