mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
Make unused_allocation
lint warn against Box::new
This commit is contained in:
parent
18caf88956
commit
9ac0da8f39
@ -1349,9 +1349,8 @@ declare_lint! {
|
||||
/// ### Example
|
||||
///
|
||||
/// ```rust
|
||||
/// #![feature(box_syntax)]
|
||||
/// fn main() {
|
||||
/// let a = (box [1, 2, 3]).len();
|
||||
/// let a = Box::new([1, 2, 3]).len();
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
@ -1373,6 +1372,11 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAllocation {
|
||||
fn check_expr(&mut self, cx: &LateContext<'_>, e: &hir::Expr<'_>) {
|
||||
match e.kind {
|
||||
hir::ExprKind::Box(_) => {}
|
||||
hir::ExprKind::Call(path_expr, [_])
|
||||
if let hir::ExprKind::Path(qpath) = &path_expr.kind
|
||||
&& let Some(did) = cx.qpath_res(qpath, path_expr.hir_id).opt_def_id()
|
||||
&& cx.tcx.is_diagnostic_item(sym::box_new, did)
|
||||
=> {}
|
||||
_ => return,
|
||||
}
|
||||
|
||||
|
@ -429,6 +429,7 @@ symbols! {
|
||||
borrowck_graphviz_format,
|
||||
borrowck_graphviz_postflow,
|
||||
box_free,
|
||||
box_new,
|
||||
box_patterns,
|
||||
box_syntax,
|
||||
bpf_target_feature,
|
||||
|
@ -214,6 +214,7 @@ impl<T> Box<T> {
|
||||
#[inline(always)]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[must_use]
|
||||
#[rustc_diagnostic_item = "box_new"]
|
||||
pub fn new(x: T) -> Self {
|
||||
#[rustc_box]
|
||||
Box::new(x)
|
||||
|
Loading…
Reference in New Issue
Block a user