Skip to content

Rollup of 11 pull requests #140503

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
Apr 30, 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
0ce0251
uses_power_alignment: wording tweaks
RalfJung Mar 28, 2025
87ff60c
check_struct_for_power_alignment: simplify code
RalfJung Apr 1, 2025
55a419f
Remove backticks from `ShouldPanic::YesWithMessage`'s `TrFailedMsg`
ShE3py Apr 28, 2025
5b1e495
Add a few extra tests to `tests/ui/macros/stringify.rs`.
nnethercote Apr 23, 2025
99f6b63
Improve pretty-printing of braces.
nnethercote May 17, 2024
cf12e29
enable msa feature for mips in codegen tests
koalatux Apr 29, 2025
4fe94ba
add `rust.debug-assertions-tools` option
pietroalbini Apr 29, 2025
2393e44
miri: algebraic intrinsics: bring back float non-determinism
RalfJung Apr 29, 2025
478b378
Move `on impl position` test to proper directory
mejrs Apr 29, 2025
fc2cd77
Fix comment describing what the test does
mejrs Apr 29, 2025
923ca85
Add test
oli-obk Apr 29, 2025
a1c7059
Treat `ManuallyDrop` as `~const Destruct`
oli-obk Apr 29, 2025
a4ce307
Coalesce duplicate missing clone tests
mejrs Apr 29, 2025
64bcf3b
Rename `rustc_query_append!` to `rustc_with_all_queries!`
Zalathar Apr 29, 2025
ed2f4b6
Reformat parameters to macros used by with-all-queries
Zalathar Apr 29, 2025
851decd
mention provenance in the pointer::wrapping_offset docs
lolbinarycat Mar 31, 2025
7275462
canonical no type foldable :<
lcnr Apr 28, 2025
bd3e447
Rollup merge of #136160 - ShE3py:should-panic-backticks, r=thomcc
matthiaskrgr Apr 30, 2025
e897144
Rollup merge of #139059 - RalfJung:uses_power_alignment, r=nagisa
matthiaskrgr Apr 30, 2025
aeec053
Rollup merge of #139192 - lolbinarycat:docs-wrapping_offset-provenanc…
matthiaskrgr Apr 30, 2025
56e01fe
Rollup merge of #140312 - nnethercote:DelimArgs-spacing, r=petrochenkov
matthiaskrgr Apr 30, 2025
b1a1c67
Rollup merge of #140404 - lcnr:canonical-no-type-foldable, r=compiler…
matthiaskrgr Apr 30, 2025
bb03780
Rollup merge of #140437 - husqvarnagroup:af/codegen-test-mips-msa, r=…
matthiaskrgr Apr 30, 2025
1267f0c
Rollup merge of #140438 - ferrocene:pa-debug-assertions-tools, r=Kobzol
matthiaskrgr Apr 30, 2025
254f050
Rollup merge of #140439 - RalfJung:miri-algebraic-float-nondet, r=oli…
matthiaskrgr Apr 30, 2025
9625096
Rollup merge of #140445 - oli-obk:const-manually-drop, r=fee1-dead
matthiaskrgr Apr 30, 2025
89ad574
Rollup merge of #140446 - mejrs:test1, r=jieyouxu
matthiaskrgr Apr 30, 2025
ae7d78a
Rollup merge of #140448 - Zalathar:query-append, r=compiler-errors
matthiaskrgr Apr 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
6 changes: 6 additions & 0 deletions bootstrap.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,12 @@
# Defaults to rust.debug-assertions value
#debug-assertions-std = rust.debug-assertions (boolean)

# Whether or not debug assertions are enabled for the tools built by bootstrap.
# Overrides the `debug-assertions` option, if defined.
#
# Defaults to rust.debug-assertions value
#debug-assertions-tools = rust.debug-assertions (boolean)

