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

Refactor suggestion diagnostic API to allow for multiple suggestions #41876

Merged
merged 7 commits into from
May 13, 2017

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented May 10, 2017

@oli-obk
Copy link
Contributor Author

oli-obk commented May 10, 2017

The failure is spurious

@oli-obk oli-obk closed this May 10, 2017
@oli-obk oli-obk reopened this May 10, 2017
@TimNN TimNN added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 10, 2017
@sophiajt
Copy link
Contributor

The design looks cleaner than what we had before, so design-wise r=me, but it's been a while since I hacked on the compiler. @nrc might be a good one to look at the code, or possibly @arielb1

@nrc
Copy link
Member

nrc commented May 11, 2017

seems fine to me, I haven't done a detailed review, but the API looks good

// to be consistent. We could try to figure out if we can
// make one (or the first one) inline, but that would give
// undue importance to a semi-random suggestion
for sugg in &db.suggestions {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This duplicates the code somewhat. Consider doing this instead:

if let Some((sugg, rest)) = db.suggestions.split_first() {
    if rest.is_empty() && sugg.substitutes.len() == 1 && ... { 
        show `sugg` as label 
    } else {
        for sugg in &db.suggestions {
        show `sugg` proper
        }
    }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not know about split_first. That's a great method.

/// ```
/// vec![(0..7, vec!["a.b", "x.y"])]
/// ```
pub substitutes: Vec<(Span, Vec<String>)>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes code fairly ugly. Can we just get a struct with named fields for this?

@@ -1054,38 +1073,44 @@ impl EmitterWriter {
-> io::Result<()> {
use std::borrow::Borrow;

let primary_span = suggestion.msp.primary_span().unwrap();
let primary_span = suggestion.substitutes[0].0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be abstracted into a method IMO.

// remove trailing newline
buf.pop();
buf
for buf in &mut bufs {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is weird, mostly due to how push_trailing is used in the loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean. The code is exactly the same as it was before, but produces multiple suggestions instead of one. The only change i made other than the multiple suggestion part is to not add the trailing line if the replacement already produced a newline character and is thus finished.

@@ -2584,7 +2598,7 @@ impl<'a> Resolver<'a> {
module = Some(self.graph_root);
continue
} else if i == 0 && ns == TypeNS && ident.name == "$crate" {
module = Some(self.resolve_crate_var(ident.ctxt));
module = Some(self.resolve_crate_var(ident.ctxt, DUMMY_SP));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is DUMMY_SP here intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for external crates. I'm not sure if external crates have spans

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use the span of the use location? Any span is better than DUMMY_SP.

"".to_owned()
}
));
err.span_suggestions(span, &msg, path_strings);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just call err.span_suggestion multiple times in the loop above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a difference. The API is probably badly named. it would be span_suggestion_with_multiple_substitutions.

I could automate it by checking if the message and span are the same as an existing suggestion and then merge them. This would get rid of the span_suggestions entirely.

RenderSpan::Suggestion(ref suggestion) =>
DiagnosticSpan::from_suggestion(suggestion, je),
// regular diagnostics don't produce this anymore
// will be removed in a later commit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tag the comment with FIXME please.

`use std::io::Result;`
`use std::thread::Result;`
help: possible better candidates are found in other modules, you can import them into scope
| use std::fmt::Result;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these multiple suggestions or multiple substitutions? If suggestions, how does the one suggestion with multiple substitutions look like? What about multiple suggestions with one substitution each? Multiple suggestions with multiple substitutions?

If they do not look any differently, perhaps we could get rid of the multiple substitutions concept and always use multiple suggestions instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

multiple substitutions.

multiple suggestions show up with their own help each (just as they did before).

multiple suggestions with multiple substitutions show up as a help each + their substitutions below.

@nagisa
Copy link
Member

nagisa commented May 11, 2017

r=me with the dummy_sp somehow removed.

@oli-obk
Copy link
Contributor Author

oli-obk commented May 12, 2017

It was a little more involved to get the span to that function, but it's there now.

@nagisa
Copy link
Member

nagisa commented May 12, 2017

@bors r+

@bors
Copy link
Contributor

bors commented May 12, 2017

📌 Commit 3f2bbe3 has been approved by nagisa

Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this pull request May 13, 2017
…agisa

Refactor suggestion diagnostic API to allow for multiple suggestions

r? @jonathandturner

cc @nrc @petrochenkov
bors added a commit that referenced this pull request May 13, 2017
@bors bors merged commit 3f2bbe3 into rust-lang:master May 13, 2017
@oli-obk oli-obk deleted the diagnosing_diagnostics branch May 14, 2017 07:02
bors added a commit that referenced this pull request Nov 9, 2017
Refactor internal suggestion API

~~The only functional change is that whitespace, which is suggested to be added, also gets `^^^^` under it. An example is shown in the tests (the only test that changed).~~

Continuation of #41876

r? @nagisa

the changes are probably best viewed [without whitespace](https://github.com/rust-lang/rust/pull/45741/files?w=1)
bors added a commit that referenced this pull request Nov 18, 2017
Remove left over dead code from suggestion diagnostic refactoring

More cleanups after #41876 and #45741
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants