Skip to content

Commit f5edbe9

Browse files
varkorAvi-D-coder
authored andcommitted
Encode stability for default generic parameters
1 parent 4f27d22 commit f5edbe9

File tree

5 files changed

+39
-11
lines changed

5 files changed

+39
-11
lines changed

src/librustc_metadata/rmeta/encoder.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,9 +1579,13 @@ impl EncodeContext<'tcx> {
15791579
EntryKind::TypeParam,
15801580
default.is_some(),
15811581
);
1582+
if default.is_some() {
1583+
self.encode_stability(def_id);
1584+
}
15821585
}
15831586
GenericParamKind::Const { .. } => {
15841587
self.encode_info_for_generic_param(def_id, EntryKind::ConstParam, true);
1588+
// FIXME(const_generics:defaults)
15851589
}
15861590
}
15871591
}

src/librustc_passes/stability.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,10 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
138138
} else {
139139
debug!("annotate: not found, parent = {:?}", self.parent_stab);
140140
if let Some(stab) = self.parent_stab {
141-
// Instability (but not typically stability) is inherited from the parent.
142-
// If something is unstable, everything inside it should also be
143-
// considered unstable.
144-
// `AnnotationKind::Optional` items also inherit stability, as they may be
145-
// considered stable-by-default items, requiring an instability attribute to
146-
// override this.
147-
if stab.level.is_unstable() || kind == AnnotationKind::Optional {
141+
// Instability is inherited from the parent: if something is unstable,
142+
// everything inside it should also be considered unstable for the same
143+
// reason.
144+
if stab.level.is_unstable() {
148145
self.index.stab_map.insert(hir_id, stab);
149146
}
150147
}
@@ -176,7 +173,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
176173
// Propagate unstability. This can happen even for non-staged-api crates in case
177174
// -Zforce-unstable-if-unmarked is set.
178175
if let Some(stab) = self.parent_stab {
179-
if stab.level.is_unstable() || kind == AnnotationKind::Optional {
176+
if stab.level.is_unstable() {
180177
self.index.stab_map.insert(hir_id, stab);
181178
}
182179
}

src/test/ui/stability-attribute/auxiliary/unstable_generic_param.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44
#![stable(feature = "stable_test_feature", since = "1.0.0")]
55

66
#[stable(feature = "stable_test_feature", since = "1.0.0")]
7-
pub trait Trait<#[unstable(feature = "ty", issue = "none")] T = ()> {
7+
pub trait Trait1<#[unstable(feature = "unstable_default", issue = "none")] T = ()> {
8+
#[stable(feature = "stable_test_feature", since = "1.0.0")]
9+
fn foo() -> T;
10+
}
11+
12+
#[stable(feature = "stable_test_feature", since = "1.0.0")]
13+
pub trait Trait2<T = ()> {
814
#[stable(feature = "stable_test_feature", since = "1.0.0")]
915
fn foo() -> T;
1016
}

src/test/ui/stability-attribute/generics-default-stability.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,24 @@
22

33
extern crate unstable_generic_param;
44

5-
use unstable_generic_param::Trait;
5+
use unstable_generic_param::{Trait1, Trait2};
6+
7+
struct R;
8+
9+
impl Trait1 for S {
10+
fn foo() -> () { () } // ok
11+
}
612

713
struct S;
814

9-
impl Trait<usize> for S {
15+
impl Trait1<usize> for S { //~ ERROR use of unstable library feature 'unstable_default'
1016
fn foo() -> usize { 0 }
1117
}
1218

19+
impl Trait2<usize> for S {
20+
fn foo() -> usize { 0 } // ok
21+
}
22+
1323
fn main() {
1424
let _ = S;
1525
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0658]: use of unstable library feature 'unstable_default'
2+
--> $DIR/generics-default-stability.rs:15:13
3+
|
4+
LL | impl Trait1<usize> for S {
5+
| ^^^^^
6+
|
7+
= help: add `#![feature(unstable_default)]` to the crate attributes to enable
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0658`.

0 commit comments

Comments
 (0)