# Whether or not to leave debug! and trace! calls in the rust binary.
#
# Defaults to rust.debug-assertions value
Expand Down
33 changes: 24 additions & 9 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
false,
None,
*delim,
None,
tokens,
true,
span,
Expand Down Expand Up @@ -679,6 +680,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
false,
None,
*delim,
Some(spacing.open),
tts,
convert_dollar_crate,
dspan.entire(),
Expand Down Expand Up @@ -735,6 +737,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
has_bang: bool,
ident: Option<Ident>,
delim: Delimiter,
open_spacing: Option<Spacing>,
tts: &TokenStream,
convert_dollar_crate: bool,
span: Span,
Expand All @@ -758,16 +761,26 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
self.nbsp();
}
self.word("{");
if !tts.is_empty() {

// Respect `Alone`, if provided, and print a space. Unless the list is empty.
let open_space = (open_spacing == None || open_spacing == Some(Spacing::Alone))
&& !tts.is_empty();
if open_space {
self.space();
}
let ib = self.ibox(0);
self.print_tts(tts, convert_dollar_crate);
self.end(ib);
let empty = tts.is_empty();
self.bclose(span, empty, cb.unwrap());

// Use `open_space` for the spacing *before* the closing delim.
// Because spacing on delimiters is lost when going through
// proc macros, and otherwise we can end up with ugly cases
// like `{ x}`. Symmetry is better.
self.bclose(span, !open_space, cb.unwrap());
}
delim => {
// `open_spacing` is ignored. We never print spaces after
// non-brace opening delims or before non-brace closing delims.
let token_str = self.token_kind_to_string(&delim.as_open_token_kind());
self.word(token_str);
let ib = self.ibox(0);
Expand Down Expand Up @@ -797,6 +810,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
has_bang,
Some(*ident),
macro_def.body.delim,
None,
&macro_def.body.tokens,
true,
sp,
Expand Down Expand Up @@ -844,9 +858,9 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
self.end(ib);
}

