Skip to content

Commit

Permalink
Hide compiler_builtins in the prelude
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Amanieu committed Jul 14, 2023
1 parent 8ca44ef commit 07f855d
Show file tree
Hide file tree
Showing 23 changed files with 347 additions and 344 deletions.
27 changes: 18 additions & 9 deletions compiler/rustc_builtin_macros/src/standard_library_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,29 @@ pub fn inject(

// .rev() to preserve ordering above in combination with insert(0, ...)
for &name in names.iter().rev() {
let ident = if edition >= Edition2018 {
Ident::new(name, span)
let ident_span = if edition >= Edition2018 { span } else { call_site };
let item = if name == sym::compiler_builtins {
// compiler_builtins 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.
//
// FIXME(#113634) We should inject this during post-processing like
// we do for the panic runtime, profiler runtime, etc.
cx.item(
span,
Ident::new(kw::Underscore, ident_span),
thin_vec![],
ast::ItemKind::ExternCrate(Some(name)),
)
} else {
Ident::new(name, call_site)
};
krate.items.insert(
0,
cx.item(
span,
ident,
Ident::new(name, ident_span),
thin_vec![cx.attr_word(sym::macro_use, span)],
ast::ItemKind::ExternCrate(None),
),
);
)
};
krate.items.insert(0, item);
}

