Skip to content

Commit 3989d9c

Browse files
committed
---
yaml --- r: 160127 b: refs/heads/issue-18208-method-dispatch-3-quick-reject c: 9ba6a6e h: refs/heads/master i: 160125: 0d26178 160123: 55ccdc9 160119: f9d919e 160111: 3904dd5 160095: ddafd2e 160063: 3e5e91f 159999: 13d4cc4 v: v3
1 parent e273082 commit 3989d9c

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2828
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
2929
refs/heads/issue-18208-method-dispatch-2: 9e1eae4fb9b6527315b4441cf8a0f5ca911d1671
3030
refs/heads/automation-fail: 1bf06495443584539b958873e04cc2f864ab10e4
31-
refs/heads/issue-18208-method-dispatch-3-quick-reject: 715129786620b3fce1b8efccb98ddab992287ff0
31+
refs/heads/issue-18208-method-dispatch-3-quick-reject: 9ba6a6e74b8ab986e3f2246926e3aba369dea0e6

branches/issue-18208-method-dispatch-3-quick-reject/src/librustc/middle/typeck/check/method/probe.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,32 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
827827
method.fty.sig.inputs[0].repr(self.tcx()),
828828
substs.repr(self.tcx()));
829829

830+
// It is possible for type parameters or early-bound lifetimes
831+
// to appear in the signature of `self`. The substitutions we
832+
// are given do not include type/lifetime parameters for the
833+
// method yet. So create fresh variables here for those too,
834+
// if there are any.
835+
assert_eq!(substs.types.len(subst::FnSpace), 0);
836+
assert_eq!(substs.regions().len(subst::FnSpace), 0);
837+
let mut substs = substs;
838+
let placeholder;
839+
if
840+
!method.generics.types.is_empty_in(subst::FnSpace) ||
841+
!method.generics.regions.is_empty_in(subst::FnSpace)
842+
{
843+
let method_types =
844+
self.infcx().next_ty_vars(
845+
method.generics.types.len(subst::FnSpace));
846+
847+
let method_regions =
848+
self.infcx().region_vars_for_defs(
849+
self.span,
850+
method.generics.regions.get_slice(subst::FnSpace));
851+
852+
placeholder = (*substs).clone().with_method(method_types, method_regions);
853+
substs = &placeholder;
854+
}
855+
830856
let xform_self_ty = method.fty.sig.inputs[0].subst(self.tcx(), substs);
831857
self.infcx().replace_late_bound_regions_with_fresh_var(method.fty.sig.binder_id,
832858
self.span,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright 2012 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+
// Check that we successfully handle methods where the `self` type has
12+
// an early-bound lifetime. Issue #18208.
13+
14+
#![allow(dead_code)]
15+
16+
struct Cursor<'a>;
17+
18+
trait CursorNavigator {
19+
fn init_cursor<'a, 'b:'a>(&'a self, cursor: &mut Cursor<'b>) -> bool;
20+
}
21+
22+
struct SimpleNavigator;
23+
24+
impl CursorNavigator for SimpleNavigator {
25+
fn init_cursor<'a, 'b: 'a>(&'a self, _cursor: &mut Cursor<'b>) -> bool {
26+
false
27+
}
28+
}
29+
30+
fn main() {
31+
let mut c = Cursor;
32+
let n = SimpleNavigator;
33+
n.init_cursor(&mut c);
34+
}

0 commit comments

Comments
 (0)