From 07e108f038d0e85c73e2910be8745b5824f1655e Mon Sep 17 00:00:00 2001 From: Devon Hollowood Date: Mon, 16 Nov 2015 20:52:30 -0800 Subject: [PATCH 1/3] Remove 'raw_pointer_derive' lint (#14615) --- src/libcore/lib.rs | 1 - src/librustc_lint/builtin.rs | 86 -------------------- src/librustc_lint/lib.rs | 3 - src/librustc_llvm/diagnostic.rs | 1 - src/test/compile-fail/lint-raw-ptr-derive.rs | 34 -------- src/test/run-pass/issue-21296.rs | 21 ----- 6 files changed, 146 deletions(-) delete mode 100644 src/test/compile-fail/lint-raw-ptr-derive.rs delete mode 100644 src/test/run-pass/issue-21296.rs diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index df7b7c437c3..a4745ac636d 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -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)] diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index a001289b196..39837862c4e 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -138,92 +138,6 @@ impl LateLintPass for BoxPointers { } } -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, diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index 920e0341372..2613115d805 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -135,7 +135,6 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) { add_builtin_with_new!(sess, TypeLimits, - RawPointerDerive, MissingDoc, MissingDebugImplementations, ); @@ -152,8 +151,6 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) { 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"); diff --git a/src/librustc_llvm/diagnostic.rs b/src/librustc_llvm/diagnostic.rs index e6350ae44d4..c09048d677e 100644 --- a/src/librustc_llvm/diagnostic.rs +++ b/src/librustc_llvm/diagnostic.rs @@ -37,7 +37,6 @@ impl OptimizationDiagnosticKind { } } -#[allow(raw_pointer_derive)] #[derive(Copy, Clone)] pub struct OptimizationDiagnostic { pub kind: OptimizationDiagnosticKind, diff --git a/src/test/compile-fail/lint-raw-ptr-derive.rs b/src/test/compile-fail/lint-raw-ptr-derive.rs deleted file mode 100644 index 4320b3e7441..00000000000 --- a/src/test/compile-fail/lint-raw-ptr-derive.rs +++ /dev/null @@ -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 or the MIT license -// , 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() {} diff --git a/src/test/run-pass/issue-21296.rs b/src/test/run-pass/issue-21296.rs deleted file mode 100644 index 5e2ac61caa2..00000000000 --- a/src/test/run-pass/issue-21296.rs +++ /dev/null @@ -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 or the MIT license -// , 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() {} From 5e8225af91e8d6fe51da67925694adac9560903e Mon Sep 17 00:00:00 2001 From: Devon Hollowood Date: Tue, 17 Nov 2015 01:14:55 -0800 Subject: [PATCH 2/3] Remove unused imports --- src/librustc_lint/builtin.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 39837862c4e..d49e0ff5321 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -46,7 +46,7 @@ use syntax::attr::{self, AttrMetaMethods}; use syntax::codemap::{self, Span}; use rustc_front::hir; -use rustc_front::visit::{self, FnKind, Visitor}; +use rustc_front::visit::FnKind; use bad_style::{MethodLateContext, method_context}; From 0823ee6940160ef057c1d90f24d45001bf33ca31 Mon Sep 17 00:00:00 2001 From: Devon Hollowood Date: Tue, 17 Nov 2015 13:16:09 -0800 Subject: [PATCH 3/3] Add changes to liblibc --- src/liblibc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/liblibc b/src/liblibc index b1a043feeae..8531cc11e19 160000 --- a/src/liblibc +++ b/src/liblibc @@ -1 +1 @@ -Subproject commit b1a043feeae3a67f45e75eaf10aa900a1f6832f9 +Subproject commit 8531cc11e196b7ae9072ae7b384a930ff7b00dfb