Skip to content

Commit 9f27b74

Browse files
committed
add test for missing_const_for_fn. fix test stderr
1 parent 8df11e4 commit 9f27b74

File tree

2 files changed

+41
-22
lines changed

2 files changed

+41
-22
lines changed

tests/ui/min_rust_version_attr.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ pub fn filter_map_next() {
7373
.next();
7474
}
7575

76+
#[allow(clippy::no_effect)]
77+
#[allow(clippy::short_circuit_statement)]
78+
#[allow(clippy::unnecessary_operation)]
7679
pub fn manual_range_contains() {
80+
let x = 5;
7781
x >= 8 && x < 12;
7882
}
7983

@@ -92,7 +96,7 @@ pub fn use_self() {
9296

9397
fn replace_with_default() {
9498
let mut s = String::from("foo");
95-
let _ = std::mem::replace(s, String::default());
99+
let _ = std::mem::replace(&mut s, String::default());
96100
}
97101

98102
fn map_unwrap_or() {
@@ -106,6 +110,11 @@ fn map_unwrap_or() {
106110
.unwrap_or(0);
107111
}
108112

113+
// Could be const
114+
fn missing_const_for_fn() -> i32 {
115+
1
116+
}
117+
109118
fn main() {
110119
filter_map_next();
111120
checked_conversion();
@@ -120,6 +129,7 @@ fn main() {
120129
use_self();
121130
replace_with_default();
122131
map_unwrap_or();
132+
missing_const_for_fn();
123133
}
124134

125135
mod meets_msrv {

tests/ui/min_rust_version_attr.stderr

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,37 @@
1-
error[E0425]: cannot find value `x` in this scope
2-
--> $DIR/min_rust_version_attr.rs:77:5
1+
error: stripping a prefix manually
2+
--> $DIR/min_rust_version_attr.rs:142:24
33
|
4-
LL | x >= 8 && x < 12;
5-
| ^ not found in this scope
6-
7-
error[E0425]: cannot find value `x` in this scope
8-
--> $DIR/min_rust_version_attr.rs:77:15
4+
LL | assert_eq!(s["hello, ".len()..].to_uppercase(), "WORLD!");
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `-D clippy::manual-strip` implied by `-D warnings`
8+
note: the prefix was tested here
9+
--> $DIR/min_rust_version_attr.rs:141:9
10+
|
11+
LL | if s.starts_with("hello, ") {
12+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
13+
help: try using the `strip_prefix` method
14+
|
15+
LL | if let Some(<stripped>) = s.strip_prefix("hello, ") {
16+
LL | assert_eq!(<stripped>.to_uppercase(), "WORLD!");
917
|
10-
LL | x >= 8 && x < 12;
11-
| ^ not found in this scope
1218

13-
error[E0308]: mismatched types
14-
--> $DIR/min_rust_version_attr.rs:95:31
19+
error: stripping a prefix manually
20+
--> $DIR/min_rust_version_attr.rs:154:24
21+
|
22+
LL | assert_eq!(s["hello, ".len()..].to_uppercase(), "WORLD!");
23+
| ^^^^^^^^^^^^^^^^^^^^
24+
|
25+
note: the prefix was tested here
26+
--> $DIR/min_rust_version_attr.rs:153:9
27+
|
28+
LL | if s.starts_with("hello, ") {
29+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
30+
help: try using the `strip_prefix` method
1531
|
16-
LL | let _ = std::mem::replace(s, String::default());
17-
| ^
18-
| |
19-
| expected `&mut _`, found struct `std::string::String`
20-
| help: consider mutably borrowing here: `&mut s`
32+
LL | if let Some(<stripped>) = s.strip_prefix("hello, ") {
33+
LL | assert_eq!(<stripped>.to_uppercase(), "WORLD!");
2134
|
22-
= note: expected mutable reference `&mut _`
23-
found struct `std::string::String`
2435

25-
error: aborting due to 3 previous errors
36+
error: aborting due to 2 previous errors
2637

27-
Some errors have detailed explanations: E0308, E0425.
28-
For more information about an error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)