Skip to content

Commit 465de33

Browse files
committed
Modify primary span on lifetime error
1 parent 5074501 commit 465de33

File tree

4 files changed

+88
-86
lines changed

4 files changed

+88
-86
lines changed

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
736736
diag.span_suggestion_verbose(span, msg, sugg, Applicability::MachineApplicable);
737737
// This is redundant but needed because we won't enter the section with the
738738
// additional note, so we point at the method call here too.
739+
diag.replace_span_with(*call_span, false);
739740
diag.span_label(
740741
*call_span,
741742
"calling this method introduces a `'static` lifetime requirement",
@@ -756,6 +757,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
756757
predicates.push(tcx.def_span(parent));
757758
}
758759
if !predicates.is_empty() {
760+
diag.replace_span_with(*call_span, false);
759761
diag.span_label(
760762
*call_span,
761763
"calling this method introduces a `'static` lifetime requirement",

compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2057,7 +2057,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
20572057
None
20582058
}
20592059
})
2060-
.unwrap_or_else(|| ObligationCauseCode::MiscObligation);
2060+
.unwrap_or(ObligationCauseCode::MiscObligation);
20612061

20622062
// Classify each of the constraints along the path.
20632063
let mut categorized_path: Vec<BlameConstraint<'tcx>> = path

