Skip to content

Commit bd5628d

Browse files
committed
Update the compiler itself to use #[rustc_auto_trait]
1 parent 0ea5146 commit bd5628d

File tree

14 files changed

+81
-41
lines changed

14 files changed

+81
-41
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2993,7 +2993,7 @@ pub enum ItemKind {
29932993
Union(VariantData, Generics),
29942994
/// A trait declaration (`trait`).
29952995
///
2996-
/// E.g., `trait Foo { .. }`, `trait Foo<T> { .. }` or `auto trait Foo {}`.
2996+
/// E.g., `trait Foo { .. }`, `trait Foo<T> { .. }`.
29972997
Trait(Box<Trait>),
29982998
/// Trait alias
29992999
///

compiler/rustc_data_structures/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
1010
#![feature(array_windows)]
1111
#![feature(associated_type_bounds)]
12-
#![feature(auto_traits)]
12+
#![cfg_attr(bootstrap, feature(auto_traits))]
1313
#![feature(cell_leak)]
1414
#![feature(core_intrinsics)]
1515
#![feature(extend_one)]

compiler/rustc_data_structures/src/marker.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,57 @@
11
cfg_if!(
22
if #[cfg(not(parallel_compiler))] {
3+
#[cfg(bootstrap)]
34
pub auto trait DynSend {}
5+
6+
#[cfg(not(bootstrap))]
7+
#[rustc_auto_trait]
8+
pub trait DynSend {}
9+
10+
#[cfg(bootstrap)]
411
pub auto trait DynSync {}
512

13+
#[cfg(not(bootstrap))]
14+
#[rustc_auto_trait]
15+
pub trait DynSync {}
16+
617
impl<T> DynSend for T {}
718
impl<T> DynSync for T {}
819
} else {
20+
#[cfg(bootstrap)]
21+
#[rustc_on_unimplemented(
22+
message = "`{Self}` doesn't implement `DynSend`. \
23+
Add it to `rustc_data_structures::marker` or use `IntoDynSyncSend` if it's already `Send`"
24+
)]
25+
pub unsafe auto trait DynSend {}
26+
27+
#[cfg(not(bootstrap))]
928
#[rustc_on_unimplemented(
1029
message = "`{Self}` doesn't implement `DynSend`. \
1130
Add it to `rustc_data_structures::marker` or use `IntoDynSyncSend` if it's already `Send`"
1231
)]
32+
#[rustc_auto_trait]
1333
// This is an auto trait for types which can be sent across threads if `sync::is_dyn_thread_safe()`
1434
// is true. These types can be wrapped in a `FromDyn` to get a `Send` type. Wrapping a
1535
// `Send` type in `IntoDynSyncSend` will create a `DynSend` type.
16-
pub unsafe auto trait DynSend {}
36+
pub unsafe trait DynSend {}
37+
38+
#[cfg(bootstrap)]
39+
#[rustc_on_unimplemented(
40+
message = "`{Self}` doesn't implement `DynSync`. \
41+
Add it to `rustc_data_structures::marker` or use `IntoDynSyncSend` if it's already `Sync`"
42+
)]
43+
pub unsafe auto trait DynSync {}
1744

45+
#[cfg(not(bootstrap))]
1846
#[rustc_on_unimplemented(
1947
message = "`{Self}` doesn't implement `DynSync`. \
2048
Add it to `rustc_data_structures::marker` or use `IntoDynSyncSend` if it's already `Sync`"
2149
)]
50+
#[rustc_auto_trait]
2251
// This is an auto trait for types which can be shared across threads if `sync::is_dyn_thread_safe()`
2352
// is true. These types can be wrapped in a `FromDyn` to get a `Sync` type. Wrapping a
2453
// `Sync` type in `IntoDynSyncSend` will create a `DynSync` type.
25-
pub unsafe auto trait DynSync {}
54+
pub unsafe trait DynSync {}
2655

2756
// Same with `Sync` and `Send`.
2857
unsafe impl<T: DynSync + ?Sized> DynSend for &T {}

