Skip to content

Commit 20cfb59

Browse files
varkorAvi-D-coder
andcommitted
Make default type parameter stability optional
Co-Authored-By: Avi Dessauer <[email protected]>
1 parent 1519c0a commit 20cfb59

File tree

3 files changed

+8
-30
lines changed

3 files changed

+8
-30
lines changed

src/librustc_passes/reachable.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,6 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
309309
| Node::Ctor(..)
310310
| Node::Field(_)
311311
| Node::Ty(_)
312-
| Node::GenericParam(_)
313312
| Node::MacroDef(_) => {}
314313
_ => {
315314
bug!(

src/librustc_passes/stability.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ enum AnnotationKind {
3232
Required,
3333
// Annotation is useless: reject it.
3434
Prohibited,
35-
// Annotation itself is useless, but it can be propagated to children.
36-
Container,
35+
// Annotation is optional. Stability can be propagated to children.
36+
Optional,
3737
}
3838

3939
// A private tree-walker for producing an index.
@@ -77,7 +77,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
7777
if let Some(mut stab) = stab {
7878
// Error if prohibited, or can't inherit anything from a container.
7979
if kind == AnnotationKind::Prohibited
80-
|| (kind == AnnotationKind::Container
80+
|| (kind == AnnotationKind::Optional
8181
&& stab.level.is_stable()
8282
&& stab.rustc_depr.is_none())
8383
{
@@ -222,7 +222,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
222222
// optional. They inherit stability from their parents when unannotated.
223223
hir::ItemKind::Impl { of_trait: None, .. } | hir::ItemKind::ForeignMod(..) => {
224224
self.in_trait_impl = false;
225-
kind = AnnotationKind::Container;
225+
kind = AnnotationKind::Optional;
226226
}
227227
hir::ItemKind::Impl { of_trait: Some(_), .. } => {
228228
self.in_trait_impl = true;
@@ -283,7 +283,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
283283
let kind = match &p.kind {
284284
// FIXME(const_generics:defaults)
285285
hir::GenericParamKind::Type { default, .. } if default.is_some() => {
286-
AnnotationKind::Required
286+
AnnotationKind::Optional
287287
}
288288
_ => AnnotationKind::Prohibited,
289289
};
@@ -363,16 +363,9 @@ impl<'a, 'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'a, 'tcx> {
363363
self.check_missing_stability(md.hir_id, md.span, "macro");
364364
}
365365

366-
fn visit_generic_param(&mut self, p: &'tcx hir::GenericParam<'tcx>) {
367-
match &p.kind {
368-
// FIXME(const_generics:defaults)
369-
hir::GenericParamKind::Type { default, .. } if default.is_some() => {
370-
self.check_missing_stability(p.hir_id, p.span, "default type parameter");
371-
}
372-
_ => {}
373-
}
374-
intravisit::walk_generic_param(self, p);
375-
}
366+
// Note that we don't need to `check_missing_stability` for default generic parameters,
367+
// as we assume that any default generic parameters without attributes are automatically
368+
// stable (assuming they have not inherited instability from their parent).
376369
}
377370

378371
fn new_index(tcx: TyCtxt<'tcx>) -> Index<'tcx> {

src/librustc_privacy/lib.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -946,20 +946,6 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
946946
module_id = self.tcx.hir().get_parent_node(module_id);
947947
}
948948
}
949-
950-
fn visit_generic_param(&mut self, p: &'tcx hir::GenericParam<'tcx>) {
951-
// Generic parameters cannot be directly accessed by users, so restricting privacy is
952-
// unimportant here.
953-
// However, parameters must be (at least) `Reachable` in order for stability requirements to
954-
// be enforced (see `check_missing_stability` in `src/librustc_passes/stability.rs`).
955-
match &p.kind {
956-
// FIXME(const_generics:defaults)
957-
hir::GenericParamKind::Type { default, .. } if default.is_some() => {
958-
self.update(p.hir_id, Some(AccessLevel::Reachable));
959-
}
960-
_ => {}
961-
}
962-
}
963949
}
964950

965951
impl ReachEverythingInTheInterfaceVisitor<'_, 'tcx> {

0 commit comments

Comments
 (0)