Skip to content

Fixed ICEs with pattern matching in const expression #41055

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions src/librustc_mir/transform/qualify_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,8 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
Rvalue::Cast(CastKind::ReifyFnPointer, ..) |
Rvalue::Cast(CastKind::UnsafeFnPointer, ..) |
Rvalue::Cast(CastKind::ClosureFnPointer, ..) |
Rvalue::Cast(CastKind::Unsize, ..) => {}
Rvalue::Cast(CastKind::Unsize, ..) |
Rvalue::Discriminant(..) => {}

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

Rvalue::Discriminant(..) => {
// FIXME discriminant
self.add(Qualif::NOT_CONST);
if self.mode != Mode::Fn {
bug!("implement discriminant const qualify");
}
}

Rvalue::Box(_) => {
self.add(Qualif::NOT_CONST);
if self.mode != Mode::Fn {
Expand Down
9 changes: 6 additions & 3 deletions src/librustc_typeck/check/dropck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,12 @@ pub fn check_safety_of_destructor_if_necessary<'a, 'gcx, 'tcx>(
debug!("check_safety_of_destructor_if_necessary typ: {:?} scope: {:?}",
typ, scope);

let parent_scope = rcx.tcx.region_maps.opt_encl_scope(scope).unwrap_or_else(|| {
span_bug!(span, "no enclosing scope found for scope: {:?}", scope)
});

let parent_scope = match rcx.tcx.region_maps.opt_encl_scope(scope) {
Some(parent_scope) => parent_scope,
// If no enclosing scope, then it must be the root scope which cannot be outlived.
None => return
};

let result = iterate_over_potentially_unsafe_regions_in_type(
&mut DropckContext {
Expand Down
25 changes: 25 additions & 0 deletions src/test/compile-fail/const-match-pattern-arm.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2017 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.

const x: bool = match Some(true) {
Some(value) => true,
//~^ ERROR: constant contains unimplemented expression type [E0019]
_ => false
};

const y: bool = {
match Some(true) {
Some(value) => true,
//~^ ERROR: constant contains unimplemented expression type [E0019]
_ => false
}
};

fn main() {}