Skip to content

Commit 2a9e6c5

Browse files
committed
Update the compiler itself to use #[rustc_auto_trait]
1 parent 3482d13 commit 2a9e6c5

File tree

13 files changed

+72
-27
lines changed

13 files changed

+72
-27
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_ast_passes/src/ast_validation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
935935
}
936936
}
937937
}
938-
// We intentionally ignore `is_auto` since `auto trait` is now meaningless.
938+
// We intentionally ignore `is_auto` since `auto` is now meaningless.
939939
ItemKind::Trait(box Trait { is_auto: _, generics, bounds, items, .. }) => {
940940
if attr::contains_name(&item.attrs, sym::rustc_auto_trait) {
941941
// Auto traits cannot have generics, super traits nor contain items.

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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ This will compile:
2020
2121
struct Foo;
2222
23-
auto trait Enterprise {}
23+
#[rustc_auto_trait]
24+
trait Enterprise {}
2425
2526
impl !Enterprise for Foo { }
2627
```

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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ Erroneous code example:
55
```compile_fail,E0567
66
#![feature(auto_traits)]
77
8-
auto trait Generic<T> {} // error!
8+
#[rustc_auto_trait]
9+
trait Generic<T> {} // error!
910
# fn main() {}
1011
```
1112

@@ -18,6 +19,7 @@ To fix this issue, just remove the generics:
1819
```
1920
#![feature(auto_traits)]
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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ Erroneous code example:
55
```compile_fail,E0568
66
#![feature(auto_traits)]
77
8-
auto trait Bound : Copy {} // error!
8+
#[rustc_auto_trait]
9+
trait Bound : Copy {} // error!
910
1011
fn main() {}
1112
```
@@ -20,7 +21,8 @@ To fix this issue, just remove the super trait:
2021
```
2122
#![feature(auto_traits)]
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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ Erroneous code example:
55
```compile_fail,E0785
66
#![feature(auto_traits)]
77
8-
auto trait AutoTrait {}
8+
#[rustc_auto_trait]
9+
trait AutoTrait {}
910
1011
impl dyn AutoTrait {}
1112
```
@@ -24,7 +25,8 @@ Working example:
2425
2526
trait PrincipalTrait {}
2627
27-
auto trait AutoTrait {}
28+
#[rustc_auto_trait]
29+
trait AutoTrait {}
2830
2931
impl dyn PrincipalTrait + AutoTrait + Send {}
3032
```

compiler/rustc_hir_analysis/src/coherence/orphan.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ fn do_orphan_check_impl<'tcx>(
7171
//
7272
// ```
7373
// // Crate A
74-
// auto trait Foo { }
74+
// #[rustc_auto_trait]
75+
// trait Foo { }
7576
// fn two_foos<A:Foo,B:Foo>(..) {
7677
// one_foo::<(A,B)>(..)
7778
// }
@@ -127,7 +128,8 @@ fn do_orphan_check_impl<'tcx>(
127128
// This is necessary in order for autotrait bounds on methods of trait
128129
// objects to be sound.
129130
//
130-
// auto trait AutoTrait {}
131+
// #[rustc_auto_trait]
132+
// trait AutoTrait {}
131133
//
132134
// trait ObjectSafeTrait {
133135
// fn f(&self) where Self: AutoTrait;

0 commit comments

Comments
 (0)