Skip to content

Commit bc7f508

Browse files
authored
Merge pull request #550 from immunant/kkysen/fix-clippy-boxed-locals
Fixed `clippy::boxed_local` warnings surfaced by de-genericizing PR
2 parents f5e39aa + d3da84c commit bc7f508

File tree

8 files changed

+81
-82
lines changed

8 files changed

+81
-82
lines changed

c2rust-ast-builder/src/builder.rs

+56-56
Original file line numberDiff line numberDiff line change
@@ -883,22 +883,22 @@ impl Builder {
883883
Box::new(Expr::Unsafe(unsafe_blk))
884884
}
885885

886-
pub fn block_expr(self, blk: Box<Block>) -> Box<Expr> {
886+
pub fn block_expr(self, block: Block) -> Box<Expr> {
887887
Box::new(Expr::Block(ExprBlock {
888888
attrs: self.attrs,
889-
block: *blk,
889+
block,
890890
label: None,
891891
}))
892892
}
893893

894-
pub fn labelled_block_expr<L>(self, blk: Box<Block>, lbl: L) -> Box<Expr>
894+
pub fn labelled_block_expr<L>(self, block: Block, lbl: L) -> Box<Expr>
895895
where
896896
L: Make<Label>,
897897
{
898898
let lbl = lbl.make(&self);
899899
Box::new(Expr::Block(ExprBlock {
900900
attrs: self.attrs,
901-
block: *blk,
901+
block,
902902
label: Some(lbl),
903903
}))
904904
}
@@ -1087,11 +1087,11 @@ impl Builder {
10871087
}))
10881088
}
10891089

