-
Notifications
You must be signed in to change notification settings - Fork 13.5k
tests/ui
: A New Order [20/N]
#143212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
tests/ui
: A New Order [20/N]
#143212
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//! Test that casting non-primitive types with `as` is rejected with a helpful suggestion. | ||
//! | ||
//! You can't use `as` to cast between non-primitive types, even if they have | ||
//! `From`/`Into` implementations. The compiler should suggest using `From::from()` | ||
//! or `.into()` instead, and rustfix should be able to apply the suggestion. | ||
|
||
//@ run-rustfix | ||
|
||
#[derive(Debug)] | ||
struct Foo { | ||
x: isize, | ||
} | ||
|
||
impl From<Foo> for isize { | ||
fn from(val: Foo) -> isize { | ||
val.x | ||
} | ||
} | ||
|
||
fn main() { | ||
let _ = isize::from(Foo { x: 1 }); | ||
//~^ ERROR non-primitive cast: `Foo` as `isize` [E0605] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//! Test that casting non-primitive types with `as` is rejected with a helpful suggestion. | ||
//! | ||
//! You can't use `as` to cast between non-primitive types, even if they have | ||
//! `From`/`Into` implementations. The compiler should suggest using `From::from()` | ||
//! or `.into()` instead, and rustfix should be able to apply the suggestion. | ||
|
||
//@ run-rustfix | ||
|
||
#[derive(Debug)] | ||
struct Foo { | ||
x: isize, | ||
} | ||
|
||
impl From<Foo> for isize { | ||
fn from(val: Foo) -> isize { | ||
val.x | ||
} | ||
} | ||
|
||
fn main() { | ||
let _ = Foo { x: 1 } as isize; | ||
//~^ ERROR non-primitive cast: `Foo` as `isize` [E0605] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error[E0605]: non-primitive cast: `Foo` as `isize` | ||
--> $DIR/non-primitive-cast-suggestion.rs:21:13 | ||
| | ||
LL | let _ = Foo { x: 1 } as isize; | ||
| ^^^^^^^^^^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object | ||
| | ||
help: consider using the `From` trait instead | ||
| | ||
LL - let _ = Foo { x: 1 } as isize; | ||
LL + let _ = isize::from(Foo { x: 1 }); | ||
| | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0605`. |
19 changes: 19 additions & 0 deletions
19
tests/ui/closures/closure-clone-requires-captured-clone.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//! Test that closures only implement `Clone` if all captured values implement `Clone`. | ||
//! | ||
//! When a closure captures variables from its environment, it can only be cloned | ||
//! if all those captured variables are cloneable. This test makes sure the compiler | ||
//! properly rejects attempts to clone closures that capture non-Clone types. | ||
|
||
//@ compile-flags: --diagnostic-width=300 | ||
|
||
struct NonClone(i32); | ||
|
||
fn main() { | ||
let captured_value = NonClone(5); | ||
let closure = move || { | ||
let _ = captured_value.0; | ||
}; | ||
|
||
closure.clone(); | ||
//~^ ERROR the trait bound `NonClone: Clone` is not satisfied | ||
} |
23 changes: 23 additions & 0 deletions
23
tests/ui/closures/closure-clone-requires-captured-clone.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
error[E0277]: the trait bound `NonClone: Clone` is not satisfied in `{closure@$DIR/closure-clone-requires-captured-clone.rs:13:19: 13:26}` | ||
--> $DIR/closure-clone-requires-captured-clone.rs:17:13 | ||
| | ||
LL | let closure = move || { | ||
| ------- within this `{closure@$DIR/closure-clone-requires-captured-clone.rs:13:19: 13:26}` | ||
... | ||
LL | closure.clone(); | ||
| ^^^^^ within `{closure@$DIR/closure-clone-requires-captured-clone.rs:13:19: 13:26}`, the trait `Clone` is not implemented for `NonClone` | ||
| | ||
note: required because it's used within this closure | ||
--> $DIR/closure-clone-requires-captured-clone.rs:13:19 | ||
| | ||
LL | let closure = move || { | ||
| ^^^^^^^ | ||
help: consider annotating `NonClone` with `#[derive(Clone)]` | ||
| | ||
LL + #[derive(Clone)] | ||
LL | struct NonClone(i32); | ||
| | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
//! Arrays created with `[value; length]` syntax need the length to be known at | ||
//! compile time. This test makes sure the compiler rejects runtime values like | ||
//! function parameters in the length position. | ||
|
||
fn main() { | ||
fn create_array(n: usize) { | ||
let _x = [0; n]; | ||
//~^ ERROR attempt to use a non-constant value in a constant [E0435] | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
...s/ui/non-constant-expr-for-arr-len.stderr → ...consts/array-repeat-expr-not-const.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
6 changes: 3 additions & 3 deletions
6
tests/ui/noexporttypeexe.rs → ...ss-crate/unexported-type-error-message.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/unexported-type-error-message.rs:10:20 | ||
| | ||
LL | let x: isize = unexported_type_error_message::foo(); | ||
| ----- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `isize`, found `Option<isize>` | ||
| | | ||
| expected due to this | ||
| | ||
= note: expected type `isize` | ||
found enum `Option<isize>` | ||
help: consider using `Option::expect` to unwrap the `Option<isize>` value, panicking if the value is an `Option::None` | ||
| | ||
LL | let x: isize = unexported_type_error_message::foo().expect("REASON"); | ||
| +++++++++++++++++ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//! Circa 2016-06-05, `fn inline` below issued an | ||
//! erroneous warning from the elaborate_drops pass about moving out of | ||
//! a field in `Foo`, which has a destructor (and thus cannot have | ||
//! content moved out of it). The reason that the warning is erroneous | ||
//! in this case is that we are doing a *replace*, not a move, of the | ||
//! content in question, and it is okay to replace fields within `Foo`. | ||
//! | ||
//! Another more subtle problem was that the elaborate_drops was | ||
//! creating a separate drop flag for that internally replaced content, | ||
//! even though the compiler should enforce an invariant that any drop | ||
//! flag for such subcontent of `Foo` will always have the same value | ||
//! as the drop flag for `Foo` itself. | ||
//! | ||
//! Regression test for <https://github.com/rust-lang/rust/issues/34101>. | ||
|
||
//@ check-pass | ||
|
||
struct Foo(String); | ||
|
||
impl Drop for Foo { | ||
fn drop(&mut self) {} | ||
} | ||
|
||
fn test_inline_replacement() { | ||
// dummy variable so `f` gets assigned `var1` in MIR for both functions | ||
let _s = (); | ||
let mut f = Foo(String::from("foo")); | ||
f.0 = String::from("bar"); // This should not warn | ||
} | ||
|
||
fn test_outline_replacement() { | ||
let _s = String::from("foo"); | ||
let mut f = Foo(_s); | ||
f.0 = String::from("bar"); // This should not warn either | ||
} | ||
|
||
fn main() { | ||
test_inline_replacement(); | ||
test_outline_replacement(); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//! Test that `#![no_core]` doesn't break modern Rust syntax in edition 2018. | ||
//! | ||
//! When you use `#![no_core]`, you lose the automatic prelude, but you can still | ||
//! get everything back by manually importing `use core::{prelude::v1::*, *}`. | ||
//! This test makes sure that after doing that, things like `for` loops and the | ||
//! `?` operator still work as expected. | ||
|
||
//@ run-pass | ||
//@ edition:2018 | ||
|
||
#![allow(dead_code, unused_imports)] | ||
#![feature(no_core)] | ||
#![no_core] | ||
|
||
extern crate core; | ||
extern crate std; | ||
use core::prelude::v1::*; | ||
use core::*; | ||
|
||
fn test_for_loop() { | ||
for _ in &[()] {} | ||
} | ||
|
||
fn test_question_mark_operator() -> Option<()> { | ||
None? | ||
} | ||
|
||
fn main() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//! Test that you can use `#![no_core]` and still import std and core manually. | ||
//! | ||
//! The `#![no_core]` attribute disables the automatic core prelude, but you should | ||
//! still be able to explicitly import both `std` and `core` crates and use types | ||
//! like `Option` normally. | ||
|
||
//@ run-pass | ||
|
||
#![allow(stable_features)] | ||
#![feature(no_core, core)] | ||
#![no_core] | ||
|
||
extern crate core; | ||
extern crate std; | ||
|
||
use std::option::Option::Some; | ||
|
||
fn main() { | ||
let a = Some("foo"); | ||
a.unwrap(); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.