Skip to content

Commit 6ac8878

Browse files
committed
Auto merge of #136292 - matthiaskrgr:rollup-fw1tlca, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #133636 ([rustdoc] Add sans-serif font setting) - #135434 (Match Ergonomics 2024: update edition 2024 behavior of feature gates) - #135739 (Clean up uses of the unstable `dwarf_version` option) - #135882 (simplify `similar_tokens` from `Option<Vec<_>>` to `&[_]`) - #136179 (Allow transmuting generic pattern types to and from their base) - #136199 (Fix a couple Emscripten tests) - #136251 (use impl Into<String> instead of explicit type args with bounds) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a6434ef + 9b7af17 commit 6ac8878

File tree

70 files changed

+2198
-416
lines changed

Some content is hidden

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

70 files changed

+2198
-416
lines changed

REUSE.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ SPDX-FileCopyrightText = "2015 Anders Kaseorg <[email protected]>"
9292
SPDX-License-Identifier = "MIT"
9393

9494
[[annotations]]
95-
path = "src/librustdoc/html/static/fonts/FiraSans**"
95+
path = "src/librustdoc/html/static/fonts/Fira**"
9696
precedence = "override"
9797
SPDX-FileCopyrightText = ["2014, Mozilla Foundation", "2014, Telefonica S.A."]
9898
SPDX-License-Identifier = "OFL-1.1"

