Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix incorrect strip r# prefix from labels #6425

Merged
merged 1 commit into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,22 @@ pub(crate) fn format_expr(
}
ast::ExprKind::Continue(ref opt_label) => {
let id_str = match *opt_label {
Some(label) => format!(" {}", label.ident),
Some(label) => {
// Ident lose the `r#` prefix in raw labels, so use the original snippet
let label_name = context.snippet(label.ident.span);
format!(" {}", label_name)
}
None => String::new(),
};
Ok(format!("continue{id_str}"))
}
ast::ExprKind::Break(ref opt_label, ref opt_expr) => {
let id_str = match *opt_label {
Some(label) => format!(" {}", label.ident),
Some(label) => {
// Ident lose the `r#` prefix in raw labels, so use the original snippet
let label_name = context.snippet(label.ident.span);
format!(" {}", label_name)
}
None => String::new(),
};

Expand Down
21 changes: 21 additions & 0 deletions tests/target/issue-6411.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// rustfmt-edition: 2021

fn test_break() {
'r#if: {
break 'r#if;
}

'r#a: {
break 'r#a;
}
}

fn test_continue() {
'r#if: {
continue 'r#if;
}

'r#a: {
continue 'r#a;
}
}
Loading