Skip to content

Commit 1aab767

Browse files
authored
Rollup merge of #134024 - jieyouxu:ui-cleanup-2, r=Nadrieril
Advent of `tests/ui` (misc cleanups and improvements) [2/N] Part of #133895. Misc improvements to some ui tests immediately under `tests/ui/`. Best reviewed commit-by-commit. Please see individual commit messages for some further rationale and change summaries. r? compiler
2 parents d619c40 + 754dec3 commit 1aab767

14 files changed

+176
-63
lines changed

tests/ui/assign-imm-local-twice.rs

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/ui/assoc-lang-items.rs

Lines changed: 0 additions & 21 deletions
This file was deleted.

tests/ui/assoc-oddities-3.rs

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/ui/atomic-from-mut-not-available.rs

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//! Check that we do not allow assigning twice to an immutable variable. This test also checks a
2+
//! few pieces of borrowck diagnostics:
3+
//!
4+
//! - A multipart borrowck diagnostics that points out the first assignment to an immutable
5+
//! variable, alongside violating assignments that follow subsequently.
6+
//! - A suggestion diagnostics to make the immutable binding mutable.
7+
8+
//@ run-rustfix
9+
10+
fn main() {
11+
let mut v: isize;
12+
//~^ HELP consider making this binding mutable
13+
//~| SUGGESTION mut
14+
v = 1;
15+
//~^ NOTE first assignment
16+
println!("v={}", v);
17+
v = 2;
18+
//~^ ERROR cannot assign twice to immutable variable
19+
//~| NOTE cannot assign twice to immutable
20+
println!("v={}", v);
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//! Check that we do not allow assigning twice to an immutable variable. This test also checks a
2+
//! few pieces of borrowck diagnostics:
3+
//!
4+
//! - A multipart borrowck diagnostics that points out the first assignment to an immutable
5+
//! variable, alongside violating assignments that follow subsequently.
6+
//! - A suggestion diagnostics to make the immutable binding mutable.
7+
8+
//@ run-rustfix
9+
10+
fn main() {
11+
let v: isize;
12+
//~^ HELP consider making this binding mutable
13+
//~| SUGGESTION mut
14+
v = 1;
15+
//~^ NOTE first assignment
16+
println!("v={}", v);
17+
v = 2;
18+
//~^ ERROR cannot assign twice to immutable variable
19+
//~| NOTE cannot assign twice to immutable
20+
println!("v={}", v);
21+
}

tests/ui/assign-imm-local-twice.stderr renamed to tests/ui/borrowck/assign-imm-local-twice.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
error[E0384]: cannot assign twice to immutable variable `v`
2-
--> $DIR/assign-imm-local-twice.rs:7:5
2+
--> $DIR/assign-imm-local-twice.rs:17:5
33
|
44
LL | v = 1;
55
| ----- first assignment to `v`
6-
LL | println!("v={}", v);
6+
...
77
LL | v = 2;
88
| ^^^^^ cannot assign twice to immutable variable
99
|

tests/ui/assign-assign.rs renamed to tests/ui/codegen/assign-expr-unit-type.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
//! Regression test for [Using the result of an assignment expression results in an LLVM assert
2+
//! #483][issue-483]. This test checks that assignment expressions produce a unit type, and is
3+
//! properly lowered to LLVM IR such that it does not trigger an LLVM assertion. This test was added
4+
//! *really* early, back in 2011.
5+
//!
6+
//! [issue-483]: https://github.com/rust-lang/rust/issues/483
7+
18
//@ run-pass
2-
// Issue 483 - Assignment expressions result in nil
39

410
fn test_assign() {
511
let mut x: isize;
@@ -27,4 +33,7 @@ fn test_assign_op() {
2733
assert_eq!(z, ());
2834
}
2935

30-
pub fn main() { test_assign(); test_assign_op(); }
36+
pub fn main() {
37+
test_assign();
38+
test_assign_op();
39+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//! Check that associated items can be marked as lang items, so that they don't have to be looked up
2+
//! by name or by definition order indirectly.
3+
//!
4+
//! This test is not *quite* high-fidelity: it checks that you can use lang items on associated
5+
//! items by looking at the error message *as a proxy*. That is, the error message is about
6+
//! undefined lang items and not invalid attribute target, indicating that it has reached lang item
7+
//! machinery (which is relying on knowing the implementation detail). However, it's annoying to
8+
//! write a full-fidelity test for this, so I think this is acceptable even though it's not *great*.
9+
//!
10+
//! This was implemented in <https://github.com/rust-lang/rust/pull/72559> to help with
11+
//! <https://github.com/rust-lang/rust/issues/70718>, which is itself relevant for e.g. `Fn::Output`
12+
//! or `Future::Output` or specific use cases like [Use `T`'s discriminant type in
13+
//! `mem::Discriminant<T>` instead of `u64`](https://github.com/rust-lang/rust/pull/70705).
14+
15+
#![feature(lang_items)]
16+
17+
trait Foo {
18+
#[lang = "dummy_lang_item_1"] //~ ERROR definition
19+
fn foo() {}
20+
21+
#[lang = "dummy_lang_item_2"] //~ ERROR definition
22+
fn bar();
23+
24+
#[lang = "dummy_lang_item_3"] //~ ERROR definition
25+
type MyType;
26+
}
27+
28+
struct Bar;
29+
30+
impl Bar {
31+
#[lang = "dummy_lang_item_4"] //~ ERROR definition
32+
fn test() {}
33+
}
34+
35+
fn main() {}

tests/ui/assoc-lang-items.stderr renamed to tests/ui/lang-items/assoc-lang-items.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
error[E0522]: definition of an unknown lang item: `dummy_lang_item_1`
2-
--> $DIR/assoc-lang-items.rs:4:5
2+
--> $DIR/assoc-lang-items.rs:18:5
33
|
44
LL | #[lang = "dummy_lang_item_1"]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition of unknown lang item `dummy_lang_item_1`
66

77
error[E0522]: definition of an unknown lang item: `dummy_lang_item_2`
8-
--> $DIR/assoc-lang-items.rs:7:5
8+
--> $DIR/assoc-lang-items.rs:21:5
99
|
1010
LL | #[lang = "dummy_lang_item_2"]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition of unknown lang item `dummy_lang_item_2`
1212

1313
error[E0522]: definition of an unknown lang item: `dummy_lang_item_3`
14-
--> $DIR/assoc-lang-items.rs:10:5
14+
--> $DIR/assoc-lang-items.rs:24:5
1515
|
1616
LL | #[lang = "dummy_lang_item_3"]
1717
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition of unknown lang item `dummy_lang_item_3`
1818

1919
error[E0522]: definition of an unknown lang item: `dummy_lang_item_4`
20-
--> $DIR/assoc-lang-items.rs:17:5
20+
--> $DIR/assoc-lang-items.rs:31:5
2121
|
2222
LL | #[lang = "dummy_lang_item_4"]
2323
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ definition of unknown lang item `dummy_lang_item_4`

0 commit comments

Comments
 (0)