Skip to content

Commit 6f6609a

Browse files
committed
Discuss #[legacy] attribute
1 parent efad6db commit 6f6609a

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

text/0000-adjust-default-object-bounds.md

+48-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ Box<Trait>` and `&'x Arc<Trait>`. The existing algorithm would default
1010
to `&'x Box<Trait+'x>`. The proposed change is to default to `&'x
1111
Box<Trait+'static>`.
1212

13-
Note: This is a **BREAKING CHANGE**. The change has [been implemented][branch]
14-
and its impact has been evaluated. It was
13+
Adds a `#[legacy(default_object_bounds)]` annotation that can be used
14+
to preserve the current behavior. This annotation is intended to allow
15+
for opt-out as described in [RFC 1122].
16+
17+
Note: This is a **BREAKING CHANGE**. The change has
18+
[been implemented][branch] and its impact has been evaluated. It was
1519
[found to cause no root regressions][crater] on `crates.io`.
1620

1721
# Motivation
@@ -98,6 +102,23 @@ defaults can be actively harmful, and hence force you to specify
98102
explicit lifetimes, whereas the newer defaults do something
99103
reasonable.
100104

105+
### Opting out
106+
107+
Even though the current defaults are judged to be suboptimal, some
108+
code out there may be relying on them. To make it easier to transition
109+
to Rust 1.1, we therefore add the option to "revert" to the older
110+
defaults by adding a `#[legacy]` attribute to the crate:
111+
112+
```rust
113+
#![legacy(default_object_bounds)]
114+
115+
mod foo;
116+
mod bar;
117+
```
118+
119+
The `#[legacy]` attribute is designed to allow for more opt-outs in
120+
the future, as discussed in [RFC 1122].
121+
101122
# Detailed design
102123

103124
The rules for user-defined types from RFC 599 are altered as follows
@@ -123,6 +144,30 @@ The rules for user-defined types from RFC 599 are altered as follows
123144
required. There are no known examples of this in the standard
124145
library as this situation arises rarely in practice.*
125146

147+
## Legacy annotation for opting out
148+
149+
RFC 1122 suggested that, at times, it would be appropriate to include
150+
an *opt-out* provision that allows users to restore older behavior, to
151+
ease transition to the new rules. An opt-out provision makes it easy
152+
to restore a crate to working order quickly.
153+
154+
This RFC proposes an attribute `#[legacy(...)]`. This attribute can be
155+
placed at any place in the tree and with any arguments -- however, if
156+
it is placed in an unexpected location, or with unexpected arguments,
157+
a lint warning (unused attribute) will be signaled. It is important
158+
that we never signal errors so as to allow new legacy opt-outs to be
159+
added in the future without causing older compilers to break
160+
(unfortunately, the 1.0 compiler will still reject the legacy
161+
annotation, but adding this change now lays the groundwork for the
162+
future).
163+
164+
With regard to this specific change, the annotation
165+
`#![legacy(default_object_bounds)]` will be accepted at the crate
166+
level (and only at the crate level). It will cause the older rules to
167+
be applied. This legacy opt-out is not time-limited and will be
168+
available indefinitely (this poses very little maintenance burden in
169+
the compiler). Any other use will yield a lint error.
170+
126171
# Timing and breaking change implications
127172

128173
This is a breaking change, and hence it behooves us to evaluate the
@@ -227,3 +272,4 @@ to contain borrowed data".
227272
[crater]: https://gist.github.com/brson/085d84d43c6a9a8d4dc3
228273
[branch]: https://github.com/nikomatsakis/rust/tree/better-object-defaults
229274
[previous run]: https://gist.github.com/brson/80f9b80acef2e7ab37ee
275+
[RFC 1122]: https://github.com/rust-lang/rfcs/pull/1122

0 commit comments

Comments
 (0)