]> git.lizzy.rs Git - rust.git/commitdiff
Fix ICE related to #53708
authorEsteban Küber <esteban@kuber.com.ar>
Fri, 19 Apr 2019 21:53:34 +0000 (14:53 -0700)
committerEsteban Küber <esteban@kuber.com.ar>
Mon, 22 Apr 2019 20:11:53 +0000 (13:11 -0700)
src/librustc/traits/codegen/mod.rs
src/librustc/ty/sty.rs
src/librustc_mir/hair/pattern/_match.rs
src/librustc_mir/hair/pattern/mod.rs
src/test/ui/consts/match_ice.rs
src/test/ui/consts/match_ice.stderr
src/test/ui/pattern/const-pat-ice.stderr

index 9b0a3820c859ce2fe7d13d928a91b4e0cae7af41..7e3d6d752ccdcf83c96c0eb750f27e4ebba26eee 100644 (file)
@@ -5,9 +5,7 @@
 
 use crate::dep_graph::{DepKind, DepTrackingMapConfig};
 use std::marker::PhantomData;
-use syntax_pos::DUMMY_SP;
 use crate::infer::InferCtxt;
-use syntax_pos::Span;
 use crate::traits::{FulfillmentContext, Obligation, ObligationCause, SelectionContext,
              TraitEngine, Vtable};
 use crate::ty::{self, Ty, TyCtxt};
@@ -69,7 +67,7 @@ pub fn codegen_fulfill_obligation<'a, 'tcx>(ty: TyCtxt<'a, 'tcx, 'tcx>,
             debug!("fulfill_obligation: register_predicate_obligation {:?}", predicate);
             fulfill_cx.register_predicate_obligation(&infcx, predicate);
         });
-        let vtable = infcx.drain_fulfillment_cx_or_panic(DUMMY_SP, &mut fulfill_cx, &vtable);
+        let vtable = infcx.drain_fulfillment_cx_or_panic(&mut fulfill_cx, &vtable);
 
         info!("Cache miss: {:?} => {:?}", trait_ref, vtable);
         vtable
@@ -141,7 +139,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
     /// unified, and hence we need to process those obligations to get
     /// the complete picture of the type.
     fn drain_fulfillment_cx_or_panic<T>(&self,
-                                        span: Span,
                                         fulfill_cx: &mut FulfillmentContext<'tcx>,
                                         result: &T)
                                         -> T::Lifted
@@ -153,15 +150,14 @@ fn drain_fulfillment_cx_or_panic<T>(&self,
         // contains unbound type parameters. It could be a slight
         // optimization to stop iterating early.
         if let Err(errors) = fulfill_cx.select_all_or_error(self) {
-            span_bug!(span, "Encountered errors `{:?}` resolving bounds after type-checking",
-                      errors);
+            bug!("Encountered errors `{:?}` resolving bounds after type-checking", errors);
         }
 
         let result = self.resolve_type_vars_if_possible(result);
         let result = self.tcx.erase_regions(&result);
 
         self.tcx.lift_to_global(&result).unwrap_or_else(||
-            span_bug!(span, "Uninferred types/regions in `{:?}`", result)
+            bug!("Uninferred types/regions in `{:?}`", result)
         )
     }
 }
index 40612ab931ada33b82a25a2a0dc390b8f386ad61..9a90ccda9140ca9bca1b3e7cea46f4a092124986 100644 (file)
@@ -85,7 +85,7 @@ pub fn assert_bound_var(&self) -> BoundVar {
 /// N.B., if you change this, you'll probably want to change the corresponding
 /// AST structure in `libsyntax/ast.rs` as well.
 #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash,
-         RustcEncodable, RustcDecodable, HashStable)]
+         RustcEncodable, RustcDecodable, HashStable, Debug)]
 pub enum TyKind<'tcx> {
     /// The primitive boolean type. Written as `bool`.
     Bool,
index a9c521f59a96c4aa39dfa96d76cbebe30e375d65..c41a09aecaad6d35fb8ec6d6f27188d1f5c08a8b 100644 (file)
@@ -211,6 +211,7 @@ fn fold_const_value_deref(
         // the constant's pointee type
         crty: Ty<'tcx>,
     ) -> ConstValue<'tcx> {
