Skip to content

Commit

Permalink
Rollup merge of rust-lang#36147 - mikhail-m1:master, r=jonathandturner
Browse files Browse the repository at this point in the history
update E0265 to new format

Fixes rust-lang#35309 as part of rust-lang#35233.
I've describe partially bonus achieve in rust-lang#35309

r? @jonathandturner
  • Loading branch information
Jonathan Turner authored Aug 31, 2016
2 parents 5123b38 + 507fe14 commit 441cb87
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/librustc_passes/static_recursion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl<'a, 'ast: 'a> CheckItemRecursionVisitor<'a, 'ast> {
idstack: Vec::new(),
}
}
fn with_item_id_pushed<F>(&mut self, id: ast::NodeId, f: F)
fn with_item_id_pushed<F>(&mut self, id: ast::NodeId, f: F, span: Span)
where F: Fn(&mut Self)
{
if self.idstack.iter().any(|&x| x == id) {
Expand All @@ -150,7 +150,9 @@ impl<'a, 'ast: 'a> CheckItemRecursionVisitor<'a, 'ast> {
"recursive static");
}
} else {
span_err!(self.sess, *self.root_span, E0265, "recursive constant");
struct_span_err!(self.sess, span, E0265, "recursive constant")
.span_label(span, &format!("recursion not allowed in constant"))
.emit();
}
return;
}
Expand Down Expand Up @@ -203,7 +205,7 @@ impl<'a, 'ast: 'a> CheckItemRecursionVisitor<'a, 'ast> {

impl<'a, 'ast: 'a> Visitor<'ast> for CheckItemRecursionVisitor<'a, 'ast> {
fn visit_item(&mut self, it: &'ast hir::Item) {
self.with_item_id_pushed(it.id, |v| intravisit::walk_item(v, it));
self.with_item_id_pushed(it.id, |v| intravisit::walk_item(v, it), it.span);
}

fn visit_enum_def(&mut self,
Expand Down Expand Up @@ -233,16 +235,16 @@ impl<'a, 'ast: 'a> Visitor<'ast> for CheckItemRecursionVisitor<'a, 'ast> {
// If `maybe_expr` is `None`, that's because no discriminant is
// specified that affects this variant. Thus, no risk of recursion.
if let Some(expr) = maybe_expr {
self.with_item_id_pushed(expr.id, |v| intravisit::walk_expr(v, expr));
self.with_item_id_pushed(expr.id, |v| intravisit::walk_expr(v, expr), expr.span);
}
}

fn visit_trait_item(&mut self, ti: &'ast hir::TraitItem) {
self.with_item_id_pushed(ti.id, |v| intravisit::walk_trait_item(v, ti));
self.with_item_id_pushed(ti.id, |v| intravisit::walk_trait_item(v, ti), ti.span);
}

fn visit_impl_item(&mut self, ii: &'ast hir::ImplItem) {
self.with_item_id_pushed(ii.id, |v| intravisit::walk_impl_item(v, ii));
self.with_item_id_pushed(ii.id, |v| intravisit::walk_impl_item(v, ii), ii.span);
}

fn visit_expr(&mut self, e: &'ast hir::Expr) {
Expand Down
8 changes: 8 additions & 0 deletions src/test/compile-fail/issue-23302.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,21 @@
// the appropriate error (rather than, say, blowing the stack).
enum X {
A = X::A as isize, //~ ERROR E0265
//~^ NOTE recursion not allowed in constant
}

// Since `Y::B` here defaults to `Y::A+1`, this is also a
// recursive definition.
enum Y {
A = Y::B as isize, //~ ERROR E0265
//~^ NOTE recursion not allowed in constant
B,
}

const A: i32 = B; //~ ERROR E0265
//~^ NOTE recursion not allowed in constant

const B: i32 = A; //~ ERROR E0265
//~^ NOTE recursion not allowed in constant

fn main() { }

0 comments on commit 441cb87

Please sign in to comment.