-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
#53359: putting multiple unresolved import on single line #53565
Conversation
I feel it might be slightly less disruptive to third party tools to only unify those unresolved imports that are part of the same path (
You need to give one label to each span and it should work.
That is because a |
This comment has been minimized.
This comment has been minimized.
18b7296
to
e8dda23
Compare
This comment has been minimized.
This comment has been minimized.
b3aaae6
to
9006adc
Compare
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
let msg = format!("unresolved import{} {}", | ||
if path_vec.len() > 1 { "s" } else { "" }, path); | ||
let mut err = struct_span_err!(self.resolver.session, | ||
multi_span.clone(), E0432, "{}", &msg); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid the error you're seeing in travis you need to extract this to a method called from both here and the other occurrence of E0432.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@estebank Sure!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@estebank Challenge here is to create a generic function which can take any one of Span
or MultiSpan
as a type of argument. I think creating a traits
and implementing it both for Span
and MultiSpan
is one way but I am bit reluctant toward this approach. Let me know what are your thoughts on that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I have found other way for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use where S: Into<MultiSpan>
and have your method accept a sp: S
. Span
implements it, so your method can take either and inside your method you operate with a MultiSpan
always.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
src/test/ui/issue-53565.stderr
Outdated
--> $DIR/issue-53565.rs:1:17 | ||
| | ||
LL | use std::time::{foo, bar, buzz}; | ||
| ^^^ ^^^ ^^^^ no `buzz` in `time` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be nice for this to be
no `buzz` in `std::time`
but I'm not too worried one way or another.
451c01d
to
62850f6
Compare
This comment has been minimized.
This comment has been minimized.
fc471ba
to
527ad26
Compare
// in case of new import line, throw diagnostic message | ||
// for previous line. | ||
self.throw_unresolved_import_error(error_vec.clone(), None); | ||
error_vec.clear(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I feel using std::mem::swap
would be a better idea:
let mut empty_vec = vec![];
swap(empty_vec, error_vec);
self.throw_unresolved_import_error(empty_vec, None);
That way you're not cloning error_vec
just to discard its contents immediately after.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than the nitpicks inline, r=me.
let (span,msg) = match error_vec.is_empty() { | ||
true => (span.unwrap(), "unresolved import".to_string()), | ||
false => { | ||
let span = MultiSpan::from_spans(error_vec.clone().into_iter() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clean up indentation in this block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get it, what's wrong with indentation here.
let path_vec: Vec<String> = error_vec.clone().into_iter() | ||
.map(|elem: (Span, String, String)| { format!("`{}`", elem.1) } | ||
).collect(); | ||
let path = path_vec.join(", "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be a good idea to bound this list to a maximum size, to avoid having a ridiculous amount of text. The limit should be high enough that it is rarely hit, but must be present in case somebody is writing non-stylistic code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@estebank What should be upper limit of path_vec here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any number would be arbitrary, but let's say... 10?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@estebank: or should we simply emit message once vector size reaches 10 or new import line? However, in that case we would not be able to avoid ridiculous amount of data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the ideal would be something similar to the unexpected token error, where the error message lists all of the tokens that could have applied (theoretically unbounded list), while the label after a certain number (don't recall the threshold) is just "expected one of N tokens here".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what I'm thinking of
error: expected one of `)`, `,`, `-`, `.`, `<`, `?`, `break`, `continue`, `false`, `for`, `if`, `loop`, `match`, `move`, `return`, `static`, `true`, `unsafe`, `while`, `yield`, or an operator, found `;`
--> $DIR/token-error-correct.rs:14:13
|
LL | foo(bar(;
| --
| ||
| |expected one of 21 possible tokens here
| |help: ...the missing `)` may belong here
| if you meant to close this...
In this case you'd have multiple spans, so the output would be a bit more cluttered, which makes me think we might want to remove the labels...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@estebank done! now I have set an upper limit on a number of span_label for each diagnostic msg.
…one diagnostic Addressed estebank's comments for 53359
527ad26
to
21ba03e
Compare
r? @estebank |
@bors r+ ❤️ |
📋 Looks like this PR is still in progress, ignoring approval. Hint: Remove WIP from this PR's title when it is ready for review. |
@estebank you may have to r+ it again :) |
@bors r+ |
📌 Commit 21ba03e has been approved by |
⌛ Testing commit 21ba03e with merge 4fdc118a89e0acbf5e753e627845ba2e310657d3... |
💔 Test failed - status-travis |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
#53359: putting multiple unresolved import on single line r? @estebank Here is WIP implementation of #53359 this PR have clubbed multiple unresolved imports into a single line. I think still two things need to improve like giving specific `label message` for each span of multi_span(how we can do this?) and second we are getting a warning while compiling, stating something like `E0432` have been passed before.
☀️ Test successful - status-appveyor, status-travis |
r? @estebank
Here is WIP implementation of #53359
this PR have clubbed multiple unresolved imports into a single line.
I think still two things need to improve like giving specific
label message
for each span of multi_span(how we can do this?) and second we are getting a warning while compiling, stating something likeE0432
have been passed before.