@@ -137,7 +137,7 @@ impl ConstStability {
137
137
pub enum StabilityLevel {
138
138
// Reason for the current stability level and the relevant rust-lang issue
139
139
Unstable { reason : Option < Symbol > , issue : Option < NonZeroU32 > , is_soft : bool } ,
140
- Stable { since : Symbol } ,
140
+ Stable { since : Symbol , allowed_through_unstable_modules : bool } ,
141
141
}
142
142
143
143
impl StabilityLevel {
@@ -172,6 +172,7 @@ where
172
172
let mut stab: Option < ( Stability , Span ) > = None ;
173
173
let mut const_stab: Option < ( ConstStability , Span ) > = None ;
174
174
let mut promotable = false ;
175
+ let mut allowed_through_unstable_modules = false ;
175
176
176
177
let diagnostic = & sess. parse_sess . span_diagnostic ;
177
178
@@ -182,6 +183,7 @@ where
182
183
sym:: unstable,
183
184
sym:: stable,
184
185
sym:: rustc_promotable,
186
+ sym:: rustc_allowed_through_unstable_modules,
185
187
]
186
188
. iter ( )
187
189
. any ( |& s| attr. has_name ( s) )
@@ -193,6 +195,8 @@ where
193
195
194
196
if attr. has_name ( sym:: rustc_promotable) {
195
197
promotable = true ;
198
+ } else if attr. has_name ( sym:: rustc_allowed_through_unstable_modules) {
199
+ allowed_through_unstable_modules = true ;
196
200
}
197
201
// attributes with data
198
202
else if let Some ( MetaItem { kind : MetaItemKind :: List ( ref metas) , .. } ) = meta {
@@ -406,7 +410,7 @@ where
406
410
407
411
match ( feature, since) {
408
412
( Some ( feature) , Some ( since) ) => {
409
- let level = Stable { since } ;
413
+ let level = Stable { since, allowed_through_unstable_modules : false } ;
410
414
if sym:: stable == meta_name {
411
415
stab = Some ( ( Stability { level, feature } , attr. span ) ) ;
412
416
} else {
@@ -447,6 +451,27 @@ where
447
451
}
448
452
}
449
453
454
+ if allowed_through_unstable_modules {
455
+ if let Some ( (
456
+ Stability {
457
+ level : StabilityLevel :: Stable { ref mut allowed_through_unstable_modules, .. } ,
458
+ ..
459
+ } ,
460
+ _,
461
+ ) ) = stab
462
+ {
463
+ * allowed_through_unstable_modules = true ;
464
+ } else {
465
+ struct_span_err ! (
466
+ diagnostic,
467
+ item_sp,
468
+ E0788 ,
469
+ "`rustc_allowed_through_unstable_modules` attribute must be paired with a `stable` attribute"
470
+ )
471
+ . emit ( ) ;
472
+ }
473
+ }
474
+
450
475
( stab, const_stab)
451
476
}
452
477
0 commit comments