Skip to content

Rollup of 12 pull requests #144355

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

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a2d03e7
coretests/num: use ldexp instead of hard-coding a power of 2
RalfJung Jul 21, 2025
bcaa795
removed tidy check on issues files
Kivooeo Jul 19, 2025
58537fb
Fix broken TLS destructors on 32-bit win7
roblabla Jul 20, 2025
b2f8b40
Don't ICE on non-TypeId metadata within TypeId
oli-obk Jul 21, 2025
6df15a1
update SUMMARY.md
makai410 Jul 16, 2025
551cb9f
mbe: Use concrete type for `get_unused_rule`
joshtriplett Jul 22, 2025
f877aa7
coverage: Enlarge empty spans during MIR instrumentation, not codegen
Zalathar May 4, 2025
2832517
Clean code for `rustc_parse/src/lexer`
xizheyin Jul 21, 2025
0aa6170
Add a test case for ui test false-sealed-traits-note.rs
yuk1ty Jul 21, 2025
f5a33e8
Add powerpc64le-unknown-linux-musl to CI rustc targets
Gelbpunkt Jul 22, 2025
25bbaf0
bootstrap: add package.json and package-lock.json to dist tarball
lolbinarycat Jul 22, 2025
9e75032
rustdoc: avoid allocating a temp String for aliases in search index
lolbinarycat Jul 22, 2025
1f14065
Rollup merge of #144173 - Kivooeo:tidy_checks, r=jieyouxu
GuillaumeGomez Jul 23, 2025
5636795
Rollup merge of #144234 - roblabla:fix-win7-tls-dtors, r=ChrisDenton
GuillaumeGomez Jul 23, 2025
a3e9041
Rollup merge of #144239 - xizheyin:clean-lexer, r=fee1-dead
GuillaumeGomez Jul 23, 2025
bfd744c
Rollup merge of #144240 - yuk1ty:false-sealed-traits-note-reported-in…
GuillaumeGomez Jul 23, 2025
609f531
Rollup merge of #144247 - RalfJung:ldexp, r=tgross35
GuillaumeGomez Jul 23, 2025
43857e3
Rollup merge of #144256 - oli-obk:type-id-ice, r=RalfJung
GuillaumeGomez Jul 23, 2025
d53e34b
Rollup merge of #144290 - makai410:summary-ups, r=jieyouxu
GuillaumeGomez Jul 23, 2025
0f54963
Rollup merge of #144292 - joshtriplett:mbe-use-concrete-type-for-get-…
GuillaumeGomez Jul 23, 2025
66624a5
Rollup merge of #144298 - Zalathar:empty-span, r=wesleywiser
GuillaumeGomez Jul 23, 2025
dc6267c
Rollup merge of #144311 - Gelbpunkt:ci-rustc-ppc64le-musl, r=Kobzol
GuillaumeGomez Jul 23, 2025
1e05e13
Rollup merge of #144315 - lolbinarycat:bootstrap-dist-package.json, r…
GuillaumeGomez Jul 23, 2025
9d4b42a
Rollup merge of #144320 - lolbinarycat:rustdoc-search_index-BTreeMap-…
GuillaumeGomez Jul 23, 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
28 changes: 4 additions & 24 deletions compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ impl Coords {
/// or other expansions), and if it does happen then skipping a span or function is
/// better than an ICE or `llvm-cov` failure that the user might have no way to avoid.
pub(crate) fn make_coords(source_map: &SourceMap, file: &SourceFile, span: Span) -> Option<Coords> {
let span = ensure_non_empty_span(source_map, span)?;
if span.is_empty() {
debug_assert!(false, "can't make coords from empty span: {span:?}");
return None;
}

let lo = span.lo();
let hi = span.hi();
Expand Down Expand Up @@ -70,29 +73,6 @@ pub(crate) fn make_coords(source_map: &SourceMap, file: &SourceFile, span: Span)
})
}

fn ensure_non_empty_span(source_map: &SourceMap, span: Span) -> Option<Span> {
if !span.is_empty() {
return Some(span);
}

// The span is empty, so try to enlarge it to cover an adjacent '{' or '}'.
source_map
.span_to_source(span, |src, start, end| try {
// Adjusting span endpoints by `BytePos(1)` is normally a bug,
// but in this case we have specifically checked that the character
// we're skipping over is one of two specific ASCII characters, so
// adjusting by exactly 1 byte is correct.
if src.as_bytes().get(end).copied() == Some(b'{') {
Some(span.with_hi(span.hi() + BytePos(1)))
} else if start > 0 && src.as_bytes()[start - 1] == b'}' {
Some(span.with_lo(span.lo() - BytePos(1)))
} else {
None
}
})
.ok()?
}

