Skip to content

Commit

Permalink
Auto merge of #36871 - petrochenkov:pdderr, r=nikomatsakis
Browse files Browse the repository at this point in the history
Turn compatibility lint `match_of_unit_variant_via_paren_dotdot` into a hard error

The lint was introduced 10 months ago and made deny-by-default 7 months ago.
In case someone is still using it, #36868 contains a stable replacement.

r? @nikomatsakis
  • Loading branch information
bors committed Oct 11, 2016
2 parents e335620 + b3cb8f6 commit 304d0c8
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 95 deletions.
19 changes: 2 additions & 17 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ use hir;
use hir::map::Definitions;
use hir::map::definitions::DefPathData;
use hir::def_id::{DefIndex, DefId};
use hir::def::{Def, CtorKind, PathResolution};
use hir::def::{Def, PathResolution};
use session::Session;
use lint;

use std::collections::BTreeMap;
use std::iter;
Expand Down Expand Up @@ -857,22 +856,8 @@ impl<'a> LoweringContext<'a> {
}
PatKind::Lit(ref e) => hir::PatKind::Lit(self.lower_expr(e)),
PatKind::TupleStruct(ref path, ref pats, ddpos) => {
match self.resolver.get_resolution(p.id).map(|d| d.base_def) {
Some(def @ Def::StructCtor(_, CtorKind::Const)) |
Some(def @ Def::VariantCtor(_, CtorKind::Const)) => {
// Temporarily lower `UnitVariant(..)` into `UnitVariant`
// for backward compatibility.
let msg = format!("expected tuple struct/variant, found {} `{}`",
def.kind_name(), path);
self.sess.add_lint(
lint::builtin::MATCH_OF_UNIT_VARIANT_VIA_PAREN_DOTDOT,
p.id, p.span, msg
);
hir::PatKind::Path(None, self.lower_path(path))
}
_ => hir::PatKind::TupleStruct(self.lower_path(path),
hir::PatKind::TupleStruct(self.lower_path(path),
pats.iter().map(|x| self.lower_pat(x)).collect(), ddpos)
}
}
PatKind::Path(ref opt_qself, ref path) => {
let opt_qself = opt_qself.as_ref().map(|qself| {
Expand Down
7 changes: 0 additions & 7 deletions src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,6 @@ declare_lint! {
the struct or enum has `#[derive(PartialEq, Eq)]`"
}

declare_lint! {
pub MATCH_OF_UNIT_VARIANT_VIA_PAREN_DOTDOT,
Deny,
"unit struct or enum variant erroneously allowed to match via path::ident(..)"
}

declare_lint! {
pub RAW_POINTER_DERIVE,
Warn,
Expand Down Expand Up @@ -226,7 +220,6 @@ impl LintPass for HardwiredLints {
INVALID_TYPE_PARAM_DEFAULT,
ILLEGAL_FLOATING_POINT_CONSTANT_PATTERN,
ILLEGAL_STRUCT_OR_ENUM_CONSTANT_PATTERN,
MATCH_OF_UNIT_VARIANT_VIA_PAREN_DOTDOT,
CONST_ERR,
RAW_POINTER_DERIVE,
TRANSMUTE_FROM_FN_ITEM_TYPES,
Expand Down
5 changes: 0 additions & 5 deletions src/librustc_lint/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,6 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
id: LintId::of(SUPER_OR_SELF_IN_GLOBAL_PATH),
reference: "PR #32403 <https://github.com/rust-lang/rust/pull/32403>",
},
FutureIncompatibleInfo {
id: LintId::of(MATCH_OF_UNIT_VARIANT_VIA_PAREN_DOTDOT),
reference: "RFC 218 <https://github.com/rust-lang/rfcs/blob/\
master/text/0218-empty-struct-with-braces.md>",
},
FutureIncompatibleInfo {
id: LintId::of(TRANSMUTE_FROM_FN_ITEM_TYPES),
reference: "issue #19925 <https://github.com/rust-lang/rust/issues/19925>",
Expand Down
6 changes: 1 addition & 5 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2412,15 +2412,11 @@ impl<'a> Resolver<'a> {
self.record_def(pat.id, resolution);
}

PatKind::TupleStruct(ref path, ref pats, ddpos) => {
PatKind::TupleStruct(ref path, ..) => {
self.resolve_pattern_path(pat.id, None, path, ValueNS, |def| {
match def {
Def::StructCtor(_, CtorKind::Fn) |
Def::VariantCtor(_, CtorKind::Fn) => true,
// `UnitVariant(..)` is accepted for backward compatibility.
Def::StructCtor(_, CtorKind::Const) |
Def::VariantCtor(_, CtorKind::Const)
if pats.is_empty() && ddpos.is_some() => true,
_ => false,
}
}, "tuple struct/variant");
Expand Down
50 changes: 0 additions & 50 deletions src/test/compile-fail/empty-struct-unit-pat-2.rs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// Can't use unit struct as enum pattern
// Can't use unit struct as tuple struct pattern

// aux-build:empty-struct.rs

Expand All @@ -23,30 +23,39 @@ enum E {
Empty4
}

// remove attribute after warning cycle and promoting warnings to errors
fn main() {
let e2 = Empty2;
let e4 = E::Empty4;
let xe2 = XEmpty2;
let xe4 = XE::XEmpty4;

match e2 {
Empty2() => () //~ ERROR expected tuple struct/variant, found unit struct `Empty2`
}
match xe2 {
XEmpty2() => () //~ ERROR expected tuple struct/variant, found unit struct `XEmpty2`
}
match e2 {
Empty2(..) => () //~ ERROR expected tuple struct/variant, found unit struct `Empty2`
//~^ WARNING hard error
}
match xe2 {
XEmpty2(..) => () //~ ERROR expected tuple struct/variant, found unit struct `XEmpty2`
//~^ WARNING hard error
}

match e4 {
E::Empty4() => () //~ ERROR expected tuple struct/variant, found unit variant `E::Empty4`
}
match xe4 {
XE::XEmpty4() => (),
//~^ ERROR expected tuple struct/variant, found unit variant `XE::XEmpty4`
_ => {},
}
match e4 {
E::Empty4(..) => () //~ ERROR expected tuple struct/variant, found unit variant `E::Empty4`
//~^ WARNING hard error
}
match xe4 {
XE::XEmpty4(..) => (),
//~^ ERROR expected tuple struct/variant, found unit variant `XE::XEmpty4`
//~| WARNING hard error
//~^ ERROR expected tuple struct/variant, found unit variant `XE::XEmpty4`
_ => {},
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![allow(match_of_unit_variant_via_paren_dotdot)]

enum E {
A,
B,
Expand All @@ -18,7 +16,7 @@ enum E {
fn main() {
match None {
None => {}
Some(E::A(..)) => {}
Some(E::B(..)) => {}
Some(E::A(..)) => {} //~ ERROR expected tuple struct/variant, found unit variant `E::A`
Some(E::B(..)) => {} //~ ERROR expected tuple struct/variant, found unit variant `E::B`
}
}

0 comments on commit 304d0c8

Please sign in to comment.