Skip to content

Commit 7188f45

Browse files
committed
Auto merge of #140503 - matthiaskrgr:rollup-n7zigts, r=matthiaskrgr
Rollup of 11 pull requests Successful merges: - #136160 (Remove backticks from `ShouldPanic::YesWithMessage`'s `TrFailedMsg`) - #139059 (uses_power_alignment: wording tweaks) - #139192 (mention provenance in the pointer::wrapping_offset docs) - #140312 (Improve pretty-printing of braces) - #140404 (rm `TypeVistable` impls for `Canonical`) - #140437 (enable msa feature for mips in codegen tests) - #140438 (Add `rust.debug-assertions-tools` option) - #140439 (miri: algebraic intrinsics: bring back float non-determinism) - #140445 (Treat ManuallyDrop as ~const Destruct) - #140446 (chore: fix some tests) - #140448 (Rename `rustc_query_append!` to `rustc_with_all_queries!`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents d2eadb7 + ae7d78a commit 7188f45

File tree

55 files changed

+382
-309
lines changed

Some content is hidden

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

55 files changed

+382
-309
lines changed

bootstrap.example.toml

+6
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,12 @@
570570
# Defaults to rust.debug-assertions value
571571
#debug-assertions-std = rust.debug-assertions (boolean)
572572

573+
# Whether or not debug assertions are enabled for the tools built by bootstrap.
574+
# Overrides the `debug-assertions` option, if defined.
575+
#
576+
# Defaults to rust.debug-assertions value
577+
#debug-assertions-tools = rust.debug-assertions (boolean)
578+
573579
# Whether or not to leave debug! and trace! calls in the rust binary.
574580
#
575581
# Defaults to rust.debug-assertions value

compiler/rustc_ast_pretty/src/pprust/state.rs

+24-9
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
634634
false,
635635
None,
636636
*delim,
637+
None,
637638
tokens,
638639
true,
639640
span,
@@ -679,6 +680,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
679680
false,
680681
None,
681682
*delim,
683+
Some(spacing.open),
682684
tts,
683685
convert_dollar_crate,
684686
dspan.entire(),
@@ -735,6 +737,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
735737
has_bang: bool,
736738
ident: Option<Ident>,
737739
delim: Delimiter,
740+
open_spacing: Option<Spacing>,
738741
tts: &TokenStream,
739742
convert_dollar_crate: bool,
740743
span: Span,
@@ -758,16 +761,26 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
758761
self.nbsp();
759762
}
760763
self.word("{");
761-
if !tts.is_empty() {
764+
765+
// Respect `Alone`, if provided, and print a space. Unless the list is empty.
766+
let open_space = (open_spacing == None || open_spacing == Some(Spacing::Alone))
767+
&& !tts.is_empty();
768+
if open_space {
762769
self.space();
763770
}
764771
let ib = self.ibox(0);
765772
self.print_tts(tts, convert_dollar_crate);
766773
self.end(ib);
767-
let empty = tts.is_empty();
768-
self.bclose(span, empty, cb.unwrap());
774+
775+
// Use `open_space` for the spacing *before* the closing delim.
776+
// Because spacing on delimiters is lost when going through
777+
// proc macros, and otherwise we can end up with ugly cases
778+
// like `{ x}`. Symmetry is better.
779+
self.bclose(span, !open_space, cb.unwrap());
769780
}
770781
delim => {
782+
// `open_spacing` is ignored. We never print spaces after
783+
// non-brace opening delims or before non-brace closing delims.
771784
let token_str = self.token_kind_to_string(&delim.as_open_token_kind());
772785
self.word(token_str);
773786
let ib = self.ibox(0);
@@ -797,6 +810,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
797810
has_bang,
798811
Some(*ident),
799812
macro_def.body.delim,
813+
None,
800814
&macro_def.body.tokens,
801815
true,
802816
sp,
@@ -844,9 +858,9 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
844858
self.end(ib);
845859
}
846860

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

858-
fn bclose(&mut self, span: rustc_span::Span, empty: bool, cb: BoxMarker) {
872+
fn bclose(&mut self, span: rustc_span::Span, no_space: bool, cb: BoxMarker) {
859873
let cb = Some(cb);
860-
self.bclose_maybe_open(span, empty, cb)
874+
self.bclose_maybe_open(span, no_space, cb)
861875
}
862876

863877
fn break_offset_if_not_bol(&mut self, n: usize, off: isize) {
@@ -1434,8 +1448,8 @@ impl<'a> State<'a> {
14341448
}
14351449
}
14361450

1437-
let empty = !has_attrs && blk.stmts.is_empty();
1438-
self.bclose_maybe_open(blk.span, empty, cb);
1451+
let no_space = !has_attrs && blk.stmts.is_empty();
1452+
self.bclose_maybe_open(blk.span, no_space, cb);
14391453
self.ann.post(self, AnnNode::Block(blk))
14401454
}
14411455

