Rollup merge of #36147 - mikhail-m1:master, r=jonathandturner
update E0265 to new format Fixes #35309 as part of #35233. I've describe partially bonus achieve in #35309 r? @jonathandturner
This commit is contained in:
commit
6631d8e9c6
@ -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) {
|
||||
@ -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;
|
||||
}
|
||||
@ -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,
|
||||
@ -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) {
|
||||
|
@ -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() { }
|
||||
|
Loading…
Reference in New Issue
Block a user