Skip to content

Commit 8b586e6

Browse files
committed
auto trait future compatibility lint
1 parent 0d1b79a commit 8b586e6

31 files changed

+90
-1
lines changed

src/libcore/marker.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ pub unsafe trait Send {
4646
}
4747

4848
#[stable(feature = "rust1", since = "1.0.0")]
49+
#[allow(unknown_lints)]
50+
#[allow(auto_impl)]
4951
unsafe impl Send for .. { }
5052

5153
#[stable(feature = "rust1", since = "1.0.0")]
@@ -349,6 +351,8 @@ pub unsafe trait Sync {
349351
}
350352

351353
#[stable(feature = "rust1", since = "1.0.0")]
354+
#[allow(unknown_lints)]
355+
#[allow(auto_impl)]
352356
unsafe impl Sync for .. { }
353357

354358
#[stable(feature = "rust1", since = "1.0.0")]
@@ -562,6 +566,8 @@ mod impls {
562566
#[lang = "freeze"]
563567
unsafe trait Freeze {}
564568

569+
#[allow(unknown_lints)]
570+
#[allow(auto_impl)]
565571
unsafe impl Freeze for .. {}
566572

567573
impl<T: ?Sized> !Freeze for UnsafeCell<T> {}

src/librustc_lint/builtin.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,31 @@ use bad_style::{MethodLateContext, method_context};
5555
// hardwired lints from librustc
5656
pub use lint::builtin::*;
5757

58+
declare_lint! {
59+
pub AUTO_IMPL,
60+
Deny,
61+
"The form `impl Foo for .. {}` will be removed, please use `auto trait Foo {}`"
62+
}
63+
64+
#[derive(Copy, Clone)]
65+
pub struct AutoImpl;
66+
67+
impl LintPass for AutoImpl {
68+
fn get_lints(&self) -> LintArray {
69+
lint_array!(AUTO_IMPL)
70+
}
71+
}
72+
73+
impl EarlyLintPass for AutoImpl {
74+
fn check_item(&mut self, cx: &EarlyContext, item: &ast::Item) {
75+
let msg = "The form `impl Foo for .. {}` will be removed, please use `auto trait Foo {}`";
76+
match item.node {
77+
ast::ItemKind::AutoImpl(..) => cx.span_lint(AUTO_IMPL, item.span, msg),
78+
_ => ()
79+
}
80+
}
81+
}
82+
5883
declare_lint! {
5984
WHILE_TRUE,
6085
Warn,

src/librustc_lint/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
109109
AnonymousParameters,
110110
IllegalFloatLiteralPattern,
111111
UnusedDocComment,
112+
AutoImpl,
112113
);
113114

114115
add_early_builtin_with_new!(sess,
@@ -181,6 +182,10 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
181182
// - Eventually, remove lint
182183
store.register_future_incompatible(sess,
183184
vec![
185+
FutureIncompatibleInfo {
186+
id: LintId::of(AUTO_IMPL),
187+
reference: "issue #13231 <https://github.com/rust-lang/rust/issues/13231>",
188+
},
184189
FutureIncompatibleInfo {
185190
id: LintId::of(PRIVATE_IN_PUBLIC),
186191
reference: "issue #34537 <https://github.com/rust-lang/rust/issues/34537>",

src/libstd/panic.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ pub struct AssertUnwindSafe<T>(
188188
// * Types like Mutex/RwLock which are explicilty poisoned are unwind safe
189189
// * Our custom AssertUnwindSafe wrapper is indeed unwind safe
190190
#[stable(feature = "catch_unwind", since = "1.9.0")]
191+
#[allow(unknown_lints)]
192+
#[allow(auto_impl)]
191193
impl UnwindSafe for .. {}
192194
#[stable(feature = "catch_unwind", since = "1.9.0")]
193195
impl<'a, T: ?Sized> !UnwindSafe for &'a mut T {}
@@ -221,6 +223,8 @@ impl<T: RefUnwindSafe + ?Sized> UnwindSafe for Arc<T> {}
221223
// only thing which doesn't implement it (which then transitively applies to
222224
// everything else).
223225
#[stable(feature = "catch_unwind", since = "1.9.0")]
226+
#[allow(unknown_lints)]
227+
#[allow(auto_impl)]
224228
impl RefUnwindSafe for .. {}
225229
#[stable(feature = "catch_unwind", since = "1.9.0")]
226230
impl<T: ?Sized> !RefUnwindSafe for UnsafeCell<T> {}

src/rtstartup/rsbegin.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// When an executable or dylib image is linked, all user code and libraries are
1515
// "sandwiched" between these two object files, so code or data from rsbegin.o
1616
// become first in the respective sections of the image, whereas code and data
17-
// from rsend.o become the last ones. This effect can be used to place symbols
17+
// from rsend.o become the last ones. This effect can be used to place symbols
1818
// at the beginning or at the end of a section, as well as to insert any required
1919
// headers or footers.
2020
//
@@ -31,11 +31,15 @@
3131
trait Sized {}
3232
#[lang = "sync"]
3333
trait Sync {}
34+
#[allow(unknown_lints)]
35+
#[allow(auto_impl)]
3436
impl Sync for .. {}
3537
#[lang = "copy"]
3638
trait Copy {}
3739
#[lang = "freeze"]
3840
trait Freeze {}
41+
#[allow(unknown_lints)]
42+
#[allow(auto_impl)]
3943
impl Freeze for .. {}
4044

4145
#[lang = "drop_in_place"]

src/rtstartup/rsend.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ impl<T> Sync for T {}
2323
trait Copy {}
2424
#[lang = "freeze"]
2525
trait Freeze {}
26+
#[allow(unknown_lints)]
27+
#[allow(auto_impl)]
2628
impl Freeze for .. {}
2729

2830
#[lang = "drop_in_place"]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
trait Foo {}
12+
impl Foo for .. {}

src/test/compile-fail/coherence-default-trait-impl.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,22 @@
1212

1313
trait MyTrait { fn foo() {} }
1414

15+
#[allow(auto_impl)]
1516
impl MyTrait for .. {}
1617
//~^ ERROR redundant auto implementations of trait `MyTrait`
1718

19+
#[allow(auto_impl)]
1820
impl MyTrait for .. {}
1921

2022
trait MySafeTrait {}
2123

24+
#[allow(auto_impl)]
2225
unsafe impl MySafeTrait for .. {}
2326
//~^ ERROR implementing the trait `MySafeTrait` is not unsafe
2427

2528
unsafe trait MyUnsafeTrait {}
2629

30+
#[allow(auto_impl)]
2731
impl MyUnsafeTrait for .. {}
2832
//~^ ERROR the trait `MyUnsafeTrait` requires an `unsafe impl` declaration
2933

src/test/compile-fail/feature-gate-optin-builtin-traits.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ trait DummyTrait {
2020
auto trait AutoDummyTrait {}
2121
//~^ ERROR auto traits are experimental and possibly buggy
2222

23+
#[allow(auto_impl)]
2324
impl DummyTrait for .. {}
2425
//~^ ERROR auto trait implementations are experimental and possibly buggy
2526

src/test/compile-fail/issue-23080-2.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ unsafe trait Trait {
1717
type Output;
1818
}
1919

20+
#[allow(auto_impl)]
2021
unsafe impl Trait for .. {}
2122

2223
fn call_method<T: Trait>(x: T) {}

0 commit comments

Comments
 (0)