Skip to content

Commit a610117

Browse files
committed
Auto merge of #41055 - Archytaus:compile-fail/const-match-pattern-arm, r=arielb1
Fixed ICEs with pattern matching in const expression Fixed 2 ICEs with when pattern matching inside a constant expression. Both of these ICEs now resolve to an appropriate compiler error. 1. ICE was caused by a compiler bug to implement discriminant const qualify. I removed this intentionally thrown bug and changed it to a FIXME as the unimplemented expression type is handled as a compiler error elsewhere. 2. ICE was caused during a drop check when checking if a variable lifetime outlives the current scope if there was no parent scope . I've changed it to stop checking if there is no parent scope for the current scope. It is valid syntax for a const variable to be assigned a match expression with no enclosing scope. The ICE seemed to mainly be used as a defensive check for bugs elsewhere. Fixes #38199. Fixes #31577. Fixes #29093. Fixes #40012.
2 parents fe39e94 + c9932b3 commit a610117

File tree

3 files changed

+33
-12
lines changed

3 files changed

+33
-12
lines changed

src/librustc_mir/transform/qualify_consts.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,8 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
603603
Rvalue::Cast(CastKind::ReifyFnPointer, ..) |
604604
Rvalue::Cast(CastKind::UnsafeFnPointer, ..) |
605605
Rvalue::Cast(CastKind::ClosureFnPointer, ..) |
606-
Rvalue::Cast(CastKind::Unsize, ..) => {}
606+
Rvalue::Cast(CastKind::Unsize, ..) |
607+
Rvalue::Discriminant(..) => {}
607608

608609
Rvalue::Len(_) => {
609610
// Static lvalues in consts would have errored already,
@@ -721,14 +722,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
721722
}
722723
}
723724

724-
Rvalue::Discriminant(..) => {
725-
// FIXME discriminant
726-
self.add(Qualif::NOT_CONST);
727-
if self.mode != Mode::Fn {
728-
bug!("implement discriminant const qualify");
729-
}
730-
}
731-
732725
Rvalue::Box(_) => {
733726
self.add(Qualif::NOT_CONST);
734727
if self.mode != Mode::Fn {

src/librustc_typeck/check/dropck.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,12 @@ pub fn check_safety_of_destructor_if_necessary<'a, 'gcx, 'tcx>(
278278
debug!("check_safety_of_destructor_if_necessary typ: {:?} scope: {:?}",
279279
typ, scope);
280280

281-
let parent_scope = rcx.tcx.region_maps.opt_encl_scope(scope).unwrap_or_else(|| {
282-
span_bug!(span, "no enclosing scope found for scope: {:?}", scope)
283-
});
281+
282+
let parent_scope = match rcx.tcx.region_maps.opt_encl_scope(scope) {
283+
Some(parent_scope) => parent_scope,
284+
// If no enclosing scope, then it must be the root scope which cannot be outlived.
285+
None => return
286+
};
284287

285288
let result = iterate_over_potentially_unsafe_regions_in_type(
286289
&mut DropckContext {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
const x: bool = match Some(true) {
12+
Some(value) => true,
13+
//~^ ERROR: constant contains unimplemented expression type [E0019]
14+
_ => false
15+
};
16+
17+
const y: bool = {
18+
match Some(true) {
19+
Some(value) => true,
20+
//~^ ERROR: constant contains unimplemented expression type [E0019]
21+
_ => false
22+
}
23+
};
24+
25+
fn main() {}

0 commit comments

Comments
 (0)