Skip to content

Commit 1d64561

Browse files
committed
Auto merge of rust-lang#124643 - fmease:rollup-esmkgxo, r=fmease
Rollup of 8 pull requests Successful merges: - rust-lang#124412 (io safety: update Unix explanation to use `Arc`) - rust-lang#124441 (String.truncate comment microfix (greater or equal)) - rust-lang#124594 (run-make-support: preserve tooks.mk behavior for EXTRACXXFLAGS) - rust-lang#124604 (library/std: Remove unused `gimli-symbolize` feature) - rust-lang#124607 (`rustc_expand` cleanups) - rust-lang#124609 (variable-precision float operations can differ depending on optimization levels) - rust-lang#124610 (Tweak `consts_may_unify`) - rust-lang#124612 (Add support for inputing via stdin with run-make-support) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 79734f1 + 6a5e8b5 commit 1d64561

File tree

27 files changed

+457
-331
lines changed

27 files changed

+457
-331
lines changed

compiler/rustc_expand/src/base.rs

+23-35
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_session::config::CollapseMacroDebuginfo;
2121
use rustc_session::{parse::ParseSess, Limit, Session};
2222
use rustc_span::def_id::{CrateNum, DefId, LocalDefId};
2323
use rustc_span::edition::Edition;
24-
use rustc_span::hygiene::{AstPass, ExpnData, ExpnKind, LocalExpnId};
24+
use rustc_span::hygiene::{AstPass, ExpnData, ExpnKind, LocalExpnId, MacroKind};
2525
use rustc_span::source_map::SourceMap;
2626
use rustc_span::symbol::{kw, sym, Ident, Symbol};
2727
use rustc_span::{FileName, Span, DUMMY_SP};
@@ -32,8 +32,6 @@ use std::path::{Path, PathBuf};
3232
use std::rc::Rc;
3333
use thin_vec::ThinVec;
3434

35-
pub(crate) use rustc_span::hygiene::MacroKind;
36-
3735
// When adding new variants, make sure to
3836
// adjust the `visit_*` / `flat_map_*` calls in `InvocationCollector`
3937
// to use `assign_id!`
@@ -573,35 +571,6 @@ impl DummyResult {
573571
tokens: None,
574572
})
575573
}
576-
577-
/// A plain dummy pattern.
578-
pub fn raw_pat(sp: Span) -> ast::Pat {
579-
ast::Pat { id: ast::DUMMY_NODE_ID, kind: PatKind::Wild, span: sp, tokens: None }
580-
}
581-
582-
/// A plain dummy type.
583-
pub fn raw_ty(sp: Span) -> P<ast::Ty> {
584-
// FIXME(nnethercote): you might expect `ast::TyKind::Dummy` to be used here, but some
585-
// values produced here end up being lowered to HIR, which `ast::TyKind::Dummy` does not
586-
// support, so we use an empty tuple instead.
587-
P(ast::Ty {
588-
id: ast::DUMMY_NODE_ID,
589-
kind: ast::TyKind::Tup(ThinVec::new()),
590-
span: sp,
591-
tokens: None,
592-
})
593-
}
594-
595-
/// A plain dummy crate.
596-
pub fn raw_crate() -> ast::Crate {
597-
ast::Crate {
598-
attrs: Default::default(),
599-
items: Default::default(),
600-
spans: Default::default(),
601-
id: ast::DUMMY_NODE_ID,
602-
is_placeholder: Default::default(),
603-
}
604-
}
605574
}
606575

