Skip to content

Commit eed7d10

Browse files
Fix ICE when using attributes on delegation items
Delegation items are skipped by `hir_walk_toplevel_module` (via `visit_if_delayed`), so they were never added to `delayed_lint_items`. This caused a debug assertion failure in `emit_ast_lowering_delayed_lints` when an attribute like `#[deprecated]` generated a delayed lint on the item. The FIXME in `ItemCollector::new` already noted this gap.
1 parent c7c14d4 commit eed7d10

3 files changed

Lines changed: 33 additions & 1 deletion

File tree

compiler/rustc_middle/src/hir/map.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1335,7 +1335,7 @@ impl<'tcx> ItemCollector<'tcx> {
13351335
let delayed_kinds =
13361336
krate.delayed_ids.iter().copied().map(|id| (id, krate.owners[id].expect_delayed()));
13371337

1338-
// FIXME(fn_delegation): need to add delayed lints, eiis
1338+
// FIXME(fn_delegation): need to add eiis
13391339
for (def_id, kind) in delayed_kinds {
13401340
let owner_id = OwnerId { def_id };
13411341

@@ -1350,6 +1350,9 @@ impl<'tcx> ItemCollector<'tcx> {
13501350
};
13511351

13521352
collector.body_owners.push(def_id);
1353+
// Delegation items are skipped by the HIR walk (see `visit_if_delayed`),
1354+
// so we have to account for their delayed lints manually.
1355+
collector.delayed_lint_items.push(owner_id);
13531356
}
13541357
}
13551358

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// https://github.com/rust-lang/rust/issues/155127
2+
3+
#![feature(fn_delegation)]
4+
#![allow(incomplete_features)]
5+
6+
struct S;
7+
8+
fn foo() {}
9+
10+
impl S {
11+
#[deprecated]
12+
//~^ ERROR `#[deprecated]` attribute cannot be used on delegations
13+
//~| WARN this was previously accepted by the compiler but is being phased out
14+
reuse foo;
15+
}
16+
17+
fn main() {}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error: `#[deprecated]` attribute cannot be used on delegations
2+
--> $DIR/ice-issue-155127.rs:11:5
3+
|
4+
LL | #[deprecated]
5+
| ^^^^^^^^^^^^^
6+
|
7+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8+
= help: `#[deprecated]` can be applied to associated consts, associated types, constants, crates, data types, enum variants, foreign statics, functions, inherent impl blocks, macro defs, modules, statics, struct fields, traits, type aliases, and use statements
9+
= note: `#[deny(useless_deprecated)]` on by default
10+
11+
error: aborting due to 1 previous error
12+

0 commit comments

Comments
 (0)