Skip to content

Commit 1090509

Browse files
committed
non_copy_const: remove incorrect suggestion
1 parent a9a3350 commit 1090509

File tree

2 files changed

+23
-53
lines changed

2 files changed

+23
-53
lines changed

clippy_lints/src/non_copy_const.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use rustc::lint::{LateContext, LateLintPass, Lint, LintArray, LintPass};
1010
use rustc::ty::adjustment::Adjust;
1111
use rustc::ty::{Ty, TypeFlags};
1212
use rustc::{declare_lint_pass, declare_tool_lint};
13-
use rustc_errors::Applicability;
1413
use rustc_typeck::hir_ty_to_ty;
1514
use syntax_pos::{InnerSpan, Span, DUMMY_SP};
1615

@@ -125,16 +124,11 @@ fn verify_ty_bound<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: Ty<'tcx>, source: S
125124
match source {
126125
Source::Item { .. } => {
127126
let const_kw_span = span.from_inner(InnerSpan::new(0, 5));
128-
db.span_suggestion(
129-
const_kw_span,
130-
"make this a static item",
131-
"static".to_string(),
132-
Applicability::MachineApplicable,
133-
);
127+
db.span_label(const_kw_span, "make this a static item (maybe with lazy_static)");
134128
},
135129
Source::Assoc { ty: ty_span, .. } => {
136130
if ty.flags.contains(TypeFlags::HAS_FREE_LOCAL_NAMES) {
137-
db.span_help(ty_span, &format!("consider requiring `{}` to be `Copy`", ty));
131+
db.span_label(ty_span, &format!("consider requiring `{}` to be `Copy`", ty));
138132
}
139133
},
140134
Source::Expr { .. } => {

tests/ui/non_copy_const.stderr

Lines changed: 21 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: a const item should never be interior mutable
44
LL | const ATOMIC: AtomicUsize = AtomicUsize::new(5); //~ ERROR interior mutable
55
| -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
| |
7-
| help: make this a static item: `static`
7+
| make this a static item (maybe with lazy_static)
88
|
99
= note: `#[deny(clippy::declare_interior_mutable_const)]` on by default
1010

@@ -14,15 +14,15 @@ error: a const item should never be interior mutable
1414
LL | const CELL: Cell<usize> = Cell::new(6); //~ ERROR interior mutable
1515
| -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1616
| |
17-
| help: make this a static item: `static`
17+
| make this a static item (maybe with lazy_static)
1818

1919
error: a const item should never be interior mutable
2020
--> $DIR/non_copy_const.rs:11:1
2121
|
2222
LL | const ATOMIC_TUPLE: ([AtomicUsize; 1], Vec<AtomicUsize>, u8) = ([ATOMIC], Vec::new(), 7);
2323
| -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2424
| |
25-
| help: make this a static item: `static`
25+
| make this a static item (maybe with lazy_static)
2626

2727
error: a const item should never be interior mutable
2828
--> $DIR/non_copy_const.rs:16:9
@@ -43,37 +43,25 @@ error: a const item should never be interior mutable
4343
--> $DIR/non_copy_const.rs:44:5
4444
|
4545
LL | const INPUT: T;
46-
| ^^^^^^^^^^^^^^^
47-
|
48-
help: consider requiring `T` to be `Copy`
49-
--> $DIR/non_copy_const.rs:44:18
50-
|
51-
LL | const INPUT: T;
52-
| ^
46+
| ^^^^^^^^^^^^^-^
47+
| |
48+
| consider requiring `T` to be `Copy`
5349

5450
error: a const item should never be interior mutable
5551
--> $DIR/non_copy_const.rs:47:5
5652
|
5753
LL | const ASSOC: Self::NonCopyType;
58-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
59-
|
60-
help: consider requiring `<Self as Trait<T>>::NonCopyType` to be `Copy`
61-
--> $DIR/non_copy_const.rs:47:18
62-
|
63-
LL | const ASSOC: Self::NonCopyType;
64-
| ^^^^^^^^^^^^^^^^^
54+
| ^^^^^^^^^^^^^-----------------^
55+
| |
56+
| consider requiring `<Self as Trait<T>>::NonCopyType` to be `Copy`
6557

6658
error: a const item should never be interior mutable
6759
--> $DIR/non_copy_const.rs:51:5
6860
|
6961
LL | const AN_INPUT: T = Self::INPUT;
70-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
71-
|
72-
help: consider requiring `T` to be `Copy`
73-
--> $DIR/non_copy_const.rs:51:21
74-
|
75-
LL | const AN_INPUT: T = Self::INPUT;
76-
| ^
62+
| ^^^^^^^^^^^^^^^^-^^^^^^^^^^^^^^^
63+
| |
64+
| consider requiring `T` to be `Copy`
7765

7866
error: a const item should never be interior mutable
7967
--> $DIR/non_copy_const.rs:16:9
@@ -88,13 +76,9 @@ error: a const item should never be interior mutable
8876
--> $DIR/non_copy_const.rs:60:5
8977
|
9078
LL | const SELF_2: Self;
91-
| ^^^^^^^^^^^^^^^^^^^
92-
|
93-
help: consider requiring `Self` to be `Copy`
94-
--> $DIR/non_copy_const.rs:60:19
95-
|
96-
LL | const SELF_2: Self;
97-
| ^^^^
79+
| ^^^^^^^^^^^^^^----^
80+
| |
81+
| consider requiring `Self` to be `Copy`
9882

9983
error: a const item should never be interior mutable
10084
--> $DIR/non_copy_const.rs:81:5
@@ -106,25 +90,17 @@ error: a const item should never be interior mutable
10690
--> $DIR/non_copy_const.rs:84:5
10791
|
10892
LL | const U_SELF: U = U::SELF_2;
109-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
110-
|
111-
help: consider requiring `U` to be `Copy`
112-
--> $DIR/non_copy_const.rs:84:19
113-
|
114-
LL | const U_SELF: U = U::SELF_2;
115-
| ^
93+
| ^^^^^^^^^^^^^^-^^^^^^^^^^^^^
94+
| |
95+
| consider requiring `U` to be `Copy`
11696

11797
error: a const item should never be interior mutable
11898
--> $DIR/non_copy_const.rs:87:5
11999
|
120100
LL | const T_ASSOC: T::NonCopyType = T::ASSOC;
121-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
122-
|
123-
help: consider requiring `<T as Trait<u32>>::NonCopyType` to be `Copy`
124-
--> $DIR/non_copy_const.rs:87:20
125-
|
126-
LL | const T_ASSOC: T::NonCopyType = T::ASSOC;
127-
| ^^^^^^^^^^^^^^
101+
| ^^^^^^^^^^^^^^^--------------^^^^^^^^^^^^
102+
| |
103+
| consider requiring `<T as Trait<u32>>::NonCopyType` to be `Copy`
128104

129105
error: a const item with interior mutability should not be borrowed
130106
--> $DIR/non_copy_const.rs:94:5

0 commit comments

Comments
 (0)