Skip to content

Commit

Permalink
Rollup merge of rust-lang#66419 - JohnTitor:ignore-underscore, r=varkor
Browse files Browse the repository at this point in the history
Don't warn labels beginning with `_` on unused_labels lint

Fixes rust-lang#66382

r? @varkor
  • Loading branch information
JohnTitor committed Nov 15, 2019
2 parents fc8a76e + 4349228 commit 175f296
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 175f296

Please sign in to comment.