-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Detect missing ;
on methods with return type ()
#42850
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8e11189
Move tests to `ui`
estebank c023856
Detect missing `;` on methods with return type `()`
estebank ecde91a
Suggest removal of semicolon (instead of being help)
estebank 27d4b31
Do not specify return type in suggestion for some `Ty`s
estebank c13a913
Don't naively point to return type on type error
estebank 7dad295
Review comments
estebank 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 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 |
---|---|---|
|
@@ -594,8 +594,12 @@ impl<'hir> Map<'hir> { | |
/// last good node id we found. Note that reaching the crate root (id == 0), | ||
/// is not an error, since items in the crate module have the crate root as | ||
/// parent. | ||
fn walk_parent_nodes<F>(&self, start_id: NodeId, found: F) -> Result<NodeId, NodeId> | ||
where F: Fn(&Node<'hir>) -> bool | ||
fn walk_parent_nodes<F, F2>(&self, | ||
start_id: NodeId, | ||
found: F, | ||
bail_early: F2) | ||
-> Result<NodeId, NodeId> | ||
where F: Fn(&Node<'hir>) -> bool, F2: Fn(&Node<'hir>) -> bool | ||
{ | ||
let mut id = start_id; | ||
loop { | ||
|
@@ -616,6 +620,8 @@ impl<'hir> Map<'hir> { | |
Some(ref node) => { | ||
if found(node) { | ||
return Ok(parent_node); | ||
} else if bail_early(node) { | ||
return Err(parent_node); | ||
} | ||
} | ||
None => { | ||
|
@@ -626,6 +632,34 @@ impl<'hir> Map<'hir> { | |
} | ||
} | ||
|
||
pub fn get_return_block(&self, id: NodeId) -> Option<NodeId> { | ||
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. Comment explaining what this function does would be good. Ideally with an example. |
||
let match_fn = |node: &Node| { | ||
match *node { | ||
NodeItem(_) | | ||
NodeForeignItem(_) | | ||
NodeTraitItem(_) | | ||
NodeImplItem(_) => true, | ||
_ => false, | ||
} | ||
}; | ||
let match_non_returning_block = |node: &Node| { | ||
match *node { | ||
NodeExpr(ref expr) => { | ||
match expr.node { | ||
ExprWhile(..) | ExprLoop(..) => true, | ||
_ => false, | ||
} | ||
} | ||
_ => false, | ||
} | ||
}; | ||
|
||
match self.walk_parent_nodes(id, match_fn, match_non_returning_block) { | ||
Ok(id) => Some(id), | ||
Err(_) => None, | ||
} | ||
} | ||
|
||
/// Retrieve the NodeId for `id`'s parent item, or `id` itself if no | ||
/// parent item is in this map. The "parent item" is the closest parent node | ||
/// in the AST which is recorded by the map and is an item, either an item | ||
|
@@ -637,7 +671,7 @@ impl<'hir> Map<'hir> { | |
NodeTraitItem(_) | | ||
NodeImplItem(_) => true, | ||
_ => false, | ||
}) { | ||
}, |_| false) { | ||
Ok(id) => id, | ||
Err(id) => id, | ||
} | ||
|
@@ -649,7 +683,7 @@ impl<'hir> Map<'hir> { | |
let id = match self.walk_parent_nodes(id, |node| match *node { | ||
NodeItem(&Item { node: Item_::ItemMod(_), .. }) => true, | ||
_ => false, | ||
}) { | ||
}, |_| false) { | ||
Ok(id) => id, | ||
Err(id) => id, | ||
}; | ||
|
@@ -668,7 +702,7 @@ impl<'hir> Map<'hir> { | |
NodeImplItem(_) | | ||
NodeBlock(_) => true, | ||
_ => false, | ||
}) { | ||
}, |_| false) { | ||
Ok(id) => Some(id), | ||
Err(_) => None, | ||
} | ||
|
This file contains 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 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 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 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 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 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 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
Oops, something went wrong.
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.
Meh. This is fine for now, but it'd be nice to make this an iterator, I think.