File tree 4 files changed +71
-2
lines changed
4 files changed +71
-2
lines changed Original file line number Diff line number Diff line change @@ -1733,7 +1733,7 @@ pub(crate) struct ExternItemCannotBeConst {
1733
1733
#[ primary_span]
1734
1734
pub ident_span : Span ,
1735
1735
#[ suggestion( code = "static " , applicability = "machine-applicable" ) ]
1736
- pub const_span : Span ,
1736
+ pub const_span : Option < Span > ,
1737
1737
}
1738
1738
1739
1739
#[ derive( Diagnostic ) ]
Original file line number Diff line number Diff line change @@ -1139,9 +1139,11 @@ impl<'a> Parser<'a> {
1139
1139
Ok ( kind) => kind,
1140
1140
Err ( kind) => match kind {
1141
1141
ItemKind :: Const ( box ConstItem { ty, expr, .. } ) => {
1142
+ let const_span = Some ( span. with_hi ( ident. span . lo ( ) ) )
1143
+ . filter ( |span| span. can_be_used_for_suggestions ( ) ) ;
1142
1144
self . sess . emit_err ( errors:: ExternItemCannotBeConst {
1143
1145
ident_span : ident. span ,
1144
- const_span : span . with_hi ( ident . span . lo ( ) ) ,
1146
+ const_span,
1145
1147
} ) ;
1146
1148
ForeignItemKind :: Static ( ty, Mutability :: Not , expr)
1147
1149
}
Original file line number Diff line number Diff line change
1
+ extern "C" {
2
+ thread_local ! {
3
+ static FOO : u32 = 0 ;
4
+ //~^ error: extern items cannot be `const`
5
+ //~| error: incorrect `static` inside `extern` block
6
+ }
7
+ }
8
+
9
+ macro_rules! hello {
10
+ ( $name: ident) => {
11
+ const $name: ( ) = ( ) ;
12
+ } ;
13
+ }
14
+
15
+ extern "C" {
16
+ hello ! { yes }
17
+ //~^ error: extern items cannot be `const`
18
+ //~| error: incorrect `static` inside `extern` block
19
+ }
20
+
21
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ error: extern items cannot be `const`
2
+ --> $DIR/issue-116203.rs:3:14
3
+ |
4
+ LL | static FOO: u32 = 0;
5
+ | ^^^
6
+ |
7
+ = note: for more information, visit https://doc.rust-lang.org/std/keyword.extern.html
8
+
9
+ error: extern items cannot be `const`
10
+ --> $DIR/issue-116203.rs:16:14
11
+ |
12
+ LL | hello! { yes }
13
+ | ^^^
14
+ |
15
+ = note: for more information, visit https://doc.rust-lang.org/std/keyword.extern.html
16
+
17
+ error: incorrect `static` inside `extern` block
18
+ --> $DIR/issue-116203.rs:3:14
19
+ |
20
+ LL | extern "C" {
21
+ | ---------- `extern` blocks define existing foreign statics and statics inside of them cannot have a body
22
+ LL | / thread_local! {
23
+ LL | | static FOO: u32 = 0;
24
+ | | ^^^ cannot have a body
25
+ LL | |
26
+ LL | |
27
+ LL | | }
28
+ | |_____- the invalid body
29
+ |
30
+ = note: for more information, visit https://doc.rust-lang.org/std/keyword.extern.html
31
+
32
+ error: incorrect `static` inside `extern` block
33
+ --> $DIR/issue-116203.rs:16:14
34
+ |
35
+ LL | const $name: () = ();
36
+ | -- the invalid body
37
+ ...
38
+ LL | extern "C" {
39
+ | ---------- `extern` blocks define existing foreign statics and statics inside of them cannot have a body
40
+ LL | hello! { yes }
41
+ | ^^^ cannot have a body
42
+ |
43
+ = note: for more information, visit https://doc.rust-lang.org/std/keyword.extern.html
44
+
45
+ error: aborting due to 4 previous errors
46
+
You can’t perform that action at this time.
0 commit comments