Skip to content

Commit f3e1d57

Browse files
committed
Allow repr attribute on single variant enum.
1 parent a581c82 commit f3e1d57

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/librustc_trans/adt.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,8 @@ fn represent_type_uncached<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
306306
cx.tcx().item_path_str(def.did));
307307
}
308308

309-
if cases.len() == 1 {
309+
if cases.len() == 1 && hint == attr::ReprAny {
310310
// Equivalent to a struct/tuple/newtype.
311-
// (Typechecking will reject discriminant-sizing attrs.)
312-
assert_eq!(hint, attr::ReprAny);
313311
let mut ftys = cases[0].tys.clone();
314312
if dtor { ftys.push(cx.tcx().dtor_type()); }
315313
return Univariant(mk_struct(cx, &ftys[..], false, t),

src/test/run-pass/issue-33202.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2016 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+
#[repr(C)]
12+
pub enum CPOption<T> {
13+
PSome(T),
14+
}
15+
16+
fn main() {
17+
println!("sizeof CPOption<i32> {}", std::mem::size_of::<CPOption<i32>>());
18+
}

0 commit comments

Comments
 (0)