Skip to content

Commit ceaec9d

Browse files
committed
internal: Replace Vec with Box in hir Pat
1 parent cc32777 commit ceaec9d

File tree

3 files changed

+33
-47
lines changed

3 files changed

+33
-47
lines changed

crates/hir_def/src/body/lower.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ impl ExprCollector<'_> {
813813
ast::Pat::RecordPat(p) => {
814814
let path =
815815
p.path().and_then(|path| self.expander.parse_path(self.db, path)).map(Box::new);
816-
let args: Vec<_> = p
816+
let args = p
817817
.record_pat_field_list()
818818
.expect("every struct should have a field list")
819819
.fields()
@@ -903,7 +903,7 @@ impl ExprCollector<'_> {
903903
}
904904
}
905905

906-
fn collect_tuple_pat(&mut self, args: AstChildren<ast::Pat>) -> (Vec<PatId>, Option<usize>) {
906+
fn collect_tuple_pat(&mut self, args: AstChildren<ast::Pat>) -> (Box<[PatId]>, Option<usize>) {
907907
// Find the location of the `..`, if there is one. Note that we do not
908908
// consider the possibility of there being multiple `..` here.
909909
let ellipsis = args.clone().position(|p| matches!(p, ast::Pat::RestPat(_)));
@@ -962,7 +962,7 @@ impl From<ast::LiteralKind> for Literal {
962962
Literal::Float(Default::default(), ty)
963963
}
964964
LiteralKind::ByteString(bs) => {
965-
let text = bs.value().map(Vec::from).unwrap_or_else(Default::default);
965+
let text = bs.value().map(Box::from).unwrap_or_else(Default::default);
966966
Literal::ByteString(text)
967967
}
968968
LiteralKind::String(_) => Literal::String(Default::default()),

crates/hir_def/src/expr.rs

Lines changed: 26 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub type LabelId = Idx<Label>;
4141
#[derive(Debug, Clone, Eq, PartialEq)]
4242
pub enum Literal {
4343
String(String),
44-
ByteString(Vec<u8>),
44+
ByteString(Box<[u8]>),
4545
Char(char),
4646
Bool(bool),
4747
Int(i128, Option<BuiltinInt>),
@@ -182,7 +182,7 @@ pub enum Expr {
182182

183183
#[derive(Debug, Clone, Eq, PartialEq)]
184184
pub enum Array {
185-
ElementList(Vec<ExprId>),
185+
ElementList(Box<[ExprId]>),
186186
Repeat { initializer: ExprId, repeat: ExprId },
187187
}
188188

@@ -228,23 +228,23 @@ impl Expr {
228228
Expr::If { condition, then_branch, else_branch } => {
229229
f(*condition);
230230
f(*then_branch);
231-
if let Some(else_branch) = else_branch {
232-
f(*else_branch);
231+
if let &Some(else_branch) = else_branch {
232+
f(else_branch);
233233
}
234234
}
235235
Expr::Block { statements, tail, .. } => {
236236
for stmt in statements.iter() {
237237
match stmt {
238238
Statement::Let { initializer, .. } => {
239-
if let Some(expr) = initializer {
240-
f(*expr);
239+
if let &Some(expr) = initializer {
240+
f(expr);
241241
}
242242
}
243243
Statement::Expr { expr: expression, .. } => f(*expression),
244244
}
245245
}
246-
if let Some(expr) = tail {
247-
f(*expr);
246+
if let &Some(expr) = tail {
247+
f(expr);
248248
}
249249
}
250250
Expr::TryBlock { body }
@@ -262,34 +262,28 @@ impl Expr {
262262
}
263263
Expr::Call { callee, args } => {
264264
f(*callee);
265-
for arg in args.iter() {
266-
f(*arg);
267-
}
265+
args.iter().copied().for_each(f);
268266
}
269267
Expr::MethodCall { receiver, args, .. } => {
270268
f(*receiver);
271-
for arg in args.iter() {
272-
f(*arg);
273-
}
269+
args.iter().copied().for_each(f);
274270
}
275271
Expr::Match { expr, arms } => {
276272
f(*expr);
277-
for arm in arms.iter() {
278-
f(arm.expr);
279-
}
273+
arms.iter().map(|arm| arm.expr).for_each(f);
280274
}
281275
Expr::Continue { .. } => {}
282276
Expr::Break { expr, .. } | Expr::Return { expr } | Expr::Yield { expr } => {
283-
if let Some(expr) = expr {
284-
f(*expr);
277+
if let &Some(expr) = expr {
278+
f(expr);
285279
}
286280
}
287281
Expr::RecordLit { fields, spread, .. } => {
288282
for field in fields.iter() {
289283
f(field.expr);
290284
}
291-
if let Some(expr) = spread {
292-
f(*expr);
285+
if let &Some(expr) = spread {
286+
f(expr);
293287
}
294288
}
295289
Expr::Lambda { body, .. } => {
@@ -300,11 +294,11 @@ impl Expr {
300294
f(*rhs);
301295
}
302296
Expr::Range { lhs, rhs, .. } => {
303-
if let Some(lhs) = rhs {
304-
f(*lhs);
297+
if let &Some(lhs) = rhs {
298+
f(lhs);
305299
}
306-
if let Some(rhs) = lhs {
307-
f(*rhs);
300+
if let &Some(rhs) = lhs {
301+
f(rhs);
308302
}
309303
}
310304
Expr::Index { base, index } => {
@@ -320,17 +314,9 @@ impl Expr {
320314
| Expr::Box { expr } => {
321315
f(*expr);
322316
}
323-
Expr::Tuple { exprs } => {
324-
for expr in exprs.iter() {
325-
f(*expr);
326-
}
327-
}
317+
Expr::Tuple { exprs } => exprs.iter().copied().for_each(f),
328318
Expr::Array(a) => match a {
329-
Array::ElementList(exprs) => {
330-
for expr in exprs {
331-
f(*expr);
332-
}
333-
}
319+
Array::ElementList(exprs) => exprs.iter().copied().for_each(f),
334320
Array::Repeat { initializer, repeat } => {
335321
f(*initializer);
336322
f(*repeat)
@@ -386,15 +372,15 @@ pub struct RecordFieldPat {
386372
pub enum Pat {
387373
Missing,
388374
Wild,
389-
Tuple { args: Vec<PatId>, ellipsis: Option<usize> },
390-
Or(Vec<PatId>),
391-
Record { path: Option<Box<Path>>, args: Vec<RecordFieldPat>, ellipsis: bool },
375+
Tuple { args: Box<[PatId]>, ellipsis: Option<usize> },
376+
Or(Box<[PatId]>),
377+
Record { path: Option<Box<Path>>, args: Box<[RecordFieldPat]>, ellipsis: bool },
392378
Range { start: ExprId, end: ExprId },
393-
Slice { prefix: Vec<PatId>, slice: Option<PatId>, suffix: Vec<PatId> },
379+
Slice { prefix: Box<[PatId]>, slice: Option<PatId>, suffix: Box<[PatId]> },
394380
Path(Box<Path>),
395381
Lit(ExprId),
396382
Bind { mode: BindingAnnotation, name: Name, subpat: Option<PatId> },
397-
TupleStruct { path: Option<Box<Path>>, args: Vec<PatId>, ellipsis: Option<usize> },
383+
TupleStruct { path: Option<Box<Path>>, args: Box<[PatId]>, ellipsis: Option<usize> },
398384
Ref { pat: PatId, mutability: Mutability },
399385
Box { inner: PatId },
400386
ConstBlock(ExprId),

crates/hir_ty/src/infer/pat.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,17 +226,17 @@ impl<'a> InferenceContext<'a> {
226226
_ => self.err_ty(),
227227
};
228228

229-
for pat_id in prefix.iter().chain(suffix) {
230-
self.infer_pat(*pat_id, &elem_ty, default_bm);
229+
for &pat_id in prefix.iter().chain(suffix.iter()) {
230+
self.infer_pat(pat_id, &elem_ty, default_bm);
231231
}
232232

233233
let pat_ty = match expected.kind(&Interner) {
234234
TyKind::Array(_, const_) => TyKind::Array(elem_ty, const_.clone()),
235235
_ => TyKind::Slice(elem_ty),
236236
}
237237
.intern(&Interner);
238-
if let Some(slice_pat_id) = slice {
239-
self.infer_pat(*slice_pat_id, &pat_ty, default_bm);
238+
if let &Some(slice_pat_id) = slice {
239+
self.infer_pat(slice_pat_id, &pat_ty, default_bm);
240240
}
241241

242242
pat_ty

0 commit comments

Comments
 (0)