Skip to content

Commit 119574f

Browse files
committed
Auto merge of #143721 - tgross35:rollup-sjdfp6r, r=tgross35
Rollup of 9 pull requests Successful merges: - #141996 (Fix `proc_macro::Ident`'s handling of `$crate`) - #142950 (mbe: Rework diagnostics for metavariable expressions) - #143011 (Make lint `ambiguous_glob_imports` deny-by-default and report-in-deps) - #143265 (Mention as_chunks in the docs for chunks) - #143270 (tests/codegen/enum/enum-match.rs: accept negative range attribute) - #143298 (`tests/ui`: A New Order [23/N]) - #143396 (Move NaN tests to floats/mod.rs) - #143398 (tidy: add support for `--extra-checks=auto:` feature) - #143644 (Add triagebot stdarch mention ping) r? `@ghost` `@rustbot` modify labels: rollup
2 parents cf3fb76 + d50eb9f commit 119574f

File tree

80 files changed

+2095
-525
lines changed

Some content is hidden

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

80 files changed

+2095
-525
lines changed

compiler/rustc_expand/messages.ftl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,32 @@ expand_module_multiple_candidates =
133133
expand_must_repeat_once =
134134
this must repeat at least once
135135
136+
expand_mve_extra_tokens =
137+
unexpected trailing tokens
138+
.label = for this metavariable expression
139+
.range = the `{$name}` metavariable expression takes between {$min_or_exact_args} and {$max_args} arguments
140+
.exact = the `{$name}` metavariable expression takes {$min_or_exact_args ->
141+
[zero] no arguments
142+
[one] a single argument
143+
*[other] {$min_or_exact_args} arguments
144+
}
145+
.suggestion = try removing {$extra_count ->
146+
[one] this token
147+
*[other] these tokens
148+
}
149+
150+
expand_mve_missing_paren =
151+
expected `(`
152+
.label = for this this metavariable expression
153+
.unexpected = unexpected token
154+
.note = metavariable expressions use function-like parentheses syntax
155+
.suggestion = try adding parentheses
156+
157+
expand_mve_unrecognized_expr =
158+
unrecognized metavariable expression
159+
.label = not a valid metavariable expression
160+
.note = valid metavariable expressions are {$valid_expr_list}
161+
136162
expand_mve_unrecognized_var =
137163
variable `{$key}` is not recognized in meta-variable expression
138164

