non_copy_const: remove incorrect suggestion

This commit is contained in:
Manish Goregaokar 2019-09-25 05:39:56 -07:00
parent a9a3350455
commit 1090509564
2 changed files with 23 additions and 53 deletions

View File

@ -10,7 +10,6 @@ use rustc::lint::{LateContext, LateLintPass, Lint, LintArray, LintPass};
use rustc::ty::adjustment::Adjust;
use rustc::ty::{Ty, TypeFlags};
use rustc::{declare_lint_pass, declare_tool_lint};
use rustc_errors::Applicability;
use rustc_typeck::hir_ty_to_ty;
use syntax_pos::{InnerSpan, Span, DUMMY_SP};
@ -125,16 +124,11 @@ fn verify_ty_bound<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>, source: S
match source {
Source::Item { .. } => {
let const_kw_span = span.from_inner(InnerSpan::new(0, 5));
db.span_suggestion(
const_kw_span,
"make this a static item",
"static".to_string(),
Applicability::MachineApplicable,
);
db.span_label(const_kw_span, "make this a static item (maybe with lazy_static)");
},
Source::Assoc { ty: ty_span, .. } => {
if ty.flags.contains(TypeFlags::HAS_FREE_LOCAL_NAMES) {
db.span_help(ty_span, &format!("consider requiring `{}` to be `Copy`", ty));
db.span_label(ty_span, &format!("consider requiring `{}` to be `Copy`", ty));
}
},
Source::Expr { .. } => {

View File

@ -4,7 +4,7 @@ error: a const item should never be interior mutable
LL | const ATOMIC: AtomicUsize = AtomicUsize::new(5); //~ ERROR interior mutable
| -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| help: make this a static item: `static`
| make this a static item (maybe with lazy_static)
|
= note: `#[deny(clippy::declare_interior_mutable_const)]` on by default
@ -14,7 +14,7 @@ error: a const item should never be interior mutable
LL | const CELL: Cell<usize> = Cell::new(6); //~ ERROR interior mutable
| -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| help: make this a static item: `static`
| make this a static item (maybe with lazy_static)
error: a const item should never be interior mutable
--> $DIR/non_copy_const.rs:11:1
@ -22,7 +22,7 @@ error: a const item should never be interior mutable
LL | const ATOMIC_TUPLE: ([AtomicUsize; 1], Vec<AtomicUsize>, u8) = ([ATOMIC], Vec::new(), 7);
| -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| help: make this a static item: `static`
| make this a static item (maybe with lazy_static)
error: a const item should never be interior mutable
--> $DIR/non_copy_const.rs:16:9
@ -43,37 +43,25 @@ error: a const item should never be interior mutable
--> $DIR/non_copy_const.rs:44:5
|
LL | const INPUT: T;
| ^^^^^^^^^^^^^^^
|
help: consider requiring `T` to be `Copy`
--> $DIR/non_copy_const.rs:44:18
|
LL | const INPUT: T;
| ^
| ^^^^^^^^^^^^^-^
| |
| consider requiring `T` to be `Copy`
error: a const item should never be interior mutable
--> $DIR/non_copy_const.rs:47:5
|
LL | const ASSOC: Self::NonCopyType;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: consider requiring `<Self as Trait<T>>::NonCopyType` to be `Copy`
--> $DIR/non_copy_const.rs:47:18
|
LL | const ASSOC: Self::NonCopyType;
| ^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^-----------------^
| |
| consider requiring `<Self as Trait<T>>::NonCopyType` to be `Copy`
error: a const item should never be interior mutable
--> $DIR/non_copy_const.rs:51:5
|
LL | const AN_INPUT: T = Self::INPUT;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: consider requiring `T` to be `Copy`
--> $DIR/non_copy_const.rs:51:21
|
LL | const AN_INPUT: T = Self::INPUT;
| ^
| ^^^^^^^^^^^^^^^^-^^^^^^^^^^^^^^^
| |
| consider requiring `T` to be `Copy`
error: a const item should never be interior mutable
--> $DIR/non_copy_const.rs:16:9
@ -88,13 +76,9 @@ error: a const item should never be interior mutable
--> $DIR/non_copy_const.rs:60:5
|
LL | const SELF_2: Self;
| ^^^^^^^^^^^^^^^^^^^
|
help: consider requiring `Self` to be `Copy`
--> $DIR/non_copy_const.rs:60:19
|
LL | const SELF_2: Self;
| ^^^^
| ^^^^^^^^^^^^^^----^
| |
| consider requiring `Self` to be `Copy`
error: a const item should never be interior mutable
--> $DIR/non_copy_const.rs:81:5
@ -106,25 +90,17 @@ error: a const item should never be interior mutable
--> $DIR/non_copy_const.rs:84:5
|
LL | const U_SELF: U = U::SELF_2;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: consider requiring `U` to be `Copy`
--> $DIR/non_copy_const.rs:84:19
|
LL | const U_SELF: U = U::SELF_2;
| ^
| ^^^^^^^^^^^^^^-^^^^^^^^^^^^^
| |
| consider requiring `U` to be `Copy`
error: a const item should never be interior mutable
--> $DIR/non_copy_const.rs:87:5
|
LL | const T_ASSOC: T::NonCopyType = T::ASSOC;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: consider requiring `<T as Trait<u32>>::NonCopyType` to be `Copy`
--> $DIR/non_copy_const.rs:87:20
|
LL | const T_ASSOC: T::NonCopyType = T::ASSOC;
| ^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^--------------^^^^^^^^^^^^
| |
| consider requiring `<T as Trait<u32>>::NonCopyType` to be `Copy`
error: a const item with interior mutability should not be borrowed
--> $DIR/non_copy_const.rs:94:5