@@ -1482,6 +1496,7 @@ impl<'a> State<'a> {
14821496
true,
14831497
None,
14841498
m.args.delim,
1499+
None,
14851500
&m.args.tokens,
14861501
true,
14871502
m.span(),

compiler/rustc_builtin_macros/src/autodiff.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,9 @@ mod llvm_enzyme {
323323
Spacing::Joint,
324324
)];
325325
let never_arg = ast::DelimArgs {
326-
dspan: ast::tokenstream::DelimSpan::from_single(span),
326+
dspan: DelimSpan::from_single(span),
327327
delim: ast::token::Delimiter::Parenthesis,
328-
tokens: ast::tokenstream::TokenStream::from_iter(ts2),
328+
tokens: TokenStream::from_iter(ts2),
329329
};
330330
let inline_item = ast::AttrItem {
331331
unsafety: ast::Safety::Default,

compiler/rustc_const_eval/src/interpret/intrinsics.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
183183

184184
let res = self.binary_op(op, &a, &b)?;
185185
// `binary_op` already called `generate_nan` if needed.
186-
187-
// 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.
186+
let res = M::apply_float_nondet(self, res)?;
188187
self.write_immediate(*res, dest)?;
189188
}
190189

compiler/rustc_const_eval/src/interpret/machine.rs

+8
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,14 @@ pub trait Machine<'tcx>: Sized {
276276
F2::NAN
277277
}
278278

279+
/// Apply non-determinism to float operations that do not return a precise result.
280+
fn apply_float_nondet(
281+
_ecx: &mut InterpCx<'tcx, Self>,
282+
val: ImmTy<'tcx, Self::Provenance>,
283+
) -> InterpResult<'tcx, ImmTy<'tcx, Self::Provenance>> {
284+
interp_ok(val)
285+
}
286+
279287
/// Determines the result of `min`/`max` on floats when the arguments are equal.
280288
fn equal_float_min_max<F: Float>(_ecx: &InterpCx<'tcx, Self>, a: F, _b: F) -> F {
281289
// By default, we pick the left argument.

compiler/rustc_expand/src/build.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use rustc_ast::ptr::P;
2+
use rustc_ast::token::Delimiter;
3+
use rustc_ast::tokenstream::TokenStream;
24
use rustc_ast::util::literal;
35
use rustc_ast::{
46
self as ast, AnonConst, AttrVec, BlockCheckMode, Expr, LocalKind, MatchKind, PatKind, UnOp,
5-
attr, token,
7+
attr, token, tokenstream,
68
};
79
use rustc_span::source_map::Spanned;
810
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym};
@@ -55,13 +57,13 @@ impl<'a> ExtCtxt<'a> {
5557
&self,
5658
span: Span,
5759
path: ast::Path,
58-
delim: ast::token::Delimiter,
59-
tokens: ast::tokenstream::TokenStream,
60+
delim: Delimiter,
61+
tokens: TokenStream,
6062
) -> P<ast::MacCall> {
6163
P(ast::MacCall {
6264
path,
6365
args: P(ast::DelimArgs {
64-
dspan: ast::tokenstream::DelimSpan { open: span, close: span },
66+
dspan: tokenstream::DelimSpan { open: span, close: span },
6567
delim,
6668
tokens,
6769
}),
@@ -480,8 +482,8 @@ impl<'a> ExtCtxt<'a> {
480482
span,
481483
[sym::std, sym::unreachable].map(|s| Ident::new(s, span)).to_vec(),
482484
),
483-
ast::token::Delimiter::Parenthesis,
484-
ast::tokenstream::TokenStream::default(),
485+
Delimiter::Parenthesis,
486+
TokenStream::default(),
485487
),
486488
)
487489
}

