-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #51750 - zackmdavis:superstructure, r=oli-obk
three diagnostics upgrades * reword `...` expression syntax error to not imply that you should use it in patterns either (#51043) and make it a structured suggestion * shorten the top-line message for the trivial-casts lint by tucking the advisory sentence into a help note * structured suggestion for pattern-named-the-same-as-variant warning r? @oli-obk
- Loading branch information
Showing
14 changed files
with
218 additions
and
56 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 @@ | ||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// run-pass | ||
// run-rustfix | ||
|
||
#![allow(non_snake_case)] | ||
#![allow(dead_code)] | ||
#![allow(unused_variables)] | ||
|
||
#[derive(Copy, Clone)] | ||
enum Foo { | ||
Bar, | ||
Baz | ||
} | ||
|
||
impl Foo { | ||
fn foo(&self) { | ||
match self { | ||
& | ||
Foo::Bar if true | ||
//~^ WARN pattern binding `Bar` is named the same as one of the variants of the type `Foo` | ||
=> println!("bar"), | ||
& | ||
Foo::Baz if false | ||
//~^ WARN pattern binding `Baz` is named the same as one of the variants of the type `Foo` | ||
=> println!("baz"), | ||
_ => () | ||
} | ||
} | ||
} | ||
|
||
fn main() {} |
This file contains 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 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 |
---|---|---|
@@ -1,16 +1,12 @@ | ||
warning[E0170]: pattern binding `Bar` is named the same as one of the variants of the type `Foo` | ||
--> $DIR/issue-19100.rs:27:1 | ||
--> $DIR/issue-19100.rs:28:1 | ||
| | ||
LL | Bar if true | ||
| ^^^ | ||
| | ||
= help: if you meant to match on a variant, consider making the path in the pattern qualified: `Foo::Bar` | ||
| ^^^ help: to match on the variant, qualify the path: `Foo::Bar` | ||
|
||
warning[E0170]: pattern binding `Baz` is named the same as one of the variants of the type `Foo` | ||
--> $DIR/issue-19100.rs:31:1 | ||
--> $DIR/issue-19100.rs:32:1 | ||
| | ||
LL | Baz if false | ||
| ^^^ | ||
| | ||
= help: if you meant to match on a variant, consider making the path in the pattern qualified: `Foo::Baz` | ||
| ^^^ help: to match on the variant, qualify the path: `Foo::Baz` | ||
|
This file contains 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
20 changes: 20 additions & 0 deletions
20
src/test/ui/lint/trivial-casts-featuring-type-ascription.rs
This file contains 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,20 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![deny(trivial_casts, trivial_numeric_casts)] | ||
#![feature(type_ascription)] | ||
|
||
fn main() { | ||
let lugubrious = 12i32 as i32; | ||
//~^ ERROR trivial numeric cast | ||
let haunted: &u32 = &99; | ||
let _ = haunted as *const u32; | ||
//~^ ERROR trivial cast | ||
} |
28 changes: 28 additions & 0 deletions
28
src/test/ui/lint/trivial-casts-featuring-type-ascription.stderr
This file contains 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 @@ | ||
error: trivial numeric cast: `i32` as `i32` | ||
--> $DIR/trivial-casts-featuring-type-ascription.rs:15:22 | ||
| | ||
LL | let lugubrious = 12i32 as i32; | ||
| ^^^^^^^^^^^^ | ||
| | ||
note: lint level defined here | ||
--> $DIR/trivial-casts-featuring-type-ascription.rs:11:24 | ||
| | ||
LL | #![deny(trivial_casts, trivial_numeric_casts)] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
= help: cast can be replaced by coercion; this might require type ascription or a temporary variable | ||
|
||
error: trivial cast: `&u32` as `*const u32` | ||
--> $DIR/trivial-casts-featuring-type-ascription.rs:18:13 | ||
| | ||
LL | let _ = haunted as *const u32; | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: lint level defined here | ||
--> $DIR/trivial-casts-featuring-type-ascription.rs:11:9 | ||
| | ||
LL | #![deny(trivial_casts, trivial_numeric_casts)] | ||
| ^^^^^^^^^^^^^ | ||
= help: cast can be replaced by coercion; this might require type ascription or a temporary variable | ||
|
||
error: aborting due to 2 previous errors | ||
|
This file contains 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 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![deny(trivial_casts, trivial_numeric_casts)] | ||
|
||
fn main() { | ||
let lugubrious = 12i32 as i32; | ||
//~^ ERROR trivial numeric cast | ||
let haunted: &u32 = &99; | ||
let _ = haunted as *const u32; | ||
//~^ ERROR trivial cast | ||
} |
This file contains 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 @@ | ||
error: trivial numeric cast: `i32` as `i32` | ||
--> $DIR/trivial-casts.rs:14:22 | ||
| | ||
LL | let lugubrious = 12i32 as i32; | ||
| ^^^^^^^^^^^^ | ||
| | ||
note: lint level defined here | ||
--> $DIR/trivial-casts.rs:11:24 | ||
| | ||
LL | #![deny(trivial_casts, trivial_numeric_casts)] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
= help: cast can be replaced by coercion; this might require a temporary variable | ||
|
||
error: trivial cast: `&u32` as `*const u32` | ||
--> $DIR/trivial-casts.rs:17:13 | ||
| | ||
LL | let _ = haunted as *const u32; | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: lint level defined here | ||
--> $DIR/trivial-casts.rs:11:9 | ||
| | ||
LL | #![deny(trivial_casts, trivial_numeric_casts)] | ||
| ^^^^^^^^^^^^^ | ||
= help: cast can be replaced by coercion; this might require a temporary variable | ||
|
||
error: aborting due to 2 previous errors | ||
|
This file contains 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,14 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
fn main() { | ||
let _redemptive = 1...21; | ||
//~^ ERROR unexpected token | ||
} |
This file contains 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,16 @@ | ||
error: unexpected token: `...` | ||
--> $DIR/dotdotdot-expr.rs:12:24 | ||
| | ||
LL | let _redemptive = 1...21; | ||
| ^^^ | ||
help: use `..` for an exclusive range | ||
| | ||
LL | let _redemptive = 1..21; | ||
| ^^ | ||
help: or `..=` for an inclusive range | ||
| | ||
LL | let _redemptive = 1..=21; | ||
| ^^^ | ||
|
||
error: aborting due to previous error | ||
|