-// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
use crate::consts::constant;
use crate::utils::{higher, is_copy, snippet_with_applicability, span_lint_and_sugg};
use if_chain::if_chain;
use rustc_errors::Applicability;
use syntax::source_map::Span;
-/// **What it does:** Checks for usage of `&vec![..]` when using `&[..]` would
-/// be possible.
-///
-/// **Why is this bad?** This is less efficient.
-///
-/// **Known problems:** None.
-///
-/// **Example:**
-/// ```rust,ignore
-/// foo(&vec![1, 2])
-/// ```
declare_clippy_lint! {
+ /// **What it does:** Checks for usage of `&vec![..]` when using `&[..]` would
+ /// be possible.
+ ///
+ /// **Why is this bad?** This is less efficient.
+ ///
+ /// **Known problems:** None.
+ ///
+ /// **Example:**
+ /// ```rust,ignore
+ /// foo(&vec![1, 2])
+ /// ```
pub USELESS_VEC,
perf,
"useless `vec!`"
fn get_lints(&self) -> LintArray {
lint_array!(USELESS_VEC)
}
+
+ fn name(&self) -> &'static str {
+ "UselessVec"
+ }
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
then {
// report the error around the `vec!` not inside `<std macros>:`
let span = arg.span
+ .ctxt()
+ .outer()
+ .expn_info()
+ .map(|info| info.call_site)
+ .expect("unable to get call_site")
.ctxt()
.outer()
.expn_info()
);
}
-/// Return the item type of the vector (ie. the `T` in `Vec<T>`).
+/// Returns the item type of the vector (i.e., the `T` in `Vec<T>`).
fn vec_type(ty: Ty<'_>) -> Ty<'_> {
if let ty::Adt(_, substs) = ty.sty {
substs.type_at(0)