Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/tools/clippy/tests/ui/large_types_passed_by_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
14 changes: 13 additions & 1 deletion src/tools/clippy/tests/ui/large_types_passed_by_value.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

15 changes: 15 additions & 0 deletions src/tools/clippy/tests/ui/shadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
74 changes: 73 additions & 1 deletion src/tools/clippy/tests/ui/shadow.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

10 changes: 10 additions & 0 deletions tests/ui/borrowck/const-cannot-move-shared-ref.rs
Original file line number Diff line number Diff line change
@@ -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() { }
17 changes: 17 additions & 0 deletions tests/ui/borrowck/const-cannot-move-shared-ref.stderr
Original file line number Diff line number Diff line change
@@ -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`.
15 changes: 15 additions & 0 deletions tests/ui/c-variadic/obligation-span.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// This test checks that the span of c-variadics is handled correctly when creating obligations

struct NeedsCopy<T: Copy>(T);

extern "C" {
fn f1(...) -> NeedsCopy<String>;
//~^ ERROR the trait bound `String: Copy` is not satisfied
fn f2(x: i32, ...) -> NeedsCopy<String>;
//~^ ERROR the trait bound `String: Copy` is not satisfied
fn f3(..., x: i32) -> NeedsCopy<String>;
//~^ ERROR `...` must be the last argument of a C-variadic function
//~| ERROR the trait bound `String: Copy` is not satisfied
}

fn main() { }
45 changes: 45 additions & 0 deletions tests/ui/c-variadic/obligation-span.stderr
Original file line number Diff line number Diff line change
@@ -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<String>;
| ^^^

error[E0277]: the trait bound `String: Copy` is not satisfied
--> $DIR/obligation-span.rs:6:19
|
LL | fn f1(...) -> NeedsCopy<String>;
| ^^^^^^^^^^^^^^^^^ 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: Copy>(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<String>;
| ^^^^^^^^^^^^^^^^^ 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: Copy>(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<String>;
| ^^^^^^^^^^^^^^^^^ 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: Copy>(T);
| ^^^^ required by this bound in `NeedsCopy`

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0277`.
17 changes: 17 additions & 0 deletions tests/ui/pattern/rfc-3637-guard-patterns/borrow-check.rs
Original file line number Diff line number Diff line change
@@ -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() {}
22 changes: 22 additions & 0 deletions tests/ui/pattern/rfc-3637-guard-patterns/borrow-check.stderr
Original file line number Diff line number Diff line change
@@ -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`.
8 changes: 8 additions & 0 deletions tests/ui/pattern/rfc-3637-guard-patterns/closure.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// checks whether closures work in guard patterns

//@ check-pass
#![feature(guard_patterns)]

pub fn probe((_ if (|| true)()): u8) {}

fn main() {}
22 changes: 22 additions & 0 deletions tests/ui/privacy/privacy-in-params.rs
Original file line number Diff line number Diff line change
@@ -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() {}
21 changes: 21 additions & 0 deletions tests/ui/privacy/privacy-in-params.stderr
Original file line number Diff line number Diff line change
@@ -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`.
12 changes: 12 additions & 0 deletions tests/ui/trait-bounds/wf-check-c-variadics.rs
Original file line number Diff line number Diff line change
@@ -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: Copy>(T);

unsafe extern "C" {
fn f(x: i32, ...) -> Option<NeedsCopy<String>>;
//~^ ERROR the trait bound `String: Copy` is not satisfied
}

fn main() {}
15 changes: 15 additions & 0 deletions tests/ui/trait-bounds/wf-check-c-variadics.stderr
Original file line number Diff line number Diff line change
@@ -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<NeedsCopy<String>>;
| ^^^^^^^^^^^^^^^^^ 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: Copy>(T);
| ^^^^ required by this bound in `NeedsCopy`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0277`.
Loading