Skip to content

Commit 9a6a608

Browse files
Use libtest errors check to better enforce UI testing
1 parent 15de3dd commit 9a6a608

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

tests/ui/needless_pass_by_ref_mut.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
use std::ptr::NonNull;
55

6-
// Should only warn for `s`.
76
fn foo(s: &mut Vec<u32>, b: &u32, x: &mut u32) {
7+
//~^ ERROR: this argument is a mutable reference, but not used mutably
88
*x += *b + s.len() as u32;
99
}
1010

@@ -28,8 +28,9 @@ fn foo5(s: &mut Vec<u32>) {
2828
foo2(s);
2929
}
3030

31-
// Should warn.
31+
3232
fn foo6(s: &mut Vec<u32>) {
33+
//~^ ERROR: this argument is a mutable reference, but not used mutably
3334
non_mut_ref(s);
3435
}
3536

@@ -41,13 +42,13 @@ impl Bar {
4142
// Should not warn on `&mut self`.
4243
fn bar(&mut self) {}
4344

44-
// Should warn about `vec`
4545
fn mushroom(&self, vec: &mut Vec<i32>) -> usize {
46+
//~^ ERROR: this argument is a mutable reference, but not used mutably
4647
vec.len()
4748
}
4849

49-
// Should warn about `vec` (and not `self`).
5050
fn badger(&mut self, vec: &mut Vec<i32>) -> usize {
51+
//~^ ERROR: this argument is a mutable reference, but not used mutably
5152
vec.len()
5253
}
5354
}
@@ -123,36 +124,36 @@ async fn f7(x: &mut i32, y: i32, z: &mut i32, a: i32) {
123124
*z += 1;
124125
}
125126

126-
// Should warn.
127127
async fn a1(x: &mut i32) {
128+
//~^ ERROR: this argument is a mutable reference, but not used mutably
128129
println!("{:?}", x);
129130
}
130-
// Should warn.
131131
async fn a2(x: &mut i32, y: String) {
132+
//~^ ERROR: this argument is a mutable reference, but not used mutably
132133
println!("{:?}", x);
133134
}
134-
// Should warn.
135135
async fn a3(x: &mut i32, y: String, z: String) {
136+
//~^ ERROR: this argument is a mutable reference, but not used mutably
136137
println!("{:?}", x);
137138
}
138-
// Should warn.
139139
async fn a4(x: &mut i32, y: i32) {
140+
//~^ ERROR: this argument is a mutable reference, but not used mutably
140141
println!("{:?}", x);
141142
}
142-
// Should warn.
143143
async fn a5(x: i32, y: &mut i32) {
144+
//~^ ERROR: this argument is a mutable reference, but not used mutably
144145
println!("{:?}", x);
145146
}
146-
// Should warn.
147147
async fn a6(x: i32, y: &mut i32) {
148+
//~^ ERROR: this argument is a mutable reference, but not used mutably
148149
println!("{:?}", x);
149150
}
150-
// Should warn.
151151
async fn a7(x: i32, y: i32, z: &mut i32) {
152+
//~^ ERROR: this argument is a mutable reference, but not used mutably
152153
println!("{:?}", z);
153154
}
154-
// Should warn.
155155
async fn a8(x: i32, a: &mut i32, y: i32, z: &mut i32) {
156+
//~^ ERROR: this argument is a mutable reference, but not used mutably
156157
println!("{:?}", z);
157158
}
158159

@@ -185,13 +186,15 @@ fn used_as_path(s: &mut u32) {}
185186
fn lint_attr(s: &mut u32) {}
186187

187188
#[cfg(not(feature = "a"))]
188-
// Should warn with note.
189189
fn cfg_warn(s: &mut u32) {}
190+
//~^ ERROR: this argument is a mutable reference, but not used mutably
191+
//~| NOTE: this is cfg-gated and may require further changes
190192

191193
#[cfg(not(feature = "a"))]
192194
mod foo {
193-
// Should warn with note.
194195
fn cfg_warn(s: &mut u32) {}
196+
//~^ ERROR: this argument is a mutable reference, but not used mutably
197+
//~| NOTE: this is cfg-gated and may require further changes
195198
}
196199

197200
fn main() {

tests/ui/needless_pass_by_ref_mut.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: this argument is a mutable reference, but not used mutably
2-
--> $DIR/needless_pass_by_ref_mut.rs:7:11
2+
--> $DIR/needless_pass_by_ref_mut.rs:6:11
33
|
44
LL | fn foo(s: &mut Vec<u32>, b: &u32, x: &mut u32) {
55
| ^^^^^^^^^^^^^ help: consider changing to: `&Vec<u32>`
@@ -87,7 +87,7 @@ LL | fn cfg_warn(s: &mut u32) {}
8787
= note: this is cfg-gated and may require further changes
8888

8989
error: this argument is a mutable reference, but not used mutably
90-
--> $DIR/needless_pass_by_ref_mut.rs:194:20
90+
--> $DIR/needless_pass_by_ref_mut.rs:195:20
9191
|
9292
LL | fn cfg_warn(s: &mut u32) {}
9393
| ^^^^^^^^ help: consider changing to: `&u32`

0 commit comments

Comments
 (0)