Abide by the common rustc::ty conventions.

This commit is contained in:
Eduard-Mihai Burtescu 2017-06-11 05:57:25 +03:00
parent cd89737b21
commit e073dfe9a2
19 changed files with 96 additions and 97 deletions

View file

@ -3,7 +3,7 @@
use reexport::*;
use rustc::lint::*;
use rustc::hir::*;
use rustc::ty;
use rustc::ty::{self, TyCtxt};
use semver::Version;
use syntax::ast::{Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem, NestedMetaItemKind};
use syntax::codemap::Span;
@ -158,7 +158,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
}
}
fn is_relevant_item(tcx: ty::TyCtxt, item: &Item) -> bool {
fn is_relevant_item(tcx: TyCtxt, item: &Item) -> bool {
if let ItemFn(_, _, _, _, _, eid) = item.node {
is_relevant_expr(tcx, tcx.body_tables(eid), &tcx.hir.body(eid).value)
} else {
@ -166,14 +166,14 @@ fn is_relevant_item(tcx: ty::TyCtxt, item: &Item) -> bool {
}
}
fn is_relevant_impl(tcx: ty::TyCtxt, item: &ImplItem) -> bool {
fn is_relevant_impl(tcx: TyCtxt, item: &ImplItem) -> bool {
match item.node {
ImplItemKind::Method(_, eid) => is_relevant_expr(tcx, tcx.body_tables(eid), &tcx.hir.body(eid).value),
_ => false,
}
}
fn is_relevant_trait(tcx: ty::TyCtxt, item: &TraitItem) -> bool {
fn is_relevant_trait(tcx: TyCtxt, item: &TraitItem) -> bool {
match item.node {
TraitItemKind::Method(_, TraitMethod::Required(_)) => true,
TraitItemKind::Method(_, TraitMethod::Provided(eid)) => {
@ -183,7 +183,7 @@ fn is_relevant_trait(tcx: ty::TyCtxt, item: &TraitItem) -> bool {
}
}
fn is_relevant_block(tcx: ty::TyCtxt, tables: &ty::TypeckTables, block: &Block) -> bool {
fn is_relevant_block(tcx: TyCtxt, tables: &ty::TypeckTables, block: &Block) -> bool {
for stmt in &block.stmts {
match stmt.node {
StmtDecl(_, _) => return true,
@ -196,7 +196,7 @@ fn is_relevant_block(tcx: ty::TyCtxt, tables: &ty::TypeckTables, block: &Block)
block.expr.as_ref().map_or(false, |e| is_relevant_expr(tcx, tables, e))
}
fn is_relevant_expr(tcx: ty::TyCtxt, tables: &ty::TypeckTables, expr: &Expr) -> bool {
fn is_relevant_expr(tcx: TyCtxt, tables: &ty::TypeckTables, expr: &Expr) -> bool {
match expr.node {
ExprBlock(ref block) => is_relevant_block(tcx, tables, block),
ExprRet(Some(ref e)) => is_relevant_expr(tcx, tables, e),

View file

@ -5,7 +5,7 @@ use rustc::hir::def::Def;
use rustc_const_eval::lookup_const_by_id;
use rustc_const_math::ConstInt;
use rustc::hir::*;
use rustc::ty::{self, TyCtxt};
use rustc::ty::{self, TyCtxt, Ty};
use rustc::ty::subst::{Substs, Subst};
use std::cmp::Ordering::{self, Equal};
use std::cmp::PartialOrd;
@ -161,7 +161,7 @@ impl PartialOrd for Constant {
/// parse a `LitKind` to a `Constant`
#[allow(cast_possible_wrap)]
pub fn lit_to_constant<'a, 'tcx>(lit: &LitKind, tcx: TyCtxt<'a, 'tcx, 'tcx>, mut ty: ty::Ty<'tcx>) -> Constant {
pub fn lit_to_constant<'a, 'tcx>(lit: &LitKind, tcx: TyCtxt<'a, 'tcx, 'tcx>, mut ty: Ty<'tcx>) -> Constant {
use syntax::ast::*;
use syntax::ast::LitIntType::*;
use rustc::ty::util::IntTypeExt;

View file

@ -1,5 +1,5 @@
use rustc::lint::*;
use rustc::ty;
use rustc::ty::Ty;
use rustc::hir::*;
use std::collections::HashMap;
use std::collections::hash_map::Entry;
@ -251,11 +251,11 @@ fn if_sequence(mut expr: &Expr) -> (SmallVector<&Expr>, SmallVector<&Block>) {
}
/// Return the list of bindings in a pattern.
fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat) -> HashMap<InternedString, ty::Ty<'tcx>> {
fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat) -> HashMap<InternedString, Ty<'tcx>> {
fn bindings_impl<'a, 'tcx>(
cx: &LateContext<'a, 'tcx>,
pat: &Pat,
map: &mut HashMap<InternedString, ty::Ty<'tcx>>
map: &mut HashMap<InternedString, Ty<'tcx>>
) {
match pat.node {
PatKind::Box(ref pat) |

View file

@ -1,6 +1,5 @@
use rustc::lint::*;
use rustc::ty::TypeVariants;
use rustc::ty;
use rustc::ty::{self, Ty};
use rustc::hir::*;
use syntax::codemap::Span;
use utils::paths;
@ -89,7 +88,7 @@ fn check_hash_peq<'a, 'tcx>(
cx: &LateContext<'a, 'tcx>,
span: Span,
trait_ref: &TraitRef,
ty: ty::Ty<'tcx>,
ty: Ty<'tcx>,
hash_is_automatically_derived: bool
) {
if_let_chain! {[
@ -134,27 +133,27 @@ fn check_hash_peq<'a, 'tcx>(
}
/// Implementation of the `EXPL_IMPL_CLONE_ON_COPY` lint.
fn check_copy_clone<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, item: &Item, trait_ref: &TraitRef, ty: ty::Ty<'tcx>) {
fn check_copy_clone<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, item: &Item, trait_ref: &TraitRef, ty: Ty<'tcx>) {
if match_path_old(&trait_ref.path, &paths::CLONE_TRAIT) {
if !is_copy(cx, ty) {
return;
}
match ty.sty {
TypeVariants::TyAdt(def, _) if def.is_union() => return,
ty::TyAdt(def, _) if def.is_union() => return,
// Some types are not Clone by default but could be cloned “by hand” if necessary
TypeVariants::TyAdt(def, substs) => {
ty::TyAdt(def, substs) => {
for variant in &def.variants {
for field in &variant.fields {
match field.ty(cx.tcx, substs).sty {
TypeVariants::TyArray(_, size) if size > 32 => {
ty::TyArray(_, size) if size > 32 => {
return;
},
TypeVariants::TyFnPtr(..) => {
ty::TyFnPtr(..) => {
return;
},
TypeVariants::TyTuple(tys, _) if tys.len() > 12 => {
ty::TyTuple(tys, _) if tys.len() > 12 => {
return;
},
_ => (),

View file

@ -4,7 +4,7 @@ use rustc::hir::map::Node::{NodeExpr, NodeStmt};
use rustc::lint::*;
use rustc::middle::expr_use_visitor::*;
use rustc::middle::mem_categorization::{cmt, Categorization};
use rustc::ty;
use rustc::ty::{self, Ty};
use rustc::util::nodemap::NodeSet;
use syntax::ast::NodeId;
use syntax::codemap::Span;
@ -37,7 +37,7 @@ declare_lint! {
"using `Box<T>` where unnecessary"
}
fn is_non_trait_box(ty: ty::Ty) -> bool {
fn is_non_trait_box(ty: Ty) -> bool {
ty.is_box() && !ty.boxed_ty().is_trait()
}
@ -168,7 +168,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
}
impl<'a, 'tcx> EscapeDelegate<'a, 'tcx> {
fn is_large_box(&self, ty: ty::Ty<'tcx>) -> bool {
fn is_large_box(&self, ty: Ty<'tcx>) -> bool {
// Large types need to be boxed to avoid stack
// overflows.
if ty.is_box() {

View file

@ -1,7 +1,7 @@
use rustc::hir::*;
use rustc::hir::map::Node::NodeItem;
use rustc::lint::*;
use rustc::ty::TypeVariants;
use rustc::ty;
use syntax::ast::LitKind;
use syntax::symbol::InternedString;
use utils::paths;
@ -132,7 +132,7 @@ fn check_arg_is_display(cx: &LateContext, expr: &Expr) -> bool {
], {
let ty = walk_ptrs_ty(cx.tables.pat_ty(&pat[0]));
return ty.sty == TypeVariants::TyStr || match_type(cx, ty, &paths::STRING);
return ty.sty == ty::TyStr || match_type(cx, ty, &paths::STRING);
}}
false

View file

@ -7,7 +7,7 @@ use rustc::hir::map::Node::NodeBlock;
use rustc::lint::*;
use rustc::middle::const_val::ConstVal;
use rustc::middle::region::CodeExtent;
use rustc::ty;
use rustc::ty::{self, Ty};
use rustc::ty::subst::Subst;
use rustc_const_eval::ConstContext;
use std::collections::HashMap;
@ -985,7 +985,7 @@ fn is_ref_iterable_type(cx: &LateContext, e: &Expr) -> bool {
match_type(cx, ty, &paths::BTREESET)
}
fn is_iterable_array(ty: ty::Ty) -> bool {
fn is_iterable_array(ty: Ty) -> bool {
// IntoIterator is currently only implemented for array sizes <= 32 in rustc
match ty.sty {
ty::TyArray(_, 0...32) => true,

View file

@ -1,7 +1,7 @@
use rustc::hir::*;
use rustc::lint::*;
use rustc::middle::const_val::ConstVal;
use rustc::ty;
use rustc::ty::{self, Ty};
use rustc_const_eval::ConstContext;
use rustc_const_math::ConstInt;
use std::cmp::Ordering;
@ -231,7 +231,7 @@ fn check_single_match_opt_like(
ex: &Expr,
arms: &[Arm],
expr: &Expr,
ty: ty::Ty,
ty: Ty,
els: Option<&Expr>
) {
// list of candidate Enums we know will never get any more members

View file

@ -1,7 +1,7 @@
use rustc::hir;
use rustc::lint::*;
use rustc::middle::const_val::ConstVal;
use rustc::ty;
use rustc::ty::{self, Ty};
use rustc::hir::def::Def;
use rustc_const_eval::ConstContext;
use std::borrow::Cow;
@ -819,7 +819,7 @@ fn lint_or_fun_call(cx: &LateContext, expr: &hir::Expr, name: &str, args: &[hir:
}
/// Checks for the `CLONE_ON_COPY` lint.
fn lint_clone_on_copy(cx: &LateContext, expr: &hir::Expr, arg: &hir::Expr, arg_ty: ty::Ty) {
fn lint_clone_on_copy(cx: &LateContext, expr: &hir::Expr, arg: &hir::Expr, arg_ty: Ty) {
let ty = cx.tables.expr_ty(expr);
if let ty::TyRef(_, ty::TypeAndMut { ty: inner, .. }) = arg_ty.sty {
if let ty::TyRef(..) = inner.sty {
@ -977,8 +977,8 @@ fn lint_iter_skip_next(cx: &LateContext, expr: &hir::Expr) {
}
}
fn derefs_to_slice(cx: &LateContext, expr: &hir::Expr, ty: ty::Ty) -> Option<sugg::Sugg<'static>> {
fn may_slice(cx: &LateContext, ty: ty::Ty) -> bool {
fn derefs_to_slice(cx: &LateContext, expr: &hir::Expr, ty: Ty) -> Option<sugg::Sugg<'static>> {
fn may_slice(cx: &LateContext, ty: Ty) -> bool {
match ty.sty {
ty::TySlice(_) => true,
ty::TyAdt(def, _) if def.is_box() => may_slice(cx, ty.boxed_ty()),
@ -1251,7 +1251,7 @@ fn lint_single_char_pattern(cx: &LateContext, expr: &hir::Expr, arg: &hir::Expr)
}
/// Given a `Result<T, E>` type, return its error type (`E`).
fn get_error_type<'a>(cx: &LateContext, ty: ty::Ty<'a>) -> Option<ty::Ty<'a>> {
fn get_error_type<'a>(cx: &LateContext, ty: Ty<'a>) -> Option<Ty<'a>> {
if let ty::TyAdt(_, substs) = ty.sty {
if match_type(cx, ty, &paths::RESULT) {
substs.types().nth(1)
@ -1264,7 +1264,7 @@ fn get_error_type<'a>(cx: &LateContext, ty: ty::Ty<'a>) -> Option<ty::Ty<'a>> {
}
/// This checks whether a given type is known to implement Debug.
fn has_debug_impl<'a, 'b>(ty: ty::Ty<'a>, cx: &LateContext<'b, 'a>) -> bool {
fn has_debug_impl<'a, 'b>(ty: Ty<'a>, cx: &LateContext<'b, 'a>) -> bool {
match cx.tcx.lang_items.debug_trait() {
Some(debug) => implements_trait(cx, ty, debug, &[]),
None => false,

View file

@ -1,7 +1,7 @@
use rustc::hir;
use rustc::hir::intravisit;
use rustc::lint::*;
use rustc::ty::{TypeAndMut, TyRef};
use rustc::ty;
use utils::{higher, in_external_macro, span_lint};
/// **What it does:** Checks for instances of `mut mut` references.
@ -68,7 +68,7 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for MutVisitor<'a, 'tcx> {
MUT_MUT,
expr.span,
"generally you want to avoid `&mut &mut _` if possible");
} else if let TyRef(_, TypeAndMut { mutbl: hir::MutMutable, .. }) = self.cx.tables.expr_ty(e).sty {
} else if let ty::TyRef(_, ty::TypeAndMut { mutbl: hir::MutMutable, .. }) = self.cx.tables.expr_ty(e).sty {
span_lint(self.cx,
MUT_MUT,
expr.span,

View file

@ -1,5 +1,5 @@
use rustc::lint::*;
use rustc::ty::{TypeAndMut, TypeVariants, TyS};
use rustc::ty::{self, Ty};
use rustc::ty::subst::Subst;
use rustc::hir::*;
use utils::span_lint;
@ -55,15 +55,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnnecessaryMutPassed {
}
}
fn check_arguments(cx: &LateContext, arguments: &[Expr], type_definition: &TyS, name: &str) {
fn check_arguments(cx: &LateContext, arguments: &[Expr], type_definition: Ty, name: &str) {
match type_definition.sty {
TypeVariants::TyFnDef(_, _, fn_type) |
TypeVariants::TyFnPtr(fn_type) => {
ty::TyFnDef(_, _, fn_type) |
ty::TyFnPtr(fn_type) => {
let parameters = fn_type.skip_binder().inputs();
for (argument, parameter) in arguments.iter().zip(parameters.iter()) {
match parameter.sty {
TypeVariants::TyRef(_, TypeAndMut { mutbl: MutImmutable, .. }) |
TypeVariants::TyRawPtr(TypeAndMut { mutbl: MutImmutable, .. }) => {
ty::TyRef(_, ty::TypeAndMut { mutbl: MutImmutable, .. }) |
ty::TyRawPtr(ty::TypeAndMut { mutbl: MutImmutable, .. }) => {
if let ExprAddrOf(MutMutable, _) = argument.node {
span_lint(cx,
UNNECESSARY_MUT_PASSED,

View file

@ -3,7 +3,7 @@
//! This lint is **warn** by default
use rustc::lint::{LintPass, LintArray, LateLintPass, LateContext};
use rustc::ty;
use rustc::ty::{self, Ty};
use rustc::hir::Expr;
use syntax::ast;
use utils::{match_type, paths, span_lint};
@ -59,12 +59,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutexAtomic {
let ty = cx.tables.expr_ty(expr);
if let ty::TyAdt(_, subst) = ty.sty {
if match_type(cx, ty, &paths::MUTEX) {
let mutex_param = &subst.type_at(0).sty;
let mutex_param = subst.type_at(0);
if let Some(atomic_name) = get_atomic_name(mutex_param) {
let msg = format!("Consider using an {} instead of a Mutex here. If you just want the locking \
behaviour and not the internal type, consider using Mutex<()>.",
atomic_name);
match *mutex_param {
match mutex_param.sty {
ty::TyUint(t) if t != ast::UintTy::Us => span_lint(cx, MUTEX_INTEGER, expr.span, &msg),
ty::TyInt(t) if t != ast::IntTy::Is => span_lint(cx, MUTEX_INTEGER, expr.span, &msg),
_ => span_lint(cx, MUTEX_ATOMIC, expr.span, &msg),
@ -75,8 +75,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutexAtomic {
}
}
fn get_atomic_name(ty: &ty::TypeVariants) -> Option<(&'static str)> {
match *ty {
fn get_atomic_name(ty: Ty) -> Option<(&'static str)> {
match ty.sty {
ty::TyBool => Some("AtomicBool"),
ty::TyUint(_) => Some("AtomicUsize"),
ty::TyInt(_) => Some("AtomicIsize"),

View file

@ -1,5 +1,5 @@
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::ty::TyAdt;
use rustc::ty;
use rustc::hir::{Expr, ExprStruct};
use utils::span_lint;
@ -34,7 +34,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
if let ExprStruct(_, ref fields, Some(ref base)) = expr.node {
let ty = cx.tables.expr_ty(expr);
if let TyAdt(def, _) = ty.sty {
if let ty::TyAdt(def, _) = ty.sty {
if fields.len() == def.struct_variant().fields.len() {
span_lint(cx,
NEEDLESS_UPDATE,

View file

@ -2,7 +2,7 @@ use rustc::hir::intravisit::FnKind;
use rustc::hir::def_id::DefId;
use rustc::hir;
use rustc::lint::*;
use rustc::ty;
use rustc::ty::{self, Ty};
use syntax::ast;
use syntax::codemap::Span;
use utils::paths;
@ -150,7 +150,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault {
}
}
fn can_derive_default<'t, 'c>(ty: ty::Ty<'t>, cx: &LateContext<'c, 't>, default_trait_id: DefId) -> Option<Span> {
fn can_derive_default<'t, 'c>(ty: Ty<'t>, cx: &LateContext<'c, 't>, default_trait_id: DefId) -> Option<Span> {
match ty.sty {
ty::TyAdt(adt_def, substs) if adt_def.is_struct() => {
for field in adt_def.all_fields() {

View file

@ -1,6 +1,5 @@
use rustc::lint::*;
use rustc::ty::TypeVariants::{TyRawPtr, TyRef};
use rustc::ty;
use rustc::ty::{self, Ty};
use rustc::hir::*;
use utils::{match_def_path, paths, span_lint, span_lint_and_then, snippet, last_path_segment};
use utils::sugg;
@ -101,7 +100,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
e.span,
&format!("transmute from a type (`{}`) to itself", from_ty))
},
(&TyRef(_, rty), &TyRawPtr(ptr_ty)) => {
(&ty::TyRef(_, rty), &ty::TyRawPtr(ptr_ty)) => {
span_lint_and_then(cx,
USELESS_TRANSMUTE,
e.span,
@ -116,8 +115,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
db.span_suggestion(e.span, "try", sugg.to_string());
})
},
(&ty::TyInt(_), &TyRawPtr(_)) |
(&ty::TyUint(_), &TyRawPtr(_)) => {
(&ty::TyInt(_), &ty::TyRawPtr(_)) |
(&ty::TyUint(_), &ty::TyRawPtr(_)) => {
span_lint_and_then(cx,
USELESS_TRANSMUTE,
e.span,
@ -128,16 +127,16 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
arg.as_ty(&to_ty.to_string()).to_string());
})
},
(&ty::TyFloat(_), &TyRef(..)) |
(&ty::TyFloat(_), &TyRawPtr(_)) |
(&ty::TyChar, &TyRef(..)) |
(&ty::TyChar, &TyRawPtr(_)) => {
(&ty::TyFloat(_), &ty::TyRef(..)) |
(&ty::TyFloat(_), &ty::TyRawPtr(_)) |
(&ty::TyChar, &ty::TyRef(..)) |
(&ty::TyChar, &ty::TyRawPtr(_)) => {
span_lint(cx,
WRONG_TRANSMUTE,
e.span,
&format!("transmute from a `{}` to a pointer", from_ty))
},
(&TyRawPtr(from_ptr), _) if from_ptr.ty == to_ty => {
(&ty::TyRawPtr(from_ptr), _) if from_ptr.ty == to_ty => {
span_lint(cx,
CROSSPOINTER_TRANSMUTE,
e.span,
@ -145,7 +144,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
from_ty,
to_ty))
},
(_, &TyRawPtr(to_ptr)) if to_ptr.ty == from_ty => {
(_, &ty::TyRawPtr(to_ptr)) if to_ptr.ty == from_ty => {
span_lint(cx,
CROSSPOINTER_TRANSMUTE,
e.span,
@ -153,7 +152,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
from_ty,
to_ty))
},
(&TyRawPtr(from_pty), &TyRef(_, to_rty)) => {
(&ty::TyRawPtr(from_pty), &ty::TyRef(_, to_rty)) => {
span_lint_and_then(cx,
TRANSMUTE_PTR_TO_REF,
e.span,
@ -189,7 +188,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Transmute {
/// Get the snippet of `Bar` in `…::transmute<Foo, &Bar>`. If that snippet is not available , use
/// the type's `ToString` implementation. In weird cases it could lead to types with invalid `'_`
/// lifetime, but it should be rare.
fn get_type_snippet(cx: &LateContext, path: &QPath, to_rty: ty::Ty) -> String {
fn get_type_snippet(cx: &LateContext, path: &QPath, to_rty: Ty) -> String {
let seg = last_path_segment(path);
if_let_chain!{[
let PathParameters::AngleBracketedParameters(ref ang) = seg.parameters,

View file

@ -1,8 +1,9 @@
use reexport::*;
use rustc::hir;
use rustc::hir::*;
use rustc::hir::intravisit::{FnKind, Visitor, walk_ty, NestedVisitorMap};
use rustc::lint::*;
use rustc::ty;
use rustc::ty::{self, Ty};
use std::cmp::Ordering;
use syntax::ast::{IntTy, UintTy, FloatTy};
use syntax::attr::IntType;
@ -106,7 +107,7 @@ fn check_fn_decl(cx: &LateContext, decl: &FnDecl) {
}
}
fn check_ty(cx: &LateContext, ast_ty: &Ty) {
fn check_ty(cx: &LateContext, ast_ty: &hir::Ty) {
if in_macro(ast_ty.span) {
return;
}
@ -398,7 +399,7 @@ declare_lint! {
/// Returns the size in bits of an integral type.
/// Will return 0 if the type is not an int or uint variant
fn int_ty_to_nbits(typ: &ty::TyS) -> usize {
fn int_ty_to_nbits(typ: Ty) -> usize {
let n = match typ.sty {
ty::TyInt(i) => 4 << (i as usize),
ty::TyUint(u) => 4 << (u as usize),
@ -412,7 +413,7 @@ fn int_ty_to_nbits(typ: &ty::TyS) -> usize {
}
}
fn is_isize_or_usize(typ: &ty::TyS) -> bool {
fn is_isize_or_usize(typ: Ty) -> bool {
match typ.sty {
ty::TyInt(IntTy::Is) |
ty::TyUint(UintTy::Us) => true,
@ -420,7 +421,7 @@ fn is_isize_or_usize(typ: &ty::TyS) -> bool {
}
}
fn span_precision_loss_lint(cx: &LateContext, expr: &Expr, cast_from: &ty::TyS, cast_to_f64: bool) {
fn span_precision_loss_lint(cx: &LateContext, expr: &Expr, cast_from: Ty, cast_to_f64: bool) {
let mantissa_nbits = if cast_to_f64 { 52 } else { 23 };
let arch_dependent = is_isize_or_usize(cast_from) && cast_to_f64;
let arch_dependent_str = "on targets with 64-bit wide pointers ";
@ -453,7 +454,7 @@ enum ArchSuffix {
None,
}
fn check_truncation_and_wrapping(cx: &LateContext, expr: &Expr, cast_from: &ty::TyS, cast_to: &ty::TyS) {
fn check_truncation_and_wrapping(cx: &LateContext, expr: &Expr, cast_from: Ty, cast_to: Ty) {
let arch_64_suffix = " on targets with 64-bit wide pointers";
let arch_32_suffix = " on targets with 32-bit wide pointers";
let cast_unsigned_to_signed = !cast_from.is_signed() && cast_to.is_signed();
@ -693,7 +694,7 @@ impl<'a, 'tcx> TypeComplexityPass {
}
}
fn check_type(&self, cx: &LateContext, ty: &Ty) {
fn check_type(&self, cx: &LateContext, ty: &hir::Ty) {
if in_macro(ty.span) {
return;
}
@ -724,7 +725,7 @@ struct TypeComplexityVisitor {
}
impl<'tcx> Visitor<'tcx> for TypeComplexityVisitor {
fn visit_ty(&mut self, ty: &'tcx Ty) {
fn visit_ty(&mut self, ty: &'tcx hir::Ty) {
let (add_score, sub_nest) = match ty.node {
// _, &x and *x have only small overhead; don't mess with nesting level
TyInfer | TyPtr(..) | TyRptr(..) => (1, 0),
@ -1070,7 +1071,6 @@ impl Ord for FullInt {
fn numeric_cast_precast_bounds<'a>(cx: &LateContext, expr: &'a Expr) -> Option<(FullInt, FullInt)> {
use rustc::ty::TypeVariants::{TyInt, TyUint};
use syntax::ast::{IntTy, UintTy};
use std::*;
@ -1082,7 +1082,7 @@ fn numeric_cast_precast_bounds<'a>(cx: &LateContext, expr: &'a Expr) -> Option<(
return None;
}
match pre_cast_ty.sty {
TyInt(int_ty) => {
ty::TyInt(int_ty) => {
Some(match int_ty {
IntTy::I8 => (FullInt::S(i8::min_value() as i128), FullInt::S(i8::max_value() as i128)),
IntTy::I16 => (FullInt::S(i16::min_value() as i128), FullInt::S(i16::max_value() as i128)),
@ -1092,7 +1092,7 @@ fn numeric_cast_precast_bounds<'a>(cx: &LateContext, expr: &'a Expr) -> Option<(
IntTy::Is => (FullInt::S(isize::min_value() as i128), FullInt::S(isize::max_value() as i128)),
})
},
TyUint(uint_ty) => {
ty::TyUint(uint_ty) => {
Some(match uint_ty {
UintTy::U8 => (FullInt::U(u8::min_value() as u128), FullInt::U(u8::max_value() as u128)),
UintTy::U16 => (FullInt::U(u16::min_value() as u128), FullInt::U(u16::max_value() as u128)),

View file

@ -1,4 +1,5 @@
use reexport::*;
use rustc::hir;
use rustc::hir::*;
use rustc::hir::def_id::{DefId, CRATE_DEF_INDEX};
use rustc::hir::def::Def;
@ -6,7 +7,7 @@ use rustc::hir::map::Node;
use rustc::lint::{LintContext, LateContext, Level, Lint};
use rustc::session::Session;
use rustc::traits;
use rustc::ty;
use rustc::ty::{self, TyCtxt, Ty};
use rustc::mir::transform::MirSource;
use rustc_errors;
use std::borrow::Cow;
@ -23,12 +24,12 @@ use syntax::symbol::keywords;
pub mod comparisons;
pub mod conf;
pub mod constants;
mod hir;
mod hir_utils;
pub mod paths;
pub mod sugg;
pub mod inspector;
pub mod internal_lints;
pub use self::hir::{SpanlessEq, SpanlessHash};
pub use self::hir_utils::{SpanlessEq, SpanlessHash};
pub type MethodArgs = HirVec<P<Expr>>;
@ -146,7 +147,7 @@ pub fn in_external_macro<'a, T: LintContext<'a>>(cx: &T, span: Span) -> bool {
/// ```
///
/// See also the `paths` module.
pub fn match_def_path(tcx: ty::TyCtxt, def_id: DefId, path: &[&str]) -> bool {
pub fn match_def_path(tcx: TyCtxt, def_id: DefId, path: &[&str]) -> bool {
use syntax::symbol;
struct AbsolutePathBuffer {
@ -172,7 +173,7 @@ pub fn match_def_path(tcx: ty::TyCtxt, def_id: DefId, path: &[&str]) -> bool {
}
/// Check if type is struct, enum or union type with given def path.
pub fn match_type(cx: &LateContext, ty: ty::Ty, path: &[&str]) -> bool {
pub fn match_type(cx: &LateContext, ty: Ty, path: &[&str]) -> bool {
match ty.sty {
ty::TyAdt(adt, _) => match_def_path(cx.tcx, adt.did, path),
_ => false,
@ -308,9 +309,9 @@ pub fn get_trait_def_id(cx: &LateContext, path: &[&str]) -> Option<DefId> {
/// See also `get_trait_def_id`.
pub fn implements_trait<'a, 'tcx>(
cx: &LateContext<'a, 'tcx>,
ty: ty::Ty<'tcx>,
ty: Ty<'tcx>,
trait_id: DefId,
ty_params: &[ty::Ty<'tcx>]
ty_params: &[Ty<'tcx>]
) -> bool {
let ty = cx.tcx.erase_regions(&ty);
let obligation = cx.tcx.predicate_for_trait_def(
@ -581,7 +582,7 @@ pub fn multispan_sugg(db: &mut DiagnosticBuilder, help_msg: String, sugg: Vec<(S
}
/// Return the base type for references and raw pointers.
pub fn walk_ptrs_ty(ty: ty::Ty) -> ty::Ty {
pub fn walk_ptrs_ty(ty: Ty) -> Ty {
match ty.sty {
ty::TyRef(_, ref tm) => walk_ptrs_ty(tm.ty),
_ => ty,
@ -589,8 +590,8 @@ pub fn walk_ptrs_ty(ty: ty::Ty) -> ty::Ty {
}
/// Return the base type for references and raw pointers, and count reference depth.
pub fn walk_ptrs_ty_depth(ty: ty::Ty) -> (ty::Ty, usize) {
fn inner(ty: ty::Ty, depth: usize) -> (ty::Ty, usize) {
pub fn walk_ptrs_ty_depth(ty: Ty) -> (Ty, usize) {
fn inner(ty: Ty, depth: usize) -> (Ty, usize) {
match ty.sty {
ty::TyRef(_, ref tm) => inner(tm.ty, depth + 1),
_ => (ty, depth),
@ -754,7 +755,7 @@ pub fn camel_case_from(s: &str) -> usize {
}
/// Convenience function to get the return type of a function
pub fn return_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, fn_item: NodeId) -> ty::Ty<'tcx> {
pub fn return_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, fn_item: NodeId) -> Ty<'tcx> {
let fn_def_id = cx.tcx.hir.local_def_id(fn_item);
let ret_ty = cx.tcx.type_of(fn_def_id).fn_sig().output();
cx.tcx.erase_late_bound_regions(&ret_ty)
@ -765,8 +766,8 @@ pub fn return_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, fn_item: NodeId) -> ty::T
// not for type parameters.
pub fn same_tys<'a, 'tcx>(
cx: &LateContext<'a, 'tcx>,
a: ty::Ty<'tcx>,
b: ty::Ty<'tcx>
a: Ty<'tcx>,
b: Ty<'tcx>
) -> bool {
cx.tcx.infer_ctxt().enter(|infcx| {
infcx.can_eq(cx.param_env, a, b).is_ok()
@ -774,7 +775,7 @@ pub fn same_tys<'a, 'tcx>(
}
/// Return whether the given type is an `unsafe` function.
pub fn type_is_unsafe_function(ty: ty::Ty) -> bool {
pub fn type_is_unsafe_function(ty: Ty) -> bool {
match ty.sty {
ty::TyFnDef(_, _, f) |
ty::TyFnPtr(f) => f.unsafety() == Unsafety::Unsafe,
@ -782,7 +783,7 @@ pub fn type_is_unsafe_function(ty: ty::Ty) -> bool {
}
}
pub fn is_copy<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: ty::Ty<'tcx>) -> bool {
pub fn is_copy<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool {
!ty.moves_by_default(cx.tcx.global_tcx(), cx.param_env, DUMMY_SP)
}
@ -885,7 +886,7 @@ pub fn is_self(slf: &Arg) -> bool {
}
}
pub fn is_self_ty(slf: &Ty) -> bool {
pub fn is_self_ty(slf: &hir::Ty) -> bool {
if_let_chain! {[
let TyPath(ref qp) = slf.node,
let QPath::Resolved(None, ref path) = *qp,
@ -944,6 +945,6 @@ pub fn is_try(expr: &Expr) -> Option<&Expr> {
None
}
pub fn type_size<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: ty::Ty<'tcx>) -> Option<u64> {
pub fn type_size<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>) -> Option<u64> {
ty.layout(cx.tcx, cx.param_env).ok().map(|layout| layout.size(cx.tcx).bytes())
}

View file

@ -1,6 +1,6 @@
use rustc::hir::*;
use rustc::lint::*;
use rustc::ty;
use rustc::ty::{self, Ty};
use rustc_const_eval::ConstContext;
use syntax::codemap::Span;
use utils::{higher, is_copy, snippet, span_lint_and_then};
@ -35,8 +35,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
// search for `&vec![_]` expressions where the adjusted type is `&[_]`
if_let_chain!{[
let ty::TypeVariants::TyRef(_, ref ty) = cx.tables.expr_ty_adjusted(expr).sty,
let ty::TypeVariants::TySlice(..) = ty.ty.sty,
let ty::TyRef(_, ref ty) = cx.tables.expr_ty_adjusted(expr).sty,
let ty::TySlice(..) = ty.ty.sty,
let ExprAddrOf(_, ref addressee) = expr.node,
let Some(vec_args) = higher::vec_macro(cx, addressee),
], {
@ -88,7 +88,7 @@ fn check_vec_macro(cx: &LateContext, vec_args: &higher::VecArgs, span: Span) {
}
/// Return the item type of the vector (ie. the `T` in `Vec<T>`).
fn vec_type(ty: ty::Ty) -> ty::Ty {
fn vec_type(ty: Ty) -> Ty {
if let ty::TyAdt(_, substs) = ty.sty {
substs.type_at(0)
} else {