Skip to content

Commit 56b1ec0

Browse files
committed
Fix ICE related to #53708
1 parent 6e723c2 commit 56b1ec0

File tree

7 files changed

+47
-26
lines changed

7 files changed

+47
-26
lines changed

src/librustc/traits/codegen/mod.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55

66
use crate::dep_graph::{DepKind, DepTrackingMapConfig};
77
use std::marker::PhantomData;
8-
use syntax_pos::DUMMY_SP;
98
use crate::infer::InferCtxt;
10-
use syntax_pos::Span;
119
use crate::traits::{FulfillmentContext, Obligation, ObligationCause, SelectionContext,
1210
TraitEngine, Vtable};
1311
use crate::ty::{self, Ty, TyCtxt};
@@ -69,7 +67,7 @@ pub fn codegen_fulfill_obligation<'a, 'tcx>(ty: TyCtxt<'a, 'tcx, 'tcx>,
6967
debug!("fulfill_obligation: register_predicate_obligation {:?}", predicate);
7068
fulfill_cx.register_predicate_obligation(&infcx, predicate);
7169
});
72-
let vtable = infcx.drain_fulfillment_cx_or_panic(DUMMY_SP, &mut fulfill_cx, &vtable);
70+
let vtable = infcx.drain_fulfillment_cx_or_panic(&mut fulfill_cx, &vtable);
7371

7472
info!("Cache miss: {:?} => {:?}", trait_ref, vtable);
7573
vtable
@@ -141,7 +139,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
141139
/// unified, and hence we need to process those obligations to get
142140
/// the complete picture of the type.
143141
fn drain_fulfillment_cx_or_panic<T>(&self,
144-
span: Span,
145142
fulfill_cx: &mut FulfillmentContext<'tcx>,
146143
result: &T)
147144
-> T::Lifted
@@ -153,15 +150,14 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
153150
// contains unbound type parameters. It could be a slight
154151
// optimization to stop iterating early.
155152
if let Err(errors) = fulfill_cx.select_all_or_error(self) {
156-
span_bug!(span, "Encountered errors `{:?}` resolving bounds after type-checking",
157-
errors);
153+
bug!("Encountered errors `{:?}` resolving bounds after type-checking", errors);
158154
}
159155

160156
let result = self.resolve_type_vars_if_possible(result);
161157
let result = self.tcx.erase_regions(&result);
162158

163159
self.tcx.lift_to_global(&result).unwrap_or_else(||
164-
span_bug!(span, "Uninferred types/regions in `{:?}`", result)
160+
bug!("Uninferred types/regions in `{:?}`", result)
165161
)
166162
}
167163
}

src/librustc/ty/sty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl BoundRegion {
8585
/// N.B., if you change this, you'll probably want to change the corresponding
8686
/// AST structure in `libsyntax/ast.rs` as well.
8787
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash,
88-
RustcEncodable, RustcDecodable, HashStable)]
88+
RustcEncodable, RustcDecodable, HashStable, Debug)]
8989
pub enum TyKind<'tcx> {
9090
/// The primitive boolean type. Written as `bool`.
9191
Bool,

src/librustc_mir/hair/pattern/_match.rs

