Skip to content

Commit

Permalink
Update test
Browse files Browse the repository at this point in the history
  • Loading branch information
obeis committed May 11, 2024
1 parent d97f0a1 commit 72b1c9b
Show file tree
Hide file tree
Showing 38 changed files with 434 additions and 48 deletions.
2 changes: 2 additions & 0 deletions compiler/rustc_driver_impl/src/signal_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ macro raw_errln($tokens:tt) {
}

/// Signal handler installed for SIGSEGV
// FIXME(obeis): Use `SyncUnsafeCell` instead of allowing `static_mut_refs` lint
#[allow(static_mut_refs)]
extern "C" fn print_stack_trace(_: libc::c_int) {
const MAX_FRAMES: usize = 256;
// Reserve data segment so we don't have to malloc in a signal handler, which might fail
Expand Down
2 changes: 2 additions & 0 deletions library/alloc/tests/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,8 @@ fn test_from_iter_specialization_panic_during_iteration_drops() {

#[test]
#[cfg_attr(not(panic = "unwind"), ignore = "test requires unwinding support")]
// FIXME(obeis): Use `SyncUnsafeCell` instead of allowing `static_mut_ref` lint
#[cfg_attr(not(bootstrap), allow(static_mut_refs))]
fn test_from_iter_specialization_panic_during_drop_doesnt_leak() {
static mut DROP_COUNTER_OLD: [usize; 5] = [0; 5];
static mut DROP_COUNTER_NEW: [usize; 2] = [0; 2];
Expand Down
2 changes: 2 additions & 0 deletions library/core/tests/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ fn static_init() {
}

#[test]
// FIXME(obeis): Use `SyncUnsafeCell` instead of allowing `static_mut_ref` lint
#[cfg_attr(not(bootstrap), allow(static_mut_refs))]
fn atomic_access_bool() {
static mut ATOMIC: AtomicBool = AtomicBool::new(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,10 @@ fn issue11371() {
static mut X: Option<i32> = Some(123);
unsafe {
if X.is_some() {
//~^ ERROR: creating a shared reference to mutable static is discouraged
X = None;
X.unwrap();
//~^ ERROR: creating a shared reference to mutable static is discouraged
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
error: creating a shared reference to mutable static is discouraged
--> tests/ui/checked_unwrap/simple_conditionals.rs:175:12
|
LL | if X.is_some() {
| ^^^^^^^^^^^ shared reference to mutable static
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
= note: this will be a hard error in the 2024 edition
= note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior
= note: `-D static-mut-refs` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(static_mut_refs)]`

error: creating a shared reference to mutable static is discouraged
--> tests/ui/checked_unwrap/simple_conditionals.rs:178:13
|
LL | X.unwrap();
| ^^^^^^^^^^ shared reference to mutable static
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
= note: this will be a hard error in the 2024 edition
= note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior

error: called `unwrap` on `x` after checking its variant with `is_some`
--> tests/ui/checked_unwrap/simple_conditionals.rs:47:9
|
Expand Down Expand Up @@ -236,5 +258,5 @@ LL | if result.is_ok() {
LL | result.as_mut().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 25 previous errors
error: aborting due to 27 previous errors

1 change: 1 addition & 0 deletions src/tools/clippy/tests/ui/redundant_static_lifetimes.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ fn main() {

unsafe {
STATIC_MUT_SLICE[0] = 0;
//~^ ERROR: creating a shared reference to mutable static is discouraged
}
}

Expand Down
1 change: 1 addition & 0 deletions src/tools/clippy/tests/ui/redundant_static_lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ fn main() {

unsafe {
STATIC_MUT_SLICE[0] = 0;
//~^ ERROR: creating a shared reference to mutable static is discouraged
}
}

Expand Down
16 changes: 14 additions & 2 deletions src/tools/clippy/tests/ui/redundant_static_lifetimes.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,22 @@ LL | static mut STATIC_MUT_SLICE: &'static mut [u32] = &mut [0];
| -^^^^^^^---------- help: consider removing `'static`: `&mut [u32]`

error: statics have by default a `'static` lifetime
--> tests/ui/redundant_static_lifetimes.rs:69:16
--> tests/ui/redundant_static_lifetimes.rs:70:16
|
LL | static V: &'static u8 = &17;
| -^^^^^^^--- help: consider removing `'static`: `&u8`

error: aborting due to 18 previous errors
error: creating a shared reference to mutable static is discouraged
--> tests/ui/redundant_static_lifetimes.rs:46:9
|
LL | STATIC_MUT_SLICE[0] = 0;
| ^^^^^^^^^^^^^^^^^^^ shared reference to mutable static
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
= note: this will be a hard error in the 2024 edition
= note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior
= note: `-D static-mut-refs` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(static_mut_refs)]`

error: aborting due to 19 previous errors

4 changes: 4 additions & 0 deletions src/tools/clippy/tests/ui/useless_conversion.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,13 @@ fn dont_lint_into_iter_on_static_copy_iter() {
static mut C: CopiableCounter = CopiableCounter { counter: 0 };
unsafe {
assert_eq!(C.into_iter().next(), Some(1));
//~^ ERROR: creating a shared reference to mutable static is discouraged
assert_eq!(C.into_iter().next(), Some(1));
//~^ ERROR: creating a shared reference to mutable static is discouraged
assert_eq!(C.next(), Some(1));
//~^ ERROR: creating a shared reference to mutable static is discouraged
assert_eq!(C.next(), Some(2));
//~^ ERROR: creating a shared reference to mutable static is discouraged
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/tools/clippy/tests/ui/useless_conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,13 @@ fn dont_lint_into_iter_on_static_copy_iter() {
static mut C: CopiableCounter = CopiableCounter { counter: 0 };
unsafe {
assert_eq!(C.into_iter().next(), Some(1));
//~^ ERROR: creating a shared reference to mutable static is discouraged
assert_eq!(C.into_iter().next(), Some(1));
//~^ ERROR: creating a shared reference to mutable static is discouraged
assert_eq!(C.next(), Some(1));
//~^ ERROR: creating a shared reference to mutable static is discouraged
assert_eq!(C.next(), Some(2));
//~^ ERROR: creating a shared reference to mutable static is discouraged
}
}

Expand Down
102 changes: 72 additions & 30 deletions src/tools/clippy/tests/ui/useless_conversion.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,45 @@
error: creating a shared reference to mutable static is discouraged
--> tests/ui/useless_conversion.rs:99:20
|
LL | assert_eq!(C.into_iter().next(), Some(1));
| ^^^^^^^^^^^^^ shared reference to mutable static
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
= note: this will be a hard error in the 2024 edition
= note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior
= note: `-D static-mut-refs` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(static_mut_refs)]`

error: creating a shared reference to mutable static is discouraged
--> tests/ui/useless_conversion.rs:101:20
|
LL | assert_eq!(C.into_iter().next(), Some(1));
| ^^^^^^^^^^^^^ shared reference to mutable static
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
= note: this will be a hard error in the 2024 edition
= note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior

error: creating a shared reference to mutable static is discouraged
--> tests/ui/useless_conversion.rs:103:20
|
LL | assert_eq!(C.next(), Some(1));
| ^^^^^^^^ shared reference to mutable static
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
= note: this will be a hard error in the 2024 edition
= note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior

error: creating a shared reference to mutable static is discouraged
--> tests/ui/useless_conversion.rs:105:20
|
LL | assert_eq!(C.next(), Some(2));
| ^^^^^^^^ shared reference to mutable static
|
= note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
= note: this will be a hard error in the 2024 edition
= note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior

error: useless conversion to the same type: `T`
--> tests/ui/useless_conversion.rs:5:13
|
Expand Down Expand Up @@ -53,178 +95,178 @@ LL | let mut n = NUMBERS.into_iter();
| ^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `NUMBERS`

error: useless conversion to the same type: `std::string::String`
--> tests/ui/useless_conversion.rs:132:21
--> tests/ui/useless_conversion.rs:136:21
|
LL | let _: String = "foo".to_string().into();
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into()`: `"foo".to_string()`

error: useless conversion to the same type: `std::string::String`
--> tests/ui/useless_conversion.rs:133:21
--> tests/ui/useless_conversion.rs:137:21
|
LL | let _: String = From::from("foo".to_string());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `From::from()`: `"foo".to_string()`

error: useless conversion to the same type: `std::string::String`
--> tests/ui/useless_conversion.rs:134:13
--> tests/ui/useless_conversion.rs:138:13
|
LL | let _ = String::from("foo".to_string());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `String::from()`: `"foo".to_string()`

error: useless conversion to the same type: `std::string::String`
--> tests/ui/useless_conversion.rs:135:13
--> tests/ui/useless_conversion.rs:139:13
|
LL | let _ = String::from(format!("A: {:04}", 123));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `String::from()`: `format!("A: {:04}", 123)`

error: useless conversion to the same type: `std::str::Lines<'_>`
--> tests/ui/useless_conversion.rs:136:13
--> tests/ui/useless_conversion.rs:140:13
|
LL | let _ = "".lines().into_iter();
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `"".lines()`

error: useless conversion to the same type: `std::vec::IntoIter<i32>`
--> tests/ui/useless_conversion.rs:137:13
--> tests/ui/useless_conversion.rs:141:13
|
LL | let _ = vec![1, 2, 3].into_iter().into_iter();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `vec![1, 2, 3].into_iter()`

error: useless conversion to the same type: `std::string::String`
--> tests/ui/useless_conversion.rs:138:21
--> tests/ui/useless_conversion.rs:142:21
|
LL | let _: String = format!("Hello {}", "world").into();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into()`: `format!("Hello {}", "world")`

error: useless conversion to the same type: `i32`
--> tests/ui/useless_conversion.rs:143:13
--> tests/ui/useless_conversion.rs:147:13
|
LL | let _ = i32::from(a + b) * 3;
| ^^^^^^^^^^^^^^^^ help: consider removing `i32::from()`: `(a + b)`

error: useless conversion to the same type: `Foo<'a'>`
--> tests/ui/useless_conversion.rs:149:23
--> tests/ui/useless_conversion.rs:153:23
|
LL | let _: Foo<'a'> = s2.into();
| ^^^^^^^^^ help: consider removing `.into()`: `s2`

error: useless conversion to the same type: `Foo<'a'>`
--> tests/ui/useless_conversion.rs:151:13
--> tests/ui/useless_conversion.rs:155:13
|
LL | let _ = Foo::<'a'>::from(s3);
| ^^^^^^^^^^^^^^^^^^^^ help: consider removing `Foo::<'a'>::from()`: `s3`

error: useless conversion to the same type: `std::vec::IntoIter<Foo<'a'>>`
--> tests/ui/useless_conversion.rs:153:13
--> tests/ui/useless_conversion.rs:157:13
|
LL | let _ = vec![s4, s4, s4].into_iter().into_iter();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `vec![s4, s4, s4].into_iter()`

error: explicit call to `.into_iter()` in function argument accepting `IntoIterator`
--> tests/ui/useless_conversion.rs:185:7
--> tests/ui/useless_conversion.rs:189:7
|
LL | b(vec![1, 2].into_iter());
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `vec![1, 2]`
|
note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()`
--> tests/ui/useless_conversion.rs:175:13
--> tests/ui/useless_conversion.rs:179:13
|
LL | fn b<T: IntoIterator<Item = i32>>(_: T) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^

error: explicit call to `.into_iter()` in function argument accepting `IntoIterator`
--> tests/ui/useless_conversion.rs:186:7
--> tests/ui/useless_conversion.rs:190:7
|
LL | c(vec![1, 2].into_iter());
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `vec![1, 2]`
|
note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()`
--> tests/ui/useless_conversion.rs:176:18
--> tests/ui/useless_conversion.rs:180:18
|
LL | fn c(_: impl IntoIterator<Item = i32>) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^

error: explicit call to `.into_iter()` in function argument accepting `IntoIterator`
--> tests/ui/useless_conversion.rs:187:7
--> tests/ui/useless_conversion.rs:191:7
|
LL | d(vec![1, 2].into_iter());
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `vec![1, 2]`
|
note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()`
--> tests/ui/useless_conversion.rs:179:12
--> tests/ui/useless_conversion.rs:183:12
|
LL | T: IntoIterator<Item = i32>,
| ^^^^^^^^^^^^^^^^^^^^^^^^

error: explicit call to `.into_iter()` in function argument accepting `IntoIterator`
--> tests/ui/useless_conversion.rs:190:7
--> tests/ui/useless_conversion.rs:194:7
|
LL | b(vec![1, 2].into_iter().into_iter());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`s: `vec![1, 2]`
|
note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()`
--> tests/ui/useless_conversion.rs:175:13
--> tests/ui/useless_conversion.rs:179:13
|
LL | fn b<T: IntoIterator<Item = i32>>(_: T) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^

error: explicit call to `.into_iter()` in function argument accepting `IntoIterator`
--> tests/ui/useless_conversion.rs:191:7
--> tests/ui/useless_conversion.rs:195:7
|
LL | b(vec![1, 2].into_iter().into_iter().into_iter());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`s: `vec![1, 2]`
|
note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()`
--> tests/ui/useless_conversion.rs:175:13
--> tests/ui/useless_conversion.rs:179:13
|
LL | fn b<T: IntoIterator<Item = i32>>(_: T) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^

error: explicit call to `.into_iter()` in function argument accepting `IntoIterator`
--> tests/ui/useless_conversion.rs:237:24
--> tests/ui/useless_conversion.rs:241:24
|
LL | foo2::<i32, _>([1, 2, 3].into_iter());
| ^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `[1, 2, 3]`
|
note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()`
--> tests/ui/useless_conversion.rs:216:12
--> tests/ui/useless_conversion.rs:220:12
|
LL | I: IntoIterator<Item = i32> + Helper<X>,
| ^^^^^^^^^^^^^^^^^^^^^^^^

error: explicit call to `.into_iter()` in function argument accepting `IntoIterator`
--> tests/ui/useless_conversion.rs:245:14
--> tests/ui/useless_conversion.rs:249:14
|
LL | foo3([1, 2, 3].into_iter());
| ^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `[1, 2, 3]`
|
note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()`
--> tests/ui/useless_conversion.rs:225:12
--> tests/ui/useless_conversion.rs:229:12
|
LL | I: IntoIterator<Item = i32>,
| ^^^^^^^^^^^^^^^^^^^^^^^^

error: explicit call to `.into_iter()` in function argument accepting `IntoIterator`
--> tests/ui/useless_conversion.rs:254:16
--> tests/ui/useless_conversion.rs:258:16
|
LL | S1.foo([1, 2].into_iter());
| ^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `[1, 2]`
|
note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()`
--> tests/ui/useless_conversion.rs:251:27
--> tests/ui/useless_conversion.rs:255:27
|
LL | pub fn foo<I: IntoIterator>(&self, _: I) {}
| ^^^^^^^^^^^^

error: explicit call to `.into_iter()` in function argument accepting `IntoIterator`
--> tests/ui/useless_conversion.rs:273:44
--> tests/ui/useless_conversion.rs:277:44
|
LL | v0.into_iter().interleave_shortest(v1.into_iter());
| ^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `v1`
|
note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()`
--> tests/ui/useless_conversion.rs:260:20
--> tests/ui/useless_conversion.rs:264:20
|
LL | J: IntoIterator,
| ^^^^^^^^^^^^

error: aborting due to 28 previous errors
error: aborting due to 32 previous errors

Loading

0 comments on commit 72b1c9b

Please sign in to comment.