// The crates have been injected, the assumption is that the first one is
Expand Down
12 changes: 6 additions & 6 deletions tests/ui/proc-macro/allowed-attr-stmt-expr.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
Punct {
ch: '#',
spacing: Alone,
span: $DIR/allowed-attr-stmt-expr.rs:35:9: 35:10 (#11),
span: $DIR/allowed-attr-stmt-expr.rs:35:9: 35:10 (#10),
},
Group {
delimiter: Bracket,
stream: TokenStream [
Ident {
ident: "rustc_dummy",
span: $DIR/allowed-attr-stmt-expr.rs:35:11: 35:22 (#11),
span: $DIR/allowed-attr-stmt-expr.rs:35:11: 35:22 (#10),
},
],
span: $DIR/allowed-attr-stmt-expr.rs:35:10: 35:23 (#11),
span: $DIR/allowed-attr-stmt-expr.rs:35:10: 35:23 (#10),
},
Ident {
ident: "struct",
Expand Down Expand Up @@ -206,17 +206,17 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
Punct {
ch: '#',
spacing: Alone,
span: $DIR/allowed-attr-stmt-expr.rs:35:9: 35:10 (#32),
span: $DIR/allowed-attr-stmt-expr.rs:35:9: 35:10 (#31),
},
Group {
delimiter: Bracket,
stream: TokenStream [
Ident {
ident: "rustc_dummy",
span: $DIR/allowed-attr-stmt-expr.rs:35:11: 35:22 (#32),
span: $DIR/allowed-attr-stmt-expr.rs:35:11: 35:22 (#31),
},
],
span: $DIR/allowed-attr-stmt-expr.rs:35:10: 35:23 (#32),
span: $DIR/allowed-attr-stmt-expr.rs:35:10: 35:23 (#31),
},
Punct {
ch: '#',
Expand Down
12 changes: 6 additions & 6 deletions tests/ui/proc-macro/attr-stmt-expr.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
Punct {
ch: '#',
spacing: Alone,
span: $DIR/attr-stmt-expr.rs:33:9: 33:10 (#8),
span: $DIR/attr-stmt-expr.rs:33:9: 33:10 (#7),
},
Group {
delimiter: Bracket,
stream: TokenStream [
Ident {
ident: "rustc_dummy",
span: $DIR/attr-stmt-expr.rs:33:11: 33:22 (#8),
span: $DIR/attr-stmt-expr.rs:33:11: 33:22 (#7),
},
],
span: $DIR/attr-stmt-expr.rs:33:10: 33:23 (#8),
span: $DIR/attr-stmt-expr.rs:33:10: 33:23 (#7),
},
Ident {
ident: "struct",
Expand Down Expand Up @@ -190,17 +190,17 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
Punct {
ch: '#',
spacing: Alone,
span: $DIR/attr-stmt-expr.rs:33:9: 33:10 (#29),
span: $DIR/attr-stmt-expr.rs:33:9: 33:10 (#28),
},
Group {
delimiter: Bracket,
stream: TokenStream [
Ident {
ident: "rustc_dummy",
span: $DIR/attr-stmt-expr.rs:33:11: 33:22 (#29),
span: $DIR/attr-stmt-expr.rs:33:11: 33:22 (#28),
},
],
span: $DIR/attr-stmt-expr.rs:33:10: 33:23 (#29),
span: $DIR/attr-stmt-expr.rs:33:10: 33:23 (#28),
},
Punct {
ch: '#',
Expand Down
42 changes: 21 additions & 21 deletions tests/ui/proc-macro/capture-macro-rules-invoke.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
span: $DIR/capture-macro-rules-invoke.rs:36:24: 36:28 (#0),
},
],
span: $DIR/capture-macro-rules-invoke.rs:21:21: 21:26 (#4),
span: $DIR/capture-macro-rules-invoke.rs:21:21: 21:26 (#3),
},
]
PRINT-BANG INPUT (DISPLAY): 1 + 1, { "a" }, let a = 1;, String, my_name, 'a, my_val = 30,
Expand Down Expand Up @@ -37,12 +37,12 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
span: $DIR/capture-macro-rules-invoke.rs:38:17: 38:18 (#0),
},
],
span: $DIR/capture-macro-rules-invoke.rs:14:29: 14:34 (#8),
span: $DIR/capture-macro-rules-invoke.rs:14:29: 14:34 (#7),
},
Punct {
ch: ',',
spacing: Alone,
span: $DIR/capture-macro-rules-invoke.rs:14:34: 14:35 (#8),
span: $DIR/capture-macro-rules-invoke.rs:14:34: 14:35 (#7),
},
Group {
delimiter: None,
Expand All @@ -60,12 +60,12 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
span: $DIR/capture-macro-rules-invoke.rs:39:13: 39:20 (#0),
},
],
span: $DIR/capture-macro-rules-invoke.rs:14:36: 14:42 (#8),
span: $DIR/capture-macro-rules-invoke.rs:14:36: 14:42 (#7),
},
Punct {
ch: ',',
spacing: Alone,
span: $DIR/capture-macro-rules-invoke.rs:14:42: 14:43 (#8),
span: $DIR/capture-macro-rules-invoke.rs:14:42: 14:43 (#7),
},
Group {
delimiter: None,
Expand All @@ -90,12 +90,12 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
span: $DIR/capture-macro-rules-invoke.rs:40:21: 40:22 (#0),
},
],
span: $DIR/capture-macro-rules-invoke.rs:14:44: 14:49 (#8),
span: $DIR/capture-macro-rules-invoke.rs:14:44: 14:49 (#7),
},
Punct {
ch: ',',
spacing: Alone,
span: $DIR/capture-macro-rules-invoke.rs:14:49: 14:50 (#8),
span: $DIR/capture-macro-rules-invoke.rs:14:49: 14:50 (#7),
},
Group {
delimiter: None,
Expand All @@ -105,12 +105,12 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
span: $DIR/capture-macro-rules-invoke.rs:41:13: 41:19 (#0),
},
],
span: $DIR/capture-macro-rules-invoke.rs:14:51: 14:54 (#8),
span: $DIR/capture-macro-rules-invoke.rs:14:51: 14:54 (#7),
},
Punct {
ch: ',',
spacing: Alone,
span: $DIR/capture-macro-rules-invoke.rs:14:54: 14:55 (#8),
span: $DIR/capture-macro-rules-invoke.rs:14:54: 14:55 (#7),
},
Ident {
ident: "my_name",
Expand All @@ -119,7 +119,7 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
Punct {
ch: ',',
spacing: Alone,
span: $DIR/capture-macro-rules-invoke.rs:14:62: 14:63 (#8),
span: $DIR/capture-macro-rules-invoke.rs:14:62: 14:63 (#7),
},
Group {
delimiter: None,
Expand All @@ -134,12 +134,12 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
span: $DIR/capture-macro-rules-invoke.rs:43:13: 43:15 (#0),
},
],
span: $DIR/capture-macro-rules-invoke.rs:15:29: 15:38 (#8),
span: $DIR/capture-macro-rules-invoke.rs:15:29: 15:38 (#7),
},
Punct {
ch: ',',
spacing: Alone,
span: $DIR/capture-macro-rules-invoke.rs:15:38: 15:39 (#8),
span: $DIR/capture-macro-rules-invoke.rs:15:38: 15:39 (#7),
},
Group {
delimiter: None,
Expand All @@ -160,12 +160,12 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
span: $DIR/capture-macro-rules-invoke.rs:44:22: 44:24 (#0),
},
],
span: $DIR/capture-macro-rules-invoke.rs:15:40: 15:45 (#8),
span: $DIR/capture-macro-rules-invoke.rs:15:40: 15:45 (#7),
},
Punct {
ch: ',',
spacing: Alone,
span: $DIR/capture-macro-rules-invoke.rs:15:45: 15:46 (#8),
span: $DIR/capture-macro-rules-invoke.rs:15:45: 15:46 (#7),
},
Group {
delimiter: None,
Expand Down Expand Up @@ -203,12 +203,12 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
span: $DIR/capture-macro-rules-invoke.rs:45:26: 45:32 (#0),
},
],
span: $DIR/capture-macro-rules-invoke.rs:15:47: 15:52 (#8),
span: $DIR/capture-macro-rules-invoke.rs:15:47: 15:52 (#7),
},
Punct {
ch: ',',
spacing: Alone,
span: $DIR/capture-macro-rules-invoke.rs:15:52: 15:53 (#8),
span: $DIR/capture-macro-rules-invoke.rs:15:52: 15:53 (#7),
},
Group {
delimiter: None,
Expand Down Expand Up @@ -246,12 +246,12 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
span: $DIR/capture-macro-rules-invoke.rs:46:16: 46:31 (#0),
},
],
span: $DIR/capture-macro-rules-invoke.rs:15:54: 15:58 (#8),
span: $DIR/capture-macro-rules-invoke.rs:15:54: 15:58 (#7),
},
Punct {
ch: ',',
spacing: Alone,
span: $DIR/capture-macro-rules-invoke.rs:15:58: 15:59 (#8),
span: $DIR/capture-macro-rules-invoke.rs:15:58: 15:59 (#7),
},
Group {
delimiter: Bracket,
Expand All @@ -274,7 +274,7 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
Punct {
ch: ',',
spacing: Alone,
span: $DIR/capture-macro-rules-invoke.rs:15:63: 15:64 (#8),
span: $DIR/capture-macro-rules-invoke.rs:15:63: 15:64 (#7),
},
Group {
delimiter: None,
Expand All @@ -291,7 +291,7 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
span: $DIR/capture-macro-rules-invoke.rs:48:14: 48:16 (#0),
},
],
span: $DIR/capture-macro-rules-invoke.rs:15:65: 15:69 (#8),
span: $DIR/capture-macro-rules-invoke.rs:15:65: 15:69 (#7),
},
]
PRINT-BANG INPUT (DISPLAY): (a, b)
Expand Down Expand Up @@ -319,6 +319,6 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
span: $DIR/capture-macro-rules-invoke.rs:52:26: 52:32 (#0),
},
],
span: $DIR/capture-macro-rules-invoke.rs:27:21: 27:25 (#12),
span: $DIR/capture-macro-rules-invoke.rs:27:21: 27:25 (#11),
},
]
2 changes: 1 addition & 1 deletion tests/ui/proc-macro/capture-unglued-token.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
span: $DIR/capture-unglued-token.rs:19:30: 19:31 (#0),
},
],
span: $DIR/capture-unglued-token.rs:15:42: 15:48 (#4),
span: $DIR/capture-unglued-token.rs:15:42: 15:48 (#3),
},
]
32 changes: 16 additions & 16 deletions tests/ui/proc-macro/dollar-crate-issue-57089.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -2,79 +2,79 @@ PRINT-BANG INPUT (DISPLAY): struct M($crate :: S) ;
PRINT-BANG INPUT (DEBUG): TokenStream [
Ident {
ident: "struct",
span: $DIR/dollar-crate-issue-57089.rs:17:13: 17:19 (#4),
span: $DIR/dollar-crate-issue-57089.rs:17:13: 17:19 (#3),
},
Ident {
ident: "M",
span: $DIR/dollar-crate-issue-57089.rs:17:20: 17:21 (#4),
span: $DIR/dollar-crate-issue-57089.rs:17:20: 17:21 (#3),
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
ident: "$crate",
span: $DIR/dollar-crate-issue-57089.rs:17:22: 17:28 (#4),
span: $DIR/dollar-crate-issue-57089.rs:17:22: 17:28 (#3),
},
Punct {
ch: ':',
spacing: Joint,
span: $DIR/dollar-crate-issue-57089.rs:17:28: 17:29 (#4),
span: $DIR/dollar-crate-issue-57089.rs:17:28: 17:29 (#3),
},
Punct {
ch: ':',
spacing: Alone,
span: $DIR/dollar-crate-issue-57089.rs:17:29: 17:30 (#4),
span: $DIR/dollar-crate-issue-57089.rs:17:29: 17:30 (#3),
},
Ident {
ident: "S",
span: $DIR/dollar-crate-issue-57089.rs:17:30: 17:31 (#4),
span: $DIR/dollar-crate-issue-57089.rs:17:30: 17:31 (#3),
},
],
span: $DIR/dollar-crate-issue-57089.rs:17:21: 17:32 (#4),
span: $DIR/dollar-crate-issue-57089.rs:17:21: 17:32 (#3),
},
Punct {
ch: ';',
spacing: Alone,
span: $DIR/dollar-crate-issue-57089.rs:17:32: 17:33 (#4),
span: $DIR/dollar-crate-issue-57089.rs:17:32: 17:33 (#3),
},
]
PRINT-ATTR INPUT (DISPLAY): struct A($crate :: S) ;
PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident {
ident: "struct",
span: $DIR/dollar-crate-issue-57089.rs:21:9: 21:15 (#4),
span: $DIR/dollar-crate-issue-57089.rs:21:9: 21:15 (#3),
},
Ident {
ident: "A",
span: $DIR/dollar-crate-issue-57089.rs:21:16: 21:17 (#4),
span: $DIR/dollar-crate-issue-57089.rs:21:16: 21:17 (#3),
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
ident: "$crate",
span: $DIR/dollar-crate-issue-57089.rs:21:18: 21:24 (#4),
span: $DIR/dollar-crate-issue-57089.rs:21:18: 21:24 (#3),
},
Punct {
ch: ':',
spacing: Joint,
span: $DIR/dollar-crate-issue-57089.rs:21:24: 21:25 (#4),
span: $DIR/dollar-crate-issue-57089.rs:21:24: 21:25 (#3),
},
Punct {
ch: ':',
spacing: Alone,
span: $DIR/dollar-crate-issue-57089.rs:21:25: 21:26 (#4),
span: $DIR/dollar-crate-issue-57089.rs:21:25: 21:26 (#3),
},
Ident {
ident: "S",
span: $DIR/dollar-crate-issue-57089.rs:21:26: 21:27 (#4),
span: $DIR/dollar-crate-issue-57089.rs:21:26: 21:27 (#3),
},
],
span: $DIR/dollar-crate-issue-57089.rs:21:17: 21:28 (#4),
span: $DIR/dollar-crate-issue-57089.rs:21:17: 21:28 (#3),
},
Punct {
ch: ';',
spacing: Alone,
span: $DIR/dollar-crate-issue-57089.rs:21:28: 21:29 (#4),
span: $DIR/dollar-crate-issue-57089.rs:21:28: 21:29 (#3),
},
]
Loading

0 comments on commit 07f855d

Please sign in to comment.