+2
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ impl<'a, 'tcx> LiteralExpander<'a, 'tcx> {
211211
// the constant's pointee type
212212
crty: Ty<'tcx>,
213213
) -> ConstValue<'tcx> {
214+
debug!("fold_const_value_deref {:?} {:?} {:?}", val, rty, crty);
214215
match (val, &crty.sty, &rty.sty) {
215216
// the easy case, deref a reference
216217
(ConstValue::Scalar(Scalar::Ptr(p)), x, y) if x == y => ConstValue::ByRef(
@@ -238,6 +239,7 @@ impl<'a, 'tcx> LiteralExpander<'a, 'tcx> {
238239

239240
impl<'a, 'tcx> PatternFolder<'tcx> for LiteralExpander<'a, 'tcx> {
240241
fn fold_pattern(&mut self, pat: &Pattern<'tcx>) -> Pattern<'tcx> {
242+
debug!("fold_pattern {:?} {:?} {:?}", pat, pat.ty.sty, pat.kind);
241243
match (&pat.ty.sty, &*pat.kind) {
242244
(
243245
&ty::Ref(_, rty, _),

src/librustc_mir/hair/pattern/mod.rs

+19-4
Original file line numberDiff line numberDiff line change
@@ -974,10 +974,25 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
974974
PatternKind::Wild
975975
}
976976
ty::Adt(adt_def, _) if !self.tcx.has_attr(adt_def.did, "structural_match") => {
977-
let msg = format!("to use a constant of type `{}` in a pattern, \
978-
`{}` must be annotated with `#[derive(PartialEq, Eq)]`",
979-
self.tcx.def_path_str(adt_def.did),
980-
self.tcx.def_path_str(adt_def.did));
977+
let path = self.tcx.def_path_str(adt_def.did);
978+
let msg = format!(
979+
"to use a constant of type `{}` in a pattern, \
980+
`{}` must be annotated with `#[derive(PartialEq, Eq)]`",
981+
path,
982+
path,
983+
);
984+
self.tcx.sess.span_err(span, &msg);
985+
PatternKind::Wild
986+
}
987+
ty::Ref(_, ty::TyS { sty: ty::Adt(adt_def, _), .. }, _)
988+
if !self.tcx.has_attr(adt_def.did, "structural_match") => {
989+
let path = self.tcx.def_path_str(adt_def.did);
990+
let msg = format!(
991+
"to use a constant of type `{}` in a pattern, \
992+
`{}` must be annotated with `#[derive(PartialEq, Eq)]`",
993+
path,
994+
path,
995+
);
981996
self.tcx.sess.span_err(span, &msg);
982997
PatternKind::Wild
983998
}

src/test/ui/consts/match_ice.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@
22

33
struct S;
44

5+
#[derive(PartialEq, Eq)]
6+
struct T;
7+
58
fn main() {
69
const C: &S = &S;
7-
match C { //~ ERROR non-exhaustive
8-
C => {} // this is a common bug around constants and references in patterns
10+
match C {
11+
C => {}
12+
//~^ ERROR to use a constant of type `S` in a pattern, `S` must be annotated with
13+
}
14+
const K: &T = &T;
15+
match K { //~ ERROR non-exhaustive patterns: `&T` not covered
16+
K => {}
917
}
1018
}

src/test/ui/consts/match_ice.stderr

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
error[E0004]: non-exhaustive patterns: `&S` not covered
2-
--> $DIR/match_ice.rs:8:11
1+
error: to use a constant of type `S` in a pattern, `S` must be annotated with `#[derive(PartialEq, Eq)]`
2+
--> $DIR/match_ice.rs:11:9
33
|
4-
LL | match C {
5-
| ^ pattern `&S` not covered
6-
|
7-
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
4+
LL | C => {}
5+
| ^
86

9-
error[E0277]: can't compare `S` with `S`
7+
error[E0004]: non-exhaustive patterns: `&T` not covered
8+
--> $DIR/match_ice.rs:15:11
109
|
11-
= help: the trait `std::cmp::PartialEq` is not implemented for `S`
12-
= note: required because of the requirements on the impl of `std::cmp::PartialEq` for `&S`
10+
LL | match K {
11+
| ^ pattern `&T` not covered
12+
|
13+
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
1314

1415
error: aborting due to 2 previous errors
1516

16-
Some errors occurred: E0004, E0277.
17-
For more information about an error, try `rustc --explain E0004`.
17+
For more information about this error, try `rustc --explain E0004`.

src/test/ui/pattern/const-pat-ice.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
thread 'rustc' panicked at 'assertion failed: rows.iter().all(|r| r.len() == v.len())', src/librustc_mir/hair/pattern/_match.rs:1069:5
1+
thread 'rustc' panicked at 'assertion failed: rows.iter().all(|r| r.len() == v.len())', src/librustc_mir/hair/pattern/_match.rs:1071:5
22
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
33

44
error: internal compiler error: unexpected panic

0 commit comments

Comments
 (0)