1
Fork 0

auto trait future compatibility lint

This commit is contained in:
leonardo.yvens 2017-10-14 18:23:50 -03:00
parent 0d1b79a01a
commit 8b586e68b5
31 changed files with 90 additions and 1 deletions

View file

@ -46,6 +46,8 @@ pub unsafe trait Send {
} }
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[allow(unknown_lints)]
#[allow(auto_impl)]
unsafe impl Send for .. { } unsafe impl Send for .. { }
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
@ -349,6 +351,8 @@ pub unsafe trait Sync {
} }
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
#[allow(unknown_lints)]
#[allow(auto_impl)]
unsafe impl Sync for .. { } unsafe impl Sync for .. { }
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
@ -562,6 +566,8 @@ mod impls {
#[lang = "freeze"] #[lang = "freeze"]
unsafe trait Freeze {} unsafe trait Freeze {}
#[allow(unknown_lints)]
#[allow(auto_impl)]
unsafe impl Freeze for .. {} unsafe impl Freeze for .. {}
impl<T: ?Sized> !Freeze for UnsafeCell<T> {} impl<T: ?Sized> !Freeze for UnsafeCell<T> {}

View file

@ -55,6 +55,31 @@ use bad_style::{MethodLateContext, method_context};
// hardwired lints from librustc // hardwired lints from librustc
pub use lint::builtin::*; pub use lint::builtin::*;
declare_lint! {
pub AUTO_IMPL,
Deny,
"The form `impl Foo for .. {}` will be removed, please use `auto trait Foo {}`"
}
#[derive(Copy, Clone)]
pub struct AutoImpl;
impl LintPass for AutoImpl {
fn get_lints(&self) -> LintArray {
lint_array!(AUTO_IMPL)
}
}
impl EarlyLintPass for AutoImpl {
fn check_item(&mut self, cx: &EarlyContext, item: &ast::Item) {
let msg = "The form `impl Foo for .. {}` will be removed, please use `auto trait Foo {}`";
match item.node {
ast::ItemKind::AutoImpl(..) => cx.span_lint(AUTO_IMPL, item.span, msg),
_ => ()
}
}
}
declare_lint! { declare_lint! {
WHILE_TRUE, WHILE_TRUE,
Warn, Warn,

View file

@ -109,6 +109,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
AnonymousParameters, AnonymousParameters,
IllegalFloatLiteralPattern, IllegalFloatLiteralPattern,
UnusedDocComment, UnusedDocComment,
AutoImpl,
); );
add_early_builtin_with_new!(sess, add_early_builtin_with_new!(sess,
@ -181,6 +182,10 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
// - Eventually, remove lint // - Eventually, remove lint
store.register_future_incompatible(sess, store.register_future_incompatible(sess,
vec![ vec![
FutureIncompatibleInfo {
id: LintId::of(AUTO_IMPL),
reference: "issue #13231 <https://github.com/rust-lang/rust/issues/13231>",
},
FutureIncompatibleInfo { FutureIncompatibleInfo {
id: LintId::of(PRIVATE_IN_PUBLIC), id: LintId::of(PRIVATE_IN_PUBLIC),
reference: "issue #34537 <https://github.com/rust-lang/rust/issues/34537>", reference: "issue #34537 <https://github.com/rust-lang/rust/issues/34537>",

View file

@ -188,6 +188,8 @@ pub struct AssertUnwindSafe<T>(
// * Types like Mutex/RwLock which are explicilty poisoned are unwind safe // * Types like Mutex/RwLock which are explicilty poisoned are unwind safe
// * Our custom AssertUnwindSafe wrapper is indeed unwind safe // * Our custom AssertUnwindSafe wrapper is indeed unwind safe
#[stable(feature = "catch_unwind", since = "1.9.0")] #[stable(feature = "catch_unwind", since = "1.9.0")]
#[allow(unknown_lints)]
#[allow(auto_impl)]
impl UnwindSafe for .. {} impl UnwindSafe for .. {}
#[stable(feature = "catch_unwind", since = "1.9.0")] #[stable(feature = "catch_unwind", since = "1.9.0")]
impl<'a, T: ?Sized> !UnwindSafe for &'a mut T {} impl<'a, T: ?Sized> !UnwindSafe for &'a mut T {}
@ -221,6 +223,8 @@ impl<T: RefUnwindSafe + ?Sized> UnwindSafe for Arc<T> {}
// only thing which doesn't implement it (which then transitively applies to // only thing which doesn't implement it (which then transitively applies to
// everything else). // everything else).
#[stable(feature = "catch_unwind", since = "1.9.0")] #[stable(feature = "catch_unwind", since = "1.9.0")]
#[allow(unknown_lints)]
#[allow(auto_impl)]
impl RefUnwindSafe for .. {} impl RefUnwindSafe for .. {}
#[stable(feature = "catch_unwind", since = "1.9.0")] #[stable(feature = "catch_unwind", since = "1.9.0")]
impl<T: ?Sized> !RefUnwindSafe for UnsafeCell<T> {} impl<T: ?Sized> !RefUnwindSafe for UnsafeCell<T> {}

View file

@ -14,7 +14,7 @@
// When an executable or dylib image is linked, all user code and libraries are // When an executable or dylib image is linked, all user code and libraries are
// "sandwiched" between these two object files, so code or data from rsbegin.o // "sandwiched" between these two object files, so code or data from rsbegin.o
// become first in the respective sections of the image, whereas code and data // become first in the respective sections of the image, whereas code and data
// from rsend.o become the last ones. This effect can be used to place symbols // from rsend.o become the last ones. This effect can be used to place symbols
// at the beginning or at the end of a section, as well as to insert any required // at the beginning or at the end of a section, as well as to insert any required
// headers or footers. // headers or footers.
// //
@ -31,11 +31,15 @@
trait Sized {} trait Sized {}
#[lang = "sync"] #[lang = "sync"]
trait Sync {} trait Sync {}
#[allow(unknown_lints)]
#[allow(auto_impl)]
impl Sync for .. {} impl Sync for .. {}
#[lang = "copy"] #[lang = "copy"]
trait Copy {} trait Copy {}
#[lang = "freeze"] #[lang = "freeze"]
trait Freeze {} trait Freeze {}
#[allow(unknown_lints)]
#[allow(auto_impl)]
impl Freeze for .. {} impl Freeze for .. {}
#[lang = "drop_in_place"] #[lang = "drop_in_place"]

View file

@ -23,6 +23,8 @@ impl<T> Sync for T {}
trait Copy {} trait Copy {}
#[lang = "freeze"] #[lang = "freeze"]
trait Freeze {} trait Freeze {}
#[allow(unknown_lints)]
#[allow(auto_impl)]
impl Freeze for .. {} impl Freeze for .. {}
#[lang = "drop_in_place"] #[lang = "drop_in_place"]

View file

@ -0,0 +1,12 @@
// Copyright 2017 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.
trait Foo {}
impl Foo for .. {}

View file

@ -12,18 +12,22 @@
trait MyTrait { fn foo() {} } trait MyTrait { fn foo() {} }
#[allow(auto_impl)]
impl MyTrait for .. {} impl MyTrait for .. {}
//~^ ERROR redundant auto implementations of trait `MyTrait` //~^ ERROR redundant auto implementations of trait `MyTrait`
#[allow(auto_impl)]
impl MyTrait for .. {} impl MyTrait for .. {}
trait MySafeTrait {} trait MySafeTrait {}
#[allow(auto_impl)]
unsafe impl MySafeTrait for .. {} unsafe impl MySafeTrait for .. {}
//~^ ERROR implementing the trait `MySafeTrait` is not unsafe //~^ ERROR implementing the trait `MySafeTrait` is not unsafe
unsafe trait MyUnsafeTrait {} unsafe trait MyUnsafeTrait {}
#[allow(auto_impl)]
impl MyUnsafeTrait for .. {} impl MyUnsafeTrait for .. {}
//~^ ERROR the trait `MyUnsafeTrait` requires an `unsafe impl` declaration //~^ ERROR the trait `MyUnsafeTrait` requires an `unsafe impl` declaration

View file

@ -20,6 +20,7 @@ trait DummyTrait {
auto trait AutoDummyTrait {} auto trait AutoDummyTrait {}
//~^ ERROR auto traits are experimental and possibly buggy //~^ ERROR auto traits are experimental and possibly buggy
#[allow(auto_impl)]
impl DummyTrait for .. {} impl DummyTrait for .. {}
//~^ ERROR auto trait implementations are experimental and possibly buggy //~^ ERROR auto trait implementations are experimental and possibly buggy

View file

@ -17,6 +17,7 @@ unsafe trait Trait {
type Output; type Output;
} }
#[allow(auto_impl)]
unsafe impl Trait for .. {} unsafe impl Trait for .. {}
fn call_method<T: Trait>(x: T) {} fn call_method<T: Trait>(x: T) {}

View file

@ -19,6 +19,7 @@ unsafe trait Trait {
} }
} }
#[allow(auto_impl)]
unsafe impl Trait for .. {} unsafe impl Trait for .. {}
fn call_method<T: Trait>(x: T) { fn call_method<T: Trait>(x: T) {

View file

@ -18,6 +18,7 @@ use std::marker::{PhantomData};
unsafe trait Zen {} unsafe trait Zen {}
#[allow(auto_impl)]
unsafe impl Zen for .. {} unsafe impl Zen for .. {}
unsafe impl<'a, T: 'a> Zen for &'a T where T: Sync {} unsafe impl<'a, T: 'a> Zen for &'a T where T: Sync {}

View file

@ -21,6 +21,7 @@ pub struct S {
} }
struct Ts(pub u8); struct Ts(pub u8);
#[allow(auto_impl)]
pub impl MarkerTr for .. {} //~ ERROR unnecessary visibility qualifier pub impl MarkerTr for .. {} //~ ERROR unnecessary visibility qualifier
pub impl Tr for S { //~ ERROR unnecessary visibility qualifier pub impl Tr for S { //~ ERROR unnecessary visibility qualifier
pub fn f() {} //~ ERROR unnecessary visibility qualifier pub fn f() {} //~ ERROR unnecessary visibility qualifier
@ -49,6 +50,7 @@ const MAIN: u8 = {
} }
struct Ts(pub u8); struct Ts(pub u8);
#[allow(auto_impl)]
pub impl MarkerTr for .. {} //~ ERROR unnecessary visibility qualifier pub impl MarkerTr for .. {} //~ ERROR unnecessary visibility qualifier
pub impl Tr for S { //~ ERROR unnecessary visibility qualifier pub impl Tr for S { //~ ERROR unnecessary visibility qualifier
pub fn f() {} //~ ERROR unnecessary visibility qualifier pub fn f() {} //~ ERROR unnecessary visibility qualifier
@ -80,6 +82,7 @@ fn main() {
} }
struct Ts(pub u8); struct Ts(pub u8);
#[allow(auto_impl)]
pub impl MarkerTr for .. {} //~ ERROR unnecessary visibility qualifier pub impl MarkerTr for .. {} //~ ERROR unnecessary visibility qualifier
pub impl Tr for S { //~ ERROR unnecessary visibility qualifier pub impl Tr for S { //~ ERROR unnecessary visibility qualifier
pub fn f() {} //~ ERROR unnecessary visibility qualifier pub fn f() {} //~ ERROR unnecessary visibility qualifier

View file

@ -13,6 +13,7 @@
trait Foo {} trait Foo {}
#[allow(auto_impl)]
default impl Foo for .. {} default impl Foo for .. {}
//~^ ERROR `default impl` is not allowed for auto trait implementations //~^ ERROR `default impl` is not allowed for auto trait implementations

View file

@ -15,6 +15,7 @@
trait Foo {} trait Foo {}
#[allow(auto_impl)]
impl Foo for .. {} impl Foo for .. {}
impl<T> Foo for T {} impl<T> Foo for T {}
@ -22,6 +23,7 @@ impl !Foo for u8 {} //~ ERROR E0119
trait Bar {} trait Bar {}
#[allow(auto_impl)]
impl Bar for .. {} impl Bar for .. {}
impl<T> !Bar for T {} impl<T> !Bar for T {}

View file

@ -12,6 +12,7 @@
trait MyAutoImpl {} trait MyAutoImpl {}
#[allow(auto_impl)]
impl<T> MyAutoImpl for .. {} impl<T> MyAutoImpl for .. {}
//~^ ERROR auto trait implementations are not allowed to have generics //~^ ERROR auto trait implementations are not allowed to have generics

View file

@ -15,6 +15,7 @@
#![feature(optin_builtin_traits)] #![feature(optin_builtin_traits)]
trait Magic: Copy {} //~ ERROR E0568 trait Magic: Copy {} //~ ERROR E0568
#[allow(auto_impl)]
impl Magic for .. {} impl Magic for .. {}
fn copy<T: Magic>(x: T) -> (T, T) { (x, x) } fn copy<T: Magic>(x: T) -> (T, T) { (x, x) }

View file

@ -11,6 +11,7 @@
#![feature(optin_builtin_traits)] #![feature(optin_builtin_traits)]
trait Magic : Sized where Option<Self> : Magic {} //~ ERROR E0568 trait Magic : Sized where Option<Self> : Magic {} //~ ERROR E0568
#[allow(auto_impl)]
impl Magic for .. {} impl Magic for .. {}
impl<T:Magic> Magic for T {} impl<T:Magic> Magic for T {}

View file

@ -35,6 +35,7 @@
#![feature(optin_builtin_traits)] #![feature(optin_builtin_traits)]
trait Magic: Copy {} //~ ERROR E0568 trait Magic: Copy {} //~ ERROR E0568
#[allow(auto_impl)]
impl Magic for .. {} impl Magic for .. {}
impl<T:Magic> Magic for T {} impl<T:Magic> Magic for T {}

View file

@ -11,4 +11,5 @@
#![feature(optin_builtin_traits)] #![feature(optin_builtin_traits)]
trait Magic<T> {} //~ ERROR E0567 trait Magic<T> {} //~ ERROR E0567
#[allow(auto_impl)]
impl Magic<isize> for .. {} impl Magic<isize> for .. {}

View file

@ -12,6 +12,7 @@
trait MyTrait {} trait MyTrait {}
#[allow(auto_impl)]
impl MyTrait for .. {} impl MyTrait for .. {}
struct MyS; struct MyS;

View file

@ -12,6 +12,7 @@
trait MyTrait {} trait MyTrait {}
#[allow(auto_impl)]
impl MyTrait for .. {} impl MyTrait for .. {}
impl<T> !MyTrait for *mut T {} impl<T> !MyTrait for *mut T {}

View file

@ -12,10 +12,12 @@
trait MyTrait {} trait MyTrait {}
#[allow(auto_impl)]
impl MyTrait for .. {} impl MyTrait for .. {}
unsafe trait MyUnsafeTrait {} unsafe trait MyUnsafeTrait {}
#[allow(auto_impl)]
unsafe impl MyUnsafeTrait for .. {} unsafe impl MyUnsafeTrait for .. {}
struct ThisImplsTrait; struct ThisImplsTrait;

View file

@ -10,6 +10,7 @@
#![feature(optin_builtin_traits)] #![feature(optin_builtin_traits)]
#[allow(auto_impl)]
impl Copy for .. {} //~ ERROR E0318 impl Copy for .. {} //~ ERROR E0318
//~^ NOTE `Copy` trait not defined in this crate //~^ NOTE `Copy` trait not defined in this crate
fn main() {} fn main() {}

View file

@ -81,4 +81,5 @@ pub mod marker {
#[lang = "freeze"] #[lang = "freeze"]
trait Freeze {} trait Freeze {}
#[allow(auto_impl)]
impl Freeze for .. {} impl Freeze for .. {}

View file

@ -19,6 +19,7 @@ trait Sized { }
#[lang = "freeze"] #[lang = "freeze"]
trait Freeze {} trait Freeze {}
#[allow(auto_impl)]
impl Freeze for .. {} impl Freeze for .. {}
#[lang="start"] #[lang="start"]

View file

@ -12,6 +12,7 @@
auto trait Auto {} auto trait Auto {}
// Redundant but accepted until we remove it. // Redundant but accepted until we remove it.
#[allow(auto_impl)]
impl Auto for .. {} impl Auto for .. {}
unsafe auto trait AutoUnsafe {} unsafe auto trait AutoUnsafe {}

View file

@ -11,6 +11,7 @@
#![feature(optin_builtin_traits)] #![feature(optin_builtin_traits)]
trait NotSame {} trait NotSame {}
#[allow(auto_impl)]
impl NotSame for .. {} impl NotSame for .. {}
impl<A> !NotSame for (A, A) {} impl<A> !NotSame for (A, A) {}

View file

@ -16,6 +16,7 @@ pub mod bar {
pub trait Bar {} pub trait Bar {}
#[allow(auto_impl)]
impl Bar for .. {} impl Bar for .. {}
pub trait Foo { pub trait Foo {

View file

@ -12,4 +12,5 @@
pub trait AnOibit {} pub trait AnOibit {}
#[allow(auto_impl)]
impl AnOibit for .. {} impl AnOibit for .. {}

View file

@ -12,6 +12,7 @@
pub trait AnOibit {} pub trait AnOibit {}
#[allow(auto_impl)]
impl AnOibit for .. {} impl AnOibit for .. {}
pub struct Foo<T> { field: T } pub struct Foo<T> { field: T }