Skip to content

Commit 4349228

Browse files
committed
Don't warn labels beginning with _
1 parent 82cf3a4 commit 4349228

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/librustc_resolve/late.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1767,7 +1767,9 @@ impl<'a, 'b> LateResolutionVisitor<'a, '_> {
17671767

17681768
fn with_resolved_label(&mut self, label: Option<Label>, id: NodeId, f: impl FnOnce(&mut Self)) {
17691769
if let Some(label) = label {
1770-
self.diagnostic_metadata.unused_labels.insert(id, label.ident.span);
1770+
if label.ident.as_str().as_bytes()[1] != b'_' {
1771+
self.diagnostic_metadata.unused_labels.insert(id, label.ident.span);
1772+
}
17711773
self.with_label_rib(NormalRibKind, |this| {
17721774
let ident = label.ident.modern_and_legacy();
17731775
this.label_ribs.last_mut().unwrap().bindings.insert(ident, id);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// check-pass
2+
3+
#![deny(unused_labels)]
4+
5+
fn main() {
6+
// `unused_label` shouldn't warn labels beginning with `_`
7+
'_unused: loop {
8+
break;
9+
}
10+
}

0 commit comments

Comments
 (0)