Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use structured suggestion when telling user about for<'a> #113177

Merged
merged 1 commit into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1632,9 +1632,13 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
..
} = &rib.kind
{
diag.span_help(
*span,
"consider introducing a higher-ranked lifetime here with `for<'a>`",
diag.multipart_suggestion(
"consider introducing a higher-ranked lifetime here",
vec![
(span.shrink_to_lo(), "for<'a> ".into()),
(lifetime.ident.span.shrink_to_hi(), "'a ".into()),
],
Applicability::MachineApplicable,
);
break;
}
Expand Down
7 changes: 3 additions & 4 deletions tests/ui/error-codes/E0637.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ error[E0637]: `&` without an explicit lifetime name cannot be used here
LL | T: Into<&u32>,
| ^ explicit lifetime name needed here
|
help: consider introducing a higher-ranked lifetime here with `for<'a>`
--> $DIR/E0637.rs:13:8
help: consider introducing a higher-ranked lifetime here
|
LL | T: Into<&u32>,
| ^
LL | T: for<'a> Into<&'a u32>,
| +++++++ ++

error: aborting due to 3 previous errors

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

error[E0106]: missing lifetime specifier
--> $DIR/issue-65285-incorrect-explicit-lifetime-name-needed.rs:9:20
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// run-rustfix

trait WithType<T> {}
trait WithRegion<'a> { }

#[allow(dead_code)]
struct Foo<T> {
t: T
}

impl<T> Foo<T>
where
T: for<'a> WithType<&'a u32>
//~^ ERROR `&` without an explicit lifetime name cannot be used here
{ }

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// run-rustfix

trait WithType<T> {}
trait WithRegion<'a> { }

#[allow(dead_code)]
struct Foo<T> {
t: T
}

impl<T> Foo<T>
where
T: WithType<&u32>
//~^ ERROR `&` without an explicit lifetime name cannot be used here
{ }

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
error[E0637]: `&` without an explicit lifetime name cannot be used here
--> $DIR/where-clause-trait-impl-region.rs:11:17
--> $DIR/where-clause-inherent-impl-ampersand-rust2015.rs:13:17
|
LL | T: WithType<&u32>
| ^ explicit lifetime name needed here
|
help: consider introducing a higher-ranked lifetime here with `for<'a>`
--> $DIR/where-clause-trait-impl-region.rs:11:8
help: consider introducing a higher-ranked lifetime here
|
LL | T: WithType<&u32>
| ^
LL | T: for<'a> WithType<&'a u32>
| +++++++ ++

error: aborting due to previous error

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// edition:2018
// run-rustfix

trait WithType<T> {}
trait WithRegion<'a> { }

#[allow(dead_code)]
struct Foo<T> {
t: T
}

impl<T> Foo<T>
where
T: for<'a> WithType<&'a u32>
//~^ ERROR `&` without an explicit lifetime name cannot be used here
{ }

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// edition:2018
// run-rustfix

trait WithType<T> {}
trait WithRegion<'a> { }

#[allow(dead_code)]
struct Foo<T> {
t: T
}

impl<T> Foo<T>
where
T: WithType<&u32>
//~^ ERROR `&` without an explicit lifetime name cannot be used here
{ }

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
error[E0637]: `&` without an explicit lifetime name cannot be used here
--> $DIR/where-clause-trait-impl-region.rs:11:17
--> $DIR/where-clause-inherent-impl-ampersand-rust2018.rs:14:17
|
LL | T: WithType<&u32>
| ^ explicit lifetime name needed here
|
help: consider introducing a higher-ranked lifetime here with `for<'a>`
--> $DIR/where-clause-trait-impl-region.rs:11:8
help: consider introducing a higher-ranked lifetime here
|
LL | T: WithType<&u32>
| ^
LL | T: for<'a> WithType<&'a u32>
| +++++++ ++

error: aborting due to previous error

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// run-rustfix

trait WithType<T> {}
trait WithRegion<'a> { }

trait Foo { }

impl<T> Foo for Vec<T>
where
T: for<'a> WithType<&'a u32>
//~^ ERROR `&` without an explicit lifetime name cannot be used here
{ }

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// run-rustfix

trait WithType<T> {}
trait WithRegion<'a> { }

trait Foo { }

impl<T> Foo for Vec<T>
where
T: WithType<&u32>
//~^ ERROR `&` without an explicit lifetime name cannot be used here
{ }

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
error[E0637]: `&` without an explicit lifetime name cannot be used here
--> $DIR/where-clause-inherent-impl-ampersand.rs:13:17
--> $DIR/where-clause-trait-impl-region-2015.rs:10:17
|
LL | T: WithType<&u32>
| ^ explicit lifetime name needed here
|
help: consider introducing a higher-ranked lifetime here with `for<'a>`
--> $DIR/where-clause-inherent-impl-ampersand.rs:13:8
help: consider introducing a higher-ranked lifetime here
|
LL | T: WithType<&u32>
| ^
LL | T: for<'a> WithType<&'a u32>
| +++++++ ++

error: aborting due to previous error

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// run-rustfix
// edition:2018

trait WithType<T> {}
trait WithRegion<'a> { }

trait Foo { }

impl<T> Foo for Vec<T>
where
T: for<'a> WithType<&'a u32>
//~^ ERROR `&` without an explicit lifetime name cannot be used here
{ }

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// run-rustfix
// edition:2018

trait WithType<T> {}
trait WithRegion<'a> { }

trait Foo { }

impl<T> Foo for Vec<T>
where
T: WithType<&u32>
//~^ ERROR `&` without an explicit lifetime name cannot be used here
{ }

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
error[E0637]: `&` without an explicit lifetime name cannot be used here
--> $DIR/where-clause-inherent-impl-ampersand.rs:13:17
--> $DIR/where-clause-trait-impl-region-2018.rs:11:17
|
LL | T: WithType<&u32>
| ^ explicit lifetime name needed here
|
help: consider introducing a higher-ranked lifetime here with `for<'a>`
--> $DIR/where-clause-inherent-impl-ampersand.rs:13:8
help: consider introducing a higher-ranked lifetime here
|
LL | T: WithType<&u32>
| ^
LL | T: for<'a> WithType<&'a u32>
| +++++++ ++

error: aborting due to previous error

Expand Down
15 changes: 0 additions & 15 deletions tests/ui/underscore-lifetime/where-clause-trait-impl-region.rs

This file was deleted.