compiler/rustc_expand/src/errors.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,50 @@ pub(crate) use metavar_exprs::*;
496496
mod metavar_exprs {
497497
use super::*;
498498

499+
#[derive(Diagnostic, Default)]
500+
#[diag(expand_mve_extra_tokens)]
501+
pub(crate) struct MveExtraTokens {
502+
#[primary_span]
503+
#[suggestion(code = "", applicability = "machine-applicable")]
504+
pub span: Span,
505+
#[label]
506+
pub ident_span: Span,
507+
pub extra_count: usize,
508+
509+
// The rest is only used for specific diagnostics and can be default if neither
510+
// `note` is `Some`.
511+
#[note(expand_exact)]
512+
pub exact_args_note: Option<()>,
513+
#[note(expand_range)]
514+
pub range_args_note: Option<()>,
515+
pub min_or_exact_args: usize,
516+
pub max_args: usize,
517+
pub name: String,
518+
}
519+
520+
#[derive(Diagnostic)]
521+
#[note]
522+
#[diag(expand_mve_missing_paren)]
523+
pub(crate) struct MveMissingParen {
524+
#[primary_span]
525+
#[label]
526+
pub ident_span: Span,
527+
#[label(expand_unexpected)]
528+
pub unexpected_span: Option<Span>,
529+
#[suggestion(code = "( /* ... */ )", applicability = "has-placeholders")]
530+
pub insert_span: Option<Span>,
531+
}
532+
533+
#[derive(Diagnostic)]
534+
#[note]
535+
#[diag(expand_mve_unrecognized_expr)]
536+
pub(crate) struct MveUnrecognizedExpr {
537+
#[primary_span]
538+
#[label]
539+
pub span: Span,
540+
pub valid_expr_list: &'static str,
541+
}
542+
499543
#[derive(Diagnostic)]
500544
#[diag(expand_mve_unrecognized_var)]
501545
pub(crate) struct MveUnrecognizedVar {

compiler/rustc_expand/src/mbe/metavar_expr.rs

Lines changed: 74 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use rustc_macros::{Decodable, Encodable};
77
use rustc_session::parse::ParseSess;
88
use rustc_span::{Ident, Span, Symbol};
99

10+
use crate::errors;
11+
1012
pub(crate) const RAW_IDENT_ERR: &str = "`${concat(..)}` currently does not support raw identifiers";
1113
pub(crate) const UNSUPPORTED_CONCAT_ELEM_ERR: &str = "expected identifier or string literal";
1214

@@ -40,11 +42,32 @@ impl MetaVarExpr {
4042
) -> PResult<'psess, MetaVarExpr> {
4143
let mut iter = input.iter();
4244
let ident = parse_ident(&mut iter, psess, outer_span)?;
43-
let Some(TokenTree::Delimited(.., Delimiter::Parenthesis, args)) = iter.next() else {
44-
let msg = "meta-variable expression parameter must be wrapped in parentheses";
45-
return Err(psess.dcx().struct_span_err(ident.span, msg));
45+
let next = iter.next();
46+
let Some(TokenTree::Delimited(.., Delimiter::Parenthesis, args)) = next else {
47+
// No `()`; wrong or no delimiters. Point at a problematic span or a place to
48+
// add parens if it makes sense.
49+
let (unexpected_span, insert_span) = match next {
50+
Some(TokenTree::Delimited(..)) => (None, None),
51+
Some(tt) => (Some(tt.span()), None),
52+
None => (None, Some(ident.span.shrink_to_hi())),
53+
};
54+
let err =
55+
errors::MveMissingParen { ident_span: ident.span, unexpected_span, insert_span };
56+
return Err(psess.dcx().create_err(err));
4657
};
47-
check_trailing_token(&mut iter, psess)?;
58+
59+
// Ensure there are no trailing tokens in the braces, e.g. `${foo() extra}`
60+
if iter.peek().is_some() {
61+
let span = iter_span(&iter).expect("checked is_some above");
62+
let err = errors::MveExtraTokens {
63+
span,
64+
ident_span: ident.span,
65+
extra_count: iter.count(),
66+
..Default::default()
67+
};
68+
return Err(psess.dcx().create_err(err));
69+
}
70+
4871
let mut iter = args.iter();
4972
let rslt = match ident.as_str() {
5073
"concat" => parse_concat(&mut iter, psess, outer_span, ident.span)?,
@@ -56,18 +79,14 @@ impl MetaVarExpr {
5679
"index" => MetaVarExpr::Index(parse_depth(&mut iter, psess, ident.span)?),
5780
"len" => MetaVarExpr::Len(parse_depth(&mut iter, psess, ident.span)?),
5881
_ => {
59-
let err_msg = "unrecognized meta-variable expression";
60-
let mut err = psess.dcx().struct_span_err(ident.span, err_msg);
61-
err.span_suggestion(
62-
ident.span,
63-
"supported expressions are count, ignore, index and len",
64-
"",
65-
Applicability::MachineApplicable,
66-
);
67-
return Err(err);
82+
let err = errors::MveUnrecognizedExpr {
83+
span: ident.span,
84+
valid_expr_list: "`count`, `ignore`, `index`, `len`, and `concat`",
85+
};
86+
return Err(psess.dcx().create_err(err));
6887
}
6988
};
70-
check_trailing_token(&mut iter, psess)?;
89+
check_trailing_tokens(&mut iter, psess, ident)?;
7190
Ok(rslt)
7291
}
7392

@@ -87,20 +106,51 @@ impl MetaVarExpr {
87106
}
88107
}
89108

90-
// Checks if there are any remaining tokens. For example, `${ignore(ident ... a b c ...)}`
91-
fn check_trailing_token<'psess>(
109+
/// Checks if there are any remaining tokens (for example, `${ignore($valid, extra)}`) and create
110+
/// a diag with the correct arg count if so.
111+
fn check_trailing_tokens<'psess>(
92112
iter: &mut TokenStreamIter<'_>,
93113
psess: &'psess ParseSess,
114+
ident: Ident,
94115
) -> PResult<'psess, ()> {
95-
if let Some(tt) = iter.next() {
96-
let mut diag = psess
97-
.dcx()
98-
.struct_span_err(tt.span(), format!("unexpected token: {}", pprust::tt_to_string(tt)));
99-
diag.span_note(tt.span(), "meta-variable expression must not have trailing tokens");
100-
Err(diag)
101-
} else {
102-
Ok(())
116+
if iter.peek().is_none() {
117+
// All tokens consumed, as expected
118+
return Ok(());
103119
}
120+
121+
// `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),
125+
// 1 or 2 args
126+
"count" => (1, Some(2)),
127+
// 0 or 1 arg
128+
"index" => (0, Some(1)),
129+
"len" => (0, Some(1)),
130+
other => unreachable!("unknown MVEs should be rejected earlier (got `{other}`)"),
131+
};
132+
133+
let err = errors::MveExtraTokens {
134+
span: iter_span(iter).expect("checked is_none above"),
135+
ident_span: ident.span,
136+
extra_count: iter.count(),
137+
138+
exact_args_note: if max_args.is_some() { None } else { Some(()) },
139+
range_args_note: if max_args.is_some() { Some(()) } else { None },
140+
min_or_exact_args,
141+
max_args: max_args.unwrap_or_default(),
142+
name: ident.to_string(),
143+
};
144+
Err(psess.dcx().create_err(err))
145+
}
146+
147+
/// Returns a span encompassing all tokens in the iterator if there is at least one item.
148+
fn iter_span(iter: &TokenStreamIter<'_>) -> Option<Span> {
149+
let mut iter = iter.clone(); // cloning is cheap
150+
let first_sp = iter.next()?.span();
151+
let last_sp = iter.last().map(TokenTree::span).unwrap_or(first_sp);
152+
let span = first_sp.with_hi(last_sp.hi());
153+
Some(span)
104154
}
105155

