Skip to content

Commit dc9128f

Browse files
committed
Fix ICE with main's return type containing lifetimes
1 parent c75d5e2 commit dc9128f

File tree

6 files changed

+78
-8
lines changed

6 files changed

+78
-8
lines changed

src/librustc_mir/monomorphize/collector.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,6 @@ use monomorphize::item::{MonoItemExt, DefPathBasedNames, InstantiationMode};
212212

213213
use rustc_data_structures::bitvec::BitVector;
214214

215-
use std::iter;
216-
217215
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
218216
pub enum MonoItemCollectionMode {
219217
Eager,
@@ -1030,13 +1028,15 @@ impl<'b, 'a, 'v> RootCollector<'b, 'a, 'v> {
10301028
// late-bound regions, since late-bound
10311029
// regions must appear in the argument
10321030
// listing.
1033-
let main_ret_ty = main_ret_ty.no_late_bound_regions().unwrap();
1031+
let main_ret_ty = self.tcx.erase_regions(
1032+
&main_ret_ty.no_late_bound_regions().unwrap(),
1033+
);
10341034

10351035
let start_instance = Instance::resolve(
10361036
self.tcx,
10371037
ty::ParamEnv::reveal_all(),
10381038
start_def_id,
1039-
self.tcx.mk_substs(iter::once(Kind::from(main_ret_ty)))
1039+
self.tcx.intern_substs(&[Kind::from(main_ret_ty)])
10401040
).unwrap();
10411041

10421042
self.output.push(create_fn_mono_item(start_instance));

src/librustc_trans/base.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ use std::str;
8282
use std::sync::Arc;
8383
use std::time::{Instant, Duration};
8484
use std::{i32, usize};
85-
use std::iter;
8685
use std::sync::mpsc;
8786
use syntax_pos::Span;
8887
use syntax_pos::symbol::InternedString;
@@ -553,7 +552,9 @@ fn maybe_create_entry_wrapper(cx: &CodegenCx) {
553552
// late-bound regions, since late-bound
554553
// regions must appear in the argument
555554
// listing.
556-
let main_ret_ty = main_ret_ty.no_late_bound_regions().unwrap();
555+
let main_ret_ty = cx.tcx.erase_regions(
556+
&main_ret_ty.no_late_bound_regions().unwrap(),
557+
);
557558

558559
if declare::get_defined_value(cx, "main").is_some() {
559560
// FIXME: We should be smart and show a better diagnostic here.
@@ -580,8 +581,11 @@ fn maybe_create_entry_wrapper(cx: &CodegenCx) {
580581

581582
let (start_fn, args) = if use_start_lang_item {
582583
let start_def_id = cx.tcx.require_lang_item(StartFnLangItem);
583-
let start_fn = callee::resolve_and_get_fn(cx, start_def_id, cx.tcx.mk_substs(
584-
iter::once(Kind::from(main_ret_ty))));
584+
let start_fn = callee::resolve_and_get_fn(
585+
cx,
586+
start_def_id,
587+
cx.tcx.intern_substs(&[Kind::from(main_ret_ty)]),
588+
);
585589
(start_fn, vec![bx.pointercast(rust_main, Type::i8p(cx).ptr_to()),
586590
arg_argc, arg_argv])
587591
} else {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2018 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+
// must-compile-successfully
12+
// failure-status: 1
13+
14+
#![feature(dyn_trait)]
15+
16+
use std::error::Error;
17+
use std::io;
18+
19+
fn main() -> Result<(), Box<dyn Error>> {
20+
Err(Box::new(io::Error::new(io::ErrorKind::Other, "returned Box<dyn Error> from main()")))
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2018 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+
// error-pattern: An error message for you
12+
13+
fn main() -> Result<(), &'static str> {
14+
Err("An error message for you")
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2018 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+
#![feature(dyn_trait)]
12+
13+
use std::error::Error;
14+
15+
fn main() -> Result<(), Box<dyn Error>> {
16+
Ok(())
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2018 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+
fn main() -> Result<(), &'static str> {
12+
Ok(())
13+
}

0 commit comments

Comments
 (0)