Skip to content

Commit b56a049

Browse files
committed
Fix multiple expect attribs in impl block
Closes #114416
1 parent c115ec1 commit b56a049

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

compiler/rustc_errors/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,10 @@ impl Handler {
12631263
std::mem::take(&mut self.inner.borrow_mut().fulfilled_expectations)
12641264
}
12651265

1266+
pub fn insert_fulfilled_expectation(&self, expectation_id: LintExpectationId) {
1267+
self.inner.borrow_mut().fulfilled_expectations.insert(expectation_id);
1268+
}
1269+
12661270
pub fn flush_delayed(&self) {
12671271
let mut inner = self.inner.lock();
12681272
let bugs = std::mem::replace(&mut inner.delayed_span_bugs, Vec::new());

compiler/rustc_passes/src/dead.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,13 @@ impl<'tcx> DeadVisitor<'tcx> {
814814
}
815815
};
816816

817+
for id in &dead_codes[1..] {
818+
let hir = self.tcx.hir().local_def_id_to_hir_id(*id);
819+
let lint_level = self.tcx.lint_level_at_node(lint::builtin::DEAD_CODE, hir).0;
820+
if let Some(expectation_id) = lint_level.get_expectation_id() {
821+
self.tcx.sess.diagnostic().insert_fulfilled_expectation(expectation_id);
822+
}
823+
}
817824
self.tcx.emit_spanned_lint(
818825
lint,
819826
tcx.hir().local_def_id_to_hir_id(first_id),
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// check-pass
2+
3+
#![feature(lint_reasons)]
4+
#![warn(unused)]
5+
6+
struct OneUnused;
7+
struct TwoUnused;
8+
9+
impl OneUnused {
10+
#[expect(unused)]
11+
fn unused() {}
12+
}
13+
14+
impl TwoUnused {
15+
#[expect(unused)]
16+
fn unused1(){}
17+
18+
#[expect(unused)]
19+
fn unused2(){}
20+
}
21+
22+
fn main() {
23+
let _ = OneUnused;
24+
let _ = TwoUnused;
25+
}

0 commit comments

Comments
 (0)