From 6be14042168ec1c1c8cfbcb6437aa3d44089a5c8 Mon Sep 17 00:00:00 2001 From: Sasha Pourcelot Date: Mon, 6 Apr 2026 07:31:34 +0000 Subject: [PATCH] attr parsing: make sure we pass the right target when errors could be emitted --- compiler/rustc_attr_parsing/src/interface.rs | 4 +++- compiler/rustc_interface/src/passes.rs | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_attr_parsing/src/interface.rs b/compiler/rustc_attr_parsing/src/interface.rs index e9d868039380b..06738b9c73375 100644 --- a/compiler/rustc_attr_parsing/src/interface.rs +++ b/compiler/rustc_attr_parsing/src/interface.rs @@ -64,6 +64,7 @@ impl<'sess> AttributeParser<'sess, Early> { sym, target_span, target_node_id, + Target::Crate, // Does not matter, we're not going to emit errors anyways features, ShouldEmit::Nothing, ) @@ -79,6 +80,7 @@ impl<'sess> AttributeParser<'sess, Early> { sym: Symbol, target_span: Span, target_node_id: NodeId, + target: Target, features: Option<&'sess Features>, should_emit: ShouldEmit, ) -> Option { @@ -86,7 +88,7 @@ impl<'sess> AttributeParser<'sess, Early> { sess, attrs, Some(sym), - Target::Crate, // Does not matter, we're not going to emit errors anyways + target, target_span, target_node_id, features, diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 7ba7fd58081a8..43efce545fc28 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -22,7 +22,7 @@ use rustc_hir::def_id::{LOCAL_CRATE, StableCrateId, StableCrateIdMap}; use rustc_hir::definitions::Definitions; use rustc_hir::limit::Limit; use rustc_hir::lints::DelayedLint; -use rustc_hir::{Attribute, MaybeOwner, find_attr}; +use rustc_hir::{Attribute, MaybeOwner, Target, find_attr}; use rustc_incremental::setup_dep_graph; use rustc_lint::{ BufferedEarlyLint, DecorateAttrLint, EarlyCheckNode, LintStore, unerased_lint_store, @@ -1372,6 +1372,7 @@ pub(crate) fn parse_crate_name( sym::crate_name, DUMMY_SP, rustc_ast::node_id::CRATE_NODE_ID, + Target::Crate, None, emit_errors, )? @@ -1421,6 +1422,7 @@ pub fn collect_crate_types( sym::crate_type, crate_span, CRATE_NODE_ID, + Target::Crate, None, ShouldEmit::EarlyFatal { also_emit_lints: false }, ) @@ -1477,6 +1479,7 @@ fn get_recursion_limit(krate_attrs: &[ast::Attribute], sess: &Session) -> Limit sym::recursion_limit, DUMMY_SP, rustc_ast::node_id::CRATE_NODE_ID, + Target::Crate, None, // errors are fatal here, but lints aren't. // If things aren't fatal we continue, and will parse this again.