From: Keegan McAllister Date: Wed, 18 Jun 2014 19:34:43 +0000 (-0700) Subject: Incorporate upstream changes to old lint code X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=51d438e568dc128af47f4ac77ea1416c29b7402c;p=rust.git Incorporate upstream changes to old lint code --- diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index f41a212df21..0a1f83fc79d 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -45,6 +45,7 @@ use std::u32; use std::u64; use std::u8; +use std::gc::Gc; use syntax::abi; use syntax::ast_map; use syntax::attr::AttrMetaMethods; @@ -98,8 +99,8 @@ fn get_lints(&self) -> LintArray { fn check_expr(&mut self, cx: &Context, e: &ast::Expr) { match e.node { ast::ExprCast(expr, ty) => { - let t_t = ast_ty_to_ty(cx, &infer::new_infer_ctxt(cx.tcx), ty); - if ty::get(ty::expr_ty(cx.tcx, expr)).sty == ty::get(t_t).sty { + let t_t = ast_ty_to_ty(cx, &infer::new_infer_ctxt(cx.tcx), &*ty); + if ty::get(ty::expr_ty(cx.tcx, &*expr)).sty == ty::get(t_t).sty { cx.span_lint(UNNECESSARY_TYPECAST, ty.span, "unnecessary type cast"); } } @@ -150,7 +151,7 @@ fn check_expr(&mut self, cx: &Context, e: &ast::Expr) { } }, _ => { - let t = ty::expr_ty(cx.tcx, expr); + let t = ty::expr_ty(cx.tcx, &*expr); match ty::get(t).sty { ty::ty_uint(_) => { cx.span_lint(UNSIGNED_NEGATE, e.span, @@ -170,7 +171,7 @@ fn check_expr(&mut self, cx: &Context, e: &ast::Expr) { self.negated_expr_id = expr.id; }, ast::ExprBinary(binop, l, r) => { - if is_comparison(binop) && !check_limits(cx.tcx, binop, l, r) { + if is_comparison(binop) && !check_limits(cx.tcx, binop, &*l, &*r) { cx.span_lint(TYPE_LIMITS, e.span, "comparison is useless due to type limits"); } @@ -202,6 +203,7 @@ fn check_expr(&mut self, cx: &Context, e: &ast::Expr) { } else { t }; let (min, max) = uint_ty_range(uint_type); let lit_val: u64 = match lit.node { + ast::LitByte(_v) => return, // _v is u8, within range by definition ast::LitInt(v, _) => v as u64, ast::LitUint(v, _) => v, ast::LitIntUnsuffixed(v) => v as u64, @@ -350,24 +352,24 @@ fn check_ty(cx: &Context, ty: &ast::Ty) { _ => () } } - ast::TyPtr(ref mt) => { check_ty(cx, mt.ty) } + ast::TyPtr(ref mt) => { check_ty(cx, &*mt.ty) } _ => {} } } fn check_foreign_fn(cx: &Context, decl: &ast::FnDecl) { for input in decl.inputs.iter() { - check_ty(cx, input.ty); + check_ty(cx, &*input.ty); } - check_ty(cx, decl.output) + check_ty(cx, &*decl.output) } match it.node { ast::ItemForeignMod(ref nmod) if nmod.abi != abi::RustIntrinsic => { for ni in nmod.items.iter() { match ni.node { - ast::ForeignItemFn(decl, _) => check_foreign_fn(cx, decl), - ast::ForeignItemStatic(t, _) => check_ty(cx, t) + ast::ForeignItemFn(decl, _) => check_foreign_fn(cx, &*decl), + ast::ForeignItemStatic(t, _) => check_ty(cx, &*t) } } } @@ -397,9 +399,6 @@ fn check_heap_type(&self, cx: &Context, span: Span, ty: ty::t) { n_box += 1; } ty::ty_uniq(_) | - ty::ty_trait(box ty::TyTrait { - store: ty::UniqTraitStore, .. - }) | ty::ty_closure(box ty::ClosureTy { store: ty::UniqTraitStore, .. @@ -523,7 +522,7 @@ fn check_item(&mut self, cx: &Context, item: &ast::Item) { match item.node { ast::ItemStruct(..) | ast::ItemEnum(..) => { let mut visitor = RawPtrDerivingVisitor { cx: cx }; - visit::walk_item(&mut visitor, item, ()); + visit::walk_item(&mut visitor, &*item, ()); } _ => {} } @@ -547,7 +546,6 @@ fn check_attribute(&mut self, cx: &Context, attr: &ast::Attribute) { // FIXME: #14406 these are processed in trans, which happens after the // lint pass - "address_insignificant", "cold", "inline", "link", @@ -653,7 +651,7 @@ fn check_stmt(&mut self, cx: &Context, s: &ast::Stmt) { ast::StmtSemi(expr, _) => expr, _ => return }; - let t = ty::expr_ty(cx.tcx, expr); + let t = ty::expr_ty(cx.tcx, &*expr); match ty::get(t).sty { ty::ty_nil | ty::ty_bot | ty::ty_bool => return, _ => {} @@ -663,7 +661,7 @@ fn check_stmt(&mut self, cx: &Context, s: &ast::Stmt) { _ => {} } - let t = ty::expr_ty(cx.tcx, expr); + let t = ty::expr_ty(cx.tcx, &*expr); let mut warned = false; match ty::get(t).sty { ty::ty_struct(did, _) | @@ -698,31 +696,6 @@ fn check_stmt(&mut self, cx: &Context, s: &ast::Stmt) { } } -declare_lint!(DEPRECATED_OWNED_VECTOR, Allow, - "use of a `~[T]` vector") - -pub struct DeprecatedOwnedVector; - -impl LintPass for DeprecatedOwnedVector { - fn get_lints(&self) -> LintArray { - lint_array!(DEPRECATED_OWNED_VECTOR) - } - - fn check_expr(&mut self, cx: &Context, e: &ast::Expr) { - let t = ty::expr_ty(cx.tcx, e); - match ty::get(t).sty { - ty::ty_uniq(t) => match ty::get(t).sty { - ty::ty_vec(_, None) => { - cx.span_lint(DEPRECATED_OWNED_VECTOR, e.span, - "use of deprecated `~[]` vector; replaced by `std::vec::Vec`") - } - _ => {} - }, - _ => {} - } - } -} - declare_lint!(NON_CAMEL_CASE_TYPES, Warn, "types, variants and traits should have camel case names") @@ -1028,7 +1001,7 @@ fn check_expr(&mut self, cx: &Context, e: &ast::Expr) { ast::ExprAssignOp(_, _, value) => (value, "assigned value"), _ => return }; - self.check_unnecessary_parens_core(cx, value, msg); + self.check_unnecessary_parens_core(cx, &*value, msg); } fn check_stmt(&mut self, cx: &Context, s: &ast::Stmt) { @@ -1042,7 +1015,7 @@ fn check_stmt(&mut self, cx: &Context, s: &ast::Stmt) { }, _ => return }; - self.check_unnecessary_parens_core(cx, value, msg); + self.check_unnecessary_parens_core(cx, &*value, msg); } } @@ -1097,12 +1070,12 @@ fn check_expr(&mut self, cx: &Context, e: &ast::Expr) { pub struct UnusedMut; impl UnusedMut { - fn check_unused_mut_pat(&self, cx: &Context, pats: &[@ast::Pat]) { + fn check_unused_mut_pat(&self, cx: &Context, pats: &[Gc]) { // collect all mutable pattern and group their NodeIDs by their Identifier to // avoid false warnings in match arms with multiple patterns let mut mutables = HashMap::new(); for &p in pats.iter() { - pat_util::pat_bindings(&cx.tcx.def_map, p, |mode, id, _, path| { + pat_util::pat_bindings(&cx.tcx.def_map, &*p, |mode, id, _, path| { match mode { ast::BindByValue(ast::MutMutable) => { if path.segments.len() != 1 { diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 4c01792bf9c..3ba948786d0 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -145,7 +145,6 @@ macro_rules! add_builtin_with_new ( ( $sess:ident, $($name:ident),*, ) => ( UnusedAttribute, PathStatement, UnusedResult, - DeprecatedOwnedVector, NonCamelCaseTypes, NonSnakeCaseFunctions, NonUppercaseStatics,