diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2018-01-25 12:48:49 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-01-25 12:48:49 -0600 |
| commit | 98b375483c44c68009d699a4cd4b7b0a3d5d97a3 (patch) | |
| tree | 1cba42b1aa98db0d012cbecfb36d7d2dea428232 /src/libsyntax/ast.rs | |
| parent | 304885d959cae6b1fd6cb9aa64b70df6269d04b4 (diff) | |
| parent | 2d56abfbebdc905dafc9cf9edc0a6f58e4de7cbd (diff) | |
| download | rust-98b375483c44c68009d699a4cd4b7b0a3d5d97a3.tar.gz rust-98b375483c44c68009d699a4cd4b7b0a3d5d97a3.zip | |
Rollup merge of #47502 - petrochenkov:label, r=eddyb
AST/HIR: Add a separate structure for labels
Diffstat (limited to 'src/libsyntax/ast.rs')
| -rw-r--r-- | src/libsyntax/ast.rs | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index d6e26057ea8..73810b3fe81 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -34,6 +34,18 @@ use std::rc::Rc; use std::u32; #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)] +pub struct Label { + pub ident: Ident, + pub span: Span, +} + +impl fmt::Debug for Label { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "label({:?})", self.ident) + } +} + +#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Copy)] pub struct Lifetime { pub id: NodeId, pub span: Span, @@ -1078,23 +1090,23 @@ pub enum ExprKind { /// A while loop, with an optional label /// /// `'label: while expr { block }` - While(P<Expr>, P<Block>, Option<SpannedIdent>), + While(P<Expr>, P<Block>, Option<Label>), /// A while-let loop, with an optional label /// /// `'label: while let pat = expr { block }` /// /// This is desugared to a combination of `loop` and `match` expressions. - WhileLet(P<Pat>, P<Expr>, P<Block>, Option<SpannedIdent>), + WhileLet(P<Pat>, P<Expr>, P<Block>, Option<Label>), /// A for loop, with an optional label /// /// `'label: for pat in expr { block }` /// /// This is desugared to a combination of `loop` and `match` expressions. - ForLoop(P<Pat>, P<Expr>, P<Block>, Option<SpannedIdent>), + ForLoop(P<Pat>, P<Expr>, P<Block>, Option<Label>), /// Conditionless loop (can be exited with break, continue, or return) /// /// `'label: loop { block }` - Loop(P<Block>, Option<SpannedIdent>), + Loop(P<Block>, Option<Label>), /// A `match` block. Match(P<Expr>, Vec<Arm>), /// A closure (for example, `move |a, b, c| a + b + c`) @@ -1133,9 +1145,9 @@ pub enum ExprKind { /// A referencing operation (`&a` or `&mut a`) AddrOf(Mutability, P<Expr>), /// A `break`, with an optional label to break, and an optional expression - Break(Option<SpannedIdent>, Option<P<Expr>>), + Break(Option<Label>, Option<P<Expr>>), /// A `continue`, with an optional label - Continue(Option<SpannedIdent>), + Continue(Option<Label>), /// A `return`, with an optional value to be returned Ret(Option<P<Expr>>), |
