diff --git a/tests/test_expr.rs b/tests/test_expr.rs index 5d529bf144..0bef6a85d2 100644 --- a/tests/test_expr.rs +++ b/tests/test_expr.rs @@ -5,7 +5,7 @@ mod macros; use proc_macro2::{Delimiter, Group, Ident, Punct, Spacing, Span, TokenStream, TokenTree}; use quote::quote; -use syn::{Expr, ExprRange}; +use syn::{Expr, ExprRange, Stmt}; #[test] fn test_expr_parse() { @@ -310,3 +310,32 @@ fn test_ranges() { syn::parse_str::("lo...").unwrap_err(); syn::parse_str::("lo...hi").unwrap_err(); } + +#[test] +fn test_ambiguous_label() { + for stmt in [ + quote! { + return 'label: loop { break 'label 42; }; + }, + quote! { + break ('label: loop { break 'label 42; }); + }, + quote! { + break 1 + 'label: loop { break 'label 42; }; + }, + quote! { + break 'outer 'inner: loop { break 'inner 42; }; + }, + ] { + syn::parse2::(stmt).unwrap(); + } + + for stmt in [ + // Parentheses required. See https://github.com/rust-lang/rust/pull/87026. + quote! { + break 'label: loop { break 'label 42; }; + }, + ] { + syn::parse2::(stmt).unwrap_err(); + } +}