This repository was archived by the owner on Nov 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
Filter by machine applicability #97
Merged
killercup
merged 3 commits into
rust-lang:master
from
killercup:feature/filter-by-machine-applicability
May 23, 2018
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,14 +18,21 @@ pub mod diagnostics; | |
use diagnostics::{Diagnostic, DiagnosticSpan}; | ||
mod replace; | ||
|
||
#[derive(Debug, Clone, Copy)] | ||
pub enum Filter { | ||
MachineApplicableOnly, | ||
Everything, | ||
} | ||
|
||
pub fn get_suggestions_from_json<S: ::std::hash::BuildHasher>( | ||
input: &str, | ||
only: &HashSet<String, S>, | ||
filter: Filter, | ||
) -> serde_json::error::Result<Vec<Suggestion>> { | ||
let mut result = Vec::new(); | ||
for cargo_msg in serde_json::Deserializer::from_str(input).into_iter::<Diagnostic>() { | ||
// One diagnostic line might have multiple suggestions | ||
result.extend(collect_suggestions(&cargo_msg?, only)); | ||
result.extend(collect_suggestions(&cargo_msg?, only, filter)); | ||
} | ||
Ok(result) | ||
} | ||
|
@@ -142,6 +149,7 @@ fn collect_span(span: &DiagnosticSpan) -> Option<Replacement> { | |
pub fn collect_suggestions<S: ::std::hash::BuildHasher>( | ||
diagnostic: &Diagnostic, | ||
only: &HashSet<String, S>, | ||
filter: Filter, | ||
) -> Option<Suggestion> { | ||
if !only.is_empty() { | ||
if let Some(ref code) = diagnostic.code { | ||
|
@@ -165,7 +173,21 @@ pub fn collect_suggestions<S: ::std::hash::BuildHasher>( | |
.children | ||
.iter() | ||
.filter_map(|child| { | ||
let replacements: Vec<_> = child.spans.iter().filter_map(collect_span).collect(); | ||
let replacements: Vec<_> = child | ||
.spans | ||
.iter() | ||
.filter(|span| { | ||
use Filter::*; | ||
use diagnostics::Applicability::*; | ||
|
||
match (filter, &span.suggestion_applicability) { | ||
(MachineApplicableOnly, Some(MachineApplicable)) => true, | ||
(MachineApplicableOnly, _) => false, | ||
(_, _) => true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could the left hand side of this match be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, good idea |
||
} | ||
}) | ||
.filter_map(collect_span) | ||
.collect(); | ||
if replacements.len() == 1 { | ||
Some(Solution { | ||
message: child.message.clone(), | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Hm does this mean that the lints we're testing against aren't currently classifed as "machine applicable"?
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.
Yeah
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.
Hm ok, could we perhaps start testing lints that are classified as machine applicable?
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.
Well, like I said, we don't have many -- just unreachable_pub, bare_trait_object, and abs_path_with_module. Do you want to rewrite the tests to always use those? I'd wait a bit for more applicability markers to land and then refactor the tests.
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.
Hm ok, the 2018 compatibility lints are at least machine applicable, right? If so can you make sure that they're already tested and/or add a test for 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.
Right -- everything but the
upgrade_extern_crate
case work without the env var. Updated.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.
Nice!
As one final comment, could this be an extension method for just the test suite to do something like
.fix_everything()
instead of duplicating the env var? Other than that r=me!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.
Good idea!