1090-
pub fn arm(self, pat: Box<Pat>, guard: Option<Box<Expr>>, body: Box<Expr>) -> Arm {
1090+
pub fn arm(self, pat: Pat, guard: Option<Box<Expr>>, body: Box<Expr>) -> Arm {
10911091
let guard = guard.map(|g| (Token![if](self.span), g));
10921092
Arm {
10931093
attrs: self.attrs,
1094-
pat: *pat,
1094+
pat,
10951095
guard,
10961096
body,
10971097
fat_arrow_token: Token![=>](self.span),
@@ -1127,10 +1127,10 @@ impl Builder {
11271127
pub fn ifte_expr(
11281128
self,
11291129
cond: Box<Expr>,
1130-
then_case: Box<Block>,
1131-
else_case: Option<Box<Expr>>,
1130+
then_branch: Block,
1131+
else_branch: Option<Box<Expr>>,
11321132
) -> Box<Expr> {
1133-
let else_case = else_case.map(|e| {
1133+
let else_branch = else_branch.map(|e| {
11341134
// The else branch in libsyntax must be one of these three cases,
11351135
// otherwise we have to manually add the block around the else expression
11361136
(
@@ -1151,12 +1151,12 @@ impl Builder {
11511151
attrs: self.attrs,
11521152
if_token: Token![if](self.span),
11531153
cond,
1154-
then_branch: *then_case,
1155-
else_branch: else_case,
1154+
then_branch,
1155+
else_branch,
11561156
}))
11571157
}
11581158

1159-
pub fn while_expr<I>(self, cond: Box<Expr>, body: Box<Block>, label: Option<I>) -> Box<Expr>
1159+
pub fn while_expr<I>(self, cond: Box<Expr>, body: Block, label: Option<I>) -> Box<Expr>
11601160
where
11611161
I: Make<Ident>,
11621162
{
@@ -1172,12 +1172,12 @@ impl Builder {
11721172
attrs: self.attrs,
11731173
while_token: Token![while](self.span),
11741174
cond,
1175-
body: *body,
1175+
body,
11761176
label,
11771177
}))
11781178
}
11791179

1180-
pub fn loop_expr<I>(self, body: Box<Block>, label: Option<I>) -> Box<Expr>
1180+
pub fn loop_expr<I>(self, body: Block, label: Option<I>) -> Box<Expr>
11811181
where
11821182
I: Make<Ident>,
11831183
{
@@ -1192,16 +1192,16 @@ impl Builder {
11921192
Box::new(Expr::Loop(ExprLoop {
11931193
attrs: self.attrs,
11941194
loop_token: Token![loop](self.span),
1195-
body: *body,
1195+
body,
11961196
label,
11971197
}))
11981198
}
11991199

12001200
pub fn for_expr<I>(
12011201
self,
1202-
pat: Box<Pat>,
1202+
pat: Pat,
12031203
expr: Box<Expr>,
1204-
body: Box<Block>,
1204+
body: Block,
12051205
label: Option<I>,
12061206
) -> Box<Expr>
12071207
where
@@ -1219,35 +1219,35 @@ impl Builder {
12191219
attrs: self.attrs,
12201220
for_token: Token![for](self.span),
12211221
in_token: Token![in](self.span),
1222-
pat: *pat,
1222+
pat,
12231223
expr,
1224-
body: *body,
1224+
body,
12251225
label,
12261226
}))
12271227
}
12281228

12291229
// Patterns
12301230

1231-
pub fn ident_pat<I>(self, name: I) -> Box<Pat>
1231+
pub fn ident_pat<I>(self, name: I) -> Pat
12321232
where
12331233
I: Make<Ident>,
12341234
{
12351235
let name = name.make(&self);
1236-
Box::new(Pat::Ident(PatIdent {
1236+
Pat::Ident(PatIdent {
12371237
attrs: self.attrs,
12381238
mutability: self.mutbl.to_token(),
12391239
by_ref: None,
12401240
ident: name,
12411241
subpat: None,
1242-
}))
1242+
})
12431243
}
12441244

1245-
pub fn tuple_pat(self, pats: Vec<Box<Pat>>) -> Box<Pat> {
1246-
Box::new(Pat::Tuple(PatTuple {
1245+
pub fn tuple_pat(self, pats: Vec<Pat>) -> Pat {
1246+
Pat::Tuple(PatTuple {
12471247
attrs: self.attrs,
12481248
paren_token: token::Paren(self.span),
1249-
elems: punct_box(pats),
1250-
}))
1249+
elems: punct(pats),
1250+
})
12511251
}
12521252

12531253
pub fn qpath_pat<Pa>(self, qself: Option<QSelf>, path: Pa) -> Box<Pat>
@@ -1262,53 +1262,53 @@ impl Builder {
12621262
}))
12631263
}
12641264

1265-
pub fn wild_pat(self) -> Box<Pat> {
1266-
Box::new(Pat::Wild(PatWild {
1265+
pub fn wild_pat(self) -> Pat {
1266+
Pat::Wild(PatWild {
12671267
attrs: self.attrs,
12681268
underscore_token: Token![_](self.span),
1269-
}))
1269+
})
12701270
}
12711271

1272-
pub fn lit_pat(self, lit: Box<Expr>) -> Box<Pat> {
1273-
Box::new(Pat::Lit(PatLit {
1272+
pub fn lit_pat(self, lit: Box<Expr>) -> Pat {
1273+
Pat::Lit(PatLit {
12741274
attrs: self.attrs,
12751275
expr: lit,
1276-
}))
1276+
})
12771277
}
12781278

1279-
pub fn mac_pat(self, mac: Macro) -> Box<Pat> {
1280-
Box::new(Pat::Macro(PatMacro {
1279+
pub fn mac_pat(self, mac: Macro) -> Pat {
1280+
Pat::Macro(PatMacro {
12811281
attrs: self.attrs,
12821282
mac,
1283-
}))
1283+
})
12841284
}
12851285

1286-
pub fn ident_ref_pat<I>(self, name: I) -> Box<Pat>
1286+
pub fn ident_ref_pat<I>(self, name: I) -> Pat
12871287
where
12881288
I: Make<Ident>,
12891289
{
12901290
let name = name.make(&self);
1291-
Box::new(Pat::Ident(PatIdent {
1291+
Pat::Ident(PatIdent {
12921292
attrs: self.attrs,
12931293
by_ref: Some(Token![ref](self.span)),
12941294
mutability: self.mutbl.to_token(),
12951295
ident: name,
12961296
subpat: None,
1297-
}))
1297+
})
12981298
}
12991299

1300-
pub fn or_pat(self, pats: Vec<Box<Pat>>) -> Box<Pat> {
1301-
Box::new(Pat::Or(PatOr {
1300+
pub fn or_pat(self, pats: Vec<Pat>) -> Pat {
1301+
Pat::Or(PatOr {
13021302
attrs: self.attrs,
13031303
leading_vert: None, // Untested
1304-
cases: punct_box(pats),
1305-
}))
1304+
cases: punct(pats),
1305+
})
13061306
}
13071307

13081308
// Types
13091309

1310-
pub fn barefn_ty(self, decl: Box<BareFnTyParts>) -> Box<Type> {
1311-
let (inputs, variadic, output) = *decl;
1310+
pub fn barefn_ty(self, decl: BareFnTyParts) -> Box<Type> {
1311+
let (inputs, variadic, output) = decl;
13121312
let abi = self.get_abi_opt();
13131313

13141314
let barefn = TypeBareFn {
@@ -1490,7 +1490,7 @@ impl Builder {
14901490
}))
14911491
}
14921492

1493-
pub fn fn_item<S>(self, sig: S, block: Box<Block>) -> Box<Item>
1493+
pub fn fn_item<S>(self, sig: S, block: Block) -> Box<Item>
14941494
where
14951495
S: Make<Signature>,
14961496
{
@@ -1499,7 +1499,7 @@ impl Builder {
14991499
attrs: self.attrs,
15001500
vis: self.vis,
15011501
sig,
1502-
block,
1502+
block: Box::new(block),
15031503
}))
15041504
}
15051505

@@ -1947,11 +1947,11 @@ impl Builder {
19471947
}
19481948
}
19491949

1950-
pub fn block(self, stmts: Vec<Stmt>) -> Box<Block> {
1951-
Box::new(Block {
1950+
pub fn block(self, stmts: Vec<Stmt>) -> Block {
1951+
Block {
19521952
stmts,
19531953
brace_token: token::Brace(self.span),
1954-
})
1954+
}
19551955
}
19561956

19571957
pub fn label<L>(self, lbl: L) -> Label
@@ -1986,11 +1986,11 @@ impl Builder {
19861986
}
19871987
}
19881988

1989-
pub fn arg(self, ty: Box<Type>, pat: Box<Pat>) -> FnArg {
1989+
pub fn arg(self, ty: Box<Type>, pat: Pat) -> FnArg {
19901990
FnArg::Typed(PatType {
19911991
attrs: Vec::new(),
19921992
ty,
1993-
pat,
1993+
pat: Box::new(pat),
19941994
colon_token: Token![:](self.span),
19951995
})
19961996
}
@@ -2160,17 +2160,17 @@ impl Builder {
21602160
}
21612161

21622162
/// Create a local variable
2163-
pub fn local(self, pat: Box<Pat>, ty: Option<Box<Type>>, init: Option<Box<Expr>>) -> Local {
2163+
pub fn local(self, pat: Pat, ty: Option<Box<Type>>, init: Option<Box<Expr>>) -> Local {
21642164
let init = init.map(|x| (Default::default(), x));
21652165
let pat = if let Some(ty) = ty {
21662166
Pat::Type(PatType {
21672167
attrs: vec![],
2168-
pat,
2168+
pat: Box::new(pat),
21692169
colon_token: Token![:](self.span),
21702170
ty,
21712171
})
21722172
} else {
2173-
*pat
2173+
pat
21742174
};
21752175
Local {
21762176
attrs: self.attrs,
@@ -2226,10 +2226,10 @@ impl Builder {
22262226
self,
22272227
capture: CaptureBy,
22282228
mov: Movability,
2229-
decl: Box<FnDecl>,
2229+
decl: FnDecl,
22302230
body: Box<Expr>,
22312231
) -> Box<Expr> {
2232-
let (_name, inputs, _variadic, output) = *decl;
2232+
let (_name, inputs, _variadic, output) = decl;
22332233
let inputs = inputs
22342234
.into_iter()
22352235
.map(|e| match e {

c2rust-transpile/src/cfg/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ pub enum GenTerminator<Lbl> {
318318
/// Multi-way branch. The patterns are expected to match the type of the expression.
319319
Switch {
320320
expr: Box<Expr>,
321-
cases: Vec<(Box<Pat>, Lbl)>, // TODO: support ranges of expressions
321+
cases: Vec<(Pat, Lbl)>, // TODO: support ranges of expressions
322322
},
323323
}
324324

@@ -429,7 +429,7 @@ impl GenTerminator<StructureLabel<StmtOrDecl>> {
429429
/// been seen which translating the body of the switch.
430430
#[derive(Clone, Debug, Default)]
431431
pub struct SwitchCases {
432-
cases: Vec<(Box<Pat>, Label)>,
432+
cases: Vec<(Pat, Label)>,
433433
default: Option<Label>,
434434
}
435435

c2rust-transpile/src/cfg/relooper.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ fn simplify_structure<Stmt: Clone>(structures: Vec<Structure<Stmt>>) -> Vec<Stru
567567
} = terminator
568568
{
569569
// Here, we group patterns by the label they go to.
570-
type Merged = IndexMap<Label, Vec<Box<Pat>>>;
570+
type Merged = IndexMap<Label, Vec<Pat>>;
571571
let mut merged_goto: Merged = IndexMap::new();
572572
let mut merged_exit: Merged = IndexMap::new();
573573

c2rust-transpile/src/cfg/structures.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub fn structured_cfg(
1414
debug_labels: bool,
1515
cut_out_trailing_ret: bool,
1616
) -> TranslationResult<Vec<Stmt>> {
17-
let ast: StructuredAST<Box<Expr>, Box<Pat>, Label, Stmt> =
17+
let ast: StructuredAST<Box<Expr>, Pat, Label, Stmt> =
1818
structured_cfg_help(vec![], &IndexSet::new(), root, &mut IndexSet::new())?;
1919

2020
let s = StructureState {
@@ -198,7 +198,7 @@ type Exit = (Label, IndexMap<Label, (IndexSet<Label>, ExitStyle)>);
198198
/// Recursive helper for `structured_cfg`
199199
///
200200
/// TODO: move this into `structured_cfg`?
201-
fn structured_cfg_help<S: StructuredStatement<E = Box<Expr>, P = Box<Pat>, L = Label, S = Stmt>>(
201+
fn structured_cfg_help<S: StructuredStatement<E = Box<Expr>, P = Pat, L = Label, S = Stmt>>(
202202
exits: Vec<Exit>,
203203
next: &IndexSet<Label>,
204204
root: &[Structure<Stmt>],
@@ -285,10 +285,10 @@ fn structured_cfg_help<S: StructuredStatement<E = Box<Expr>, P = Box<Pat>, L = L
285285
Jump(to) => branch(to)?,
286286
Branch(c, t, f) => S::mk_if(c.clone(), branch(t)?, branch(f)?),
287287
Switch { expr, cases } => {
288-
let branched_cases: Vec<(Box<Pat>, S)> = cases
288+
let branched_cases = cases
289289
.iter()
290290
.map(|&(ref pat, ref slbl)| Ok((pat.clone(), branch(slbl)?)))
291-
.collect::<TranslationResult<Vec<(Box<Pat>, S)>>>()?;
291+
.collect::<TranslationResult<_>>()?;
292292

293293
S::mk_match(expr.clone(), branched_cases)
294294
}
@@ -299,12 +299,12 @@ fn structured_cfg_help<S: StructuredStatement<E = Box<Expr>, P = Box<Pat>, L = L
299299
Multiple { branches, then, .. } => {
300300
let cases = branches
301301
.iter()
302-
.map(|(lbl, body)| -> TranslationResult<(Label, S)> {
302+
.map(|(lbl, body)| {
303303
let stmts =
304304
structured_cfg_help(exits.clone(), next, body, used_loop_labels)?;
305305
Ok((lbl.clone(), stmts))
306306
})
307-
.collect::<TranslationResult<Vec<(Label, S)>>>()?;
307+
.collect::<TranslationResult<_>>()?;
308308

309309
let then: S = structured_cfg_help(exits.clone(), next, then, used_loop_labels)?;
310310

@@ -405,7 +405,7 @@ fn span_subst_hi(span: Span, other: Span) -> Option<Span> {
405405
impl StructureState {
406406
pub fn to_stmt(
407407
&self,
408-
ast: StructuredAST<Box<Expr>, Box<Pat>, Label, Stmt>,
408+
ast: StructuredAST<Box<Expr>, Pat, Label, Stmt>,
409409
comment_store: &mut comment_store::CommentStore,
410410
) -> (Vec<Stmt>, Span) {
411411
use crate::cfg::structures::StructuredASTKind::*;

c2rust-transpile/src/convert_type.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,11 @@ impl TypeConverter {
248248

249249
let variadic = is_variadic.then(|| mk().variadic_arg(vec![]));
250250

251-
let fn_ty = Box::new((
251+
let fn_ty = (
252252
barefn_inputs,
253253
variadic,
254254
ReturnType::Type(Default::default(), output),
255-
));
255+
);
256256
Ok(mk().unsafe_().extern_("C").barefn_ty(fn_ty))
257257
}
258258

0 commit comments

Comments
 (0)