fn bclose_maybe_open(&mut self, span: rustc_span::Span, empty: bool, cb: Option<BoxMarker>) {
fn bclose_maybe_open(&mut self, span: rustc_span::Span, no_space: bool, cb: Option<BoxMarker>) {
let has_comment = self.maybe_print_comment(span.hi());
if !empty || has_comment {
if !no_space || has_comment {
self.break_offset_if_not_bol(1, -INDENT_UNIT);
}
self.word("}");
Expand All @@ -855,9 +869,9 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
}
}

fn bclose(&mut self, span: rustc_span::Span, empty: bool, cb: BoxMarker) {
fn bclose(&mut self, span: rustc_span::Span, no_space: bool, cb: BoxMarker) {
let cb = Some(cb);
self.bclose_maybe_open(span, empty, cb)
self.bclose_maybe_open(span, no_space, cb)
}

fn break_offset_if_not_bol(&mut self, n: usize, off: isize) {
Expand Down Expand Up @@ -1434,8 +1448,8 @@ impl<'a> State<'a> {
}
}

let empty = !has_attrs && blk.stmts.is_empty();
self.bclose_maybe_open(blk.span, empty, cb);
let no_space = !has_attrs && blk.stmts.is_empty();
self.bclose_maybe_open(blk.span, no_space, cb);
self.ann.post(self, AnnNode::Block(blk))
}

Expand Down Expand Up @@ -1482,6 +1496,7 @@ impl<'a> State<'a> {
true,
None,
m.args.delim,
None,
&m.args.tokens,
true,
m.span(),
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_builtin_macros/src/autodiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,9 @@ mod llvm_enzyme {
Spacing::Joint,
)];
let never_arg = ast::DelimArgs {
dspan: ast::tokenstream::DelimSpan::from_single(span),
dspan: DelimSpan::from_single(span),
delim: ast::token::Delimiter::Parenthesis,
tokens: ast::tokenstream::TokenStream::from_iter(ts2),
tokens: TokenStream::from_iter(ts2),
};
let inline_item = ast::AttrItem {
unsafety: ast::Safety::Default,
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_const_eval/src/interpret/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {

let res = self.binary_op(op, &a, &b)?;
// `binary_op` already called `generate_nan` if needed.

// FIXME: Miri should add some non-determinism to the result here to catch any dependences on exact computations. This has previously been done, but the behaviour was removed as part of constification.
let res = M::apply_float_nondet(self, res)?;
self.write_immediate(*res, dest)?;
}

Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_const_eval/src/interpret/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,14 @@ pub trait Machine<'tcx>: Sized {
F2::NAN
}

/// Apply non-determinism to float operations that do not return a precise result.
fn apply_float_nondet(
_ecx: &mut InterpCx<'tcx, Self>,
val: ImmTy<'tcx, Self::Provenance>,
) -> InterpResult<'tcx, ImmTy<'tcx, Self::Provenance>> {
interp_ok(val)
}

/// Determines the result of `min`/`max` on floats when the arguments are equal.
fn equal_float_min_max<F: Float>(_ecx: &InterpCx<'tcx, Self>, a: F, _b: F) -> F {
// By default, we pick the left argument.
Expand Down
14 changes: 8 additions & 6 deletions compiler/rustc_expand/src/build.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use rustc_ast::ptr::P;
use rustc_ast::token::Delimiter;
use rustc_ast::tokenstream::TokenStream;
use rustc_ast::util::literal;
use rustc_ast::{
self as ast, AnonConst, AttrVec, BlockCheckMode, Expr, LocalKind, MatchKind, PatKind, UnOp,
attr, token,
attr, token, tokenstream,
};
use rustc_span::source_map::Spanned;
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym};
Expand Down Expand Up @@ -55,13 +57,13 @@ impl<'a> ExtCtxt<'a> {
&self,
span: Span,
path: ast::Path,
delim: ast::token::Delimiter,
tokens: ast::tokenstream::TokenStream,
delim: Delimiter,
tokens: TokenStream,
) -> P<ast::MacCall> {
P(ast::MacCall {
path,
args: P(ast::DelimArgs {
dspan: ast::tokenstream::DelimSpan { open: span, close: span },
dspan: tokenstream::DelimSpan { open: span, close: span },
delim,
tokens,
}),
Expand Down Expand Up @@ -480,8 +482,8 @@ impl<'a> ExtCtxt<'a> {
span,
[sym::std, sym::unreachable].map(|s| Ident::new(s, span)).to_vec(),
),
ast::token::Delimiter::Parenthesis,
ast::tokenstream::TokenStream::default(),
Delimiter::Parenthesis,
TokenStream::default(),
),
)
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ impl<'a> State<'a> {
false,
None,
*delim,
None,
&tokens,
true,
span,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
debug!("pick_all_method: step={:?}", step);
// skip types that are from a type error or that would require dereferencing
// a raw pointer
!step.self_ty.references_error() && !step.from_unsafe_deref
!step.self_ty.value.references_error() && !step.from_unsafe_deref
})
.find_map(|step| {
let InferOk { value: self_ty, obligations: _ } = self
Expand Down
22 changes: 1 addition & 21 deletions compiler/rustc_hir_typeck/src/writeback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use rustc_errors::ErrorGuaranteed;
use rustc_hir::intravisit::{self, InferKind, Visitor};
use rustc_hir::{self as hir, AmbigArg, HirId};
use rustc_infer::traits::solve::Goal;
use rustc_middle::span_bug;
use rustc_middle::traits::ObligationCause;
use rustc_middle::ty::adjustment::{Adjust, Adjustment, PointerCoercion};
use rustc_middle::ty::{
Expand Down Expand Up @@ -513,15 +512,6 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
self.typeck_results.user_provided_types_mut().extend(
fcx_typeck_results.user_provided_types().items().map(|(local_id, c_ty)| {
let hir_id = HirId { owner: common_hir_owner, local_id };

if cfg!(debug_assertions) && c_ty.has_infer() {
span_bug!(
hir_id.to_span(self.fcx.tcx),
"writeback: `{:?}` has inference variables",
c_ty
);
};

(hir_id, *c_ty)
}),
);
Expand All @@ -532,17 +522,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
assert_eq!(fcx_typeck_results.hir_owner, self.typeck_results.hir_owner);

self.typeck_results.user_provided_sigs.extend_unord(
fcx_typeck_results.user_provided_sigs.items().map(|(&def_id, c_sig)| {
if cfg!(debug_assertions) && c_sig.has_infer() {
span_bug!(
self.fcx.tcx.def_span(def_id),
"writeback: `{:?}` has inference variables",
c_sig
);
};

(def_id, *c_sig)
}),
fcx_typeck_results.user_provided_sigs.items().map(|(def_id, c_sig)| (*def_id, *c_sig)),
);
}

Expand Down
35 changes: 14 additions & 21 deletions compiler/rustc_lint/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -755,10 +755,10 @@ declare_lint! {
/// *subsequent* fields of the associated structs to use an alignment value
/// where the floating-point type is aligned on a 4-byte boundary.
///
/// The power alignment rule for structs needed for C compatibility is
/// unimplementable within `repr(C)` in the compiler without building in
/// handling of references to packed fields and infectious nested layouts,
/// so a warning is produced in these situations.
/// Effectively, subsequent floating-point fields act as-if they are `repr(packed(4))`. This
/// would be unsound to do in a `repr(C)` type without all the restrictions that come with
/// `repr(packed)`. Rust instead chooses a layout that maintains soundness of Rust code, at the
/// expense of incompatibility with C code.
///
/// ### Example
///
Expand Down Expand Up @@ -790,8 +790,10 @@ declare_lint! {
/// - offset_of!(Floats, a) == 0
/// - offset_of!(Floats, b) == 8
/// - offset_of!(Floats, c) == 12
/// However, rust currently aligns `c` at offset_of!(Floats, c) == 16.
/// Thus, a warning should be produced for the above struct in this case.
///
/// However, Rust currently aligns `c` at `offset_of!(Floats, c) == 16`.
/// Using offset 12 would be unsound since `f64` generally must be 8-aligned on this target.
/// Thus, a warning is produced for the above struct.
USES_POWER_ALIGNMENT,
Warn,
"Structs do not follow the power alignment rule under repr(C)"
Expand Down Expand Up @@ -1655,15 +1657,13 @@ impl ImproperCTypesDefinitions {
cx: &LateContext<'tcx>,
ty: Ty<'tcx>,
) -> bool {
assert!(cx.tcx.sess.target.os == "aix");
// Structs (under repr(C)) follow the power alignment rule if:
// - the first field of the struct is a floating-point type that
// is greater than 4-bytes, or
// - the first field of the struct is an aggregate whose
// recursively first field is a floating-point type greater than
// 4 bytes.
if cx.tcx.sess.target.os != "aix" {
return false;
}
if ty.is_floating_point() && ty.primitive_size(cx.tcx).bytes() > 4 {
return true;
} else if let Adt(adt_def, _) = ty.kind()
Expand Down Expand Up @@ -1701,21 +1701,14 @@ impl ImproperCTypesDefinitions {
&& !adt_def.all_fields().next().is_none()
{
let struct_variant_data = item.expect_struct().1;
for (index, ..) in struct_variant_data.fields().iter().enumerate() {
for field_def in struct_variant_data.fields().iter().skip(1) {
// Struct fields (after the first field) are checked for the
// power alignment rule, as fields after the first are likely
// to be the fields that are misaligned.
if index != 0 {
let first_field_def = struct_variant_data.fields()[index];
let def_id = first_field_def.def_id;
let ty = cx.tcx.type_of(def_id).instantiate_identity();
if self.check_arg_for_power_alignment(cx, ty) {
cx.emit_span_lint(
USES_POWER_ALIGNMENT,
first_field_def.span,
UsesPowerAlignment,
);
}
let def_id = field_def.def_id;
let ty = cx.tcx.type_of(def_id).instantiate_identity();
if self.check_arg_for_power_alignment(cx, ty) {
cx.emit_span_lint(USES_POWER_ALIGNMENT, field_def.span, UsesPowerAlignment);
}
}
}
Expand Down
18 changes: 15 additions & 3 deletions compiler/rustc_macros/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,11 +407,23 @@ pub(super) fn rustc_queries(input: TokenStream) -> TokenStream {
}

TokenStream::from(quote! {
/// Higher-order macro that invokes the specified macro with a prepared
/// list of all query signatures (including modifiers).
///
/// This allows multiple simpler macros to each have access to the list
/// of queries.
#[macro_export]
macro_rules! rustc_query_append {
($macro:ident! $( [$($other:tt)*] )?) => {
macro_rules! rustc_with_all_queries {
(
// The macro to invoke once, on all queries (plus extras).
$macro:ident!

// Within [], an optional list of extra "query" signatures to
// pass to the given macro, in addition to the actual queries.
$( [$($extra_fake_queries:tt)*] )?
) => {
$macro! {
$( $($other)* )?
$( $($extra_fake_queries)* )?
#query_stream
}
}
Expand Down
11 changes: 8 additions & 3 deletions compiler/rustc_middle/src/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ use crate::ty::TyCtxt;

macro_rules! define_dep_nodes {
(
$($(#[$attr:meta])*
[$($modifiers:tt)*] fn $variant:ident($($K:tt)*) -> $V:ty,)*) => {
$(
$(#[$attr:meta])*
[$($modifiers:tt)*] fn $variant:ident($($K:tt)*) -> $V:ty,
)*
) => {

#[macro_export]
macro_rules! make_dep_kind_array {
Expand Down Expand Up @@ -83,7 +86,9 @@ macro_rules! define_dep_nodes {
};
}

rustc_query_append!(define_dep_nodes![
// Create various data structures for each query, and also for a few things
// that aren't queries.
rustc_with_all_queries!(define_dep_nodes![
/// We use this for most things when incr. comp. is turned off.
[] fn Null() -> (),
/// We use this to create a forever-red node.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2578,5 +2578,5 @@ rustc_queries! {
}
}

rustc_query_append! { define_callbacks! }
rustc_with_all_queries! { define_callbacks! }
rustc_feedable_queries! { define_feedable! }
7 changes: 5 additions & 2 deletions compiler/rustc_middle/src/query/plumbing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,11 @@ macro_rules! separate_provide_extern_default {

macro_rules! define_callbacks {
(
$($(#[$attr:meta])*
[$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,)*) => {
$(
$(#[$attr:meta])*
[$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,
)*
) => {

#[allow(unused_lifetimes)]
pub mod queries {
Expand Down
Loading
Loading