Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
12cde30
Add note for identifier with attempted hygiene violation
chenyukang Nov 7, 2025
5ed01e9
Switch hexagon targets to rust-lld
androm3da Nov 7, 2025
b827732
Enable std locking functions on AIX
amy-kwan Nov 7, 2025
fc20a28
Modify contributor email entries in .mailmap
hkBst Oct 28, 2025
fdced17
[bootstrap] Make `--open` option work with `doc src/tools/error_index…
GuillaumeGomez Nov 7, 2025
bd23d55
`invalid_atomic_ordering`: also lint `update` & `try_update`
GrigorenkoPV Nov 6, 2025
c07f11a
don't completely reset `HeadUsages`
lcnr Nov 7, 2025
566a86b
show packed alignment in mir_transform_unaligned_packed_ref
21aslade Oct 20, 2025
67802e0
rustc_builtin_macros: rename bench parameter to avoid collisions with…
IntegralPilot Oct 30, 2025
025ebb0
Rollup merge of #147743 - 21aslade:packed-diagnostic, r=RalfJung
matthiaskrgr Nov 8, 2025
2bc0c2e
Rollup merge of #148204 - hkBst:patch-5, r=nnethercote
matthiaskrgr Nov 8, 2025
51d5907
Rollup merge of #148279 - IntegralPilot:master, r=hkBst
matthiaskrgr Nov 8, 2025
5c04890
Rollup merge of #148601 - GrigorenkoPV:invalid_atomic_ordering, r=Kiv…
matthiaskrgr Nov 8, 2025
2121d09
Rollup merge of #148612 - chenyukang:yukang-fix-148580-macro-hygiene-…
matthiaskrgr Nov 8, 2025
9ff169d
Rollup merge of #148613 - androm3da:bcain/hex_lld, r=JonathanBrouwer,…
matthiaskrgr Nov 8, 2025
ac2fc2b
Rollup merge of #148619 - amy-kwan:amyk/AddLockingFunctions_AIX, r=wo…
matthiaskrgr Nov 8, 2025
f7e8585
Rollup merge of #148644 - GuillaumeGomez:error-index-index-open, r=Ko…
matthiaskrgr Nov 8, 2025
36af9ae
Rollup merge of #148649 - lcnr:rarwwww, r=BoxyUwU
matthiaskrgr Nov 8, 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
19 changes: 16 additions & 3 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Aaron Todd <github@opprobrio.us>
Abhishek Chanda <abhishek.becs@gmail.com> Abhishek Chanda <abhishek@cloudscaling.com>
Abhijeet Bhagat <abhijeet.bhagat@gmx.com>
Abroskin Alexander <arkweid@evilmartians.com>
Adolfo Ochagavía <aochagavia92@gmail.com>
Adolfo Ochagavía <aochagavia92@gmail.com> <github@adolfo.ochagavia.xyz>
Adrian Heine né Lang <mail@adrianheine.de>
Adrien Tétar <adri-from-59@hotmail.fr>
Ahmed Charles <ahmedcharles@gmail.com> <acharles@outlook.com>
Expand All @@ -36,6 +36,7 @@ Amanda Stjerna <mail@amandastjerna.se> <albin.stjerna@gmail.com>
Amanda Stjerna <mail@amandastjerna.se> <amanda.stjerna@it.uu.se>
Amanieu d'Antras <amanieu@gmail.com> <amanieu.dantras@huawei.com>
Amos Onn <amosonn@gmail.com>
Amos Wenger <amoswenger@gmail.com> <fasterthanlime@users.noreply.github.com>
Ana-Maria Mihalache <mihalacheana.maria@yahoo.com>
Anatoly Ikorsky <aikorsky@gmail.com>
Andre Bogus <bogusandre@gmail.com>
Expand Down Expand Up @@ -276,7 +277,8 @@ Irina Popa <irinagpopa@gmail.com>
Ivan Ivaschenko <defuz.net@gmail.com>
ivan tkachenko <me@ratijas.tk>
J. J. Weber <jjweber@gmail.com>
Jack Huey <jack.huey@umassmed.edu> <jackh726@gmail.com>
Jack Huey <jackh726@gmail.com> <jack.huey@umassmed.edu>
Jack Huey <jackh726@gmail.com> <31162821+jackh726@users.noreply.github.com>
Jacob <jacob.macritchie@gmail.com>
Jacob Hoffman-Andrews <rust@hoffman-andrews.com> <github@hoffman-andrews.com>
Jacob Greenfield <xales@naveria.com>
Expand All @@ -292,6 +294,8 @@ Jakub Adam Wieczorek <jakub.adam.wieczorek@gmail.com>
Jakub Adam Wieczorek <jakub.adam.wieczorek@gmail.com> <jakub.bukaj@yahoo.com>
Jakub Adam Wieczorek <jakub.adam.wieczorek@gmail.com> <jakub@jakub.cc>
Jakub Adam Wieczorek <jakub.adam.wieczorek@gmail.com> <jakubw@jakubw.net>
Jakub Adam Wieczorek <jakub.adam.wieczorek@gmail.com> <ja.wieczorek@student.uw.edu.pl>
Jakub Adam Wieczorek <jakub.adam.wieczorek@gmail.com> <software@jacobadam.net>
Jakub Beránek <berykubik@gmail.com> <jakub.beranek@vsb.cz>
James [Undefined] <tpzker@thepuzzlemaker.info>
James Deng <cnjamesdeng@gmail.com> <cnJamesDeng@gmail.com>
Expand All @@ -303,6 +307,7 @@ Jamie Hill-Daniel <jamie@hill-daniel.co.uk> <clubby789@gmail.com>
Jana Dönszelmann <jana@donsz.nl>
Jana Dönszelmann <jana@donsz.nl> <jonathan@donsz.nl>
Jana Dönszelmann <jana@donsz.nl> <jonabent@gmail.com>
Jane Lusby <jlusby42@gmail.com> <jlusby@yaah.dev>
Jan-Erik Rediger <janerik@fnordig.de> <badboy@archlinux.us>
Jaro Fietz <jaro.fietz@gmx.de>
Jason Fager <jfager@gmail.com>
Expand All @@ -313,6 +318,7 @@ Jason Toffaletti <toffaletti@gmail.com> Jason Toffaletti <jason@topsy.com>
Jauhien Piatlicki <jauhien@gentoo.org> Jauhien Piatlicki <jpiatlicki@zertisa.com>
Jay True <glacjay@gmail.com>
Jeremy Letang <letang.jeremy@gmail.com>
Jeremy Soller <jackpot51@gmail.com> <jeremy@system76.com>
Jeremy Sorensen <jeremy.a.sorensen@gmail.com>
Jeremy Stucki <dev@jeremystucki.ch> <stucki.jeremy@gmail.com>
Jeremy Stucki <dev@jeremystucki.ch> <jeremy@myelin.ch>
Expand All @@ -336,6 +342,7 @@ John Kåre Alsaker <john.kare.alsaker@gmail.com>
John Kåre Alsaker <john.kare.alsaker@gmail.com> <zoxc32@gmail.com>
John Talling <inrustwetrust@users.noreply.github.com>
John Van Enk <vanenkj@gmail.com>
Jon Gjengset <jon@thesquareplanet.com> <jongje@amazon.com>
Jonas Tepe <jonasprogrammer@gmail.com>
Jonathan Bailey <jbailey@mozilla.com> <jbailey@jbailey-20809.local>
Jonathan Chan Kwan Yin <sofe2038@gmail.com>
Expand Down Expand Up @@ -424,7 +431,7 @@ Malo Jaffré <jaffre.malo@gmail.com>
Manish Goregaokar <manishsmail@gmail.com>
Mara Bos <m-ou.se@m-ou.se>
Marcell Pardavi <marcell.pardavi@gmail.com>
Marco Ieni <11428655+MarcoIeni@users.noreply.github.com>
Marco Ieni <marcoieni@rustfoundation.org> <11428655+MarcoIeni@users.noreply.github.com>
Marcus Klaas de Vries <mail@marcusklaas.nl>
Margaret Meyerhofer <mmeyerho@andrew.cmu.edu> <mmeyerho@andrew>
Marijn Schouten <mhkbst@gmail.com> <hkBst@users.noreply.github.com>
Expand Down Expand Up @@ -531,6 +538,7 @@ Oliver Scherer <oli-obk@users.noreply.github.com> <oliver.schneider@kit.edu>
Oliver Scherer <oli-obk@users.noreply.github.com> <obk8176014uqher834@olio-obk.de>
Oliver Scherer <oli-obk@users.noreply.github.com> <rustc-contact@oli-obk.de>
Oliver Scherer <oli-obk@users.noreply.github.com>
Onur Özkan <onurozkan.dev@outlook.com> <contact@onurozkan.dev>
Onur Özkan <onurozkan.dev@outlook.com> <work@onurozkan.dev>
Onur Özkan <onurozkan.dev@outlook.com>
Ömer Sinan Ağacan <omeragacan@gmail.com>
Expand Down Expand Up @@ -591,6 +599,7 @@ Rusty Blitzerr <rusty.blitzerr@gmail.com>
RustyYato <krishna.sd.2012@gmail.com>
Ruud van Asseldonk <dev@veniogames.com> Ruud van Asseldonk <ruuda@google.com>
Ryan Leung <rleungx@gmail.com>
Ryan Levick <me@ryanlevick.com> <rylev@users.noreply.github.com>
Ryan Scheel <ryan.havvy@gmail.com>
Ryan Sullivant <rsulli55@gmail.com>
Ryan Wiedemann <Ryan1729@gmail.com>
Expand Down Expand Up @@ -686,6 +695,8 @@ Weihang Lo <me@weihanglo.tw>
Weihang Lo <me@weihanglo.tw> <weihanglo@users.noreply.github.com>
Wesley Wiser <wwiser@gmail.com> <wesleywiser@microsoft.com>
whitequark <whitequark@whitequark.org>
Will Crichton <crichton.will@gmail.com> <wcrichto@stanford.edu>
Will Crichton <crichton.will@gmail.com> <wcrichto@cs.stanford.edu>
William Ting <io@williamting.com> <william.h.ting@gmail.com>
Wim Looman <wim@nemo157.com> <rust-lang@nemo157.com>
Wim Looman <wim@nemo157.com> <git@nemo157.com>
Expand All @@ -695,6 +706,8 @@ Xinye Tao <xy.tao@outlook.com>
Xuefeng Wu <benewu@gmail.com> Xuefeng Wu <xfwu@thoughtworks.com>
Xuefeng Wu <benewu@gmail.com> XuefengWu <benewu@gmail.com>
York Xiang <bombless@126.com>
Yoshua Wuyts <yoshuawuyts@gmail.com> <yoshuawuyts+github@gmail.com>
Yoshua Wuyts <yoshuawuyts@gmail.com> <2467194+yoshuawuyts@users.noreply.github.com>
Yotam Ofek <yotam.ofek@gmail.com> <yotamofek@microsoft.com>
Youngsoo Son <ysson83@gmail.com> <ysoo.son@samsung.com>
Youngsuk Kim <joseph942010@gmail.com>
Expand Down
14 changes: 7 additions & 7 deletions compiler/rustc_builtin_macros/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,30 +207,30 @@ pub(crate) fn expand_test_or_bench(
};

let test_fn = if is_bench {
// A simple ident for a lambda
let b = Ident::from_str_and_span("b", attr_sp);

// avoid name collisions by using the function name within the identifier, see bug #148275
let bencher_param =
Ident::from_str_and_span(&format!("__bench_{}", fn_.ident.name), attr_sp);
cx.expr_call(
sp,
cx.expr_path(test_path("StaticBenchFn")),
thin_vec![
// #[coverage(off)]
// |b| self::test::assert_test_result(
// |__bench_fn_name| self::test::assert_test_result(
coverage_off(cx.lambda1(
sp,
cx.expr_call(
sp,
cx.expr_path(test_path("assert_test_result")),
thin_vec![
// super::$test_fn(b)
// super::$test_fn(__bench_fn_name)
cx.expr_call(
ret_ty_sp,
cx.expr_path(cx.path(sp, vec![fn_.ident])),
thin_vec![cx.expr_ident(sp, b)],
thin_vec![cx.expr_ident(sp, bencher_param)],
),
],
),
b,
bencher_param,
)), // )
],
)
Expand Down
45 changes: 25 additions & 20 deletions compiler/rustc_const_eval/src/util/alignment.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
use rustc_abi::Align;
use rustc_middle::mir::*;
use rustc_middle::ty::{self, TyCtxt};
use rustc_middle::ty::{self, AdtDef, TyCtxt};
use tracing::debug;

/// Returns `true` if this place is allowed to be less aligned
/// than its containing struct (because it is within a packed
/// struct).
pub fn is_disaligned<'tcx, L>(
/// If the place may be less aligned than its type requires
/// (because it is in a packed type), returns the AdtDef
/// and packed alignment of its most-unaligned projection.
pub fn place_unalignment<'tcx, L>(
tcx: TyCtxt<'tcx>,
local_decls: &L,
typing_env: ty::TypingEnv<'tcx>,
place: Place<'tcx>,
) -> bool
) -> Option<(AdtDef<'tcx>, Align)>
where
L: HasLocalDecls<'tcx>,
{
debug!("is_disaligned({:?})", place);
let Some(pack) = is_within_packed(tcx, local_decls, place) else {
debug!("is_disaligned({:?}) - not within packed", place);
return false;
debug!("unalignment({:?})", place);
let Some((descr, pack)) = most_packed_projection(tcx, local_decls, place) else {
debug!("unalignment({:?}) - not within packed", place);
return None;
};

let ty = place.ty(local_decls, tcx).ty;
Expand All @@ -30,31 +30,34 @@ where
|| matches!(unsized_tail().kind(), ty::Slice(..) | ty::Str)) =>
{
// If the packed alignment is greater or equal to the field alignment, the type won't be
// further disaligned.
// further unaligned.
// However we need to ensure the field is sized; for unsized fields, `layout.align` is
// just an approximation -- except when the unsized tail is a slice, where the alignment
// is fully determined by the type.
debug!(
"is_disaligned({:?}) - align = {}, packed = {}; not disaligned",
"unalignment({:?}) - align = {}, packed = {}; not unaligned",
place,
layout.align.bytes(),
pack.bytes()
);
false
None
}
_ => {
// We cannot figure out the layout. Conservatively assume that this is disaligned.
debug!("is_disaligned({:?}) - true", place);
true
// We cannot figure out the layout. Conservatively assume that this is unaligned.
debug!("unalignment({:?}) - unaligned", place);
Some((descr, pack))
}
}
}

pub fn is_within_packed<'tcx, L>(
/// If the place includes a projection from a packed struct,
/// returns the AdtDef and packed alignment of the projection
/// with the lowest pack
pub fn most_packed_projection<'tcx, L>(
tcx: TyCtxt<'tcx>,
local_decls: &L,
place: Place<'tcx>,
) -> Option<Align>
) -> Option<(AdtDef<'tcx>, Align)>
where
L: HasLocalDecls<'tcx>,
{
Expand All @@ -65,9 +68,11 @@ where
.take_while(|(_base, elem)| !matches!(elem, ProjectionElem::Deref))
// Consider the packed alignments at play here...
.filter_map(|(base, _elem)| {
base.ty(local_decls, tcx).ty.ty_adt_def().and_then(|adt| adt.repr().pack)
let adt = base.ty(local_decls, tcx).ty.ty_adt_def()?;
let pack = adt.repr().pack?;
Some((adt, pack))
})
// ... and compute their minimum.
// The overall smallest alignment is what matters.
.min()
.min_by_key(|(_, align)| *align)
}
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod check_validity_requirement;
mod compare_types;
mod type_name;

pub use self::alignment::{is_disaligned, is_within_packed};
pub use self::alignment::{most_packed_projection, place_unalignment};
pub use self::check_validity_requirement::check_validity_requirement;
pub(crate) use self::check_validity_requirement::validate_scalar_in_layout;
pub use self::compare_types::{relate_types, sub_types};
Expand Down
13 changes: 10 additions & 3 deletions compiler/rustc_lint/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,8 @@ declare_lint! {
///
/// - Passing `Ordering::Release` or `Ordering::AcqRel` as the failure
/// ordering for any of `AtomicType::compare_exchange`,
/// `AtomicType::compare_exchange_weak`, or `AtomicType::fetch_update`.
/// `AtomicType::compare_exchange_weak`, `AtomicType::update`, or
/// `AtomicType::try_update`.
INVALID_ATOMIC_ORDERING,
Deny,
"usage of invalid atomic ordering in atomic operations and memory fences"
Expand Down Expand Up @@ -1118,13 +1119,19 @@ impl InvalidAtomicOrdering {
let Some((method, args)) = Self::inherent_atomic_method_call(
cx,
expr,
&[sym::fetch_update, sym::compare_exchange, sym::compare_exchange_weak],
&[
sym::update,
sym::try_update,
sym::fetch_update,
sym::compare_exchange,
sym::compare_exchange_weak,
],
) else {
return;
};

let fail_order_arg = match method {
sym::fetch_update => &args[1],
sym::update | sym::try_update | sym::fetch_update => &args[1],
sym::compare_exchange | sym::compare_exchange_weak => &args[3],
_ => return,
};
Expand Down
7 changes: 5 additions & 2 deletions compiler/rustc_mir_transform/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@ mir_transform_tail_expr_local = {$is_generated_name ->
*[false] `{$name}` calls a custom destructor
}

mir_transform_unaligned_packed_ref = reference to packed field is unaligned
.note = packed structs are only aligned by one byte, and many modern architectures penalize unaligned field accesses
mir_transform_unaligned_packed_ref = reference to field of packed {$ty_descr} is unaligned
.note = this {$ty_descr} is {$align ->
[one] {""}
*[other] {"at most "}
}{$align}-byte aligned, but the type of this field may require higher alignment
.note_ub = creating a misaligned reference is undefined behavior (even if that reference is never dereferenced)
.help = copy the field contents to a local variable, or replace the reference with a raw pointer and use `read_unaligned`/`write_unaligned` (loads and stores via `*p` must be properly aligned even when using raw pointers)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl<'tcx> crate::MirPass<'tcx> for AddMovesForPackedDrops {

match terminator.kind {
TerminatorKind::Drop { place, .. }
if util::is_disaligned(tcx, body, typing_env, place) =>
if util::place_unalignment(tcx, body, typing_env, place).is_some() =>
{
add_move_for_packed_drop(
tcx,
Expand Down
10 changes: 8 additions & 2 deletions compiler/rustc_mir_transform/src/check_packed_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ impl<'tcx> Visitor<'tcx> for PackedRefChecker<'_, 'tcx> {
}

fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext, _location: Location) {
if context.is_borrow() && util::is_disaligned(self.tcx, self.body, self.typing_env, *place)
if context.is_borrow()
&& let Some((adt, pack)) =
util::place_unalignment(self.tcx, self.body, self.typing_env, *place)
{
let def_id = self.body.source.instance.def_id();
if let Some(impl_def_id) = self.tcx.trait_impl_of_assoc(def_id)
Expand All @@ -48,7 +50,11 @@ impl<'tcx> Visitor<'tcx> for PackedRefChecker<'_, 'tcx> {
// shouldn't do.
span_bug!(self.source_info.span, "builtin derive created an unaligned reference");
} else {
self.tcx.dcx().emit_err(errors::UnalignedPackedRef { span: self.source_info.span });
self.tcx.dcx().emit_err(errors::UnalignedPackedRef {
span: self.source_info.span,
ty_descr: adt.descr(),
align: pack.bytes(),
});
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir_transform/src/dead_store_elimination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use rustc_mir_dataflow::impls::{
};

use crate::simplify::UsedInStmtLocals;
use crate::util::is_within_packed;
use crate::util::most_packed_projection;

/// Performs the optimization on the body
///
Expand Down Expand Up @@ -65,7 +65,7 @@ fn eliminate<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) -> bool {
// the move may be codegened as a pointer to that field.
// Using that disaligned pointer may trigger UB in the callee,
// so do nothing.
&& is_within_packed(tcx, body, place).is_none()
&& most_packed_projection(tcx, body, place).is_none()
{
call_operands_to_move.push((bb, index));
}
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_mir_transform/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ pub(crate) enum ConstMutate {
pub(crate) struct UnalignedPackedRef {
#[primary_span]
pub span: Span,
pub ty_descr: &'static str,
pub align: u64,
}

#[derive(Diagnostic)]
Expand Down
10 changes: 7 additions & 3 deletions compiler/rustc_mir_transform/src/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use rustc_middle::{bug, span_bug};
use rustc_mir_dataflow::debuginfo::debuginfo_locals;
use rustc_trait_selection::traits::ObligationCtxt;

use crate::util::{self, is_within_packed};
use crate::util::{self, most_packed_projection};

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
enum EdgeKind {
Expand Down Expand Up @@ -409,7 +409,9 @@ impl<'a, 'tcx> Visitor<'tcx> for CfgChecker<'a, 'tcx> {

// The call destination place and Operand::Move place used as an argument might
// be passed by a reference to the callee. Consequently they cannot be packed.
if is_within_packed(self.tcx, &self.body.local_decls, destination).is_some() {
if most_packed_projection(self.tcx, &self.body.local_decls, destination)
.is_some()
{
// This is bad! The callee will expect the memory to be aligned.
self.fail(
location,
Expand All @@ -423,7 +425,9 @@ impl<'a, 'tcx> Visitor<'tcx> for CfgChecker<'a, 'tcx> {

for arg in args {
if let Operand::Move(place) = &arg.node {
if is_within_packed(self.tcx, &self.body.local_decls, *place).is_some() {
if most_packed_projection(self.tcx, &self.body.local_decls, *place)
.is_some()
{
// This is bad! The callee will expect the memory to be aligned.
self.fail(
location,
Expand Down
Loading
Loading