-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Fix build error due to removed method in libsyntax #1119
Conversation
Please ignore this for now. Looks like I underestimated the change required |
Hum, it looks like since rust-lang/rust#34965, there is no way to create a MultiSpan with several primary spans (it's just 0 or 1, despite |
@mcarton - Ha, I hadn't noticed that, I just saw that they weren't being used in the compiler. Hmm... Out of curiosity, how is clippy using multiple primary spans? In the compiler, there are places where multiple primary spans are used, but they generally get their own snippets, so they get turned into SubDiagnostic(s). I ask because I was hoping to simplify things a bit further. |
@jonathandturner We use them in one function, which builds a suggestion from several snippets (eg. for Do you know another way to build that |
@mcarton - Ah, so you SubDiagnostic there, too. I guess I was more wondering if it needs to all be primary spans or if you could use secondary spans for part of the message. |
any update on what to do about this? We could just move to showing two suggestions (and thus two helps) |
@oli-obk no, it's not two suggestions. It's one suggestion made from two different changes. If something must be changed in Clippy, we should play with spans and snippets. |
Temporarily we can just get two suggestions and then re-add the support, no? |
Two suggestions wouldn't make sense. If we're to remove that temporarily, just don't make a suggestion. |
As for why I used that feature (it's from my recent big-PR of suggestions improvement I think) while it wasn't used anywhere in rustc itself: it is less error-prone than making spans and cut-and-paste bits of code to make a suggestion. It is also well supported in the two different human-readable error formats and the JSON error format (and for tools such as rustfix, using that feature would be more convenient than having one big suggestion). |
@mcarton - What do you mean by "If that feature is to be removed from rustc for some reason"? FWIW - these changes shouldn't have any impact on human-readable or JSON errors. |
@jonathandturner we can't create a suggestion from multiple spans anymore, which is less error prone than getting snippets from different ast nodes and trying to build a big suggestions with For example, currently we suggest to change In the JSON format the suggestion for that looks like: {
"message": "consider using an iterator",
"code": null,
"level": "help",
"spans": [
{
"file_name": "tests/compile-fail/for_loop.rs",
"byte_start": 3019,
"byte_end": 3020,
"line_start": 99,
"line_end": 99,
"column_start": 9,
"column_end": 10,
"is_primary": true,
"text": [
{
"text": " for i in 0..vec.len() {",
"highlight_start": 9,
"highlight_end": 10
}
],
"label": null,
"suggested_replacement": "<item>",
"expansion": null
},
{
"file_name": "tests/compile-fail/for_loop.rs",
"byte_start": 3024,
"byte_end": 3036,
"line_start": 99,
"line_end": 99,
"column_start": 14,
"column_end": 26,
"is_primary": true,
"text": [
{
"text": " for i in 0..vec.len() {",
"highlight_start": 14,
"highlight_end": 26
}
],
"label": null,
"suggested_replacement": "&vec",
"expansion": null
}
],
"children": [
],
"rendered": " for <item> in &vec {"
} Everything seems to indicate this is not an accidental feature rustc had (even though rustc does not use it; but it also uses actual suggestions like 3 times, most of them are just suggested in an English sentence rather than code-replacement) so I was happy to use it. |
I mentioned this earlier but maybe it got lost in the shuffle. pub struct MultiSpan {
primary_spans: Vec<Span>,
span_labels: Vec<(Span, String)>,
} There are other spans associated with errors. I was asking earlier if you need to always be using the primary_spans or if you could use the secondary spans. Secondary spans are mentioned in span_labels but are not one of the ones given in primary_spans. It's the difference between ^^^ and --- in the new error format, where ^^^ is primary and --- is secondary. Can you use the other spans instead? |
Anyway, labels don't make sense for a suggestion, and there is no |
Ahh, I hadn't seen that assert! Yeah, good point. Maybe suggestions do want their own type. For now, might as well put the methods back into MultiSpan until we come up with a better solution. If you decide to go that route, feel free to r? me. |
Revert "Remove unused methods from MultiSpan" This reverts commit f7019a4. That commit removed the only way to make a suggestion with more than one substitute. That feature is not used directly by rustc but exists and is used by Clippy. Bring it back until we come up with a better solution (suggestions don't use span labels, so it would make sense for them to use their own type). Rational there: https://github.com/Manishearth/rust-clippy/pull/1119. r? @jonathandturner Cc @Manishearth
Revert "Remove unused methods from MultiSpan" This reverts commit f7019a4. That commit removed the only way to make a suggestion with more than one substitute. That feature is not used directly by rustc but exists and is used by Clippy. Bring it back until we come up with a better solution (suggestions don't use span labels, so it would make sense for them to use their own type). Rational there: https://github.com/Manishearth/rust-clippy/pull/1119. r? @jonathandturner Cc @Manishearth
No description provided.