Skip to content

Commit bf9c8b4

Browse files
authored
Unrolled build for rust-lang#124391
Rollup merge of rust-lang#124391 - nnethercote:builtin_macros-cleanups, r=fee1-dead `rustc_builtin_macros` cleanups Some improvements I found while looking over this code. r? ``@fee1-dead``
2 parents aa6a8ee + 30d6f63 commit bf9c8b4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+352
-341
lines changed

Diff for: compiler/rustc_builtin_macros/messages.ftl

+6
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ builtin_macros_env_not_unicode = environment variable `{$var}` is not a valid Un
118118
119119
builtin_macros_env_takes_args = `env!()` takes 1 or 2 arguments
120120
121+
builtin_macros_expected_comma_in_list = expected token: `,`
122+
121123
builtin_macros_expected_one_cfg_pattern = expected 1 cfg-pattern
122124
123125
builtin_macros_expected_register_class_or_explicit_register = expected register class or explicit register
@@ -219,12 +221,16 @@ builtin_macros_non_exhaustive_default = default variant must be exhaustive
219221
builtin_macros_non_unit_default = the `#[default]` attribute may only be used on unit enum variants
220222
.help = consider a manual implementation of `Default`
221223
224+
builtin_macros_only_one_argument = {$name} takes 1 argument
225+
222226
builtin_macros_proc_macro = `proc-macro` crate types currently cannot export any items other than functions tagged with `#[proc_macro]`, `#[proc_macro_derive]`, or `#[proc_macro_attribute]`
223227
224228
builtin_macros_requires_cfg_pattern =
225229
macro requires a cfg-pattern as an argument
226230
.label = cfg-pattern required
227231
232+
builtin_macros_takes_no_arguments = {$name} takes no arguments
233+
228234
builtin_macros_test_bad_fn = {$kind} functions cannot be used for tests
229235
.label = `{$kind}` because of this
230236

Diff for: compiler/rustc_builtin_macros/src/alloc_error_handler.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_span::symbol::{kw, sym, Ident};
99
use rustc_span::Span;
1010
use thin_vec::{thin_vec, ThinVec};
1111

