deprecate extend_from_slice lint

This commit is contained in:
Andre Bogus 2017-01-14 14:39:41 +01:00
parent e3605dd29b
commit 2fdb6e4d1a
5 changed files with 18 additions and 66 deletions

View file

@ -180,7 +180,7 @@ transparently:
## Lints ## Lints
There are 184 lints included in this crate: There are 183 lints included in this crate:
name | default | triggers on name | default | triggers on
-----------------------------------------------------------------------------------------------------------------------|---------|---------------------------------------------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------------------------------|---------|----------------------------------------------------------------------------------------------------------------------------------
@ -230,7 +230,6 @@ name
[explicit_counter_loop](https://github.com/Manishearth/rust-clippy/wiki#explicit_counter_loop) | warn | for-looping with an explicit counter when `_.enumerate()` would do [explicit_counter_loop](https://github.com/Manishearth/rust-clippy/wiki#explicit_counter_loop) | warn | for-looping with an explicit counter when `_.enumerate()` would do
[explicit_into_iter_loop](https://github.com/Manishearth/rust-clippy/wiki#explicit_into_iter_loop) | warn | for-looping over `_.into_iter()` when `_` would do [explicit_into_iter_loop](https://github.com/Manishearth/rust-clippy/wiki#explicit_into_iter_loop) | warn | for-looping over `_.into_iter()` when `_` would do
[explicit_iter_loop](https://github.com/Manishearth/rust-clippy/wiki#explicit_iter_loop) | warn | for-looping over `_.iter()` or `_.iter_mut()` when `&_` or `&mut _` would do [explicit_iter_loop](https://github.com/Manishearth/rust-clippy/wiki#explicit_iter_loop) | warn | for-looping over `_.iter()` or `_.iter_mut()` when `&_` or `&mut _` would do
[extend_from_slice](https://github.com/Manishearth/rust-clippy/wiki#extend_from_slice) | warn | `.extend_from_slice(_)` is a faster way to extend a Vec by a slice
[filter_map](https://github.com/Manishearth/rust-clippy/wiki#filter_map) | allow | using combinations of `filter`, `map`, `filter_map` and `flat_map` which can usually be written as a single method call [filter_map](https://github.com/Manishearth/rust-clippy/wiki#filter_map) | allow | using combinations of `filter`, `map`, `filter_map` and `flat_map` which can usually be written as a single method call
[filter_next](https://github.com/Manishearth/rust-clippy/wiki#filter_next) | warn | using `filter(p).next()`, which is more succinctly expressed as `.find(p)` [filter_next](https://github.com/Manishearth/rust-clippy/wiki#filter_next) | warn | using `filter(p).next()`, which is more succinctly expressed as `.find(p)`
[float_arithmetic](https://github.com/Manishearth/rust-clippy/wiki#float_arithmetic) | allow | any floating-point arithmetic statement [float_arithmetic](https://github.com/Manishearth/rust-clippy/wiki#float_arithmetic) | allow | any floating-point arithmetic statement

View file

@ -4,6 +4,17 @@ macro_rules! declare_deprecated_lint {
} }
} }
/// **What it does:** Nothing. This lint has been deprecated.
///
/// **Deprecation reason:** This used to check for `Vec::extend`, which was slower than
/// `Vec::extend_from_slice`. Thanks to specialization, this is no longer true.
declare_deprecated_lint! {
pub EXTEND_FROM_SLICE,
"`.extend_from_slice(_)` is a faster way to extend a Vec by a slice"
}
/// **What it does:** Nothing. This lint has been deprecated. /// **What it does:** Nothing. This lint has been deprecated.
/// ///
/// **Deprecation reason:** This used to check for `Vec::as_slice`, which was unstable with good /// **Deprecation reason:** This used to check for `Vec::as_slice`, which was unstable with good

View file

@ -179,6 +179,10 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
}; };
let mut store = reg.sess.lint_store.borrow_mut(); let mut store = reg.sess.lint_store.borrow_mut();
store.register_removed(
"extend_from_slice",
"`.extend_from_slice(_)` is a faster way to extend a Vec by a slice",
);
store.register_removed( store.register_removed(
"unstable_as_slice", "unstable_as_slice",
"`Vec::as_slice` has been stabilized in 1.7", "`Vec::as_slice` has been stabilized in 1.7",
@ -408,7 +412,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
methods::CHARS_NEXT_CMP, methods::CHARS_NEXT_CMP,
methods::CLONE_DOUBLE_REF, methods::CLONE_DOUBLE_REF,
methods::CLONE_ON_COPY, methods::CLONE_ON_COPY,
methods::EXTEND_FROM_SLICE,
methods::FILTER_NEXT, methods::FILTER_NEXT,
methods::GET_UNWRAP, methods::GET_UNWRAP,
methods::ITER_NTH, methods::ITER_NTH,

View file

@ -292,24 +292,6 @@ declare_lint! {
"using any `*or` method with a function call, which suggests `*or_else`" "using any `*or` method with a function call, which suggests `*or_else`"
} }
/// **What it does:** Checks for usage of `.extend(s)` on a `Vec` to extend the
/// vector by a slice.
///
/// **Why is this bad?** Since Rust 1.6, the `extend_from_slice(_)` method is
/// stable and at least for now faster.
///
/// **Known problems:** None.
///
/// **Example:**
/// ```rust
/// my_vec.extend(&xs)
/// ```
declare_lint! {
pub EXTEND_FROM_SLICE,
Warn,
"`.extend_from_slice(_)` is a faster way to extend a Vec by a slice"
}
/// **What it does:** Checks for usage of `.clone()` on a `Copy` type. /// **What it does:** Checks for usage of `.clone()` on a `Copy` type.
/// ///
/// **Why is this bad?** The only reason `Copy` types implement `Clone` is for /// **Why is this bad?** The only reason `Copy` types implement `Clone` is for
@ -522,8 +504,7 @@ declare_lint! {
impl LintPass for Pass { impl LintPass for Pass {
fn get_lints(&self) -> LintArray { fn get_lints(&self) -> LintArray {
lint_array!(EXTEND_FROM_SLICE, lint_array!(OPTION_UNWRAP_USED,
OPTION_UNWRAP_USED,
RESULT_UNWRAP_USED, RESULT_UNWRAP_USED,
SHOULD_IMPLEMENT_TRAIT, SHOULD_IMPLEMENT_TRAIT,
WRONG_SELF_CONVENTION, WRONG_SELF_CONVENTION,
@ -844,21 +825,6 @@ 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: &[hir::Expr]) {
let arg_ty = cx.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| {
db.span_suggestion(expr.span,
"try this",
format!("{}.extend_from_slice({})", snippet(cx, args[0].span, "_"), slice));
});
}
}
fn lint_string_extend(cx: &LateContext, expr: &hir::Expr, args: &[hir::Expr]) { fn lint_string_extend(cx: &LateContext, expr: &hir::Expr, args: &[hir::Expr]) {
let arg = &args[1]; let arg = &args[1];
if let Some(arglists) = method_chain_args(arg, &["chars"]) { if let Some(arglists) = method_chain_args(arg, &["chars"]) {
@ -885,9 +851,7 @@ fn lint_string_extend(cx: &LateContext, expr: &hir::Expr, args: &[hir::Expr]) {
fn lint_extend(cx: &LateContext, expr: &hir::Expr, args: &[hir::Expr]) { fn lint_extend(cx: &LateContext, expr: &hir::Expr, args: &[hir::Expr]) {
let (obj_ty, _) = walk_ptrs_ty_depth(cx.tables.expr_ty(&args[0])); let (obj_ty, _) = walk_ptrs_ty_depth(cx.tables.expr_ty(&args[0]));
if match_type(cx, obj_ty, &paths::VEC) { if match_type(cx, obj_ty, &paths::STRING) {
lint_vec_extend(cx, expr, args);
} else if match_type(cx, obj_ty, &paths::STRING) {
lint_string_extend(cx, expr, args); lint_string_extend(cx, expr, args);
} }
} }

View file

@ -508,31 +508,6 @@ fn starts_with() {
//~| SUGGESTION !"".starts_with(' ') //~| SUGGESTION !"".starts_with(' ')
} }
fn use_extend_from_slice() {
let mut v : Vec<&'static str> = vec![];
v.extend(&["Hello", "World"]);
//~^ ERROR use of `extend`
//~| HELP try this
//~| SUGGESTION v.extend_from_slice(&["Hello", "World"]);
v.extend(&vec!["Some", "more"]);
//~^ ERROR use of `extend`
//~| HELP try this
//~| SUGGESTION v.extend_from_slice(&vec!["Some", "more"]);
v.extend(vec!["And", "even", "more"].iter());
//~^ ERROR use of `extend`
//~| HELP try this
//FIXME: the suggestion if broken because of the macro
let o : Option<&'static str> = None;
v.extend(o);
v.extend(Some("Bye"));
v.extend(vec!["Not", "like", "this"]);
v.extend(["But", "this"].iter());
//~^ERROR use of `extend
//~| HELP try this
//~| SUGGESTION v.extend_from_slice(&["But", "this"]);
}
fn str_extend_chars() { fn str_extend_chars() {
let abc = "abc"; let abc = "abc";
let def = String::from("def"); let def = String::from("def");