Skip to content

Commit

Permalink
Review comments
Browse files Browse the repository at this point in the history
- Fix typo
- Add docstring
- Remove spurious test output file
  • Loading branch information
estebank committed Jun 27, 2017
1 parent c13a913 commit 7dad295
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
22 changes: 22 additions & 0 deletions src/librustc/hir/map/mod.rs
Expand Up @@ -632,6 +632,28 @@ impl<'hir> Map<'hir> {
}
}

/// Retrieve the NodeId for `id`'s enclosing method, unless there's a
/// `while` or `loop` before reacing it, as block tail returns are not
/// available in them.
///
/// ```
/// fn foo(x: usize) -> bool {
/// if x == 1 {
/// true // `get_return_block` gets passed the `id` corresponding
/// } else { // to this, it will return `foo`'s `NodeId`.
/// false
/// }
/// }
/// ```
///
/// ```
/// fn foo(x: usize) -> bool {
/// loop {
/// true // `get_return_block` gets passed the `id` corresponding
/// } // to this, it will return `None`.
/// false
/// }
/// ```
pub fn get_return_block(&self, id: NodeId) -> Option<NodeId> {
let match_fn = |node: &Node| {
match *node {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/mod.rs
Expand Up @@ -4214,7 +4214,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
ty
}

/// Given a `NodeId`, return the `FnDecl` of the method it is enclosed by and wether it is
/// Given a `NodeId`, return the `FnDecl` of the method it is enclosed by and whether it is
/// `fn main` if it is a method, `None` otherwise.
pub fn get_fn_decl(&self, blk_id: ast::NodeId) -> Option<(hir::FnDecl, bool)> {
// Get enclosing Fn, if it is a function or a trait method, unless there's a `loop` or
Expand All @@ -4227,7 +4227,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
}) = parent {
decl.clone().and_then(|decl| {
// This is less than ideal, it will not present the return type span on any
// method called `main`, regardless of wether it is actually the entry point.
// method called `main`, regardless of whether it is actually the entry point.
Some((decl, name == Symbol::intern("main")))
})
} else if let Node::NodeTraitItem(&hir::TraitItem {
Expand Down
4 changes: 0 additions & 4 deletions src/test/ui/block-result/expected-return-on-unit.stderr

This file was deleted.

0 comments on commit 7dad295

Please sign in to comment.