Replace non-shorthand variables with _, not _var

This commit is contained in:
sapir 2020-03-06 10:03:34 +02:00
parent e22e443208
commit a8e3d0b71e
3 changed files with 18 additions and 14 deletions

View File

@ -1556,15 +1556,16 @@ impl<'tcx> Liveness<'_, 'tcx> {
.map(|(_, span)| (span, format!("{}: _", name)))
.collect::<Vec<_>>();
let non_shorthands = non_shorthands
.into_iter()
.map(|(_, span)| (span, format!("_{}", name)))
.collect::<Vec<_>>();
// If we have both shorthand and non-shorthand, prefer the "try ignoring
// the field" message.
// the field" message, and suggest `_` for the non-shorthands. If we only
// have non-shorthand, then prefix with an underscore instead.
if !shorthands.is_empty() {
shorthands.extend(non_shorthands);
shorthands.extend(
non_shorthands
.into_iter()
.map(|(_, span)| (span, "_".to_string()))
.collect::<Vec<_>>(),
);
err.multipart_suggestion(
"try ignoring the field",
@ -1574,7 +1575,10 @@ impl<'tcx> Liveness<'_, 'tcx> {
} else {
err.multipart_suggestion(
"if this is intentional, prefix it with an underscore",
non_shorthands,
non_shorthands
.into_iter()
.map(|(_, span)| (span, format!("_{}", name)))
.collect::<Vec<_>>(),
Applicability::MachineApplicable,
);
}

View File

@ -59,7 +59,7 @@ pub fn inner_with_ref(x: Option<MyEnum>) {
pub fn mixed_no_ref(x: MixedEnum) {
match x {
MixedEnum::A { i: _ } | MixedEnum::B(_i) => {
MixedEnum::A { i: _ } | MixedEnum::B(_) => {
println!("match");
}
}
@ -67,7 +67,7 @@ pub fn mixed_no_ref(x: MixedEnum) {
pub fn mixed_with_ref(x: MixedEnum) {
match x {
MixedEnum::A { i: _ } | MixedEnum::B(_i) => {
MixedEnum::A { i: _ } | MixedEnum::B(_) => {
println!("match");
}
}

View File

@ -56,8 +56,8 @@ LL | MixedEnum::A { i } | MixedEnum::B(i) => {
|
help: try ignoring the field
|
LL | MixedEnum::A { i: _ } | MixedEnum::B(_i) => {
| ^^^^ ^^
LL | MixedEnum::A { i: _ } | MixedEnum::B(_) => {
| ^^^^ ^
error: unused variable: `i`
--> $DIR/issue-67691-unused-field-in-or-pattern.rs:70:24
@ -67,8 +67,8 @@ LL | MixedEnum::A { ref i } | MixedEnum::B(ref i) => {
|
help: try ignoring the field
|
LL | MixedEnum::A { i: _ } | MixedEnum::B(_i) => {
| ^^^^ ^^
LL | MixedEnum::A { i: _ } | MixedEnum::B(_) => {
| ^^^^ ^
error: aborting due to 6 previous errors