/// If `llvm-cov` sees a source region that is improperly ordered (end < start),
/// it will immediately exit with a fatal error. To prevent that from happening,
/// discard regions that are improperly ordered, or might be interpreted in a
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/interpret/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
ptr: Pointer<Option<M::Provenance>>,
) -> InterpResult<'tcx, (Ty<'tcx>, u64)> {
let (alloc_id, offset, _meta) = self.ptr_get_alloc_id(ptr, 0)?;
let GlobalAlloc::TypeId { ty } = self.tcx.global_alloc(alloc_id) else {
let Some(GlobalAlloc::TypeId { ty }) = self.tcx.try_get_global_alloc(alloc_id) else {
throw_ub_format!("invalid `TypeId` value: not all bytes carry type id metadata")
};
interp_ok((ty, offset.bytes()))
Expand Down
9 changes: 3 additions & 6 deletions compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::any::Any;
use std::default::Default;
use std::iter;
use std::path::Component::Prefix;
Expand Down Expand Up @@ -361,25 +362,21 @@ where
}

/// Represents a thing that maps token trees to Macro Results
pub trait TTMacroExpander {
pub trait TTMacroExpander: Any {
fn expand<'cx>(
&self,
ecx: &'cx mut ExtCtxt<'_>,
span: Span,
input: TokenStream,
) -> MacroExpanderResult<'cx>;

fn get_unused_rule(&self, _rule_i: usize) -> Option<(&Ident, Span)> {
None
}
}

pub type MacroExpanderResult<'cx> = ExpandResult<Box<dyn MacResult + 'cx>, ()>;

pub type MacroExpanderFn =
for<'cx> fn(&'cx mut ExtCtxt<'_>, Span, TokenStream) -> MacroExpanderResult<'cx>;

impl<F> TTMacroExpander for F
impl<F: 'static> TTMacroExpander for F
where
F: for<'cx> Fn(&'cx mut ExtCtxt<'_>, Span, TokenStream) -> MacroExpanderResult<'cx>,
{
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ mod placeholders;
mod proc_macro_server;
mod stats;

pub use mbe::macro_rules::compile_declarative_macro;
pub use mbe::macro_rules::{MacroRulesMacroExpander, compile_declarative_macro};
pub mod base;
pub mod config;
pub mod expand;
Expand Down
16 changes: 9 additions & 7 deletions compiler/rustc_expand/src/mbe/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,22 @@ pub(super) struct MacroRule {
rhs: mbe::TokenTree,
}

struct MacroRulesMacroExpander {
pub struct MacroRulesMacroExpander {
node_id: NodeId,
name: Ident,
span: Span,
transparency: Transparency,
rules: Vec<MacroRule>,
}

impl MacroRulesMacroExpander {
pub fn get_unused_rule(&self, rule_i: usize) -> Option<(&Ident, Span)> {
// If the rhs contains an invocation like `compile_error!`, don't report it as unused.
let rule = &self.rules[rule_i];
if has_compile_error_macro(&rule.rhs) { None } else { Some((&self.name, rule.lhs_span)) }
}
}

impl TTMacroExpander for MacroRulesMacroExpander {
fn expand<'cx>(
&self,
Expand All @@ -154,12 +162,6 @@ impl TTMacroExpander for MacroRulesMacroExpander {
&self.rules,
))
}

fn get_unused_rule(&self, rule_i: usize) -> Option<(&Ident, Span)> {
// If the rhs contains an invocation like `compile_error!`, don't report it as unused.
let rule = &self.rules[rule_i];
if has_compile_error_macro(&rule.rhs) { None } else { Some((&self.name, rule.lhs_span)) }
}
}

struct DummyExpander(ErrorGuaranteed);
Expand Down
38 changes: 36 additions & 2 deletions compiler/rustc_mir_transform/src/coverage/spans.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use rustc_data_structures::fx::FxHashSet;
use rustc_middle::mir;
use rustc_middle::ty::TyCtxt;
use rustc_span::{DesugaringKind, ExpnKind, MacroKind, Span};
use rustc_span::source_map::SourceMap;
use rustc_span::{BytePos, DesugaringKind, ExpnKind, MacroKind, Span};
use tracing::instrument;

use crate::coverage::graph::{BasicCoverageBlock, CoverageGraph};
Expand Down Expand Up @@ -83,8 +84,18 @@ pub(super) fn extract_refined_covspans<'tcx>(
// Discard any span that overlaps with a hole.
discard_spans_overlapping_holes(&mut covspans, &holes);

// Perform more refinement steps after holes have been dealt with.
// Discard spans that overlap in unwanted ways.
let mut covspans = remove_unwanted_overlapping_spans(covspans);

// For all empty spans, either enlarge them to be non-empty, or discard them.
let source_map = tcx.sess.source_map();
covspans.retain_mut(|covspan| {
let Some(span) = ensure_non_empty_span(source_map, covspan.span) else { return false };
covspan.span = span;
true
});

// Merge covspans that can be merged.
covspans.dedup_by(|b, a| a.merge_if_eligible(b));

code_mappings.extend(covspans.into_iter().map(|Covspan { span, bcb }| {
Expand Down Expand Up @@ -230,3 +241,26 @@ fn compare_spans(a: Span, b: Span) -> std::cmp::Ordering {
// - Both have the same start and span A extends further right
.then_with(|| Ord::cmp(&a.hi(), &b.hi()).reverse())
}

fn ensure_non_empty_span(source_map: &SourceMap, span: Span) -> Option<Span> {
if !span.is_empty() {
return Some(span);
}

// The span is empty, so try to enlarge it to cover an adjacent '{' or '}'.
source_map
.span_to_source(span, |src, start, end| try {
// Adjusting span endpoints by `BytePos(1)` is normally a bug,
// but in this case we have specifically checked that the character
// we're skipping over is one of two specific ASCII characters, so
// adjusting by exactly 1 byte is correct.
if src.as_bytes().get(end).copied() == Some(b'{') {
Some(span.with_hi(span.hi() + BytePos(1)))
} else if start > 0 && src.as_bytes()[start - 1] == b'}' {
Some(span.with_lo(span.lo() - BytePos(1)))
} else {
None
}
})
.ok()?
}
44 changes: 25 additions & 19 deletions compiler/rustc_parse/src/lexer/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,23 +126,29 @@ pub(super) fn report_suspicious_mismatch_block(
}
}

pub(crate) fn make_unclosed_delims_error(
unmatched: UnmatchedDelim,
psess: &ParseSess,
) -> Option<Diag<'_>> {
// `None` here means an `Eof` was found. We already emit those errors elsewhere, we add them to
// `unmatched_delims` only for error recovery in the `Parser`.
let found_delim = unmatched.found_delim?;
let mut spans = vec![unmatched.found_span];
if let Some(sp) = unmatched.unclosed_span {
spans.push(sp);
};
let err = psess.dcx().create_err(MismatchedClosingDelimiter {
spans,
delimiter: pprust::token_kind_to_string(&found_delim.as_close_token_kind()).to_string(),
unmatched: unmatched.found_span,
opening_candidate: unmatched.candidate_span,
unclosed: unmatched.unclosed_span,
});
Some(err)
pub(crate) fn make_errors_for_mismatched_closing_delims<'psess>(
unmatcheds: &[UnmatchedDelim],
psess: &'psess ParseSess,
) -> Vec<Diag<'psess>> {
unmatcheds
.iter()
.filter_map(|unmatched| {
// `None` here means an `Eof` was found. We already emit those errors elsewhere, we add them to
// `unmatched_delims` only for error recovery in the `Parser`.
let found_delim = unmatched.found_delim?;
let mut spans = vec![unmatched.found_span];
if let Some(sp) = unmatched.unclosed_span {
spans.push(sp);
};
let err = psess.dcx().create_err(MismatchedClosingDelimiter {
spans,
delimiter: pprust::token_kind_to_string(&found_delim.as_close_token_kind())
.to_string(),
unmatched: unmatched.found_span,
opening_candidate: unmatched.candidate_span,
unclosed: unmatched.unclosed_span,
});
Some(err)
})
.collect()
}
18 changes: 7 additions & 11 deletions compiler/rustc_parse/src/lexer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use diagnostics::make_unclosed_delims_error;
use diagnostics::make_errors_for_mismatched_closing_delims;
use rustc_ast::ast::{self, AttrStyle};
use rustc_ast::token::{self, CommentKind, Delimiter, IdentIsRaw, Token, TokenKind};
use rustc_ast::tokenstream::TokenStream;
Expand Down Expand Up @@ -71,27 +71,23 @@ pub(crate) fn lex_token_trees<'psess, 'src>(
};
let res = lexer.lex_token_trees(/* is_delimited */ false);

let mut unmatched_delims: Vec<_> = lexer
.diag_info
.unmatched_delims
.into_iter()
.filter_map(|unmatched_delim| make_unclosed_delims_error(unmatched_delim, psess))
.collect();
let mut unmatched_closing_delims: Vec<_> =
make_errors_for_mismatched_closing_delims(&lexer.diag_info.unmatched_delims, psess);

match res {
Ok((_open_spacing, stream)) => {
if unmatched_delims.is_empty() {
if unmatched_closing_delims.is_empty() {
Ok(stream)
} else {
// Return error if there are unmatched delimiters or unclosed delimiters.
Err(unmatched_delims)
Err(unmatched_closing_delims)
}
}
Err(errs) => {
// We emit delimiter mismatch errors first, then emit the unclosing delimiter mismatch
// because the delimiter mismatch is more likely to be the root cause of error
unmatched_delims.extend(errs);
Err(unmatched_delims)
unmatched_closing_delims.extend(errs);
Err(unmatched_closing_delims)
}
}
}
Expand Down
Loading
Loading