Skip to content

Commit 4e2c993

Browse files
committed
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 #39823.
1 parent 306035c commit 4e2c993

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
@@ -615,19 +615,13 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
615615
def_id: DefId)
616616
-> bool {
617617
match tcx.item_type(def_id).sty {
618-
ty::TyFnDef(def_id, _, f) => {
618+
ty::TyFnDef(def_id, _, _) => {
619619
// Some constructors also have type TyFnDef but they are
620620
// always instantiated inline and don't result in a
621621
// translation item. Same for FFI functions.
622622
if let Some(hir_map::NodeForeignItem(_)) = tcx.hir.get_if_local(def_id) {
623623
return false;
624624
}
625-
626-
if let Some(adt_def) = f.sig.output().skip_binder().ty_adt_def() {
627-
if adt_def.variants.iter().any(|v| def_id == v.did) {
628-
return false;
629-
}
630-
}
631625
}
632626
ty::TyClosure(..) => {}
633627
_ => return false
@@ -689,6 +683,16 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
689683
fn should_trans_locally<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
690684
def_id: DefId)
691685
-> bool {
686+
if let ty::TyFnDef(_, _, f) = tcx.item_type(def_id).sty {
687+
if let Some(adt_def) = f.sig.output().skip_binder().ty_adt_def() {
688+
if adt_def.variants.iter().any(|v| def_id == v.did) {
689+
// HACK: ADT constructors are translated in-place and
690+
// do not have a trans-item.
691+
return false;
692+
}
693+
}
694+
}
695+
692696
if def_id.is_local() {
693697
true
694698
} 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)