Skip to content

Fix ICE on debug builds where lints are delayed on the crate root #142892

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

Merged
merged 2 commits into from
Jun 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 9 additions & 1 deletion compiler/rustc_middle/src/hir/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1254,10 +1254,18 @@ pub(crate) fn hir_crate_items(tcx: TyCtxt<'_>, _: ()) -> ModuleItems {
body_owners,
opaques,
nested_bodies,
delayed_lint_items,
mut delayed_lint_items,
..
} = collector;

// The crate could have delayed lints too, but would not be picked up by the visitor.
// The `delayed_lint_items` list is smart - it only contains items which we know from
// earlier passes is guaranteed to contain lints. It's a little harder to determine that
// for sure here, so we simply always add the crate to the list. If it has no lints,
// we'll discover that later. The cost of this should be low, there's only one crate
// after all compared to the many items we have we wouldn't want to iterate over later.
delayed_lint_items.push(CRATE_OWNER_ID);

ModuleItems {
add_root: true,
submodules: submodules.into_boxed_slice(),
Expand Down
7 changes: 7 additions & 0 deletions tests/ui/attributes/lint_on_root.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// NOTE: this used to panic in debug builds (by a sanity assertion)
// and not emit any lint on release builds. See https://github.com/rust-lang/rust/issues/142891.
#![inline = ""]
//~^ ERROR valid forms for the attribute are `#[inline(always|never)]` and `#[inline]`
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

fn main() {}
12 changes: 12 additions & 0 deletions tests/ui/attributes/lint_on_root.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error: valid forms for the attribute are `#[inline(always|never)]` and `#[inline]`
--> $DIR/lint_on_root.rs:3:1
|
LL | #![inline = ""]
| ^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
= note: `#[deny(ill_formed_attribute_input)]` on by default

error: aborting due to 1 previous error

Loading