Skip to content

Commit 8ad46b4

Browse files
committed
Misc progress
1 parent b56a049 commit 8ad46b4

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

compiler/rustc_errors/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,10 +1263,6 @@ 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-
12701266
pub fn flush_delayed(&self) {
12711267
let mut inner = self.inner.lock();
12721268
let bugs = std::mem::replace(&mut inner.delayed_span_bugs, Vec::new());

compiler/rustc_passes/src/dead.rs

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This implements the dead-code warning pass. It follows middle::reachable
1+
// This implements the dead-code warning pass. It follows crate::reachable
22
// closely. The idea is that all reachable symbols are live, codes called
33
// from live codes are live, and everything else is dead.
44

@@ -814,13 +814,15 @@ 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-
}
817+
// FIXME: Remove this before landing the PR.
818+
// Just keeping it around so that I remember how to get the expectation id.
819+
// for id in &dead_codes[1..] {
820+
// let hir = self.tcx.hir().local_def_id_to_hir_id(*id);
821+
// let lint_level = self.tcx.lint_level_at_node(lint::builtin::DEAD_CODE, hir).0;
822+
// if let Some(expectation_id) = lint_level.get_expectation_id() {
823+
// self.tcx.sess.diagnostic().insert_fulfilled_expectation(expectation_id);
824+
// }
825+
// }
824826
self.tcx.emit_spanned_lint(
825827
lint,
826828
tcx.hir().local_def_id_to_hir_id(first_id),
@@ -829,7 +831,7 @@ impl<'tcx> DeadVisitor<'tcx> {
829831
);
830832
}
831833

832-
fn warn_dead_fields_and_variants(
834+
fn warn_dead_code_grouped_by_lint_level(
833835
&self,
834836
def_id: LocalDefId,
835837
participle: &str,
@@ -903,13 +905,21 @@ fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalDefId) {
903905
for item in impl_item.items {
904906
let did = item.id.owner_id.def_id;
905907
if !visitor.is_live_code(did) {
906-
dead_items.push(did)
908+
let name = tcx.item_name(def_id.to_def_id());
909+
let hir = tcx.hir().local_def_id_to_hir_id(did);
910+
let level = tcx.lint_level_at_node(lint::builtin::DEAD_CODE, hir).0;
911+
912+
dead_items.push(DeadVariant {
913+
def_id: did,
914+
name,
915+
level,
916+
})
907917
}
908918
}
909-
visitor.warn_multiple_dead_codes(
910-
&dead_items,
919+
visitor.warn_dead_code_grouped_by_lint_level(
920+
item.owner_id.def_id,
911921
"used",
912-
Some(item.owner_id.def_id),
922+
dead_items,
913923
false,
914924
);
915925
}
@@ -966,10 +976,10 @@ fn check_mod_deathness(tcx: TyCtxt<'_>, module: LocalDefId) {
966976
}
967977
})
968978
.collect();
969-
visitor.warn_dead_fields_and_variants(def_id, "read", dead_fields, is_positional)
979+
visitor.warn_dead_code_grouped_by_lint_level(def_id, "read", dead_fields, is_positional)
970980
}
971981

972-
visitor.warn_dead_fields_and_variants(
982+
visitor.warn_dead_code_grouped_by_lint_level(
973983
item.owner_id.def_id,
974984
"constructed",
975985
dead_variants,

tests/ui/lint/rfc-2383-lint-reason/expect_unused_inside_impl_block.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ impl TwoUnused {
1515
#[expect(unused)]
1616
fn unused1(){}
1717

18+
// Tests a regression where the compiler erroneously determined that all `#[expect(unused)]`
19+
// after the first method in the impl block were unfulfilled.
20+
// issue 114416
1821
#[expect(unused)]
1922
fn unused2(){}
2023
}

0 commit comments

Comments
 (0)