Skip to content

Commit fa4163d

Browse files
Auto merge of #146429 - Zalathar:rollup-eivhl6u, r=<try>
Rollup of 11 pull requests try-job: test-various try-job: dist-various try-job: x86_64-gnu-llvm-19-3
2 parents f4665ab + 613a3b6 commit fa4163d

File tree

49 files changed

+576
-534
lines changed

Some content is hidden

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

49 files changed

+576
-534
lines changed

compiler/rustc_builtin_macros/src/assert.rs

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
mod context;
22

3-
use rustc_ast::token::{self, Delimiter};
3+
use rustc_ast::token::Delimiter;
44
use rustc_ast::tokenstream::{DelimSpan, TokenStream};
5-
use rustc_ast::{DelimArgs, Expr, ExprKind, MacCall, Path, PathSegment};
5+
use rustc_ast::{DelimArgs, Expr, ExprKind, MacCall, Path, PathSegment, UnOp, token};
66
use rustc_ast_pretty::pprust;
77
use rustc_errors::PResult;
88
use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt, MacEager, MacroExpanderResult};
@@ -29,7 +29,7 @@ pub(crate) fn expand_assert<'cx>(
2929

3030
// `core::panic` and `std::panic` are different macros, so we use call-site
3131
// context to pick up whichever is currently in scope.
32-
let call_site_span = cx.with_call_site_ctxt(cond_expr.span);
32+
let call_site_span = cx.with_call_site_ctxt(span);
3333

3434
let panic_path = || {
3535
if use_panic_2021(span) {
@@ -63,7 +63,7 @@ pub(crate) fn expand_assert<'cx>(
6363
}),
6464
})),
6565
);
66-
assert_cond_check(cx, call_site_span, cond_expr, then)
66+
expr_if_not(cx, call_site_span, cond_expr, then, None)
6767
}
6868
// If `generic_assert` is enabled, generates rich captured outputs
6969
//
@@ -88,33 +88,26 @@ pub(crate) fn expand_assert<'cx>(
8888
)),
8989
)],
9090
);
91-
assert_cond_check(cx, call_site_span, cond_expr, then)
91+
expr_if_not(cx, call_site_span, cond_expr, then, None)
9292
};
9393

9494
ExpandResult::Ready(MacEager::expr(expr))
9595
}
9696

97-
/// `assert!($cond_expr, $custom_message)`
9897
struct Assert {
9998
cond_expr: Box<Expr>,
10099
custom_message: Option<TokenStream>,
101100
}
102101

103-
/// `match <cond> { true => {} _ => <then> }`
104-
fn assert_cond_check(cx: &ExtCtxt<'_>, span: Span, cond: Box<Expr>, then: Box<Expr>) -> Box<Expr> {
105-
// Instead of expanding to `if !<cond> { <then> }`, we expand to
106-
// `match <cond> { true => {} _ => <then> }`.
107-
// This allows us to always complain about mismatched types instead of "cannot apply unary
108-
// operator `!` to type `X`" when passing an invalid `<cond>`, while also allowing `<cond>` to
109-
// be `&true`.
110-
let els = cx.expr_block(cx.block(span, thin_vec![]));
111-
let mut arms = thin_vec![];
112-
arms.push(cx.arm(span, cx.pat_lit(span, cx.expr_bool(span, true)), els));
113-
arms.push(cx.arm(span, cx.pat_wild(span), then));
114-
115-
// We wrap the `match` in a statement to limit the length of any borrows introduced in the
116-
// condition.
117-
cx.expr_block(cx.block(span, [cx.stmt_expr(cx.expr_match(span, cond, arms))].into()))
102+
// if !{ ... } { ... } else { ... }
103+
fn expr_if_not(
104+
cx: &ExtCtxt<'_>,
105+
span: Span,
106+
cond: Box<Expr>,
107+
then: Box<Expr>,
108+
els: Option<Box<Expr>>,
109+
) -> Box<Expr> {
110+
cx.expr_if(span, cx.expr(span, ExprKind::Unary(UnOp::Not, cond)), then, els)
118111
}
119112

120113
fn parse_assert<'a>(cx: &ExtCtxt<'a>, sp: Span, stream: TokenStream) -> PResult<'a, Assert> {

