diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2025-02-07 10:57:14 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2025-02-17 09:30:33 +1100 |
| commit | b023671ce2019cdc1768d4acfb148c86ab70183a (patch) | |
| tree | 1a97d7b1eddf25dbcaa4e83bb107cc7b5b8c3c60 /compiler/rustc_pattern_analysis/src/usefulness.rs | |
| parent | 5bc62314547c7639484481f62f218156697cfef0 (diff) | |
| download | rust-b023671ce2019cdc1768d4acfb148c86ab70183a.tar.gz rust-b023671ce2019cdc1768d4acfb148c86ab70183a.zip | |
Add `pattern_complexity_limit` to `Limits`.
It's similar to the other limits, e.g. obtained via `get_limit`. So it makes sense to handle it consistently with the other limits. We now use `Limit`/`usize` in most places instead of `Option<usize>`, so we use `Limit::new(usize::MAX)`/`usize::MAX` to emulate how `None` used to work. The commit also adds `Limit::unlimited`.
Diffstat (limited to 'compiler/rustc_pattern_analysis/src/usefulness.rs')
| -rw-r--r-- | compiler/rustc_pattern_analysis/src/usefulness.rs | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/compiler/rustc_pattern_analysis/src/usefulness.rs b/compiler/rustc_pattern_analysis/src/usefulness.rs index cc09cd491af..1dff76141da 100644 --- a/compiler/rustc_pattern_analysis/src/usefulness.rs +++ b/compiler/rustc_pattern_analysis/src/usefulness.rs @@ -795,20 +795,21 @@ struct UsefulnessCtxt<'a, 'p, Cx: PatCx> { /// Track information about the usefulness of branch patterns (see definition of "branch /// pattern" at [`BranchPatUsefulness`]). branch_usefulness: FxHashMap<PatId, BranchPatUsefulness<'p, Cx>>, - complexity_limit: Option<usize>, + // Ideally this field would have type `Limit`, but this crate is used by + // rust-analyzer which cannot have a dependency on `Limit`, because `Limit` + // is from crate `rustc_session` which uses unstable Rust features. + complexity_limit: usize, complexity_level: usize, } impl<'a, 'p, Cx: PatCx> UsefulnessCtxt<'a, 'p, Cx> { fn increase_complexity_level(&mut self, complexity_add: usize) -> Result<(), Cx::Error> { self.complexity_level += complexity_add; - if self - .complexity_limit - .is_some_and(|complexity_limit| complexity_limit < self.complexity_level) - { - return self.tycx.complexity_exceeded(); + if self.complexity_level <= self.complexity_limit { + Ok(()) + } else { + self.tycx.complexity_exceeded() } - Ok(()) } } @@ -1834,7 +1835,7 @@ pub fn compute_match_usefulness<'p, Cx: PatCx>( arms: &[MatchArm<'p, Cx>], scrut_ty: Cx::Ty, scrut_validity: PlaceValidity, - complexity_limit: Option<usize>, + complexity_limit: usize, ) -> Result<UsefulnessReport<'p, Cx>, Cx::Error> { let mut cx = UsefulnessCtxt { tycx, |
