Skip to content

Commit ecae5bf

Browse files
authored
Rollup merge of rust-lang#40064 - arielb1:virtual-enum, r=nikomatsakis
trans: don't ICE when trying to create ADT trans-items ADTs are translated in-place from rustc_trans::callee, so no trans-items are needed. This fix will be superseded by the shimmir branch, but I prefer not to backport that to beta. Fixes rust-lang#39823. Beta-nominating because regression. r? @michaelwoerister
2 parents 393d80d + 4e2c993 commit ecae5bf

File tree

3 files changed

+62
-7
lines changed

3 files changed

+62
-7
lines changed

src/librustc_trans/collector.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -629,19 +629,13 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
629629
def_id: DefId)
630630
-> bool {
631631
match tcx.item_type(def_id).sty {
632-
ty::TyFnDef(def_id, _, f) => {
632+
ty::TyFnDef(def_id, _, _) => {
633633
// Some constructors also have type TyFnDef but they are
634634
// always instantiated inline and don't result in a
635635
// translation item. Same for FFI functions.
636636
if let Some(hir_map::NodeForeignItem(_)) = tcx.hir.get_if_local(def_id) {
637637
return false;
638638
}
639-
640-
if let Some(adt_def) = f.sig.output().skip_binder().ty_adt_def() {
641-
if adt_def.variants.iter().any(|v| def_id == v.did) {
642-
return false;
643-
}
644-
}
645639
}
646640
ty::TyClosure(..) => {}
647641
_ => return false
@@ -703,6 +697,16 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
703697
fn should_trans_locally<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
704698
def_id: DefId)
705699
-> bool {
700+
if let ty::TyFnDef(_, _, f) = tcx.item_type(def_id).sty {
701+
if let Some(adt_def) = f.sig.output().skip_binder().ty_adt_def() {
702+
if adt_def.variants.iter().any(|v| def_id == v.did) {
703+
// HACK: ADT constructors are translated in-place and
704+
// do not have a trans-item.
705+
return false;
706+
}
707+
}
708+
}
709+
706710
if def_id.is_local() {
707711
true
708712
} else {
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
#![crate_type="rlib"]
12+
13+
#[derive(Debug, PartialEq)]
14+
pub struct RemoteC(pub u32);
15+
16+
#[derive(Debug, PartialEq)]
17+
pub struct RemoteG<T>(pub T);

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

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
// aux-build:issue_39823.rs
12+
13+
extern crate issue_39823;
14+
use issue_39823::{RemoteC, RemoteG};
15+
16+
#[derive(Debug, PartialEq)]
17+
struct LocalC(u32);
18+
19+
#[derive(Debug, PartialEq)]
20+
struct LocalG<T>(T);
21+
22+
fn main() {
23+
let virtual_localc : &Fn(_) -> LocalC = &LocalC;
24+
assert_eq!(virtual_localc(1), LocalC(1));
25+
26+
let virtual_localg : &Fn(_) -> LocalG<u32> = &LocalG;
27+
assert_eq!(virtual_localg(1), LocalG(1));
28+
29+
let virtual_remotec : &Fn(_) -> RemoteC = &RemoteC;
30+
assert_eq!(virtual_remotec(1), RemoteC(1));
31+
32+
let virtual_remoteg : &Fn(_) -> RemoteG<u32> = &RemoteG;
33+
assert_eq!(virtual_remoteg(1), RemoteG(1));
34+
}

0 commit comments

Comments
 (0)