Skip to content

Commit e981311

Browse files
committed
eval_const_expr_partial now returns ConstVal::Struct instead of None for unit-struct path expressions. Fixes #27008
1 parent 7911d99 commit e981311

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/librustc/middle/const_eval.rs

+3
Original file line numberDiff line numberDiff line change
@@ -967,6 +967,9 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
967967
Some(def::DefVariant(enum_def, variant_def, _)) => {
968968
(lookup_variant_by_id(tcx, enum_def, variant_def), None)
969969
}
970+
Some(def::DefStruct(_)) => {
971+
return Ok(ConstVal::Struct(e.id))
972+
}
970973
_ => (None, None)
971974
};
972975
let const_expr = match const_expr {

src/test/compile-fail/issue-27008.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2015 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+
struct S;
12+
13+
fn main() {
14+
let b = [0; S];
15+
//~^ ERROR mismatched types
16+
//~| expected `usize`
17+
//~| found `S`
18+
//~| expected usize
19+
//~| found struct `S`
20+
//~| ERROR expected positive integer for repeat count, found struct
21+
}

0 commit comments

Comments
 (0)