Skip to content

Commit 4762e22

Browse files
authored
Rollup merge of #71517 - flip1995:unused_braces_hack, r=oli-obk
Quick and dirty fix of the unused_braces lint cc @lcnr Adresses #70814 This at least prevents lint output, if no span is available. Even though this also prevents the `unused_parens` lint from emitting, when the `DUMMY_SP` is used there, but I think that should be ok, since error messages without a span are quite useless anyway. Clippy CI is currently blocked on this bug. If this quick and dirty fix should be rejected, I could try to work around this in Clippy. r? @shepmaster
2 parents 6ded356 + 485f199 commit 4762e22

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/librustc_lint/unused.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_middle::ty::{self, Ty};
1616
use rustc_session::lint::builtin::UNUSED_ATTRIBUTES;
1717
use rustc_span::symbol::Symbol;
1818
use rustc_span::symbol::{kw, sym};
19-
use rustc_span::{BytePos, Span};
19+
use rustc_span::{BytePos, Span, DUMMY_SP};
2020

2121
use log::debug;
2222

@@ -415,6 +415,12 @@ trait UnusedDelimLint {
415415
msg: &str,
416416
keep_space: (bool, bool),
417417
) {
418+
// FIXME(flip1995): Quick and dirty fix for #70814. This should be fixed in rustdoc
419+
// properly.
420+
if span == DUMMY_SP {
421+
return;
422+
}
423+
418424
cx.struct_span_lint(self.lint(), span, |lint| {
419425
let span_msg = format!("unnecessary {} around {}", Self::DELIM_STR, msg);
420426
let mut err = lint.build(&span_msg);
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// check-pass
2+
3+
// This tests the bug in #70814, where the unused_braces lint triggered on the following code
4+
// without providing a span.
5+
6+
#![deny(unused_braces)]
7+
8+
fn main() {
9+
{
10+
{
11+
use std;
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)