Skip to content

Commit e753dfa

Browse files
Ryan Scottryan-scott-dev
Ryan Scott
authored andcommitted
Fixed ICEs with pattern matching in const fn. Fixes #38199, fixes #31577, fixes #29093, and fixes #40012.
1 parent 5309a3e commit e753dfa

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

src/librustc_mir/transform/qualify_consts.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -722,11 +722,9 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
722722
}
723723

724724
Rvalue::Discriminant(..) => {
725-
// FIXME discriminant
725+
// FIXME implement discriminant const qualify
726726
self.add(Qualif::NOT_CONST);
727-
if self.mode != Mode::Fn {
728-
bug!("implement discriminant const qualify");
729-
}
727+
// Discriminants in consts will error elsewhere as an unimplemented expression type
730728
}
731729

732730
Rvalue::Box(_) => {

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)