Skip to content

Commit b6c9dbd

Browse files
committed
Check lifetime parameters when we do check for supertrait impls. Fixes #14050.
1 parent fa43727 commit b6c9dbd

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

src/librustc/middle/typeck/check/vtable.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,8 @@ pub fn early_resolve_expr(ex: &ast::Expr, fcx: &FnCtxt, is_early: bool) {
733733
pub fn resolve_impl(tcx: &ty::ctxt,
734734
impl_item: &ast::Item,
735735
impl_generics: &ty::Generics,
736-
impl_trait_ref: &ty::TraitRef) {
736+
impl_trait_ref: &ty::TraitRef)
737+
{
737738
let param_env = ty::construct_parameter_environment(
738739
tcx,
739740
None,
@@ -774,6 +775,7 @@ pub fn resolve_impl(tcx: &ty::ctxt,
774775
lookup_vtables_for_param(&vcx, impl_item.span, None,
775776
&param_bounds, t, false);
776777

778+
infcx.resolve_regions_and_report_errors();
777779

778780
let res = impl_res {
779781
trait_vtables: vtbls,
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2014 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 when we test the supertrait we ensure consistent use of
12+
// lifetime parameters. In this case, implementing T2<'a,'b> requires
13+
// an impl of T1<'a>, but we have an impl of T1<'b>.
14+
15+
trait T1<'x> {
16+
fn x(&self) -> &'x int;
17+
}
18+
19+
trait T2<'x, 'y> : T1<'x> {
20+
fn y(&self) -> &'y int;
21+
}
22+
23+
struct S<'a, 'b> {
24+
a: &'a int,
25+
b: &'b int
26+
}
27+
28+
impl<'a,'b> T1<'b> for S<'a, 'b> {
29+
fn x(&self) -> &'b int {
30+
self.b
31+
}
32+
}
33+
34+
impl<'a,'b> T2<'a, 'b> for S<'a, 'b> { //~ ERROR cannot infer an appropriate lifetime
35+
fn y(&self) -> &'b int {
36+
self.b
37+
}
38+
}
39+
40+
pub fn main() {
41+
}

0 commit comments

Comments
 (0)