Skip to content

Commit 7d33094

Browse files
committed
Use structured suggestion when telling user about for<'a>
``` error[E0637]: `&` without an explicit lifetime name cannot be used here --> $DIR/E0637.rs:13:13 | LL | T: Into<&u32>, | ^ explicit lifetime name needed here | help: consider introducing a higher-ranked lifetime here | LL | T: for<'a> Into<&'a u32>, | +++++++ ++ ```
1 parent 54d6738 commit 7d33094

17 files changed

+157
-64
lines changed

Diff for: compiler/rustc_resolve/src/late.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1632,9 +1632,13 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
16321632
..
16331633
} = &rib.kind
16341634
{
1635-
diag.span_help(
1636-
*span,
1637-
"consider introducing a higher-ranked lifetime here with `for<'a>`",
1635+
diag.multipart_suggestion(
1636+
"consider introducing a higher-ranked lifetime here",
1637+
vec![
1638+
(span.shrink_to_lo(), "for<'a> ".into()),
1639+
(lifetime.ident.span.shrink_to_hi(), "'a ".into()),
1640+
],
1641+
Applicability::MachineApplicable,
16381642
);
16391643
break;
16401644
}

Diff for: tests/ui/error-codes/E0637.stderr

+3-4
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ error[E0637]: `&` without an explicit lifetime name cannot be used here
2222
LL | T: Into<&u32>,
2323
| ^ explicit lifetime name needed here
2424
|
25-
help: consider introducing a higher-ranked lifetime here with `for<'a>`
26-
--> $DIR/E0637.rs:13:8
25+
help: consider introducing a higher-ranked lifetime here
2726
|
28-
LL | T: Into<&u32>,
29-
| ^
27+
LL | T: for<'a> Into<&'a u32>,
28+
| +++++++ ++
3029

3130
error: aborting due to 3 previous errors
3231

Diff for: tests/ui/generics/issue-65285-incorrect-explicit-lifetime-name-needed.stderr

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ error[E0637]: `&` without an explicit lifetime name cannot be used here
44
LL | fn should_error<T>() where T : Into<&u32> {}
55
| ^ explicit lifetime name needed here
66
|
7-
help: consider introducing a higher-ranked lifetime here with `for<'a>`
8-
--> $DIR/issue-65285-incorrect-explicit-lifetime-name-needed.rs:5:32
7+
help: consider introducing a higher-ranked lifetime here
98
|
10-
LL | fn should_error<T>() where T : Into<&u32> {}
11-
| ^
9+
LL | fn should_error<T>() where T : for<'a> Into<&'a u32> {}
10+
| +++++++ ++
1211

1312
error[E0106]: missing lifetime specifier
1413
--> $DIR/issue-65285-incorrect-explicit-lifetime-name-needed.rs:9:20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// run-rustfix
2+
3+
trait WithType<T> {}
4+
trait WithRegion<'a> { }
5+
6+
#[allow(dead_code)]
7+
struct Foo<T> {
8+
t: T
9+
}
10+
11+
impl<T> Foo<T>
12+
where
13+
T: for<'a> WithType<&'a u32>
14+
//~^ ERROR `&` without an explicit lifetime name cannot be used here
15+
{ }
16+
17+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// run-rustfix
2+
3+
trait WithType<T> {}
4+
trait WithRegion<'a> { }
5+
6+
#[allow(dead_code)]
7+
struct Foo<T> {
8+
t: T
9+
}
10+
11+
impl<T> Foo<T>
12+
where
13+
T: WithType<&u32>
14+
//~^ ERROR `&` without an explicit lifetime name cannot be used here
15+
{ }
16+
17+
fn main() {}

Diff for: tests/ui/underscore-lifetime/where-clause-trait-impl-region.rust2015.stderr renamed to tests/ui/underscore-lifetime/where-clause-inherent-impl-ampersand-rust2015.stderr

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
error[E0637]: `&` without an explicit lifetime name cannot be used here
2-
--> $DIR/where-clause-trait-impl-region.rs:11:17
2+
--> $DIR/where-clause-inherent-impl-ampersand-rust2015.rs:13:17
33
|
44
LL | T: WithType<&u32>
55
| ^ explicit lifetime name needed here
66
|
7-
help: consider introducing a higher-ranked lifetime here with `for<'a>`
8-
--> $DIR/where-clause-trait-impl-region.rs:11:8
7+
help: consider introducing a higher-ranked lifetime here
98
|
10-
LL | T: WithType<&u32>
11-
| ^
9+
LL | T: for<'a> WithType<&'a u32>
10+
| +++++++ ++
1211

1312
error: aborting due to previous error
1413

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// edition:2018
2+
// run-rustfix
3+
4+
trait WithType<T> {}
5+
trait WithRegion<'a> { }
6+
7+
#[allow(dead_code)]
8+
struct Foo<T> {
9+
t: T
10+
}
11+
12+
impl<T> Foo<T>
13+
where
14+
T: for<'a> WithType<&'a u32>
15+
//~^ ERROR `&` without an explicit lifetime name cannot be used here
16+
{ }
17+
18+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// edition:2018
2+
// run-rustfix
3+
4+
trait WithType<T> {}
5+
trait WithRegion<'a> { }
6+
7+
#[allow(dead_code)]
8+
struct Foo<T> {
9+
t: T
10+
}
11+
12+
impl<T> Foo<T>
13+
where
14+
T: WithType<&u32>
15+
//~^ ERROR `&` without an explicit lifetime name cannot be used here
16+
{ }
17+
18+
fn main() {}

Diff for: tests/ui/underscore-lifetime/where-clause-trait-impl-region.rust2018.stderr renamed to tests/ui/underscore-lifetime/where-clause-inherent-impl-ampersand-rust2018.stderr

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
error[E0637]: `&` without an explicit lifetime name cannot be used here
2-
--> $DIR/where-clause-trait-impl-region.rs:11:17
2+
--> $DIR/where-clause-inherent-impl-ampersand-rust2018.rs:14:17
33
|
44
LL | T: WithType<&u32>
55
| ^ explicit lifetime name needed here
66
|
7-
help: consider introducing a higher-ranked lifetime here with `for<'a>`
8-
--> $DIR/where-clause-trait-impl-region.rs:11:8
7+
help: consider introducing a higher-ranked lifetime here
98
|
10-
LL | T: WithType<&u32>
11-
| ^
9+
LL | T: for<'a> WithType<&'a u32>
10+
| +++++++ ++
1211

1312
error: aborting due to previous error
1413

Diff for: tests/ui/underscore-lifetime/where-clause-inherent-impl-ampersand.rs

-18
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// run-rustfix
2+
3+
trait WithType<T> {}
4+
trait WithRegion<'a> { }
5+
6+
trait Foo { }
7+
8+
impl<T> Foo for Vec<T>
9+
where
10+
T: for<'a> WithType<&'a u32>
11+
//~^ ERROR `&` without an explicit lifetime name cannot be used here
12+
{ }
13+
14+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// run-rustfix
2+
3+
trait WithType<T> {}
4+
trait WithRegion<'a> { }
5+
6+
trait Foo { }
7+
8+
impl<T> Foo for Vec<T>
9+
where
10+
T: WithType<&u32>
11+
//~^ ERROR `&` without an explicit lifetime name cannot be used here
12+
{ }
13+
14+
fn main() {}

Diff for: tests/ui/underscore-lifetime/where-clause-inherent-impl-ampersand.rust2015.stderr renamed to tests/ui/underscore-lifetime/where-clause-trait-impl-region-2015.stderr

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
error[E0637]: `&` without an explicit lifetime name cannot be used here
2-
--> $DIR/where-clause-inherent-impl-ampersand.rs:13:17
2+
--> $DIR/where-clause-trait-impl-region-2015.rs:10:17
33
|
44
LL | T: WithType<&u32>
55
| ^ explicit lifetime name needed here
66
|
7-
help: consider introducing a higher-ranked lifetime here with `for<'a>`
8-
--> $DIR/where-clause-inherent-impl-ampersand.rs:13:8
7+
help: consider introducing a higher-ranked lifetime here
98
|
10-
LL | T: WithType<&u32>
11-
| ^
9+
LL | T: for<'a> WithType<&'a u32>
10+
| +++++++ ++
1211

1312
error: aborting due to previous error
1413

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// run-rustfix
2+
// edition:2018
3+
4+
trait WithType<T> {}
5+
trait WithRegion<'a> { }
6+
7+
trait Foo { }
8+
9+
impl<T> Foo for Vec<T>
10+
where
11+
T: for<'a> WithType<&'a u32>
12+
//~^ ERROR `&` without an explicit lifetime name cannot be used here
13+
{ }
14+
15+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// run-rustfix
2+
// edition:2018
3+
4+
trait WithType<T> {}
5+
trait WithRegion<'a> { }
6+
7+
trait Foo { }
8+
9+
impl<T> Foo for Vec<T>
10+
where
11+
T: WithType<&u32>
12+
//~^ ERROR `&` without an explicit lifetime name cannot be used here
13+
{ }
14+
15+
fn main() {}

Diff for: tests/ui/underscore-lifetime/where-clause-inherent-impl-ampersand.rust2018.stderr renamed to tests/ui/underscore-lifetime/where-clause-trait-impl-region-2018.stderr

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
error[E0637]: `&` without an explicit lifetime name cannot be used here
2-
--> $DIR/where-clause-inherent-impl-ampersand.rs:13:17
2+
--> $DIR/where-clause-trait-impl-region-2018.rs:11:17
33
|
44
LL | T: WithType<&u32>
55
| ^ explicit lifetime name needed here
66
|
7-
help: consider introducing a higher-ranked lifetime here with `for<'a>`
8-
--> $DIR/where-clause-inherent-impl-ampersand.rs:13:8
7+
help: consider introducing a higher-ranked lifetime here
98
|
10-
LL | T: WithType<&u32>
11-
| ^
9+
LL | T: for<'a> WithType<&'a u32>
10+
| +++++++ ++
1211

1312
error: aborting due to previous error
1413

Diff for: tests/ui/underscore-lifetime/where-clause-trait-impl-region.rs

-15
This file was deleted.

0 commit comments

Comments
 (0)