1 //! Checks for usage of nightly features that have simple stable equivalents
3 //! This lint is **warn** by default
6 use rustc_front::hir::*;
11 /// **What it does:** This lint `Warn`s on use of the `as_slice(..)` function, which is unstable.
13 /// **Why is this bad?** Using this function doesn't make your code better, but it will preclude it from building with stable Rust.
15 /// **Known problems:** None.
17 /// **Example:** `x.as_slice(..)`
19 pub UNSTABLE_AS_SLICE,
21 "as_slice is not stable and can be replaced by & v[..]\
22 see https://github.com/rust-lang/rust/issues/27729"
25 /// **What it does:** This lint `Warn`s on use of the `as_mut_slice(..)` function, which is unstable.
27 /// **Why is this bad?** Using this function doesn't make your code better, but it will preclude it from building with stable Rust.
29 /// **Known problems:** None.
31 /// **Example:** `x.as_mut_slice(..)`
33 pub UNSTABLE_AS_MUT_SLICE,
35 "as_mut_slice is not stable and can be replaced by &mut v[..]\
36 see https://github.com/rust-lang/rust/issues/27729"
40 pub struct NeedlessFeaturesPass;
42 impl LintPass for NeedlessFeaturesPass {
43 fn get_lints(&self) -> LintArray {
44 lint_array!(UNSTABLE_AS_SLICE, UNSTABLE_AS_MUT_SLICE)
48 impl LateLintPass for NeedlessFeaturesPass {
49 fn check_expr(&mut self, cx: &LateContext, expr: &Expr) {
50 if let ExprMethodCall(ref name, _, _) = expr.node {
51 if name.node.as_str() == "as_slice" && check_paths(cx, expr) {
52 span_lint(cx, UNSTABLE_AS_SLICE, expr.span,
53 "used as_slice() from the 'convert' nightly feature. Use &[..] \
56 if name.node.as_str() == "as_mut_slice" && check_paths(cx, expr) {
57 span_lint(cx, UNSTABLE_AS_MUT_SLICE, expr.span,
58 "used as_mut_slice() from the 'convert' nightly feature. Use &mut [..] \
65 fn check_paths(cx: &LateContext, expr: &Expr) -> bool {
66 utils::match_impl_method(cx, expr, &["collections", "vec", "Vec<T>"])