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

Suggest removing parenthesis surrounding lifetimes #57386

Closed
estebank opened this issue Jan 6, 2019 · 4 comments
Closed

Suggest removing parenthesis surrounding lifetimes #57386

estebank opened this issue Jan 6, 2019 · 4 comments
Labels
A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@estebank
Copy link
Contributor

estebank commented Jan 6, 2019

Given:

trait Trait {}
fn f<'a, T: Trait + ('a)>() {}

suggest the correct syntax

error: parenthesized lifetime bounds are not supported
  --> $DIR/trait-object-lifetime-parens.rs:5:24
   |
LL | fn f<'a, T: Trait + ('a)>() {}
   |                        ^
help: remove the braces
   |
LL | fn f<'a, T: Trait + 'a>() {}
   |                     ^^
@estebank estebank added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. and removed A-diagnostics Area: Messages for errors, warnings, and lints labels Jan 6, 2019
@igorsdv
Copy link
Contributor

igorsdv commented Jan 8, 2019

I'd like to work on this (I'm new)

@estebank
Copy link
Contributor Author

estebank commented Jan 8, 2019

@goldenlentils feel free to reach out for any help you might need! And take a look at The Forge, particularly the explanation on how to run tests (./x.py test src/test/ui --stage 1 --bless is what I normally run).

You will find the code that emits this error in parse_generic_bounds_common in libsyntax/parse/parser.rs. You will need to change the span_err call for an struct_span_err that will give you a DiagnosticBuilder that you can modify using span_suggestion_with_applicability. You can search the codebase (and the same file) for how to use it.

@igorsdv
Copy link
Contributor

igorsdv commented Jan 8, 2019

@estebank Thanks!

I managed to get the error to look like this:

error: parenthesized lifetime bounds are not supported
 --> /home/igor/dev/sandbox/sample.rs:3:21
  |
3 | fn f<'a, T: Trait + ('a)>() {}
  |                     ^^^^ help: remove the parentheses: `'a`

error: aborting due to previous error

Or, if using span_suggestion_short_with_applicability:

error: parenthesized lifetime bounds are not supported
 --> /home/igor/dev/sandbox/sample.rs:3:21
  |
3 | fn f<'a, T: Trait + ('a)>() {}
  |                     ^^^^ help: remove the parentheses

error: aborting due to previous error

As I understand, the help message appears inline because of the condition sugg.msg.split_whitespace().count() < 10 at librustc_errors/emitter.rs:46. Is this fine? Is any of the two options above preferable?

@estebank
Copy link
Contributor Author

@igorsdv your understanding is correct. Being inline is fine and I'm partial towards the short version, at least in this case.

Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this issue Feb 18, 2019
…s-surrounding-lifetimes, r=estebank

Suggest removing parentheses surrounding lifetimes

Fixes rust-lang#57386.

r? @estebank
Centril added a commit to Centril/rust that referenced this issue Feb 20, 2019
…s-surrounding-lifetimes, r=estebank

Suggest removing parentheses surrounding lifetimes

Fixes rust-lang#57386.

r? @estebank
Centril added a commit to Centril/rust that referenced this issue Feb 22, 2019
…s-surrounding-lifetimes, r=estebank

Suggest removing parentheses surrounding lifetimes

Fixes rust-lang#57386.

r? @estebank
Centril added a commit to Centril/rust that referenced this issue Feb 22, 2019
…s-surrounding-lifetimes, r=estebank

Suggest removing parentheses surrounding lifetimes

Fixes rust-lang#57386.

r? @estebank
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

No branches or pull requests

2 participants