607576
impl MacResult for DummyResult {
@@ -610,7 +579,12 @@ impl MacResult for DummyResult {
610579
}
611580

612581
fn make_pat(self: Box<DummyResult>) -> Option<P<ast::Pat>> {
613-
Some(P(DummyResult::raw_pat(self.span)))
582+
Some(P(ast::Pat {
583+
id: ast::DUMMY_NODE_ID,
584+
kind: PatKind::Wild,
585+
span: self.span,
586+
tokens: None,
587+
}))
614588
}
615589

616590
fn make_items(self: Box<DummyResult>) -> Option<SmallVec<[P<ast::Item>; 1]>> {
@@ -638,7 +612,15 @@ impl MacResult for DummyResult {
638612
}
639613

640614
fn make_ty(self: Box<DummyResult>) -> Option<P<ast::Ty>> {
641-
Some(DummyResult::raw_ty(self.span))
615+
// FIXME(nnethercote): you might expect `ast::TyKind::Dummy` to be used here, but some
616+
// values produced here end up being lowered to HIR, which `ast::TyKind::Dummy` does not
617+
// support, so we use an empty tuple instead.
618+
Some(P(ast::Ty {
619+
id: ast::DUMMY_NODE_ID,
620+
kind: ast::TyKind::Tup(ThinVec::new()),
621+
span: self.span,
622+
tokens: None,
623+
}))
642624
}
643625

644626
fn make_arms(self: Box<DummyResult>) -> Option<SmallVec<[ast::Arm; 1]>> {
@@ -670,7 +652,13 @@ impl MacResult for DummyResult {
670652
}
671653

672654
fn make_crate(self: Box<DummyResult>) -> Option<ast::Crate> {
673-
Some(DummyResult::raw_crate())
655+
Some(ast::Crate {
656+
attrs: Default::default(),
657+
items: Default::default(),
658+
spans: Default::default(),
659+
id: ast::DUMMY_NODE_ID,
660+
is_placeholder: Default::default(),
661+
})
674662
}
675663
}
676664

compiler/rustc_expand/src/build.rs

-27
Original file line numberDiff line numberDiff line change
@@ -175,20 +175,6 @@ impl<'a> ExtCtxt<'a> {
175175
ast::Stmt { id: ast::DUMMY_NODE_ID, span: expr.span, kind: ast::StmtKind::Expr(expr) }
176176
}
177177

178-
pub fn stmt_let_pat(&self, sp: Span, pat: P<ast::Pat>, ex: P<ast::Expr>) -> ast::Stmt {
179-
let local = P(ast::Local {
180-
pat,
181-
ty: None,
182-
id: ast::DUMMY_NODE_ID,
183-
kind: LocalKind::Init(ex),
184-
span: sp,
185-
colon_sp: None,
186-
attrs: AttrVec::new(),
187-
tokens: None,
188-
});
189-
self.stmt_local(local, sp)
190-
}
191-
192178
pub fn stmt_let(&self, sp: Span, mutbl: bool, ident: Ident, ex: P<ast::Expr>) -> ast::Stmt {
193179
self.stmt_let_ty(sp, mutbl, ident, None, ex)
194180
}
@@ -278,10 +264,6 @@ impl<'a> ExtCtxt<'a> {
278264
self.expr_ident(span, Ident::with_dummy_span(kw::SelfLower))
279265
}
280266

281-
pub fn expr_field(&self, span: Span, expr: P<Expr>, field: Ident) -> P<ast::Expr> {
282-
self.expr(span, ast::ExprKind::Field(expr, field))
283-
}
284-
285267
pub fn expr_macro_call(&self, span: Span, call: P<ast::MacCall>) -> P<ast::Expr> {
286268
self.expr(span, ast::ExprKind::MacCall(call))
287269
}
@@ -394,11 +376,6 @@ impl<'a> ExtCtxt<'a> {
394376
self.expr(span, ast::ExprKind::Lit(lit))
395377
}
396378

397-
pub fn expr_char(&self, span: Span, ch: char) -> P<ast::Expr> {
398-
let lit = token::Lit::new(token::Char, literal::escape_char_symbol(ch), None);
399-
self.expr(span, ast::ExprKind::Lit(lit))
400-
}
401-
402379
pub fn expr_byte_str(&self, span: Span, bytes: Vec<u8>) -> P<ast::Expr> {
403380
let lit = token::Lit::new(token::ByteStr, literal::escape_byte_str_symbol(&bytes), None);
404381
self.expr(span, ast::ExprKind::Lit(lit))
@@ -414,10 +391,6 @@ impl<'a> ExtCtxt<'a> {
414391
self.expr_addr_of(sp, self.expr_array(sp, exprs))
415392
}
416393

417-
pub fn expr_cast(&self, sp: Span, expr: P<ast::Expr>, ty: P<ast::Ty>) -> P<ast::Expr> {
418-
self.expr(sp, ast::ExprKind::Cast(expr, ty))
419-
}
420-
421394
pub fn expr_some(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr> {
422395
let some = self.std_path(&[sym::option, sym::Option, sym::Some]);
423396
self.expr_call_global(sp, some, thin_vec![expr])

compiler/rustc_expand/src/config.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,11 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute], crate_name: Symbol) -
9999
// If the declared feature is unstable, record it.
100100
if let Some(f) = UNSTABLE_FEATURES.iter().find(|f| name == f.feature.name) {
101101
(f.set_enabled)(&mut features);
102-
// When the ICE comes from core, alloc or std (approximation of the standard library), there's a chance
103-
// that the person hitting the ICE may be using -Zbuild-std or similar with an untested target.
104-
// The bug is probably in the standard library and not the compiler in that case, but that doesn't
105-
// really matter - we want a bug report.
102+
// When the ICE comes from core, alloc or std (approximation of the standard
103+
// library), there's a chance that the person hitting the ICE may be using
104+
// -Zbuild-std or similar with an untested target. The bug is probably in the
105+
// standard library and not the compiler in that case, but that doesn't really
106+
// matter - we want a bug report.
106107
if features.internal(name)
107108
&& ![sym::core, sym::alloc, sym::std].contains(&crate_name)
108109
{

compiler/rustc_expand/src/expand.rs

+29-25
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::errors::{
44
IncompleteParse, RecursionLimitReached, RemoveExprNotSupported, RemoveNodeNotSupported,
55
UnsupportedKeyValue, WrongFragmentKind,
66
};
7-
use crate::hygiene::SyntaxContext;
87
use crate::mbe::diagnostics::annotate_err_with_kind;
98
use crate::module::{mod_dir_path, parse_external_mod, DirOwnership, ParsedExternalMod};
109
use crate::placeholders::{placeholder, PlaceholderExpander};
@@ -32,6 +31,7 @@ use rustc_session::lint::builtin::{UNUSED_ATTRIBUTES, UNUSED_DOC_COMMENTS};
3231
use rustc_session::lint::BuiltinLintDiag;
3332
use rustc_session::parse::feature_err;
3433
use rustc_session::{Limit, Session};
34+
use rustc_span::hygiene::SyntaxContext;
3535
use rustc_span::symbol::{sym, Ident};
3636
use rustc_span::{ErrorGuaranteed, FileName, LocalExpnId, Span};
3737

@@ -87,7 +87,7 @@ macro_rules! ast_fragments {
8787
}
8888

8989
impl AstFragment {
90-
pub fn add_placeholders(&mut self, placeholders: &[NodeId]) {
90+
fn add_placeholders(&mut self, placeholders: &[NodeId]) {
9191
if placeholders.is_empty() {
9292
return;
9393
}
@@ -100,14 +100,14 @@ macro_rules! ast_fragments {
100100
}
101101
}
102102

103-
pub fn make_opt_expr(self) -> Option<P<ast::Expr>> {
103+
pub(crate) fn make_opt_expr(self) -> Option<P<ast::Expr>> {
104104
match self {
105105
AstFragment::OptExpr(expr) => expr,
106106
_ => panic!("AstFragment::make_* called on the wrong kind of fragment"),
107107
}
108108
}
109109

110-
pub fn make_method_receiver_expr(self) -> P<ast::Expr> {
110+
pub(crate) fn make_method_receiver_expr(self) -> P<ast::Expr> {
111111
match self {
112112
AstFragment::MethodReceiverExpr(expr) => expr,
113113
_ => panic!("AstFragment::make_* called on the wrong kind of fragment"),
@@ -125,7 +125,7 @@ macro_rules! ast_fragments {
125125
T::fragment_to_output(self)
126126
}
127127

128-
pub fn mut_visit_with<F: MutVisitor>(&mut self, vis: &mut F) {
128+
pub(crate) fn mut_visit_with<F: MutVisitor>(&mut self, vis: &mut F) {
129129
match self {
130130
AstFragment::OptExpr(opt_expr) => {
131131
visit_clobber(opt_expr, |opt_expr| {
@@ -372,6 +372,14 @@ impl Invocation {
372372
InvocationKind::Derive { path, .. } => path.span,
373373
}
374374
}
375+
376+
fn span_mut(&mut self) -> &mut Span {
377+
match &mut self.kind {
378+
InvocationKind::Bang { span, .. } => span,
379+
InvocationKind::Attr { attr, .. } => &mut attr.span,
380+
InvocationKind::Derive { path, .. } => &mut path.span,
381+
}
382+
}
375383
}
376384

377385
pub struct MacroExpander<'a, 'b> {
@@ -432,7 +440,8 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
432440
break;
433441
}
434442
invocations = mem::take(&mut undetermined_invocations);
435-
force = !mem::replace(&mut progress, false);
443+
force = !progress;
444+
progress = false;
436445
if force && self.monotonic {
437446
self.cx.dcx().span_delayed_bug(
438447
invocations.last().unwrap().0.span(),
@@ -471,7 +480,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
471480
self.cx.force_mode = force;
472481

473482
let fragment_kind = invoc.fragment_kind;
474-
let (expanded_fragment, new_invocations) = match self.expand_invoc(invoc, &ext.kind) {
483+
match self.expand_invoc(invoc, &ext.kind) {
475484
ExpandResult::Ready(fragment) => {
476485
let mut derive_invocations = Vec::new();
477486
let derive_placeholders = self
@@ -503,12 +512,19 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
503512
})
504513
.unwrap_or_default();
505514

506-
let (fragment, collected_invocations) =
515+
let (expanded_fragment, collected_invocations) =
507516
self.collect_invocations(fragment, &derive_placeholders);
508-
// We choose to expand any derive invocations associated with this macro invocation
509-
// *before* any macro invocations collected from the output fragment
517+
// We choose to expand any derive invocations associated with this macro
518+
// invocation *before* any macro invocations collected from the output
519+
// fragment.
510520
derive_invocations.extend(collected_invocations);
511-
(fragment, derive_invocations)
521+
522+
progress = true;
523+
if expanded_fragments.len() < depth {
524+
expanded_fragments.push(Vec::new());
525+
}
526+
expanded_fragments[depth - 1].push((expn_id, expanded_fragment));
527+
invocations.extend(derive_invocations.into_iter().rev());
512528
}
513529
ExpandResult::Retry(invoc) => {
514530
if force {
@@ -519,17 +535,9 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
519535
} else {
520536
// Cannot expand, will retry this invocation later.
521537
undetermined_invocations.push((invoc, Some(ext)));
522-
continue;
523538
}
524539
}
525-
};
526-
527-
progress = true;
528-
if expanded_fragments.len() < depth {
529-
expanded_fragments.push(Vec::new());
530540
}
531-
expanded_fragments[depth - 1].push((expn_id, expanded_fragment));
532-
invocations.extend(new_invocations.into_iter().rev());
533541
}
534542

535543
self.cx.current_expansion = orig_expansion_data;
@@ -590,11 +598,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
590598
for (invoc, _) in invocations.iter_mut() {
591599
let expn_id = invoc.expansion_data.id;
592600
let parent_def = self.cx.resolver.invocation_parent(expn_id);
593-
let span = match &mut invoc.kind {
594-
InvocationKind::Bang { span, .. } => span,
595-
InvocationKind::Attr { attr, .. } => &mut attr.span,
596-
InvocationKind::Derive { path, .. } => &mut path.span,
597-
};
601+
let span = invoc.span_mut();
598602
*span = span.with_parent(Some(parent_def));
599603
}
600604
}
@@ -957,7 +961,7 @@ pub fn parse_ast_fragment<'a>(
957961
})
958962
}
959963

960-
pub fn ensure_complete_parse<'a>(
964+
pub(crate) fn ensure_complete_parse<'a>(
961965
parser: &Parser<'a>,
962966
macro_path: &ast::Path,
963967
kind_name: &str,

compiler/rustc_expand/src/lib.rs

+10-14
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,39 @@
1+
// tidy-alphabetical-start
2+
#![allow(internal_features)]
3+
#![allow(rustc::diagnostic_outside_of_impl)]
14
#![doc(rust_logo)]
2-
#![feature(rustdoc_internals)]
35
#![feature(array_windows)]
46
#![feature(associated_type_defaults)]
57
#![feature(if_let_guard)]
68
#![feature(let_chains)]
7-
#![feature(lint_reasons)]
89
#![feature(macro_metavar_expr)]
910
#![feature(map_try_insert)]
1011
#![feature(proc_macro_diagnostic)]
1112
#![feature(proc_macro_internals)]
12-
#![feature(proc_macro_span)]
13+
#![feature(rustdoc_internals)]
1314
#![feature(try_blocks)]
1415
#![feature(yeet_expr)]
15-
#![allow(rustc::diagnostic_outside_of_impl)]
16-
#![allow(internal_features)]
16+
// tidy-alphabetical-end
1717

1818
extern crate proc_macro as pm;
1919

20+
mod build;
21+
mod errors;
22+
// FIXME(Nilstrieb) Translate macro_rules diagnostics
23+
#[allow(rustc::untranslatable_diagnostic)]
24+
mod mbe;
2025
mod placeholders;
2126
mod proc_macro_server;
2227

2328
pub use mbe::macro_rules::compile_declarative_macro;
24-
pub(crate) use rustc_span::hygiene;
2529
pub mod base;
26-
pub mod build;
27-
#[macro_use]
2830
pub mod config;
29-
pub mod errors;
3031
pub mod expand;
3132
pub mod module;
32-
3333
// FIXME(Nilstrieb) Translate proc_macro diagnostics
3434
#[allow(rustc::untranslatable_diagnostic)]
3535
pub mod proc_macro;
3636

37-
// FIXME(Nilstrieb) Translate macro_rules diagnostics
38-
#[allow(rustc::untranslatable_diagnostic)]
39-
pub(crate) mod mbe;
40-
4137
// HACK(Centril, #64197): These shouldn't really be here.
4238
// Rather, they should be with their respective modules which are defined in other crates.
4339
// However, since for now constructing a `ParseSess` sorta requires `config` from this crate,

compiler/rustc_expand/src/mbe.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
//! official terminology: "declarative macros".
55
66
pub(crate) mod diagnostics;
7-
pub(crate) mod macro_check;
8-
pub(crate) mod macro_parser;
97
pub(crate) mod macro_rules;
10-
pub(crate) mod metavar_expr;
11-
pub(crate) mod quoted;
12-
pub(crate) mod transcribe;
8+
9+
mod macro_check;
10+
mod macro_parser;
11+
mod metavar_expr;
12+
mod quoted;
13+
mod transcribe;
1314

1415
use metavar_expr::MetaVarExpr;
1516
use rustc_ast::token::{Delimiter, NonterminalKind, Token, TokenKind};

0 commit comments

Comments
 (0)