compiler/rustc_parse/src/parser/ty.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ fn can_continue_type_after_non_fn_ident(t: &Token) -> bool {
9292
}
9393

9494
fn can_begin_dyn_bound_in_edition_2015(t: &Token) -> bool {
95-
// `Not`, `Tilde` & `Const` are deliberately not part of this list to
95+
// `!`, `const`, `[`, `async` are deliberately not part of this list to
9696
// contain the number of potential regressions esp. in MBE code.
97-
// `Const` would regress `rfc-2632-const-trait-impl/mbe-dyn-const-2015.rs`.
98-
// `Not` would regress `dyn!(...)` macro calls in Rust 2015.
97+
// `const` and `[` would regress UI test `macro-dyn-const-2015.rs`.
98+
// `!` would regress `dyn!(...)` macro calls in Rust 2015.
9999
t.is_path_start()
100100
|| t.is_lifetime()
101101
|| t == &TokenKind::Question
@@ -1015,12 +1015,18 @@ impl<'a> Parser<'a> {
10151015
|| self.check(exp!(Tilde))
10161016
|| self.check_keyword(exp!(For))
10171017
|| self.check(exp!(OpenParen))
1018-
|| self.check(exp!(OpenBracket))
1018+
|| self.can_begin_maybe_const_bound()
10191019
|| self.check_keyword(exp!(Const))
10201020
|| self.check_keyword(exp!(Async))
10211021
|| self.check_keyword(exp!(Use))
10221022
}
10231023

1024+
fn can_begin_maybe_const_bound(&mut self) -> bool {
1025+
self.check(exp!(OpenBracket))
1026+
&& self.look_ahead(1, |t| t.is_keyword(kw::Const))
1027+
&& self.look_ahead(2, |t| *t == token::CloseBracket)
1028+
}
1029+
10241030
/// Parse a bound.
10251031
///
10261032
/// ```ebnf
@@ -1199,10 +1205,7 @@ impl<'a> Parser<'a> {
11991205
let span = tilde.to(self.prev_token.span);
12001206
self.psess.gated_spans.gate(sym::const_trait_impl, span);
12011207
BoundConstness::Maybe(span)
1202-
} else if self.check(exp!(OpenBracket))
1203-
&& self.look_ahead(1, |t| t.is_keyword(kw::Const))
1204-
&& self.look_ahead(2, |t| *t == token::CloseBracket)
1205-
{
1208+
} else if self.can_begin_maybe_const_bound() {
12061209
let start = self.token.span;
12071210
self.bump();
12081211
self.expect_keyword(exp!(Const)).unwrap();

compiler/rustc_span/src/symbol.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::ops::Deref;
77
use std::{fmt, str};
88

99
use rustc_arena::DroplessArena;
10-
use rustc_data_structures::fx::FxIndexSet;
10+
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
1111
use rustc_data_structures::stable_hasher::{
1212
HashStable, StableCompare, StableHasher, ToStableHashKey,
1313
};
@@ -2871,11 +2871,20 @@ impl Interner {
28712871
let byte_strs = FxIndexSet::from_iter(
28722872
init.iter().copied().chain(extra.iter().copied()).map(|str| str.as_bytes()),
28732873
);
2874-
assert_eq!(
2875-
byte_strs.len(),
2876-
init.len() + extra.len(),
2877-
"duplicate symbols in the rustc symbol list and the extra symbols added by the driver",
2878-
);
2874+
2875+
// The order in which duplicates are reported is irrelevant.
2876+
#[expect(rustc::potential_query_instability)]
2877+
if byte_strs.len() != init.len() + extra.len() {
2878+
panic!(
2879+
"duplicate symbols in the rustc symbol list and the extra symbols added by the driver: {:?}",
2880+
FxHashSet::intersection(
2881+
&init.iter().copied().collect(),
2882+
&extra.iter().copied().collect(),
2883+
)
2884+
.collect::<Vec<_>>()
2885+
)
2886+
}
2887+
28792888
Interner(Lock::new(InternerInner { arena: Default::default(), byte_strs }))
28802889
}
28812890

compiler/rustc_target/src/target_features.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,7 @@ const IBMZ_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[
849849
("miscellaneous-extensions-3", Unstable(sym::s390x_target_feature), &[]),
850850
("miscellaneous-extensions-4", Unstable(sym::s390x_target_feature), &[]),
851851
("nnp-assist", Unstable(sym::s390x_target_feature), &["vector"]),
852+
("soft-float", Forbidden { reason: "currently unsupported ABI-configuration feature" }, &[]),
852853
("transactional-execution", Unstable(sym::s390x_target_feature), &[]),
853854
("vector", Unstable(sym::s390x_target_feature), &[]),
854855
("vector-enhancements-1", Unstable(sym::s390x_target_feature), &["vector"]),
@@ -1177,6 +1178,13 @@ impl Target {
11771178
_ => unreachable!(),
11781179
}
11791180
}
1181+
"s390x" => {
1182+
// We don't currently support a softfloat target on this architecture.
1183+
// As usual, we have to reject swapping the `soft-float` target feature.
1184+
// The "vector" target feature does not affect the ABI for floats
1185+
// because the vector and float registers overlap.
1186+
FeatureConstraints { required: &[], incompatible: &["soft-float"] }
1187+
}
11801188
_ => NOTHING,
11811189
}
11821190
}

compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,18 +1618,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
16181618
{
16191619
let e = self.tcx.erase_and_anonymize_regions(e);
16201620
let f = self.tcx.erase_and_anonymize_regions(f);
1621-
let mut expected = with_forced_trimmed_paths!(e.sort_string(self.tcx));
1622-
let mut found = with_forced_trimmed_paths!(f.sort_string(self.tcx));
1623-
if let ObligationCauseCode::Pattern { span, .. } = cause.code()
1624-
&& let Some(span) = span
1625-
&& !span.from_expansion()
1626-
&& cause.span.from_expansion()
1627-
{
1628-
// When the type error comes from a macro like `assert!()`, and we are pointing at
1629-
// code the user wrote the cause and effect are reversed as the expected value is
1630-
// what the macro expanded to.
1631-
(found, expected) = (expected, found);
1632-
}
1621+
let expected = with_forced_trimmed_paths!(e.sort_string(self.tcx));
1622+
let found = with_forced_trimmed_paths!(f.sort_string(self.tcx));
16331623
if expected == found {
16341624
label_or_note(span, terr.to_string(self.tcx));
16351625
} else {
@@ -2152,9 +2142,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
21522142
) -> Option<(DiagStyledString, DiagStyledString)> {
21532143
match values {
21542144
ValuePairs::Regions(exp_found) => self.expected_found_str(exp_found),
2155-
ValuePairs::Terms(exp_found) => {
2156-
self.expected_found_str_term(cause, exp_found, long_ty_path)
2157-
}
2145+
ValuePairs::Terms(exp_found) => self.expected_found_str_term(exp_found, long_ty_path),
21582146
ValuePairs::Aliases(exp_found) => self.expected_found_str(exp_found),
21592147
ValuePairs::ExistentialTraitRef(exp_found) => self.expected_found_str(exp_found),
21602148
ValuePairs::ExistentialProjection(exp_found) => self.expected_found_str(exp_found),
@@ -2193,35 +2181,15 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
21932181

21942182
fn expected_found_str_term(
21952183
&self,
2196-
cause: &ObligationCause<'tcx>,
21972184
exp_found: ty::error::ExpectedFound<ty::Term<'tcx>>,
21982185
long_ty_path: &mut Option<PathBuf>,
21992186
) -> Option<(DiagStyledString, DiagStyledString)> {
22002187
let exp_found = self.resolve_vars_if_possible(exp_found);
22012188
if exp_found.references_error() {
22022189
return None;
22032190
}
2204-
let (mut expected, mut found) = (exp_found.expected, exp_found.found);
2205-
2206-
if let ObligationCauseCode::Pattern { span, .. } = cause.code()
2207-
&& let Some(span) = span
2208-
&& !span.from_expansion()
2209-
&& cause.span.from_expansion()
2210-
{
2211-
// When the type error comes from a macro like `assert!()`, and we are pointing at
2212-
// code the user wrote, the cause and effect are reversed as the expected value is
2213-
// what the macro expanded to. So if the user provided a `Type` when the macro is
2214-
// written in such a way that a `bool` was expected, we want to print:
2215-
// = note: expected `bool`
2216-
// found `Type`"
2217-
// but as far as the compiler is concerned, after expansion what was expected was `Type`
2218-
// = note: expected `Type`
2219-
// found `bool`"
2220-
// so we reverse them here to match user expectation.
2221-
(expected, found) = (found, expected);
2222-
}
22232191

2224-
Some(match (expected.kind(), found.kind()) {
2192+
Some(match (exp_found.expected.kind(), exp_found.found.kind()) {
22252193
(ty::TermKind::Ty(expected), ty::TermKind::Ty(found)) => {
22262194
let (mut exp, mut fnd) = self.cmp(expected, found);
22272195
// Use the terminal width as the basis to determine when to compress the printed

library/core/src/ptr/const_ptr.rs

Lines changed: 13 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -146,28 +146,7 @@ impl<T: PointeeSized> *const T {
146146
self as _
147147
}
148148

149-
/// Gets the "address" portion of the pointer.
150-
///
151-
/// This is similar to `self as usize`, except that the [provenance][crate::ptr#provenance] of
152-
/// the pointer is discarded and not [exposed][crate::ptr#exposed-provenance]. This means that
153-
/// casting the returned address back to a pointer yields a [pointer without
154-
/// provenance][without_provenance], which is undefined behavior to dereference. To properly
155-
/// restore the lost information and obtain a dereferenceable pointer, use
156-
/// [`with_addr`][pointer::with_addr] or [`map_addr`][pointer::map_addr].
157-
///
158-
/// If using those APIs is not possible because there is no way to preserve a pointer with the
159-
/// required provenance, then Strict Provenance might not be for you. Use pointer-integer casts
160-
/// or [`expose_provenance`][pointer::expose_provenance] and [`with_exposed_provenance`][with_exposed_provenance]
161-
/// instead. However, note that this makes your code less portable and less amenable to tools
162-
/// that check for compliance with the Rust memory model.
163-
///
164-
/// On most platforms this will produce a value with the same bytes as the original
165-
/// pointer, because all the bytes are dedicated to describing the address.
166-
/// Platforms which need to store additional information in the pointer may
167-
/// perform a change of representation to produce a value containing only the address
168-
/// portion of the pointer. What that means is up to the platform to define.
169-
///
170-
/// This is a [Strict Provenance][crate::ptr#strict-provenance] API.
149+
#[doc = include_str!("./docs/addr.md")]
171150
#[must_use]
172151
#[inline(always)]
173152
#[stable(feature = "strict_provenance", since = "1.84.0")]
@@ -254,23 +233,16 @@ impl<T: PointeeSized> *const T {
254233
(self.cast(), metadata(self))
255234
}
256235

257-
/// Returns `None` if the pointer is null, or else returns a shared reference to
258-
/// the value wrapped in `Some`. If the value may be uninitialized, [`as_uninit_ref`]
259-
/// must be used instead.
260-
///
261-
/// [`as_uninit_ref`]: #method.as_uninit_ref
262-
///
263-
/// # Safety
264-
///
265-
/// When calling this method, you have to ensure that *either* the pointer is null *or*
266-
/// the pointer is [convertible to a reference](crate::ptr#pointer-to-reference-conversion).
236+
#[doc = include_str!("./docs/as_ref.md")]
267237
///
268-
/// # Panics during const evaluation
269-
///
270-
/// This method will panic during const evaluation if the pointer cannot be
271-
/// determined to be null or not. See [`is_null`] for more information.
238+
/// ```
239+
/// let ptr: *const u8 = &10u8 as *const u8;
272240
///
273-
/// [`is_null`]: #method.is_null
241+
/// unsafe {
242+
/// let val_back = &*ptr;
243+
/// assert_eq!(val_back, &10);
244+
/// }
245+
/// ```
274246
///
275247
/// # Examples
276248
///
@@ -284,20 +256,9 @@ impl<T: PointeeSized> *const T {
284256
/// }
285257
/// ```
286258
///
287-
/// # Null-unchecked version
288259
///
289-
/// If you are sure the pointer can never be null and are looking for some kind of
290-
/// `as_ref_unchecked` that returns the `&T` instead of `Option<&T>`, know that you can
291-
/// dereference the pointer directly.
292-
///
293-
/// ```
294-
/// let ptr: *const u8 = &10u8 as *const u8;
295-
///
296-
/// unsafe {
297-
/// let val_back = &*ptr;
298-
/// assert_eq!(val_back, &10);
299-
/// }
300-
/// ```
260+
/// [`is_null`]: #method.is_null
261+
/// [`as_uninit_ref`]: #method.as_uninit_ref
301262
#[stable(feature = "ptr_as_ref", since = "1.9.0")]
302263
#[rustc_const_stable(feature = "const_ptr_is_null", since = "1.84.0")]
303264
#[inline]
@@ -338,23 +299,10 @@ impl<T: PointeeSized> *const T {
338299
unsafe { &*self }
339300
}
340301

341-
/// Returns `None` if the pointer is null, or else returns a shared reference to
342-
/// the value wrapped in `Some`. In contrast to [`as_ref`], this does not require
343-
/// that the value has to be initialized.
344-
///
345-
/// [`as_ref`]: #method.as_ref
346-
///
347-
/// # Safety
348-
///
349-
/// When calling this method, you have to ensure that *either* the pointer is null *or*
350-
/// the pointer is [convertible to a reference](crate::ptr#pointer-to-reference-conversion).
351-
///
352-
/// # Panics during const evaluation
353-
///
354-
/// This method will panic during const evaluation if the pointer cannot be
355-
/// determined to be null or not. See [`is_null`] for more information.
302+
#[doc = include_str!("./docs/as_uninit_ref.md")]
356303
///
357304
/// [`is_null`]: #method.is_null
305+
/// [`as_ref`]: #method.as_ref
358306
///
359307
/// # Examples
360308
///

library/core/src/ptr/docs/INFO.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
This directory holds method documentation that otherwise
2+
would be duplicated across mutable and immutable pointers.
3+
4+
Note that most of the docs here are not the complete docs
5+
for their corresponding method. This is for a few reasons:
6+
7+
1. Examples need to be different for mutable/immutable
8+
pointers, in order to actually call the correct method.
9+
2. Link reference definitions are frequently different
10+
between mutable/immutable pointers, in order to link to
11+
the correct method.
12+
For example, `<*const T>::as_ref` links to
13+
`<*const T>::is_null`, while `<*mut T>::as_ref` links to
14+
`<*mut T>::is_null`.
15+
3. Many methods on mutable pointers link to an alternate
16+
version that returns a mutable reference instead of
17+
a shared reference.
18+
19+
Always review the rendered docs manually when making
20+
changes to these files to make sure you're not accidentally
21+
splitting up a section.

0 commit comments

Comments
 (0)