Skip to content

Commit d3d7317

Browse files
committed
Auto merge of #146910 - matthiaskrgr:rollup-n2qahqc, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #146632 (Fix uses of "adaptor") - #146775 (fixes for numerous clippy warnings) - #146802 (mbe: Simplifications and refactoring) - #146806 (add private module override re-export test) - #146866 ([rustdoc] Correctly handle intra doc link when type alias disambiguator is passed for primitive) - #146896 (rustc-dev-guide subtree update) - #146898 (Update books) r? `@ghost` `@rustbot` modify labels: rollup
2 parents f6092f2 + 9a65b33 commit d3d7317

File tree

30 files changed

+516
-184
lines changed

30 files changed

+516
-184
lines changed

compiler/rustc_expand/src/mbe/metavar_expr.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_ast_pretty::pprust;
55
use rustc_errors::{Applicability, PResult};
66
use rustc_macros::{Decodable, Encodable};
77
use rustc_session::parse::ParseSess;
8-
use rustc_span::{Ident, Span, Symbol};
8+
use rustc_span::{Ident, Span, Symbol, sym};
99

1010
use crate::errors;
1111

@@ -69,15 +69,15 @@ impl MetaVarExpr {
6969
}
7070

7171
let mut iter = args.iter();
72-
let rslt = match ident.as_str() {
73-
"concat" => parse_concat(&mut iter, psess, outer_span, ident.span)?,
74-
"count" => parse_count(&mut iter, psess, ident.span)?,
75-
"ignore" => {
72+
let rslt = match ident.name {
73+
sym::concat => parse_concat(&mut iter, psess, outer_span, ident.span)?,
74+
sym::count => parse_count(&mut iter, psess, ident.span)?,
75+
sym::ignore => {
7676
eat_dollar(&mut iter, psess, ident.span)?;
7777
MetaVarExpr::Ignore(parse_ident(&mut iter, psess, ident.span)?)
7878
}
79-
"index" => MetaVarExpr::Index(parse_depth(&mut iter, psess, ident.span)?),
80-
"len" => MetaVarExpr::Len(parse_depth(&mut iter, psess, ident.span)?),
79+
sym::index => MetaVarExpr::Index(parse_depth(&mut iter, psess, ident.span)?),
80+
sym::len => MetaVarExpr::Len(parse_depth(&mut iter, psess, ident.span)?),
8181
_ => {
8282
let err = errors::MveUnrecognizedExpr {
8383
span: ident.span,
@@ -119,14 +119,13 @@ fn check_trailing_tokens<'psess>(
119119
}
120120

121121
// `None` for max indicates the arg count must be exact, `Some` indicates a range is accepted.
122-
let (min_or_exact_args, max_args) = match ident.as_str() {
123-
"concat" => panic!("concat takes unlimited tokens but didn't eat them all"),
124-
"ignore" => (1, None),
122+
let (min_or_exact_args, max_args) = match ident.name {
123+
sym::concat => panic!("concat takes unlimited tokens but didn't eat them all"),
124+
sym::ignore => (1, None),
125125
// 1 or 2 args
126-
"count" => (1, Some(2)),
126+
sym::count => (1, Some(2)),
127127
// 0 or 1 arg
128-
"index" => (0, Some(1)),
129-
"len" => (0, Some(1)),
128+
sym::index | sym::len => (0, Some(1)),
130129
other => unreachable!("unknown MVEs should be rejected earlier (got `{other}`)"),
131130
};
132131

compiler/rustc_expand/src/mbe/transcribe.rs

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,19 @@ fn transcribe_metavar<'tx>(
375375
return Ok(());
376376
};
377377

378+
let MatchedSingle(pnr) = cur_matched else {
379+
// We were unable to descend far enough. This is an error.
380+
return Err(dcx.create_err(MacroVarStillRepeating { span: sp, ident }));
381+
};
382+
383+
transcribe_pnr(tscx, sp, pnr)
384+
}
385+
386+
fn transcribe_pnr<'tx>(
387+
tscx: &mut TranscrCtx<'tx, '_>,
388+
mut sp: Span,
389+
pnr: &ParseNtResult,
390+
) -> PResult<'tx, ()> {
378391
// We wrap the tokens in invisible delimiters, unless they are already wrapped
379392
// in invisible delimiters with the same `MetaVarKind`. Because some proc
380393
// macros can't handle multiple layers of invisible delimiters of the same
@@ -404,33 +417,33 @@ fn transcribe_metavar<'tx>(
404417
)
405418
};
406419

