Skip to content

Commit 4a07b2b

Browse files
committed
Auto merge of rust-lang#113557 - Amanieu:no-builtins-prelude, r=petrochenkov
Hide `compiler_builtins` in the prelude This crate is a private implementation detail. We only need to insert it into the crate graph for linking and should not expose any of its public API. Fixes rust-lang#113533
2 parents 55be59d + 07f855d commit 4a07b2b

23 files changed

+347
-344
lines changed

compiler/rustc_builtin_macros/src/standard_library_imports.rs

+18-9
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,29 @@ pub fn inject(
4444

4545
// .rev() to preserve ordering above in combination with insert(0, ...)
4646
for &name in names.iter().rev() {
47-
let ident = if edition >= Edition2018 {
48-
Ident::new(name, span)
47+
let ident_span = if edition >= Edition2018 { span } else { call_site };
48+
let item = if name == sym::compiler_builtins {
49+
// compiler_builtins is a private implementation detail. We only
50+
// need to insert it into the crate graph for linking and should not
51+
// expose any of its public API.
52+
//
53+
// FIXME(#113634) We should inject this during post-processing like
54+
// we do for the panic runtime, profiler runtime, etc.
55+
cx.item(
56+
span,
57+
Ident::new(kw::Underscore, ident_span),
58+
thin_vec![],
59+
ast::ItemKind::ExternCrate(Some(name)),
60+
)
4961
} else {
50-
Ident::new(name, call_site)
51-
};
52-
krate.items.insert(
53-
0,
5462
cx.item(
5563
span,
56-
ident,
64+
Ident::new(name, ident_span),
5765
thin_vec![cx.attr_word(sym::macro_use, span)],
5866
ast::ItemKind::ExternCrate(None),
59-
),
60-
);
67+
)
68+
};
69+
krate.items.insert(0, item);
6170
}
6271

6372
// The crates have been injected, the assumption is that the first one is

tests/ui/proc-macro/allowed-attr-stmt-expr.stdout

