Skip to content

Commit 99f9bea

Browse files
authored
Rollup merge of #155949 - GuillaumeGomez:steal-lints, r=JonathanBrouwer,kivooeo
Update `opt_ast_lowering_delayed_lints` query to allow "stealing" lints, allowing to use `FnOnce` instead of `Fn` Part of #153099. This is needed for https://github.com/rust-lang/rust/compare/main...GuillaumeGomez:rust:diagnostic-instead-of-closure?expand=1 which will allow to pass `Diagnostic` instead of a closure. As asked by @JonathanBrouwer, I make this as a stand-alone PR. :) r? @JonathanBrouwer
2 parents 552dad3 + fffc4b5 commit 99f9bea

4 files changed

Lines changed: 6 additions & 5 deletions

File tree

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
765765
let mut bodies = std::mem::take(&mut self.bodies);
766766
let define_opaque = std::mem::take(&mut self.define_opaque);
767767
let trait_map = std::mem::take(&mut self.trait_map);
768-
let delayed_lints = std::mem::take(&mut self.delayed_lints).into_boxed_slice();
768+
let delayed_lints = Steal::new(std::mem::take(&mut self.delayed_lints).into_boxed_slice());
769769

770770
#[cfg(debug_assertions)]
771771
for (id, attrs) in attrs.iter() {

compiler/rustc_hir/src/hir.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub use rustc_ast::{
1818
};
1919
use rustc_data_structures::fingerprint::Fingerprint;
2020
use rustc_data_structures::sorted_map::SortedMap;
21+
use rustc_data_structures::steal::Steal;
2122
use rustc_data_structures::tagged_ptr::TaggedRef;
2223
use rustc_error_messages::{DiagArgValue, IntoDiagArg};
2324
use rustc_index::IndexVec;
@@ -1636,7 +1637,7 @@ pub struct OwnerInfo<'hir> {
16361637
/// WARNING: The delayed lints are not hashed as a part of the `OwnerInfo`, and therefore
16371638
/// should only be accessed in `eval_always` queries.
16381639
#[stable_hasher(ignore)]
1639-
pub delayed_lints: DelayedLints,
1640+
pub delayed_lints: Steal<DelayedLints>,
16401641
}
16411642

16421643
impl<'tcx> OwnerInfo<'tcx> {

compiler/rustc_interface/src/passes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ impl<'a, 'b, 'tcx> Diagnostic<'a, ()> for DiagCallback<'b, 'tcx> {
10411041
pub fn emit_delayed_lints(tcx: TyCtxt<'_>) {
10421042
for owner_id in tcx.hir_crate_items(()).delayed_lint_items() {
10431043
if let Some(delayed_lints) = tcx.opt_ast_lowering_delayed_lints(owner_id) {
1044-
for lint in delayed_lints {
1044+
for lint in delayed_lints.steal() {
10451045
tcx.emit_node_span_lint(
10461046
lint.lint_id.lint,
10471047
lint.id,
@@ -1117,7 +1117,7 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
11171117
let hir_items = tcx.hir_crate_items(());
11181118
for owner_id in hir_items.owners() {
11191119
if let Some(delayed_lints) = tcx.opt_ast_lowering_delayed_lints(owner_id)
1120-
&& !delayed_lints.is_empty()
1120+
&& !delayed_lints.borrow().is_empty()
11211121
{
11221122
// Assert that delayed_lint_items also picked up this item to have lints.
11231123
assert!(hir_items.delayed_lint_items().any(|i| i == owner_id));

compiler/rustc_middle/src/queries.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ rustc_queries! {
274274
///
275275
/// This can be conveniently accessed by `tcx.hir_*` methods.
276276
/// Avoid calling this query directly.
277-
query opt_ast_lowering_delayed_lints(key: hir::OwnerId) -> Option<&'tcx hir::lints::DelayedLints> {
277+
query opt_ast_lowering_delayed_lints(key: hir::OwnerId) -> Option<&'tcx Steal<hir::lints::DelayedLints>> {
278278
desc { "getting AST lowering delayed lints in `{}`", tcx.def_path_str(key) }
279279
// This query has to be `no_hash` and `eval_always`,
280280
// because it accesses `delayed_lints` which is not hashed as part of the HIR

0 commit comments

Comments
 (0)