Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multiple expect attribs in impl block #114417

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
chinedufn marked this conversation as resolved.
Show resolved Hide resolved

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);
}
}
chinedufn marked this conversation as resolved.
Show resolved Hide resolved
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
chinedufn marked this conversation as resolved.
Show resolved Hide resolved

#![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;
}
Loading