]> git.lizzy.rs Git - rust.git/commitdiff
Turn compatibility lint `match_of_unit_variant_via_paren_dotdot` into a hard error
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Wed, 14 Sep 2016 21:51:46 +0000 (00:51 +0300)
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Wed, 5 Oct 2016 09:22:26 +0000 (12:22 +0300)
src/librustc/hir/lowering.rs
src/librustc/lint/builtin.rs
src/librustc_lint/lib.rs
src/librustc_resolve/lib.rs
src/test/compile-fail/empty-struct-unit-pat-1.rs [deleted file]
src/test/compile-fail/empty-struct-unit-pat-2.rs [deleted file]
src/test/compile-fail/empty-struct-unit-pat.rs [new file with mode: 0644]
src/test/compile-fail/issue-pr29383.rs [new file with mode: 0644]
src/test/run-pass/issue-pr29383.rs [deleted file]

index f56a27b9ae04a1213463efe6f4f0c06dae80ce02..bca3ed93812026b062645a37c57658c85e95ed73 100644 (file)
@@ -44,9 +44,8 @@
 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;
@@ -857,22 +856,8 @@ fn lower_pat(&mut self, p: &Pat) -> P<hir::Pat> {
                 }
                 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| {
index d378772e6557029985b0f825d0f0eae5aae17c1e..7fc3f638979ff4a671608a6ba2a66205f265d908 100644 (file)
      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,
@@ -226,7 +220,6 @@ fn get_lints(&self) -> LintArray {
             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,
index bc2979c806f65abb619ddc63cfcb4100ddf8d3d1..47d248fe2f2416ab7e74b415cbf98b17e4aa9bae 100644 (file)
@@ -172,11 +172,6 @@ macro_rules! add_lint_group {
             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>",
index 4f41dfc8b645551e23dab1db11024aba5e27fdc0..b573a78d3b327c5e862b175e3c0bc9c030a8246f 100644 (file)
@@ -2412,15 +2412,11 @@ fn resolve_pattern(&mut self,
                     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");
diff --git a/src/test/compile-fail/empty-struct-unit-pat-1.rs b/src/test/compile-fail/empty-struct-unit-pat-1.rs
deleted file mode 100644 (file)
index 273cb48..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright 2015 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.
-
-// Can't use unit struct as enum pattern
-
-// aux-build:empty-struct.rs
-
-#![feature(relaxed_adts)]
-
-extern crate empty_struct;
-use empty_struct::*;
-
-struct Empty2;
-
-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`
-            //~^ 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`
-            //~^ WARNING hard error
-    }
-    match xe4 {
-        XE::XEmpty4(..) => (),
-            //~^ ERROR expected tuple struct/variant, found unit variant `XE::XEmpty4`
-            //~| WARNING hard error
-        _ => {},
-    }
-}
diff --git a/src/test/compile-fail/empty-struct-unit-pat-2.rs b/src/test/compile-fail/empty-struct-unit-pat-2.rs
deleted file mode 100644 (file)
index 993f10e..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright 2015 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.
-
-// Can't use unit struct as enum pattern
-
-// aux-build:empty-struct.rs
-
-#![feature(relaxed_adts)]
-
-extern crate empty_struct;
-use empty_struct::*;
-
-struct Empty2;
-
-enum E {
-    Empty4
-}
-
-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 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`
-        _ => {},
-    }
-}
diff --git a/src/test/compile-fail/empty-struct-unit-pat.rs b/src/test/compile-fail/empty-struct-unit-pat.rs
new file mode 100644 (file)
index 0000000..90f6ae5
--- /dev/null
@@ -0,0 +1,61 @@
+// Copyright 2015 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.
+
+// Can't use unit struct as tuple struct pattern
+
+// aux-build:empty-struct.rs
+
+#![feature(relaxed_adts)]
+
+extern crate empty_struct;
+use empty_struct::*;
+
+struct Empty2;
+
+enum E {
+    Empty4
+}
+
+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`
+    }
+    match xe2 {
+        XEmpty2(..) => () //~ ERROR expected tuple struct/variant, found unit struct `XEmpty2`
+    }
+
+    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`
+    }
+    match xe4 {
+        XE::XEmpty4(..) => (),
+        //~^ ERROR expected tuple struct/variant, found unit variant `XE::XEmpty4`
+        _ => {},
+    }
+}
diff --git a/src/test/compile-fail/issue-pr29383.rs b/src/test/compile-fail/issue-pr29383.rs
new file mode 100644 (file)
index 0000000..b60c537
--- /dev/null
@@ -0,0 +1,22 @@
+// Copyright 2015 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.
+
+enum E {
+    A,
+    B,
+}
+
+fn main() {
+    match None {
+        None => {}
+        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`
+    }
+}
diff --git a/src/test/run-pass/issue-pr29383.rs b/src/test/run-pass/issue-pr29383.rs
deleted file mode 100644 (file)
index defb2c1..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright 2015 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.
-
-#![allow(match_of_unit_variant_via_paren_dotdot)]
-
-enum E {
-    A,
-    B,
-}
-
-fn main() {
-    match None {
-        None => {}
-        Some(E::A(..)) => {}
-        Some(E::B(..)) => {}
-    }
-}