diff options
| author | Eduard Burtescu <edy.burt@gmail.com> | 2015-02-25 22:06:08 +0200 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2015-05-21 11:47:30 -0400 |
| commit | 1bd420555e7eb49c2c9a6ecc68e1797540bef403 (patch) | |
| tree | 4f6d735d8defa838107ad0a765994c527b0862a6 /src/libsyntax/ast_map | |
| parent | af3795721cd9ffc591eeeb077df16d3658be150f (diff) | |
| download | rust-1bd420555e7eb49c2c9a6ecc68e1797540bef403.tar.gz rust-1bd420555e7eb49c2c9a6ecc68e1797540bef403.zip | |
rustc: const-qualify `const fn` function and method calls.
Diffstat (limited to 'src/libsyntax/ast_map')
| -rw-r--r-- | src/libsyntax/ast_map/blocks.rs | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/src/libsyntax/ast_map/blocks.rs b/src/libsyntax/ast_map/blocks.rs index 8b2b2fbeca1..58627b37a87 100644 --- a/src/libsyntax/ast_map/blocks.rs +++ b/src/libsyntax/ast_map/blocks.rs @@ -96,20 +96,10 @@ impl<'a> Code<'a> { /// Attempts to construct a Code from presumed FnLike or Block node input. pub fn from_node(node: Node) -> Option<Code> { - fn new(node: Node) -> FnLikeNode { FnLikeNode { node: node } } - match node { - ast_map::NodeItem(item) if item.is_fn_like() => - Some(FnLikeCode(new(node))), - ast_map::NodeTraitItem(tm) if tm.is_fn_like() => - Some(FnLikeCode(new(node))), - ast_map::NodeImplItem(_) => - Some(FnLikeCode(new(node))), - ast_map::NodeExpr(e) if e.is_fn_like() => - Some(FnLikeCode(new(node))), - ast_map::NodeBlock(block) => - Some(BlockCode(block)), - _ => - None, + if let ast_map::NodeBlock(block) = node { + Some(BlockCode(block)) + } else { + FnLikeNode::from_node(node).map(|fn_like| FnLikeCode(fn_like)) } } } @@ -145,6 +135,24 @@ impl<'a> ClosureParts<'a> { } impl<'a> FnLikeNode<'a> { + /// Attempts to construct a FnLikeNode from presumed FnLike node input. + pub fn from_node(node: Node) -> Option<FnLikeNode> { + let fn_like = match node { + ast_map::NodeItem(item) => item.is_fn_like(), + ast_map::NodeTraitItem(tm) => tm.is_fn_like(), + ast_map::NodeImplItem(_) => true, + ast_map::NodeExpr(e) => e.is_fn_like(), + _ => false + }; + if fn_like { + Some(FnLikeNode { + node: node + }) + } else { + None + } + } + pub fn to_fn_parts(self) -> FnParts<'a> { FnParts { decl: self.decl(), |
