Skip to content

Commit e0158e0

Browse files
committed
Auto merge of rust-lang#38249 - arielb1:special-substs, r=nikomatsakis
erase lifetimes when translating specialized substs Projections can generate lifetime variables with equality constraints, that will not be resolved by `resolve_type_vars_if_possible`, so substs need to be lifetime-erased after that. Fixes rust-lang#36848.
2 parents 368e092 + 55180d0 commit e0158e0

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

Diff for: src/librustc/traits/specialize/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ pub fn find_method<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
127127
let substs = substs.rebase_onto(tcx, trait_def_id, impl_data.substs);
128128
let substs = translate_substs(&infcx, impl_data.impl_def_id,
129129
substs, node_item.node);
130+
let substs = infcx.tcx.erase_regions(&substs);
130131
tcx.lift(&substs).unwrap_or_else(|| {
131132
bug!("find_method: translate_substs \
132133
returned {:?} which contains inference types/regions",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2016 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+
#![feature(specialization)]
12+
13+
trait Iterator {
14+
fn next(&self);
15+
}
16+
17+
trait WithAssoc {
18+
type Item;
19+
}
20+
21+
impl<'a> WithAssoc for &'a () {
22+
type Item = &'a u32;
23+
}
24+
25+
struct Cloned<I>(I);
26+
27+
impl<'a, I, T: 'a> Iterator for Cloned<I>
28+
where I: WithAssoc<Item=&'a T>, T: Clone
29+
{
30+
fn next(&self) {}
31+
}
32+
33+
impl<'a, I, T: 'a> Iterator for Cloned<I>
34+
where I: WithAssoc<Item=&'a T>, T: Copy
35+
{
36+
37+
}
38+
39+
fn main() {
40+
Cloned(&()).next();
41+
}

0 commit comments

Comments
 (0)