12-
pub fn expand(
12+
pub(crate) fn expand(
1313
ecx: &mut ExtCtxt<'_>,
1414
_span: Span,
1515
meta_item: &ast::MetaItem,

Diff for: compiler/rustc_builtin_macros/src/asm.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use crate::errors;
2+
use crate::util::expr_to_spanned_string;
13
use ast::token::IdentIsRaw;
24
use rustc_ast as ast;
35
use rustc_ast::ptr::P;
@@ -16,8 +18,6 @@ use rustc_span::{ErrorGuaranteed, InnerSpan, Span};
1618
use rustc_target::asm::InlineAsmArch;
1719
use smallvec::smallvec;
1820

19-
use crate::errors;
20-
2121
pub struct AsmArgs {
2222
pub templates: Vec<P<ast::Expr>>,
2323
pub operands: Vec<(ast::InlineAsmOperand, Span)>,

Diff for: compiler/rustc_builtin_macros/src/assert.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_span::symbol::{sym, Ident, Symbol};
1515
use rustc_span::{Span, DUMMY_SP};
1616
use thin_vec::thin_vec;
1717

18-
pub fn expand_assert<'cx>(
18+
pub(crate) fn expand_assert<'cx>(
1919
cx: &'cx mut ExtCtxt<'_>,
2020
span: Span,
2121
tts: TokenStream,

Diff for: compiler/rustc_builtin_macros/src/cfg.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_errors::PResult;
1111
use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt, MacEager, MacroExpanderResult};
1212
use rustc_span::Span;
1313

14-
pub fn expand_cfg(
14+
pub(crate) fn expand_cfg(
1515
cx: &mut ExtCtxt<'_>,
1616
sp: Span,
1717
tts: TokenStream,

Diff for: compiler/rustc_builtin_macros/src/compile_error.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// The compiler code necessary to support the compile_error! extension.
22

3+
use crate::util::get_single_str_from_tts;
34
use rustc_ast::tokenstream::TokenStream;
4-
use rustc_expand::base::get_single_str_from_tts;
55
use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt, MacroExpanderResult};
66
use rustc_span::Span;
77

8-
pub fn expand_compile_error<'cx>(
8+
pub(crate) fn expand_compile_error<'cx>(
99
cx: &'cx mut ExtCtxt<'_>,
1010
sp: Span,
1111
tts: TokenStream,

Diff for: compiler/rustc_builtin_macros/src/concat.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1+
use crate::errors;
2+
use crate::util::get_exprs_from_tts;
13
use rustc_ast::tokenstream::TokenStream;
24
use rustc_ast::{ExprKind, LitKind, UnOp};
3-
use rustc_expand::base::get_exprs_from_tts;
45
use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt, MacEager, MacroExpanderResult};
56
use rustc_session::errors::report_lit_error;
67
use rustc_span::symbol::Symbol;
78

8-
use crate::errors;
9-
10-
pub fn expand_concat(
9+
pub(crate) fn expand_concat(
1110
cx: &mut ExtCtxt<'_>,
1211
sp: rustc_span::Span,
1312
tts: TokenStream,

Diff for: compiler/rustc_builtin_macros/src/concat_bytes.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1+
use crate::errors;
2+
use crate::util::get_exprs_from_tts;
13
use rustc_ast::{ptr::P, token, tokenstream::TokenStream, ExprKind, LitIntType, LitKind, UintTy};
2-
use rustc_expand::base::get_exprs_from_tts;
34
use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt, MacEager, MacroExpanderResult};
45
use rustc_session::errors::report_lit_error;
56
use rustc_span::{ErrorGuaranteed, Span};
67

7-
use crate::errors;
8-
98
/// Emits errors for literal expressions that are invalid inside and outside of an array.
109
fn invalid_type_err(
1110
cx: &ExtCtxt<'_>,
@@ -108,7 +107,7 @@ fn handle_array_element(
108107
None
109108
}
110109

111-
pub fn expand_concat_bytes(
110+
pub(crate) fn expand_concat_bytes(
112111
cx: &mut ExtCtxt<'_>,
113112
sp: Span,
114113
tts: TokenStream,

Diff for: compiler/rustc_builtin_macros/src/concat_idents.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_span::Span;
88

99
use crate::errors;
1010

11-
pub fn expand_concat_idents<'cx>(
11+
pub(crate) fn expand_concat_idents<'cx>(
1212
cx: &'cx mut ExtCtxt<'_>,
1313
sp: Span,
1414
tts: TokenStream,

Diff for: compiler/rustc_builtin_macros/src/derive.rs

+16-7
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@ use crate::errors;
33

44
use rustc_ast as ast;
55
use rustc_ast::{GenericParamKind, ItemKind, MetaItemKind, NestedMetaItem, StmtKind};
6-
use rustc_expand::base::{Annotatable, ExpandResult, ExtCtxt, Indeterminate, MultiItemModifier};
6+
use rustc_expand::base::{
7+
Annotatable, DeriveResolution, ExpandResult, ExtCtxt, Indeterminate, MultiItemModifier,
8+
};
79
use rustc_feature::AttributeTemplate;
810
use rustc_parse::validate_attr;
911
use rustc_session::Session;
1012
use rustc_span::symbol::{sym, Ident};
1113
use rustc_span::{ErrorGuaranteed, Span};
1214

13-
pub(crate) struct Expander(pub bool);
15+
pub(crate) struct Expander {
16+
pub is_const: bool,
17+
}
1418

1519
impl MultiItemModifier for Expander {
1620
fn expand(
@@ -58,7 +62,12 @@ impl MultiItemModifier for Expander {
5862
report_path_args(sess, meta);
5963
meta.path.clone()
6064
})
61-
.map(|path| (path, dummy_annotatable(), None, self.0))
65+
.map(|path| DeriveResolution {
66+
path,
67+
item: dummy_annotatable(),
68+
exts: None,
69+
is_const: self.is_const,
70+
})
6271
.collect()
6372
}
6473
_ => vec![],
@@ -67,15 +76,15 @@ impl MultiItemModifier for Expander {
6776
// Do not configure or clone items unless necessary.
6877
match &mut resolutions[..] {
6978
[] => {}
70-
[(_, first_item, ..), others @ ..] => {
71-
*first_item = cfg_eval(
79+
[first, others @ ..] => {
80+
first.item = cfg_eval(
7281
sess,
7382
features,
7483
item.clone(),
7584
ecx.current_expansion.lint_node_id,
7685
);
77-
for (_, item, _, _) in others {
78-
*item = first_item.clone();
86+
for other in others {
87+
other.item = first.item.clone();
7988
}
8089
}
8190
}

Diff for: compiler/rustc_builtin_macros/src/deriving/bounds.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_ast::MetaItem;
55
use rustc_expand::base::{Annotatable, ExtCtxt};
66
use rustc_span::Span;
77

8-
pub fn expand_deriving_copy(
8+
pub(crate) fn expand_deriving_copy(
99
cx: &ExtCtxt<'_>,
1010
span: Span,
1111
mitem: &MetaItem,
@@ -28,7 +28,7 @@ pub fn expand_deriving_copy(
2828
trait_def.expand(cx, mitem, item, push);
2929
}
3030

31-
pub fn expand_deriving_const_param_ty(
31+
pub(crate) fn expand_deriving_const_param_ty(
3232
cx: &ExtCtxt<'_>,
3333
span: Span,
3434
mitem: &MetaItem,

Diff for: compiler/rustc_builtin_macros/src/deriving/clone.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_span::symbol::{kw, sym, Ident};
88
use rustc_span::Span;
99
use thin_vec::{thin_vec, ThinVec};
1010

11-
pub fn expand_deriving_clone(
11+
pub(crate) fn expand_deriving_clone(
1212
cx: &ExtCtxt<'_>,
1313
span: Span,
1414
mitem: &MetaItem,

Diff for: compiler/rustc_builtin_macros/src/deriving/cmp/eq.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_span::symbol::sym;
99
use rustc_span::Span;
1010
use thin_vec::{thin_vec, ThinVec};
1111

12-
pub fn expand_deriving_eq(
12+
pub(crate) fn expand_deriving_eq(
1313
cx: &ExtCtxt<'_>,
1414
span: Span,
1515
mitem: &MetaItem,

Diff for: compiler/rustc_builtin_macros/src/deriving/cmp/ord.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_span::symbol::{sym, Ident};
77
use rustc_span::Span;
88
use thin_vec::thin_vec;
99

10-
pub fn expand_deriving_ord(
10+
pub(crate) fn expand_deriving_ord(
1111
cx: &ExtCtxt<'_>,
1212
span: Span,
1313
mitem: &MetaItem,
@@ -39,7 +39,7 @@ pub fn expand_deriving_ord(
3939
trait_def.expand(cx, mitem, item, push)
4040
}
4141

42-
pub fn cs_cmp(cx: &ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> BlockOrExpr {
42+
pub(crate) fn cs_cmp(cx: &ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> BlockOrExpr {
4343
let test_id = Ident::new(sym::cmp, span);
4444
let equal_path = cx.path_global(span, cx.std_path(&[sym::cmp, sym::Ordering, sym::Equal]));
4545
let cmp_path = cx.std_path(&[sym::cmp, sym::Ord, sym::cmp]);

Diff for: compiler/rustc_builtin_macros/src/deriving/cmp/partial_eq.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_span::symbol::sym;
88
use rustc_span::Span;
99
use thin_vec::thin_vec;
1010

11-
pub fn expand_deriving_partial_eq(
11+
pub(crate) fn expand_deriving_partial_eq(
1212
cx: &ExtCtxt<'_>,
1313
span: Span,
1414
mitem: &MetaItem,

Diff for: compiler/rustc_builtin_macros/src/deriving/cmp/partial_ord.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_span::symbol::{sym, Ident};
77
use rustc_span::Span;
88
use thin_vec::thin_vec;
99

10-
pub fn expand_deriving_partial_ord(
10+
pub(crate) fn expand_deriving_partial_ord(
1111
cx: &ExtCtxt<'_>,
1212
span: Span,
1313
mitem: &MetaItem,

Diff for: compiler/rustc_builtin_macros/src/deriving/debug.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_span::symbol::{sym, Ident, Symbol};
88
use rustc_span::Span;
99
use thin_vec::{thin_vec, ThinVec};
1010

11-
pub fn expand_deriving_debug(
11+
pub(crate) fn expand_deriving_debug(
1212
cx: &ExtCtxt<'_>,
1313
span: Span,
1414
mitem: &MetaItem,

Diff for: compiler/rustc_builtin_macros/src/deriving/decodable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_span::symbol::{sym, Ident, Symbol};
1010
use rustc_span::Span;
1111
use thin_vec::{thin_vec, ThinVec};
1212

13-
pub fn expand_deriving_rustc_decodable(
13+
pub(crate) fn expand_deriving_rustc_decodable(
1414
cx: &ExtCtxt<'_>,
1515
span: Span,
1616
mitem: &MetaItem,

Diff for: compiler/rustc_builtin_macros/src/deriving/default.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_span::{ErrorGuaranteed, Span};
1212
use smallvec::SmallVec;
1313
use thin_vec::{thin_vec, ThinVec};
1414

15-
pub fn expand_deriving_default(
15+
pub(crate) fn expand_deriving_default(
1616
cx: &ExtCtxt<'_>,
1717
span: Span,
1818
mitem: &ast::MetaItem,

Diff for: compiler/rustc_builtin_macros/src/deriving/encodable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ use rustc_span::symbol::{sym, Ident, Symbol};
9494
use rustc_span::Span;
9595
use thin_vec::{thin_vec, ThinVec};
9696

97-
pub fn expand_deriving_rustc_encodable(
97+
pub(crate) fn expand_deriving_rustc_encodable(
9898
cx: &ExtCtxt<'_>,
9999
span: Span,
100100
mitem: &MetaItem,

0 commit comments

Comments
 (0)