Skip to content

Commit 82b4827

Browse files
committed
Correctly identify named early bound regions.
1 parent 76b69a6 commit 82b4827

File tree

5 files changed

+56
-4
lines changed

5 files changed

+56
-4
lines changed

src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
129129
ty::BrNamed(..) => true,
130130
_ => false,
131131
},
132-
ty::ReEarlyBound(_) => true,
132+
ty::ReEarlyBound(ebr) => ebr.has_name(),
133133
_ => false,
134134
}
135135
}

src/librustc/ty/mod.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ use std::{mem, ptr};
5151
use syntax::ast::{self, DUMMY_NODE_ID, Name, Ident, NodeId};
5252
use syntax::attr;
5353
use syntax::ext::hygiene::Mark;
54-
use syntax::symbol::{Symbol, LocalInternedString, InternedString};
54+
use syntax::symbol::{keywords, Symbol, LocalInternedString, InternedString};
5555
use syntax_pos::{DUMMY_SP, Span};
5656

5757
use rustc_data_structures::accumulate_vec::IntoIter as AccIntoIter;
@@ -824,6 +824,12 @@ impl ty::EarlyBoundRegion {
824824
pub fn to_bound_region(&self) -> ty::BoundRegion {
825825
ty::BoundRegion::BrNamed(self.def_id, self.name)
826826
}
827+
828+
/// Does this early bound region have a name? Early bound regions normally
829+
/// always have names except when using anonymous lifetimes (`'_`).
830+
pub fn has_name(&self) -> bool {
831+
self.name != keywords::UnderscoreLifetime.name().as_interned_str()
832+
}
827833
}
828834

829835
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]

src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,12 @@ impl<'tcx> RegionInferenceContext<'tcx> {
9595
debug!("give_region_a_name: error_region = {:?}", error_region);
9696
match error_region {
9797
ty::ReEarlyBound(ebr) => {
98-
self.highlight_named_span(tcx, error_region, &ebr.name, diag);
99-
Some(ebr.name)
98+
if ebr.has_name() {
99+
self.highlight_named_span(tcx, error_region, &ebr.name, diag);
100+
Some(ebr.name)
101+
} else {
102+
None
103+
}
100104
},
101105

102106
ty::ReStatic => Some(keywords::StaticLifetime.name().as_interned_str()),

src/test/ui/nll/issue-52742.rs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
#![feature(nll)]
12+
#![feature(in_band_lifetimes)]
13+
14+
struct Foo<'a, 'b> {
15+
x: &'a u32,
16+
y: &'b u32,
17+
}
18+
19+
struct Bar<'b> {
20+
z: &'b u32
21+
}
22+
23+
impl Foo<'_, '_> {
24+
fn take_bar(&mut self, b: Bar<'_>) {
25+
self.y = b.z
26+
//~^ ERROR unsatisfied lifetime constraints
27+
}
28+
}
29+
30+
fn main() { }

src/test/ui/nll/issue-52742.stderr

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error: unsatisfied lifetime constraints
2+
--> $DIR/issue-52742.rs:25:9
3+
|
4+
LL | fn take_bar(&mut self, b: Bar<'_>) {
5+
| --------- -- let's call this `'1`
6+
| |
7+
| lifetime `'2` appears in this type
8+
LL | self.y = b.z
9+
| ^^^^^^^^^^^^ requires that `'1` must outlive `'2`
10+
11+
error: aborting due to previous error
12+

0 commit comments

Comments
 (0)