auto trait future compatibility lint
This commit is contained in:
parent
0d1b79a01a
commit
8b586e68b5
31 changed files with 90 additions and 1 deletions
|
@ -46,6 +46,8 @@ pub unsafe trait Send {
|
|||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[allow(unknown_lints)]
|
||||
#[allow(auto_impl)]
|
||||
unsafe impl Send for .. { }
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
|
@ -349,6 +351,8 @@ pub unsafe trait Sync {
|
|||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[allow(unknown_lints)]
|
||||
#[allow(auto_impl)]
|
||||
unsafe impl Sync for .. { }
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
|
@ -562,6 +566,8 @@ mod impls {
|
|||
#[lang = "freeze"]
|
||||
unsafe trait Freeze {}
|
||||
|
||||
#[allow(unknown_lints)]
|
||||
#[allow(auto_impl)]
|
||||
unsafe impl Freeze for .. {}
|
||||
|
||||
impl<T: ?Sized> !Freeze for UnsafeCell<T> {}
|
||||
|
|
|
@ -55,6 +55,31 @@ use bad_style::{MethodLateContext, method_context};
|
|||
// hardwired lints from librustc
|
||||
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! {
|
||||
WHILE_TRUE,
|
||||
Warn,
|
||||
|
|
|
@ -109,6 +109,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
|
|||
AnonymousParameters,
|
||||
IllegalFloatLiteralPattern,
|
||||
UnusedDocComment,
|
||||
AutoImpl,
|
||||
);
|
||||
|
||||
add_early_builtin_with_new!(sess,
|
||||
|
@ -181,6 +182,10 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
|
|||
// - Eventually, remove lint
|
||||
store.register_future_incompatible(sess,
|
||||
vec![
|
||||
FutureIncompatibleInfo {
|
||||
id: LintId::of(AUTO_IMPL),
|
||||
reference: "issue #13231 <https://github.com/rust-lang/rust/issues/13231>",
|
||||
},
|
||||
FutureIncompatibleInfo {
|
||||
id: LintId::of(PRIVATE_IN_PUBLIC),
|
||||
reference: "issue #34537 <https://github.com/rust-lang/rust/issues/34537>",
|
||||
|
|
|
@ -188,6 +188,8 @@ pub struct AssertUnwindSafe<T>(
|
|||
// * Types like Mutex/RwLock which are explicilty poisoned are unwind safe
|
||||
// * Our custom AssertUnwindSafe wrapper is indeed unwind safe
|
||||
#[stable(feature = "catch_unwind", since = "1.9.0")]
|
||||
#[allow(unknown_lints)]
|
||||
#[allow(auto_impl)]
|
||||
impl UnwindSafe for .. {}
|
||||
#[stable(feature = "catch_unwind", since = "1.9.0")]
|
||||
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
|
||||
// everything else).
|
||||
#[stable(feature = "catch_unwind", since = "1.9.0")]
|
||||
#[allow(unknown_lints)]
|
||||
#[allow(auto_impl)]
|
||||
impl RefUnwindSafe for .. {}
|
||||
#[stable(feature = "catch_unwind", since = "1.9.0")]
|
||||
impl<T: ?Sized> !RefUnwindSafe for UnsafeCell<T> {}
|
||||
|
|
|
@ -31,11 +31,15 @@
|
|||
trait Sized {}
|
||||
#[lang = "sync"]
|
||||
trait Sync {}
|
||||
#[allow(unknown_lints)]
|
||||
#[allow(auto_impl)]
|
||||
impl Sync for .. {}
|
||||
#[lang = "copy"]
|
||||
trait Copy {}
|
||||
#[lang = "freeze"]
|
||||
trait Freeze {}
|
||||
#[allow(unknown_lints)]
|
||||
#[allow(auto_impl)]
|
||||
impl Freeze for .. {}
|
||||
|
||||
#[lang = "drop_in_place"]
|
||||
|
|
|
@ -23,6 +23,8 @@ impl<T> Sync for T {}
|
|||
trait Copy {}
|
||||
#[lang = "freeze"]
|
||||
trait Freeze {}
|
||||
#[allow(unknown_lints)]
|
||||
#[allow(auto_impl)]
|
||||
impl Freeze for .. {}
|
||||
|
||||
#[lang = "drop_in_place"]
|
||||
|
|
12
src/test/compile-fail/auto-impl-future-compat.rs
Normal file
12
src/test/compile-fail/auto-impl-future-compat.rs
Normal 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 .. {}
|
|
@ -12,18 +12,22 @@
|
|||
|
||||
trait MyTrait { fn foo() {} }
|
||||
|
||||
#[allow(auto_impl)]
|
||||
impl MyTrait for .. {}
|
||||
//~^ ERROR redundant auto implementations of trait `MyTrait`
|
||||
|
||||
#[allow(auto_impl)]
|
||||
impl MyTrait for .. {}
|
||||
|
||||
trait MySafeTrait {}
|
||||
|
||||
#[allow(auto_impl)]
|
||||
unsafe impl MySafeTrait for .. {}
|
||||
//~^ ERROR implementing the trait `MySafeTrait` is not unsafe
|
||||
|
||||
unsafe trait MyUnsafeTrait {}
|
||||
|
||||
#[allow(auto_impl)]
|
||||
impl MyUnsafeTrait for .. {}
|
||||
//~^ ERROR the trait `MyUnsafeTrait` requires an `unsafe impl` declaration
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ trait DummyTrait {
|
|||
auto trait AutoDummyTrait {}
|
||||
//~^ ERROR auto traits are experimental and possibly buggy
|
||||
|
||||
#[allow(auto_impl)]
|
||||
impl DummyTrait for .. {}
|
||||
//~^ ERROR auto trait implementations are experimental and possibly buggy
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ unsafe trait Trait {
|
|||
type Output;
|
||||
}
|
||||
|
||||
#[allow(auto_impl)]
|
||||
unsafe impl Trait for .. {}
|
||||
|
||||
fn call_method<T: Trait>(x: T) {}
|
||||
|
|
|
@ -19,6 +19,7 @@ unsafe trait Trait {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(auto_impl)]
|
||||
unsafe impl Trait for .. {}
|
||||
|
||||
fn call_method<T: Trait>(x: T) {
|
||||
|
|
|
@ -18,6 +18,7 @@ use std::marker::{PhantomData};
|
|||
|
||||
unsafe trait Zen {}
|
||||
|
||||
#[allow(auto_impl)]
|
||||
unsafe impl Zen for .. {}
|
||||
|
||||
unsafe impl<'a, T: 'a> Zen for &'a T where T: Sync {}
|
||||
|
|
|
@ -21,6 +21,7 @@ pub struct S {
|
|||
}
|
||||
struct Ts(pub u8);
|
||||
|
||||
#[allow(auto_impl)]
|
||||
pub impl MarkerTr for .. {} //~ ERROR unnecessary visibility qualifier
|
||||
pub impl Tr for S { //~ ERROR unnecessary visibility qualifier
|
||||
pub fn f() {} //~ ERROR unnecessary visibility qualifier
|
||||
|
@ -49,6 +50,7 @@ const MAIN: u8 = {
|
|||
}
|
||||
struct Ts(pub u8);
|
||||
|
||||
#[allow(auto_impl)]
|
||||
pub impl MarkerTr for .. {} //~ ERROR unnecessary visibility qualifier
|
||||
pub impl Tr for S { //~ ERROR unnecessary visibility qualifier
|
||||
pub fn f() {} //~ ERROR unnecessary visibility qualifier
|
||||
|
@ -80,6 +82,7 @@ fn main() {
|
|||
}
|
||||
struct Ts(pub u8);
|
||||
|
||||
#[allow(auto_impl)]
|
||||
pub impl MarkerTr for .. {} //~ ERROR unnecessary visibility qualifier
|
||||
pub impl Tr for S { //~ ERROR unnecessary visibility qualifier
|
||||
pub fn f() {} //~ ERROR unnecessary visibility qualifier
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
trait Foo {}
|
||||
|
||||
#[allow(auto_impl)]
|
||||
default impl Foo for .. {}
|
||||
//~^ ERROR `default impl` is not allowed for auto trait implementations
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
trait Foo {}
|
||||
|
||||
#[allow(auto_impl)]
|
||||
impl Foo for .. {}
|
||||
|
||||
impl<T> Foo for T {}
|
||||
|
@ -22,6 +23,7 @@ impl !Foo for u8 {} //~ ERROR E0119
|
|||
|
||||
trait Bar {}
|
||||
|
||||
#[allow(auto_impl)]
|
||||
impl Bar for .. {}
|
||||
|
||||
impl<T> !Bar for T {}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
trait MyAutoImpl {}
|
||||
|
||||
#[allow(auto_impl)]
|
||||
impl<T> MyAutoImpl for .. {}
|
||||
//~^ ERROR auto trait implementations are not allowed to have generics
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#![feature(optin_builtin_traits)]
|
||||
|
||||
trait Magic: Copy {} //~ ERROR E0568
|
||||
#[allow(auto_impl)]
|
||||
impl Magic for .. {}
|
||||
|
||||
fn copy<T: Magic>(x: T) -> (T, T) { (x, x) }
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#![feature(optin_builtin_traits)]
|
||||
|
||||
trait Magic : Sized where Option<Self> : Magic {} //~ ERROR E0568
|
||||
#[allow(auto_impl)]
|
||||
impl Magic for .. {}
|
||||
impl<T:Magic> Magic for T {}
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#![feature(optin_builtin_traits)]
|
||||
|
||||
trait Magic: Copy {} //~ ERROR E0568
|
||||
#[allow(auto_impl)]
|
||||
impl Magic for .. {}
|
||||
impl<T:Magic> Magic for T {}
|
||||
|
||||
|
|
|
@ -11,4 +11,5 @@
|
|||
#![feature(optin_builtin_traits)]
|
||||
|
||||
trait Magic<T> {} //~ ERROR E0567
|
||||
#[allow(auto_impl)]
|
||||
impl Magic<isize> for .. {}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
trait MyTrait {}
|
||||
|
||||
#[allow(auto_impl)]
|
||||
impl MyTrait for .. {}
|
||||
|
||||
struct MyS;
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
trait MyTrait {}
|
||||
|
||||
#[allow(auto_impl)]
|
||||
impl MyTrait for .. {}
|
||||
impl<T> !MyTrait for *mut T {}
|
||||
|
||||
|
|
|
@ -12,10 +12,12 @@
|
|||
|
||||
trait MyTrait {}
|
||||
|
||||
#[allow(auto_impl)]
|
||||
impl MyTrait for .. {}
|
||||
|
||||
unsafe trait MyUnsafeTrait {}
|
||||
|
||||
#[allow(auto_impl)]
|
||||
unsafe impl MyUnsafeTrait for .. {}
|
||||
|
||||
struct ThisImplsTrait;
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
#![feature(optin_builtin_traits)]
|
||||
|
||||
#[allow(auto_impl)]
|
||||
impl Copy for .. {} //~ ERROR E0318
|
||||
//~^ NOTE `Copy` trait not defined in this crate
|
||||
fn main() {}
|
||||
|
|
|
@ -81,4 +81,5 @@ pub mod marker {
|
|||
|
||||
#[lang = "freeze"]
|
||||
trait Freeze {}
|
||||
#[allow(auto_impl)]
|
||||
impl Freeze for .. {}
|
||||
|
|
|
@ -19,6 +19,7 @@ trait Sized { }
|
|||
|
||||
#[lang = "freeze"]
|
||||
trait Freeze {}
|
||||
#[allow(auto_impl)]
|
||||
impl Freeze for .. {}
|
||||
|
||||
#[lang="start"]
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
auto trait Auto {}
|
||||
// Redundant but accepted until we remove it.
|
||||
#[allow(auto_impl)]
|
||||
impl Auto for .. {}
|
||||
|
||||
unsafe auto trait AutoUnsafe {}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#![feature(optin_builtin_traits)]
|
||||
|
||||
trait NotSame {}
|
||||
#[allow(auto_impl)]
|
||||
impl NotSame for .. {}
|
||||
impl<A> !NotSame for (A, A) {}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ pub mod bar {
|
|||
|
||||
pub trait Bar {}
|
||||
|
||||
#[allow(auto_impl)]
|
||||
impl Bar for .. {}
|
||||
|
||||
pub trait Foo {
|
||||
|
|
|
@ -12,4 +12,5 @@
|
|||
|
||||
pub trait AnOibit {}
|
||||
|
||||
#[allow(auto_impl)]
|
||||
impl AnOibit for .. {}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
pub trait AnOibit {}
|
||||
|
||||
#[allow(auto_impl)]
|
||||
impl AnOibit for .. {}
|
||||
|
||||
pub struct Foo<T> { field: T }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue