Rustup to *rustc 1.15.0-nightly (3bf2be9ce 2016-11-22)*

This commit is contained in:
mcarton 2016-11-23 22:44:00 +01:00
parent 0b7de0d01f
commit c7e3cc1e27
No known key found for this signature in database
GPG Key ID: 5E427C794CBA45E8
13 changed files with 36 additions and 62 deletions

View File

@ -9,7 +9,6 @@
use std::cmp::PartialOrd;
use std::hash::{Hash, Hasher};
use std::mem;
use std::ops::Deref;
use std::rc::Rc;
use syntax::ast::{FloatTy, LitIntType, LitKind, StrStyle, UintTy, IntTy};
use syntax::ptr::P;
@ -279,7 +278,7 @@ fn expr(&mut self, e: &Expr) -> Option<Constant> {
/// create `Some(Vec![..])` of all constants, unless there is any
/// non-constant part
fn multi<E: Deref<Target = Expr> + Sized>(&mut self, vec: &[E]) -> Option<Vec<Constant>> {
fn multi(&mut self, vec: &[Expr]) -> Option<Vec<Constant>> {
vec.iter()
.map(|elem| self.expr(elem))
.collect::<Option<_>>()

View File

@ -44,7 +44,7 @@ fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
if args.len() != 1 {
return;
}
check_drop_arg(cx, expr.span, &*args[0]);
check_drop_arg(cx, expr.span, &args[0]);
}
}
}

View File

