Properly handle collecting default impls of methods with lifetime parameters.
This commit is contained in:
parent
b41f2278f4
commit
5218c2d5ef
@ -1068,7 +1068,6 @@ fn create_mono_items_for_default_impls<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
def_id_to_string(tcx, impl_def_id));
|
||||
|
||||
if let Some(trait_ref) = tcx.impl_trait_ref(impl_def_id) {
|
||||
let callee_substs = tcx.erase_regions(&trait_ref.substs);
|
||||
let overridden_methods: FxHashSet<_> =
|
||||
impl_item_refs.iter()
|
||||
.map(|iiref| iiref.name)
|
||||
@ -1082,10 +1081,15 @@ fn create_mono_items_for_default_impls<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
continue;
|
||||
}
|
||||
|
||||
let substs = Substs::for_item(tcx,
|
||||
method.def_id,
|
||||
|_, _| tcx.types.re_erased,
|
||||
|def, _| trait_ref.substs.type_for_def(def));
|
||||
|
||||
let instance = ty::Instance::resolve(tcx,
|
||||
ty::ParamEnv::reveal_all(),
|
||||
method.def_id,
|
||||
callee_substs).unwrap();
|
||||
substs).unwrap();
|
||||
|
||||
let mono_item = create_fn_mono_item(instance);
|
||||
if mono_item.is_instantiable(tcx)
|
||||
|
31
src/test/compile-fail/issue-47309.rs
Normal file
31
src/test/compile-fail/issue-47309.rs
Normal file
@ -0,0 +1,31 @@
|
||||
// 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.
|
||||
|
||||
// Make sure that the mono-item collector does not crash when trying to
|
||||
// instantiate a default impl of a method with lifetime parameters.
|
||||
// See https://github.com/rust-lang/rust/issues/47309
|
||||
|
||||
// compile-flags:-Clink-dead-code
|
||||
// must-compile-successfully
|
||||
|
||||
#![crate_type="rlib"]
|
||||
|
||||
pub trait EnvFuture {
|
||||
type Item;
|
||||
|
||||
fn boxed_result<'a>(self) where Self: Sized, Self::Item: 'a, {
|
||||
}
|
||||
}
|
||||
|
||||
struct Foo;
|
||||
|
||||
impl<'a> EnvFuture for &'a Foo {
|
||||
type Item = ();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user