Skip to content

Commit 106b16c

Browse files
Add support for static EIIs in late resolution
1 parent 1f2b090 commit 106b16c

5 files changed

Lines changed: 26 additions & 13 deletions

File tree

compiler/rustc_resolve/src/late.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -530,9 +530,8 @@ impl PathSource<'_, '_, '_> {
530530
},
531531
_ => "value",
532532
},
533-
PathSource::ReturnTypeNotation
534-
| PathSource::Delegation
535-
| PathSource::ExternItemImpl => "function",
533+
PathSource::ReturnTypeNotation | PathSource::Delegation => "function",
534+
PathSource::ExternItemImpl => "function or static",
536535
PathSource::PreciseCapturingArg(..) => "type or const parameter",
537536
PathSource::Macro => "macro",
538537
PathSource::Module => "module",
@@ -625,7 +624,13 @@ impl PathSource<'_, '_, '_> {
625624
},
626625
PathSource::Delegation => matches!(res, Res::Def(DefKind::Fn | DefKind::AssocFn, _)),
627626
PathSource::ExternItemImpl => {
628-
matches!(res, Res::Def(DefKind::Fn | DefKind::AssocFn | DefKind::Ctor(..), _))
627+
matches!(
628+
res,
629+
Res::Def(
630+
DefKind::Fn | DefKind::AssocFn | DefKind::Ctor(..) | DefKind::Static { .. },
631+
_
632+
)
633+
)
629634
}
630635
PathSource::PreciseCapturingArg(ValueNS) => {
631636
matches!(res, Res::Def(DefKind::ConstParam, _))
@@ -5500,7 +5505,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
55005505
*node_id,
55015506
&None,
55025507
&target.foreign_item,
5503-
PathSource::ExternItemImpl
5508+
PathSource::ExternItemImpl,
55045509
);
55055510
} else {
55065511
self.smart_resolve_path(*node_id, &None, &eii_macro_path, PathSource::Macro);

tests/ui/eii/eii-declaration-not-fn-issue-152337.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
const A: () = ();
77
#[eii]
88
fn A() {} //~ ERROR the name `A` is defined multiple times
9-
//~^ ERROR expected function, found constant
10-
//~| ERROR expected function, found constant
9+
//~^ ERROR expected function or static, found constant
10+
//~| ERROR expected function or static, found constant
1111

1212
fn main() {}

tests/ui/eii/eii-declaration-not-fn-issue-152337.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ LL | fn A() {}
99
|
1010
= note: `A` must be defined only once in the value namespace of this module
1111

12-
error[E0423]: expected function, found constant `self::A`
12+
error[E0423]: expected function or static, found constant `self::A`
1313
--> $DIR/eii-declaration-not-fn-issue-152337.rs:8:4
1414
|
1515
LL | fn A() {}
16-
| ^ not a function
16+
| ^ not a function or static
1717

18-
error[E0423]: expected function, found constant `A`
18+
error[E0423]: expected function or static, found constant `A`
1919
--> $DIR/eii-declaration-not-fn-issue-152337.rs:8:4
2020
|
2121
LL | fn A() {}
22-
| ^ not a function
22+
| ^ not a function or static
2323

2424
error: aborting due to 3 previous errors
2525

tests/ui/eii/static/multiple_decls.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const A: () = ();
44
#[eii(A)]
55
static A: u64;
66
//~^ ERROR the name `A` is defined multiple times
7+
//~| ERROR expected function or static, found constant `A`
78

89
#[A]
910
static A_IMPL: u64 = 5;

tests/ui/eii/static/multiple_decls.stderr

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ LL | static A: u64;
99
|
1010
= note: `A` must be defined only once in the value namespace of this module
1111

12-
error: aborting due to 1 previous error
12+
error[E0423]: expected function or static, found constant `A`
13+
--> $DIR/multiple_decls.rs:5:8
14+
|
15+
LL | static A: u64;
16+
| ^ not a function or static
17+
18+
error: aborting due to 2 previous errors
1319

14-
For more information about this error, try `rustc --explain E0428`.
20+
Some errors have detailed explanations: E0423, E0428.
21+
For more information about an error, try `rustc --explain E0423`.

0 commit comments

Comments
 (0)