File tree 4 files changed +41
-2
lines changed
4 files changed +41
-2
lines changed Original file line number Diff line number Diff line change @@ -1621,7 +1621,7 @@ pub(crate) struct ExternItemCannotBeConst {
1621
1621
#[ primary_span]
1622
1622
pub ident_span : Span ,
1623
1623
#[ suggestion( code = "static " , applicability = "machine-applicable" ) ]
1624
- pub const_span : Span ,
1624
+ pub const_span : Option < Span > ,
1625
1625
}
1626
1626
1627
1627
#[ derive( Diagnostic ) ]
Original file line number Diff line number Diff line change @@ -1142,9 +1142,14 @@ impl<'a> Parser<'a> {
1142
1142
Ok ( kind) => kind,
1143
1143
Err ( kind) => match kind {
1144
1144
ItemKind :: Const ( box ConstItem { ty, expr, .. } ) => {
1145
+ let const_span = self
1146
+ . sess
1147
+ . source_map ( )
1148
+ . is_span_accessible ( span)
1149
+ . then_some ( span. with_hi ( ident. span . lo ( ) ) ) ;
1145
1150
self . sess . emit_err ( errors:: ExternItemCannotBeConst {
1146
1151
ident_span : ident. span ,
1147
- const_span : span . with_hi ( ident . span . lo ( ) ) ,
1152
+ const_span,
1148
1153
} ) ;
1149
1154
ForeignItemKind :: Static ( ty, Mutability :: Not , expr)
1150
1155
}
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
+ 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: incorrect `static` inside `extern` block
10
+ --> $DIR/issue-116203.rs:3:14
11
+ |
12
+ LL | extern "C" {
13
+ | ---------- `extern` blocks define existing foreign statics and statics inside of them cannot have a body
14
+ LL | / thread_local! {
15
+ LL | | static FOO: u32 = 0;
16
+ | | ^^^ cannot have a body
17
+ LL | |
18
+ LL | |
19
+ LL | | }
20
+ | |_____- the invalid body
21
+ |
22
+ = note: for more information, visit https://doc.rust-lang.org/std/keyword.extern.html
23
+
24
+ error: aborting due to 2 previous errors
25
+
You can’t perform that action at this time.
0 commit comments