diff --git a/src/tools/clippy/tests/ui/large_types_passed_by_value.rs b/src/tools/clippy/tests/ui/large_types_passed_by_value.rs index 562a46306e065..50148ff9b6a70 100644 --- a/src/tools/clippy/tests/ui/large_types_passed_by_value.rs +++ b/src/tools/clippy/tests/ui/large_types_passed_by_value.rs @@ -71,4 +71,14 @@ fn foo(x: LargeAndCopy) { todo!(); } +#[derive(Clone, Copy)] +struct Big([u64; 1024]); + +trait Trait { + fn named(x: Big); + //~^ large_types_passed_by_value + fn unnamed(_: Big); + //~^ large_types_passed_by_value +} + fn main() {} diff --git a/src/tools/clippy/tests/ui/large_types_passed_by_value.stderr b/src/tools/clippy/tests/ui/large_types_passed_by_value.stderr index 0ad68bc326e02..ab0d9cae5b440 100644 --- a/src/tools/clippy/tests/ui/large_types_passed_by_value.stderr +++ b/src/tools/clippy/tests/ui/large_types_passed_by_value.stderr @@ -49,5 +49,17 @@ error: this argument (N byte) is passed by value, but might be more efficient if LL | fn foo(x: LargeAndCopy) { | ^^^^^^^^^^^^ help: consider passing by reference instead: `&LargeAndCopy` -error: aborting due to 8 previous errors +error: this argument (N byte) is passed by value, but might be more efficient if passed by reference (limit: N byte) + --> tests/ui/large_types_passed_by_value.rs:78:17 + | +LL | fn named(x: Big); + | ^^^ help: consider passing by reference instead: `&Big` + +error: this argument (N byte) is passed by value, but might be more efficient if passed by reference (limit: N byte) + --> tests/ui/large_types_passed_by_value.rs:80:19 + | +LL | fn unnamed(_: Big); + | ^^^ help: consider passing by reference instead: `&Big` + +error: aborting due to 10 previous errors diff --git a/src/tools/clippy/tests/ui/shadow.rs b/src/tools/clippy/tests/ui/shadow.rs index 90953cda10107..0235671e67905 100644 --- a/src/tools/clippy/tests/ui/shadow.rs +++ b/src/tools/clippy/tests/ui/shadow.rs @@ -177,4 +177,19 @@ fn issue14377() { S { c, d } = S { c: 1, d: 2 }; } +fn plain_same(x: u8) { let x = x; } +//~^ shadow_same +fn tuple_same((x,): (u8,)) { let x = x; } +//~^ shadow_same + +fn plain_reuse(x: u8) { let x = x + 1; } +//~^ shadow_reuse +fn tuple_reuse((x,): (u8,)) { let x = x + 1; } +//~^ shadow_reuse + +fn plain_unrelated(x: u8) { let x = 1u8; } +//~^ shadow_unrelated +fn tuple_unrelated((x,): (u8,)) { let x = 1u8; } +//~^ shadow_unrelated + fn main() {} diff --git a/src/tools/clippy/tests/ui/shadow.stderr b/src/tools/clippy/tests/ui/shadow.stderr index c356e4a130d06..ef94faa1a30aa 100644 --- a/src/tools/clippy/tests/ui/shadow.stderr +++ b/src/tools/clippy/tests/ui/shadow.stderr @@ -316,5 +316,77 @@ note: previous binding is here LL | fn issue13795(value: Issue13795) { | ^^^^^ -error: aborting due to 26 previous errors +error: `x` is shadowed by itself in `x` + --> tests/ui/shadow.rs:180:28 + | +LL | fn plain_same(x: u8) { let x = x; } + | ^ + | +note: previous binding is here + --> tests/ui/shadow.rs:180:15 + | +LL | fn plain_same(x: u8) { let x = x; } + | ^ + +error: `x` is shadowed by itself in `x` + --> tests/ui/shadow.rs:182:34 + | +LL | fn tuple_same((x,): (u8,)) { let x = x; } + | ^ + | +note: previous binding is here + --> tests/ui/shadow.rs:182:16 + | +LL | fn tuple_same((x,): (u8,)) { let x = x; } + | ^ + +error: `x` is shadowed + --> tests/ui/shadow.rs:185:29 + | +LL | fn plain_reuse(x: u8) { let x = x + 1; } + | ^ + | +note: previous binding is here + --> tests/ui/shadow.rs:185:16 + | +LL | fn plain_reuse(x: u8) { let x = x + 1; } + | ^ + +error: `x` is shadowed + --> tests/ui/shadow.rs:187:35 + | +LL | fn tuple_reuse((x,): (u8,)) { let x = x + 1; } + | ^ + | +note: previous binding is here + --> tests/ui/shadow.rs:187:17 + | +LL | fn tuple_reuse((x,): (u8,)) { let x = x + 1; } + | ^ + +error: `x` shadows a previous, unrelated binding + --> tests/ui/shadow.rs:190:33 + | +LL | fn plain_unrelated(x: u8) { let x = 1u8; } + | ^ + | +note: previous binding is here + --> tests/ui/shadow.rs:190:20 + | +LL | fn plain_unrelated(x: u8) { let x = 1u8; } + | ^ + +error: `x` shadows a previous, unrelated binding + --> tests/ui/shadow.rs:192:39 + | +LL | fn tuple_unrelated((x,): (u8,)) { let x = 1u8; } + | ^ + | +note: previous binding is here + --> tests/ui/shadow.rs:192:21 + | +LL | fn tuple_unrelated((x,): (u8,)) { let x = 1u8; } + | ^ + +error: aborting due to 32 previous errors diff --git a/tests/ui/borrowck/const-cannot-move-shared-ref.rs b/tests/ui/borrowck/const-cannot-move-shared-ref.rs new file mode 100644 index 0000000000000..96a38a0e9f00e --- /dev/null +++ b/tests/ui/borrowck/const-cannot-move-shared-ref.rs @@ -0,0 +1,10 @@ +// Checks whether borrow checking visits constants correctly + +struct NonCopy(u8); + +const C: () = { + let &moved = &NonCopy(0); + //~^ ERROR cannot move out of a shared reference +}; + +fn main() { } diff --git a/tests/ui/borrowck/const-cannot-move-shared-ref.stderr b/tests/ui/borrowck/const-cannot-move-shared-ref.stderr new file mode 100644 index 0000000000000..2daac49319ab3 --- /dev/null +++ b/tests/ui/borrowck/const-cannot-move-shared-ref.stderr @@ -0,0 +1,17 @@ +error[E0507]: cannot move out of a shared reference + --> $DIR/const-cannot-move-shared-ref.rs:6:18 + | +LL | let &moved = &NonCopy(0); + | ----- ^^^^^^^^^^^ + | | + | data moved here because `moved` has type `NonCopy`, which does not implement the `Copy` trait + | +help: consider removing the borrow + | +LL - let &moved = &NonCopy(0); +LL + let moved = &NonCopy(0); + | + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0507`. diff --git a/tests/ui/c-variadic/obligation-span.rs b/tests/ui/c-variadic/obligation-span.rs new file mode 100644 index 0000000000000..b14d645444fbd --- /dev/null +++ b/tests/ui/c-variadic/obligation-span.rs @@ -0,0 +1,15 @@ +// This test checks that the span of c-variadics is handled correctly when creating obligations + +struct NeedsCopy(T); + +extern "C" { + fn f1(...) -> NeedsCopy; + //~^ ERROR the trait bound `String: Copy` is not satisfied + fn f2(x: i32, ...) -> NeedsCopy; + //~^ ERROR the trait bound `String: Copy` is not satisfied + fn f3(..., x: i32) -> NeedsCopy; + //~^ ERROR `...` must be the last argument of a C-variadic function + //~| ERROR the trait bound `String: Copy` is not satisfied +} + +fn main() { } diff --git a/tests/ui/c-variadic/obligation-span.stderr b/tests/ui/c-variadic/obligation-span.stderr new file mode 100644 index 0000000000000..aaa329d70e3ee --- /dev/null +++ b/tests/ui/c-variadic/obligation-span.stderr @@ -0,0 +1,45 @@ +error: `...` must be the last argument of a C-variadic function + --> $DIR/obligation-span.rs:10:11 + | +LL | fn f3(..., x: i32) -> NeedsCopy; + | ^^^ + +error[E0277]: the trait bound `String: Copy` is not satisfied + --> $DIR/obligation-span.rs:6:19 + | +LL | fn f1(...) -> NeedsCopy; + | ^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String` + | +note: required by a bound in `NeedsCopy` + --> $DIR/obligation-span.rs:3:21 + | +LL | struct NeedsCopy(T); + | ^^^^ required by this bound in `NeedsCopy` + +error[E0277]: the trait bound `String: Copy` is not satisfied + --> $DIR/obligation-span.rs:8:27 + | +LL | fn f2(x: i32, ...) -> NeedsCopy; + | ^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String` + | +note: required by a bound in `NeedsCopy` + --> $DIR/obligation-span.rs:3:21 + | +LL | struct NeedsCopy(T); + | ^^^^ required by this bound in `NeedsCopy` + +error[E0277]: the trait bound `String: Copy` is not satisfied + --> $DIR/obligation-span.rs:10:27 + | +LL | fn f3(..., x: i32) -> NeedsCopy; + | ^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String` + | +note: required by a bound in `NeedsCopy` + --> $DIR/obligation-span.rs:3:21 + | +LL | struct NeedsCopy(T); + | ^^^^ required by this bound in `NeedsCopy` + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/pattern/rfc-3637-guard-patterns/borrow-check.rs b/tests/ui/pattern/rfc-3637-guard-patterns/borrow-check.rs new file mode 100644 index 0000000000000..2a30bcca100c1 --- /dev/null +++ b/tests/ui/pattern/rfc-3637-guard-patterns/borrow-check.rs @@ -0,0 +1,17 @@ +// Check whether the borrow checker runs in guard patterns + +#![feature(guard_patterns)] + +struct NonCopy(u8); + +pub fn probe( + (_ if const { + let x = NonCopy(0); + let y = x; + let z = x; + //~^ ERROR use of moved value: `x` [E0382] + true +}): u8, +) {} + +fn main() {} diff --git a/tests/ui/pattern/rfc-3637-guard-patterns/borrow-check.stderr b/tests/ui/pattern/rfc-3637-guard-patterns/borrow-check.stderr new file mode 100644 index 0000000000000..19a821e465ee5 --- /dev/null +++ b/tests/ui/pattern/rfc-3637-guard-patterns/borrow-check.stderr @@ -0,0 +1,22 @@ +error[E0382]: use of moved value: `x` + --> $DIR/borrow-check.rs:11:13 + | +LL | let x = NonCopy(0); + | - move occurs because `x` has type `NonCopy`, which does not implement the `Copy` trait +LL | let y = x; + | - value moved here +LL | let z = x; + | ^ value used here after move + | +note: if `NonCopy` implemented `Clone`, you could clone the value + --> $DIR/borrow-check.rs:5:1 + | +LL | struct NonCopy(u8); + | ^^^^^^^^^^^^^^ consider implementing `Clone` for this type +... +LL | let y = x; + | - you could clone this value + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0382`. diff --git a/tests/ui/pattern/rfc-3637-guard-patterns/closure.rs b/tests/ui/pattern/rfc-3637-guard-patterns/closure.rs new file mode 100644 index 0000000000000..186842fb860cc --- /dev/null +++ b/tests/ui/pattern/rfc-3637-guard-patterns/closure.rs @@ -0,0 +1,8 @@ +// checks whether closures work in guard patterns + +//@ check-pass +#![feature(guard_patterns)] + +pub fn probe((_ if (|| true)()): u8) {} + +fn main() {} diff --git a/tests/ui/privacy/privacy-in-params.rs b/tests/ui/privacy/privacy-in-params.rs new file mode 100644 index 0000000000000..aa95d3a85baa6 --- /dev/null +++ b/tests/ui/privacy/privacy-in-params.rs @@ -0,0 +1,22 @@ +// Checks whether privacy of fields is checked in parameters + +mod hidden { + pub struct Record { secret: u8 } +} + +fn leak(hidden::Record { secret }: hidden::Record) -> u8 { + //~^ ERROR field `secret` of struct `Record` is private + secret +} + +fn f() -> [u8; { let _ = hidden::Record { secret: 1 }; 0 }] { + //~^ ERROR field `secret` of struct `Record` is private + [] +} + +trait Test { + fn trait_method() -> [u8; { let _ = hidden::Record { secret: 1 }; 0 }]; + //~^ ERROR field `secret` of struct `Record` is private +} + +fn main() {} diff --git a/tests/ui/privacy/privacy-in-params.stderr b/tests/ui/privacy/privacy-in-params.stderr new file mode 100644 index 0000000000000..eec757c1c84b5 --- /dev/null +++ b/tests/ui/privacy/privacy-in-params.stderr @@ -0,0 +1,21 @@ +error[E0451]: field `secret` of struct `Record` is private + --> $DIR/privacy-in-params.rs:7:26 + | +LL | fn leak(hidden::Record { secret }: hidden::Record) -> u8 { + | ^^^^^^ private field + +error[E0451]: field `secret` of struct `Record` is private + --> $DIR/privacy-in-params.rs:12:43 + | +LL | fn f() -> [u8; { let _ = hidden::Record { secret: 1 }; 0 }] { + | ^^^^^^ private field + +error[E0451]: field `secret` of struct `Record` is private + --> $DIR/privacy-in-params.rs:18:58 + | +LL | fn trait_method() -> [u8; { let _ = hidden::Record { secret: 1 }; 0 }]; + | ^^^^^^ private field + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0451`. diff --git a/tests/ui/trait-bounds/wf-check-c-variadics.rs b/tests/ui/trait-bounds/wf-check-c-variadics.rs new file mode 100644 index 0000000000000..463f019f604d8 --- /dev/null +++ b/tests/ui/trait-bounds/wf-check-c-variadics.rs @@ -0,0 +1,12 @@ +// In `hir_wf_check.rs` we try to find the innermost type that is not well formed, +// so we can give the user an accurate span. +// This test checks if this happens correctly for c-variadics. + +struct NeedsCopy(T); + +unsafe extern "C" { + fn f(x: i32, ...) -> Option>; + //~^ ERROR the trait bound `String: Copy` is not satisfied +} + +fn main() {} diff --git a/tests/ui/trait-bounds/wf-check-c-variadics.stderr b/tests/ui/trait-bounds/wf-check-c-variadics.stderr new file mode 100644 index 0000000000000..8aaf40469dc72 --- /dev/null +++ b/tests/ui/trait-bounds/wf-check-c-variadics.stderr @@ -0,0 +1,15 @@ +error[E0277]: the trait bound `String: Copy` is not satisfied + --> $DIR/wf-check-c-variadics.rs:8:33 + | +LL | fn f(x: i32, ...) -> Option>; + | ^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String` + | +note: required by a bound in `NeedsCopy` + --> $DIR/wf-check-c-variadics.rs:5:21 + | +LL | struct NeedsCopy(T); + | ^^^^ required by this bound in `NeedsCopy` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0277`.