From 106b16cd2d9e64b950924be6469fdc0854eb3515 Mon Sep 17 00:00:00 2001 From: Jonathan Brouwer Date: Sun, 12 Apr 2026 11:06:40 +0200 Subject: [PATCH] Add support for static EIIs in late resolution --- compiler/rustc_resolve/src/late.rs | 15 ++++++++++----- .../ui/eii/eii-declaration-not-fn-issue-152337.rs | 4 ++-- .../eii-declaration-not-fn-issue-152337.stderr | 8 ++++---- tests/ui/eii/static/multiple_decls.rs | 1 + tests/ui/eii/static/multiple_decls.stderr | 11 +++++++++-- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 540e7ec52f51..56e26b1ac6cb 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -530,9 +530,8 @@ fn descr_expected(self) -> &'static str { }, _ => "value", }, - PathSource::ReturnTypeNotation - | PathSource::Delegation - | PathSource::ExternItemImpl => "function", + PathSource::ReturnTypeNotation | PathSource::Delegation => "function", + PathSource::ExternItemImpl => "function or static", PathSource::PreciseCapturingArg(..) => "type or const parameter", PathSource::Macro => "macro", PathSource::Module => "module", @@ -625,7 +624,13 @@ pub(crate) fn is_expected(self, res: Res) -> bool { }, PathSource::Delegation => matches!(res, Res::Def(DefKind::Fn | DefKind::AssocFn, _)), PathSource::ExternItemImpl => { - matches!(res, Res::Def(DefKind::Fn | DefKind::AssocFn | DefKind::Ctor(..), _)) + matches!( + res, + Res::Def( + DefKind::Fn | DefKind::AssocFn | DefKind::Ctor(..) | DefKind::Static { .. }, + _ + ) + ) } PathSource::PreciseCapturingArg(ValueNS) => { matches!(res, Res::Def(DefKind::ConstParam, _)) @@ -5500,7 +5505,7 @@ fn resolve_eii(&mut self, eii_impls: &[EiiImpl]) { *node_id, &None, &target.foreign_item, - PathSource::ExternItemImpl + PathSource::ExternItemImpl, ); } else { self.smart_resolve_path(*node_id, &None, &eii_macro_path, PathSource::Macro); diff --git a/tests/ui/eii/eii-declaration-not-fn-issue-152337.rs b/tests/ui/eii/eii-declaration-not-fn-issue-152337.rs index 8564a5a74847..0d71f4854d34 100644 --- a/tests/ui/eii/eii-declaration-not-fn-issue-152337.rs +++ b/tests/ui/eii/eii-declaration-not-fn-issue-152337.rs @@ -6,7 +6,7 @@ const A: () = (); #[eii] fn A() {} //~ ERROR the name `A` is defined multiple times -//~^ ERROR expected function, found constant -//~| ERROR expected function, found constant +//~^ ERROR expected function or static, found constant +//~| ERROR expected function or static, found constant fn main() {} diff --git a/tests/ui/eii/eii-declaration-not-fn-issue-152337.stderr b/tests/ui/eii/eii-declaration-not-fn-issue-152337.stderr index ea4ec604e7aa..34998f33cc92 100644 --- a/tests/ui/eii/eii-declaration-not-fn-issue-152337.stderr +++ b/tests/ui/eii/eii-declaration-not-fn-issue-152337.stderr @@ -9,17 +9,17 @@ LL | fn A() {} | = note: `A` must be defined only once in the value namespace of this module -error[E0423]: expected function, found constant `self::A` +error[E0423]: expected function or static, found constant `self::A` --> $DIR/eii-declaration-not-fn-issue-152337.rs:8:4 | LL | fn A() {} - | ^ not a function + | ^ not a function or static -error[E0423]: expected function, found constant `A` +error[E0423]: expected function or static, found constant `A` --> $DIR/eii-declaration-not-fn-issue-152337.rs:8:4 | LL | fn A() {} - | ^ not a function + | ^ not a function or static error: aborting due to 3 previous errors diff --git a/tests/ui/eii/static/multiple_decls.rs b/tests/ui/eii/static/multiple_decls.rs index 1913dc39e8b7..791e2725087f 100644 --- a/tests/ui/eii/static/multiple_decls.rs +++ b/tests/ui/eii/static/multiple_decls.rs @@ -4,6 +4,7 @@ #[eii(A)] static A: u64; //~^ ERROR the name `A` is defined multiple times +//~| ERROR expected function or static, found constant `A` #[A] static A_IMPL: u64 = 5; diff --git a/tests/ui/eii/static/multiple_decls.stderr b/tests/ui/eii/static/multiple_decls.stderr index b0b5da1aabe1..fcc5d93c5f99 100644 --- a/tests/ui/eii/static/multiple_decls.stderr +++ b/tests/ui/eii/static/multiple_decls.stderr @@ -9,6 +9,13 @@ LL | static A: u64; | = note: `A` must be defined only once in the value namespace of this module -error: aborting due to 1 previous error +error[E0423]: expected function or static, found constant `A` + --> $DIR/multiple_decls.rs:5:8 + | +LL | static A: u64; + | ^ not a function or static -For more information about this error, try `rustc --explain E0428`. +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0423, E0428. +For more information about an error, try `rustc --explain E0423`.