Remove 'raw_pointer_derive' lint (#14615)
This commit is contained in:
parent
c124cd523a
commit
07e108f038
@ -63,7 +63,6 @@
|
||||
#![doc(test(no_crate_inject, attr(allow(unused_variables), deny(warnings))))]
|
||||
|
||||
#![no_core]
|
||||
#![allow(raw_pointer_derive)]
|
||||
#![deny(missing_docs)]
|
||||
|
||||
#![feature(allow_internal_unstable)]
|
||||
|
@ -138,92 +138,6 @@ fn check_expr(&mut self, cx: &LateContext, e: &hir::Expr) {
|
||||
}
|
||||
}
|
||||
|
||||
declare_lint! {
|
||||
RAW_POINTER_DERIVE,
|
||||
Warn,
|
||||
"uses of #[derive] with raw pointers are rarely correct"
|
||||
}
|
||||
|
||||
struct RawPtrDeriveVisitor<'a, 'tcx: 'a> {
|
||||
cx: &'a LateContext<'a, 'tcx>
|
||||
}
|
||||
|
||||
impl<'a, 'tcx, 'v> Visitor<'v> for RawPtrDeriveVisitor<'a, 'tcx> {
|
||||
fn visit_ty(&mut self, ty: &hir::Ty) {
|
||||
const MSG: &'static str = "use of `#[derive]` with a raw pointer";
|
||||
if let hir::TyPtr(..) = ty.node {
|
||||
self.cx.span_lint(RAW_POINTER_DERIVE, ty.span, MSG);
|
||||
}
|
||||
visit::walk_ty(self, ty);
|
||||
}
|
||||
// explicit override to a no-op to reduce code bloat
|
||||
fn visit_expr(&mut self, _: &hir::Expr) {}
|
||||
fn visit_block(&mut self, _: &hir::Block) {}
|
||||
}
|
||||
|
||||
pub struct RawPointerDerive {
|
||||
checked_raw_pointers: NodeSet,
|
||||
}
|
||||
|
||||
impl RawPointerDerive {
|
||||
pub fn new() -> RawPointerDerive {
|
||||
RawPointerDerive {
|
||||
checked_raw_pointers: NodeSet(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl LintPass for RawPointerDerive {
|
||||
fn get_lints(&self) -> LintArray {
|
||||
lint_array!(RAW_POINTER_DERIVE)
|
||||
}
|
||||
}
|
||||
|
||||
impl LateLintPass for RawPointerDerive {
|
||||
fn check_item(&mut self, cx: &LateContext, item: &hir::Item) {
|
||||
if !attr::contains_name(&item.attrs, "automatically_derived") {
|
||||
return;
|
||||
}
|
||||
let did = match item.node {
|
||||
hir::ItemImpl(_, _, _, ref t_ref_opt, _, _) => {
|
||||
// Deriving the Copy trait does not cause a warning
|
||||
if let &Some(ref trait_ref) = t_ref_opt {
|
||||
let def_id = cx.tcx.trait_ref_to_def_id(trait_ref);
|
||||
if Some(def_id) == cx.tcx.lang_items.copy_trait() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
match cx.tcx.node_id_to_type(item.id).sty {
|
||||
ty::TyEnum(def, _) => def.did,
|
||||
ty::TyStruct(def, _) => def.did,
|
||||
_ => return,
|
||||
}
|
||||
}
|
||||
_ => return,
|
||||
};
|
||||
let node_id = if let Some(node_id) = cx.tcx.map.as_local_node_id(did) {
|
||||
node_id
|
||||
} else {
|
||||
return;
|
||||
};
|
||||
let item = match cx.tcx.map.find(node_id) {
|
||||
Some(hir_map::NodeItem(item)) => item,
|
||||
_ => return,
|
||||
};
|
||||
if !self.checked_raw_pointers.insert(item.id) {
|
||||
return;
|
||||
}
|
||||
match item.node {
|
||||
hir::ItemStruct(..) | hir::ItemEnum(..) => {
|
||||
let mut visitor = RawPtrDeriveVisitor { cx: cx };
|
||||
visit::walk_item(&mut visitor, &item);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
declare_lint! {
|
||||
NON_SHORTHAND_FIELD_PATTERNS,
|
||||
Warn,
|
||||
|
@ -135,7 +135,6 @@ macro_rules! add_lint_group {
|
||||
|
||||
add_builtin_with_new!(sess,
|
||||
TypeLimits,
|
||||
RawPointerDerive,
|
||||
MissingDoc,
|
||||
MissingDebugImplementations,
|
||||
);
|
||||
@ -152,8 +151,6 @@ macro_rules! add_lint_group {
|
||||
store.register_late_pass(sess, false, box lint::GatherNodeLevels);
|
||||
|
||||
// Insert temporary renamings for a one-time deprecation
|
||||
store.register_renamed("raw_pointer_deriving", "raw_pointer_derive");
|
||||
|
||||
store.register_renamed("unknown_features", "unused_features");
|
||||
|
||||
store.register_removed("unsigned_negation", "replaced by negate_unsigned feature gate");
|
||||
|
@ -37,7 +37,6 @@ pub fn describe(self) -> &'static str {
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(raw_pointer_derive)]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct OptimizationDiagnostic {
|
||||
pub kind: OptimizationDiagnosticKind,
|
||||
|
@ -1,34 +0,0 @@
|
||||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![allow(dead_code)]
|
||||
#![deny(raw_pointer_derive)]
|
||||
|
||||
#[derive(Clone)]
|
||||
struct Foo {
|
||||
x: *const isize //~ ERROR use of `#[derive]` with a raw pointer
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct Bar(*mut isize); //~ ERROR use of `#[derive]` with a raw pointer
|
||||
|
||||
#[derive(Clone)]
|
||||
enum Baz {
|
||||
A(*const isize), //~ ERROR use of `#[derive]` with a raw pointer
|
||||
B { x: *mut isize } //~ ERROR use of `#[derive]` with a raw pointer
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct Buzz {
|
||||
x: (*const isize, //~ ERROR use of `#[derive]` with a raw pointer
|
||||
*const usize) //~ ERROR use of `#[derive]` with a raw pointer
|
||||
}
|
||||
|
||||
fn main() {}
|
@ -1,21 +0,0 @@
|
||||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// pretty-expanded FIXME #23616
|
||||
|
||||
#[forbid(raw_pointer_derive)]
|
||||
#[derive(Copy)]
|
||||
struct Test(*const i32);
|
||||
|
||||
impl Clone for Test {
|
||||
fn clone(&self) -> Test { *self }
|
||||
}
|
||||
|
||||
fn main() {}
|
Loading…
Reference in New Issue
Block a user