@@ -137,7 +137,7 @@ impl ConstStability {
137137pub enum StabilityLevel {
138138 // Reason for the current stability level and the relevant rust-lang issue
139139 Unstable { reason : Option < Symbol > , issue : Option < NonZeroU32 > , is_soft : bool } ,
140- Stable { since : Symbol } ,
140+ Stable { since : Symbol , allowed_through_unstable_modules : bool } ,
141141}
142142
143143impl StabilityLevel {
@@ -172,6 +172,7 @@ where
172172 let mut stab: Option < ( Stability , Span ) > = None ;
173173 let mut const_stab: Option < ( ConstStability , Span ) > = None ;
174174 let mut promotable = false ;
175+ let mut allowed_through_unstable_modules = false ;
175176
176177 let diagnostic = & sess. parse_sess . span_diagnostic ;
177178
@@ -182,6 +183,7 @@ where
182183 sym:: unstable,
183184 sym:: stable,
184185 sym:: rustc_promotable,
186+ sym:: rustc_allowed_through_unstable_modules,
185187 ]
186188 . iter ( )
187189 . any ( |& s| attr. has_name ( s) )
@@ -193,6 +195,8 @@ where
193195
194196 if attr. has_name ( sym:: rustc_promotable) {
195197 promotable = true ;
198+ } else if attr. has_name ( sym:: rustc_allowed_through_unstable_modules) {
199+ allowed_through_unstable_modules = true ;
196200 }
197201 // attributes with data
198202 else if let Some ( MetaItem { kind : MetaItemKind :: List ( ref metas) , .. } ) = meta {
@@ -406,7 +410,7 @@ where
406410
407411 match ( feature, since) {
408412 ( Some ( feature) , Some ( since) ) => {
409- let level = Stable { since } ;
413+ let level = Stable { since, allowed_through_unstable_modules : false } ;
410414 if sym:: stable == meta_name {
411415 stab = Some ( ( Stability { level, feature } , attr. span ) ) ;
412416 } else {
@@ -447,6 +451,27 @@ where
447451 }
448452 }
449453
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+
450475 ( stab, const_stab)
451476}
452477
0 commit comments