Skip to content

Commit b3cb8f6

Browse files
committedOct 5, 2016
Turn compatibility lint match_of_unit_variant_via_paren_dotdot into a hard error
1 parent 165a03d commit b3cb8f6

File tree

7 files changed

+21
-95
lines changed

7 files changed

+21
-95
lines changed
 

‎src/librustc/hir/lowering.rs

+2-17
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ use hir;
4444
use hir::map::Definitions;
4545
use hir::map::definitions::DefPathData;
4646
use hir::def_id::{DefIndex, DefId};
47-
use hir::def::{Def, CtorKind, PathResolution};
47+
use hir::def::{Def, PathResolution};
4848
use session::Session;
49-
use lint;
5049

5150
use std::collections::BTreeMap;
5251
use std::iter;
@@ -857,22 +856,8 @@ impl<'a> LoweringContext<'a> {
857856
}
858857
PatKind::Lit(ref e) => hir::PatKind::Lit(self.lower_expr(e)),
859858
PatKind::TupleStruct(ref path, ref pats, ddpos) => {
860-
match self.resolver.get_resolution(p.id).map(|d| d.base_def) {
861-
Some(def @ Def::StructCtor(_, CtorKind::Const)) |
862-
Some(def @ Def::VariantCtor(_, CtorKind::Const)) => {
863-
// Temporarily lower `UnitVariant(..)` into `UnitVariant`
864-
// for backward compatibility.
865-
let msg = format!("expected tuple struct/variant, found {} `{}`",
866-
def.kind_name(), path);
867-
self.sess.add_lint(
868-
lint::builtin::MATCH_OF_UNIT_VARIANT_VIA_PAREN_DOTDOT,
869-
p.id, p.span, msg
870-
);
871-
hir::PatKind::Path(None, self.lower_path(path))
872-
}
873-
_ => hir::PatKind::TupleStruct(self.lower_path(path),
859+
hir::PatKind::TupleStruct(self.lower_path(path),
874860
pats.iter().map(|x| self.lower_pat(x)).collect(), ddpos)
875-
}
876861
}
877862
PatKind::Path(ref opt_qself, ref path) => {
878863
let opt_qself = opt_qself.as_ref().map(|qself| {

‎src/librustc/lint/builtin.rs

-7
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,6 @@ declare_lint! {
143143
the struct or enum has `#[derive(PartialEq, Eq)]`"
144144
}
145145

146-
declare_lint! {
147-
pub MATCH_OF_UNIT_VARIANT_VIA_PAREN_DOTDOT,
148-
Deny,
149-
"unit struct or enum variant erroneously allowed to match via path::ident(..)"
150-
}
151-
152146
declare_lint! {
153147
pub RAW_POINTER_DERIVE,
154148
Warn,
@@ -226,7 +220,6 @@ impl LintPass for HardwiredLints {
226220
INVALID_TYPE_PARAM_DEFAULT,
227221
ILLEGAL_FLOATING_POINT_CONSTANT_PATTERN,
228222
ILLEGAL_STRUCT_OR_ENUM_CONSTANT_PATTERN,
229-
MATCH_OF_UNIT_VARIANT_VIA_PAREN_DOTDOT,
230223
CONST_ERR,
231224
RAW_POINTER_DERIVE,
232225
TRANSMUTE_FROM_FN_ITEM_TYPES,

‎src/librustc_lint/lib.rs

-5
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,6 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
172172
id: LintId::of(SUPER_OR_SELF_IN_GLOBAL_PATH),
173173
reference: "PR #32403 <https://github.com/rust-lang/rust/pull/32403>",
174174
},
175-
FutureIncompatibleInfo {
176-
id: LintId::of(MATCH_OF_UNIT_VARIANT_VIA_PAREN_DOTDOT),
177-
reference: "RFC 218 <https://github.com/rust-lang/rfcs/blob/\
178-
master/text/0218-empty-struct-with-braces.md>",
179-
},
180175
FutureIncompatibleInfo {
181176
id: LintId::of(TRANSMUTE_FROM_FN_ITEM_TYPES),
182177
reference: "issue #19925 <https://github.com/rust-lang/rust/issues/19925>",

‎src/librustc_resolve/lib.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -2412,15 +2412,11 @@ impl<'a> Resolver<'a> {
24122412
self.record_def(pat.id, resolution);
24132413
}
24142414

2415-
PatKind::TupleStruct(ref path, ref pats, ddpos) => {
2415+
PatKind::TupleStruct(ref path, ..) => {
24162416
self.resolve_pattern_path(pat.id, None, path, ValueNS, |def| {
24172417
match def {
24182418
Def::StructCtor(_, CtorKind::Fn) |
24192419
Def::VariantCtor(_, CtorKind::Fn) => true,
2420-
// `UnitVariant(..)` is accepted for backward compatibility.
2421-
Def::StructCtor(_, CtorKind::Const) |
2422-
Def::VariantCtor(_, CtorKind::Const)
2423-
if pats.is_empty() && ddpos.is_some() => true,
24242420
_ => false,
24252421
}
24262422
}, "tuple struct/variant");

‎src/test/compile-fail/empty-struct-unit-pat-2.rs

-50
This file was deleted.

‎src/test/compile-fail/empty-struct-unit-pat-1.rs ‎src/test/compile-fail/empty-struct-unit-pat.rs

+16-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// Can't use unit struct as enum pattern
11+
// Can't use unit struct as tuple struct pattern
1212

1313
// aux-build:empty-struct.rs
1414

@@ -23,30 +23,39 @@ enum E {
2323
Empty4
2424
}
2525

26-
// remove attribute after warning cycle and promoting warnings to errors
2726
fn main() {
2827
let e2 = Empty2;
2928
let e4 = E::Empty4;
3029
let xe2 = XEmpty2;
3130
let xe4 = XE::XEmpty4;
3231

32+
match e2 {
33+
Empty2() => () //~ ERROR expected tuple struct/variant, found unit struct `Empty2`
34+
}
35+
match xe2 {
36+
XEmpty2() => () //~ ERROR expected tuple struct/variant, found unit struct `XEmpty2`
37+
}
3338
match e2 {
3439
Empty2(..) => () //~ ERROR expected tuple struct/variant, found unit struct `Empty2`
35-
//~^ WARNING hard error
3640
}
3741
match xe2 {
3842
XEmpty2(..) => () //~ ERROR expected tuple struct/variant, found unit struct `XEmpty2`
39-
//~^ WARNING hard error
4043
}
4144

45+
match e4 {
46+
E::Empty4() => () //~ ERROR expected tuple struct/variant, found unit variant `E::Empty4`
47+
}
48+
match xe4 {
49+
XE::XEmpty4() => (),
50+
//~^ ERROR expected tuple struct/variant, found unit variant `XE::XEmpty4`
51+
_ => {},
52+
}
4253
match e4 {
4354
E::Empty4(..) => () //~ ERROR expected tuple struct/variant, found unit variant `E::Empty4`
44-
//~^ WARNING hard error
4555
}
4656
match xe4 {
4757
XE::XEmpty4(..) => (),
48-
//~^ ERROR expected tuple struct/variant, found unit variant `XE::XEmpty4`
49-
//~| WARNING hard error
58+
//~^ ERROR expected tuple struct/variant, found unit variant `XE::XEmpty4`
5059
_ => {},
5160
}
5261
}

‎src/test/run-pass/issue-pr29383.rs ‎src/test/compile-fail/issue-pr29383.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![allow(match_of_unit_variant_via_paren_dotdot)]
12-
1311
enum E {
1412
A,
1513
B,
@@ -18,7 +16,7 @@ enum E {
1816
fn main() {
1917
match None {
2018
None => {}
21-
Some(E::A(..)) => {}
22-
Some(E::B(..)) => {}
19+
Some(E::A(..)) => {} //~ ERROR expected tuple struct/variant, found unit variant `E::A`
20+
Some(E::B(..)) => {} //~ ERROR expected tuple struct/variant, found unit variant `E::B`
2321
}
2422
}

0 commit comments

Comments
 (0)
Please sign in to comment.