提交 dc9128ff 编写于 作者: S Shotaro Yamada

Fix ICE with `main`'s return type containing lifetimes

上级 c75d5e24
......@@ -212,8 +212,6 @@
use rustc_data_structures::bitvec::BitVector;
use std::iter;
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
pub enum MonoItemCollectionMode {
Eager,
......@@ -1030,13 +1028,15 @@ fn push_extra_entry_roots(&mut self) {
// 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));
......
......@@ -82,7 +82,6 @@
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;
......@@ -553,7 +552,9 @@ fn create_entry_fn<'cx>(cx: &'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.
......@@ -580,8 +581,11 @@ fn create_entry_fn<'cx>(cx: &'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 {
......
// 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()")))
}
// 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")
}
// 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(())
}
// 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(())
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册