Skip to content

Commit 8000472

Browse files
committed
non_copy_const: remove incorrect suggestion
1 parent f32c8df commit 8000472

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

clippy_lints/src/non_copy_const.rs

Lines changed: 1 addition & 7 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,12 +124,7 @@ 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_help(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) {

tests/ui/non_copy_const.stderr

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,38 @@ error: a const item should never be interior mutable
22
--> $DIR/non_copy_const.rs:9:1
33
|
44
LL | const ATOMIC: AtomicUsize = AtomicUsize::new(5); //~ ERROR interior mutable
5-
| -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6-
| |
7-
| help: make this a static item: `static`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
86
|
97
= note: `#[deny(clippy::declare_interior_mutable_const)]` on by default
8+
help: make this a static item (maybe with lazy_static)
9+
--> $DIR/non_copy_const.rs:9:1
10+
|
11+
LL | const ATOMIC: AtomicUsize = AtomicUsize::new(5); //~ ERROR interior mutable
12+
| ^^^^^
1013

1114
error: a const item should never be interior mutable
1215
--> $DIR/non_copy_const.rs:10:1
1316
|
1417
LL | const CELL: Cell<usize> = Cell::new(6); //~ ERROR interior mutable
15-
| -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16-
| |
17-
| help: make this a static item: `static`
18+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19+
|
20+
help: make this a static item (maybe with lazy_static)
21+
--> $DIR/non_copy_const.rs:10:1
22+
|
23+
LL | const CELL: Cell<usize> = Cell::new(6); //~ ERROR interior mutable
24+
| ^^^^^
1825

1926
error: a const item should never be interior mutable
2027
--> $DIR/non_copy_const.rs:11:1
2128
|
2229
LL | const ATOMIC_TUPLE: ([AtomicUsize; 1], Vec<AtomicUsize>, u8) = ([ATOMIC], Vec::new(), 7);
23-
| -----^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24-
| |
25-
| help: make this a static item: `static`
30+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
31+
|
32+
help: make this a static item (maybe with lazy_static)
33+
--> $DIR/non_copy_const.rs:11:1
34+
|
35+
LL | const ATOMIC_TUPLE: ([AtomicUsize; 1], Vec<AtomicUsize>, u8) = ([ATOMIC], Vec::new(), 7);
36+
| ^^^^^
2637

2738
error: a const item should never be interior mutable
2839
--> $DIR/non_copy_const.rs:16:9

0 commit comments

Comments
 (0)