Skip to content

Commit

Permalink
Fix ICE with main's return type containing lifetimes
Browse files Browse the repository at this point in the history
  • Loading branch information
sinkuu committed Apr 5, 2018
1 parent c75d5e2 commit dc9128f
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/librustc_mir/monomorphize/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,6 @@ use monomorphize::item::{MonoItemExt, DefPathBasedNames, InstantiationMode};

use rustc_data_structures::bitvec::BitVector;

use std::iter;

#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
pub enum MonoItemCollectionMode {
Eager,
Expand Down Expand Up @@ -1030,13 +1028,15 @@ impl<'b, 'a, 'v> RootCollector<'b, 'a, 'v> {
// late-bound regions, since late-bound
// regions must appear in the argument
// listing.
let main_ret_ty = main_ret_ty.no_late_bound_regions().unwrap();
let main_ret_ty = self.tcx.erase_regions(
&main_ret_ty.no_late_bound_regions().unwrap(),
);

let start_instance = Instance::resolve(
self.tcx,
ty::ParamEnv::reveal_all(),
start_def_id,
self.tcx.mk_substs(iter::once(Kind::from(main_ret_ty)))
self.tcx.intern_substs(&[Kind::from(main_ret_ty)])
).unwrap();

self.output.push(create_fn_mono_item(start_instance));
Expand Down
12 changes: 8 additions & 4 deletions src/librustc_trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ use std::str;
use std::sync::Arc;
use std::time::{Instant, Duration};
use std::{i32, usize};
use std::iter;
use std::sync::mpsc;
use syntax_pos::Span;
use syntax_pos::symbol::InternedString;
Expand Down Expand Up @@ -553,7 +552,9 @@ fn maybe_create_entry_wrapper(cx: &CodegenCx) {
// late-bound regions, since late-bound
// regions must appear in the argument
// listing.
let main_ret_ty = main_ret_ty.no_late_bound_regions().unwrap();
let main_ret_ty = cx.tcx.erase_regions(
&main_ret_ty.no_late_bound_regions().unwrap(),
);

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

let (start_fn, args) = if use_start_lang_item {
let start_def_id = cx.tcx.require_lang_item(StartFnLangItem);
let start_fn = callee::resolve_and_get_fn(cx, start_def_id, cx.tcx.mk_substs(
iter::once(Kind::from(main_ret_ty))));
let start_fn = callee::resolve_and_get_fn(
cx,
start_def_id,
cx.tcx.intern_substs(&[Kind::from(main_ret_ty)]),
);
(start_fn, vec![bx.pointercast(rust_main, Type::i8p(cx).ptr_to()),
arg_argc, arg_argv])
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// must-compile-successfully
// failure-status: 1

#![feature(dyn_trait)]

use std::error::Error;
use std::io;

fn main() -> Result<(), Box<dyn Error>> {
Err(Box::new(io::Error::new(io::ErrorKind::Other, "returned Box<dyn Error> from main()")))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// error-pattern: An error message for you

fn main() -> Result<(), &'static str> {
Err("An error message for you")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(dyn_trait)]

use std::error::Error;

fn main() -> Result<(), Box<dyn Error>> {
Ok(())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

fn main() -> Result<(), &'static str> {
Ok(())
}

0 comments on commit dc9128f

Please sign in to comment.