Skip to content

Commit

Permalink
Rollup merge of rust-lang#108516 - clubby789:rustc-box-restrict, r=co…
Browse files Browse the repository at this point in the history
…mpiler-errors

Restrict `#[rustc_box]` to `Box::new` calls

Currently, `#[rustc_box]` can be applied to any call expression with a single argument. This PR only allows it to be applied to calls to `Box::new`
  • Loading branch information
matthiaskrgr authored Mar 2, 2023
2 parents 0966f59 + 702a83b commit 5cf9c34
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions clippy_utils/src/higher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,15 +287,12 @@ impl<'a> VecArgs<'a> {
Some(VecArgs::Repeat(&args[0], &args[1]))
} else if match_def_path(cx, fun_def_id, &paths::SLICE_INTO_VEC) && args.len() == 1 {
// `vec![a, b, c]` case
if_chain! {
if let hir::ExprKind::Box(boxed) = args[0].kind;
if let hir::ExprKind::Array(args) = boxed.kind;
then {
return Some(VecArgs::Vec(args));
}
if let hir::ExprKind::Call(_, [arg]) = &args[0].kind
&& let hir::ExprKind::Array(args) = arg.kind {
Some(VecArgs::Vec(args))
} else {
None
}

None
} else if match_def_path(cx, fun_def_id, &paths::VEC_NEW) && args.is_empty() {
Some(VecArgs::Vec(&[]))
} else {
Expand Down

0 comments on commit 5cf9c34

Please sign in to comment.