Skip to content

Commit eccc251

Browse files
authored
Rollup merge of rust-lang#44549 - gaurikholkar:master, r=arielb1
extend E0623 for earlybound and latebound for structs This fixes rust-lang#44508 r? @nikomatsakis
2 parents 6501701 + 5229443 commit eccc251

6 files changed

+97
-20
lines changed

fn.rs

-8
This file was deleted.

src/librustc/infer/error_reporting/different_lifetimes.rs

+37-12
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for FindNestedTypeVisitor<'a, 'gcx, 'tcx> {
287287
found_it: false,
288288
bound_region: self.bound_region,
289289
hir_map: self.hir_map,
290+
depth: self.depth,
290291
};
291292
intravisit::walk_ty(subvisitor, arg); // call walk_ty; as visit_ty is empty,
292293
// this will visit only outermost type
@@ -313,6 +314,7 @@ struct TyPathVisitor<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
313314
hir_map: &'a hir::map::Map<'gcx>,
314315
found_it: bool,
315316
bound_region: ty::BoundRegion,
317+
depth: u32,
316318
}
317319

318320
impl<'a, 'gcx, 'tcx> Visitor<'gcx> for TyPathVisitor<'a, 'gcx, 'tcx> {
@@ -321,24 +323,47 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for TyPathVisitor<'a, 'gcx, 'tcx> {
321323
}
322324

323325
fn visit_lifetime(&mut self, lifetime: &hir::Lifetime) {
324-
let br_index = match self.bound_region {
325-
ty::BrAnon(index) => index,
326-
_ => return,
327-
};
328326

329327
let hir_id = self.infcx.tcx.hir.node_to_hir_id(lifetime.id);
330-
match self.infcx.tcx.named_region(hir_id) {
328+
match (self.infcx.tcx.named_region(hir_id), self.bound_region) {
331329
// the lifetime of the TyPath!
332-
Some(rl::Region::LateBoundAnon(debruijn_index, anon_index)) => {
333-
if debruijn_index.depth == 1 && anon_index == br_index {
330+
(Some(rl::Region::LateBoundAnon(debruijn_index, anon_index)), ty::BrAnon(br_index)) => {
331+
if debruijn_index.depth == self.depth && anon_index == br_index {
332+
self.found_it = true;
333+
return;
334+
}
335+
}
336+
337+
(Some(rl::Region::EarlyBound(_, id)), ty::BrNamed(def_id, _)) => {
338+
debug!("EarlyBound self.infcx.tcx.hir.local_def_id(id)={:?} \
339+
def_id={:?}",
340+
self.infcx.tcx.hir.local_def_id(id),
341+
def_id);
342+
if self.infcx.tcx.hir.local_def_id(id) == def_id {
343+
self.found_it = true;
344+
return; // we can stop visiting now
345+
}
346+
}
347+
348+
(Some(rl::Region::LateBound(debruijn_index, id)), ty::BrNamed(def_id, _)) => {
349+
debug!("FindNestedTypeVisitor::visit_ty: LateBound depth = {:?}",
350+
debruijn_index.depth);
351+
debug!("self.infcx.tcx.hir.local_def_id(id)={:?}",
352+
self.infcx.tcx.hir.local_def_id(id));
353+
debug!("def_id={:?}", def_id);
354+
if debruijn_index.depth == self.depth &&
355+
self.infcx.tcx.hir.local_def_id(id) == def_id {
334356
self.found_it = true;
357+
return; // we can stop visiting now
335358
}
336359
}
337-
Some(rl::Region::Static) |
338-
Some(rl::Region::EarlyBound(_, _)) |
339-
Some(rl::Region::LateBound(_, _)) |
340-
Some(rl::Region::Free(_, _)) |
341-
None => {
360+
361+
(Some(rl::Region::Static), _) |
362+
(Some(rl::Region::EarlyBound(_, _)), _) |
363+
(Some(rl::Region::LateBound(_, _)), _) |
364+
(Some(rl::Region::LateBoundAnon(_, _)), _) |
365+
(Some(rl::Region::Free(_, _)), _) |
366+
(None, _) => {
342367
debug!("no arg found");
343368
}
344369
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2017 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+
struct Ref<'a> {
11+
x: &'a u32,
12+
}
13+
14+
fn foo<'a, 'b>(mut x: Vec<Ref<'a>>, y: Ref<'b>)
15+
where &'a (): Sized,
16+
&'b u32: Sized
17+
{
18+
x.push(y);
19+
}
20+
21+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0623]: lifetime mismatch
2+
--> $DIR/ex3-both-anon-regions-both-are-structs-earlybound-regions.rs:18:12
3+
|
4+
14 | fn foo<'a, 'b>(mut x: Vec<Ref<'a>>, y: Ref<'b>)
5+
| ------- ------- these two types are declared with different lifetimes...
6+
...
7+
18 | x.push(y);
8+
| ^ ...but data from `y` flows into `x` here
9+
10+
error: aborting due to previous error
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2017 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+
struct Ref<'a> {
11+
x: &'a u32,
12+
}
13+
14+
fn foo<'a, 'b>(mut x: Vec<Ref<'a>>, y: Ref<'b>) {
15+
x.push(y);
16+
}
17+
18+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error[E0623]: lifetime mismatch
2+
--> $DIR/ex3-both-anon-regions-both-are-structs-latebound-regions.rs:15:12
3+
|
4+
14 | fn foo<'a, 'b>(mut x: Vec<Ref<'a>>, y: Ref<'b>) {
5+
| ------- ------- these two types are declared with different lifetimes...
6+
15 | x.push(y);
7+
| ^ ...but data from `y` flows into `x` here
8+
9+
error: aborting due to previous error
10+

0 commit comments

Comments
 (0)