Skip to content

Rollup of 9 pull requests #143721

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

Merged
merged 28 commits into from
Jul 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6d1e93d
Add support for $crate to Ident
Apr 14, 2025
9624046
deny AMBIGUOUS_GLOB_IMPORTS; tests fail in this commit
LorrensP-2158466 Jun 24, 2025
3be0b6b
update ui/import tests
LorrensP-2158466 Jun 24, 2025
9a7db56
moved tests
Kivooeo Jun 30, 2025
fd3161c
Mention as_chunks in the docs for chunks
scottmcm Jul 1, 2025
7ca9f93
tests/codegen/enum/enum-match.rs: accept negative range attribute
TimNN Jul 1, 2025
7c2cc2c
cleaned up some tests
Kivooeo Jun 30, 2025
fab9c64
Add triagebot stdarch mention ping
Kobzol Jul 8, 2025
66bc234
tidy: refactor --extra-checks parsing
lolbinarycat Jul 3, 2025
9eb1805
tidy: factor out change detection logic and make it more robust
lolbinarycat Jul 3, 2025
4a6f697
tidy: update files_modified to take CiInfo
lolbinarycat Jul 3, 2025
64456e0
tidy: add `auto:` prefix to --extra-checks syntax
lolbinarycat Jul 3, 2025
6b349a4
tidy: warn when --extra-checks is passed an invalid lang:kind combo
lolbinarycat Jul 3, 2025
9aafc98
tidy: assume all files are modified in CI
lolbinarycat Jul 8, 2025
1f80fd0
bootstrap: add change tracker entry for new --extra-checks=auto: feature
lolbinarycat Jul 8, 2025
b286bc3
fix aux-build failures
LorrensP-2158466 Jul 9, 2025
e7ef31d
mbe: Refactor diagnostics for invalid metavar expression syntax
tgross35 Jun 21, 2025
87e9819
mbe: Refactor the diagnostic for unrecognized metavariable expressions
tgross35 Jun 21, 2025
bc2001f
Refactor nan tests
rocurley Jul 3, 2025
73d3adc
Rollup merge of #141996 - Daniel-Aaron-Bloom:dollar_crate, r=petroche…
tgross35 Jul 10, 2025
643efda
Rollup merge of #142950 - tgross35:metavariable-expr-rework, r=petroc…
tgross35 Jul 10, 2025
6bcc39c
Rollup merge of #143011 - LorrensP-2158466:warn-ambiguity-into-error,…
tgross35 Jul 10, 2025
ebd3940
Rollup merge of #143265 - scottmcm:mention-as-chunks, r=ibraheemdev
tgross35 Jul 10, 2025
a2fe1bc
Rollup merge of #143270 - TimNN:fix-enum-match, r=nikic
tgross35 Jul 10, 2025
7ad9096
Rollup merge of #143298 - Kivooeo:tf23, r=tgross35
tgross35 Jul 10, 2025
9af7bda
Rollup merge of #143396 - rocurley:float_tests_refactor, r=tgross35
tgross35 Jul 10, 2025
58ec9db
Rollup merge of #143398 - lolbinarycat:tidy-extra-checks-auto, r=Kobzol
tgross35 Jul 10, 2025
d50eb9f
Rollup merge of #143644 - Kobzol:stdarch-mention, r=Amanieu
tgross35 Jul 10, 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
26 changes: 26 additions & 0 deletions compiler/rustc_expand/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,32 @@ expand_module_multiple_candidates =
expand_must_repeat_once =
this must repeat at least once

expand_mve_extra_tokens =
unexpected trailing tokens
.label = for this metavariable expression
.range = the `{$name}` metavariable expression takes between {$min_or_exact_args} and {$max_args} arguments
.exact = the `{$name}` metavariable expression takes {$min_or_exact_args ->
[zero] no arguments
[one] a single argument
*[other] {$min_or_exact_args} arguments
}
.suggestion = try removing {$extra_count ->
[one] this token
*[other] these tokens
}

