From 47b8a32ca311e2c441f4e7d747bfd75f0045baa1 Mon Sep 17 00:00:00 2001 From: Kivooeo Date: Tue, 1 Jul 2025 20:20:14 +0500 Subject: moved tests --- .../super-let-lifetime-and-drop.borrowck.stderr | 174 +++++++++++++ tests/ui/borrowck/super-let-lifetime-and-drop.rs | 286 +++++++++++++++++++++ tests/ui/cast/cast-enum-to-primitive-error.fixed | 20 ++ tests/ui/cast/cast-enum-to-primitive-error.rs | 20 ++ tests/ui/cast/cast-enum-to-primitive-error.stderr | 16 ++ tests/ui/cast/coercion-as-explicit-cast.rs | 62 +++++ tests/ui/cast/coercion-as-explicit-cast.stderr | 12 + tests/ui/generics/generic-enum-errors.rs | 6 + tests/ui/generics/generic-enum-errors.stderr | 29 +++ tests/ui/modules/module-super-access.rs | 15 ++ tests/ui/modules/super-at-crate-root.rs | 4 + tests/ui/modules/super-at-crate-root.stderr | 9 + tests/ui/parser/syntactic-trailing-commas.rs | 34 +++ tests/ui/ptr_ops/ptr-swap-basic.rs | 10 + tests/ui/ptr_ops/ptr-swap-overlapping-regions.rs | 43 ++++ .../recursion/recursion-tail-call-no-arg-leak.rs | 8 + tests/ui/recursion/recursion-tail-cps.rs | 17 ++ tests/ui/super-at-top-level.rs | 4 - tests/ui/super-at-top-level.stderr | 9 - tests/ui/super-let.borrowck.stderr | 174 ------------- tests/ui/super-let.rs | 286 --------------------- tests/ui/super.rs | 15 -- tests/ui/svh-add-nothing.rs | 13 - tests/ui/svh/svh-no-api-change-no-recompile.rs | 13 + tests/ui/swap-1.rs | 10 - tests/ui/swap-overlapping.rs | 43 ---- tests/ui/switched-expectations.rs | 4 - tests/ui/switched-expectations.stderr | 14 - tests/ui/tag-type-args.rs | 6 - tests/ui/tag-type-args.stderr | 29 --- tests/ui/tag-variant-cast-non-nullary.fixed | 20 -- tests/ui/tag-variant-cast-non-nullary.rs | 20 -- tests/ui/tag-variant-cast-non-nullary.stderr | 16 -- tests/ui/tail-call-arg-leak.rs | 8 - tests/ui/tail-cps.rs | 17 -- tests/ui/tail-typeck.rs | 5 - tests/ui/tail-typeck.stderr | 16 -- tests/ui/trailing-comma.rs | 34 --- tests/ui/trait-method-number-parameters.rs | 13 - tests/ui/trait-method-number-parameters.stderr | 13 - tests/ui/traits/trait-method-signature-mismatch.rs | 13 + .../traits/trait-method-signature-mismatch.stderr | 13 + .../ui/traits/tryfrominterror-result-comparison.rs | 12 + tests/ui/transmute-equal-assoc-types.rs | 11 - tests/ui/transmute-non-immediate-to-immediate.rs | 10 - tests/ui/transmute/transmute-array-to-scalar.rs | 10 + .../ui/transmute/transmute-same-associated-type.rs | 11 + tests/ui/trivial_casts-rpass.rs | 62 ----- tests/ui/trivial_casts-rpass.stderr | 12 - tests/ui/try-from-int-error-partial-eq.rs | 12 - tests/ui/typeck/mismatched-types-ref-binding.rs | 4 + .../ui/typeck/mismatched-types-ref-binding.stderr | 14 + tests/ui/typeck/tail-return-type-mismatch.rs | 5 + tests/ui/typeck/tail-return-type-mismatch.stderr | 16 ++ 54 files changed, 876 insertions(+), 876 deletions(-) create mode 100644 tests/ui/borrowck/super-let-lifetime-and-drop.borrowck.stderr create mode 100644 tests/ui/borrowck/super-let-lifetime-and-drop.rs create mode 100644 tests/ui/cast/cast-enum-to-primitive-error.fixed create mode 100644 tests/ui/cast/cast-enum-to-primitive-error.rs create mode 100644 tests/ui/cast/cast-enum-to-primitive-error.stderr create mode 100644 tests/ui/cast/coercion-as-explicit-cast.rs create mode 100644 tests/ui/cast/coercion-as-explicit-cast.stderr create mode 100644 tests/ui/generics/generic-enum-errors.rs create mode 100644 tests/ui/generics/generic-enum-errors.stderr create mode 100644 tests/ui/modules/module-super-access.rs create mode 100644 tests/ui/modules/super-at-crate-root.rs create mode 100644 tests/ui/modules/super-at-crate-root.stderr create mode 100644 tests/ui/parser/syntactic-trailing-commas.rs create mode 100644 tests/ui/ptr_ops/ptr-swap-basic.rs create mode 100644 tests/ui/ptr_ops/ptr-swap-overlapping-regions.rs create mode 100644 tests/ui/recursion/recursion-tail-call-no-arg-leak.rs create mode 100644 tests/ui/recursion/recursion-tail-cps.rs delete mode 100644 tests/ui/super-at-top-level.rs delete mode 100644 tests/ui/super-at-top-level.stderr delete mode 100644 tests/ui/super-let.borrowck.stderr delete mode 100644 tests/ui/super-let.rs delete mode 100644 tests/ui/super.rs delete mode 100644 tests/ui/svh-add-nothing.rs create mode 100644 tests/ui/svh/svh-no-api-change-no-recompile.rs delete mode 100644 tests/ui/swap-1.rs delete mode 100644 tests/ui/swap-overlapping.rs delete mode 100644 tests/ui/switched-expectations.rs delete mode 100644 tests/ui/switched-expectations.stderr delete mode 100644 tests/ui/tag-type-args.rs delete mode 100644 tests/ui/tag-type-args.stderr delete mode 100644 tests/ui/tag-variant-cast-non-nullary.fixed delete mode 100644 tests/ui/tag-variant-cast-non-nullary.rs delete mode 100644 tests/ui/tag-variant-cast-non-nullary.stderr delete mode 100644 tests/ui/tail-call-arg-leak.rs delete mode 100644 tests/ui/tail-cps.rs delete mode 100644 tests/ui/tail-typeck.rs delete mode 100644 tests/ui/tail-typeck.stderr delete mode 100644 tests/ui/trailing-comma.rs delete mode 100644 tests/ui/trait-method-number-parameters.rs delete mode 100644 tests/ui/trait-method-number-parameters.stderr create mode 100644 tests/ui/traits/trait-method-signature-mismatch.rs create mode 100644 tests/ui/traits/trait-method-signature-mismatch.stderr create mode 100644 tests/ui/traits/tryfrominterror-result-comparison.rs delete mode 100644 tests/ui/transmute-equal-assoc-types.rs delete mode 100644 tests/ui/transmute-non-immediate-to-immediate.rs create mode 100644 tests/ui/transmute/transmute-array-to-scalar.rs create mode 100644 tests/ui/transmute/transmute-same-associated-type.rs delete mode 100644 tests/ui/trivial_casts-rpass.rs delete mode 100644 tests/ui/trivial_casts-rpass.stderr delete mode 100644 tests/ui/try-from-int-error-partial-eq.rs create mode 100644 tests/ui/typeck/mismatched-types-ref-binding.rs create mode 100644 tests/ui/typeck/mismatched-types-ref-binding.stderr create mode 100644 tests/ui/typeck/tail-return-type-mismatch.rs create mode 100644 tests/ui/typeck/tail-return-type-mismatch.stderr diff --git a/tests/ui/borrowck/super-let-lifetime-and-drop.borrowck.stderr b/tests/ui/borrowck/super-let-lifetime-and-drop.borrowck.stderr new file mode 100644 index 00000000000..7fe0b47ed57 --- /dev/null +++ b/tests/ui/borrowck/super-let-lifetime-and-drop.borrowck.stderr @@ -0,0 +1,174 @@ +error[E0506]: cannot assign to `x` because it is borrowed + --> $DIR/super-let-lifetime-and-drop.rs:30:28 + | +LL | super let b = DropMe(&mut x); + | ------ `x` is borrowed here +... +LL | #[cfg(borrowck)] { x = true; } + | ^^^^^^^^ `x` is assigned to here but it was already borrowed +... +LL | } + | - borrow might be used here, when `b` is dropped and runs the `Drop` code for type `DropMe` + +error[E0506]: cannot assign to `x` because it is borrowed + --> $DIR/super-let-lifetime-and-drop.rs:46:28 + | +LL | super let b = &DropMe(&mut x); + | -------------- + | | | + | | `x` is borrowed here + | a temporary with access to the borrow is created here ... +... +LL | #[cfg(borrowck)] { x = true; } + | ^^^^^^^^ `x` is assigned to here but it was already borrowed +... +LL | } + | - ... and the borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `DropMe` + +error[E0506]: cannot assign to `x` because it is borrowed + --> $DIR/super-let-lifetime-and-drop.rs:64:32 + | +LL | super let b = identity(&DropMe(&mut x)); + | -------------- + | | | + | | `x` is borrowed here + | a temporary with access to the borrow is created here ... +LL | #[cfg(borrowck)] { x = true; } + | ^^^^^^^^ `x` is assigned to here but it was already borrowed +... +LL | }; + | - ... and the borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `DropMe` + +error[E0506]: cannot assign to `x` because it is borrowed + --> $DIR/super-let-lifetime-and-drop.rs:87:36 + | +LL | super let b = identity(&DropMe(&mut x)); + | -------------- + | | | + | | `x` is borrowed here + | a temporary with access to the borrow is created here ... +... +LL | #[cfg(borrowck)] { x = true; } + | ^^^^^^^^ `x` is assigned to here but it was already borrowed +... +LL | )); + | - ... and the borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `DropMe` + +error[E0506]: cannot assign to `x` because it is borrowed + --> $DIR/super-let-lifetime-and-drop.rs:107:28 + | +LL | super let b = DropMe(&mut x); + | ------ `x` is borrowed here +... +LL | #[cfg(borrowck)] { x = true; } + | ^^^^^^^^ `x` is assigned to here but it was already borrowed +... +LL | } + | - borrow might be used here, when `b` is dropped and runs the `Drop` code for type `DropMe` + +error[E0506]: cannot assign to `x` because it is borrowed + --> $DIR/super-let-lifetime-and-drop.rs:125:28 + | +LL | super let b = DropMe(&mut x); + | ------ `x` is borrowed here +... +LL | #[cfg(borrowck)] { x = true; } + | ^^^^^^^^ `x` is assigned to here but it was already borrowed +... +LL | } + | - borrow might be used here, when `b` is dropped and runs the `Drop` code for type `DropMe` + +error[E0506]: cannot assign to `x` because it is borrowed + --> $DIR/super-let-lifetime-and-drop.rs:143:28 + | +LL | super let b = DropMe(&mut x); + | ------ `x` is borrowed here +... +LL | #[cfg(borrowck)] { x = true; } + | ^^^^^^^^ `x` is assigned to here but it was already borrowed +... +LL | } + | - borrow might be used here, when `b` is dropped and runs the `Drop` code for type `DropMe` + +error[E0506]: cannot assign to `x` because it is borrowed + --> $DIR/super-let-lifetime-and-drop.rs:159:28 + | +LL | b = DropMe(&mut x); + | ------ `x` is borrowed here +... +LL | #[cfg(borrowck)] { x = true; } + | ^^^^^^^^ `x` is assigned to here but it was already borrowed +LL | drop(a); + | - borrow later used here + +error[E0716]: temporary value dropped while borrowed + --> $DIR/super-let-lifetime-and-drop.rs:172:33 + | +LL | #[cfg(borrowck)] { a = &String::from("asdf"); }; + | ^^^^^^^^^^^^^^^^^^^^- temporary value is freed at the end of this statement + | | + | creates a temporary value which is freed while still in use +... +LL | let _ = a; + | - borrow later used here + | + = note: consider using a `let` binding to create a longer lived value + +error[E0506]: cannot assign to `x` because it is borrowed + --> $DIR/super-let-lifetime-and-drop.rs:206:28 + | +LL | super let d = &DropMe(&mut x); + | -------------- + | | | + | | `x` is borrowed here + | a temporary with access to the borrow is created here ... +... +LL | #[cfg(borrowck)] { x = true; } + | ^^^^^^^^ `x` is assigned to here but it was already borrowed +... +LL | } + | - ... and the borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `DropMe` + +error[E0506]: cannot assign to `x` because it is borrowed + --> $DIR/super-let-lifetime-and-drop.rs:227:32 + | +LL | super let d = identity(&DropMe(&mut x)); + | -------------- + | | | + | | `x` is borrowed here + | a temporary with access to the borrow is created here ... +... +LL | #[cfg(borrowck)] { x = true; } + | ^^^^^^^^ `x` is assigned to here but it was already borrowed +... +LL | }; + | - ... and the borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `DropMe` + +error[E0506]: cannot assign to `x` because it is borrowed + --> $DIR/super-let-lifetime-and-drop.rs:246:28 + | +LL | super let b = DropMe(&mut x); + | ------ `x` is borrowed here +... +LL | #[cfg(borrowck)] { x = true; } + | ^^^^^^^^ `x` is assigned to here but it was already borrowed +... +LL | } + | - borrow might be used here, when `b` is dropped and runs the `Drop` code for type `DropMe` + +error[E0506]: cannot assign to `x` because it is borrowed + --> $DIR/super-let-lifetime-and-drop.rs:263:28 + | +LL | let dropme = Some(DropMe(&mut x)); + | ------ `x` is borrowed here +... +LL | #[cfg(borrowck)] { x = true; } + | ^^^^^^^^ `x` is assigned to here but it was already borrowed +... +LL | } + | - borrow might be used here, when `x` is dropped and runs the `Drop` code for type `DropMe` + +error: aborting due to 13 previous errors + +Some errors have detailed explanations: E0506, E0716. +For more information about an error, try `rustc --explain E0506`. diff --git a/tests/ui/borrowck/super-let-lifetime-and-drop.rs b/tests/ui/borrowck/super-let-lifetime-and-drop.rs new file mode 100644 index 00000000000..380470f792f --- /dev/null +++ b/tests/ui/borrowck/super-let-lifetime-and-drop.rs @@ -0,0 +1,286 @@ +// Check in two ways: +// - borrowck: Check with borrow checking errors when things are alive and dead. +// - runtime: Check with a mutable bool if things are dropped on time. +// +//@ revisions: runtime borrowck +//@ [runtime] run-pass +//@ [borrowck] check-fail + +#![allow(dropping_references)] +#![feature(super_let, stmt_expr_attributes)] + +use std::convert::identity; + +struct DropMe<'a>(&'a mut bool); + +impl Drop for DropMe<'_> { + fn drop(&mut self) { + *self.0 = true; + } +} + +// Check that a super let variable lives as long as the result of a block. +fn extended_variable() { + let mut x = false; + { + let a = { + super let b = DropMe(&mut x); + &b + }; + #[cfg(borrowck)] { x = true; } //[borrowck]~ ERROR borrowed + drop(a); + // DropMe is still alive here... + } + // ... but not here. + assert_eq!(x, true) // ok +} + +// Check that the init expression of a super let is subject to (temporary) lifetime extension. +fn extended_temporary() { + let mut x = false; + { + let a = { + super let b = &DropMe(&mut x); + b + }; + #[cfg(borrowck)] { x = true; } //[borrowck]~ ERROR borrowed + drop(a); + // DropMe is still alive here... + } + // ... but not here. + assert_eq!(x, true); // ok +} + +// Check that even non-extended temporaries live until the end of the block, +// but (unlike extended temporaries) not beyond that. +// +// This is necessary for things like select(pin!(identity(&temp()))) to work. +fn non_extended() { + let mut x = false; + { + let _a = { + // Use identity() to supress temporary lifetime extension. + super let b = identity(&DropMe(&mut x)); + #[cfg(borrowck)] { x = true; } //[borrowck]~ ERROR borrowed + b + // DropMe is still alive here... + }; + // ... but not here. + assert_eq!(x, true); // ok + } +} + +// Check that even non-extended temporaries live until the end of the block, +// but (unlike extended temporaries) not beyond that. +// +// This is necessary for things like select(pin!(identity(&temp()))) to work. +fn non_extended_in_expression() { + let mut x = false; + { + identity(( + { + // Use identity() to supress temporary lifetime extension. + super let b = identity(&DropMe(&mut x)); + b + }, + { + #[cfg(borrowck)] { x = true; } //[borrowck]~ ERROR borrowed + // DropMe is still alive here... + } + )); + // ... but not here. + assert_eq!(x, true); // ok + } +} + +// Check `super let` in a match arm. +fn match_arm() { + let mut x = false; + { + let a = match Some(123) { + Some(_) => { + super let b = DropMe(&mut x); + &b + } + None => unreachable!(), + }; + #[cfg(borrowck)] { x = true; } //[borrowck]~ ERROR borrowed + drop(a); + // DropMe is still alive here... + } + // ... but not here. + assert_eq!(x, true); // ok +} + +// Check `super let` in an if body. +fn if_body() { + let mut x = false; + { + let a = if true { + super let b = DropMe(&mut x); + &b + } else { + unreachable!() + }; + #[cfg(borrowck)] { x = true; } //[borrowck]~ ERROR borrowed + drop(a); + // DropMe is still alive here... + } + // ... but not here. + assert_eq!(x, true); // ok +} + +// Check `super let` in an else body. +fn else_body() { + let mut x = false; + { + let a = if false { + unreachable!() + } else { + super let b = DropMe(&mut x); + &b + }; + #[cfg(borrowck)] { x = true; } //[borrowck]~ ERROR borrowed + drop(a); + // DropMe is still alive here... + } + // ... but not here. + assert_eq!(x, true); // ok +} + +fn without_initializer() { + let mut x = false; + { + let a = { + super let b; + b = DropMe(&mut x); + b + }; + #[cfg(borrowck)] { x = true; } //[borrowck]~ ERROR borrowed + drop(a); + // DropMe is still alive here... + } + // ... but not here. + assert_eq!(x, true); +} + +// Assignment isn't special, even when assigning to a `super let` variable. +fn assignment() { + let mut x = false; + { + super let a; + #[cfg(borrowck)] { a = &String::from("asdf"); }; //[borrowck]~ ERROR dropped while borrowed + #[cfg(runtime)] { a = drop(&DropMe(&mut x)); } // Temporary dropped at the `;` as usual. + assert_eq!(x, true); + let _ = a; + } +} + +// `super let mut` should work just fine. +fn mutable() { + let mut x = false; + { + let a = { + super let mut b = None; + &mut b + }; + *a = Some(DropMe(&mut x)); + } + assert_eq!(x, true); +} + +// Temporary lifetime extension should recurse through `super let`s. +fn multiple_levels() { + let mut x = false; + { + let a = { + super let b = { + super let c = { + super let d = &DropMe(&mut x); + d + }; + c + }; + b + }; + #[cfg(borrowck)] { x = true; } //[borrowck]~ ERROR borrowed + drop(a); + // DropMe is still alive here... + } + // ... but not here. + assert_eq!(x, true); +} + +// Non-extended temporaries should be dropped at the +// end of the first parent statement that isn't `super`. +fn multiple_levels_but_no_extension() { + let mut x = false; + { + let _a = { + super let b = { + super let c = { + super let d = identity(&DropMe(&mut x)); + d + }; + c + }; + #[cfg(borrowck)] { x = true; } //[borrowck]~ ERROR borrowed + b + // DropMe is still alive here... + }; + // ... but not here. + assert_eq!(x, true); + } +} + +// Check for potential weird interactions with `let else`. +fn super_let_and_let_else() { + let mut x = false; + { + let a = 'a: { + let Some(_) = Some(123) else { unreachable!() }; + super let b = DropMe(&mut x); + let None = Some(123) else { break 'a &b }; + unreachable!() + }; + #[cfg(borrowck)] { x = true; } //[borrowck]~ ERROR borrowed + // DropMe is still alive here... + drop(a); + } + // ... but not here. + assert_eq!(x, true); +} + +// Check if `super let .. else ..;` works. +fn super_let_else() { + let mut x = false; + { + let a = { + let dropme = Some(DropMe(&mut x)); + super let Some(x) = dropme else { unreachable!() }; + &x + }; + #[cfg(borrowck)] { x = true; } //[borrowck]~ ERROR borrowed + // DropMe is still alive here... + drop(a); + } + // ... but not here. + assert_eq!(x, true); +} + +fn main() { + extended_variable(); + extended_temporary(); + non_extended(); + non_extended_in_expression(); + match_arm(); + if_body(); + else_body(); + without_initializer(); + assignment(); + mutable(); + multiple_levels(); + multiple_levels_but_no_extension(); + super_let_and_let_else(); + super_let_else(); +} diff --git a/tests/ui/cast/cast-enum-to-primitive-error.fixed b/tests/ui/cast/cast-enum-to-primitive-error.fixed new file mode 100644 index 00000000000..7e22116b955 --- /dev/null +++ b/tests/ui/cast/cast-enum-to-primitive-error.fixed @@ -0,0 +1,20 @@ +//@ run-rustfix +#![allow(dead_code, unused_variables)] +enum NonNullary { + Nullary, + Other(isize), +} + +impl From for isize { + fn from(val: NonNullary) -> isize { + match val { + NonNullary::Nullary => 0, + NonNullary::Other(i) => i, + } + } +} + +fn main() { + let v = NonNullary::Nullary; + let val = isize::from(v); //~ ERROR non-primitive cast: `NonNullary` as `isize` [E0605] +} diff --git a/tests/ui/cast/cast-enum-to-primitive-error.rs b/tests/ui/cast/cast-enum-to-primitive-error.rs new file mode 100644 index 00000000000..1a64cf1933d --- /dev/null +++ b/tests/ui/cast/cast-enum-to-primitive-error.rs @@ -0,0 +1,20 @@ +//@ run-rustfix +#![allow(dead_code, unused_variables)] +enum NonNullary { + Nullary, + Other(isize), +} + +impl From for isize { + fn from(val: NonNullary) -> isize { + match val { + NonNullary::Nullary => 0, + NonNullary::Other(i) => i, + } + } +} + +fn main() { + let v = NonNullary::Nullary; + let val = v as isize; //~ ERROR non-primitive cast: `NonNullary` as `isize` [E0605] +} diff --git a/tests/ui/cast/cast-enum-to-primitive-error.stderr b/tests/ui/cast/cast-enum-to-primitive-error.stderr new file mode 100644 index 00000000000..8ec1c5f11ec --- /dev/null +++ b/tests/ui/cast/cast-enum-to-primitive-error.stderr @@ -0,0 +1,16 @@ +error[E0605]: non-primitive cast: `NonNullary` as `isize` + --> $DIR/tag-variant-cast-non-nullary.rs:19:15 + | +LL | let val = v as isize; + | ^^^^^^^^^^ an `as` expression can be used to convert enum types to numeric types only if the enum type is unit-only or field-less + | + = note: see https://doc.rust-lang.org/reference/items/enumerations.html#casting for more information +help: consider using the `From` trait instead + | +LL - let val = v as isize; +LL + let val = isize::from(v); + | + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0605`. diff --git a/tests/ui/cast/coercion-as-explicit-cast.rs b/tests/ui/cast/coercion-as-explicit-cast.rs new file mode 100644 index 00000000000..701e2f6166f --- /dev/null +++ b/tests/ui/cast/coercion-as-explicit-cast.rs @@ -0,0 +1,62 @@ +//@ run-pass +// Test that all coercions can actually be done using casts (modulo the lints). + +#![allow(trivial_casts, trivial_numeric_casts)] + +trait Foo { + fn foo(&self) {} //~ WARN method `foo` is never used +} + +pub struct Bar; + +impl Foo for Bar {} + +pub fn main() { + // Numeric + let _ = 42_i32 as i32; + let _ = 42_u8 as u8; + + // & to * pointers + let x: &u32 = &42; + let _ = x as *const u32; + + let x: &mut u32 = &mut 42; + let _ = x as *mut u32; + + // unsize array + let x: &[u32; 3] = &[42, 43, 44]; + let _ = x as &[u32]; + let _ = x as *const [u32]; + + let x: &mut [u32; 3] = &mut [42, 43, 44]; + let _ = x as &mut [u32]; + let _ = x as *mut [u32]; + + let x: Box<[u32; 3]> = Box::new([42, 43, 44]); + let _ = x as Box<[u32]>; + + // unsize trait + let x: &Bar = &Bar; + let _ = x as &dyn Foo; + let _ = x as *const dyn Foo; + + let x: &mut Bar = &mut Bar; + let _ = x as &mut dyn Foo; + let _ = x as *mut dyn Foo; + + let x: Box = Box::new(Bar); + let _ = x as Box; + + // functions + fn baz(_x: i32) {} + let _ = &baz as &dyn Fn(i32); + let x = |_x: i32| {}; + let _ = &x as &dyn Fn(i32); +} + +// subtyping +pub fn test_subtyping<'a, 'b: 'a>(a: &'a Bar, b: &'b Bar) { + let _ = a as &'a Bar; + let _ = b as &'a Bar; + let _ = b as &'b Bar; +} diff --git a/tests/ui/cast/coercion-as-explicit-cast.stderr b/tests/ui/cast/coercion-as-explicit-cast.stderr new file mode 100644 index 00000000000..74698b61ab4 --- /dev/null +++ b/tests/ui/cast/coercion-as-explicit-cast.stderr @@ -0,0 +1,12 @@ +warning: method `foo` is never used + --> $DIR/trivial_casts-rpass.rs:7:8 + | +LL | trait Foo { + | --- method in this trait +LL | fn foo(&self) {} + | ^^^ + | + = note: `#[warn(dead_code)]` on by default + +warning: 1 warning emitted + diff --git a/tests/ui/generics/generic-enum-errors.rs b/tests/ui/generics/generic-enum-errors.rs new file mode 100644 index 00000000000..75a54927443 --- /dev/null +++ b/tests/ui/generics/generic-enum-errors.rs @@ -0,0 +1,6 @@ +enum Quux { Bar } +//~^ ERROR: parameter `T` is never used + +fn foo(c: Quux) { assert!((false)); } //~ ERROR missing generics for enum `Quux` + +fn main() { panic!(); } diff --git a/tests/ui/generics/generic-enum-errors.stderr b/tests/ui/generics/generic-enum-errors.stderr new file mode 100644 index 00000000000..def13832e1a --- /dev/null +++ b/tests/ui/generics/generic-enum-errors.stderr @@ -0,0 +1,29 @@ +error[E0392]: type parameter `T` is never used + --> $DIR/tag-type-args.rs:1:11 + | +LL | enum Quux { Bar } + | ^ unused type parameter + | + = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData` + = help: if you intended `T` to be a const parameter, use `const T: /* Type */` instead + +error[E0107]: missing generics for enum `Quux` + --> $DIR/tag-type-args.rs:4:11 + | +LL | fn foo(c: Quux) { assert!((false)); } + | ^^^^ expected 1 generic argument + | +note: enum defined here, with 1 generic parameter: `T` + --> $DIR/tag-type-args.rs:1:6 + | +LL | enum Quux { Bar } + | ^^^^ - +help: add missing generic argument + | +LL | fn foo(c: Quux) { assert!((false)); } + | +++ + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0107, E0392. +For more information about an error, try `rustc --explain E0107`. diff --git a/tests/ui/modules/module-super-access.rs b/tests/ui/modules/module-super-access.rs new file mode 100644 index 00000000000..69aff4f98e0 --- /dev/null +++ b/tests/ui/modules/module-super-access.rs @@ -0,0 +1,15 @@ +//@ run-pass + +#![allow(dead_code)] + +pub mod a { + pub fn f() {} + pub mod b { + fn g() { + super::f(); + } + } +} + +pub fn main() { +} diff --git a/tests/ui/modules/super-at-crate-root.rs b/tests/ui/modules/super-at-crate-root.rs new file mode 100644 index 00000000000..e4d587bc9ef --- /dev/null +++ b/tests/ui/modules/super-at-crate-root.rs @@ -0,0 +1,4 @@ +use super::f; //~ ERROR there are too many leading `super` keywords + +fn main() { +} diff --git a/tests/ui/modules/super-at-crate-root.stderr b/tests/ui/modules/super-at-crate-root.stderr new file mode 100644 index 00000000000..4dce81fbef4 --- /dev/null +++ b/tests/ui/modules/super-at-crate-root.stderr @@ -0,0 +1,9 @@ +error[E0433]: failed to resolve: there are too many leading `super` keywords + --> $DIR/super-at-top-level.rs:1:5 + | +LL | use super::f; + | ^^^^^ there are too many leading `super` keywords + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0433`. diff --git a/tests/ui/parser/syntactic-trailing-commas.rs b/tests/ui/parser/syntactic-trailing-commas.rs new file mode 100644 index 00000000000..53b76fb6037 --- /dev/null +++ b/tests/ui/parser/syntactic-trailing-commas.rs @@ -0,0 +1,34 @@ +//@ run-pass + +fn f(_: T,) {} + +struct Foo(#[allow(dead_code)] T); + +struct Bar; + +impl Bar { + fn f(_: isize,) {} + fn g(self, _: isize,) {} + fn h(self,) {} +} + +enum Baz { + Qux(#[allow(dead_code)] isize,), +} + +#[allow(unused,)] +pub fn main() { + f::(0,); + let (_, _,) = (1, 1,); + let [_, _,] = [1, 1,]; + let [_, _, .., _,] = [1, 1, 1, 1,]; + let [_, _, _, ..,] = [1, 1, 1, 1,]; + + let x: Foo = Foo::(1); + + Bar::f(0,); + Bar.g(0,); + Bar.h(); + + let x = Baz::Qux(1,); +} diff --git a/tests/ui/ptr_ops/ptr-swap-basic.rs b/tests/ui/ptr_ops/ptr-swap-basic.rs new file mode 100644 index 00000000000..b104c3ade42 --- /dev/null +++ b/tests/ui/ptr_ops/ptr-swap-basic.rs @@ -0,0 +1,10 @@ +//@ run-pass + +use std::mem::swap; + +pub fn main() { + let mut x = 3; let mut y = 7; + swap(&mut x, &mut y); + assert_eq!(x, 7); + assert_eq!(y, 3); +} diff --git a/tests/ui/ptr_ops/ptr-swap-overlapping-regions.rs b/tests/ui/ptr_ops/ptr-swap-overlapping-regions.rs new file mode 100644 index 00000000000..38d5a8109d1 --- /dev/null +++ b/tests/ui/ptr_ops/ptr-swap-overlapping-regions.rs @@ -0,0 +1,43 @@ +//@ run-pass + +#![allow(dead_code)] +// Issue #5041 - avoid overlapping memcpy when src and dest of a swap are the same + + +use std::ptr; + +pub fn main() { + let mut test = TestDescAndFn { + desc: TestDesc { + name: TestName::DynTestName("test".to_string()), + should_fail: false + }, + testfn: TestFn::DynTestFn(22), + }; + do_swap(&mut test); +} + +fn do_swap(test: &mut TestDescAndFn) { + unsafe { + ptr::swap(test, test); + } +} + +pub enum TestName { + DynTestName(String) +} + +pub enum TestFn { + DynTestFn(isize), + DynBenchFn(isize), +} + +pub struct TestDesc { + name: TestName, + should_fail: bool +} + +pub struct TestDescAndFn { + desc: TestDesc, + testfn: TestFn, +} diff --git a/tests/ui/recursion/recursion-tail-call-no-arg-leak.rs b/tests/ui/recursion/recursion-tail-call-no-arg-leak.rs new file mode 100644 index 00000000000..234924307c3 --- /dev/null +++ b/tests/ui/recursion/recursion-tail-call-no-arg-leak.rs @@ -0,0 +1,8 @@ +//@ run-pass +// use of tail calls causes arg slot leaks, issue #160. + +fn inner(dummy: String, b: bool) { if b { return inner(dummy, false); } } + +pub fn main() { + inner("hi".to_string(), true); +} diff --git a/tests/ui/recursion/recursion-tail-cps.rs b/tests/ui/recursion/recursion-tail-cps.rs new file mode 100644 index 00000000000..fe99dadf795 --- /dev/null +++ b/tests/ui/recursion/recursion-tail-cps.rs @@ -0,0 +1,17 @@ +//@ run-pass + +fn checktrue(rs: bool) -> bool { assert!(rs); return true; } + +pub fn main() { let k = checktrue; evenk(42, k); oddk(45, k); } + +fn evenk(n: isize, k: fn(bool) -> bool) -> bool { + println!("evenk"); + println!("{}", n); + if n == 0 { return k(true); } else { return oddk(n - 1, k); } +} + +fn oddk(n: isize, k: fn(bool) -> bool) -> bool { + println!("oddk"); + println!("{}", n); + if n == 0 { return k(false); } else { return evenk(n - 1, k); } +} diff --git a/tests/ui/super-at-top-level.rs b/tests/ui/super-at-top-level.rs deleted file mode 100644 index e4d587bc9ef..00000000000 --- a/tests/ui/super-at-top-level.rs +++ /dev/null @@ -1,4 +0,0 @@ -use super::f; //~ ERROR there are too many leading `super` keywords - -fn main() { -} diff --git a/tests/ui/super-at-top-level.stderr b/tests/ui/super-at-top-level.stderr deleted file mode 100644 index 4dce81fbef4..00000000000 --- a/tests/ui/super-at-top-level.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0433]: failed to resolve: there are too many leading `super` keywords - --> $DIR/super-at-top-level.rs:1:5 - | -LL | use super::f; - | ^^^^^ there are too many leading `super` keywords - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0433`. diff --git a/tests/ui/super-let.borrowck.stderr b/tests/ui/super-let.borrowck.stderr deleted file mode 100644 index 01ef29d8758..00000000000 --- a/tests/ui/super-let.borrowck.stderr +++ /dev/null @@ -1,174 +0,0 @@ -error[E0506]: cannot assign to `x` because it is borrowed - --> $DIR/super-let.rs:30:28 - | -LL | super let b = DropMe(&mut x); - | ------ `x` is borrowed here -... -LL | #[cfg(borrowck)] { x = true; } - | ^^^^^^^^ `x` is assigned to here but it was already borrowed -... -LL | } - | - borrow might be used here, when `b` is dropped and runs the `Drop` code for type `DropMe` - -error[E0506]: cannot assign to `x` because it is borrowed - --> $DIR/super-let.rs:46:28 - | -LL | super let b = &DropMe(&mut x); - | -------------- - | | | - | | `x` is borrowed here - | a temporary with access to the borrow is created here ... -... -LL | #[cfg(borrowck)] { x = true; } - | ^^^^^^^^ `x` is assigned to here but it was already borrowed -... -LL | } - | - ... and the borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `DropMe` - -error[E0506]: cannot assign to `x` because it is borrowed - --> $DIR/super-let.rs:64:32 - | -LL | super let b = identity(&DropMe(&mut x)); - | -------------- - | | | - | | `x` is borrowed here - | a temporary with access to the borrow is created here ... -LL | #[cfg(borrowck)] { x = true; } - | ^^^^^^^^ `x` is assigned to here but it was already borrowed -... -LL | }; - | - ... and the borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `DropMe` - -error[E0506]: cannot assign to `x` because it is borrowed - --> $DIR/super-let.rs:87:36 - | -LL | super let b = identity(&DropMe(&mut x)); - | -------------- - | | | - | | `x` is borrowed here - | a temporary with access to the borrow is created here ... -... -LL | #[cfg(borrowck)] { x = true; } - | ^^^^^^^^ `x` is assigned to here but it was already borrowed -... -LL | )); - | - ... and the borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `DropMe` - -error[E0506]: cannot assign to `x` because it is borrowed - --> $DIR/super-let.rs:107:28 - | -LL | super let b = DropMe(&mut x); - | ------ `x` is borrowed here -... -LL | #[cfg(borrowck)] { x = true; } - | ^^^^^^^^ `x` is assigned to here but it was already borrowed -... -LL | } - | - borrow might be used here, when `b` is dropped and runs the `Drop` code for type `DropMe` - -error[E0506]: cannot assign to `x` because it is borrowed - --> $DIR/super-let.rs:125:28 - | -LL | super let b = DropMe(&mut x); - | ------ `x` is borrowed here -... -LL | #[cfg(borrowck)] { x = true; } - | ^^^^^^^^ `x` is assigned to here but it was already borrowed -... -LL | } - | - borrow might be used here, when `b` is dropped and runs the `Drop` code for type `DropMe` - -error[E0506]: cannot assign to `x` because it is borrowed - --> $DIR/super-let.rs:143:28 - | -LL | super let b = DropMe(&mut x); - | ------ `x` is borrowed here -... -LL | #[cfg(borrowck)] { x = true; } - | ^^^^^^^^ `x` is assigned to here but it was already borrowed -... -LL | } - | - borrow might be used here, when `b` is dropped and runs the `Drop` code for type `DropMe` - -error[E0506]: cannot assign to `x` because it is borrowed - --> $DIR/super-let.rs:159:28 - | -LL | b = DropMe(&mut x); - | ------ `x` is borrowed here -... -LL | #[cfg(borrowck)] { x = true; } - | ^^^^^^^^ `x` is assigned to here but it was already borrowed -LL | drop(a); - | - borrow later used here - -error[E0716]: temporary value dropped while borrowed - --> $DIR/super-let.rs:172:33 - | -LL | #[cfg(borrowck)] { a = &String::from("asdf"); }; - | ^^^^^^^^^^^^^^^^^^^^- temporary value is freed at the end of this statement - | | - | creates a temporary value which is freed while still in use -... -LL | let _ = a; - | - borrow later used here - | - = note: consider using a `let` binding to create a longer lived value - -error[E0506]: cannot assign to `x` because it is borrowed - --> $DIR/super-let.rs:206:28 - | -LL | super let d = &DropMe(&mut x); - | -------------- - | | | - | | `x` is borrowed here - | a temporary with access to the borrow is created here ... -... -LL | #[cfg(borrowck)] { x = true; } - | ^^^^^^^^ `x` is assigned to here but it was already borrowed -... -LL | } - | - ... and the borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `DropMe` - -error[E0506]: cannot assign to `x` because it is borrowed - --> $DIR/super-let.rs:227:32 - | -LL | super let d = identity(&DropMe(&mut x)); - | -------------- - | | | - | | `x` is borrowed here - | a temporary with access to the borrow is created here ... -... -LL | #[cfg(borrowck)] { x = true; } - | ^^^^^^^^ `x` is assigned to here but it was already borrowed -... -LL | }; - | - ... and the borrow might be used here, when that temporary is dropped and runs the `Drop` code for type `DropMe` - -error[E0506]: cannot assign to `x` because it is borrowed - --> $DIR/super-let.rs:246:28 - | -LL | super let b = DropMe(&mut x); - | ------ `x` is borrowed here -... -LL | #[cfg(borrowck)] { x = true; } - | ^^^^^^^^ `x` is assigned to here but it was already borrowed -... -LL | } - | - borrow might be used here, when `b` is dropped and runs the `Drop` code for type `DropMe` - -error[E0506]: cannot assign to `x` because it is borrowed - --> $DIR/super-let.rs:263:28 - | -LL | let dropme = Some(DropMe(&mut x)); - | ------ `x` is borrowed here -... -LL | #[cfg(borrowck)] { x = true; } - | ^^^^^^^^ `x` is assigned to here but it was already borrowed -... -LL | } - | - borrow might be used here, when `x` is dropped and runs the `Drop` code for type `DropMe` - -error: aborting due to 13 previous errors - -Some errors have detailed explanations: E0506, E0716. -For more information about an error, try `rustc --explain E0506`. diff --git a/tests/ui/super-let.rs b/tests/ui/super-let.rs deleted file mode 100644 index 380470f792f..00000000000 --- a/tests/ui/super-let.rs +++ /dev/null @@ -1,286 +0,0 @@ -// Check in two ways: -// - borrowck: Check with borrow checking errors when things are alive and dead. -// - runtime: Check with a mutable bool if things are dropped on time. -// -//@ revisions: runtime borrowck -//@ [runtime] run-pass -//@ [borrowck] check-fail - -#![allow(dropping_references)] -#![feature(super_let, stmt_expr_attributes)] - -use std::convert::identity; - -struct DropMe<'a>(&'a mut bool); - -impl Drop for DropMe<'_> { - fn drop(&mut self) { - *self.0 = true; - } -} - -// Check that a super let variable lives as long as the result of a block. -fn extended_variable() { - let mut x = false; - { - let a = { - super let b = DropMe(&mut x); - &b - }; - #[cfg(borrowck)] { x = true; } //[borrowck]~ ERROR borrowed - drop(a); - // DropMe is still alive here... - } - // ... but not here. - assert_eq!(x, true) // ok -} - -// Check that the init expression of a super let is subject to (temporary) lifetime extension. -fn extended_temporary() { - let mut x = false; - { - let a = { - super let b = &DropMe(&mut x); - b - }; - #[cfg(borrowck)] { x = true; } //[borrowck]~ ERROR borrowed - drop(a); - // DropMe is still alive here... - } - // ... but not here. - assert_eq!(x, true); // ok -} - -// Check that even non-extended temporaries live until the end of the block, -// but (unlike extended temporaries) not beyond that. -// -// This is necessary for things like select(pin!(identity(&temp()))) to work. -fn non_extended() { - let mut x = false; - { - let _a = { - // Use identity() to supress temporary lifetime extension. - super let b = identity(&DropMe(&mut x)); - #[cfg(borrowck)] { x = true; } //[borrowck]~ ERROR borrowed - b - // DropMe is still alive here... - }; - // ... but not here. - assert_eq!(x, true); // ok - } -} - -// Check that even non-extended temporaries live until the end of the block, -// but (unlike extended temporaries) not beyond that. -// -// This is necessary for things like select(pin!(identity(&temp()))) to work. -fn non_extended_in_expression() { - let mut x = false; - { - identity(( - { - // Use identity() to supress temporary lifetime extension. - super let b = identity(&DropMe(&mut x)); - b - }, - { - #[cfg(borrowck)] { x = true; } //[borrowck]~ ERROR borrowed - // DropMe is still alive here... - } - )); - // ... but not here. - assert_eq!(x, true); // ok - } -} - -// Check `super let` in a match arm. -fn match_arm() { - let mut x = false; - { - let a = match Some(123) { - Some(_) => { - super let b = DropMe(&mut x); - &b - } - None => unreachable!(), - }; - #[cfg(borrowck)] { x = true; } //[borrowck]~ ERROR borrowed - drop(a); - // DropMe is still alive here... - } - // ... but not here. - assert_eq!(x, true); // ok -} - -// Check `super let` in an if body. -fn if_body() { - let mut x = false; - { - let a = if true { - super let b = DropMe(&mut x); - &b - } else { - unreachable!() - }; - #[cfg(borrowck)] { x = true; } //[borrowck]~ ERROR borrowed - drop(a); - // DropMe is still alive here... - } - // ... but not here. - assert_eq!(x, true); // ok -} - -// Check `super let` in an else body. -fn else_body() { - let mut x = false; - { - let a = if false { - unreachable!() - } else { - super let b = DropMe(&mut x); - &b - }; - #[cfg(borrowck)] { x = true; } //[borrowck]~ ERROR borrowed - drop(a); - // DropMe is still alive here... - } - // ... but not here. - assert_eq!(x, true); // ok -} - -fn without_initializer() { - let mut x = false; - { - let a = { - super let b; - b = DropMe(&mut x); - b - }; - #[cfg(borrowck)] { x = true; } //[borrowck]~ ERROR borrowed - drop(a); - // DropMe is still alive here... - } - // ... but not here. - assert_eq!(x, true); -} - -// Assignment isn't special, even when assigning to a `super let` variable. -fn assignment() { - let mut x = false; - { - super let a; - #[cfg(borrowck)] { a = &String::from("asdf"); }; //[borrowck]~ ERROR dropped while borrowed - #[cfg(runtime)] { a = drop(&DropMe(&mut x)); } // Temporary dropped at the `;` as usual. - assert_eq!(x, true); - let _ = a; - } -} - -// `super let mut` should work just fine. -fn mutable() { - let mut x = false; - { - let a = { - super let mut b = None; - &mut b - }; - *a = Some(DropMe(&mut x)); - } - assert_eq!(x, true); -} - -// Temporary lifetime extension should recurse through `super let`s. -fn multiple_levels() { - let mut x = false; - { - let a = { - super let b = { - super let c = { - super let d = &DropMe(&mut x); - d - }; - c - }; - b - }; - #[cfg(borrowck)] { x = true; } //[borrowck]~ ERROR borrowed - drop(a); - // DropMe is still alive here... - } - // ... but not here. - assert_eq!(x, true); -} - -// Non-extended temporaries should be dropped at the -// end of the first parent statement that isn't `super`. -fn multiple_levels_but_no_extension() { - let mut x = false; - { - let _a = { - super let b = { - super let c = { - super let d = identity(&DropMe(&mut x)); - d - }; - c - }; - #[cfg(borrowck)] { x = true; } //[borrowck]~ ERROR borrowed - b - // DropMe is still alive here... - }; - // ... but not here. - assert_eq!(x, true); - } -} - -// Check for potential weird interactions with `let else`. -fn super_let_and_let_else() { - let mut x = false; - { - let a = 'a: { - let Some(_) = Some(123) else { unreachable!() }; - super let b = DropMe(&mut x); - let None = Some(123) else { break 'a &b }; - unreachable!() - }; - #[cfg(borrowck)] { x = true; } //[borrowck]~ ERROR borrowed - // DropMe is still alive here... - drop(a); - } - // ... but not here. - assert_eq!(x, true); -} - -// Check if `super let .. else ..;` works. -fn super_let_else() { - let mut x = false; - { - let a = { - let dropme = Some(DropMe(&mut x)); - super let Some(x) = dropme else { unreachable!() }; - &x - }; - #[cfg(borrowck)] { x = true; } //[borrowck]~ ERROR borrowed - // DropMe is still alive here... - drop(a); - } - // ... but not here. - assert_eq!(x, true); -} - -fn main() { - extended_variable(); - extended_temporary(); - non_extended(); - non_extended_in_expression(); - match_arm(); - if_body(); - else_body(); - without_initializer(); - assignment(); - mutable(); - multiple_levels(); - multiple_levels_but_no_extension(); - super_let_and_let_else(); - super_let_else(); -} diff --git a/tests/ui/super.rs b/tests/ui/super.rs deleted file mode 100644 index 69aff4f98e0..00000000000 --- a/tests/ui/super.rs +++ /dev/null @@ -1,15 +0,0 @@ -//@ run-pass - -#![allow(dead_code)] - -pub mod a { - pub fn f() {} - pub mod b { - fn g() { - super::f(); - } - } -} - -pub fn main() { -} diff --git a/tests/ui/svh-add-nothing.rs b/tests/ui/svh-add-nothing.rs deleted file mode 100644 index 6e4b9fa7f4c..00000000000 --- a/tests/ui/svh-add-nothing.rs +++ /dev/null @@ -1,13 +0,0 @@ -//@ run-pass -// note that these aux-build directives must be in this order -//@ aux-build:svh-a-base.rs -//@ aux-build:svh-b.rs -//@ aux-build:svh-a-base.rs - - -extern crate a; -extern crate b; - -fn main() { - b::foo() -} diff --git a/tests/ui/svh/svh-no-api-change-no-recompile.rs b/tests/ui/svh/svh-no-api-change-no-recompile.rs new file mode 100644 index 00000000000..6e4b9fa7f4c --- /dev/null +++ b/tests/ui/svh/svh-no-api-change-no-recompile.rs @@ -0,0 +1,13 @@ +//@ run-pass +// note that these aux-build directives must be in this order +//@ aux-build:svh-a-base.rs +//@ aux-build:svh-b.rs +//@ aux-build:svh-a-base.rs + + +extern crate a; +extern crate b; + +fn main() { + b::foo() +} diff --git a/tests/ui/swap-1.rs b/tests/ui/swap-1.rs deleted file mode 100644 index b104c3ade42..00000000000 --- a/tests/ui/swap-1.rs +++ /dev/null @@ -1,10 +0,0 @@ -//@ run-pass - -use std::mem::swap; - -pub fn main() { - let mut x = 3; let mut y = 7; - swap(&mut x, &mut y); - assert_eq!(x, 7); - assert_eq!(y, 3); -} diff --git a/tests/ui/swap-overlapping.rs b/tests/ui/swap-overlapping.rs deleted file mode 100644 index 38d5a8109d1..00000000000 --- a/tests/ui/swap-overlapping.rs +++ /dev/null @@ -1,43 +0,0 @@ -//@ run-pass - -#![allow(dead_code)] -// Issue #5041 - avoid overlapping memcpy when src and dest of a swap are the same - - -use std::ptr; - -pub fn main() { - let mut test = TestDescAndFn { - desc: TestDesc { - name: TestName::DynTestName("test".to_string()), - should_fail: false - }, - testfn: TestFn::DynTestFn(22), - }; - do_swap(&mut test); -} - -fn do_swap(test: &mut TestDescAndFn) { - unsafe { - ptr::swap(test, test); - } -} - -pub enum TestName { - DynTestName(String) -} - -pub enum TestFn { - DynTestFn(isize), - DynBenchFn(isize), -} - -pub struct TestDesc { - name: TestName, - should_fail: bool -} - -pub struct TestDescAndFn { - desc: TestDesc, - testfn: TestFn, -} diff --git a/tests/ui/switched-expectations.rs b/tests/ui/switched-expectations.rs deleted file mode 100644 index c5bc84de54c..00000000000 --- a/tests/ui/switched-expectations.rs +++ /dev/null @@ -1,4 +0,0 @@ -fn main() { - let var = 10i32; - let ref string: String = var; //~ ERROR mismatched types [E0308] -} diff --git a/tests/ui/switched-expectations.stderr b/tests/ui/switched-expectations.stderr deleted file mode 100644 index e235c2da1f7..00000000000 --- a/tests/ui/switched-expectations.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error[E0308]: mismatched types - --> $DIR/switched-expectations.rs:3:30 - | -LL | let ref string: String = var; - | ^^^ expected `String`, found `i32` - | -help: try using a conversion method - | -LL | let ref string: String = var.to_string(); - | ++++++++++++ - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/tag-type-args.rs b/tests/ui/tag-type-args.rs deleted file mode 100644 index 75a54927443..00000000000 --- a/tests/ui/tag-type-args.rs +++ /dev/null @@ -1,6 +0,0 @@ -enum Quux { Bar } -//~^ ERROR: parameter `T` is never used - -fn foo(c: Quux) { assert!((false)); } //~ ERROR missing generics for enum `Quux` - -fn main() { panic!(); } diff --git a/tests/ui/tag-type-args.stderr b/tests/ui/tag-type-args.stderr deleted file mode 100644 index def13832e1a..00000000000 --- a/tests/ui/tag-type-args.stderr +++ /dev/null @@ -1,29 +0,0 @@ -error[E0392]: type parameter `T` is never used - --> $DIR/tag-type-args.rs:1:11 - | -LL | enum Quux { Bar } - | ^ unused type parameter - | - = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData` - = help: if you intended `T` to be a const parameter, use `const T: /* Type */` instead - -error[E0107]: missing generics for enum `Quux` - --> $DIR/tag-type-args.rs:4:11 - | -LL | fn foo(c: Quux) { assert!((false)); } - | ^^^^ expected 1 generic argument - | -note: enum defined here, with 1 generic parameter: `T` - --> $DIR/tag-type-args.rs:1:6 - | -LL | enum Quux { Bar } - | ^^^^ - -help: add missing generic argument - | -LL | fn foo(c: Quux) { assert!((false)); } - | +++ - -error: aborting due to 2 previous errors - -Some errors have detailed explanations: E0107, E0392. -For more information about an error, try `rustc --explain E0107`. diff --git a/tests/ui/tag-variant-cast-non-nullary.fixed b/tests/ui/tag-variant-cast-non-nullary.fixed deleted file mode 100644 index 7e22116b955..00000000000 --- a/tests/ui/tag-variant-cast-non-nullary.fixed +++ /dev/null @@ -1,20 +0,0 @@ -//@ run-rustfix -#![allow(dead_code, unused_variables)] -enum NonNullary { - Nullary, - Other(isize), -} - -impl From for isize { - fn from(val: NonNullary) -> isize { - match val { - NonNullary::Nullary => 0, - NonNullary::Other(i) => i, - } - } -} - -fn main() { - let v = NonNullary::Nullary; - let val = isize::from(v); //~ ERROR non-primitive cast: `NonNullary` as `isize` [E0605] -} diff --git a/tests/ui/tag-variant-cast-non-nullary.rs b/tests/ui/tag-variant-cast-non-nullary.rs deleted file mode 100644 index 1a64cf1933d..00000000000 --- a/tests/ui/tag-variant-cast-non-nullary.rs +++ /dev/null @@ -1,20 +0,0 @@ -//@ run-rustfix -#![allow(dead_code, unused_variables)] -enum NonNullary { - Nullary, - Other(isize), -} - -impl From for isize { - fn from(val: NonNullary) -> isize { - match val { - NonNullary::Nullary => 0, - NonNullary::Other(i) => i, - } - } -} - -fn main() { - let v = NonNullary::Nullary; - let val = v as isize; //~ ERROR non-primitive cast: `NonNullary` as `isize` [E0605] -} diff --git a/tests/ui/tag-variant-cast-non-nullary.stderr b/tests/ui/tag-variant-cast-non-nullary.stderr deleted file mode 100644 index 8ec1c5f11ec..00000000000 --- a/tests/ui/tag-variant-cast-non-nullary.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error[E0605]: non-primitive cast: `NonNullary` as `isize` - --> $DIR/tag-variant-cast-non-nullary.rs:19:15 - | -LL | let val = v as isize; - | ^^^^^^^^^^ an `as` expression can be used to convert enum types to numeric types only if the enum type is unit-only or field-less - | - = note: see https://doc.rust-lang.org/reference/items/enumerations.html#casting for more information -help: consider using the `From` trait instead - | -LL - let val = v as isize; -LL + let val = isize::from(v); - | - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0605`. diff --git a/tests/ui/tail-call-arg-leak.rs b/tests/ui/tail-call-arg-leak.rs deleted file mode 100644 index 234924307c3..00000000000 --- a/tests/ui/tail-call-arg-leak.rs +++ /dev/null @@ -1,8 +0,0 @@ -//@ run-pass -// use of tail calls causes arg slot leaks, issue #160. - -fn inner(dummy: String, b: bool) { if b { return inner(dummy, false); } } - -pub fn main() { - inner("hi".to_string(), true); -} diff --git a/tests/ui/tail-cps.rs b/tests/ui/tail-cps.rs deleted file mode 100644 index fe99dadf795..00000000000 --- a/tests/ui/tail-cps.rs +++ /dev/null @@ -1,17 +0,0 @@ -//@ run-pass - -fn checktrue(rs: bool) -> bool { assert!(rs); return true; } - -pub fn main() { let k = checktrue; evenk(42, k); oddk(45, k); } - -fn evenk(n: isize, k: fn(bool) -> bool) -> bool { - println!("evenk"); - println!("{}", n); - if n == 0 { return k(true); } else { return oddk(n - 1, k); } -} - -fn oddk(n: isize, k: fn(bool) -> bool) -> bool { - println!("oddk"); - println!("{}", n); - if n == 0 { return k(false); } else { return evenk(n - 1, k); } -} diff --git a/tests/ui/tail-typeck.rs b/tests/ui/tail-typeck.rs deleted file mode 100644 index 1deb43c9496..00000000000 --- a/tests/ui/tail-typeck.rs +++ /dev/null @@ -1,5 +0,0 @@ -fn f() -> isize { return g(); } //~ ERROR mismatched types - -fn g() -> usize { return 0; } - -fn main() { let y = f(); } diff --git a/tests/ui/tail-typeck.stderr b/tests/ui/tail-typeck.stderr deleted file mode 100644 index 3cfbfa0fb56..00000000000 --- a/tests/ui/tail-typeck.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error[E0308]: mismatched types - --> $DIR/tail-typeck.rs:1:26 - | -LL | fn f() -> isize { return g(); } - | ----- ^^^ expected `isize`, found `usize` - | | - | expected `isize` because of return type - | -help: you can convert a `usize` to an `isize` and panic if the converted value doesn't fit - | -LL | fn f() -> isize { return g().try_into().unwrap(); } - | ++++++++++++++++++++ - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/trailing-comma.rs b/tests/ui/trailing-comma.rs deleted file mode 100644 index 53b76fb6037..00000000000 --- a/tests/ui/trailing-comma.rs +++ /dev/null @@ -1,34 +0,0 @@ -//@ run-pass - -fn f(_: T,) {} - -struct Foo(#[allow(dead_code)] T); - -struct Bar; - -impl Bar { - fn f(_: isize,) {} - fn g(self, _: isize,) {} - fn h(self,) {} -} - -enum Baz { - Qux(#[allow(dead_code)] isize,), -} - -#[allow(unused,)] -pub fn main() { - f::(0,); - let (_, _,) = (1, 1,); - let [_, _,] = [1, 1,]; - let [_, _, .., _,] = [1, 1, 1, 1,]; - let [_, _, _, ..,] = [1, 1, 1, 1,]; - - let x: Foo = Foo::(1); - - Bar::f(0,); - Bar.g(0,); - Bar.h(); - - let x = Baz::Qux(1,); -} diff --git a/tests/ui/trait-method-number-parameters.rs b/tests/ui/trait-method-number-parameters.rs deleted file mode 100644 index 719005d6643..00000000000 --- a/tests/ui/trait-method-number-parameters.rs +++ /dev/null @@ -1,13 +0,0 @@ -trait Foo { - fn foo(&mut self, x: i32, y: i32) -> i32; -} - -impl Foo for i32 { - fn foo( - &mut self, //~ ERROR - x: i32, - ) { - } -} - -fn main() {} diff --git a/tests/ui/trait-method-number-parameters.stderr b/tests/ui/trait-method-number-parameters.stderr deleted file mode 100644 index cf9b4f2ae79..00000000000 --- a/tests/ui/trait-method-number-parameters.stderr +++ /dev/null @@ -1,13 +0,0 @@ -error[E0050]: method `foo` has 2 parameters but the declaration in trait `Foo::foo` has 3 - --> $DIR/trait-method-number-parameters.rs:7:9 - | -LL | fn foo(&mut self, x: i32, y: i32) -> i32; - | ------------------------- trait requires 3 parameters -... -LL | / &mut self, -LL | | x: i32, - | |______________^ expected 3 parameters, found 2 - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0050`. diff --git a/tests/ui/traits/trait-method-signature-mismatch.rs b/tests/ui/traits/trait-method-signature-mismatch.rs new file mode 100644 index 00000000000..719005d6643 --- /dev/null +++ b/tests/ui/traits/trait-method-signature-mismatch.rs @@ -0,0 +1,13 @@ +trait Foo { + fn foo(&mut self, x: i32, y: i32) -> i32; +} + +impl Foo for i32 { + fn foo( + &mut self, //~ ERROR + x: i32, + ) { + } +} + +fn main() {} diff --git a/tests/ui/traits/trait-method-signature-mismatch.stderr b/tests/ui/traits/trait-method-signature-mismatch.stderr new file mode 100644 index 00000000000..cf9b4f2ae79 --- /dev/null +++ b/tests/ui/traits/trait-method-signature-mismatch.stderr @@ -0,0 +1,13 @@ +error[E0050]: method `foo` has 2 parameters but the declaration in trait `Foo::foo` has 3 + --> $DIR/trait-method-number-parameters.rs:7:9 + | +LL | fn foo(&mut self, x: i32, y: i32) -> i32; + | ------------------------- trait requires 3 parameters +... +LL | / &mut self, +LL | | x: i32, + | |______________^ expected 3 parameters, found 2 + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0050`. diff --git a/tests/ui/traits/tryfrominterror-result-comparison.rs b/tests/ui/traits/tryfrominterror-result-comparison.rs new file mode 100644 index 00000000000..66a78b3f842 --- /dev/null +++ b/tests/ui/traits/tryfrominterror-result-comparison.rs @@ -0,0 +1,12 @@ +//@ run-pass + +#![allow(unused_must_use)] + +use std::convert::TryFrom; +use std::num::TryFromIntError; + +fn main() { + let x: u32 = 125; + let y: Result = u8::try_from(x); + y == Ok(125); +} diff --git a/tests/ui/transmute-equal-assoc-types.rs b/tests/ui/transmute-equal-assoc-types.rs deleted file mode 100644 index 526f4ebbffa..00000000000 --- a/tests/ui/transmute-equal-assoc-types.rs +++ /dev/null @@ -1,11 +0,0 @@ -//@ check-pass - -trait Foo { - type Bar; -} - -unsafe fn noop(foo: F::Bar) -> F::Bar { - ::std::mem::transmute(foo) -} - -fn main() {} diff --git a/tests/ui/transmute-non-immediate-to-immediate.rs b/tests/ui/transmute-non-immediate-to-immediate.rs deleted file mode 100644 index d99bbcc600f..00000000000 --- a/tests/ui/transmute-non-immediate-to-immediate.rs +++ /dev/null @@ -1,10 +0,0 @@ -//@ run-pass -// Issue #7988 -// Transmuting non-immediate type to immediate type - - -pub fn main() { - unsafe { - ::std::mem::transmute::<[isize; 1],isize>([1]) - }; -} diff --git a/tests/ui/transmute/transmute-array-to-scalar.rs b/tests/ui/transmute/transmute-array-to-scalar.rs new file mode 100644 index 00000000000..d99bbcc600f --- /dev/null +++ b/tests/ui/transmute/transmute-array-to-scalar.rs @@ -0,0 +1,10 @@ +//@ run-pass +// Issue #7988 +// Transmuting non-immediate type to immediate type + + +pub fn main() { + unsafe { + ::std::mem::transmute::<[isize; 1],isize>([1]) + }; +} diff --git a/tests/ui/transmute/transmute-same-associated-type.rs b/tests/ui/transmute/transmute-same-associated-type.rs new file mode 100644 index 00000000000..526f4ebbffa --- /dev/null +++ b/tests/ui/transmute/transmute-same-associated-type.rs @@ -0,0 +1,11 @@ +//@ check-pass + +trait Foo { + type Bar; +} + +unsafe fn noop(foo: F::Bar) -> F::Bar { + ::std::mem::transmute(foo) +} + +fn main() {} diff --git a/tests/ui/trivial_casts-rpass.rs b/tests/ui/trivial_casts-rpass.rs deleted file mode 100644 index 701e2f6166f..00000000000 --- a/tests/ui/trivial_casts-rpass.rs +++ /dev/null @@ -1,62 +0,0 @@ -//@ run-pass -// Test that all coercions can actually be done using casts (modulo the lints). - -#![allow(trivial_casts, trivial_numeric_casts)] - -trait Foo { - fn foo(&self) {} //~ WARN method `foo` is never used -} - -pub struct Bar; - -impl Foo for Bar {} - -pub fn main() { - // Numeric - let _ = 42_i32 as i32; - let _ = 42_u8 as u8; - - // & to * pointers - let x: &u32 = &42; - let _ = x as *const u32; - - let x: &mut u32 = &mut 42; - let _ = x as *mut u32; - - // unsize array - let x: &[u32; 3] = &[42, 43, 44]; - let _ = x as &[u32]; - let _ = x as *const [u32]; - - let x: &mut [u32; 3] = &mut [42, 43, 44]; - let _ = x as &mut [u32]; - let _ = x as *mut [u32]; - - let x: Box<[u32; 3]> = Box::new([42, 43, 44]); - let _ = x as Box<[u32]>; - - // unsize trait - let x: &Bar = &Bar; - let _ = x as &dyn Foo; - let _ = x as *const dyn Foo; - - let x: &mut Bar = &mut Bar; - let _ = x as &mut dyn Foo; - let _ = x as *mut dyn Foo; - - let x: Box = Box::new(Bar); - let _ = x as Box; - - // functions - fn baz(_x: i32) {} - let _ = &baz as &dyn Fn(i32); - let x = |_x: i32| {}; - let _ = &x as &dyn Fn(i32); -} - -// subtyping -pub fn test_subtyping<'a, 'b: 'a>(a: &'a Bar, b: &'b Bar) { - let _ = a as &'a Bar; - let _ = b as &'a Bar; - let _ = b as &'b Bar; -} diff --git a/tests/ui/trivial_casts-rpass.stderr b/tests/ui/trivial_casts-rpass.stderr deleted file mode 100644 index 74698b61ab4..00000000000 --- a/tests/ui/trivial_casts-rpass.stderr +++ /dev/null @@ -1,12 +0,0 @@ -warning: method `foo` is never used - --> $DIR/trivial_casts-rpass.rs:7:8 - | -LL | trait Foo { - | --- method in this trait -LL | fn foo(&self) {} - | ^^^ - | - = note: `#[warn(dead_code)]` on by default - -warning: 1 warning emitted - diff --git a/tests/ui/try-from-int-error-partial-eq.rs b/tests/ui/try-from-int-error-partial-eq.rs deleted file mode 100644 index 66a78b3f842..00000000000 --- a/tests/ui/try-from-int-error-partial-eq.rs +++ /dev/null @@ -1,12 +0,0 @@ -//@ run-pass - -#![allow(unused_must_use)] - -use std::convert::TryFrom; -use std::num::TryFromIntError; - -fn main() { - let x: u32 = 125; - let y: Result = u8::try_from(x); - y == Ok(125); -} diff --git a/tests/ui/typeck/mismatched-types-ref-binding.rs b/tests/ui/typeck/mismatched-types-ref-binding.rs new file mode 100644 index 00000000000..c5bc84de54c --- /dev/null +++ b/tests/ui/typeck/mismatched-types-ref-binding.rs @@ -0,0 +1,4 @@ +fn main() { + let var = 10i32; + let ref string: String = var; //~ ERROR mismatched types [E0308] +} diff --git a/tests/ui/typeck/mismatched-types-ref-binding.stderr b/tests/ui/typeck/mismatched-types-ref-binding.stderr new file mode 100644 index 00000000000..e235c2da1f7 --- /dev/null +++ b/tests/ui/typeck/mismatched-types-ref-binding.stderr @@ -0,0 +1,14 @@ +error[E0308]: mismatched types + --> $DIR/switched-expectations.rs:3:30 + | +LL | let ref string: String = var; + | ^^^ expected `String`, found `i32` + | +help: try using a conversion method + | +LL | let ref string: String = var.to_string(); + | ++++++++++++ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/typeck/tail-return-type-mismatch.rs b/tests/ui/typeck/tail-return-type-mismatch.rs new file mode 100644 index 00000000000..1deb43c9496 --- /dev/null +++ b/tests/ui/typeck/tail-return-type-mismatch.rs @@ -0,0 +1,5 @@ +fn f() -> isize { return g(); } //~ ERROR mismatched types + +fn g() -> usize { return 0; } + +fn main() { let y = f(); } diff --git a/tests/ui/typeck/tail-return-type-mismatch.stderr b/tests/ui/typeck/tail-return-type-mismatch.stderr new file mode 100644 index 00000000000..3cfbfa0fb56 --- /dev/null +++ b/tests/ui/typeck/tail-return-type-mismatch.stderr @@ -0,0 +1,16 @@ +error[E0308]: mismatched types + --> $DIR/tail-typeck.rs:1:26 + | +LL | fn f() -> isize { return g(); } + | ----- ^^^ expected `isize`, found `usize` + | | + | expected `isize` because of return type + | +help: you can convert a `usize` to an `isize` and panic if the converted value doesn't fit + | +LL | fn f() -> isize { return g().try_into().unwrap(); } + | ++++++++++++++++++++ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0308`. -- cgit 1.4.1-3-g733a5