Skip to content

Commit

Permalink
Fix multiple expect attribs in impl block
Browse files Browse the repository at this point in the history
Closes #114416
  • Loading branch information
chinedufn committed Aug 8, 2023
1 parent c115ec1 commit b56a049
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,10 @@ impl Handler {
std::mem::take(&mut self.inner.borrow_mut().fulfilled_expectations)
}

pub fn insert_fulfilled_expectation(&self, expectation_id: LintExpectationId) {
self.inner.borrow_mut().fulfilled_expectations.insert(expectation_id);
}

pub fn flush_delayed(&self) {
let mut inner = self.inner.lock();
let bugs = std::mem::replace(&mut inner.delayed_span_bugs, Vec::new());
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_passes/src/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,13 @@ impl<'tcx> DeadVisitor<'tcx> {
}
};

for id in &dead_codes[1..] {
let hir = self.tcx.hir().local_def_id_to_hir_id(*id);
let lint_level = self.tcx.lint_level_at_node(lint::builtin::DEAD_CODE, hir).0;
if let Some(expectation_id) = lint_level.get_expectation_id() {
self.tcx.sess.diagnostic().insert_fulfilled_expectation(expectation_id);
}
}
self.tcx.emit_spanned_lint(
lint,
tcx.hir().local_def_id_to_hir_id(first_id),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// check-pass

#![feature(lint_reasons)]
#![warn(unused)]

struct OneUnused;
struct TwoUnused;

impl OneUnused {
#[expect(unused)]
fn unused() {}
}

impl TwoUnused {
#[expect(unused)]
fn unused1(){}

#[expect(unused)]
fn unused2(){}
}

fn main() {
let _ = OneUnused;
let _ = TwoUnused;
}

0 comments on commit b56a049

Please sign in to comment.