expand_mve_missing_paren =
expected `(`
.label = for this this metavariable expression
.unexpected = unexpected token
.note = metavariable expressions use function-like parentheses syntax
.suggestion = try adding parentheses

expand_mve_unrecognized_expr =
unrecognized metavariable expression
.label = not a valid metavariable expression
.note = valid metavariable expressions are {$valid_expr_list}

expand_mve_unrecognized_var =
variable `{$key}` is not recognized in meta-variable expression

Expand Down
44 changes: 44 additions & 0 deletions compiler/rustc_expand/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,50 @@ pub(crate) use metavar_exprs::*;
mod metavar_exprs {
use super::*;

#[derive(Diagnostic, Default)]
#[diag(expand_mve_extra_tokens)]
pub(crate) struct MveExtraTokens {
#[primary_span]
#[suggestion(code = "", applicability = "machine-applicable")]
pub span: Span,
#[label]
pub ident_span: Span,
pub extra_count: usize,

// The rest is only used for specific diagnostics and can be default if neither
// `note` is `Some`.
#[note(expand_exact)]
pub exact_args_note: Option<()>,
#[note(expand_range)]
pub range_args_note: Option<()>,
pub min_or_exact_args: usize,
pub max_args: usize,
pub name: String,
}

#[derive(Diagnostic)]
#[note]
#[diag(expand_mve_missing_paren)]
pub(crate) struct MveMissingParen {
#[primary_span]
#[label]
pub ident_span: Span,
#[label(expand_unexpected)]
pub unexpected_span: Option<Span>,
#[suggestion(code = "( /* ... */ )", applicability = "has-placeholders")]
pub insert_span: Option<Span>,
}

#[derive(Diagnostic)]
#[note]
#[diag(expand_mve_unrecognized_expr)]
pub(crate) struct MveUnrecognizedExpr {
#[primary_span]
#[label]
pub span: Span,
pub valid_expr_list: &'static str,
}

#[derive(Diagnostic)]
#[diag(expand_mve_unrecognized_var)]
pub(crate) struct MveUnrecognizedVar {
Expand Down
98 changes: 74 additions & 24 deletions compiler/rustc_expand/src/mbe/metavar_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use rustc_macros::{Decodable, Encodable};
use rustc_session::parse::ParseSess;
use rustc_span::{Ident, Span, Symbol};

use crate::errors;

pub(crate) const RAW_IDENT_ERR: &str = "`${concat(..)}` currently does not support raw identifiers";
pub(crate) const UNSUPPORTED_CONCAT_ELEM_ERR: &str = "expected identifier or string literal";

Expand Down Expand Up @@ -40,11 +42,32 @@ impl MetaVarExpr {
) -> PResult<'psess, MetaVarExpr> {
let mut iter = input.iter();
let ident = parse_ident(&mut iter, psess, outer_span)?;
let Some(TokenTree::Delimited(.., Delimiter::Parenthesis, args)) = iter.next() else {
let msg = "meta-variable expression parameter must be wrapped in parentheses";
return Err(psess.dcx().struct_span_err(ident.span, msg));
let next = iter.next();
let Some(TokenTree::Delimited(.., Delimiter::Parenthesis, args)) = next else {
// No `()`; wrong or no delimiters. Point at a problematic span or a place to
// add parens if it makes sense.
let (unexpected_span, insert_span) = match next {
Some(TokenTree::Delimited(..)) => (None, None),
Some(tt) => (Some(tt.span()), None),
None => (None, Some(ident.span.shrink_to_hi())),
};
let err =
errors::MveMissingParen { ident_span: ident.span, unexpected_span, insert_span };
return Err(psess.dcx().create_err(err));
};
check_trailing_token(&mut iter, psess)?;

// Ensure there are no trailing tokens in the braces, e.g. `${foo() extra}`
if iter.peek().is_some() {
let span = iter_span(&iter).expect("checked is_some above");
let err = errors::MveExtraTokens {
span,
ident_span: ident.span,
extra_count: iter.count(),
..Default::default()
};
return Err(psess.dcx().create_err(err));
}

let mut iter = args.iter();
let rslt = match ident.as_str() {
"concat" => parse_concat(&mut iter, psess, outer_span, ident.span)?,
Expand All @@ -56,18 +79,14 @@ impl MetaVarExpr {
"index" => MetaVarExpr::Index(parse_depth(&mut iter, psess, ident.span)?),
"len" => MetaVarExpr::Len(parse_depth(&mut iter, psess, ident.span)?),
_ => {
let err_msg = "unrecognized meta-variable expression";
let mut err = psess.dcx().struct_span_err(ident.span, err_msg);
err.span_suggestion(
ident.span,
"supported expressions are count, ignore, index and len",
"",
Applicability::MachineApplicable,
);
return Err(err);
let err = errors::MveUnrecognizedExpr {
span: ident.span,
valid_expr_list: "`count`, `ignore`, `index`, `len`, and `concat`",
};
return Err(psess.dcx().create_err(err));
}
};
check_trailing_token(&mut iter, psess)?;
check_trailing_tokens(&mut iter, psess, ident)?;
Ok(rslt)
}

Expand All @@ -87,20 +106,51 @@ impl MetaVarExpr {
}
}

// Checks if there are any remaining tokens. For example, `${ignore(ident ... a b c ...)}`
fn check_trailing_token<'psess>(
/// Checks if there are any remaining tokens (for example, `${ignore($valid, extra)}`) and create
/// a diag with the correct arg count if so.
fn check_trailing_tokens<'psess>(
iter: &mut TokenStreamIter<'_>,
psess: &'psess ParseSess,
ident: Ident,
) -> PResult<'psess, ()> {
if let Some(tt) = iter.next() {
let mut diag = psess
.dcx()
.struct_span_err(tt.span(), format!("unexpected token: {}", pprust::tt_to_string(tt)));
diag.span_note(tt.span(), "meta-variable expression must not have trailing tokens");
Err(diag)
} else {
Ok(())
if iter.peek().is_none() {
// All tokens consumed, as expected
return Ok(());
}

// `None` for max indicates the arg count must be exact, `Some` indicates a range is accepted.
let (min_or_exact_args, max_args) = match ident.as_str() {
"concat" => panic!("concat takes unlimited tokens but didn't eat them all"),
"ignore" => (1, None),
// 1 or 2 args
"count" => (1, Some(2)),
// 0 or 1 arg
"index" => (0, Some(1)),
"len" => (0, Some(1)),
other => unreachable!("unknown MVEs should be rejected earlier (got `{other}`)"),
};

let err = errors::MveExtraTokens {
span: iter_span(iter).expect("checked is_none above"),
ident_span: ident.span,
extra_count: iter.count(),

exact_args_note: if max_args.is_some() { None } else { Some(()) },
range_args_note: if max_args.is_some() { Some(()) } else { None },
min_or_exact_args,
max_args: max_args.unwrap_or_default(),
name: ident.to_string(),
};
Err(psess.dcx().create_err(err))
}

/// Returns a span encompassing all tokens in the iterator if there is at least one item.
fn iter_span(iter: &TokenStreamIter<'_>) -> Option<Span> {
let mut iter = iter.clone(); // cloning is cheap
let first_sp = iter.next()?.span();
let last_sp = iter.last().map(TokenTree::span).unwrap_or(first_sp);
let span = first_sp.with_hi(last_sp.hi());
Some(span)
}

/// Indicates what is placed in a `concat` parameter. For example, literals
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4343,11 +4343,12 @@ declare_lint! {
///
/// [future-incompatible]: ../index.md#future-incompatible-lints
pub AMBIGUOUS_GLOB_IMPORTS,
Warn,
Deny,
"detects certain glob imports that require reporting an ambiguity error",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::FutureReleaseError,
reference: "issue #114095 <https://github.com/rust-lang/rust/issues/114095>",
report_in_deps: true,
};
}

