mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-14 01:25:54 +00:00
Mostly apply rustfmt
This commit is contained in:
parent
484e219b93
commit
2a8fca599b
@ -2,7 +2,7 @@ use rustc::lint::*;
|
|||||||
use rustc::middle::const_val::ConstVal;
|
use rustc::middle::const_val::ConstVal;
|
||||||
use rustc::ty;
|
use rustc::ty;
|
||||||
use rustc_const_eval::ConstContext;
|
use rustc_const_eval::ConstContext;
|
||||||
use rustc_const_math::{ConstUsize,ConstIsize,ConstInt};
|
use rustc_const_math::{ConstUsize, ConstIsize, ConstInt};
|
||||||
use rustc::hir;
|
use rustc::hir;
|
||||||
use syntax::ast::RangeLimits;
|
use syntax::ast::RangeLimits;
|
||||||
use utils::{self, higher};
|
use utils::{self, higher};
|
||||||
@ -60,7 +60,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ArrayIndexing {
|
|||||||
// Array with known size can be checked statically
|
// Array with known size can be checked statically
|
||||||
let ty = cx.tables.expr_ty(array);
|
let ty = cx.tables.expr_ty(array);
|
||||||
if let ty::TyArray(_, size) = ty.sty {
|
if let ty::TyArray(_, size) = ty.sty {
|
||||||
let size = ConstInt::Usize(ConstUsize::new(size as u64, cx.sess().target.uint_type).expect("array size is invalid"));
|
let size = ConstInt::Usize(ConstUsize::new(size as u64, cx.sess().target.uint_type)
|
||||||
|
.expect("array size is invalid"));
|
||||||
let constcx = ConstContext::with_tables(cx.tcx, cx.tables);
|
let constcx = ConstContext::with_tables(cx.tcx, cx.tables);
|
||||||
|
|
||||||
// Index is a constant uint
|
// Index is a constant uint
|
||||||
@ -123,23 +124,24 @@ fn to_const_range(
|
|||||||
Some(Some(ConstVal::Integral(x))) => {
|
Some(Some(ConstVal::Integral(x))) => {
|
||||||
if limits == RangeLimits::Closed {
|
if limits == RangeLimits::Closed {
|
||||||
match x {
|
match x {
|
||||||
ConstInt::U8(_) => (x + ConstInt::U8(1)),
|
ConstInt::U8(_) => (x + ConstInt::U8(1)),
|
||||||
ConstInt::U16(_) => (x + ConstInt::U16(1)),
|
ConstInt::U16(_) => (x + ConstInt::U16(1)),
|
||||||
ConstInt::U32(_) => (x + ConstInt::U32(1)),
|
ConstInt::U32(_) => (x + ConstInt::U32(1)),
|
||||||
ConstInt::U64(_) => (x + ConstInt::U64(1)),
|
ConstInt::U64(_) => (x + ConstInt::U64(1)),
|
||||||
ConstInt::U128(_) => (x + ConstInt::U128(1)),
|
ConstInt::U128(_) => (x + ConstInt::U128(1)),
|
||||||
ConstInt::Usize(ConstUsize::Us16(_)) => (x + ConstInt::Usize(ConstUsize::Us16(1))),
|
ConstInt::Usize(ConstUsize::Us16(_)) => (x + ConstInt::Usize(ConstUsize::Us16(1))),
|
||||||
ConstInt::Usize(ConstUsize::Us32(_)) => (x + ConstInt::Usize(ConstUsize::Us32(1))),
|
ConstInt::Usize(ConstUsize::Us32(_)) => (x + ConstInt::Usize(ConstUsize::Us32(1))),
|
||||||
ConstInt::Usize(ConstUsize::Us64(_)) => (x + ConstInt::Usize(ConstUsize::Us64(1))),
|
ConstInt::Usize(ConstUsize::Us64(_)) => (x + ConstInt::Usize(ConstUsize::Us64(1))),
|
||||||
ConstInt::I8(_) => (x + ConstInt::I8(1)),
|
ConstInt::I8(_) => (x + ConstInt::I8(1)),
|
||||||
ConstInt::I16(_) => (x + ConstInt::I16(1)),
|
ConstInt::I16(_) => (x + ConstInt::I16(1)),
|
||||||
ConstInt::I32(_) => (x + ConstInt::I32(1)),
|
ConstInt::I32(_) => (x + ConstInt::I32(1)),
|
||||||
ConstInt::I64(_) => (x + ConstInt::I64(1)),
|
ConstInt::I64(_) => (x + ConstInt::I64(1)),
|
||||||
ConstInt::I128(_) => (x + ConstInt::I128(1)),
|
ConstInt::I128(_) => (x + ConstInt::I128(1)),
|
||||||
ConstInt::Isize(ConstIsize::Is16(_)) => (x + ConstInt::Isize(ConstIsize::Is16(1))),
|
ConstInt::Isize(ConstIsize::Is16(_)) => (x + ConstInt::Isize(ConstIsize::Is16(1))),
|
||||||
ConstInt::Isize(ConstIsize::Is32(_)) => (x + ConstInt::Isize(ConstIsize::Is32(1))),
|
ConstInt::Isize(ConstIsize::Is32(_)) => (x + ConstInt::Isize(ConstIsize::Is32(1))),
|
||||||
ConstInt::Isize(ConstIsize::Is64(_)) => (x + ConstInt::Isize(ConstIsize::Is64(1))),
|
ConstInt::Isize(ConstIsize::Is64(_)) => (x + ConstInt::Isize(ConstIsize::Is64(1))),
|
||||||
}.expect("such a big array is not realistic")
|
}
|
||||||
|
.expect("such a big array is not realistic")
|
||||||
} else {
|
} else {
|
||||||
x
|
x
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ use rustc::hir::def::Def;
|
|||||||
use rustc_const_eval::lookup_const_by_id;
|
use rustc_const_eval::lookup_const_by_id;
|
||||||
use rustc_const_math::ConstInt;
|
use rustc_const_math::ConstInt;
|
||||||
use rustc::hir::*;
|
use rustc::hir::*;
|
||||||
use rustc::ty::{TyCtxt, self};
|
use rustc::ty::{self, TyCtxt};
|
||||||
use std::cmp::Ordering::{self, Equal};
|
use std::cmp::Ordering::{self, Equal};
|
||||||
use std::cmp::PartialOrd;
|
use std::cmp::PartialOrd;
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
@ -179,17 +179,15 @@ pub fn lit_to_constant<'a, 'tcx>(lit: &LitKind, tcx: TyCtxt<'a, 'tcx, 'tcx>, mut
|
|||||||
match (&ty.sty, hint) {
|
match (&ty.sty, hint) {
|
||||||
(&ty::TyInt(ity), _) |
|
(&ty::TyInt(ity), _) |
|
||||||
(_, Signed(ity)) => {
|
(_, Signed(ity)) => {
|
||||||
Constant::Int(ConstInt::new_signed_truncating(n as i128,
|
Constant::Int(ConstInt::new_signed_truncating(n as i128, ity, tcx.sess.target.int_type))
|
||||||
ity, tcx.sess.target.int_type))
|
},
|
||||||
}
|
|
||||||
(&ty::TyUint(uty), _) |
|
(&ty::TyUint(uty), _) |
|
||||||
(_, Unsigned(uty)) => {
|
(_, Unsigned(uty)) => {
|
||||||
Constant::Int(ConstInt::new_unsigned_truncating(n as u128,
|
Constant::Int(ConstInt::new_unsigned_truncating(n as u128, uty, tcx.sess.target.uint_type))
|
||||||
uty, tcx.sess.target.uint_type))
|
},
|
||||||
}
|
_ => bug!(),
|
||||||
_ => bug!()
|
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
LitKind::Float(ref is, ty) => Constant::Float(is.to_string(), ty.into()),
|
LitKind::Float(ref is, ty) => Constant::Float(is.to_string(), ty.into()),
|
||||||
LitKind::FloatUnsuffixed(ref is) => Constant::Float(is.to_string(), FloatWidth::Any),
|
LitKind::FloatUnsuffixed(ref is) => Constant::Float(is.to_string(), FloatWidth::Any),
|
||||||
LitKind::Bool(b) => Constant::Bool(b),
|
LitKind::Bool(b) => Constant::Bool(b),
|
||||||
@ -291,7 +289,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
|
|||||||
if let Some((const_expr, tables)) = lookup_const_by_id(self.tcx, def_id, substs) {
|
if let Some((const_expr, tables)) = lookup_const_by_id(self.tcx, def_id, substs) {
|
||||||
let mut cx = ConstEvalLateContext {
|
let mut cx = ConstEvalLateContext {
|
||||||
tcx: self.tcx,
|
tcx: self.tcx,
|
||||||
tables,
|
tables: tables,
|
||||||
needed_resolution: false,
|
needed_resolution: false,
|
||||||
};
|
};
|
||||||
let ret = cx.expr(const_expr);
|
let ret = cx.expr(const_expr);
|
||||||
|
@ -66,7 +66,8 @@ fn check_closure(cx: &LateContext, expr: &Expr) {
|
|||||||
// Is it an unsafe function? They don't implement the closure traits
|
// Is it an unsafe function? They don't implement the closure traits
|
||||||
ty::TyFnDef(_, _, fn_ty) |
|
ty::TyFnDef(_, _, fn_ty) |
|
||||||
ty::TyFnPtr(fn_ty) => {
|
ty::TyFnPtr(fn_ty) => {
|
||||||
if fn_ty.skip_binder().unsafety == Unsafety::Unsafe || fn_ty.skip_binder().output().sty == ty::TyNever {
|
if fn_ty.skip_binder().unsafety == Unsafety::Unsafe ||
|
||||||
|
fn_ty.skip_binder().output().sty == ty::TyNever {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -211,14 +211,14 @@ fn report_single_match_single_pattern(cx: &LateContext, ex: &Expr, arms: &[Arm],
|
|||||||
};
|
};
|
||||||
let els_str = els.map_or(String::new(), |els| format!(" else {}", expr_block(cx, els, None, "..")));
|
let els_str = els.map_or(String::new(), |els| format!(" else {}", expr_block(cx, els, None, "..")));
|
||||||
span_lint_and_then(cx,
|
span_lint_and_then(cx,
|
||||||
lint,
|
lint,
|
||||||
expr.span,
|
expr.span,
|
||||||
"you seem to be trying to use match for destructuring a single pattern. \
|
"you seem to be trying to use match for destructuring a single pattern. Consider using `if \
|
||||||
Consider using `if let`",
|
let`",
|
||||||
|db| {
|
|db| {
|
||||||
db.span_suggestion(expr.span,
|
db.span_suggestion(expr.span,
|
||||||
"try this",
|
"try this",
|
||||||
format!("if let {} = {} {}{}",
|
format!("if let {} = {} {}{}",
|
||||||
snippet(cx, arms[0].pats[0].span, ".."),
|
snippet(cx, arms[0].pats[0].span, ".."),
|
||||||
snippet(cx, ex.span, ".."),
|
snippet(cx, ex.span, ".."),
|
||||||
expr_block(cx, &arms[0].body, None, ".."),
|
expr_block(cx, &arms[0].body, None, ".."),
|
||||||
|
@ -382,7 +382,7 @@ fn is_allowed(cx: &LateContext, expr: &Expr) -> bool {
|
|||||||
|
|
||||||
val.try_cmp(zero) == Ok(Ordering::Equal) || val.try_cmp(infinity) == Ok(Ordering::Equal) ||
|
val.try_cmp(zero) == Ok(Ordering::Equal) || val.try_cmp(infinity) == Ok(Ordering::Equal) ||
|
||||||
val.try_cmp(neg_infinity) == Ok(Ordering::Equal)
|
val.try_cmp(neg_infinity) == Ok(Ordering::Equal)
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
@ -975,7 +975,7 @@ pub fn is_try(expr: &Expr) -> Option<&Expr> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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::Ty<'tcx>) -> Option<u64> {
|
||||||
cx.tcx.infer_ctxt((), Reveal::All).enter(|infcx|
|
cx.tcx
|
||||||
ty.layout(&infcx).ok().map(|lay| lay.size(&TargetDataLayout::parse(cx.sess())).bytes())
|
.infer_ctxt((), Reveal::All)
|
||||||
)
|
.enter(|infcx| ty.layout(&infcx).ok().map(|lay| lay.size(&TargetDataLayout::parse(cx.sess())).bytes()))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user