Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 7 pull requests #136292

Merged
merged 35 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
a56f9ad
remove Rule 3 from `ref_pat_eat_one_layer_2024`
dianne Jan 3, 2025
c57708a
add more tests where the rulesets disagree
dianne Jan 4, 2025
c037695
"structural" ruleset: account for dbm mutability cap in Deref(EatInne…
dianne Jan 5, 2025
f8315ae
"structural" ruleset: use the "classic" ruleset's diagnostic and fall…
dianne Jan 6, 2025
586ff15
"structural" ruleset: match against the inherited ref when a referenc…
dianne Jan 13, 2025
3f9b198
rename tests' revisions to allow testing multiple editions
dianne Jan 15, 2025
fdcbd71
minor test cleanup
dianne Jan 21, 2025
afd976b
add more information to old tests
dianne Jan 21, 2025
4ed44c9
add a stable edition 2021 revision to pattern typing tests
dianne Jan 21, 2025
f5567e1
organize old well-typed-edition-2024 tests
dianne Jan 21, 2025
e288cff
add tests differing between stable and new rules (with errors on new …
dianne Jan 21, 2025
ccb9674
simplify similar_tokens from Option<Vec<_>> to Vec<_>
hkBst Jan 22, 2025
5f01e12
simplify similar_tokens from Vec<_> to &[_]
hkBst Jan 22, 2025
be7d6e3
add work-in-progress unstable book chapters
dianne Jan 21, 2025
5df5193
Fix tests/codegen/float/f128
purplesyringa Jan 28, 2025
efaeede
Fix tests/codegen/wasm_exceptions
purplesyringa Jan 28, 2025
644e527
Fix tests/ui/privacy/sysroot-private
purplesyringa Jan 28, 2025
57cfcd2
use impl Into<String>
hkBst Jan 23, 2025
d93cbe5
Add new setting allowing to switch to sans serif fonts
GuillaumeGomez Dec 3, 2024
65fedeb
Add GUI test for new "sans serif fonts" setting
GuillaumeGomez Dec 3, 2024
91f6e00
Fix tidy errors
GuillaumeGomez Dec 3, 2024
999a25e
Fix tidy errors
GuillaumeGomez Dec 3, 2024
895564e
Add italic for newly added sans serif fonts
GuillaumeGomez Jan 18, 2025
22f0741
Add tests for transmuting pattern types
oli-obk Jan 28, 2025
a639e27
Allow transmuting generic pattern types to and from their base
oli-obk Jan 28, 2025
2511faf
Add SemiBold for SourceSerif4
GuillaumeGomez Jan 29, 2025
51eaa0d
Clean up uses of the unstable `dwarf_version` option
wesleywiser Jan 19, 2025
4d5a63f
Add tracking issue to docs
wesleywiser Jan 19, 2025
282d866
Rollup merge of #133636 - GuillaumeGomez:sans-serif, r=rustdoc
matthiaskrgr Jan 30, 2025
a366357
Rollup merge of #135434 - dianne:match-2024-for-edition-2024, r=Nadri…
matthiaskrgr Jan 30, 2025
aedc0a3
Rollup merge of #135739 - wesleywiser:dwarf_version_handling, r=lqd
matthiaskrgr Jan 30, 2025
78ded09
Rollup merge of #135882 - hkBst:master, r=estebank
matthiaskrgr Jan 30, 2025
aab61ad
Rollup merge of #136179 - oli-obk:push-vxvyttorquxw, r=BoxyUwU
matthiaskrgr Jan 30, 2025
d7668d8
Rollup merge of #136199 - purplesyringa:emscripten-tests, r=jieyouxu
matthiaskrgr Jan 30, 2025
9b7af17
Rollup merge of #136251 - hkBst:opt_imports, r=estebank
matthiaskrgr Jan 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion REUSE.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ SPDX-FileCopyrightText = "2015 Anders Kaseorg <[email protected]>"
SPDX-License-Identifier = "MIT"

[[annotations]]
path = "src/librustdoc/html/static/fonts/FiraSans**"
path = "src/librustdoc/html/static/fonts/Fira**"
precedence = "override"
SPDX-FileCopyrightText = ["2014, Mozilla Foundation", "2014, Telefonica S.A."]
SPDX-License-Identifier = "OFL-1.1"
Expand Down
14 changes: 7 additions & 7 deletions compiler/rustc_ast/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,13 +527,13 @@ impl TokenKind {

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

Expand Down
15 changes: 7 additions & 8 deletions compiler/rustc_builtin_macros/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,14 @@ fn parse_args<'a>(ecx: &ExtCtxt<'a>, sp: Span, tts: TokenStream) -> PResult<'a,

match p.expect(exp!(Comma)) {
Err(err) => {
match token::TokenKind::Comma.similar_tokens() {
Some(tks) if tks.contains(&p.token.kind) => {
// If a similar token is found, then it may be a typo. We
// consider it as a comma, and continue parsing.
err.emit();
p.bump();
}
if token::TokenKind::Comma.similar_tokens().contains(&p.token.kind) {
// If a similar token is found, then it may be a typo. We
// consider it as a comma, and continue parsing.
err.emit();
p.bump();
} else {
// Otherwise stop the parsing and return the error.
_ => return Err(err),
return Err(err);
}
}
Ok(Recovered::Yes(_)) => (),
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -919,8 +919,7 @@ pub(crate) fn build_compile_unit_di_node<'ll, 'tcx>(
.unwrap_or_default();
let kind = DebugEmissionKind::from_generic(tcx.sess.opts.debuginfo);

let dwarf_version =
tcx.sess.opts.unstable_opts.dwarf_version.unwrap_or(tcx.sess.target.default_dwarf_version);
let dwarf_version = tcx.sess.dwarf_version();
let is_dwarf_kind =
matches!(tcx.sess.target.debuginfo_kind, DebuginfoKind::Dwarf | DebuginfoKind::DwarfDsym);
// Don't emit `.debug_pubnames` and `.debug_pubtypes` on DWARFv4 or lower.
Expand Down
49 changes: 26 additions & 23 deletions compiler/rustc_codegen_llvm/src/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use rustc_session::config::{self, DebugInfo};
use rustc_span::{
BytePos, Pos, SourceFile, SourceFileAndLine, SourceFileHash, Span, StableSourceFileId, Symbol,
};
use rustc_target::spec::DebuginfoKind;
use smallvec::SmallVec;
use tracing::debug;

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

pub(crate) fn finalize(&self, sess: &Session) {
unsafe { llvm::LLVMRustDIBuilderFinalize(self.builder) };
if !sess.target.is_like_msvc {
// Debuginfo generation in LLVM by default uses a higher
// version of dwarf than macOS currently understands. We can
// instruct LLVM to emit an older version of dwarf, however,
// for macOS to understand. For more info see #11352
// This can be overridden using --llvm-opts -dwarf-version,N.
// Android has the same issue (#22398)
let dwarf_version =
sess.opts.unstable_opts.dwarf_version.unwrap_or(sess.target.default_dwarf_version);
llvm::add_module_flag_u32(
self.llmod,
llvm::ModuleFlagMergeBehavior::Warning,
"Dwarf Version",
dwarf_version,
);
} else {
// Indicate that we want CodeView debug information on MSVC
llvm::add_module_flag_u32(
self.llmod,
llvm::ModuleFlagMergeBehavior::Warning,
"CodeView",
1,
);

match sess.target.debuginfo_kind {
DebuginfoKind::Dwarf | DebuginfoKind::DwarfDsym => {
// Debuginfo generation in LLVM by default uses a higher
// version of dwarf than macOS currently understands. We can
// instruct LLVM to emit an older version of dwarf, however,
// for macOS to understand. For more info see #11352
// This can be overridden using --llvm-opts -dwarf-version,N.
// Android has the same issue (#22398)
llvm::add_module_flag_u32(
self.llmod,
llvm::ModuleFlagMergeBehavior::Warning,
"Dwarf Version",
sess.dwarf_version(),
);
}
DebuginfoKind::Pdb => {
// Indicate that we want CodeView debug information
llvm::add_module_flag_u32(
self.llmod,
llvm::ModuleFlagMergeBehavior::Warning,
"CodeView",
1,
);
}
}

// Prevent bitcode readers from deleting the debug info.
Expand Down
86 changes: 53 additions & 33 deletions compiler/rustc_hir_typeck/src/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fn downgrade_mut_inside_shared(&self) -> bool {
// NB: RFC 3627 proposes stabilizing Rule 3 in all editions. If we adopt the same behavior
// across all editions, this may be removed.
self.tcx.features().ref_pat_eat_one_layer_2024()
|| self.tcx.features().ref_pat_eat_one_layer_2024_structural()
self.tcx.features().ref_pat_eat_one_layer_2024_structural()
}

/// Experimental pattern feature: when do reference patterns match against inherited references?
Expand Down Expand Up @@ -435,7 +434,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
max_ref_mutbl: MutblCap,
) -> (Ty<'tcx>, ByRef, MutblCap) {
#[cfg(debug_assertions)]
if def_br == ByRef::Yes(Mutability::Mut) && max_ref_mutbl != MutblCap::Mut {
if def_br == ByRef::Yes(Mutability::Mut)
&& max_ref_mutbl != MutblCap::Mut
&& self.downgrade_mut_inside_shared()
{
span_bug!(pat.span, "Pattern mutability cap violated!");
}
match adjust_mode {
Expand Down Expand Up @@ -2328,22 +2330,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// (RFC 3627, Rule 5). If we implement a pattern typing ruleset with Rule 4E
// but not Rule 5, we'll need to check that here.
debug_assert!(ref_pat_matches_mut_ref);
let err_msg = "mismatched types";
let err = if let Some(span) = pat_prefix_span {
let mut err = self.dcx().struct_span_err(span, err_msg);
err.code(E0308);
err.note("cannot match inherited `&` with `&mut` pattern");
err.span_suggestion_verbose(
span,
"replace this `&mut` pattern with `&`",
"&",
Applicability::MachineApplicable,
);
err
} else {
self.dcx().struct_span_err(pat.span, err_msg)
};
err.emit();
self.error_inherited_ref_mutability_mismatch(pat, pat_prefix_span);
}

pat_info.binding_mode = ByRef::No;
Expand All @@ -2352,28 +2339,38 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return expected;
}
InheritedRefMatchRule::EatInner => {
if let ty::Ref(_, _, r_mutbl) = *expected.kind() {
if let ty::Ref(_, _, r_mutbl) = *expected.kind()
&& pat_mutbl <= r_mutbl
{
// Match against the reference type; don't consume the inherited ref.
pat_info.binding_mode = pat_info.binding_mode.cap_ref_mutability(r_mutbl);
// NB: The check for compatible pattern and ref type mutability assumes that
// `&` patterns can match against mutable references (RFC 3627, Rule 5). If
// we implement a pattern typing ruleset with Rule 4 (including the fallback
// to matching the inherited ref when the inner ref can't match) but not
// Rule 5, we'll need to check that here.
debug_assert!(ref_pat_matches_mut_ref);
// NB: For RFC 3627's Rule 3, we limit the default binding mode's ref
// mutability to `pat_info.max_ref_mutbl`. If we implement a pattern typing
// ruleset with Rule 4 but not Rule 3, we'll need to check that here.
debug_assert!(self.downgrade_mut_inside_shared());
let mutbl_cap = cmp::min(r_mutbl, pat_info.max_ref_mutbl.as_mutbl());
pat_info.binding_mode = pat_info.binding_mode.cap_ref_mutability(mutbl_cap);
} else {
// The expected type isn't a reference, so match against the inherited ref.
// The reference pattern can't match against the expected type, so try
// matching against the inherited ref instead.
if pat_mutbl > inh_mut {
// We can't match an inherited shared reference with `&mut`. This will
// be a type error later, since we're matching a reference pattern
// against a non-reference type.
// We can't match an inherited shared reference with `&mut`.
// NB: This assumes that `&` patterns can match against mutable
// references (RFC 3627, Rule 5). If we implement a pattern typing
// ruleset with Rule 4 but not Rule 5, we'll need to check that here.
debug_assert!(ref_pat_matches_mut_ref);
} else {
pat_info.binding_mode = ByRef::No;
self.typeck_results
.borrow_mut()
.skipped_ref_pats_mut()
.insert(pat.hir_id);
self.check_pat(inner, expected, pat_info);
return expected;
self.error_inherited_ref_mutability_mismatch(pat, pat_prefix_span);
}

pat_info.binding_mode = ByRef::No;
self.typeck_results.borrow_mut().skipped_ref_pats_mut().insert(pat.hir_id);
self.check_pat(inner, expected, pat_info);
return expected;
}
}
InheritedRefMatchRule::EatBoth => {
Expand Down Expand Up @@ -2447,6 +2444,29 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Ty::new_ref(self.tcx, region, ty, mutbl)
}

fn error_inherited_ref_mutability_mismatch(
&self,
pat: &'tcx Pat<'tcx>,
pat_prefix_span: Option<Span>,
) -> ErrorGuaranteed {
let err_msg = "mismatched types";
let err = if let Some(span) = pat_prefix_span {
let mut err = self.dcx().struct_span_err(span, err_msg);
err.code(E0308);
err.note("cannot match inherited `&` with `&mut` pattern");
err.span_suggestion_verbose(
span,
"replace this `&mut` pattern with `&`",
"&",
Applicability::MachineApplicable,
);
err
} else {
self.dcx().struct_span_err(pat.span, err_msg)
};
err.emit()
}

fn try_resolve_slice_ty_to_array_ty(
&self,
before: &'tcx [Pat<'tcx>],
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,9 @@ impl<'tcx> SizeSkeleton<'tcx> {
}
}

// Pattern types are always the same size as their base.
ty::Pat(base, _) => SizeSkeleton::compute(base, tcx, typing_env),

_ => Err(err),
}
}
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3114,9 +3114,8 @@ impl<'a> Parser<'a> {
let span_before_body = this.prev_token.span;
let arm_body;
let is_fat_arrow = this.check(exp!(FatArrow));
let is_almost_fat_arrow = TokenKind::FatArrow
.similar_tokens()
.is_some_and(|similar_tokens| similar_tokens.contains(&this.token.kind));
let is_almost_fat_arrow =
TokenKind::FatArrow.similar_tokens().contains(&this.token.kind);

// this avoids the compiler saying that a `,` or `}` was expected even though
// the pattern isn't a never pattern (and thus an arm body is required)
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_parse/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -924,10 +924,8 @@ impl<'a> Parser<'a> {

_ => {
// Attempt to keep parsing if it was a similar separator.
if let Some(tokens) = exp.tok.similar_tokens() {
if tokens.contains(&self.token.kind) {
self.bump();
}
if exp.tok.similar_tokens().contains(&self.token.kind) {
self.bump();
}
}
}
Expand Down
15 changes: 5 additions & 10 deletions compiler/rustc_parse_format/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,12 +363,7 @@ impl<'a> Parser<'a> {
/// Notifies of an error. The message doesn't actually need to be of type
/// String, but I think it does when this eventually uses conditions so it
/// might as well start using it now.
fn err<S1: Into<String>, S2: Into<String>>(
&mut self,
description: S1,
label: S2,
span: InnerSpan,
) {
fn err(&mut self, description: impl Into<String>, label: impl Into<String>, span: InnerSpan) {
self.errors.push(ParseError {
description: description.into(),
note: None,
Expand All @@ -382,11 +377,11 @@ impl<'a> Parser<'a> {
/// Notifies of an error. The message doesn't actually need to be of type
/// String, but I think it does when this eventually uses conditions so it
/// might as well start using it now.
fn err_with_note<S1: Into<String>, S2: Into<String>, S3: Into<String>>(
fn err_with_note(
&mut self,
description: S1,
label: S2,
note: S3,
description: impl Into<String>,
label: impl Into<String>,
note: impl Into<String>,
span: InnerSpan,
) {
self.errors.push(ParseError {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1803,6 +1803,7 @@ options! {
"output statistics about monomorphization collection"),
dump_mono_stats_format: DumpMonoStatsFormat = (DumpMonoStatsFormat::Markdown, parse_dump_mono_stats, [UNTRACKED],
"the format to use for -Z dump-mono-stats (`markdown` (default) or `json`)"),
#[rustc_lint_opt_deny_field_access("use `Session::dwarf_version` instead of this field")]
dwarf_version: Option<u32> = (None, parse_opt_number, [TRACKED],
"version of DWARF debug information to emit (default: 2 or 4, depending on platform)"),
dylib_lto: bool = (false, parse_bool, [UNTRACKED],
Expand Down
8 changes: 6 additions & 2 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,11 @@ impl Session {
self.opts.cg.split_debuginfo.unwrap_or(self.target.split_debuginfo)
}

/// Returns the DWARF version passed on the CLI or the default for the target.
pub fn dwarf_version(&self) -> u32 {
self.opts.unstable_opts.dwarf_version.unwrap_or(self.target.default_dwarf_version)
}

pub fn stack_protector(&self) -> StackProtector {
if self.target.options.supports_stack_protector {
self.opts.unstable_opts.stack_protector
Expand Down Expand Up @@ -1263,8 +1268,7 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
}

if sess.opts.unstable_opts.embed_source {
let dwarf_version =
sess.opts.unstable_opts.dwarf_version.unwrap_or(sess.target.default_dwarf_version);
let dwarf_version = sess.dwarf_version();

if dwarf_version < 5 {
sess.dcx().emit_warn(errors::EmbedSourceInsufficientDwarfVersion { dwarf_version });
Expand Down
6 changes: 5 additions & 1 deletion license-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,12 @@
{
"directories": [],
"files": [
"FiraMono-Medium.woff2",
"FiraMono-Regular.woff2",
"FiraSans-Italic.woff2",
"FiraSans-LICENSE.txt",
"FiraSans-Medium.woff2",
"FiraSans-MediumItalic.woff2",
"FiraSans-Regular.woff2"
],
"license": {
Expand Down Expand Up @@ -266,4 +270,4 @@
],
"type": "root"
}
}
}
4 changes: 4 additions & 0 deletions src/doc/unstable-book/src/compiler-flags/dwarf-version.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## `dwarf-version`

The tracking issue for this feature is: <https://github.com/rust-lang/rust/issues/103057>

----------------------------

This option controls the version of DWARF that the compiler emits, on platforms
that use DWARF to encode debug information. It takes one of the following
values:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# `ref_pat_eat_one_layer_2024_structural`

The tracking issue for this feature is: [#123076]

[#123076]: https://github.com/rust-lang/rust/issues/123076

---

This feature is incomplete and not yet intended for general use.

This implements experimental, Edition-dependent match ergonomics under consideration for inclusion
in Rust.
For more information, see the corresponding typing rules for [Editions 2024 and later].
On earlier Editions, the current behavior is unspecified.

For alternative experimental match ergonomics, see the feature
[`ref_pat_eat_one_layer_2024`](./ref-pat-eat-one-layer-2024.md).

[Editions 2024 and later]: https://nadrieril.github.io/typing-rust-patterns/?compare=false&opts1=AQEBAgEBAQEBAgIAAAAAAAAAAAAAAAA%3D&mode=rules&do_cmp=false
Loading
Loading