Skip to content

Commit

Permalink
Don't warn labels beginning with _
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnTitor committed Nov 14, 2019
1 parent 82cf3a4 commit 4349228
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/librustc_resolve/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1767,7 +1767,9 @@ impl<'a, 'b> LateResolutionVisitor<'a, '_> {

fn with_resolved_label(&mut self, label: Option<Label>, id: NodeId, f: impl FnOnce(&mut Self)) {
if let Some(label) = label {
self.diagnostic_metadata.unused_labels.insert(id, label.ident.span);
if label.ident.as_str().as_bytes()[1] != b'_' {
self.diagnostic_metadata.unused_labels.insert(id, label.ident.span);
}
self.with_label_rib(NormalRibKind, |this| {
let ident = label.ident.modern_and_legacy();
this.label_ribs.last_mut().unwrap().bindings.insert(ident, id);
Expand Down
10 changes: 10 additions & 0 deletions src/test/ui/label/label-beginning-with-underscore.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// check-pass

#![deny(unused_labels)]

fn main() {
// `unused_label` shouldn't warn labels beginning with `_`
'_unused: loop {
break;
}
}

0 comments on commit 4349228

Please sign in to comment.