Skip to content

Commit a878871

Browse files
committed
bugfix 2/2
1 parent 52cf5fc commit a878871

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,8 @@ codegen-units = 1
9393
# FIXME: LTO cannot be enabled for binaries in a workspace
9494
# <https://github.com/rust-lang/cargo/issues/9330>
9595
# lto = true
96+
97+
[profile.release.package.rustc_mir_build]
98+
opt-level = 1
99+
[profile.release.package.rustc_driver]
100+
opt-level = 1

compiler/rustc_mir_build/src/builder/matches/match_pair.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
use std::ops;
2+
13
use either::Either;
24
use rustc_middle::mir::*;
35
use rustc_middle::thir::{self, *};
46
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
5-
use std::ops;
67

78
use crate::builder::Builder;
89
use crate::builder::expr::as_place::{PlaceBase, PlaceBuilder};
@@ -58,9 +59,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
5859
((prefix.len() + suffix.len()).try_into().unwrap(), false)
5960
};
6061

61-
tracing::warn!("Builder::prefix_slice_suffix: min_length: {}, exact_size: {} -> {:?}", min_length, exact_size, top_pattern);
62-
tracing::warn!("prefix: {:?}, suffix: {:?}", prefix.len(), suffix.len());
63-
6462
if !prefix.is_empty() {
6563
let bounds = Range::from_start(0..prefix.len() as u64);
6664
let subpattern = bounds.apply(prefix);
@@ -110,7 +108,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
110108
};
111109

112110
match entry {
113-
Either::Right(range) if range.end-range.start > 1 => {
111+
Either::Right(range) if range.end - range.start > 1 => {
114112
assert!(
115113
(range.start..range.end)
116114
.all(|idx| self.is_constant_pattern(&pattern[idx as usize]))
@@ -126,7 +124,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
126124
place.clone(),
127125
elem_ty,
128126
bounds.shift_range(range),
129-
true, // TODO: set false if only branch and only entry
127+
true, // TODO: set false if only branch and only entry
130128
)
131129
}
132130
Either::Right(range) => {
@@ -143,26 +141,26 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
143141
let mut entries = Vec::new();
144142
let mut current_seq_start = None;
145143

146-
let mut apply = |state: &mut _, idx, b: bool| {
147-
if let Some(start) = *state {
148-
*state = None;
149-
entries.push(Either::Right(start..idx));
150-
} else if !b {
151-
entries.push(Either::Left(idx));
152-
}
153-
};
154-
155144
for (idx, pat) in pattern.iter().enumerate() {
156145
if self.is_constant_pattern(pat) {
157146
if current_seq_start.is_none() {
158147
current_seq_start = Some(idx as u64);
148+
} else {
149+
continue;
159150
}
160151
} else {
161-
apply(&mut current_seq_start, idx as u64, false);
152+
if let Some(start) = current_seq_start {
153+
entries.push(Either::Right(start..idx as u64));
154+
current_seq_start = None;
155+
}
156+
entries.push(Either::Left(idx as u64));
162157
}
163158
}
164159

165-
apply(&mut current_seq_start, pattern.len() as u64, true);
160+
if let Some(start) = current_seq_start {
161+
entries.push(Either::Right(start..pattern.len() as u64));
162+
}
163+
166164
entries
167165
}
168166

compiler/rustc_mir_build/src/builder/matches/util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,11 @@ impl Range {
266266

267267
pub(crate) fn shift_range(self, range_within: ops::Range<u64>) -> Self {
268268
if !self.from_end {
269-
Self::from_start(self.start+range_within.start..self.start+range_within.end)
269+
Self::from_start(self.start + range_within.start..self.start + range_within.end)
270270
} else {
271271
let range_within_start = range_within.end;
272272
let range_within_end = range_within.start;
273-
Self::from_end(self.start-range_within_start..self.start-range_within_end)
273+
Self::from_end(self.start - range_within_start..self.start - range_within_end)
274274
}
275275
}
276276
}

0 commit comments

Comments
 (0)