self.err_handler().span_err(span, &format!("invalid label name `{}`", label.name));
}
if label.name.as_str() == "'_" {
- self.session.add_lint(
- lint::builtin::LIFETIME_UNDERSCORE, id, span,
- format!("invalid label name `{}`", label.name)
- );
+ self.session.add_lint(lint::builtin::LIFETIME_UNDERSCORE,
+ id,
+ span,
+ format!("invalid label name `{}`", label.name));
}
}
fn invalid_visibility(&self, vis: &Visibility, span: Span, note: Option<&str>) {
if vis != &Visibility::Inherited {
- let mut err = struct_span_err!(self.session, span, E0449,
+ let mut err = struct_span_err!(self.session,
+ span,
+ E0449,
"unnecessary visibility qualifier");
if let Some(note) = note {
err.span_note(span, note);
impl<'a> Visitor for AstValidator<'a> {
fn visit_lifetime(&mut self, lt: &Lifetime) {
if lt.name.as_str() == "'_" {
- self.session.add_lint(
- lint::builtin::LIFETIME_UNDERSCORE, lt.id, lt.span,
- format!("invalid lifetime name `{}`", lt.name)
- );
+ self.session.add_lint(lint::builtin::LIFETIME_UNDERSCORE,
+ lt.id,
+ lt.span,
+ format!("invalid lifetime name `{}`", lt.name));
}
visit::walk_lifetime(self, lt)
fn visit_expr(&mut self, expr: &Expr) {
match expr.node {
- ExprKind::While(_, _, Some(ident)) | ExprKind::Loop(_, Some(ident)) |
- ExprKind::WhileLet(_, _, _, Some(ident)) | ExprKind::ForLoop(_, _, _, Some(ident)) |
- ExprKind::Break(Some(ident)) | ExprKind::Continue(Some(ident)) => {
+ ExprKind::While(_, _, Some(ident)) |
+ ExprKind::Loop(_, Some(ident)) |
+ ExprKind::WhileLet(_, _, _, Some(ident)) |
+ ExprKind::ForLoop(_, _, _, Some(ident)) |
+ ExprKind::Break(Some(ident)) |
+ ExprKind::Continue(Some(ident)) => {
self.check_label(ident.node, ident.span, expr.id);
}
_ => {}
match ty.node {
TyKind::BareFn(ref bfty) => {
self.check_decl_no_pat(&bfty.decl, |span, _| {
- let mut err = struct_span_err!(self.session, span, E0561,
- "patterns aren't allowed in function pointer types");
- err.span_note(span, "this is a recent error, see \
- issue #35203 for more details");
+ let mut err = struct_span_err!(self.session,
+ span,
+ E0561,
+ "patterns aren't allowed in function pointer \
+ types");
+ err.span_note(span,
+ "this is a recent error, see issue #35203 for more details");
err.emit();
});
}
if path.global && path.segments.len() > 0 {
let ident = path.segments[0].identifier;
if token::Ident(ident).is_path_segment_keyword() {
- self.session.add_lint(
- lint::builtin::SUPER_OR_SELF_IN_GLOBAL_PATH, id, path.span,
- format!("global paths cannot start with `{}`", ident)
- );
+ self.session.add_lint(lint::builtin::SUPER_OR_SELF_IN_GLOBAL_PATH,
+ id,
+ path.span,
+ format!("global paths cannot start with `{}`", ident));
}
}
ItemKind::Use(ref view_path) => {
let path = view_path.node.path();
if !path.segments.iter().all(|segment| segment.parameters.is_empty()) {
- self.err_handler().span_err(path.span, "type or lifetime parameters \
- in import path");
+ self.err_handler()
+ .span_err(path.span, "type or lifetime parameters in import path");
}
}
ItemKind::Impl(_, _, _, Some(..), _, ref impl_items) => {
}
}
ItemKind::Impl(_, _, _, None, _, _) => {
- self.invalid_visibility(&item.vis, item.span, Some("place qualifiers on individual \
- impl items instead"));
+ self.invalid_visibility(&item.vis,
+ item.span,
+ Some("place qualifiers on individual impl items instead"));
}
ItemKind::DefaultImpl(..) => {
self.invalid_visibility(&item.vis, item.span, None);
}
ItemKind::ForeignMod(..) => {
- self.invalid_visibility(&item.vis, item.span, Some("place qualifiers on individual \
- foreign items instead"));
+ self.invalid_visibility(&item.vis,
+ item.span,
+ Some("place qualifiers on individual foreign items \
+ instead"));
}
ItemKind::Enum(ref def, _) => {
for variant in &def.variants {
match fi.node {
ForeignItemKind::Fn(ref decl, _) => {
self.check_decl_no_pat(decl, |span, is_recent| {
- let mut err = struct_span_err!(self.session, span, E0130,
- "patterns aren't allowed in foreign function declarations");
+ let mut err = struct_span_err!(self.session,
+ span,
+ E0130,
+ "patterns aren't allowed in foreign function \
+ declarations");
if is_recent {
- err.span_note(span, "this is a recent error, see \
- issue #35203 for more details");
+ err.span_note(span,
+ "this is a recent error, see issue #35203 for more details");
}
err.emit();
});
visit::walk_foreign_item(self, fi)
}
- fn visit_variant_data(&mut self, vdata: &VariantData, _: Ident,
- _: &Generics, _: NodeId, span: Span) {
+ fn visit_variant_data(&mut self,
+ vdata: &VariantData,
+ _: Ident,
+ _: &Generics,
+ _: NodeId,
+ span: Span) {
if vdata.fields().is_empty() {
if vdata.is_tuple() {
- self.err_handler().struct_span_err(span, "empty tuple structs and enum variants \
- are not allowed, use unit structs and \
- enum variants instead")
- .span_help(span, "remove trailing `()` to make a unit \
- struct or unit enum variant")
- .emit();
+ self.err_handler()
+ .struct_span_err(span,
+ "empty tuple structs and enum variants are not allowed, use \
+ unit structs and enum variants instead")
+ .span_help(span,
+ "remove trailing `()` to make a unit struct or unit enum variant")
+ .emit();
}
}
fn visit_vis(&mut self, vis: &Visibility) {
match *vis {
- Visibility::Restricted{ref path, ..} => {
+ Visibility::Restricted { ref path, .. } => {
if !path.segments.iter().all(|segment| segment.parameters.is_empty()) {
- self.err_handler().span_err(path.span, "type or lifetime parameters \
- in visibility path");
+ self.err_handler()
+ .span_err(path.span, "type or lifetime parameters in visibility path");
}
}
_ => {}
// by borrowck::gather_loans
use rustc::dep_graph::DepNode;
-use rustc::ty::cast::{CastKind};
+use rustc::ty::cast::CastKind;
use rustc_const_eval::{ConstEvalErr, lookup_const_fn_by_id, compare_lit_exprs};
use rustc_const_eval::{eval_const_expr_partial, lookup_const_by_id};
use rustc_const_eval::ErrKind::{IndexOpFeatureGated, UnimplementedConstVal, MiscCatchAll, Math};
tcx: TyCtxt<'a, 'tcx, 'tcx>,
mode: Mode,
qualif: ConstQualif,
- rvalue_borrows: NodeMap<hir::Mutability>
+ rvalue_borrows: NodeMap<hir::Mutability>,
}
impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> {
- fn with_mode<F, R>(&mut self, mode: Mode, f: F) -> R where
- F: FnOnce(&mut CheckCrateVisitor<'a, 'gcx>) -> R,
+ fn with_mode<F, R>(&mut self, mode: Mode, f: F) -> R
+ where F: FnOnce(&mut CheckCrateVisitor<'a, 'gcx>) -> R
{
let (old_mode, old_qualif) = (self.mode, self.qualif);
self.mode = mode;
r
}
- fn with_euv<F, R>(&mut self, item_id: Option<ast::NodeId>, f: F) -> R where
- F: for<'b, 'tcx> FnOnce(&mut euv::ExprUseVisitor<'b, 'gcx, 'tcx>) -> R,
+ fn with_euv<F, R>(&mut self, item_id: Option<ast::NodeId>, f: F) -> R
+ where F: for<'b, 'tcx> FnOnce(&mut euv::ExprUseVisitor<'b, 'gcx, 'tcx>) -> R
{
let param_env = match item_id {
Some(item_id) => ty::ParameterEnvironment::for_item(self.tcx, item_id),
- None => self.tcx.empty_parameter_environment()
+ None => self.tcx.empty_parameter_environment(),
};
- self.tcx.infer_ctxt(None, Some(param_env), ProjectionMode::AnyFinal).enter(|infcx| {
- f(&mut euv::ExprUseVisitor::new(self, &infcx))
- })
+ self.tcx
+ .infer_ctxt(None, Some(param_env), ProjectionMode::AnyFinal)
+ .enter(|infcx| f(&mut euv::ExprUseVisitor::new(self, &infcx)))
}
fn global_expr(&mut self, mode: Mode, expr: &hir::Expr) -> ConstQualif {
}
if let Err(err) = eval_const_expr_partial(self.tcx, expr, ExprTypeChecked, None) {
match err.kind {
- UnimplementedConstVal(_) => {},
- IndexOpFeatureGated => {},
- ErroneousReferencedConstant(_) => {},
- _ => self.tcx.sess.add_lint(CONST_ERR, expr.id, expr.span,
- format!("constant evaluation error: {}. This will \
- become a HARD ERROR in the future",
- err.description().into_oneline())),
+ UnimplementedConstVal(_) => {}
+ IndexOpFeatureGated => {}
+ ErroneousReferencedConstant(_) => {}
+ _ => {
+ self.tcx.sess.add_lint(CONST_ERR,
+ expr.id,
+ expr.span,
+ format!("constant evaluation error: {}. This will \
+ become a HARD ERROR in the future",
+ err.description().into_oneline()))
+ }
}
}
self.with_mode(mode, |this| {
}
let mode = match fk {
- FnKind::ItemFn(_, _, _, hir::Constness::Const, _, _, _) => {
- Mode::ConstFn
- }
+ FnKind::ItemFn(_, _, _, hir::Constness::Const, _, _, _) => Mode::ConstFn,
FnKind::Method(_, m, _, _) => {
if m.constness == hir::Constness::Const {
Mode::ConstFn
Mode::Var
}
}
- _ => Mode::Var
+ _ => Mode::Var,
};
let qualif = self.with_mode(mode, |this| {
}
/// Returns true if the call is to a const fn or method.
- fn handle_const_fn_call(&mut self,
- _expr: &hir::Expr,
- def_id: DefId,
- ret_ty: Ty<'gcx>)
- -> bool {
+ fn handle_const_fn_call(&mut self, _expr: &hir::Expr, def_id: DefId, ret_ty: Ty<'gcx>) -> bool {
if let Some(fn_like) = lookup_const_fn_by_id(self.tcx, def_id) {
let qualif = self.fn_like(fn_like.kind(),
fn_like.decl(),
Ok(Ordering::Less) |
Ok(Ordering::Equal) => {}
Ok(Ordering::Greater) => {
- span_err!(self.tcx.sess, start.span, E0030,
- "lower range bound must be less than or equal to upper");
+ span_err!(self.tcx.sess,
+ start.span,
+ E0030,
+ "lower range bound must be less than or equal to upper");
}
Err(ErrorReported) => {}
}
}
- _ => intravisit::walk_pat(self, p)
+ _ => intravisit::walk_pat(self, p),
}
}
match stmt.node {
hir::StmtDecl(ref decl, _) => {
match decl.node {
- hir::DeclLocal(_) => {},
+ hir::DeclLocal(_) => {}
// Item statements are allowed
- hir::DeclItem(_) => continue
+ hir::DeclItem(_) => continue,
}
}
- hir::StmtExpr(_, _) => {},
- hir::StmtSemi(_, _) => {},
+ hir::StmtExpr(_, _) => {}
+ hir::StmtSemi(_, _) => {}
}
self.add_qualif(ConstQualif::NOT_CONST);
}
// The count is checked elsewhere (typeck).
let count = match node_ty.sty {
ty::TyArray(_, n) => n,
- _ => bug!()
+ _ => bug!(),
};
// [element; 0] is always zero-sized.
if count == 0 {
for pat in arms.iter().flat_map(|arm| &arm.pats) {
let pat_borrow = self.rvalue_borrows.remove(&pat.id);
match (borrow, pat_borrow) {
- (None, _) | (_, Some(hir::MutMutable)) => {
+ (None, _) |
+ (_, Some(hir::MutMutable)) => {
borrow = pat_borrow;
}
_ => {}
}
intravisit::walk_expr(self, ex);
}
- _ => intravisit::walk_expr(self, ex)
+ _ => intravisit::walk_expr(self, ex),
}
// Handle borrows on (or inside the autorefs of) this expression.
if self.mode == Mode::Var && !self.qualif.intersects(ConstQualif::NOT_CONST) {
match eval_const_expr_partial(self.tcx, ex, ExprTypeChecked, None) {
Ok(_) => {}
- Err(ConstEvalErr { kind: UnimplementedConstVal(_), ..}) |
- Err(ConstEvalErr { kind: MiscCatchAll, ..}) |
- Err(ConstEvalErr { kind: MiscBinaryOp, ..}) |
- Err(ConstEvalErr { kind: NonConstPath, ..}) |
- Err(ConstEvalErr { kind: UnresolvedPath, ..}) |
- Err(ConstEvalErr { kind: ErroneousReferencedConstant(_), ..}) |
- Err(ConstEvalErr { kind: Math(ConstMathErr::Overflow(Op::Shr)), ..}) |
- Err(ConstEvalErr { kind: Math(ConstMathErr::Overflow(Op::Shl)), ..}) |
- Err(ConstEvalErr { kind: IndexOpFeatureGated, ..}) => {},
+ Err(ConstEvalErr { kind: UnimplementedConstVal(_), .. }) |
+ Err(ConstEvalErr { kind: MiscCatchAll, .. }) |
+ Err(ConstEvalErr { kind: MiscBinaryOp, .. }) |
+ Err(ConstEvalErr { kind: NonConstPath, .. }) |
+ Err(ConstEvalErr { kind: UnresolvedPath, .. }) |
+ Err(ConstEvalErr { kind: ErroneousReferencedConstant(_), .. }) |
+ Err(ConstEvalErr { kind: Math(ConstMathErr::Overflow(Op::Shr)), .. }) |
+ Err(ConstEvalErr { kind: Math(ConstMathErr::Overflow(Op::Shl)), .. }) |
+ Err(ConstEvalErr { kind: IndexOpFeatureGated, .. }) => {}
Err(msg) => {
- self.tcx.sess.add_lint(CONST_ERR, ex.id,
+ self.tcx.sess.add_lint(CONST_ERR,
+ ex.id,
msg.span,
msg.description().into_oneline().into_owned())
}
/// every nested expression. If the expression is not part
/// of a const/static item, it is qualified for promotion
/// instead of producing errors.
-fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
- e: &hir::Expr, node_ty: Ty<'tcx>) {
+fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>, e: &hir::Expr, node_ty: Ty<'tcx>) {
match node_ty.sty {
ty::TyStruct(def, _) |
ty::TyEnum(def, _) if def.has_dtor() => {
Some(&ty::adjustment::AdjustUnsafeFnPointer) |
Some(&ty::adjustment::AdjustMutToConstPointer) => {}
- Some(&ty::adjustment::AdjustDerefRef(
- ty::adjustment::AutoDerefRef { autoderefs, .. }
- )) => {
- if (0..autoderefs as u32).any(|autoderef| {
- v.tcx.is_overloaded_autoderef(e.id, autoderef)
- }) {
+ Some(&ty::adjustment::AdjustDerefRef(ty::adjustment::AutoDerefRef { autoderefs, .. })) => {
+ if (0..autoderefs as u32)
+ .any(|autoderef| v.tcx.is_overloaded_autoderef(e.id, autoderef)) {
v.add_qualif(ConstQualif::NOT_CONST);
}
}
}
pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
- tcx.visit_all_items_in_krate(DepNode::CheckConst, &mut CheckCrateVisitor {
- tcx: tcx,
- mode: Mode::Var,
- qualif: ConstQualif::NOT_CONST,
- rvalue_borrows: NodeMap()
- });
+ tcx.visit_all_items_in_krate(DepNode::CheckConst,
+ &mut CheckCrateVisitor {
+ tcx: tcx,
+ mode: Mode::Var,
+ qualif: ConstQualif::NOT_CONST,
+ rvalue_borrows: NodeMap(),
+ });
tcx.sess.abort_if_errors();
}
Categorization::Rvalue(..) |
Categorization::Upvar(..) |
- Categorization::Local(..) => break
+ Categorization::Local(..) => break,
}
}
}
cmt: mc::cmt<'tcx>,
_loan_region: ty::Region,
bk: ty::BorrowKind,
- loan_cause: euv::LoanCause)
- {
+ loan_cause: euv::LoanCause) {
// Kind of hacky, but we allow Unsafe coercions in constants.
// These occur when we convert a &T or *T to a *U, as well as
// when making a thin pointer (e.g., `*T`) into a fat pointer
euv::LoanCause::AutoUnsafe => {
return;
}
- _ => { }
+ _ => {}
}
let mut cur = &cmt;
// type of the expression. `&mut [1]` has exactly the
// same representation as &mut 1.
match cmt.ty.sty {
- ty::TyArray(_, _) | ty::TySlice(_) => break,
+ ty::TyArray(_, _) |
+ ty::TySlice(_) => break,
_ => {}
}
}
}
Categorization::Upvar(..) |
- Categorization::Local(..) => break
+ Categorization::Local(..) => break,
}
}
}
- fn decl_without_init(&mut self,
- _id: ast::NodeId,
- _span: Span) {}
+ fn decl_without_init(&mut self, _id: ast::NodeId, _span: Span) {}
fn mutate(&mut self,
_assignment_id: ast::NodeId,
_assignment_span: Span,
_assignee_cmt: mc::cmt,
- _mode: euv::MutateMode) {}
+ _mode: euv::MutateMode) {
+ }
- fn matched_pat(&mut self,
- _: &hir::Pat,
- _: mc::cmt,
- _: euv::MatchMode) {}
+ fn matched_pat(&mut self, _: &hir::Pat, _: mc::cmt, _: euv::MatchMode) {}
- fn consume_pat(&mut self,
- _consume_pat: &hir::Pat,
- _cmt: mc::cmt,
- _mode: euv::ConsumeMode) {}
+ fn consume_pat(&mut self, _consume_pat: &hir::Pat, _cmt: mc::cmt, _mode: euv::ConsumeMode) {}
}
#![feature(rustc_private)]
extern crate core;
-#[macro_use] extern crate rustc;
+#[macro_use]
+extern crate rustc;
extern crate rustc_const_eval;
extern crate rustc_const_math;
-#[macro_use] extern crate log;
-#[macro_use] extern crate syntax;
+#[macro_use]
+extern crate log;
+#[macro_use]
+extern crate syntax;
extern crate syntax_pos;
extern crate rustc_errors as errors;
#[derive(Clone, Copy, PartialEq)]
enum Context {
- Normal, Loop, Closure
+ Normal,
+ Loop,
+ Closure,
}
#[derive(Copy, Clone)]
struct CheckLoopVisitor<'a> {
sess: &'a Session,
- cx: Context
+ cx: Context,
}
pub fn check_crate(sess: &Session, map: &Map) {
let _task = map.dep_graph.in_task(DepNode::CheckLoops);
let krate = map.krate();
- krate.visit_all_items(&mut CheckLoopVisitor { sess: sess, cx: Normal });
+ krate.visit_all_items(&mut CheckLoopVisitor {
+ sess: sess,
+ cx: Normal,
+ });
}
impl<'a, 'v> Visitor<'v> for CheckLoopVisitor<'a> {
}
hir::ExprBreak(_) => self.require_loop("break", e.span),
hir::ExprAgain(_) => self.require_loop("continue", e.span),
- _ => intravisit::walk_expr(self, e)
+ _ => intravisit::walk_expr(self, e),
}
}
}
impl<'a> CheckLoopVisitor<'a> {
- fn with_context<F>(&mut self, cx: Context, f: F) where
- F: FnOnce(&mut CheckLoopVisitor<'a>),
+ fn with_context<F>(&mut self, cx: Context, f: F)
+ where F: FnOnce(&mut CheckLoopVisitor<'a>)
{
let old_cx = self.cx;
self.cx = cx;
match self.cx {
Loop => {}
Closure => {
- span_err!(self.sess, span, E0267,
- "`{}` inside of a closure", name);
+ span_err!(self.sess, span, E0267, "`{}` inside of a closure", name);
}
Normal => {
- span_err!(self.sess, span, E0268,
- "`{}` outside of loop", name);
+ span_err!(self.sess, span, E0268, "`{}` outside of loop", name);
}
}
}
use syntax::visit;
pub fn check_crate(sess: &Session, krate: &ast::Crate) {
- if sess.target.target.options.allow_asm { return; }
+ if sess.target.target.options.allow_asm {
+ return;
+ }
- visit::walk_crate(&mut CheckNoAsm { sess: sess, }, krate);
+ visit::walk_crate(&mut CheckNoAsm { sess: sess }, krate);
}
#[derive(Copy, Clone)]
impl<'a> Visitor for CheckNoAsm<'a> {
fn visit_expr(&mut self, e: &ast::Expr) {
match e.node {
- ast::ExprKind::InlineAsm(_) => span_err!(self.sess, e.span, E0472,
- "asm! is unsupported on this target"),
- _ => {},
+ ast::ExprKind::InlineAsm(_) => {
+ span_err!(self.sess,
+ e.span,
+ E0472,
+ "asm! is unsupported on this target")
+ }
+ _ => {}
}
visit::walk_expr(self, e)
}
use rustc::dep_graph::DepNode;
use rustc::hir::map as ast_map;
-use rustc::session::{Session, CompileResult};
+use rustc::session::{CompileResult, Session};
use rustc::hir::def::{Def, DefMap};
use rustc::util::nodemap::NodeMap;
-use syntax::{ast};
+use syntax::ast;
use syntax::feature_gate::{GateIssue, emit_feature_err};
use syntax_pos::Span;
use rustc::hir::intravisit::{self, Visitor};
match it.node {
hir::ItemStatic(..) |
hir::ItemConst(..) => {
- let mut recursion_visitor =
- CheckItemRecursionVisitor::new(self, &it.span);
+ let mut recursion_visitor = CheckItemRecursionVisitor::new(self, &it.span);
recursion_visitor.visit_item(it);
- },
+ }
hir::ItemEnum(ref enum_def, ref generics) => {
// We could process the whole enum, but handling the variants
// with discriminant expressions one by one gives more specific,
// 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,
+ &variant.span);
recursion_visitor.populate_enum_discriminants(enum_def);
recursion_visitor.visit_variant(variant, generics, it.id);
}
match ti.node {
hir::ConstTraitItem(_, ref default) => {
if let Some(_) = *default {
- let mut recursion_visitor =
- CheckItemRecursionVisitor::new(self, &ti.span);
+ let mut recursion_visitor = CheckItemRecursionVisitor::new(self, &ti.span);
recursion_visitor.visit_trait_item(ti);
}
}
fn visit_impl_item(&mut self, ii: &'ast hir::ImplItem) {
match ii.node {
hir::ImplItemKind::Const(..) => {
- let mut recursion_visitor =
- CheckItemRecursionVisitor::new(self, &ii.span);
+ let mut recursion_visitor = CheckItemRecursionVisitor::new(self, &ii.span);
recursion_visitor.visit_impl_item(ii);
}
_ => {}
}
impl<'a, 'ast: 'a> CheckItemRecursionVisitor<'a, 'ast> {
- fn new(v: &'a CheckCrateVisitor<'a, 'ast>, span: &'a Span)
+ fn new(v: &'a CheckCrateVisitor<'a, 'ast>,
+ span: &'a Span)
-> CheckItemRecursionVisitor<'a, 'ast> {
CheckItemRecursionVisitor {
root_span: span,
}
}
fn with_item_id_pushed<F>(&mut self, id: ast::NodeId, f: F)
- where F: Fn(&mut Self) {
+ where F: Fn(&mut Self)
+ {
if self.idstack.iter().any(|&x| x == id) {
let any_static = self.idstack.iter().any(|&x| {
if let ast_map::NodeItem(item) = self.ast_map.get(x) {
if !self.sess.features.borrow().static_recursion {
emit_feature_err(&self.sess.parse_sess.span_diagnostic,
"static_recursion",
- *self.root_span, GateIssue::Language, "recursive static");
+ *self.root_span,
+ GateIssue::Language,
+ "recursive static");
}
} else {
span_err!(self.sess, *self.root_span, E0265, "recursive constant");
// has no variants.
let mut discriminant_map = self.discriminant_map.borrow_mut();
match enum_definition.variants.first() {
- None => { return; }
+ None => {
+ return;
+ }
Some(variant) if discriminant_map.contains_key(&variant.node.data.id()) => {
return;
}
self.with_item_id_pushed(it.id, |v| intravisit::walk_item(v, it));
}
- fn visit_enum_def(&mut self, enum_definition: &'ast hir::EnumDef,
- generics: &'ast hir::Generics, item_id: ast::NodeId, _: Span) {
+ fn visit_enum_def(&mut self,
+ enum_definition: &'ast hir::EnumDef,
+ generics: &'ast hir::Generics,
+ item_id: ast::NodeId,
+ _: Span) {
self.populate_enum_discriminants(enum_definition);
intravisit::walk_enum_def(self, enum_definition, generics, item_id);
}
- fn visit_variant(&mut self, variant: &'ast hir::Variant,
- _: &'ast hir::Generics, _: ast::NodeId) {
+ fn visit_variant(&mut self,
+ variant: &'ast hir::Variant,
+ _: &'ast hir::Generics,
+ _: ast::NodeId) {
let variant_id = variant.node.data.id();
let maybe_expr;
if let Some(get_expr) = self.discriminant_map.borrow().get(&variant_id) {
Some(Def::Const(def_id)) => {
if let Some(node_id) = self.ast_map.as_local_node_id(def_id) {
match self.ast_map.get(node_id) {
- ast_map::NodeItem(item) =>
- self.visit_item(item),
- ast_map::NodeTraitItem(item) =>
- self.visit_trait_item(item),
- ast_map::NodeImplItem(item) =>
- self.visit_impl_item(item),
- ast_map::NodeForeignItem(_) => {},
+ ast_map::NodeItem(item) => self.visit_item(item),
+ ast_map::NodeTraitItem(item) => self.visit_trait_item(item),
+ ast_map::NodeImplItem(item) => self.visit_impl_item(item),
+ ast_map::NodeForeignItem(_) => {}
_ => {
- span_bug!(
- e.span,
- "expected item, found {}",
- self.ast_map.node_to_string(node_id));
+ span_bug!(e.span,
+ "expected item, found {}",
+ self.ast_map.node_to_string(node_id));
}
}
}
// might be (if any).
Some(Def::Variant(enum_id, variant_id)) => {
if let Some(enum_node_id) = self.ast_map.as_local_node_id(enum_id) {
- if let hir::ItemEnum(ref enum_def, ref generics) =
- self.ast_map.expect_item(enum_node_id).node
- {
+ if let hir::ItemEnum(ref enum_def, ref generics) = self.ast_map
+ .expect_item(enum_node_id)
+ .node {
self.populate_enum_discriminants(enum_def);
let enum_id = self.ast_map.as_local_node_id(enum_id).unwrap();
let variant_id = self.ast_map.as_local_node_id(variant_id).unwrap();
}
}
}
- _ => ()
+ _ => (),
}
- },
- _ => ()
+ }
+ _ => (),
}
intravisit::walk_expr(self, e);
}