+        debug!("fold_const_value_deref {:?} {:?} {:?}", val, rty, crty);
         match (val, &crty.sty, &rty.sty) {
             // the easy case, deref a reference
             (ConstValue::Scalar(Scalar::Ptr(p)), x, y) if x == y => ConstValue::ByRef(
@@ -238,6 +239,7 @@ fn fold_const_value_deref(
 
 impl<'a, 'tcx> PatternFolder<'tcx> for LiteralExpander<'a, 'tcx> {
     fn fold_pattern(&mut self, pat: &Pattern<'tcx>) -> Pattern<'tcx> {
+        debug!("fold_pattern {:?} {:?} {:?}", pat, pat.ty.sty, pat.kind);
         match (&pat.ty.sty, &*pat.kind) {
             (
                 &ty::Ref(_, rty, _),
index fc12443c0923a7ccb660ff2778557cf13422c9b9..aff9d7b8eb0dbf14d0be36af47fcdac769330a78 100644 (file)
@@ -974,10 +974,25 @@ fn const_to_pat(
                 PatternKind::Wild
             }
             ty::Adt(adt_def, _) if !self.tcx.has_attr(adt_def.did, "structural_match") => {
-                let msg = format!("to use a constant of type `{}` in a pattern, \
-                                    `{}` must be annotated with `#[derive(PartialEq, Eq)]`",
-                                    self.tcx.def_path_str(adt_def.did),
-                                    self.tcx.def_path_str(adt_def.did));
+                let path = self.tcx.def_path_str(adt_def.did);
+                let msg = format!(
+                    "to use a constant of type `{}` in a pattern, \
+                     `{}` must be annotated with `#[derive(PartialEq, Eq)]`",
+                    path,
+                    path,
+                );
+                self.tcx.sess.span_err(span, &msg);
+                PatternKind::Wild
+            }
+            ty::Ref(_, ty::TyS { sty: ty::Adt(adt_def, _), .. }, _)
+            if !self.tcx.has_attr(adt_def.did, "structural_match") => {
+                let path = self.tcx.def_path_str(adt_def.did);
+                let msg = format!(
+                    "to use a constant of type `{}` in a pattern, \
+                     `{}` must be annotated with `#[derive(PartialEq, Eq)]`",
+                    path,
+                    path,
+                );
                 self.tcx.sess.span_err(span, &msg);
                 PatternKind::Wild
             }
index 53c5782a4c70e53d8b0c3854c8be8476126f0f27..1c13bfceb6cc28c56793b830707baca6ba60d682 100644 (file)
@@ -2,9 +2,17 @@
 
 struct S;
 
+#[derive(PartialEq, Eq)]
+struct T;
+
 fn main() {
     const C: &S = &S;
-    match C { //~ ERROR non-exhaustive
-        C => {} // this is a common bug around constants and references in patterns
+    match C {
+        C => {}
+        //~^ ERROR to use a constant of type `S` in a pattern, `S` must be annotated with
+    }
+    const K: &T = &T;
+    match K { //~ ERROR non-exhaustive patterns: `&T` not covered
+        K => {}
     }
 }
index 64f0503242459ef9acb043b8e1603f34c6eaa757..158581fcb1599c460f70b677ab78f086c17d8ea4 100644 (file)
@@ -1,17 +1,17 @@
-error[E0004]: non-exhaustive patterns: `&S` not covered
-  --> $DIR/match_ice.rs:8:11
+error: to use a constant of type `S` in a pattern, `S` must be annotated with `#[derive(PartialEq, Eq)]`
+  --> $DIR/match_ice.rs:11:9
    |
-LL |     match C {
-   |           ^ pattern `&S` not covered
-   |
-   = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
+LL |         C => {}
+   |         ^
 
-error[E0277]: can't compare `S` with `S`
+error[E0004]: non-exhaustive patterns: `&T` not covered
+  --> $DIR/match_ice.rs:15:11
    |
-   = help: the trait `std::cmp::PartialEq` is not implemented for `S`
-   = note: required because of the requirements on the impl of `std::cmp::PartialEq` for `&S`
+LL |     match K {
+   |           ^ pattern `&T` not covered
+   |
+   = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
 
 error: aborting due to 2 previous errors
 
-Some errors occurred: E0004, E0277.
-For more information about an error, try `rustc --explain E0004`.
+For more information about this error, try `rustc --explain E0004`.
index 03580dfecfb5946f89ed57ec36abad55af89bdd2..261e95229a76e5895022f0a82f524b69bae3658d 100644 (file)
@@ -1,4 +1,4 @@
-thread 'rustc' panicked at 'assertion failed: rows.iter().all(|r| r.len() == v.len())', src/librustc_mir/hair/pattern/_match.rs:1069:5
+thread 'rustc' panicked at 'assertion failed: rows.iter().all(|r| r.len() == v.len())', src/librustc_mir/hair/pattern/_match.rs:1071:5
 note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
 
 error: internal compiler error: unexpected panic