+6-6
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
1919
Punct {
2020
ch: '#',
2121
spacing: Alone,
22-
span: $DIR/allowed-attr-stmt-expr.rs:35:9: 35:10 (#11),
22+
span: $DIR/allowed-attr-stmt-expr.rs:35:9: 35:10 (#10),
2323
},
2424
Group {
2525
delimiter: Bracket,
2626
stream: TokenStream [
2727
Ident {
2828
ident: "rustc_dummy",
29-
span: $DIR/allowed-attr-stmt-expr.rs:35:11: 35:22 (#11),
29+
span: $DIR/allowed-attr-stmt-expr.rs:35:11: 35:22 (#10),
3030
},
3131
],
32-
span: $DIR/allowed-attr-stmt-expr.rs:35:10: 35:23 (#11),
32+
span: $DIR/allowed-attr-stmt-expr.rs:35:10: 35:23 (#10),
3333
},
3434
Ident {
3535
ident: "struct",
@@ -206,17 +206,17 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
206206
Punct {
207207
ch: '#',
208208
spacing: Alone,
209-
span: $DIR/allowed-attr-stmt-expr.rs:35:9: 35:10 (#32),
209+
span: $DIR/allowed-attr-stmt-expr.rs:35:9: 35:10 (#31),
210210
},
211211
Group {
212212
delimiter: Bracket,
213213
stream: TokenStream [
214214
Ident {
215215
ident: "rustc_dummy",
216-
span: $DIR/allowed-attr-stmt-expr.rs:35:11: 35:22 (#32),
216+
span: $DIR/allowed-attr-stmt-expr.rs:35:11: 35:22 (#31),
217217
},
218218
],
219-
span: $DIR/allowed-attr-stmt-expr.rs:35:10: 35:23 (#32),
219+
span: $DIR/allowed-attr-stmt-expr.rs:35:10: 35:23 (#31),
220220
},
221221
Punct {
222222
ch: '#',

tests/ui/proc-macro/attr-stmt-expr.stdout

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
33
Punct {
44
ch: '#',
55
spacing: Alone,
6-
span: $DIR/attr-stmt-expr.rs:33:9: 33:10 (#8),
6+
span: $DIR/attr-stmt-expr.rs:33:9: 33:10 (#7),
77
},
88
Group {
99
delimiter: Bracket,
1010
stream: TokenStream [
1111
Ident {
1212
ident: "rustc_dummy",
13-
span: $DIR/attr-stmt-expr.rs:33:11: 33:22 (#8),
13+
span: $DIR/attr-stmt-expr.rs:33:11: 33:22 (#7),
1414
},
1515
],
16-
span: $DIR/attr-stmt-expr.rs:33:10: 33:23 (#8),
16+
span: $DIR/attr-stmt-expr.rs:33:10: 33:23 (#7),
1717
},
1818
Ident {
1919
ident: "struct",
@@ -190,17 +190,17 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
190190
Punct {
191191
ch: '#',
192192
spacing: Alone,
193-
span: $DIR/attr-stmt-expr.rs:33:9: 33:10 (#29),
193+
span: $DIR/attr-stmt-expr.rs:33:9: 33:10 (#28),
194194
},
195195
Group {
196196
delimiter: Bracket,
197197
stream: TokenStream [
198198
Ident {
199199
ident: "rustc_dummy",
200-
span: $DIR/attr-stmt-expr.rs:33:11: 33:22 (#29),
200+
span: $DIR/attr-stmt-expr.rs:33:11: 33:22 (#28),
201201
},
202202
],
203-
span: $DIR/attr-stmt-expr.rs:33:10: 33:23 (#29),
203+
span: $DIR/attr-stmt-expr.rs:33:10: 33:23 (#28),
204204
},
205205
Punct {
206206
ch: '#',

tests/ui/proc-macro/capture-macro-rules-invoke.stdout

+21-21
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
88
span: $DIR/capture-macro-rules-invoke.rs:36:24: 36:28 (#0),
99
},
1010
],
11-
span: $DIR/capture-macro-rules-invoke.rs:21:21: 21:26 (#4),
11+
span: $DIR/capture-macro-rules-invoke.rs:21:21: 21:26 (#3),
1212
},
1313
]
1414
PRINT-BANG INPUT (DISPLAY): 1 + 1, { "a" }, let a = 1;, String, my_name, 'a, my_val = 30,
@@ -37,12 +37,12 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
3737
span: $DIR/capture-macro-rules-invoke.rs:38:17: 38:18 (#0),
3838
},
3939
],
40-
span: $DIR/capture-macro-rules-invoke.rs:14:29: 14:34 (#8),
40+
span: $DIR/capture-macro-rules-invoke.rs:14:29: 14:34 (#7),
4141
},
4242
Punct {
4343
ch: ',',
4444
spacing: Alone,
45-
span: $DIR/capture-macro-rules-invoke.rs:14:34: 14:35 (#8),
45+
span: $DIR/capture-macro-rules-invoke.rs:14:34: 14:35 (#7),
4646
},
4747
Group {
4848
delimiter: None,
@@ -60,12 +60,12 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
6060
span: $DIR/capture-macro-rules-invoke.rs:39:13: 39:20 (#0),
6161
},
6262
],
63-
span: $DIR/capture-macro-rules-invoke.rs:14:36: 14:42 (#8),
63+
span: $DIR/capture-macro-rules-invoke.rs:14:36: 14:42 (#7),
6464
},
6565
Punct {
6666
ch: ',',
6767
spacing: Alone,
68-
span: $DIR/capture-macro-rules-invoke.rs:14:42: 14:43 (#8),
68+
span: $DIR/capture-macro-rules-invoke.rs:14:42: 14:43 (#7),
6969
},
7070
Group {
7171
delimiter: None,
@@ -90,12 +90,12 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
9090
span: $DIR/capture-macro-rules-invoke.rs:40:21: 40:22 (#0),
9191
},
9292
],
93-
span: $DIR/capture-macro-rules-invoke.rs:14:44: 14:49 (#8),
93+
span: $DIR/capture-macro-rules-invoke.rs:14:44: 14:49 (#7),
9494
},
9595
Punct {
9696
ch: ',',
9797
spacing: Alone,
98-
span: $DIR/capture-macro-rules-invoke.rs:14:49: 14:50 (#8),
98+
span: $DIR/capture-macro-rules-invoke.rs:14:49: 14:50 (#7),
9999
},
100100
Group {
101101
delimiter: None,
@@ -105,12 +105,12 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
105105
span: $DIR/capture-macro-rules-invoke.rs:41:13: 41:19 (#0),
106106
},
107107
],
108-
span: $DIR/capture-macro-rules-invoke.rs:14:51: 14:54 (#8),
108+
span: $DIR/capture-macro-rules-invoke.rs:14:51: 14:54 (#7),
109109
},
110110
Punct {
111111
ch: ',',
112112
spacing: Alone,
113-
span: $DIR/capture-macro-rules-invoke.rs:14:54: 14:55 (#8),
113+
span: $DIR/capture-macro-rules-invoke.rs:14:54: 14:55 (#7),
114114
},
115115
Ident {
116116
ident: "my_name",
@@ -119,7 +119,7 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
119119
Punct {
120120
ch: ',',
121121
spacing: Alone,
122-
span: $DIR/capture-macro-rules-invoke.rs:14:62: 14:63 (#8),
122+
span: $DIR/capture-macro-rules-invoke.rs:14:62: 14:63 (#7),
123123
},
124124
Group {
125125
delimiter: None,
@@ -134,12 +134,12 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
134134
span: $DIR/capture-macro-rules-invoke.rs:43:13: 43:15 (#0),
135135
},
136136
],
137-
span: $DIR/capture-macro-rules-invoke.rs:15:29: 15:38 (#8),
137+
span: $DIR/capture-macro-rules-invoke.rs:15:29: 15:38 (#7),
138138
},
139139
Punct {
140140
ch: ',',
141141
spacing: Alone,
142-
span: $DIR/capture-macro-rules-invoke.rs:15:38: 15:39 (#8),
142+
span: $DIR/capture-macro-rules-invoke.rs:15:38: 15:39 (#7),
143143
},
144144
Group {
145145
delimiter: None,
@@ -160,12 +160,12 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
160160
span: $DIR/capture-macro-rules-invoke.rs:44:22: 44:24 (#0),
161161
},
162162
],
163-
span: $DIR/capture-macro-rules-invoke.rs:15:40: 15:45 (#8),
163+
span: $DIR/capture-macro-rules-invoke.rs:15:40: 15:45 (#7),
164164
},
165165
Punct {
166166
ch: ',',
167167
spacing: Alone,
168-
span: $DIR/capture-macro-rules-invoke.rs:15:45: 15:46 (#8),
168+
span: $DIR/capture-macro-rules-invoke.rs:15:45: 15:46 (#7),
169169
},
170170
Group {
171171
delimiter: None,
@@ -203,12 +203,12 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
203203
span: $DIR/capture-macro-rules-invoke.rs:45:26: 45:32 (#0),
204204
},
205205
],
206-
span: $DIR/capture-macro-rules-invoke.rs:15:47: 15:52 (#8),
206+
span: $DIR/capture-macro-rules-invoke.rs:15:47: 15:52 (#7),
207207
},
208208
Punct {
209209
ch: ',',
210210
spacing: Alone,
211-
span: $DIR/capture-macro-rules-invoke.rs:15:52: 15:53 (#8),
211+
span: $DIR/capture-macro-rules-invoke.rs:15:52: 15:53 (#7),
212212
},
213213
Group {
214214
delimiter: None,
@@ -246,12 +246,12 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
246246
span: $DIR/capture-macro-rules-invoke.rs:46:16: 46:31 (#0),
247247
},
248248
],
249-
span: $DIR/capture-macro-rules-invoke.rs:15:54: 15:58 (#8),
249+
span: $DIR/capture-macro-rules-invoke.rs:15:54: 15:58 (#7),
250250
},
251251
Punct {
252252
ch: ',',
253253
spacing: Alone,
254-
span: $DIR/capture-macro-rules-invoke.rs:15:58: 15:59 (#8),
254+
span: $DIR/capture-macro-rules-invoke.rs:15:58: 15:59 (#7),
255255
},
256256
Group {
257257
delimiter: Bracket,
@@ -274,7 +274,7 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
274274
Punct {
275275
ch: ',',
276276
spacing: Alone,
277-
span: $DIR/capture-macro-rules-invoke.rs:15:63: 15:64 (#8),
277+
span: $DIR/capture-macro-rules-invoke.rs:15:63: 15:64 (#7),
278278
},
279279
Group {
280280
delimiter: None,
@@ -291,7 +291,7 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
291291
span: $DIR/capture-macro-rules-invoke.rs:48:14: 48:16 (#0),
292292
},
293293
],
294-
span: $DIR/capture-macro-rules-invoke.rs:15:65: 15:69 (#8),
294+
span: $DIR/capture-macro-rules-invoke.rs:15:65: 15:69 (#7),
295295
},
296296
]
297297
PRINT-BANG INPUT (DISPLAY): (a, b)
@@ -319,6 +319,6 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
319319
span: $DIR/capture-macro-rules-invoke.rs:52:26: 52:32 (#0),
320320
},
321321
],
322-
span: $DIR/capture-macro-rules-invoke.rs:27:21: 27:25 (#12),
322+
span: $DIR/capture-macro-rules-invoke.rs:27:21: 27:25 (#11),
323323
},
324324
]

tests/ui/proc-macro/capture-unglued-token.stdout

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
2323
span: $DIR/capture-unglued-token.rs:19:30: 19:31 (#0),
2424
},
2525
],
26-
span: $DIR/capture-unglued-token.rs:15:42: 15:48 (#4),
26+
span: $DIR/capture-unglued-token.rs:15:42: 15:48 (#3),
2727
},
2828
]

tests/ui/proc-macro/dollar-crate-issue-57089.stdout

+16-16
Original file line numberDiff line numberDiff line change
@@ -2,79 +2,79 @@ PRINT-BANG INPUT (DISPLAY): struct M($crate :: S) ;
22
PRINT-BANG INPUT (DEBUG): TokenStream [
33
Ident {
44
ident: "struct",
5-
span: $DIR/dollar-crate-issue-57089.rs:17:13: 17:19 (#4),
5+
span: $DIR/dollar-crate-issue-57089.rs:17:13: 17:19 (#3),
66
},
77
Ident {
88
ident: "M",
9-
span: $DIR/dollar-crate-issue-57089.rs:17:20: 17:21 (#4),
9+
span: $DIR/dollar-crate-issue-57089.rs:17:20: 17:21 (#3),
1010
},
1111
Group {
1212
delimiter: Parenthesis,
1313
stream: TokenStream [
1414
Ident {
1515
ident: "$crate",
16-
span: $DIR/dollar-crate-issue-57089.rs:17:22: 17:28 (#4),
16+
span: $DIR/dollar-crate-issue-57089.rs:17:22: 17:28 (#3),
1717
},
1818
Punct {
1919
ch: ':',
2020
spacing: Joint,
21-
span: $DIR/dollar-crate-issue-57089.rs:17:28: 17:29 (#4),
21+
span: $DIR/dollar-crate-issue-57089.rs:17:28: 17:29 (#3),
2222
},
2323
Punct {
2424
ch: ':',
2525
spacing: Alone,
26-
span: $DIR/dollar-crate-issue-57089.rs:17:29: 17:30 (#4),
26+
span: $DIR/dollar-crate-issue-57089.rs:17:29: 17:30 (#3),
2727
},
2828
Ident {
2929
ident: "S",
30-
span: $DIR/dollar-crate-issue-57089.rs:17:30: 17:31 (#4),
30+
span: $DIR/dollar-crate-issue-57089.rs:17:30: 17:31 (#3),
3131
},
3232
],
33-
span: $DIR/dollar-crate-issue-57089.rs:17:21: 17:32 (#4),
33+
span: $DIR/dollar-crate-issue-57089.rs:17:21: 17:32 (#3),
3434
},
3535
Punct {
3636
ch: ';',
3737
spacing: Alone,
38-
span: $DIR/dollar-crate-issue-57089.rs:17:32: 17:33 (#4),
38+
span: $DIR/dollar-crate-issue-57089.rs:17:32: 17:33 (#3),
3939
},
4040
]
4141
PRINT-ATTR INPUT (DISPLAY): struct A($crate :: S) ;
4242
PRINT-ATTR INPUT (DEBUG): TokenStream [
4343
Ident {
4444
ident: "struct",
45-
span: $DIR/dollar-crate-issue-57089.rs:21:9: 21:15 (#4),
45+
span: $DIR/dollar-crate-issue-57089.rs:21:9: 21:15 (#3),
4646
},
4747
Ident {
4848
ident: "A",
49-
span: $DIR/dollar-crate-issue-57089.rs:21:16: 21:17 (#4),
49+
span: $DIR/dollar-crate-issue-57089.rs:21:16: 21:17 (#3),
5050
},
5151
Group {
5252
delimiter: Parenthesis,
5353
stream: TokenStream [
5454
Ident {
5555
ident: "$crate",
56-
span: $DIR/dollar-crate-issue-57089.rs:21:18: 21:24 (#4),
56+
span: $DIR/dollar-crate-issue-57089.rs:21:18: 21:24 (#3),
5757
},
5858
Punct {
5959
ch: ':',
6060
spacing: Joint,
61-
span: $DIR/dollar-crate-issue-57089.rs:21:24: 21:25 (#4),
61+
span: $DIR/dollar-crate-issue-57089.rs:21:24: 21:25 (#3),
6262
},
6363
Punct {
6464
ch: ':',
6565
spacing: Alone,
66-
span: $DIR/dollar-crate-issue-57089.rs:21:25: 21:26 (#4),
66+
span: $DIR/dollar-crate-issue-57089.rs:21:25: 21:26 (#3),
6767
},
6868
Ident {
6969
ident: "S",
70-
span: $DIR/dollar-crate-issue-57089.rs:21:26: 21:27 (#4),
70+
span: $DIR/dollar-crate-issue-57089.rs:21:26: 21:27 (#3),
7171
},
7272
],
73-
span: $DIR/dollar-crate-issue-57089.rs:21:17: 21:28 (#4),
73+
span: $DIR/dollar-crate-issue-57089.rs:21:17: 21:28 (#3),
7474
},
7575
Punct {
7676
ch: ';',
7777
spacing: Alone,
78-
span: $DIR/dollar-crate-issue-57089.rs:21:28: 21:29 (#4),
78+
span: $DIR/dollar-crate-issue-57089.rs:21:28: 21:29 (#3),
7979
},
8080
]

0 commit comments

Comments
 (0)