@@ -10,8 +10,12 @@ Box<Trait>` and `&'x Arc<Trait>`. The existing algorithm would default
10
10
to ` &'x Box<Trait+'x> ` . The proposed change is to default to `&'x
11
11
Box<Trait+'static>`.
12
12
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
15
19
[ found to cause no root regressions] [ crater ] on ` crates.io ` .
16
20
17
21
# Motivation
@@ -98,6 +102,23 @@ defaults can be actively harmful, and hence force you to specify
98
102
explicit lifetimes, whereas the newer defaults do something
99
103
reasonable.
100
104
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
+
101
122
# Detailed design
102
123
103
124
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
123
144
required. There are no known examples of this in the standard
124
145
library as this situation arises rarely in practice.*
125
146
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
+
126
171
# Timing and breaking change implications
127
172
128
173
This is a breaking change, and hence it behooves us to evaluate the
@@ -227,3 +272,4 @@ to contain borrowed data".
227
272
[ crater ] : https://gist.github.com/brson/085d84d43c6a9a8d4dc3
228
273
[ branch ] : https://github.com/nikomatsakis/rust/tree/better-object-defaults
229
274
[ previous run ] : https://gist.github.com/brson/80f9b80acef2e7ab37ee
275
+ [ RFC 1122 ] : https://github.com/rust-lang/rfcs/pull/1122
0 commit comments