compiler/rustc_hir_pretty/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ impl<'a> State<'a> {
146146
false,
147147
None,
148148
*delim,
149+
None,
149150
&tokens,
150151
true,
151152
span,

compiler/rustc_hir_typeck/src/method/probe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
12131213
debug!("pick_all_method: step={:?}", step);
12141214
// skip types that are from a type error or that would require dereferencing
12151215
// a raw pointer
1216-
!step.self_ty.references_error() && !step.from_unsafe_deref
1216+
!step.self_ty.value.references_error() && !step.from_unsafe_deref
12171217
})
12181218
.find_map(|step| {
12191219
let InferOk { value: self_ty, obligations: _ } = self

compiler/rustc_hir_typeck/src/writeback.rs

+1-21
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use rustc_errors::ErrorGuaranteed;
99
use rustc_hir::intravisit::{self, InferKind, Visitor};
1010
use rustc_hir::{self as hir, AmbigArg, HirId};
1111
use rustc_infer::traits::solve::Goal;
12-
use rustc_middle::span_bug;
1312
use rustc_middle::traits::ObligationCause;
1413
use rustc_middle::ty::adjustment::{Adjust, Adjustment, PointerCoercion};
1514
use rustc_middle::ty::{
@@ -513,15 +512,6 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
513512
self.typeck_results.user_provided_types_mut().extend(
514513
fcx_typeck_results.user_provided_types().items().map(|(local_id, c_ty)| {
515514
let hir_id = HirId { owner: common_hir_owner, local_id };
516-
517-
if cfg!(debug_assertions) && c_ty.has_infer() {
518-
span_bug!(
519-
hir_id.to_span(self.fcx.tcx),
520-
"writeback: `{:?}` has inference variables",
521-
c_ty
522-
);
523-
};
524-
525515
(hir_id, *c_ty)
526516
}),
527517
);
@@ -532,17 +522,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
532522
assert_eq!(fcx_typeck_results.hir_owner, self.typeck_results.hir_owner);
533523

534524
self.typeck_results.user_provided_sigs.extend_unord(
535-
fcx_typeck_results.user_provided_sigs.items().map(|(&def_id, c_sig)| {
536-
if cfg!(debug_assertions) && c_sig.has_infer() {
537-
span_bug!(
538-
self.fcx.tcx.def_span(def_id),
539-
"writeback: `{:?}` has inference variables",
540-
c_sig
541-
);
542-
};
543-
544-
(def_id, *c_sig)
545-
}),
525+
fcx_typeck_results.user_provided_sigs.items().map(|(def_id, c_sig)| (*def_id, *c_sig)),
546526
);
547527
}
548528

compiler/rustc_lint/src/types.rs

+14-21
Original file line numberDiff line numberDiff line change
@@ -755,10 +755,10 @@ declare_lint! {
755755
/// *subsequent* fields of the associated structs to use an alignment value
756756
/// where the floating-point type is aligned on a 4-byte boundary.
757757
///
758-
/// The power alignment rule for structs needed for C compatibility is
759-
/// unimplementable within `repr(C)` in the compiler without building in
760-
/// handling of references to packed fields and infectious nested layouts,
761-
/// so a warning is produced in these situations.
758+
/// Effectively, subsequent floating-point fields act as-if they are `repr(packed(4))`. This
759+
/// would be unsound to do in a `repr(C)` type without all the restrictions that come with
760+
/// `repr(packed)`. Rust instead chooses a layout that maintains soundness of Rust code, at the
761+
/// expense of incompatibility with C code.
762762
///
763763
/// ### Example
764764
///
@@ -790,8 +790,10 @@ declare_lint! {
790790
/// - offset_of!(Floats, a) == 0
791791
/// - offset_of!(Floats, b) == 8
792792
/// - offset_of!(Floats, c) == 12
793-
/// However, rust currently aligns `c` at offset_of!(Floats, c) == 16.
794-
/// Thus, a warning should be produced for the above struct in this case.
793+
///
794+
/// However, Rust currently aligns `c` at `offset_of!(Floats, c) == 16`.
795+
/// Using offset 12 would be unsound since `f64` generally must be 8-aligned on this target.
796+
/// Thus, a warning is produced for the above struct.
795797
USES_POWER_ALIGNMENT,
796798
Warn,
797799
"Structs do not follow the power alignment rule under repr(C)"
@@ -1655,15 +1657,13 @@ impl ImproperCTypesDefinitions {
16551657
cx: &LateContext<'tcx>,
16561658
ty: Ty<'tcx>,
16571659
) -> bool {
1660+
assert!(cx.tcx.sess.target.os == "aix");
16581661
// Structs (under repr(C)) follow the power alignment rule if:
16591662
// - the first field of the struct is a floating-point type that
16601663
// is greater than 4-bytes, or
16611664
// - the first field of the struct is an aggregate whose
16621665
// recursively first field is a floating-point type greater than
16631666
// 4 bytes.
1664-
if cx.tcx.sess.target.os != "aix" {
1665-
return false;
1666-
}
16671667
if ty.is_floating_point() && ty.primitive_size(cx.tcx).bytes() > 4 {
16681668
return true;
16691669
} else if let Adt(adt_def, _) = ty.kind()
@@ -1701,21 +1701,14 @@ impl ImproperCTypesDefinitions {
17011701
&& !adt_def.all_fields().next().is_none()
17021702
{
17031703
let struct_variant_data = item.expect_struct().1;
1704-
for (index, ..) in struct_variant_data.fields().iter().enumerate() {
1704+
for field_def in struct_variant_data.fields().iter().skip(1) {
17051705
// Struct fields (after the first field) are checked for the
17061706
// power alignment rule, as fields after the first are likely
17071707
// to be the fields that are misaligned.
1708-
if index != 0 {
1709-
let first_field_def = struct_variant_data.fields()[index];
1710-
let def_id = first_field_def.def_id;
1711-
let ty = cx.tcx.type_of(def_id).instantiate_identity();
1712-
if self.check_arg_for_power_alignment(cx, ty) {
1713-
cx.emit_span_lint(
1714-
USES_POWER_ALIGNMENT,
1715-
first_field_def.span,
1716-
UsesPowerAlignment,
1717-
);
1718-
}
1708+
let def_id = field_def.def_id;
1709+
let ty = cx.tcx.type_of(def_id).instantiate_identity();
1710+
if self.check_arg_for_power_alignment(cx, ty) {
1711+
cx.emit_span_lint(USES_POWER_ALIGNMENT, field_def.span, UsesPowerAlignment);
17191712
}
17201713
}
17211714
}

compiler/rustc_macros/src/query.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -407,11 +407,23 @@ pub(super) fn rustc_queries(input: TokenStream) -> TokenStream {
407407
}
408408

409409
TokenStream::from(quote! {
410+
/// Higher-order macro that invokes the specified macro with a prepared
411+
/// list of all query signatures (including modifiers).
412+
///
413+
/// This allows multiple simpler macros to each have access to the list
414+
/// of queries.
410415
#[macro_export]
411-
macro_rules! rustc_query_append {
412-
($macro:ident! $( [$($other:tt)*] )?) => {
416+
macro_rules! rustc_with_all_queries {
417+
(
418+
// The macro to invoke once, on all queries (plus extras).
419+
$macro:ident!
420+
421+
// Within [], an optional list of extra "query" signatures to
422+
// pass to the given macro, in addition to the actual queries.
423+
$( [$($extra_fake_queries:tt)*] )?
424+
) => {
413425
$macro! {
414-
$( $($other)* )?
426+
$( $($extra_fake_queries)* )?
415427
#query_stream
416428
}
417429
}

compiler/rustc_middle/src/dep_graph/dep_node.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ use crate::ty::TyCtxt;
1313

1414
macro_rules! define_dep_nodes {
1515
(
16-
$($(#[$attr:meta])*
17-
[$($modifiers:tt)*] fn $variant:ident($($K:tt)*) -> $V:ty,)*) => {
16+
$(
17+
$(#[$attr:meta])*
18+
[$($modifiers:tt)*] fn $variant:ident($($K:tt)*) -> $V:ty,
19+
)*
20+
) => {
1821

1922
#[macro_export]
2023
macro_rules! make_dep_kind_array {
@@ -83,7 +86,9 @@ macro_rules! define_dep_nodes {
8386
};
8487
}
8588

86-
rustc_query_append!(define_dep_nodes![
89+
// Create various data structures for each query, and also for a few things
90+
// that aren't queries.
91+
rustc_with_all_queries!(define_dep_nodes![
8792
/// We use this for most things when incr. comp. is turned off.
8893
[] fn Null() -> (),
8994
/// We use this to create a forever-red node.

compiler/rustc_middle/src/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2578,5 +2578,5 @@ rustc_queries! {
25782578
}
25792579
}
25802580

2581-
rustc_query_append! { define_callbacks! }
2581+
rustc_with_all_queries! { define_callbacks! }
25822582
rustc_feedable_queries! { define_feedable! }

compiler/rustc_middle/src/query/plumbing.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,11 @@ macro_rules! separate_provide_extern_default {
313313

314314
macro_rules! define_callbacks {
315315
(
316-
$($(#[$attr:meta])*
317-
[$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,)*) => {
316+
$(
317+
$(#[$attr:meta])*
318+
[$($modifiers:tt)*] fn $name:ident($($K:tt)*) -> $V:ty,
319+
)*
320+
) => {
318321

319322
#[allow(unused_lifetimes)]
320323
pub mod queries {

0 commit comments

Comments
 (0)