Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[beta] ICE fixes for newly stabilized features #49948

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 36 additions & 17 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -780,8 +780,9 @@ impl<'a> LoweringContext<'a> {
_ => None,
}),
|this| {
let itctx = ImplTraitContext::Universal(parent_id);
this.collect_in_band_defs(parent_id, anonymous_lifetime_mode, |this| {
(this.lower_generics(generics), f(this))
(this.lower_generics(generics, itctx), f(this))
})
},
);
Expand Down Expand Up @@ -1043,7 +1044,11 @@ impl<'a> LoweringContext<'a> {
}),
|this| {
hir::TyBareFn(P(hir::BareFnTy {
generic_params: this.lower_generic_params(&f.generic_params, &NodeMap()),
generic_params: this.lower_generic_params(
&f.generic_params,
&NodeMap(),
ImplTraitContext::Disallowed,
),
unsafety: this.lower_unsafety(f.unsafety),
abi: f.abi,
decl: this.lower_fn_decl(&f.decl, None, false),
Expand Down Expand Up @@ -1784,7 +1789,12 @@ impl<'a> LoweringContext<'a> {
}
}

fn lower_ty_param(&mut self, tp: &TyParam, add_bounds: &[TyParamBound]) -> hir::TyParam {
fn lower_ty_param(
&mut self,
tp: &TyParam,
add_bounds: &[TyParamBound],
itctx: ImplTraitContext,
) -> hir::TyParam {
let mut name = self.lower_ident(tp.ident);

// Don't expose `Self` (recovered "keyword used as ident" parse error).
Expand All @@ -1794,7 +1804,6 @@ impl<'a> LoweringContext<'a> {
name = Symbol::gensym("Self");
}

let itctx = ImplTraitContext::Universal(self.resolver.definitions().local_def_id(tp.id));
let mut bounds = self.lower_bounds(&tp.bounds, itctx);
if !add_bounds.is_empty() {
bounds = bounds
Expand Down Expand Up @@ -1878,6 +1887,7 @@ impl<'a> LoweringContext<'a> {
&mut self,
params: &Vec<GenericParam>,
add_bounds: &NodeMap<Vec<TyParamBound>>,
itctx: ImplTraitContext,
) -> hir::HirVec<hir::GenericParam> {
params
.iter()
Expand All @@ -1888,12 +1898,13 @@ impl<'a> LoweringContext<'a> {
GenericParam::Type(ref ty_param) => hir::GenericParam::Type(self.lower_ty_param(
ty_param,
add_bounds.get(&ty_param.id).map_or(&[][..], |x| &x),
itctx,
)),
})
.collect()
}

fn lower_generics(&mut self, g: &Generics) -> hir::Generics {
fn lower_generics(&mut self, g: &Generics, itctx: ImplTraitContext) -> hir::Generics {
// Collect `?Trait` bounds in where clause and move them to parameter definitions.
// FIXME: This could probably be done with less rightward drift. Also looks like two control
// paths where report_error is called are also the only paths that advance to after
Expand Down Expand Up @@ -1946,7 +1957,7 @@ impl<'a> LoweringContext<'a> {
}

hir::Generics {
params: self.lower_generic_params(&g.params, &add_bounds),
params: self.lower_generic_params(&g.params, &add_bounds, itctx),
where_clause: self.lower_where_clause(&g.where_clause),
span: g.span,
}
Expand Down Expand Up @@ -1980,6 +1991,7 @@ impl<'a> LoweringContext<'a> {
bound_generic_params: this.lower_generic_params(
bound_generic_params,
&NodeMap(),
ImplTraitContext::Disallowed,
),
bounded_ty: this.lower_ty(bounded_ty, ImplTraitContext::Disallowed),
bounds: bounds
Expand Down Expand Up @@ -2063,7 +2075,8 @@ impl<'a> LoweringContext<'a> {
p: &PolyTraitRef,
itctx: ImplTraitContext,
) -> hir::PolyTraitRef {
let bound_generic_params = self.lower_generic_params(&p.bound_generic_params, &NodeMap());
let bound_generic_params =
self.lower_generic_params(&p.bound_generic_params, &NodeMap(), itctx);
let trait_ref = self.with_parent_impl_lifetime_defs(
&bound_generic_params
.iter()
Expand Down Expand Up @@ -2218,7 +2231,7 @@ impl<'a> LoweringContext<'a> {
ItemKind::GlobalAsm(ref ga) => hir::ItemGlobalAsm(self.lower_global_asm(ga)),
ItemKind::Ty(ref t, ref generics) => hir::ItemTy(
self.lower_ty(t, ImplTraitContext::Disallowed),
self.lower_generics(generics),
self.lower_generics(generics, ImplTraitContext::Disallowed),
),
ItemKind::Enum(ref enum_definition, ref generics) => hir::ItemEnum(
hir::EnumDef {
Expand All @@ -2228,15 +2241,21 @@ impl<'a> LoweringContext<'a> {
.map(|x| self.lower_variant(x))
.collect(),
},
self.lower_generics(generics),
self.lower_generics(generics, ImplTraitContext::Disallowed),
),
ItemKind::Struct(ref struct_def, ref generics) => {
let struct_def = self.lower_variant_data(struct_def);
hir::ItemStruct(struct_def, self.lower_generics(generics))
hir::ItemStruct(
struct_def,
self.lower_generics(generics, ImplTraitContext::Disallowed),
)
}
ItemKind::Union(ref vdata, ref generics) => {
let vdata = self.lower_variant_data(vdata);
hir::ItemUnion(vdata, self.lower_generics(generics))
hir::ItemUnion(
vdata,
self.lower_generics(generics, ImplTraitContext::Disallowed),
)
}
ItemKind::Impl(
unsafety,
Expand Down Expand Up @@ -2315,13 +2334,13 @@ impl<'a> LoweringContext<'a> {
hir::ItemTrait(
self.lower_is_auto(is_auto),
self.lower_unsafety(unsafety),
self.lower_generics(generics),
self.lower_generics(generics, ImplTraitContext::Disallowed),
bounds,
items,
)
}
ItemKind::TraitAlias(ref generics, ref bounds) => hir::ItemTraitAlias(
self.lower_generics(generics),
self.lower_generics(generics, ImplTraitContext::Disallowed),
self.lower_bounds(bounds, ImplTraitContext::Disallowed),
),
ItemKind::MacroDef(..) | ItemKind::Mac(..) => panic!("Shouldn't still be around"),
Expand Down Expand Up @@ -2456,7 +2475,7 @@ impl<'a> LoweringContext<'a> {

let (generics, node) = match i.node {
TraitItemKind::Const(ref ty, ref default) => (
this.lower_generics(&i.generics),
this.lower_generics(&i.generics, ImplTraitContext::Disallowed),
hir::TraitItemKind::Const(
this.lower_ty(ty, ImplTraitContext::Disallowed),
default
Expand Down Expand Up @@ -2497,7 +2516,7 @@ impl<'a> LoweringContext<'a> {
)
}
TraitItemKind::Type(ref bounds, ref default) => (
this.lower_generics(&i.generics),
this.lower_generics(&i.generics, ImplTraitContext::Disallowed),
hir::TraitItemKind::Type(
this.lower_bounds(bounds, ImplTraitContext::Disallowed),
default
Expand Down Expand Up @@ -2554,7 +2573,7 @@ impl<'a> LoweringContext<'a> {
ImplItemKind::Const(ref ty, ref expr) => {
let body_id = this.lower_body(None, |this| this.lower_expr(expr));
(
this.lower_generics(&i.generics),
this.lower_generics(&i.generics, ImplTraitContext::Disallowed),
hir::ImplItemKind::Const(
this.lower_ty(ty, ImplTraitContext::Disallowed),
body_id,
Expand Down Expand Up @@ -2585,7 +2604,7 @@ impl<'a> LoweringContext<'a> {
)
}
ImplItemKind::Type(ref ty) => (
this.lower_generics(&i.generics),
this.lower_generics(&i.generics, ImplTraitContext::Disallowed),
hir::ImplItemKind::Type(this.lower_ty(ty, ImplTraitContext::Disallowed)),
),
ImplItemKind::Macro(..) => panic!("Shouldn't exist any more"),
Expand Down
8 changes: 6 additions & 2 deletions src/librustc/infer/anon_types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,10 +533,14 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for ReverseMapper<'cx, 'gcx, 'tcx>
match r {
// ignore bound regions that appear in the type (e.g., this
// would ignore `'r` in a type like `for<'r> fn(&'r u32)`.
ty::ReLateBound(..) => return r,
ty::ReLateBound(..) |

// ignore `'static`, as that can appear anywhere
ty::ReStatic => return r,
ty::ReStatic |

// ignore `ReScope`, as that can appear anywhere
// See `src/test/run-pass/issue-49556.rs` for example.
ty::ReScope(..) => return r,

_ => { }
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
self.msg_span_from_early_bound_and_free_regions(region)
},
ty::ReStatic => ("the static lifetime".to_owned(), None),
_ => bug!(),
_ => bug!("{:?}", region),
}
}

Expand Down
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
38 changes: 38 additions & 0 deletions src/test/compile-fail/issue-47715.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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.

trait Foo {}

trait Bar<T> {}

trait Iterable {
type Item;
}

struct Container<T: Iterable<Item = impl Foo>> {
//~^ ERROR `impl Trait` not allowed
field: T
}

enum Enum<T: Iterable<Item = impl Foo>> {
//~^ ERROR `impl Trait` not allowed
A(T),
}

union Union<T: Iterable<Item = impl Foo> + Copy> {
//~^ ERROR `impl Trait` not allowed
x: T,
}

type Type<T: Iterable<Item = impl Foo>> = T;
//~^ ERROR `impl Trait` not allowed

fn main() {
}
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,16 @@
// 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
// failure-status: 1

fn main() -> Result<(), &'static str> {
Err("An error message for you")
}
22 changes: 22 additions & 0 deletions src/test/run-pass/issue-49556.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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 iter<'a>(data: &'a [usize]) -> impl Iterator<Item = usize> + 'a {
data.iter()
.map(
|x| x // fn(&'a usize) -> &'(ReScope) usize
)
.map(
|x| *x // fn(&'(ReScope) usize) -> usize
)
}

fn main() {
}
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(())
}
Loading