407-
let tt = match cur_matched {
408-
MatchedSingle(ParseNtResult::Tt(tt)) => {
420+
let tt = match pnr {
421+
ParseNtResult::Tt(tt) => {
409422
// `tt`s are emitted into the output stream directly as "raw tokens",
410423
// without wrapping them into groups. Other variables are emitted into
411424
// the output stream as groups with `Delimiter::Invisible` to maintain
412425
// parsing priorities.
413426
maybe_use_metavar_location(tscx.psess, &tscx.stack, sp, tt, &mut tscx.marker)
414427
}
415-
MatchedSingle(ParseNtResult::Ident(ident, is_raw)) => {
428+
ParseNtResult::Ident(ident, is_raw) => {
416429
tscx.marker.mark_span(&mut sp);
417430
with_metavar_spans(|mspans| mspans.insert(ident.span, sp));
418431
let kind = token::NtIdent(*ident, *is_raw);
419432
TokenTree::token_alone(kind, sp)
420433
}
421-
MatchedSingle(ParseNtResult::Lifetime(ident, is_raw)) => {
434+
ParseNtResult::Lifetime(ident, is_raw) => {
422435
tscx.marker.mark_span(&mut sp);
423436
with_metavar_spans(|mspans| mspans.insert(ident.span, sp));
424437
let kind = token::NtLifetime(*ident, *is_raw);
425438
TokenTree::token_alone(kind, sp)
426439
}
427-
MatchedSingle(ParseNtResult::Item(item)) => {
440+
ParseNtResult::Item(item) => {
428441
mk_delimited(item.span, MetaVarKind::Item, TokenStream::from_ast(item))
429442
}
430-
MatchedSingle(ParseNtResult::Block(block)) => {
443+
ParseNtResult::Block(block) => {
431444
mk_delimited(block.span, MetaVarKind::Block, TokenStream::from_ast(block))
432445
}
433-
MatchedSingle(ParseNtResult::Stmt(stmt)) => {
446+
ParseNtResult::Stmt(stmt) => {
434447
let stream = if let StmtKind::Empty = stmt.kind {
435448
// FIXME: Properly collect tokens for empty statements.
436449
TokenStream::token_alone(token::Semi, stmt.span)
@@ -439,10 +452,10 @@ fn transcribe_metavar<'tx>(
439452
};
440453
mk_delimited(stmt.span, MetaVarKind::Stmt, stream)
441454
}
442-
MatchedSingle(ParseNtResult::Pat(pat, pat_kind)) => {
455+
ParseNtResult::Pat(pat, pat_kind) => {
443456
mk_delimited(pat.span, MetaVarKind::Pat(*pat_kind), TokenStream::from_ast(pat))
444457
}
445-
MatchedSingle(ParseNtResult::Expr(expr, kind)) => {
458+
ParseNtResult::Expr(expr, kind) => {
446459
let (can_begin_literal_maybe_minus, can_begin_string_literal) = match &expr.kind {
447460
ExprKind::Lit(_) => (true, true),
448461
ExprKind::Unary(UnOp::Neg, e) if matches!(&e.kind, ExprKind::Lit(_)) => {
@@ -460,31 +473,27 @@ fn transcribe_metavar<'tx>(
460473
TokenStream::from_ast(expr),
461474
)
462475
}
463-
MatchedSingle(ParseNtResult::Literal(lit)) => {
476+
ParseNtResult::Literal(lit) => {
464477
mk_delimited(lit.span, MetaVarKind::Literal, TokenStream::from_ast(lit))
465478
}
466-
MatchedSingle(ParseNtResult::Ty(ty)) => {
479+
ParseNtResult::Ty(ty) => {
467480
let is_path = matches!(&ty.kind, TyKind::Path(None, _path));
468481
mk_delimited(ty.span, MetaVarKind::Ty { is_path }, TokenStream::from_ast(ty))
469482
}
470-
MatchedSingle(ParseNtResult::Meta(attr_item)) => {
483+
ParseNtResult::Meta(attr_item) => {
471484
let has_meta_form = attr_item.meta_kind().is_some();
472485
mk_delimited(
473486
attr_item.span(),
474487
MetaVarKind::Meta { has_meta_form },
475488
TokenStream::from_ast(attr_item),
476489
)
477490
}
478-
MatchedSingle(ParseNtResult::Path(path)) => {
491+
ParseNtResult::Path(path) => {
479492
mk_delimited(path.span, MetaVarKind::Path, TokenStream::from_ast(path))
480493
}
481-
MatchedSingle(ParseNtResult::Vis(vis)) => {
494+
ParseNtResult::Vis(vis) => {
482495
mk_delimited(vis.span, MetaVarKind::Vis, TokenStream::from_ast(vis))
483496
}
484-
MatchedSeq(..) => {
485-
// We were unable to descend far enough. This is an error.
486-
return Err(dcx.create_err(MacroVarStillRepeating { span: sp, ident }));
487-
}
488497
};
489498

490499
tscx.result.push(tt);

compiler/rustc_hir_typeck/src/pat.rs

Lines changed: 33 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ You can read more about trait objects in the Trait Objects section of the Refere
4747
https://doc.rust-lang.org/reference/types.html#trait-objects";
4848

4949
fn is_number(text: &str) -> bool {
50-
text.chars().all(|c: char| c.is_digit(10))
50+
text.chars().all(|c: char| c.is_ascii_digit())
5151
}
5252

5353
/// Information about the expected type at the top level of type checking a pattern.
@@ -262,8 +262,9 @@ enum InheritedRefMatchRule {
262262
/// pattern matches a given type:
263263
/// - If the underlying type is not a reference, a reference pattern may eat the inherited reference;
264264
/// - If the underlying type is a reference, a reference pattern matches if it can eat either one
265-
/// of the underlying and inherited references. E.g. a `&mut` pattern is allowed if either the
266-
/// underlying type is `&mut` or the inherited reference is `&mut`.
265+
/// of the underlying and inherited references. E.g. a `&mut` pattern is allowed if either the
266+
/// underlying type is `&mut` or the inherited reference is `&mut`.
267+
///
267268
/// If `false`, a reference pattern is only matched against the underlying type.
268269
/// This is `false` for stable Rust and `true` for both the `ref_pat_eat_one_layer_2024` and
269270
/// `ref_pat_eat_one_layer_2024_structural` feature gates.
@@ -1069,7 +1070,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10691070
{
10701071
if !self.tcx.features().mut_ref() {
10711072
feature_err(
1072-
&self.tcx.sess,
1073+
self.tcx.sess,
10731074
sym::mut_ref,
10741075
pat.span.until(ident.span),
10751076
"binding cannot be both mutable and by-reference",
@@ -1487,31 +1488,24 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14871488
opt_def_id: Option<hir::def_id::DefId>,
14881489
ident: Ident,
14891490
) -> bool {
1490-
match opt_def_id {
1491-
Some(def_id) => match self.tcx.hir_get_if_local(def_id) {
1492-
Some(hir::Node::Item(hir::Item {
1493-
kind: hir::ItemKind::Const(_, _, _, body_id),
1494-
..
1495-
})) => match self.tcx.hir_node(body_id.hir_id) {
1496-
hir::Node::Expr(expr) => {
1497-
if hir::is_range_literal(expr) {
1498-
let span = self.tcx.hir_span(body_id.hir_id);
1499-
if let Ok(snip) = self.tcx.sess.source_map().span_to_snippet(span) {
1500-
e.span_suggestion_verbose(
1501-
ident.span,
1502-
"you may want to move the range into the match block",
1503-
snip,
1504-
Applicability::MachineApplicable,
1505-
);
1506-
return true;
1507-
}
1508-
}
1509-
}
1510-
_ => (),
1511-
},
1512-
_ => (),
1513-
},
1514-
_ => (),
1491+
if let Some(def_id) = opt_def_id
1492+
&& let Some(hir::Node::Item(hir::Item {
1493+
kind: hir::ItemKind::Const(_, _, _, body_id),
1494+
..
1495+
})) = self.tcx.hir_get_if_local(def_id)
1496+
&& let hir::Node::Expr(expr) = self.tcx.hir_node(body_id.hir_id)
1497+
&& hir::is_range_literal(expr)
1498+
{
1499+
let span = self.tcx.hir_span(body_id.hir_id);
1500+
if let Ok(snip) = self.tcx.sess.source_map().span_to_snippet(span) {
1501+
e.span_suggestion_verbose(
1502+
ident.span,
1503+
"you may want to move the range into the match block",
1504+
snip,
1505+
Applicability::MachineApplicable,
1506+
);
1507+
return true;
1508+
}
15151509
}
15161510
false
15171511
}
@@ -1529,7 +1523,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15291523

15301524
if let Some(span) = self.tcx.hir_res_span(pat_res) {
15311525
e.span_label(span, format!("{} defined here", res.descr()));
1532-
if let [hir::PathSegment { ident, .. }] = &*segments {
1526+
if let [hir::PathSegment { ident, .. }] = segments {
15331527
e.span_label(
15341528
pat_span,
15351529
format!(
@@ -1557,17 +1551,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15571551
_ => (None, None),
15581552
};
15591553

1560-
let is_range = match type_def_id.and_then(|id| self.tcx.as_lang_item(id)) {
1554+
let is_range = matches!(
1555+
type_def_id.and_then(|id| self.tcx.as_lang_item(id)),
15611556
Some(
15621557
LangItem::Range
1563-
| LangItem::RangeFrom
1564-
| LangItem::RangeTo
1565-
| LangItem::RangeFull
1566-
| LangItem::RangeInclusiveStruct
1567-
| LangItem::RangeToInclusive,
1568-
) => true,
1569-
_ => false,
1570-
};
1558+
| LangItem::RangeFrom
1559+
| LangItem::RangeTo
1560+
| LangItem::RangeFull
1561+
| LangItem::RangeInclusiveStruct
1562+
| LangItem::RangeToInclusive,
1563+
)
1564+
);
15711565
if is_range {
15721566
if !self.maybe_suggest_range_literal(&mut e, item_def_id, *ident) {
15731567
let msg = "constants only support matching by type, \

library/core/src/iter/adapters/flatten.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ impl<T> OneShot for result::IterMut<'_, T> {}
779779
impl<T> OneShot for Empty<T> {}
780780
impl<T> OneShot for array::IntoIter<T, 0> {}
781781

782-
// These adaptors never increase the number of items.
782+
// These adapters never increase the number of items.
783783
// (There are more possible, but for now this matches BoundedSize above.)
784784
impl<I: OneShot> OneShot for Cloned<I> {}
785785
impl<I: OneShot> OneShot for Copied<I> {}

library/std/src/io/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,7 @@ pub trait Read {
10811081
default_read_buf_exact(self, cursor)
10821082
}
10831083

1084-
/// Creates a "by reference" adaptor for this instance of `Read`.
1084+
/// Creates a "by reference" adapter for this instance of `Read`.
10851085
///
10861086
/// The returned adapter also implements `Read` and will simply borrow this
10871087
/// current reader.

src/doc/rust-by-example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2f3f27bf79ec147fec9d2e7980605307a74067f4
1+
9f32ccf35fb877270bc44a86a126440f04d676d0

src/doc/rustc-dev-guide/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
- [Installation](./autodiff/installation.md)
109109
- [How to debug](./autodiff/debugging.md)
110110
- [Autodiff flags](./autodiff/flags.md)
111+
- [Type Trees](./autodiff/type-trees.md)
111112

112113
# Source Code Representation
113114

0 commit comments

Comments
 (0)