@ -117,7 +117,7 @@ fn visit_expr(&mut self, expr: &'v Expr) {
let ExprMethodCall(ref name, _, ref params) = expr.node,
params.len() == 3,
&*name.node.as_str() == "insert",
get_item_name(self.cx, self.map) == get_item_name(self.cx, &*params[0]),
get_item_name(self.cx, self.map) == get_item_name(self.cx, &params[0]),
SpanlessEq::new(self.cx).eq_expr(self.key, &params[1])
], {
span_lint_and_then(self.cx, MAP_ENTRY, self.span,

View File

@ -4,7 +4,6 @@
use rustc::hir::*;
use syntax::ast::{Lit, LitKind, Name};
use syntax::codemap::{Span, Spanned};
use syntax::ptr::P;
use utils::{get_item_name, in_macro, snippet, span_lint, span_lint_and_then, walk_ptrs_ty};
/// **What it does:** Checks for getting the length of something via `.len()`
@ -170,7 +169,7 @@ fn check_cmp(cx: &LateContext, span: Span, left: &Expr, right: &Expr, op: &str)
}
}
fn check_len_zero(cx: &LateContext, span: Span, name: &Name, args: &[P<Expr>], lit: &Lit, op: &str) {
fn check_len_zero(cx: &LateContext, span: Span, name: &Name, args: &[Expr], lit: &Lit, op: &str) {
if let Spanned { node: LitKind::Int(0, _), .. } = *lit {
if &*name.as_str() == "len" && args.len() == 1 && has_is_empty(cx, &args[0]) {
span_lint_and_then(cx, LEN_ZERO, span, "length comparison to zero", |db| {

View File

@ -8,11 +8,9 @@
use std::borrow::Cow;
use std::fmt;
use syntax::codemap::Span;
use syntax::ptr::P;
use utils::{get_trait_def_id, implements_trait, in_external_macro, in_macro, is_copy, match_path,
match_trait_method, match_type, method_chain_args, return_ty, same_tys, snippet,
span_lint, span_lint_and_then, span_note_and_lint, walk_ptrs_ty, walk_ptrs_ty_depth};
use utils::MethodArgs;
use utils::paths;
use utils::sugg;
@ -693,7 +691,7 @@ fn check_impl_item(&mut self, cx: &LateContext, implitem: &hir::ImplItem) {
}
/// Checks for the `OR_FUN_CALL` lint.
fn lint_or_fun_call(cx: &LateContext, expr: &hir::Expr, name: &str, args: &[P<hir::Expr>]) {
fn lint_or_fun_call(cx: &LateContext, expr: &hir::Expr, name: &str, args: &[hir::Expr]) {
/// Check for `unwrap_or(T::new())` or `unwrap_or(T::default())`.
fn check_unwrap_or_default(cx: &LateContext, name: &str, fun: &hir::Expr, self_expr: &hir::Expr, arg: &hir::Expr,
or_has_args: bool, span: Span)
@ -825,7 +823,7 @@ fn lint_clone_on_copy(cx: &LateContext, expr: &hir::Expr, arg: &hir::Expr, arg_t
}
}
fn lint_vec_extend(cx: &LateContext, expr: &hir::Expr, args: &MethodArgs) {
fn lint_vec_extend(cx: &LateContext, expr: &hir::Expr, args: &[hir::Expr]) {
let arg_ty = cx.tcx.tables().expr_ty(&args[1]);
if let Some(slice) = derefs_to_slice(cx, &args[1], arg_ty) {
span_lint_and_then(cx, EXTEND_FROM_SLICE, expr.span, "use of `extend` to extend a Vec by a slice", |db| {
@ -838,7 +836,7 @@ fn lint_vec_extend(cx: &LateContext, expr: &hir::Expr, args: &MethodArgs) {
}
}
fn lint_string_extend(cx: &LateContext, expr: &hir::Expr, args: &MethodArgs) {
fn lint_string_extend(cx: &LateContext, expr: &hir::Expr, args: &[hir::Expr]) {
let arg = &args[1];
if let Some(arglists) = method_chain_args(arg, &["chars"]) {
let target = &arglists[0][0];
@ -866,7 +864,7 @@ fn lint_string_extend(cx: &LateContext, expr: &hir::Expr, args: &MethodArgs) {
}
}
fn lint_extend(cx: &LateContext, expr: &hir::Expr, args: &MethodArgs) {
fn lint_extend(cx: &LateContext, expr: &hir::Expr, args: &[hir::Expr]) {
let (obj_ty, _) = walk_ptrs_ty_depth(cx.tcx.tables().expr_ty(&args[0]));
if match_type(cx, obj_ty, &paths::VEC) {
lint_vec_extend(cx, expr, args);
@ -891,9 +889,7 @@ fn lint_cstring_as_ptr(cx: &LateContext, expr: &hir::Expr, new: &hir::Expr, unwr
}}
}
#[allow(ptr_arg)]
// Type of MethodArgs is potentially a Vec
fn lint_iter_nth(cx: &LateContext, expr: &hir::Expr, iter_args: &MethodArgs, is_mut: bool){
fn lint_iter_nth(cx: &LateContext, expr: &hir::Expr, iter_args: &[hir::Expr], is_mut: bool){
let mut_str = if is_mut { "_mut" } else {""};
let caller_type = if derefs_to_slice(cx, &iter_args[0], cx.tcx.tables().expr_ty(&iter_args[0])).is_some() {
"slice"
@ -917,7 +913,7 @@ fn lint_iter_nth(cx: &LateContext, expr: &hir::Expr, iter_args: &MethodArgs, is_
);
}
fn lint_get_unwrap(cx: &LateContext, expr: &hir::Expr, get_args: &MethodArgs, is_mut: bool) {
fn lint_get_unwrap(cx: &LateContext, expr: &hir::Expr, get_args: &[hir::Expr], is_mut: bool) {
// Note: we don't want to lint `get_mut().unwrap` for HashMap or BTreeMap,
// because they do not implement `IndexMut`
let expr_ty = cx.tcx.tables().expr_ty(&get_args[0]);
@ -980,7 +976,7 @@ fn may_slice(cx: &LateContext, ty: ty::Ty) -> bool {
if let hir::ExprMethodCall(name, _, ref args) = expr.node {
if &*name.node.as_str() == "iter" && may_slice(cx, cx.tcx.tables().expr_ty(&args[0])) {
sugg::Sugg::hir_opt(cx, &*args[0]).map(|sugg| {
sugg::Sugg::hir_opt(cx, &args[0]).map(|sugg| {
sugg.addr()
})
} else {
@ -1002,10 +998,8 @@ fn may_slice(cx: &LateContext, ty: ty::Ty) -> bool {
}
}
#[allow(ptr_arg)]
// Type of MethodArgs is potentially a Vec
/// lint use of `unwrap()` for `Option`s and `Result`s
fn lint_unwrap(cx: &LateContext, expr: &hir::Expr, unwrap_args: &MethodArgs) {
fn lint_unwrap(cx: &LateContext, expr: &hir::Expr, unwrap_args: &[hir::Expr]) {
let (obj_ty, _) = walk_ptrs_ty_depth(cx.tcx.tables().expr_ty(&unwrap_args[0]));
let mess = if match_type(cx, obj_ty, &paths::OPTION) {
@ -1028,10 +1022,8 @@ fn lint_unwrap(cx: &LateContext, expr: &hir::Expr, unwrap_args: &MethodArgs) {
}
}
#[allow(ptr_arg)]
// Type of MethodArgs is potentially a Vec
/// lint use of `ok().expect()` for `Result`s
fn lint_ok_expect(cx: &LateContext, expr: &hir::Expr, ok_args: &MethodArgs) {
fn lint_ok_expect(cx: &LateContext, expr: &hir::Expr, ok_args: &[hir::Expr]) {
// lint if the caller of `ok()` is a `Result`
if match_type(cx, cx.tcx.tables().expr_ty(&ok_args[0]), &paths::RESULT) {
let result_type = cx.tcx.tables().expr_ty(&ok_args[0]);
@ -1046,10 +1038,8 @@ fn lint_ok_expect(cx: &LateContext, expr: &hir::Expr, ok_args: &MethodArgs) {
}
}
#[allow(ptr_arg)]
// Type of MethodArgs is potentially a Vec
/// lint use of `map().unwrap_or()` for `Option`s
fn lint_map_unwrap_or(cx: &LateContext, expr: &hir::Expr, map_args: &MethodArgs, unwrap_args: &MethodArgs) {
fn lint_map_unwrap_or(cx: &LateContext, expr: &hir::Expr, map_args: &[hir::Expr], unwrap_args: &[hir::Expr]) {
// lint if the caller of `map()` is an `Option`
if match_type(cx, cx.tcx.tables().expr_ty(&map_args[0]), &paths::OPTION) {
// lint message
@ -1077,10 +1067,8 @@ fn lint_map_unwrap_or(cx: &LateContext, expr: &hir::Expr, map_args: &MethodArgs,
}
}
#[allow(ptr_arg)]
// Type of MethodArgs is potentially a Vec
/// lint use of `map().unwrap_or_else()` for `Option`s
fn lint_map_unwrap_or_else(cx: &LateContext, expr: &hir::Expr, map_args: &MethodArgs, unwrap_args: &MethodArgs) {
fn lint_map_unwrap_or_else(cx: &LateContext, expr: &hir::Expr, map_args: &[hir::Expr], unwrap_args: &[hir::Expr]) {
// lint if the caller of `map()` is an `Option`
if match_type(cx, cx.tcx.tables().expr_ty(&map_args[0]), &paths::OPTION) {
// lint message
@ -1108,10 +1096,8 @@ fn lint_map_unwrap_or_else(cx: &LateContext, expr: &hir::Expr, map_args: &Method
}
}
#[allow(ptr_arg)]
// Type of MethodArgs is potentially a Vec
/// lint use of `filter().next()` for `Iterators`
fn lint_filter_next(cx: &LateContext, expr: &hir::Expr, filter_args: &MethodArgs) {
fn lint_filter_next(cx: &LateContext, expr: &hir::Expr, filter_args: &[hir::Expr]) {
// lint if caller of `.filter().next()` is an Iterator
if match_trait_method(cx, expr, &paths::ITERATOR) {
let msg = "called `filter(p).next()` on an `Iterator`. This is more succinctly expressed by calling `.find(p)` \
@ -1131,9 +1117,8 @@ fn lint_filter_next(cx: &LateContext, expr: &hir::Expr, filter_args: &MethodArgs
}
}
// Type of MethodArgs is potentially a Vec
/// lint use of `filter().map()` for `Iterators`
fn lint_filter_map(cx: &LateContext, expr: &hir::Expr, _filter_args: &MethodArgs, _map_args: &MethodArgs) {
fn lint_filter_map(cx: &LateContext, expr: &hir::Expr, _filter_args: &[hir::Expr], _map_args: &[hir::Expr]) {
// lint if caller of `.filter().map()` is an Iterator
if match_trait_method(cx, expr, &paths::ITERATOR) {
let msg = "called `filter(p).map(q)` on an `Iterator`. \
@ -1142,9 +1127,8 @@ fn lint_filter_map(cx: &LateContext, expr: &hir::Expr, _filter_args: &MethodArgs
}
}
// Type of MethodArgs is potentially a Vec
/// lint use of `filter().map()` for `Iterators`
fn lint_filter_map_map(cx: &LateContext, expr: &hir::Expr, _filter_args: &MethodArgs, _map_args: &MethodArgs) {
fn lint_filter_map_map(cx: &LateContext, expr: &hir::Expr, _filter_args: &[hir::Expr], _map_args: &[hir::Expr]) {
// lint if caller of `.filter().map()` is an Iterator
if match_trait_method(cx, expr, &paths::ITERATOR) {
let msg = "called `filter_map(p).map(q)` on an `Iterator`. \
@ -1153,9 +1137,8 @@ fn lint_filter_map_map(cx: &LateContext, expr: &hir::Expr, _filter_args: &Method
}
}
// Type of MethodArgs is potentially a Vec
/// lint use of `filter().flat_map()` for `Iterators`
fn lint_filter_flat_map(cx: &LateContext, expr: &hir::Expr, _filter_args: &MethodArgs, _map_args: &MethodArgs) {
fn lint_filter_flat_map(cx: &LateContext, expr: &hir::Expr, _filter_args: &[hir::Expr], _map_args: &[hir::Expr]) {
// lint if caller of `.filter().flat_map()` is an Iterator
if match_trait_method(cx, expr, &paths::ITERATOR) {
let msg = "called `filter(p).flat_map(q)` on an `Iterator`. \
@ -1165,9 +1148,8 @@ fn lint_filter_flat_map(cx: &LateContext, expr: &hir::Expr, _filter_args: &Metho
}
}
// Type of MethodArgs is potentially a Vec
/// lint use of `filter_map().flat_map()` for `Iterators`
fn lint_filter_map_flat_map(cx: &LateContext, expr: &hir::Expr, _filter_args: &MethodArgs, _map_args: &MethodArgs) {
fn lint_filter_map_flat_map(cx: &LateContext, expr: &hir::Expr, _filter_args: &[hir::Expr], _map_args: &[hir::Expr]) {
// lint if caller of `.filter_map().flat_map()` is an Iterator
if match_trait_method(cx, expr, &paths::ITERATOR) {
let msg = "called `filter_map(p).flat_map(q)` on an `Iterator`. \
@ -1177,13 +1159,11 @@ fn lint_filter_map_flat_map(cx: &LateContext, expr: &hir::Expr, _filter_args: &M
}
}
#[allow(ptr_arg)]
// Type of MethodArgs is potentially a Vec
/// lint searching an Iterator followed by `is_some()`
fn lint_search_is_some(cx: &LateContext, expr: &hir::Expr, search_method: &str, search_args: &MethodArgs,
is_some_args: &MethodArgs) {
fn lint_search_is_some(cx: &LateContext, expr: &hir::Expr, search_method: &str, search_args: &[hir::Expr],
is_some_args: &[hir::Expr]) {
// lint if caller of search is an Iterator
if match_trait_method(cx, &*is_some_args[0], &paths::ITERATOR) {
if match_trait_method(cx, &is_some_args[0], &paths::ITERATOR) {
let msg = format!("called `is_some()` after searching an `Iterator` with {}. This is more succinctly expressed \
by calling `any()`.",
search_method);

View File

@ -2,7 +2,6 @@
use rustc::lint::*;
use rustc::hir::*;
use std::cmp::{PartialOrd, Ordering};
use syntax::ptr::P;
use utils::{match_def_path, paths, span_lint};
/// **What it does:** Checks for expressions where `std::cmp::min` and `max` are
@ -80,7 +79,7 @@ fn min_max<'a>(cx: &LateContext, expr: &'a Expr) -> Option<(MinMax, Constant, &'
}
}
fn fetch_const(args: &[P<Expr>], m: MinMax) -> Option<(MinMax, Constant, &Expr)> {
fn fetch_const(args: &[Expr], m: MinMax) -> Option<(MinMax, Constant, &Expr)> {
if args.len() != 2 {
return None;
}

View File

@ -8,7 +8,6 @@
use rustc_const_eval::eval_const_expr_partial;
use rustc_const_math::ConstFloat;
use syntax::codemap::{Span, Spanned, ExpnFormat};
use syntax::ptr::P;
use utils::{
get_item_name, get_parent_expr, implements_trait, in_macro, is_integer_literal, match_path,
snippet, span_lint, span_lint_and_then, walk_ptrs_ty
@ -412,7 +411,7 @@ fn check_to_owned(cx: &LateContext, expr: &Expr, other: &Expr, left: bool, op: S
}
fn is_str_arg(cx: &LateContext, args: &[P<Expr>]) -> bool {
fn is_str_arg(cx: &LateContext, args: &[Expr]) -> bool {
args.len() == 1 &&
matches!(walk_ptrs_ty(cx.tcx.tables().expr_ty(&args[0])).sty, ty::TyStr)
}

View File

@ -1,7 +1,6 @@
use rustc::lint::*;
use rustc::ty::{TypeAndMut, TypeVariants, MethodCall, TyS};
use rustc::hir::*;
use syntax::ptr::P;
use utils::span_lint;
/// **What it does:** Detects giving a mutable reference to a function that only
@ -57,7 +56,7 @@ fn check_expr(&mut self, cx: &LateContext, e: &Expr) {
}
}
fn check_arguments(cx: &LateContext, arguments: &[P<Expr>], type_definition: &TyS, name: &str) {
fn check_arguments(cx: &LateContext, arguments: &[Expr], type_definition: &TyS, name: &str) {
match type_definition.sty {
TypeVariants::TyFnDef(_, _, fn_type) |
TypeVariants::TyFnPtr(fn_type) => {

View File

@ -133,7 +133,7 @@ fn reduce_expression<'a>(cx: &LateContext, expr: &'a Expr) -> Option<Vec<&'a Exp
Expr_::ExprIndex(ref a, ref b) |
Expr_::ExprBinary(_, ref a, ref b) => Some(vec![&**a, &**b]),
Expr_::ExprArray(ref v) |
Expr_::ExprTup(ref v) => Some(v.iter().map(Deref::deref).collect()),
Expr_::ExprTup(ref v) => Some(v.iter().collect()),
Expr_::ExprRepeat(ref inner, _) |
Expr_::ExprCast(ref inner, _) |
Expr_::ExprType(ref inner, _) |
@ -150,7 +150,7 @@ fn reduce_expression<'a>(cx: &LateContext, expr: &'a Expr) -> Option<Vec<&'a Exp
Some(Def::Struct(..)) |
Some(Def::Variant(..)) |
Some(Def::StructCtor(..)) |
Some(Def::VariantCtor(..)) => Some(args.iter().map(Deref::deref).collect()),
Some(Def::VariantCtor(..)) => Some(args.iter().collect()),
_ => None,
}
}

View File

@ -107,7 +107,7 @@ fn check_expr(&mut self, cx: &LateContext, e: &Expr) {
e.span,
"transmute from a reference to a pointer",
|db| {
if let Some(arg) = sugg::Sugg::hir_opt(cx, &*args[0]) {
if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) {
let sugg = if ptr_ty == rty {
arg.as_ty(to_ty)
} else {
@ -125,7 +125,7 @@ fn check_expr(&mut self, cx: &LateContext, e: &Expr) {
e.span,
"transmute from an integer to a pointer",
|db| {
if let Some(arg) = sugg::Sugg::hir_opt(cx, &*args[0]) {
if let Some(arg) = sugg::Sugg::hir_opt(cx, &args[0]) {
db.span_suggestion(e.span, "try", arg.as_ty(&to_ty.to_string()).to_string());
}
},

View File

@ -5,7 +5,6 @@
use rustc::hir;
use rustc::lint::LateContext;
use syntax::ast;
use syntax::ptr::P;
use utils::{is_expn_of, match_path, match_def_path, resolve_node, paths};
/// Convert a hir binary operator to the corresponding `ast` type.
@ -160,9 +159,9 @@ pub fn for_loop(expr: &hir::Expr) -> Option<(&hir::Pat, &hir::Expr, &hir::Expr)>
/// Represent the pre-expansion arguments of a `vec!` invocation.
pub enum VecArgs<'a> {
/// `vec![elem; len]`
Repeat(&'a P<hir::Expr>, &'a P<hir::Expr>),
Repeat(&'a hir::Expr, &'a hir::Expr),
/// `vec![a, b, c]`
Vec(&'a [P<hir::Expr>]),
Vec(&'a [hir::Expr]),
}
/// Returns the arguments of the `vec!` macro if this expression was expanded from `vec!`.

View File

@ -134,7 +134,7 @@ pub fn eq_expr(&self, left: &Expr, right: &Expr) -> bool {
}
}
fn eq_exprs(&self, left: &[P<Expr>], right: &[P<Expr>]) -> bool {
fn eq_exprs(&self, left: &P<[Expr]>, right: &P<[Expr]>) -> bool {
over(left, right, |l, r| self.eq_expr(l, r))
}
@ -510,7 +510,7 @@ pub fn hash_expr(&mut self, e: &Expr) {
}
}
pub fn hash_exprs(&mut self, e: &[P<Expr>]) {
pub fn hash_exprs(&mut self, e: &P<[Expr]>) {
for e in e {
self.hash_expr(e);
}

View File

@ -292,14 +292,14 @@ pub fn resolve_node(cx: &LateContext, id: NodeId) -> Option<def::Def> {
/// For example, if `expr` represents the `.baz()` in `foo.bar().baz()`,
/// `matched_method_chain(expr, &["bar", "baz"])` will return a `Vec` containing the `Expr`s for
/// `.bar()` and `.baz()`
pub fn method_chain_args<'a>(expr: &'a Expr, methods: &[&str]) -> Option<Vec<&'a MethodArgs>> {
pub fn method_chain_args<'a>(expr: &'a Expr, methods: &[&str]) -> Option<Vec<&'a [Expr]>> {
let mut current = expr;
let mut matched = Vec::with_capacity(methods.len());
for method_name in methods.iter().rev() {
// method chains are stored last -> first
if let ExprMethodCall(ref name, _, ref args) = current.node {
if name.node == *method_name {
matched.push(args); // build up `matched` backwards
matched.push(&**args); // build up `matched` backwards
current = &args[0] // go to parent expression
} else {
return None;