mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 15:11:30 +00:00
Merge pull request #1360 from Manishearth/rustup
Rustup to *rustc 1.15.0-nightly (3bf2be9ce 2016-11-22)* and bump to 0.0.102
This commit is contained in:
commit
11ca07c8ad
16 changed files with 42 additions and 65 deletions
|
@ -1,6 +1,9 @@
|
|||
# Change Log
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## 0.0.102 — date
|
||||
* Update to *rustc 1.15.0-nightly (3bf2be9ce 2016-11-22)*
|
||||
|
||||
## 0.0.101 — 2016-11-23
|
||||
* Update to *rustc 1.15.0-nightly (7b3eeea22 2016-11-21)*
|
||||
* New lint: [`string_extend_chars`]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "clippy"
|
||||
version = "0.0.101"
|
||||
version = "0.0.102"
|
||||
authors = [
|
||||
"Manish Goregaokar <manishsmail@gmail.com>",
|
||||
"Andre Bogus <bogusandre@gmail.com>",
|
||||
|
@ -25,7 +25,7 @@ test = false
|
|||
|
||||
[dependencies]
|
||||
# begin automatic update
|
||||
clippy_lints = { version = "0.0.101", path = "clippy_lints" }
|
||||
clippy_lints = { version = "0.0.102", path = "clippy_lints" }
|
||||
# end automatic update
|
||||
|
||||
[dev-dependencies]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "clippy_lints"
|
||||
# begin automatic update
|
||||
version = "0.0.101"
|
||||
version = "0.0.102"
|
||||
# end automatic update
|
||||
authors = [
|
||||
"Manish Goregaokar <manishsmail@gmail.com>",
|
||||
|
|
|
@ -9,7 +9,6 @@ use std::cmp::Ordering::{self, Equal};
|
|||
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 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
|
|||
|
||||
/// 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<_>>()
|
||||
|
|
|
@ -44,7 +44,7 @@ impl LateLintPass for Pass {
|
|||
if args.len() != 1 {
|
||||
return;
|
||||
}
|
||||
check_drop_arg(cx, expr.span, &*args[0]);
|
||||
check_drop_arg(cx, expr.span, &args[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -117,7 +117,7 @@ impl<'a, 'tcx, 'v, 'b> Visitor<'v> for InsertVisitor<'a, 'tcx, 'b> {
|
|||
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, ¶ms[0]),
|
||||
SpanlessEq::new(self.cx).eq_expr(self.key, ¶ms[1])
|
||||
], {
|
||||
span_lint_and_then(self.cx, MAP_ENTRY, self.span,
|
||||
|
|
|
@ -4,7 +4,6 @@ use rustc::ty;
|
|||
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| {
|
||||
|
|
|
@ -8,11 +8,9 @@ use rustc_const_eval::eval_const_expr_partial;
|
|||
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 @@ impl LateLintPass for Pass {
|
|||
}
|
||||
|
||||
/// 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 derefs_to_slice(cx: &LateContext, expr: &hir::Expr, ty: ty::Ty) -> Option<sug
|
|||
|
||||
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 derefs_to_slice(cx: &LateContext, expr: &hir::Expr, ty: ty::Ty) -> Option<sug
|
|||
}
|
||||
}
|
||||
|
||||
#[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);
|
||||
|
|
|
@ -2,7 +2,6 @@ use consts::{Constant, constant_simple};
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ use rustc_const_eval::EvalHint::ExprTypeChecked;
|
|||
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)
|
||||
}
|
||||
|
|
|
@ -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 @@ impl LateLintPass for UnnecessaryMutPassed {
|
|||
}
|
||||
}
|
||||
|
||||
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) => {
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -107,7 +107,7 @@ impl LateLintPass for Transmute {
|
|||
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 @@ impl LateLintPass for Transmute {
|
|||
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());
|
||||
}
|
||||
},
|
||||
|
|
|
@ -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!`.
|
||||
|
|
|
@ -134,7 +134,7 @@ impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
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 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue