Skip to content

Commit 82dc34a

Browse files
committed
Auto merge of #25652 - arielb1:free-self, r=nikomatsakis
This is needed because `Self` can be substituted to a type with lifetime parameters. Fixes #24308 Fixes #25071 Fixes #25259 Fixes #25279
2 parents d7185dc + 7b1e844 commit 82dc34a

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

src/librustc_typeck/astconv.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1395,7 +1395,11 @@ fn base_def_to_ty<'tcx>(this: &AstConv<'tcx>,
13951395
// Self in impl (we know the concrete type).
13961396
check_path_args(tcx, base_segments, NO_TPS | NO_REGIONS);
13971397
if let Some(&ty) = tcx.ast_ty_to_ty_cache.borrow().get(&self_ty_id) {
1398-
ty
1398+
if let Some(free_substs) = this.get_free_substs() {
1399+
ty.subst(tcx, free_substs)
1400+
} else {
1401+
ty
1402+
}
13991403
} else {
14001404
tcx.sess.span_bug(span, "self type has not been fully resolved")
14011405
}

src/test/run-pass/issue-24308.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2015 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+
pub trait Foo {
12+
fn method1() {}
13+
fn method2();
14+
}
15+
16+
struct Slice<'a, T: 'a>(&'a [T]);
17+
18+
impl<'a, T: 'a> Foo for Slice<'a, T> {
19+
fn method2() {
20+
<Self as Foo>::method1();
21+
}
22+
}
23+
24+
fn main() {
25+
<Slice<()> as Foo>::method2();
26+
}

src/test/run-pass/issue-25279.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2015 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+
struct S<'a>(&'a ());
12+
13+
impl<'a> S<'a> {
14+
fn foo(self) -> &'a () {
15+
<Self>::bar(self)
16+
}
17+
18+
fn bar(self) -> &'a () {
19+
self.0
20+
}
21+
}
22+
23+
fn main() {
24+
S(&()).foo();
25+
}

0 commit comments

Comments
 (0)