compiler/rustc_ast/src/token.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -527,13 +527,13 @@ impl TokenKind {
527527

528528
/// Returns tokens that are likely to be typed accidentally instead of the current token.
529529
/// Enables better error recovery when the wrong token is found.
530-
pub fn similar_tokens(&self) -> Option<Vec<TokenKind>> {
531-
match *self {
532-
Comma => Some(vec![Dot, Lt, Semi]),
533-
Semi => Some(vec![Colon, Comma]),
534-
Colon => Some(vec![Semi]),
535-
FatArrow => Some(vec![Eq, RArrow, Ge, Gt]),
536-
_ => None,
530+
pub fn similar_tokens(&self) -> &[TokenKind] {
531+
match self {
532+
Comma => &[Dot, Lt, Semi],
533+
Semi => &[Colon, Comma],
534+
Colon => &[Semi],
535+
FatArrow => &[Eq, RArrow, Ge, Gt],
536+
_ => &[],
537537
}
538538
}
539539

compiler/rustc_builtin_macros/src/format.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,14 @@ fn parse_args<'a>(ecx: &ExtCtxt<'a>, sp: Span, tts: TokenStream) -> PResult<'a,
101101

102102
match p.expect(exp!(Comma)) {
103103
Err(err) => {
104-
match token::TokenKind::Comma.similar_tokens() {
105-
Some(tks) if tks.contains(&p.token.kind) => {
106-
// If a similar token is found, then it may be a typo. We
107-
// consider it as a comma, and continue parsing.
108-
err.emit();
109-
p.bump();
110-
}
104+
if token::TokenKind::Comma.similar_tokens().contains(&p.token.kind) {
105+
// If a similar token is found, then it may be a typo. We
106+
// consider it as a comma, and continue parsing.
107+
err.emit();
108+
p.bump();
109+
} else {
111110
// Otherwise stop the parsing and return the error.
112-
_ => return Err(err),
111+
return Err(err);
113112
}
114113
}
115114
Ok(Recovered::Yes(_)) => (),

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -919,8 +919,7 @@ pub(crate) fn build_compile_unit_di_node<'ll, 'tcx>(
919919
.unwrap_or_default();
920920
let kind = DebugEmissionKind::from_generic(tcx.sess.opts.debuginfo);
921921

922-
let dwarf_version =
923-
tcx.sess.opts.unstable_opts.dwarf_version.unwrap_or(tcx.sess.target.default_dwarf_version);
922+
let dwarf_version = tcx.sess.dwarf_version();
924923
let is_dwarf_kind =
925924
matches!(tcx.sess.target.debuginfo_kind, DebuginfoKind::Dwarf | DebuginfoKind::DwarfDsym);
926925
// Don't emit `.debug_pubnames` and `.debug_pubtypes` on DWARFv4 or lower.

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

+26-23
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use rustc_session::config::{self, DebugInfo};
2222
use rustc_span::{
2323
BytePos, Pos, SourceFile, SourceFileAndLine, SourceFileHash, Span, StableSourceFileId, Symbol,
2424
};
25+
use rustc_target::spec::DebuginfoKind;
2526
use smallvec::SmallVec;
2627
use tracing::debug;
2728

@@ -93,29 +94,31 @@ impl<'ll, 'tcx> CodegenUnitDebugContext<'ll, 'tcx> {
9394

9495
pub(crate) fn finalize(&self, sess: &Session) {
9596
unsafe { llvm::LLVMRustDIBuilderFinalize(self.builder) };
96-
if !sess.target.is_like_msvc {
97-
// Debuginfo generation in LLVM by default uses a higher
98-
// version of dwarf than macOS currently understands. We can
99-
// instruct LLVM to emit an older version of dwarf, however,
100-
// for macOS to understand. For more info see #11352
101-
// This can be overridden using --llvm-opts -dwarf-version,N.
102-
// Android has the same issue (#22398)
103-
let dwarf_version =
104-
sess.opts.unstable_opts.dwarf_version.unwrap_or(sess.target.default_dwarf_version);
105-
llvm::add_module_flag_u32(
106-
self.llmod,
107-
llvm::ModuleFlagMergeBehavior::Warning,
108-
"Dwarf Version",
109-
dwarf_version,
110-
);
111-
} else {
112-
// Indicate that we want CodeView debug information on MSVC
113-
llvm::add_module_flag_u32(
114-
self.llmod,
115-
llvm::ModuleFlagMergeBehavior::Warning,
116-
"CodeView",
117-
1,
118-
);
97+
98+
match sess.target.debuginfo_kind {
99+
DebuginfoKind::Dwarf | DebuginfoKind::DwarfDsym => {
100+
// Debuginfo generation in LLVM by default uses a higher
101+
// version of dwarf than macOS currently understands. We can
102+
// instruct LLVM to emit an older version of dwarf, however,
103+
// for macOS to understand. For more info see #11352
104+
// This can be overridden using --llvm-opts -dwarf-version,N.
105+
// Android has the same issue (#22398)
106+
llvm::add_module_flag_u32(
107+
self.llmod,
108+
llvm::ModuleFlagMergeBehavior::Warning,
109+
"Dwarf Version",
110+
sess.dwarf_version(),
111+
);
112+
}
113+
DebuginfoKind::Pdb => {
114+
// Indicate that we want CodeView debug information
115+
llvm::add_module_flag_u32(
116+
self.llmod,
117+
llvm::ModuleFlagMergeBehavior::Warning,
118+
"CodeView",
119+
1,
120+
);
121+
}
119122
}
120123

121124
// Prevent bitcode readers from deleting the debug info.

compiler/rustc_hir_typeck/src/pat.rs

+53-33
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
243243
fn downgrade_mut_inside_shared(&self) -> bool {
244244
// NB: RFC 3627 proposes stabilizing Rule 3 in all editions. If we adopt the same behavior
245245
// across all editions, this may be removed.
246-
self.tcx.features().ref_pat_eat_one_layer_2024()
247-
|| self.tcx.features().ref_pat_eat_one_layer_2024_structural()
246+
self.tcx.features().ref_pat_eat_one_layer_2024_structural()
248247
}
249248

250249
/// Experimental pattern feature: when do reference patterns match against inherited references?
@@ -435,7 +434,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
435434
max_ref_mutbl: MutblCap,
436435
) -> (Ty<'tcx>, ByRef, MutblCap) {
437436
#[cfg(debug_assertions)]
438-
if def_br == ByRef::Yes(Mutability::Mut) && max_ref_mutbl != MutblCap::Mut {
437+
if def_br == ByRef::Yes(Mutability::Mut)
438+
&& max_ref_mutbl != MutblCap::Mut
439+
&& self.downgrade_mut_inside_shared()
440+
{
439441
span_bug!(pat.span, "Pattern mutability cap violated!");
440442
}
441443
match adjust_mode {
@@ -2328,22 +2330,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23282330
// (RFC 3627, Rule 5). If we implement a pattern typing ruleset with Rule 4E
23292331
// but not Rule 5, we'll need to check that here.
23302332
debug_assert!(ref_pat_matches_mut_ref);
2331-
let err_msg = "mismatched types";
2332-
let err = if let Some(span) = pat_prefix_span {
2333-
let mut err = self.dcx().struct_span_err(span, err_msg);
2334-
err.code(E0308);
2335-
err.note("cannot match inherited `&` with `&mut` pattern");
2336-
err.span_suggestion_verbose(
2337-
span,
2338-
"replace this `&mut` pattern with `&`",
2339-
"&",
2340-
Applicability::MachineApplicable,
2341-
);
2342-
err
2343-
} else {
2344-
self.dcx().struct_span_err(pat.span, err_msg)
2345-
};
2346-
err.emit();
2333+
self.error_inherited_ref_mutability_mismatch(pat, pat_prefix_span);
23472334
}
23482335

23492336
pat_info.binding_mode = ByRef::No;
@@ -2352,28 +2339,38 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23522339
return expected;
23532340
}
23542341
InheritedRefMatchRule::EatInner => {
2355-
if let ty::Ref(_, _, r_mutbl) = *expected.kind() {
2342+
if let ty::Ref(_, _, r_mutbl) = *expected.kind()
2343+
&& pat_mutbl <= r_mutbl
2344+
{
23562345
// Match against the reference type; don't consume the inherited ref.
2357-
pat_info.binding_mode = pat_info.binding_mode.cap_ref_mutability(r_mutbl);
2346+
// NB: The check for compatible pattern and ref type mutability assumes that
2347+
// `&` patterns can match against mutable references (RFC 3627, Rule 5). If
2348+
// we implement a pattern typing ruleset with Rule 4 (including the fallback
2349+
// to matching the inherited ref when the inner ref can't match) but not
2350+
// Rule 5, we'll need to check that here.
2351+
debug_assert!(ref_pat_matches_mut_ref);
2352+
// NB: For RFC 3627's Rule 3, we limit the default binding mode's ref
2353+
// mutability to `pat_info.max_ref_mutbl`. If we implement a pattern typing
2354+
// ruleset with Rule 4 but not Rule 3, we'll need to check that here.
2355+
debug_assert!(self.downgrade_mut_inside_shared());
2356+
let mutbl_cap = cmp::min(r_mutbl, pat_info.max_ref_mutbl.as_mutbl());
2357+
pat_info.binding_mode = pat_info.binding_mode.cap_ref_mutability(mutbl_cap);
23582358
} else {
2359-
// The expected type isn't a reference, so match against the inherited ref.
2359+
// The reference pattern can't match against the expected type, so try
2360+
// matching against the inherited ref instead.
23602361
if pat_mutbl > inh_mut {
2361-
// We can't match an inherited shared reference with `&mut`. This will
2362-
// be a type error later, since we're matching a reference pattern
2363-
// against a non-reference type.
2362+
// We can't match an inherited shared reference with `&mut`.
23642363
// NB: This assumes that `&` patterns can match against mutable
23652364
// references (RFC 3627, Rule 5). If we implement a pattern typing
23662365
// ruleset with Rule 4 but not Rule 5, we'll need to check that here.
23672366
debug_assert!(ref_pat_matches_mut_ref);
2368-
} else {
2369-
pat_info.binding_mode = ByRef::No;
2370-
self.typeck_results
2371-
.borrow_mut()
2372-
.skipped_ref_pats_mut()
2373-
.insert(pat.hir_id);
2374-
self.check_pat(inner, expected, pat_info);
2375-
return expected;
2367+
self.error_inherited_ref_mutability_mismatch(pat, pat_prefix_span);
23762368
}
2369+
2370+
pat_info.binding_mode = ByRef::No;
2371+
self.typeck_results.borrow_mut().skipped_ref_pats_mut().insert(pat.hir_id);
2372+
self.check_pat(inner, expected, pat_info);
2373+
return expected;
23772374
}
23782375
}
23792376
InheritedRefMatchRule::EatBoth => {
@@ -2447,6 +2444,29 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
24472444
Ty::new_ref(self.tcx, region, ty, mutbl)
24482445
}
24492446

2447+
fn error_inherited_ref_mutability_mismatch(
2448+
&self,
2449+
pat: &'tcx Pat<'tcx>,
2450+
pat_prefix_span: Option<Span>,
2451+
) -> ErrorGuaranteed {
2452+
let err_msg = "mismatched types";
2453+
let err = if let Some(span) = pat_prefix_span {
2454+
let mut err = self.dcx().struct_span_err(span, err_msg);
2455+
err.code(E0308);
2456+
err.note("cannot match inherited `&` with `&mut` pattern");
2457+
err.span_suggestion_verbose(
2458+
span,
2459+
"replace this `&mut` pattern with `&`",
2460+
"&",
2461+
Applicability::MachineApplicable,
2462+
);
2463+
err
2464+
} else {
2465+
self.dcx().struct_span_err(pat.span, err_msg)
2466+
};
2467+
err.emit()
2468+
}
2469+
24502470
fn try_resolve_slice_ty_to_array_ty(
24512471
&self,
24522472
before: &'tcx [Pat<'tcx>],

compiler/rustc_middle/src/ty/layout.rs

+3
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,9 @@ impl<'tcx> SizeSkeleton<'tcx> {
504504
}
505505
}
506506

507+
// Pattern types are always the same size as their base.
508+
ty::Pat(base, _) => SizeSkeleton::compute(base, tcx, typing_env),
509+
507510
_ => Err(err),
508511
}
509512
}

compiler/rustc_parse/src/parser/expr.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -3114,9 +3114,8 @@ impl<'a> Parser<'a> {
31143114
let span_before_body = this.prev_token.span;
31153115
let arm_body;
31163116
let is_fat_arrow = this.check(exp!(FatArrow));
3117-
let is_almost_fat_arrow = TokenKind::FatArrow
3118-
.similar_tokens()
3119-
.is_some_and(|similar_tokens| similar_tokens.contains(&this.token.kind));
3117+
let is_almost_fat_arrow =
3118+
TokenKind::FatArrow.similar_tokens().contains(&this.token.kind);
31203119

31213120
// this avoids the compiler saying that a `,` or `}` was expected even though
31223121
// the pattern isn't a never pattern (and thus an arm body is required)

compiler/rustc_parse/src/parser/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -924,10 +924,8 @@ impl<'a> Parser<'a> {
924924

925925
_ => {
926926
// Attempt to keep parsing if it was a similar separator.
927-
if let Some(tokens) = exp.tok.similar_tokens() {
928-
if tokens.contains(&self.token.kind) {
929-
self.bump();
930-
}
927+
if exp.tok.similar_tokens().contains(&self.token.kind) {
928+
self.bump();
931929
}
932930
}
933931
}

compiler/rustc_parse_format/src/lib.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -363,12 +363,7 @@ impl<'a> Parser<'a> {
363363
/// Notifies of an error. The message doesn't actually need to be of type
364364
/// String, but I think it does when this eventually uses conditions so it
365365
/// might as well start using it now.
366-
fn err<S1: Into<String>, S2: Into<String>>(
367-
&mut self,
368-
description: S1,
369-
label: S2,
370-
span: InnerSpan,
371-
) {
366+
fn err(&mut self, description: impl Into<String>, label: impl Into<String>, span: InnerSpan) {
372367
self.errors.push(ParseError {
373368
description: description.into(),
374369
note: None,
@@ -382,11 +377,11 @@ impl<'a> Parser<'a> {
382377
/// Notifies of an error. The message doesn't actually need to be of type
383378
/// String, but I think it does when this eventually uses conditions so it
384379
/// might as well start using it now.
385-
fn err_with_note<S1: Into<String>, S2: Into<String>, S3: Into<String>>(
380+
fn err_with_note(
386381
&mut self,
387-
description: S1,
388-
label: S2,
389-
note: S3,
382+
description: impl Into<String>,
383+
label: impl Into<String>,
384+
note: impl Into<String>,
390385
span: InnerSpan,
391386
) {
392387
self.errors.push(ParseError {

compiler/rustc_session/src/options.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1803,6 +1803,7 @@ options! {
18031803
"output statistics about monomorphization collection"),
18041804
dump_mono_stats_format: DumpMonoStatsFormat = (DumpMonoStatsFormat::Markdown, parse_dump_mono_stats, [UNTRACKED],
18051805
"the format to use for -Z dump-mono-stats (`markdown` (default) or `json`)"),
1806+
#[rustc_lint_opt_deny_field_access("use `Session::dwarf_version` instead of this field")]
18061807
dwarf_version: Option<u32> = (None, parse_opt_number, [TRACKED],
18071808
"version of DWARF debug information to emit (default: 2 or 4, depending on platform)"),
18081809
dylib_lto: bool = (false, parse_bool, [UNTRACKED],

compiler/rustc_session/src/session.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,11 @@ impl Session {
732732
self.opts.cg.split_debuginfo.unwrap_or(self.target.split_debuginfo)
733733
}
734734

735+
/// Returns the DWARF version passed on the CLI or the default for the target.
736+
pub fn dwarf_version(&self) -> u32 {
737+
self.opts.unstable_opts.dwarf_version.unwrap_or(self.target.default_dwarf_version)
738+
}
739+
735740
pub fn stack_protector(&self) -> StackProtector {
736741
if self.target.options.supports_stack_protector {
737742
self.opts.unstable_opts.stack_protector
@@ -1263,8 +1268,7 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
12631268
}
12641269

12651270
if sess.opts.unstable_opts.embed_source {
1266-
let dwarf_version =
1267-
sess.opts.unstable_opts.dwarf_version.unwrap_or(sess.target.default_dwarf_version);
1271+
let dwarf_version = sess.dwarf_version();
12681272

12691273
if dwarf_version < 5 {
12701274
sess.dcx().emit_warn(errors::EmbedSourceInsufficientDwarfVersion { dwarf_version });

license-metadata.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,12 @@
113113
{
114114
"directories": [],
115115
"files": [
116+
"FiraMono-Medium.woff2",
117+
"FiraMono-Regular.woff2",
118+
"FiraSans-Italic.woff2",
116119
"FiraSans-LICENSE.txt",
117120
"FiraSans-Medium.woff2",
121+
"FiraSans-MediumItalic.woff2",
118122
"FiraSans-Regular.woff2"
119123
],
120124
"license": {
@@ -266,4 +270,4 @@
266270
],
267271
"type": "root"
268272
}
269-
}
273+
}

src/doc/unstable-book/src/compiler-flags/dwarf-version.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## `dwarf-version`
22

3+
The tracking issue for this feature is: <https://github.com/rust-lang/rust/issues/103057>
4+
5+
----------------------------
6+
37
This option controls the version of DWARF that the compiler emits, on platforms
48
that use DWARF to encode debug information. It takes one of the following
59
values:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# `ref_pat_eat_one_layer_2024_structural`
2+
3+
The tracking issue for this feature is: [#123076]
4+
5+
[#123076]: https://github.com/rust-lang/rust/issues/123076
6+
7+
---
8+
9+
This feature is incomplete and not yet intended for general use.
10+
11+
This implements experimental, Edition-dependent match ergonomics under consideration for inclusion
12+
in Rust.
13+
For more information, see the corresponding typing rules for [Editions 2024 and later].
14+
On earlier Editions, the current behavior is unspecified.
15+
16+
For alternative experimental match ergonomics, see the feature
17+
[`ref_pat_eat_one_layer_2024`](./ref-pat-eat-one-layer-2024.md).
18+
19+
[Editions 2024 and later]: https://nadrieril.github.io/typing-rust-patterns/?compare=false&opts1=AQEBAgEBAQEBAgIAAAAAAAAAAAAAAAA%3D&mode=rules&do_cmp=false

0 commit comments

Comments
 (0)