Skip to content

Commit 2ae0a72

Browse files
authored
Unrolled build for #143212
Rollup merge of #143212 - Kivooeo:tf20, r=tgross35 `tests/ui`: A New Order [20/N] > [!NOTE] > > Intermediate commits are intended to help review, but will be squashed prior to merge. Some `tests/ui/` housekeeping, to trim down number of tests directly under `tests/ui/`. Part of #133895. r? `@tgross35`
2 parents 4e97337 + da5c639 commit 2ae0a72

25 files changed

+253
-223
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//! Test that casting non-primitive types with `as` is rejected with a helpful suggestion.
2+
//!
3+
//! You can't use `as` to cast between non-primitive types, even if they have
4+
//! `From`/`Into` implementations. The compiler should suggest using `From::from()`
5+
//! or `.into()` instead, and rustfix should be able to apply the suggestion.
6+
7+
//@ run-rustfix
8+
9+
#[derive(Debug)]
10+
struct Foo {
11+
x: isize,
12+
}
13+
14+
impl From<Foo> for isize {
15+
fn from(val: Foo) -> isize {
16+
val.x
17+
}
18+
}
19+
20+
fn main() {
21+
let _ = isize::from(Foo { x: 1 });
22+
//~^ ERROR non-primitive cast: `Foo` as `isize` [E0605]
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//! Test that casting non-primitive types with `as` is rejected with a helpful suggestion.
2+
//!
3+
//! You can't use `as` to cast between non-primitive types, even if they have
4+
//! `From`/`Into` implementations. The compiler should suggest using `From::from()`
5+
//! or `.into()` instead, and rustfix should be able to apply the suggestion.
6+
7+
//@ run-rustfix
8+
9+
#[derive(Debug)]
10+
struct Foo {
11+
x: isize,
12+
}
13+
14+
impl From<Foo> for isize {
15+
fn from(val: Foo) -> isize {
16+
val.x
17+
}
18+
}
19+
20+
fn main() {
21+
let _ = Foo { x: 1 } as isize;
22+
//~^ ERROR non-primitive cast: `Foo` as `isize` [E0605]
23+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0605]: non-primitive cast: `Foo` as `isize`
2+
--> $DIR/non-primitive-cast-suggestion.rs:21:13
3+
|
4+
LL | let _ = Foo { x: 1 } as isize;
5+
| ^^^^^^^^^^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
6+
|
7+
help: consider using the `From` trait instead
8+
|
9+
LL - let _ = Foo { x: 1 } as isize;
10+
LL + let _ = isize::from(Foo { x: 1 });
11+
|
12+
13+
error: aborting due to 1 previous error
14+
15+
For more information about this error, try `rustc --explain E0605`.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//! Test that closures only implement `Clone` if all captured values implement `Clone`.
2+
//!
3+
//! When a closure captures variables from its environment, it can only be cloned
4+
//! if all those captured variables are cloneable. This test makes sure the compiler
5+
//! properly rejects attempts to clone closures that capture non-Clone types.
6+
7+
//@ compile-flags: --diagnostic-width=300
8+
9+
struct NonClone(i32);
10+
11+
fn main() {
12+
let captured_value = NonClone(5);
13+
let closure = move || {
14+
let _ = captured_value.0;
15+
};
16+
17+
closure.clone();
18+
//~^ ERROR the trait bound `NonClone: Clone` is not satisfied
19+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error[E0277]: the trait bound `NonClone: Clone` is not satisfied in `{closure@$DIR/closure-clone-requires-captured-clone.rs:13:19: 13:26}`
2+
--> $DIR/closure-clone-requires-captured-clone.rs:17:13
3+
|
4+
LL | let closure = move || {
5+
| ------- within this `{closure@$DIR/closure-clone-requires-captured-clone.rs:13:19: 13:26}`
6+
...
7+
LL | closure.clone();
8+
| ^^^^^ within `{closure@$DIR/closure-clone-requires-captured-clone.rs:13:19: 13:26}`, the trait `Clone` is not implemented for `NonClone`
9+
|
10+
note: required because it's used within this closure
11+
--> $DIR/closure-clone-requires-captured-clone.rs:13:19
12+
|
13+
LL | let closure = move || {
14+
| ^^^^^^^
15+
help: consider annotating `NonClone` with `#[derive(Clone)]`
16+
|
17+
LL + #[derive(Clone)]
18+
LL | struct NonClone(i32);
19+
|
20+
21+
error: aborting due to 1 previous error
22+
23+
For more information about this error, try `rustc --explain E0277`.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//! Arrays created with `[value; length]` syntax need the length to be known at
2+
//! compile time. This test makes sure the compiler rejects runtime values like
3+
//! function parameters in the length position.
4+
5+
fn main() {
6+
fn create_array(n: usize) {
7+
let _x = [0; n];
8+
//~^ ERROR attempt to use a non-constant value in a constant [E0435]
9+
}
10+
}

tests/ui/non-constant-expr-for-arr-len.stderr renamed to tests/ui/consts/array-repeat-expr-not-const.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0435]: attempt to use a non-constant value in a constant
2-
--> $DIR/non-constant-expr-for-arr-len.rs:5:22
2+
--> $DIR/array-repeat-expr-not-const.rs:7:22
33
|
4-
LL | fn bar(n: usize) {
5-
| - this would need to be a `const`
4+
LL | fn create_array(n: usize) {
5+
| - this would need to be a `const`
66
LL | let _x = [0; n];
77
| ^
88

tests/ui/noexporttypeexe.rs renamed to tests/ui/cross-crate/unexported-type-error-message.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
//@ aux-build:noexporttypelib.rs
1+
//@ aux-build:unexported-type-error-message.rs
22

3-
extern crate noexporttypelib;
3+
extern crate unexported_type_error_message;
44

55
fn main() {
66
// Here, the type returned by foo() is not exported.
77
// This used to cause internal errors when serializing
88
// because the def_id associated with the type was
99
// not convertible to a path.
10-
let x: isize = noexporttypelib::foo();
10+
let x: isize = unexported_type_error_message::foo();
1111
//~^ ERROR mismatched types
1212
//~| NOTE expected type `isize`
1313
//~| NOTE found enum `Option<isize>`
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/unexported-type-error-message.rs:10:20
3+
|
4+
LL | let x: isize = unexported_type_error_message::foo();
5+
| ----- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `isize`, found `Option<isize>`
6+
| |
7+
| expected due to this
8+
|
9+
= note: expected type `isize`
10+
found enum `Option<isize>`
11+
help: consider using `Option::expect` to unwrap the `Option<isize>` value, panicking if the value is an `Option::None`
12+
|
13+
LL | let x: isize = unexported_type_error_message::foo().expect("REASON");
14+
| +++++++++++++++++
15+
16+
error: aborting due to 1 previous error
17+
18+
For more information about this error, try `rustc --explain E0308`.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//! Circa 2016-06-05, `fn inline` below issued an
2+
//! erroneous warning from the elaborate_drops pass about moving out of
3+
//! a field in `Foo`, which has a destructor (and thus cannot have
4+
//! content moved out of it). The reason that the warning is erroneous
5+
//! in this case is that we are doing a *replace*, not a move, of the
6+
//! content in question, and it is okay to replace fields within `Foo`.
7+
//!
8+
//! Another more subtle problem was that the elaborate_drops was
9+
//! creating a separate drop flag for that internally replaced content,
10+
//! even though the compiler should enforce an invariant that any drop
11+
//! flag for such subcontent of `Foo` will always have the same value
12+
//! as the drop flag for `Foo` itself.
13+
//!
14+
//! Regression test for <https://github.com/rust-lang/rust/issues/34101>.
15+
16+
//@ check-pass
17+
18+
struct Foo(String);
19+
20+
impl Drop for Foo {
21+
fn drop(&mut self) {}
22+
}
23+
24+
fn test_inline_replacement() {
25+
// dummy variable so `f` gets assigned `var1` in MIR for both functions
26+
let _s = ();
27+
let mut f = Foo(String::from("foo"));
28+
f.0 = String::from("bar"); // This should not warn
29+
}
30+
31+
fn test_outline_replacement() {
32+
let _s = String::from("foo");
33+
let mut f = Foo(_s);
34+
f.0 = String::from("bar"); // This should not warn either
35+
}
36+
37+
fn main() {
38+
test_inline_replacement();
39+
test_outline_replacement();
40+
}

tests/ui/no-core-1.rs

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

tests/ui/no-core-2.rs

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

tests/ui/no-warn-on-field-replace-issue-34101.rs

Lines changed: 0 additions & 46 deletions
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//! Test that `#![no_core]` doesn't break modern Rust syntax in edition 2018.
2+
//!
3+
//! When you use `#![no_core]`, you lose the automatic prelude, but you can still
4+
//! get everything back by manually importing `use core::{prelude::v1::*, *}`.
5+
//! This test makes sure that after doing that, things like `for` loops and the
6+
//! `?` operator still work as expected.
7+
8+
//@ run-pass
9+
//@ edition:2018
10+
11+
#![allow(dead_code, unused_imports)]
12+
#![feature(no_core)]
13+
#![no_core]
14+
15+
extern crate core;
16+
extern crate std;
17+
use core::prelude::v1::*;
18+
use core::*;
19+
20+
fn test_for_loop() {
21+
for _ in &[()] {}
22+
}
23+
24+
fn test_question_mark_operator() -> Option<()> {
25+
None?
26+
}
27+
28+
fn main() {}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//! Test that you can use `#![no_core]` and still import std and core manually.
2+
//!
3+
//! The `#![no_core]` attribute disables the automatic core prelude, but you should
4+
//! still be able to explicitly import both `std` and `core` crates and use types
5+
//! like `Option` normally.
6+
7+
//@ run-pass
8+
9+
#![allow(stable_features)]
10+
#![feature(no_core, core)]
11+
#![no_core]
12+
13+
extern crate core;
14+
extern crate std;
15+
16+
use std::option::Option::Some;
17+
18+
fn main() {
19+
let a = Some("foo");
20+
a.unwrap();
21+
}

tests/ui/noexporttypeexe.stderr

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

tests/ui/non-constant-expr-for-arr-len.rs

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

tests/ui/nonscalar-cast.fixed

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

0 commit comments

Comments
 (0)