From 7dad2958be59801881fb3db7544de423420dabd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Tue, 27 Jun 2017 13:34:56 -0700 Subject: [PATCH] Review comments - Fix typo - Add docstring - Remove spurious test output file --- src/librustc/hir/map/mod.rs | 22 +++++++++++++++++++ src/librustc_typeck/check/mod.rs | 4 ++-- .../expected-return-on-unit.stderr | 4 ---- 3 files changed, 24 insertions(+), 6 deletions(-) delete mode 100644 src/test/ui/block-result/expected-return-on-unit.stderr diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index ddcc2c0885085..02a36a372d9ef 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -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 { let match_fn = |node: &Node| { match *node { diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 7c4b6a858d957..cba930d312f8e 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -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 @@ -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 { diff --git a/src/test/ui/block-result/expected-return-on-unit.stderr b/src/test/ui/block-result/expected-return-on-unit.stderr deleted file mode 100644 index 8a0d7a335d6af..0000000000000 --- a/src/test/ui/block-result/expected-return-on-unit.stderr +++ /dev/null @@ -1,4 +0,0 @@ -error[E0601]: main function not found - -error: aborting due to previous error(s) -