Skip to content

Commit 5218c2d

Browse files
Properly handle collecting default impls of methods with lifetime parameters.
1 parent b41f227 commit 5218c2d

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

Diff for: src/librustc_mir/monomorphize/collector.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,6 @@ fn create_mono_items_for_default_impls<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
10681068
def_id_to_string(tcx, impl_def_id));
10691069

10701070
if let Some(trait_ref) = tcx.impl_trait_ref(impl_def_id) {
1071-
let callee_substs = tcx.erase_regions(&trait_ref.substs);
10721071
let overridden_methods: FxHashSet<_> =
10731072
impl_item_refs.iter()
10741073
.map(|iiref| iiref.name)
@@ -1082,10 +1081,15 @@ fn create_mono_items_for_default_impls<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
10821081
continue;
10831082
}
10841083

1084+
let substs = Substs::for_item(tcx,
1085+
method.def_id,
1086+
|_, _| tcx.types.re_erased,
1087+
|def, _| trait_ref.substs.type_for_def(def));
1088+
10851089
let instance = ty::Instance::resolve(tcx,
10861090
ty::ParamEnv::reveal_all(),
10871091
method.def_id,
1088-
callee_substs).unwrap();
1092+
substs).unwrap();
10891093

10901094
let mono_item = create_fn_mono_item(instance);
10911095
if mono_item.is_instantiable(tcx)

Diff for: src/test/compile-fail/issue-47309.rs

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
// Make sure that the mono-item collector does not crash when trying to
12+
// instantiate a default impl of a method with lifetime parameters.
13+
// See https://github.com/rust-lang/rust/issues/47309
14+
15+
// compile-flags:-Clink-dead-code
16+
// must-compile-successfully
17+
18+
#![crate_type="rlib"]
19+
20+
pub trait EnvFuture {
21+
type Item;
22+
23+
fn boxed_result<'a>(self) where Self: Sized, Self::Item: 'a, {
24+
}
25+
}
26+
27+
struct Foo;
28+
29+
impl<'a> EnvFuture for &'a Foo {
30+
type Item = ();
31+
}

0 commit comments

Comments
 (0)