tests/ui/lifetimes/static-impl-obligation.rs

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ mod a {
55
fn hello(&self) {}
66
}
77
fn bar<'a>(x: &'a &'a u32) {
8-
let y: &dyn Foo = x; //~ ERROR lifetime may not live long enough
9-
y.hello();
8+
let y: &dyn Foo = x;
9+
y.hello(); //~ ERROR lifetime may not live long enough
1010
}
1111
}
1212
mod b {
@@ -16,8 +16,8 @@ mod b {
1616
fn hello(&'static self) {}
1717
}
1818
fn bar<'a>(x: &'a &'a u32) {
19-
let y: &dyn Foo = x; //~ ERROR lifetime may not live long enough
20-
y.hello();
19+
let y: &dyn Foo = x;
20+
y.hello(); //~ ERROR lifetime may not live long enough
2121
}
2222
}
2323
mod c {
@@ -27,8 +27,8 @@ mod c {
2727
fn hello(&'static self) where Self: 'static {}
2828
}
2929
fn bar<'a>(x: &'a &'a u32) {
30-
let y: &dyn Foo = x; //~ ERROR lifetime may not live long enough
31-
y.hello();
30+
let y: &dyn Foo = x;
31+
y.hello(); //~ ERROR lifetime may not live long enough
3232
}
3333
}
3434
mod d {
@@ -38,8 +38,8 @@ mod d {
3838
fn hello(&self) where Self: 'static {}
3939
}
4040
fn bar<'a>(x: &'a &'a u32) {
41-
let y: &dyn Foo = x; //~ ERROR lifetime may not live long enough
42-
y.hello();
41+
let y: &dyn Foo = x;
42+
y.hello(); //~ ERROR lifetime may not live long enough
4343
}
4444
}
4545
mod e {
@@ -49,8 +49,8 @@ mod e {
4949
fn hello(&self) {}
5050
}
5151
fn bar<'a>(x: &'a &'a u32) {
52-
let y: &dyn Foo = x; //~ ERROR lifetime may not live long enough
53-
y.hello();
52+
let y: &dyn Foo = x;
53+
y.hello(); //~ ERROR lifetime may not live long enough
5454
}
5555
}
5656
mod f {
@@ -60,8 +60,8 @@ mod f {
6060
fn hello(&'static self) {}
6161
}
6262
fn bar<'a>(x: &'a &'a u32) {
63-
let y: &dyn Foo = x; //~ ERROR lifetime may not live long enough
64-
y.hello();
63+
let y: &dyn Foo = x;
64+
y.hello(); //~ ERROR lifetime may not live long enough
6565
}
6666
}
6767
mod g {
@@ -71,8 +71,8 @@ mod g {
7171
fn hello(&'static self) where Self: 'static {}
7272
}
7373
fn bar<'a>(x: &'a &'a u32) {
74-
let y: &dyn Foo = x; //~ ERROR lifetime may not live long enough
75-
y.hello();
74+
let y: &dyn Foo = x;
75+
y.hello(); //~ ERROR lifetime may not live long enough
7676
}
7777
}
7878
mod h {
@@ -82,8 +82,8 @@ mod h {
8282
fn hello(&self) where Self: 'static {}
8383
}
8484
fn bar<'a>(x: &'a &'a u32) {
85-
let y: &dyn Foo = x; //~ ERROR lifetime may not live long enough
86-
y.hello();
85+
let y: &dyn Foo = x;
86+
y.hello(); //~ ERROR lifetime may not live long enough
8787
}
8888
}
8989
mod i {
@@ -93,8 +93,8 @@ mod i {
9393
fn hello(&self) {}
9494
}
9595
fn bar<'a>(x: &'a &'a u32) {
96-
let y: &dyn Foo = x; //~ ERROR lifetime may not live long enough
97-
y.hello();
96+
let y: &dyn Foo = x;
97+
y.hello(); //~ ERROR lifetime may not live long enough
9898
}
9999
}
100100
mod j {
@@ -104,8 +104,8 @@ mod j {
104104
fn hello(&'static self) {}
105105
}
106106
fn bar<'a>(x: &'a &'a u32) {
107-
let y: &dyn Foo = x; //~ ERROR lifetime may not live long enough
108-
y.hello();
107+
let y: &dyn Foo = x;
108+
y.hello(); //~ ERROR lifetime may not live long enough
109109
}
110110
}
111111
mod k {
@@ -115,8 +115,8 @@ mod k {
115115
fn hello(&'static self) where Self: 'static {}
116116
}
117117
fn bar<'a>(x: &'a &'a u32) {
118-
let y: &dyn Foo = x; //~ ERROR lifetime may not live long enough
119-
y.hello();
118+
let y: &dyn Foo = x;
119+
y.hello(); //~ ERROR lifetime may not live long enough
120120
}
121121
}
122122
mod l {
@@ -126,8 +126,8 @@ mod l {
126126
fn hello(&self) where Self: 'static {}
127127
}
128128
fn bar<'a>(x: &'a &'a u32) {
129-
let y: &dyn Foo = x; //~ ERROR lifetime may not live long enough
130-
y.hello();
129+
let y: &dyn Foo = x;
130+
y.hello(); //~ ERROR lifetime may not live long enough
131131
}
132132
}
133133
mod m {
@@ -137,8 +137,8 @@ mod m {
137137
fn hello(&self) {}
138138
}
139139
fn bar<'a>(x: &'a &'a u32) {
140-
let y: &dyn Foo = x; //~ ERROR lifetime may not live long enough
141-
y.hello();
140+
let y: &dyn Foo = x;
141+
y.hello(); //~ ERROR lifetime may not live long enough
142142
}
143143
}
144144
mod n {
@@ -148,8 +148,8 @@ mod n {
148148
fn hello(&'static self) {}
149149
}
150150
fn bar<'a>(x: &'a &'a u32) {
151-
let y: &dyn Foo = x; //~ ERROR lifetime may not live long enough
152-
y.hello();
151+
let y: &dyn Foo = x;
152+
y.hello(); //~ ERROR lifetime may not live long enough
153153
}
154154
}
155155
mod o {
@@ -159,8 +159,8 @@ mod o {
159159
fn hello(&'static self) where Self: 'static {}
160160
}
161161
fn bar<'a>(x: &'a &'a u32) {
162-
let y: &dyn Foo = x; //~ ERROR lifetime may not live long enough
163-
y.hello();
162+
let y: &dyn Foo = x;
163+
y.hello(); //~ ERROR lifetime may not live long enough
164164
}
165165
}
166166
mod p {
@@ -170,8 +170,8 @@ mod p {
170170
fn hello(&self) where Self: 'static {}
171171
}
172172
fn bar<'a>(x: &'a &'a u32) {
173-
let y: &dyn Foo = x; //~ ERROR lifetime may not live long enough
174-
y.hello();
173+
let y: &dyn Foo = x;
174+
y.hello(); //~ ERROR lifetime may not live long enough
175175
}
176176
}
177177
mod q {
@@ -203,8 +203,8 @@ mod s {
203203

204204
}
205205
fn convert<'a>(x: &'a &'a u32) {
206-
let y: &dyn Foo = x; //~ ERROR lifetime may not live long enough
207-
y.hello();
206+
let y: &dyn Foo = x;
207+
y.hello(); //~ ERROR lifetime may not live long enough
208208
}
209209
}
210210
fn main() {}

0 commit comments

Comments
 (0)