mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 02:03:53 +00:00
Merge pull request #690 from quininer/fix-nightly
fix nightly (2016-02-17)
This commit is contained in:
commit
c47d5a615f
@ -175,13 +175,13 @@ fn if_sequence(mut expr: &Expr) -> (SmallVector<&Expr>, SmallVector<&Block>) {
|
||||
fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat) -> HashMap<InternedString, ty::Ty<'tcx>> {
|
||||
fn bindings_impl<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat, map: &mut HashMap<InternedString, ty::Ty<'tcx>>) {
|
||||
match pat.node {
|
||||
PatBox(ref pat) | PatRegion(ref pat, _) => bindings_impl(cx, pat, map),
|
||||
PatEnum(_, Some(ref pats)) => {
|
||||
PatKind::Box(ref pat) | PatKind::Ref(ref pat, _) => bindings_impl(cx, pat, map),
|
||||
PatKind::TupleStruct(_, Some(ref pats)) => {
|
||||
for pat in pats {
|
||||
bindings_impl(cx, pat, map);
|
||||
}
|
||||
}
|
||||
PatIdent(_, ref ident, ref as_pat) => {
|
||||
PatKind::Ident(_, ref ident, ref as_pat) => {
|
||||
if let Entry::Vacant(v) = map.entry(ident.node.name.as_str()) {
|
||||
v.insert(cx.tcx.pat_ty(pat));
|
||||
}
|
||||
@ -189,17 +189,17 @@ fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat) -> HashMap<Interned
|
||||
bindings_impl(cx, as_pat, map);
|
||||
}
|
||||
},
|
||||
PatStruct(_, ref fields, _) => {
|
||||
PatKind::Struct(_, ref fields, _) => {
|
||||
for pat in fields {
|
||||
bindings_impl(cx, &pat.node.pat, map);
|
||||
}
|
||||
}
|
||||
PatTup(ref fields) => {
|
||||
PatKind::Tup(ref fields) => {
|
||||
for pat in fields {
|
||||
bindings_impl(cx, pat, map);
|
||||
}
|
||||
}
|
||||
PatVec(ref lhs, ref mid, ref rhs) => {
|
||||
PatKind::Vec(ref lhs, ref mid, ref rhs) => {
|
||||
for pat in lhs {
|
||||
bindings_impl(cx, pat, map);
|
||||
}
|
||||
@ -210,7 +210,7 @@ fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat) -> HashMap<Interned
|
||||
bindings_impl(cx, pat, map);
|
||||
}
|
||||
}
|
||||
PatEnum(..) | PatLit(..) | PatQPath(..) | PatRange(..) | PatWild => (),
|
||||
PatKind::TupleStruct(..) | PatKind::Lit(..) | PatKind::QPath(..) | PatKind::Range(..) | PatKind::Wild | PatKind::Path(..) => (),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ fn check_closure(cx: &LateContext, expr: &Expr) {
|
||||
}
|
||||
}
|
||||
for (ref a1, ref a2) in decl.inputs.iter().zip(args) {
|
||||
if let PatIdent(_, ident, _) = a1.pat.node {
|
||||
if let PatKind::Ident(_, ident, _) = a1.pat.node {
|
||||
// XXXManishearth Should I be checking the binding mode here?
|
||||
if let ExprPath(None, ref p) = a2.node {
|
||||
if p.segments.len() != 1 {
|
||||
|
16
src/loops.rs
16
src/loops.rs
@ -288,7 +288,7 @@ impl LateLintPass for LoopsPass {
|
||||
}
|
||||
if let ExprMatch(ref match_expr, ref arms, MatchSource::WhileLetDesugar) = expr.node {
|
||||
let pat = &arms[0].pats[0].node;
|
||||
if let (&PatEnum(ref path, Some(ref pat_args)),
|
||||
if let (&PatKind::TupleStruct(ref path, Some(ref pat_args)),
|
||||
&ExprMethodCall(method_name, _, ref method_args)) = (pat, &match_expr.node) {
|
||||
let iter_expr = &method_args[0];
|
||||
if let Some(lhs_constructor) = path.segments.last() {
|
||||
@ -338,7 +338,7 @@ fn check_for_loop(cx: &LateContext, pat: &Pat, arg: &Expr, body: &Expr, expr: &E
|
||||
fn check_for_loop_range(cx: &LateContext, pat: &Pat, arg: &Expr, body: &Expr, expr: &Expr) {
|
||||
if let ExprRange(Some(ref l), ref r) = arg.node {
|
||||
// the var must be a single name
|
||||
if let PatIdent(_, ref ident, _) = pat.node {
|
||||
if let PatKind::Ident(_, ref ident, _) = pat.node {
|
||||
|
||||
let mut visitor = VarVisitor {
|
||||
cx: cx,
|
||||
@ -584,7 +584,7 @@ fn check_for_loop_explicit_counter(cx: &LateContext, arg: &Expr, body: &Expr, ex
|
||||
|
||||
// Check for the FOR_KV_MAP lint.
|
||||
fn check_for_loop_over_map_kv(cx: &LateContext, pat: &Pat, arg: &Expr, body: &Expr, expr: &Expr) {
|
||||
if let PatTup(ref pat) = pat.node {
|
||||
if let PatKind::Tup(ref pat) = pat.node {
|
||||
if pat.len() == 2 {
|
||||
|
||||
let (pat_span, kind) = match (&pat[0].node, &pat[1].node) {
|
||||
@ -622,10 +622,10 @@ fn check_for_loop_over_map_kv(cx: &LateContext, pat: &Pat, arg: &Expr, body: &Ex
|
||||
}
|
||||
|
||||
// Return true if the pattern is a `PatWild` or an ident prefixed with '_'.
|
||||
fn pat_is_wild(pat: &Pat_, body: &Expr) -> bool {
|
||||
fn pat_is_wild(pat: &PatKind, body: &Expr) -> bool {
|
||||
match *pat {
|
||||
PatWild => true,
|
||||
PatIdent(_, ident, None) if ident.node.name.as_str().starts_with('_') => {
|
||||
PatKind::Wild => true,
|
||||
PatKind::Ident(_, ident, None) if ident.node.name.as_str().starts_with('_') => {
|
||||
let mut visitor = UsedVisitor {
|
||||
var: ident.node,
|
||||
used: false,
|
||||
@ -668,7 +668,7 @@ fn recover_for_loop(expr: &Expr) -> Option<(&Pat, &Expr, &Expr)> {
|
||||
let Some(ref loopexpr) = block.expr,
|
||||
let ExprMatch(_, ref innerarms, MatchSource::ForLoopDesugar) = loopexpr.node,
|
||||
innerarms.len() == 2 && innerarms[0].pats.len() == 1,
|
||||
let PatEnum(_, Some(ref somepats)) = innerarms[0].pats[0].node,
|
||||
let PatKind::TupleStruct(_, Some(ref somepats)) = innerarms[0].pats[0].node,
|
||||
somepats.len() == 1
|
||||
], {
|
||||
return Some((&somepats[0],
|
||||
@ -909,7 +909,7 @@ impl<'v, 't> Visitor<'v> for InitializeVisitor<'v, 't> {
|
||||
// Look for declarations of the variable
|
||||
if let DeclLocal(ref local) = decl.node {
|
||||
if local.pat.id == self.var_id {
|
||||
if let PatIdent(_, ref ident, _) = local.pat.node {
|
||||
if let PatKind::Ident(_, ref ident, _) = local.pat.node {
|
||||
self.name = Some(ident.node.name);
|
||||
|
||||
self.state = if let Some(ref init) = local.init {
|
||||
|
@ -108,8 +108,8 @@ fn get_type_name(cx: &LateContext, expr: &Expr, arg: &Expr) -> Option<&'static s
|
||||
|
||||
fn get_arg_name(pat: &Pat) -> Option<Ident> {
|
||||
match pat.node {
|
||||
PatIdent(_, ident, None) => Some(ident.node),
|
||||
PatRegion(ref subpat, _) => get_arg_name(subpat),
|
||||
PatKind::Ident(_, ident, None) => Some(ident.node),
|
||||
PatKind::Ref(ref subpat, _) => get_arg_name(subpat),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ fn check_single_match(cx: &LateContext, ex: &Expr, arms: &[Arm], expr: &Expr) {
|
||||
}
|
||||
|
||||
fn check_single_match_single_pattern(cx: &LateContext, ex: &Expr, arms: &[Arm], expr: &Expr, els: Option<&Expr>) {
|
||||
if arms[1].pats[0].node == PatWild {
|
||||
if arms[1].pats[0].node == PatKind::Wild {
|
||||
let lint = if els.is_some() {
|
||||
SINGLE_MATCH_ELSE
|
||||
} else {
|
||||
@ -192,15 +192,15 @@ fn check_single_match_opt_like(cx: &LateContext, ex: &Expr, arms: &[Arm], expr:
|
||||
];
|
||||
|
||||
let path = match arms[1].pats[0].node {
|
||||
PatEnum(ref path, Some(ref inner)) => {
|
||||
PatKind::TupleStruct(ref path, Some(ref inner)) => {
|
||||
// contains any non wildcard patterns? e.g. Err(err)
|
||||
if inner.iter().any(|pat| if let PatWild = pat.node { false } else { true }) {
|
||||
if inner.iter().any(|pat| if let PatKind::Wild = pat.node { false } else { true }) {
|
||||
return;
|
||||
}
|
||||
path.to_string()
|
||||
},
|
||||
PatEnum(ref path, None) => path.to_string(),
|
||||
PatIdent(BindByValue(MutImmutable), ident, None) => ident.node.to_string(),
|
||||
PatKind::TupleStruct(ref path, None) => path.to_string(),
|
||||
PatKind::Ident(BindByValue(MutImmutable), ident, None) => ident.node.to_string(),
|
||||
_ => return,
|
||||
};
|
||||
|
||||
@ -235,7 +235,7 @@ fn check_match_bool(cx: &LateContext, ex: &Expr, arms: &[Arm], expr: &Expr) {
|
||||
if cx.tcx.expr_ty(ex).sty == ty::TyBool {
|
||||
let sugg = if arms.len() == 2 && arms[0].pats.len() == 1 {
|
||||
// no guards
|
||||
let exprs = if let PatLit(ref arm_bool) = arms[0].pats[0].node {
|
||||
let exprs = if let PatKind::Lit(ref arm_bool) = arms[0].pats[0].node {
|
||||
if let ExprLit(ref lit) = arm_bool.node {
|
||||
match lit.node {
|
||||
LitKind::Bool(true) => Some((&*arms[0].body, &*arms[1].body)),
|
||||
@ -334,7 +334,7 @@ fn all_ranges(cx: &LateContext, arms: &[Arm]) -> Vec<SpannedRange<ConstVal>> {
|
||||
if let Arm { ref pats, guard: None, .. } = *arm {
|
||||
Some(pats.iter().filter_map(|pat| {
|
||||
if_let_chain! {[
|
||||
let PatRange(ref lhs, ref rhs) = pat.node,
|
||||
let PatKind::Range(ref lhs, ref rhs) = pat.node,
|
||||
let Ok(lhs) = eval_const_expr_partial(cx.tcx, &lhs, ExprTypeChecked, None),
|
||||
let Ok(rhs) = eval_const_expr_partial(cx.tcx, &rhs, ExprTypeChecked, None)
|
||||
], {
|
||||
@ -342,7 +342,7 @@ fn all_ranges(cx: &LateContext, arms: &[Arm]) -> Vec<SpannedRange<ConstVal>> {
|
||||
}}
|
||||
|
||||
if_let_chain! {[
|
||||
let PatLit(ref value) = pat.node,
|
||||
let PatKind::Lit(ref value) = pat.node,
|
||||
let Ok(value) = eval_const_expr_partial(cx.tcx, &value, ExprTypeChecked, None)
|
||||
], {
|
||||
return Some(SpannedRange { span: pat.span, node: (value.clone(), value) });
|
||||
@ -424,8 +424,8 @@ fn has_only_ref_pats(arms: &[Arm]) -> bool {
|
||||
.flat_map(|a| &a.pats)
|
||||
.map(|p| {
|
||||
match p.node {
|
||||
PatRegion(..) => Some(true), // &-patterns
|
||||
PatWild => Some(false), // an "anything" wildcard is also fine
|
||||
PatKind::Ref(..) => Some(true), // &-patterns
|
||||
PatKind::Wild => Some(false), // an "anything" wildcard is also fine
|
||||
_ => None, // any other pattern is not fine
|
||||
}
|
||||
})
|
||||
|
@ -45,7 +45,7 @@ impl LateLintPass for TopLevelRefPass {
|
||||
return;
|
||||
}
|
||||
for ref arg in &decl.inputs {
|
||||
if let PatIdent(BindByRef(_), _, _) = arg.pat.node {
|
||||
if let PatKind::Ident(BindByRef(_), _, _) = arg.pat.node {
|
||||
span_lint(cx,
|
||||
TOPLEVEL_REF_ARG,
|
||||
arg.pat.span,
|
||||
@ -58,7 +58,7 @@ impl LateLintPass for TopLevelRefPass {
|
||||
[
|
||||
let StmtDecl(ref d, _) = s.node,
|
||||
let DeclLocal(ref l) = d.node,
|
||||
let PatIdent(BindByRef(_), i, None) = l.pat.node,
|
||||
let PatKind::Ident(BindByRef(_), i, None) = l.pat.node,
|
||||
let Some(ref init) = l.init
|
||||
], {
|
||||
let tyopt = if let Some(ref ty) = l.ty {
|
||||
@ -345,8 +345,8 @@ impl LintPass for PatternPass {
|
||||
|
||||
impl LateLintPass for PatternPass {
|
||||
fn check_pat(&mut self, cx: &LateContext, pat: &Pat) {
|
||||
if let PatIdent(_, ref ident, Some(ref right)) = pat.node {
|
||||
if right.node == PatWild {
|
||||
if let PatKind::Ident(_, ref ident, Some(ref right)) = pat.node {
|
||||
if right.node == PatKind::Wild {
|
||||
cx.span_lint(REDUNDANT_PATTERN,
|
||||
pat.span,
|
||||
&format!("the `{} @ _` pattern can be written as just `{}`",
|
||||
|
@ -67,7 +67,7 @@ impl LateLintPass for ShadowPass {
|
||||
fn check_fn(cx: &LateContext, decl: &FnDecl, block: &Block) {
|
||||
let mut bindings = Vec::new();
|
||||
for arg in &decl.inputs {
|
||||
if let PatIdent(_, ident, _) = arg.pat.node {
|
||||
if let PatKind::Ident(_, ident, _) = arg.pat.node {
|
||||
bindings.push((ident.node.unhygienic_name, ident.span))
|
||||
}
|
||||
}
|
||||
@ -119,7 +119,7 @@ fn is_binding(cx: &LateContext, pat: &Pat) -> bool {
|
||||
fn check_pat(cx: &LateContext, pat: &Pat, init: &Option<&Expr>, span: Span, bindings: &mut Vec<(Name, Span)>) {
|
||||
// TODO: match more stuff / destructuring
|
||||
match pat.node {
|
||||
PatIdent(_, ref ident, ref inner) => {
|
||||
PatKind::Ident(_, ref ident, ref inner) => {
|
||||
let name = ident.node.unhygienic_name;
|
||||
if is_binding(cx, pat) {
|
||||
let mut new_binding = true;
|
||||
@ -140,7 +140,7 @@ fn check_pat(cx: &LateContext, pat: &Pat, init: &Option<&Expr>, span: Span, bind
|
||||
}
|
||||
}
|
||||
// PatEnum(Path, Option<Vec<P<Pat>>>),
|
||||
PatStruct(_, ref pfields, _) => {
|
||||
PatKind::Struct(_, ref pfields, _) => {
|
||||
if let Some(ref init_struct) = *init {
|
||||
if let ExprStruct(_, ref efields, _) = init_struct.node {
|
||||
for field in pfields {
|
||||
@ -161,7 +161,7 @@ fn check_pat(cx: &LateContext, pat: &Pat, init: &Option<&Expr>, span: Span, bind
|
||||
}
|
||||
}
|
||||
}
|
||||
PatTup(ref inner) => {
|
||||
PatKind::Tup(ref inner) => {
|
||||
if let Some(ref init_tup) = *init {
|
||||
if let ExprTup(ref tup) = init_tup.node {
|
||||
for (i, p) in inner.iter().enumerate() {
|
||||
@ -178,7 +178,7 @@ fn check_pat(cx: &LateContext, pat: &Pat, init: &Option<&Expr>, span: Span, bind
|
||||
}
|
||||
}
|
||||
}
|
||||
PatBox(ref inner) => {
|
||||
PatKind::Box(ref inner) => {
|
||||
if let Some(ref initp) = *init {
|
||||
if let ExprBox(ref inner_init) = initp.node {
|
||||
check_pat(cx, inner, &Some(&**inner_init), span, bindings);
|
||||
@ -189,7 +189,7 @@ fn check_pat(cx: &LateContext, pat: &Pat, init: &Option<&Expr>, span: Span, bind
|
||||
check_pat(cx, inner, init, span, bindings);
|
||||
}
|
||||
}
|
||||
PatRegion(ref inner, _) => check_pat(cx, inner, init, span, bindings),
|
||||
PatKind::Ref(ref inner, _) => check_pat(cx, inner, init, span, bindings),
|
||||
// PatVec(Vec<P<Pat>>, Option<P<Pat>>, Vec<P<Pat>>),
|
||||
_ => (),
|
||||
}
|
||||
|
@ -168,41 +168,41 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
|
||||
/// Check whether two patterns are the same.
|
||||
pub fn eq_pat(&self, left: &Pat, right: &Pat) -> bool {
|
||||
match (&left.node, &right.node) {
|
||||
(&PatBox(ref l), &PatBox(ref r)) => {
|
||||
(&PatKind::Box(ref l), &PatKind::Box(ref r)) => {
|
||||
self.eq_pat(l, r)
|
||||
}
|
||||
(&PatEnum(ref lp, ref la), &PatEnum(ref rp, ref ra)) => {
|
||||
(&PatKind::TupleStruct(ref lp, ref la), &PatKind::TupleStruct(ref rp, ref ra)) => {
|
||||
self.eq_path(lp, rp) &&
|
||||
both(la, ra, |l, r| {
|
||||
over(l, r, |l, r| self.eq_pat(l, r))
|
||||
})
|
||||
}
|
||||
(&PatIdent(ref lb, ref li, ref lp), &PatIdent(ref rb, ref ri, ref rp)) => {
|
||||
(&PatKind::Ident(ref lb, ref li, ref lp), &PatKind::Ident(ref rb, ref ri, ref rp)) => {
|
||||
lb == rb && li.node.name.as_str() == ri.node.name.as_str() &&
|
||||
both(lp, rp, |l, r| self.eq_pat(l, r))
|
||||
}
|
||||
(&PatLit(ref l), &PatLit(ref r)) => {
|
||||
(&PatKind::Lit(ref l), &PatKind::Lit(ref r)) => {
|
||||
self.eq_expr(l, r)
|
||||
}
|
||||
(&PatQPath(ref ls, ref lp), &PatQPath(ref rs, ref rp)) => {
|
||||
(&PatKind::QPath(ref ls, ref lp), &PatKind::QPath(ref rs, ref rp)) => {
|
||||
self.eq_qself(ls, rs) && self.eq_path(lp, rp)
|
||||
}
|
||||
(&PatTup(ref l), &PatTup(ref r)) => {
|
||||
(&PatKind::Tup(ref l), &PatKind::Tup(ref r)) => {
|
||||
over(l, r, |l, r| self.eq_pat(l, r))
|
||||
}
|
||||
(&PatRange(ref ls, ref le), &PatRange(ref rs, ref re)) => {
|
||||
(&PatKind::Range(ref ls, ref le), &PatKind::Range(ref rs, ref re)) => {
|
||||
self.eq_expr(ls, rs) &&
|
||||
self.eq_expr(le, re)
|
||||
}
|
||||
(&PatRegion(ref le, ref lm), &PatRegion(ref re, ref rm)) => {
|
||||
(&PatKind::Ref(ref le, ref lm), &PatKind::Ref(ref re, ref rm)) => {
|
||||
lm == rm && self.eq_pat(le, re)
|
||||
}
|
||||
(&PatVec(ref ls, ref li, ref le), &PatVec(ref rs, ref ri, ref re)) => {
|
||||
(&PatKind::Vec(ref ls, ref li, ref le), &PatKind::Vec(ref rs, ref ri, ref re)) => {
|
||||
over(ls, rs, |l, r| self.eq_pat(l, r)) &&
|
||||
over(le, re, |l, r| self.eq_pat(l, r)) &&
|
||||
both(li, ri, |l, r| self.eq_pat(l, r))
|
||||
}
|
||||
(&PatWild, &PatWild) => true,
|
||||
(&PatKind::Wild, &PatKind::Wild) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user