Skip to content

Commit

Permalink
Rollup merge of rust-lang#40027 - cramertj:stabilize_static_recursion…
Browse files Browse the repository at this point in the history
…, r=nrc

Stabilize static_recursion

Fix rust-lang#29719.
  • Loading branch information
eddyb authored Feb 25, 2017
2 parents f135040 + 802a826 commit 69e5967
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 94 deletions.
24 changes: 6 additions & 18 deletions src/librustc_passes/static_recursion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use rustc::hir::def::{Def, CtorKind};
use rustc::util::nodemap::{NodeMap, NodeSet};

use syntax::ast;
use syntax::feature_gate::{GateIssue, emit_feature_err};
use syntax_pos::Span;
use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
use rustc::hir;
Expand All @@ -43,7 +42,7 @@ impl<'a, 'hir: 'a> Visitor<'hir> for CheckCrateVisitor<'a, 'hir> {
match it.node {
hir::ItemStatic(..) |
hir::ItemConst(..) => {
let mut recursion_visitor = CheckItemRecursionVisitor::new(self, &it.span);
let mut recursion_visitor = CheckItemRecursionVisitor::new(self);
recursion_visitor.visit_item(it);
}
hir::ItemEnum(ref enum_def, ref generics) => {
Expand All @@ -52,8 +51,7 @@ impl<'a, 'hir: 'a> Visitor<'hir> for CheckCrateVisitor<'a, 'hir> {
// less redundant output.
for variant in &enum_def.variants {
if let Some(_) = variant.node.disr_expr {
let mut recursion_visitor = CheckItemRecursionVisitor::new(self,
&variant.span);
let mut recursion_visitor = CheckItemRecursionVisitor::new(self);
recursion_visitor.populate_enum_discriminants(enum_def);
recursion_visitor.visit_variant(variant, generics, it.id);
}
Expand All @@ -68,7 +66,7 @@ impl<'a, 'hir: 'a> Visitor<'hir> for CheckCrateVisitor<'a, 'hir> {
match ti.node {
hir::TraitItemKind::Const(_, ref default) => {
if let Some(_) = *default {
let mut recursion_visitor = CheckItemRecursionVisitor::new(self, &ti.span);
let mut recursion_visitor = CheckItemRecursionVisitor::new(self);
recursion_visitor.visit_trait_item(ti);
}
}
Expand All @@ -80,7 +78,7 @@ impl<'a, 'hir: 'a> Visitor<'hir> for CheckCrateVisitor<'a, 'hir> {
fn visit_impl_item(&mut self, ii: &'hir hir::ImplItem) {
match ii.node {
hir::ImplItemKind::Const(..) => {
let mut recursion_visitor = CheckItemRecursionVisitor::new(self, &ii.span);
let mut recursion_visitor = CheckItemRecursionVisitor::new(self);
recursion_visitor.visit_impl_item(ii);
}
_ => {}
Expand All @@ -105,7 +103,6 @@ pub fn check_crate<'hir>(sess: &Session, hir_map: &hir_map::Map<'hir>) -> Compil
}

struct CheckItemRecursionVisitor<'a, 'b: 'a, 'hir: 'b> {
root_span: &'b Span,
sess: &'b Session,
hir_map: &'b hir_map::Map<'hir>,
discriminant_map: &'a mut NodeMap<Option<hir::BodyId>>,
Expand All @@ -114,9 +111,8 @@ struct CheckItemRecursionVisitor<'a, 'b: 'a, 'hir: 'b> {
}

impl<'a, 'b: 'a, 'hir: 'b> CheckItemRecursionVisitor<'a, 'b, 'hir> {
fn new(v: &'a mut CheckCrateVisitor<'b, 'hir>, span: &'b Span) -> Self {
fn new(v: &'a mut CheckCrateVisitor<'b, 'hir>) -> Self {
CheckItemRecursionVisitor {
root_span: span,
sess: v.sess,
hir_map: v.hir_map,
discriminant_map: &mut v.discriminant_map,
Expand All @@ -143,15 +139,7 @@ impl<'a, 'b: 'a, 'hir: 'b> CheckItemRecursionVisitor<'a, 'b, 'hir> {
false
}
});
if any_static {
if !self.sess.features.borrow().static_recursion {
emit_feature_err(&self.sess.parse_sess,
"static_recursion",
*self.root_span,
GateIssue::Language,
"recursive static");
}
} else {
if !any_static {
struct_span_err!(self.sess, span, E0265, "recursive constant")
.span_label(span, &format!("recursion not allowed in constant"))
.emit();
Expand Down
5 changes: 2 additions & 3 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,6 @@ declare_features! (
// rustc internal
(active, prelude_import, "1.2.0", None),

// Allows the definition recursive static items.
(active, static_recursion, "1.3.0", Some(29719)),

// Allows default type parameters to influence type inference.
(active, default_type_parameter_fallback, "1.3.0", Some(27336)),

Expand Down Expand Up @@ -391,6 +388,8 @@ declare_features! (
(accepted, static_in_const, "1.17.0", Some(35897)),
// Allows field shorthands (`x` meaning `x: x`) in struct literal expressions.
(accepted, field_init_shorthand, "1.17.0", Some(37340)),
// Allows the definition recursive static items.
(accepted, static_recursion, "1.17.0", Some(29719)),
);
// If you change this, please modify src/doc/unstable-book as well. You must
// move that documentation into the relevant place in the other docs, and
Expand Down
49 changes: 0 additions & 49 deletions src/test/compile-fail/feature-gate-static_recursion.rs

This file was deleted.

2 changes: 0 additions & 2 deletions src/test/compile-fail/issue-3008-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(static_recursion)]

enum foo { foo_(bar) }
struct bar { x: bar }
//~^ ERROR E0072
Expand Down
16 changes: 0 additions & 16 deletions src/test/compile-fail/static-recursion-gate.rs

This file was deleted.

2 changes: 0 additions & 2 deletions src/test/run-pass/issue-2063-resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(static_recursion)]

// test that autoderef of a type like this does not
// cause compiler to loop. Note that no instances
// of such a type could ever be constructed.
Expand Down
2 changes: 0 additions & 2 deletions src/test/run-pass/issue-2063.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(static_recursion)]

// test that autoderef of a type like this does not
// cause compiler to loop. Note that no instances
// of such a type could ever be constructed.
Expand Down
2 changes: 0 additions & 2 deletions src/test/run-pass/static-recursive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(static_recursion)]

static mut S: *const u8 = unsafe { &S as *const *const u8 as *const u8 };

struct StaticDoubleLinked {
Expand Down

0 comments on commit 69e5967

Please sign in to comment.