106156
/// Indicates what is placed in a `concat` parameter. For example, literals

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4343,11 +4343,12 @@ declare_lint! {
43434343
///
43444344
/// [future-incompatible]: ../index.md#future-incompatible-lints
43454345
pub AMBIGUOUS_GLOB_IMPORTS,
4346-
Warn,
4346+
Deny,
43474347
"detects certain glob imports that require reporting an ambiguity error",
43484348
@future_incompatible = FutureIncompatibleInfo {
43494349
reason: FutureIncompatibilityReason::FutureReleaseError,
43504350
reference: "issue #114095 <https://github.com/rust-lang/rust/issues/114095>",
4351+
report_in_deps: true,
43514352
};
43524353
}
43534354

library/core/src/slice/mod.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,9 @@ impl<T> [T] {
11201120
/// `chunk_size` elements, and [`rchunks`] for the same iterator but starting at the end of the
11211121
/// slice.
11221122
///
1123+
/// If your `chunk_size` is a constant, consider using [`as_chunks`] instead, which will
1124+
/// give references to arrays of exactly that length, rather than slices.
1125+
///
11231126
/// # Panics
11241127
///
11251128
/// Panics if `chunk_size` is zero.
@@ -1137,6 +1140,7 @@ impl<T> [T] {
11371140
///
11381141
/// [`chunks_exact`]: slice::chunks_exact
11391142
/// [`rchunks`]: slice::rchunks
1143+
/// [`as_chunks`]: slice::as_chunks
11401144
#[stable(feature = "rust1", since = "1.0.0")]
11411145
#[rustc_const_unstable(feature = "const_slice_make_iter", issue = "137737")]
11421146
#[inline]
@@ -1156,6 +1160,9 @@ impl<T> [T] {
11561160
/// exactly `chunk_size` elements, and [`rchunks_mut`] for the same iterator but starting at
11571161
/// the end of the slice.
11581162
///
1163+
/// If your `chunk_size` is a constant, consider using [`as_chunks_mut`] instead, which will
1164+
/// give references to arrays of exactly that length, rather than slices.
1165+
///
11591166
/// # Panics
11601167
///
11611168
/// Panics if `chunk_size` is zero.
@@ -1177,6 +1184,7 @@ impl<T> [T] {
11771184
///
11781185
/// [`chunks_exact_mut`]: slice::chunks_exact_mut
11791186
/// [`rchunks_mut`]: slice::rchunks_mut
1187+
/// [`as_chunks_mut`]: slice::as_chunks_mut
11801188
#[stable(feature = "rust1", since = "1.0.0")]
11811189
#[rustc_const_unstable(feature = "const_slice_make_iter", issue = "137737")]
11821190
#[inline]
@@ -1199,6 +1207,9 @@ impl<T> [T] {
11991207
/// See [`chunks`] for a variant of this iterator that also returns the remainder as a smaller
12001208
/// chunk, and [`rchunks_exact`] for the same iterator but starting at the end of the slice.
12011209
///
1210+
/// If your `chunk_size` is a constant, consider using [`as_chunks`] instead, which will
1211+
/// give references to arrays of exactly that length, rather than slices.
1212+
///
12021213
/// # Panics
12031214
///
12041215
/// Panics if `chunk_size` is zero.
@@ -1216,6 +1227,7 @@ impl<T> [T] {
12161227
///
12171228
/// [`chunks`]: slice::chunks
12181229
/// [`rchunks_exact`]: slice::rchunks_exact
1230+
/// [`as_chunks`]: slice::chunks
12191231
#[stable(feature = "chunks_exact", since = "1.31.0")]
12201232
#[rustc_const_unstable(feature = "const_slice_make_iter", issue = "137737")]
12211233
#[inline]
@@ -1239,6 +1251,9 @@ impl<T> [T] {
12391251
/// smaller chunk, and [`rchunks_exact_mut`] for the same iterator but starting at the end of
12401252
/// the slice.
12411253
///
1254+
/// If your `chunk_size` is a constant, consider using [`as_chunks_mut`] instead, which will
1255+
/// give references to arrays of exactly that length, rather than slices.
1256+
///
12421257
/// # Panics
12431258
///
12441259
/// Panics if `chunk_size` is zero.
@@ -1260,6 +1275,7 @@ impl<T> [T] {
12601275
///
12611276
/// [`chunks_mut`]: slice::chunks_mut
12621277
/// [`rchunks_exact_mut`]: slice::rchunks_exact_mut
1278+
/// [`as_chunks_mut`]: slice::as_chunks_mut
12631279
#[stable(feature = "chunks_exact", since = "1.31.0")]
12641280
#[rustc_const_unstable(feature = "const_slice_make_iter", issue = "137737")]
12651281
#[inline]
@@ -1707,6 +1723,9 @@ impl<T> [T] {
17071723
/// `chunk_size` elements, and [`chunks`] for the same iterator but starting at the beginning
17081724
/// of the slice.
17091725
///
1726+
/// If your `chunk_size` is a constant, consider using [`as_rchunks`] instead, which will
1727+
/// give references to arrays of exactly that length, rather than slices.
1728+
///
17101729
/// # Panics
17111730
///
17121731
/// Panics if `chunk_size` is zero.
@@ -1724,6 +1743,7 @@ impl<T> [T] {
17241743
///
17251744
/// [`rchunks_exact`]: slice::rchunks_exact
17261745
/// [`chunks`]: slice::chunks
1746+
/// [`as_rchunks`]: slice::as_rchunks
17271747
#[stable(feature = "rchunks", since = "1.31.0")]
17281748
#[rustc_const_unstable(feature = "const_slice_make_iter", issue = "137737")]
17291749
#[inline]
@@ -1743,6 +1763,9 @@ impl<T> [T] {
17431763
/// exactly `chunk_size` elements, and [`chunks_mut`] for the same iterator but starting at the
17441764
/// beginning of the slice.
17451765
///
1766+
/// If your `chunk_size` is a constant, consider using [`as_rchunks_mut`] instead, which will
1767+
/// give references to arrays of exactly that length, rather than slices.
1768+
///
17461769
/// # Panics
17471770
///
17481771
/// Panics if `chunk_size` is zero.
@@ -1764,6 +1787,7 @@ impl<T> [T] {
17641787
///
17651788
/// [`rchunks_exact_mut`]: slice::rchunks_exact_mut
17661789
/// [`chunks_mut`]: slice::chunks_mut
1790+
/// [`as_rchunks_mut`]: slice::as_rchunks_mut
17671791
#[stable(feature = "rchunks", since = "1.31.0")]
17681792
#[rustc_const_unstable(feature = "const_slice_make_iter", issue = "137737")]
17691793
#[inline]
@@ -1787,6 +1811,9 @@ impl<T> [T] {
17871811
/// chunk, and [`chunks_exact`] for the same iterator but starting at the beginning of the
17881812
/// slice.
17891813
///
1814+
/// If your `chunk_size` is a constant, consider using [`as_rchunks`] instead, which will
1815+
/// give references to arrays of exactly that length, rather than slices.
1816+
///
17901817
/// # Panics
17911818
///
17921819
/// Panics if `chunk_size` is zero.
@@ -1805,6 +1832,7 @@ impl<T> [T] {
18051832
/// [`chunks`]: slice::chunks
18061833
/// [`rchunks`]: slice::rchunks
18071834
/// [`chunks_exact`]: slice::chunks_exact
1835+
/// [`as_rchunks`]: slice::as_rchunks
18081836
#[stable(feature = "rchunks", since = "1.31.0")]
18091837
#[rustc_const_unstable(feature = "const_slice_make_iter", issue = "137737")]
18101838
#[inline]
@@ -1828,6 +1856,9 @@ impl<T> [T] {
18281856
/// smaller chunk, and [`chunks_exact_mut`] for the same iterator but starting at the beginning
18291857
/// of the slice.
18301858
///
1859+
/// If your `chunk_size` is a constant, consider using [`as_rchunks_mut`] instead, which will
1860+
/// give references to arrays of exactly that length, rather than slices.
1861+
///
18311862
/// # Panics
18321863
///
18331864
/// Panics if `chunk_size` is zero.
@@ -1850,6 +1881,7 @@ impl<T> [T] {
18501881
/// [`chunks_mut`]: slice::chunks_mut
18511882
/// [`rchunks_mut`]: slice::rchunks_mut
18521883
/// [`chunks_exact_mut`]: slice::chunks_exact_mut
1884+
/// [`as_rchunks_mut`]: slice::as_rchunks_mut
18531885
#[stable(feature = "rchunks", since = "1.31.0")]
18541886
#[rustc_const_unstable(feature = "const_slice_make_iter", issue = "137737")]
18551887
#[inline]

library/coretests/tests/floats/f128.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,6 @@ fn test_num_f128() {
5555
// FIXME(f16_f128,miri): many of these have to be disabled since miri does not yet support
5656
// the intrinsics.
5757

58-
#[test]
59-
fn test_nan() {
60-
let nan: f128 = f128::NAN;
61-
assert!(nan.is_nan());
62-
assert!(!nan.is_infinite());
63-
assert!(!nan.is_finite());
64-
assert!(nan.is_sign_positive());
65-
assert!(!nan.is_sign_negative());
66-
assert!(!nan.is_normal());
67-
assert_eq!(Fp::Nan, nan.classify());
68-
// Ensure the quiet bit is set.
69-
assert!(nan.to_bits() & (1 << (f128::MANTISSA_DIGITS - 2)) != 0);
70-
}
71-
7258
#[test]
7359
fn test_infinity() {
7460
let inf: f128 = f128::INFINITY;

0 commit comments

Comments
 (0)