Expand Down
32 changes: 32 additions & 0 deletions library/core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,9 @@ impl<T> [T] {
/// `chunk_size` elements, and [`rchunks`] for the same iterator but starting at the end of the
/// slice.
///
/// If your `chunk_size` is a constant, consider using [`as_chunks`] instead, which will
/// give references to arrays of exactly that length, rather than slices.
///
/// # Panics
///
/// Panics if `chunk_size` is zero.
Expand All @@ -1137,6 +1140,7 @@ impl<T> [T] {
///
/// [`chunks_exact`]: slice::chunks_exact
/// [`rchunks`]: slice::rchunks
/// [`as_chunks`]: slice::as_chunks
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_slice_make_iter", issue = "137737")]
#[inline]
Expand All @@ -1156,6 +1160,9 @@ impl<T> [T] {
/// exactly `chunk_size` elements, and [`rchunks_mut`] for the same iterator but starting at
/// the end of the slice.
///
/// If your `chunk_size` is a constant, consider using [`as_chunks_mut`] instead, which will
/// give references to arrays of exactly that length, rather than slices.
///
/// # Panics
///
/// Panics if `chunk_size` is zero.
Expand All @@ -1177,6 +1184,7 @@ impl<T> [T] {
///
/// [`chunks_exact_mut`]: slice::chunks_exact_mut
/// [`rchunks_mut`]: slice::rchunks_mut
/// [`as_chunks_mut`]: slice::as_chunks_mut
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_slice_make_iter", issue = "137737")]
#[inline]
Expand All @@ -1199,6 +1207,9 @@ impl<T> [T] {
/// See [`chunks`] for a variant of this iterator that also returns the remainder as a smaller
/// chunk, and [`rchunks_exact`] for the same iterator but starting at the end of the slice.
///
/// If your `chunk_size` is a constant, consider using [`as_chunks`] instead, which will
/// give references to arrays of exactly that length, rather than slices.
///
/// # Panics
///
/// Panics if `chunk_size` is zero.
Expand All @@ -1216,6 +1227,7 @@ impl<T> [T] {
///
/// [`chunks`]: slice::chunks
/// [`rchunks_exact`]: slice::rchunks_exact
/// [`as_chunks`]: slice::chunks
#[stable(feature = "chunks_exact", since = "1.31.0")]
#[rustc_const_unstable(feature = "const_slice_make_iter", issue = "137737")]
#[inline]
Expand All @@ -1239,6 +1251,9 @@ impl<T> [T] {
/// smaller chunk, and [`rchunks_exact_mut`] for the same iterator but starting at the end of
/// the slice.
///
/// If your `chunk_size` is a constant, consider using [`as_chunks_mut`] instead, which will
/// give references to arrays of exactly that length, rather than slices.
///
/// # Panics
///
/// Panics if `chunk_size` is zero.
Expand All @@ -1260,6 +1275,7 @@ impl<T> [T] {
///
/// [`chunks_mut`]: slice::chunks_mut
/// [`rchunks_exact_mut`]: slice::rchunks_exact_mut
/// [`as_chunks_mut`]: slice::as_chunks_mut
#[stable(feature = "chunks_exact", since = "1.31.0")]
#[rustc_const_unstable(feature = "const_slice_make_iter", issue = "137737")]
#[inline]
Expand Down Expand Up @@ -1707,6 +1723,9 @@ impl<T> [T] {
/// `chunk_size` elements, and [`chunks`] for the same iterator but starting at the beginning
/// of the slice.
///
/// If your `chunk_size` is a constant, consider using [`as_rchunks`] instead, which will
/// give references to arrays of exactly that length, rather than slices.
///
/// # Panics
///
/// Panics if `chunk_size` is zero.
Expand All @@ -1724,6 +1743,7 @@ impl<T> [T] {
///
/// [`rchunks_exact`]: slice::rchunks_exact
/// [`chunks`]: slice::chunks
/// [`as_rchunks`]: slice::as_rchunks
#[stable(feature = "rchunks", since = "1.31.0")]
#[rustc_const_unstable(feature = "const_slice_make_iter", issue = "137737")]
#[inline]
Expand All @@ -1743,6 +1763,9 @@ impl<T> [T] {
/// exactly `chunk_size` elements, and [`chunks_mut`] for the same iterator but starting at the
/// beginning of the slice.
///
/// If your `chunk_size` is a constant, consider using [`as_rchunks_mut`] instead, which will
/// give references to arrays of exactly that length, rather than slices.
///
/// # Panics
///
/// Panics if `chunk_size` is zero.
Expand All @@ -1764,6 +1787,7 @@ impl<T> [T] {
///
/// [`rchunks_exact_mut`]: slice::rchunks_exact_mut
/// [`chunks_mut`]: slice::chunks_mut
/// [`as_rchunks_mut`]: slice::as_rchunks_mut
#[stable(feature = "rchunks", since = "1.31.0")]
#[rustc_const_unstable(feature = "const_slice_make_iter", issue = "137737")]
#[inline]
Expand All @@ -1787,6 +1811,9 @@ impl<T> [T] {
/// chunk, and [`chunks_exact`] for the same iterator but starting at the beginning of the
/// slice.
///
/// If your `chunk_size` is a constant, consider using [`as_rchunks`] instead, which will
/// give references to arrays of exactly that length, rather than slices.
///
/// # Panics
///
/// Panics if `chunk_size` is zero.
Expand All @@ -1805,6 +1832,7 @@ impl<T> [T] {
/// [`chunks`]: slice::chunks
/// [`rchunks`]: slice::rchunks
/// [`chunks_exact`]: slice::chunks_exact
/// [`as_rchunks`]: slice::as_rchunks
#[stable(feature = "rchunks", since = "1.31.0")]
#[rustc_const_unstable(feature = "const_slice_make_iter", issue = "137737")]
#[inline]
Expand All @@ -1828,6 +1856,9 @@ impl<T> [T] {
/// smaller chunk, and [`chunks_exact_mut`] for the same iterator but starting at the beginning
/// of the slice.
///
/// If your `chunk_size` is a constant, consider using [`as_rchunks_mut`] instead, which will
/// give references to arrays of exactly that length, rather than slices.
///
/// # Panics
///
/// Panics if `chunk_size` is zero.
Expand All @@ -1850,6 +1881,7 @@ impl<T> [T] {
/// [`chunks_mut`]: slice::chunks_mut
/// [`rchunks_mut`]: slice::rchunks_mut
/// [`chunks_exact_mut`]: slice::chunks_exact_mut
/// [`as_rchunks_mut`]: slice::as_rchunks_mut
#[stable(feature = "rchunks", since = "1.31.0")]
#[rustc_const_unstable(feature = "const_slice_make_iter", issue = "137737")]
#[inline]
Expand Down
14 changes: 0 additions & 14 deletions library/coretests/tests/floats/f128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,6 @@ fn test_num_f128() {
// FIXME(f16_f128,miri): many of these have to be disabled since miri does not yet support
// the intrinsics.

#[test]
fn test_nan() {
let nan: f128 = f128::NAN;
assert!(nan.is_nan());
assert!(!nan.is_infinite());
assert!(!nan.is_finite());
assert!(nan.is_sign_positive());
assert!(!nan.is_sign_negative());
assert!(!nan.is_normal());
assert_eq!(Fp::Nan, nan.classify());
// Ensure the quiet bit is set.
assert!(nan.to_bits() & (1 << (f128::MANTISSA_DIGITS - 2)) != 0);
}

#[test]
fn test_infinity() {
let inf: f128 = f128::INFINITY;
Expand Down
Loading