compiler/rustc_data_structures/src/sync.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,17 @@ cfg_if! {
114114
use std::ops::Add;
115115
use std::cell::Cell;
116116

117+
#[cfg(bootstrap)]
117118
pub unsafe auto trait Send {}
119+
#[cfg(not(bootstrap))]
120+
#[rustc_auto_trait]
121+
pub unsafe trait Send {}
122+
123+
#[cfg(bootstrap)]
118124
pub unsafe auto trait Sync {}
125+
#[cfg(not(bootstrap))]
126+
#[rustc_auto_trait]
127+
pub unsafe trait Sync {}
119128

120129
unsafe impl<T> Send for T {}
121130
unsafe impl<T> Sync for T {}

compiler/rustc_error_codes/src/error_codes/E0198.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@ unsafe.
1515

1616
This will compile:
1717

18-
```ignore (ignore auto_trait future compatibility warning)
19-
#![feature(auto_traits)]
18+
```
19+
#![feature(negative_impls)]
2020
2121
struct Foo;
2222
23-
auto trait Enterprise {}
23+
trait Enterprise {}
2424
2525
impl !Enterprise for Foo { }
2626
```
27-
28-
Please note that negative impls are only allowed for auto traits.
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
A cross-crate opt-out trait was implemented on something which wasn't a struct
1+
A cross-crate auto trait was implemented on something which wasn't a struct
22
or enum type.
33

44
Erroneous code example:
55

66
```compile_fail,E0321
7-
#![feature(auto_traits)]
8-
97
struct Foo;
108
119
impl !Sync for Foo {}
@@ -16,6 +14,6 @@ unsafe impl Send for &'static Foo {}
1614
// `&'static Foo`
1715
```
1816

19-
Only structs and enums are permitted to impl Send, Sync, and other opt-out
17+
Only structs and enums are permitted to impl Send, Sync, and other auto
2018
trait, and the struct or enum must be local to the current crate. So, for
2119
example, `unsafe impl Send for Rc<Foo>` is not allowed.

compiler/rustc_error_codes/src/error_codes/E0380.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ An auto trait was declared with a method or an associated item.
33
Erroneous code example:
44

55
```compile_fail,E0380
6-
unsafe auto trait Trait {
6+
#[rustc_auto_trait]
7+
unsafe trait Trait {
78
type Output; // error!
89
}
910
```

compiler/rustc_error_codes/src/error_codes/E0567.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ Generics have been used on an auto trait.
33
Erroneous code example:
44

55
```compile_fail,E0567
6-
#![feature(auto_traits)]
6+
#![feature(rustc_attrs)]
77
8-
auto trait Generic<T> {} // error!
8+
#[rustc_auto_trait]
9+
trait Generic<T> {} // error!
910
# fn main() {}
1011
```
1112

@@ -16,8 +17,9 @@ parameters.
1617
To fix this issue, just remove the generics:
1718

1819
```
19-
#![feature(auto_traits)]
20+
#![feature(rustc_attrs)]
2021
21-
auto trait Generic {} // ok!
22+
#[rustc_auto_trait]
23+
trait Generic {} // ok!
2224
# fn main() {}
2325
```

compiler/rustc_error_codes/src/error_codes/E0568.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ A super trait has been added to an auto trait.
33
Erroneous code example:
44

55
```compile_fail,E0568
6-
#![feature(auto_traits)]
6+
#![feature(rustc_attrs)]
77
8-
auto trait Bound : Copy {} // error!
8+
#[rustc_auto_trait]
9+
trait Bound : Copy {} // error!
910
1011
fn main() {}
1112
```
@@ -18,9 +19,10 @@ all the existing types could implement `Bound` because very few of them have the
1819
To fix this issue, just remove the super trait:
1920

2021
```
21-
#![feature(auto_traits)]
22+
#![feature(rustc_attrs)]
2223
23-
auto trait Bound {} // ok!
24+
#[rustc_auto_trait]
25+
trait Bound {} // ok!
2426
2527
fn main() {}
2628
```

compiler/rustc_error_codes/src/error_codes/E0785.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ An inherent `impl` was written on a dyn auto trait.
33
Erroneous code example:
44

55
```compile_fail,E0785
6-
#![feature(auto_traits)]
6+
#![feature(rustc_attrs)]
77
8-
auto trait AutoTrait {}
8+
#[rustc_auto_trait]
9+
trait AutoTrait {}
910
1011
impl dyn AutoTrait {}
1112
```
@@ -20,11 +21,12 @@ trait, it cannot be implemented at all.
2021
Working example:
2122

2223
```
23-
#![feature(auto_traits)]
24+
#![feature(rustc_attrs)]
2425
2526
trait PrincipalTrait {}
2627
27-
auto trait AutoTrait {}
28+
#[rustc_auto_trait]
29+
trait AutoTrait {}
2830
2931
impl dyn PrincipalTrait + AutoTrait + Send {}
3032
```

0 commit comments

Comments
 (0)