Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5eec5e3
perf(codegen): Eliminate `size_of_val == 0` for non-ZST DSTs via nuw+…
TKanX Mar 7, 2026
d7923d4
simd_add/sub/mul/neg: document overflow behavior
RalfJung Mar 10, 2026
84a2d2a
Pass -pg to linker when using -Zinstrument-mcount
pmur Feb 10, 2026
cc2c5f9
Fix mcount name for *-windows-gnu targets
pmur Mar 12, 2026
87c2552
Link extra libraries when using mcount on *-windows-gnu targets
pmur Mar 12, 2026
384f363
change "error finalizing incremental compilation" from warning to note
lambdageek Mar 13, 2026
4845f78
Reword the incremental finalize diagnostic
lambdageek Mar 17, 2026
fac53a0
add regression test for issue 153695
TaKO8Ki Mar 18, 2026
74909ec
fix ICE for arrays in diverging never-pattern closure bodies
TaKO8Ki Mar 18, 2026
0cc4946
add a test to make rustc_incremental finalize_session_directory renam…
lambdageek Mar 20, 2026
f8d658a
core: move `Alignment` from `ptr` to `mem`
GrigorenkoPV Mar 1, 2026
ba1e06a
`core::mem::Alignemnt`: rename `as_nonzero` to `as_nonzero_usize`
GrigorenkoPV Mar 1, 2026
46a9efc
Detect more cases of method shadowing with incorrect arguments
estebank Mar 9, 2026
0a5a78c
Account for inherent methods
estebank Mar 10, 2026
a72d226
Tweak output
estebank Mar 10, 2026
0bd2852
Tweak wording on "other methods available" note
estebank Mar 25, 2026
b5605cd
move many tests out of `ui/unsafe`
cyrgani Mar 26, 2026
5efde4b
Create GPU target notification group
apiraino Mar 26, 2026
75bcc86
Rollup merge of #152843 - TKanX:bugfix/152788-codegen-dst-size-nuw-as…
JonathanBrouwer Mar 26, 2026
63220ce
Rollup merge of #154004 - GrigorenkoPV:alignment/as_nonzero_usize, r=…
JonathanBrouwer Mar 26, 2026
ba7e290
Rollup merge of #152457 - pmur:murp/mcount-link-pg, r=davidtwco
JonathanBrouwer Mar 26, 2026
6f0b82e
Rollup merge of #154031 - TaKO8Ki:fix-153695-never-pattern-array-ice,…
JonathanBrouwer Mar 26, 2026
18a088a
Rollup merge of #154418 - cyrgani:move-unsafe, r=chenyukang
JonathanBrouwer Mar 26, 2026
7e25d62
Rollup merge of #153662 - estebank:suggest-fully-qualified-path, r=da…
JonathanBrouwer Mar 26, 2026
115af01
Rollup merge of #153675 - RalfJung:simd-overflow, r=scottmcm
JonathanBrouwer Mar 26, 2026
3aeaf0f
Rollup merge of #154110 - lambdageek:fix/incr-compile-note, r=wesleyw…
JonathanBrouwer Mar 26, 2026
0a50bb0
Rollup merge of #154430 - apiraino:create-gpu-target-notif-group, r=j…
JonathanBrouwer Mar 26, 2026
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
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/global_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl AllocFnFactory<'_, '_> {
}

fn ptr_alignment(&self) -> Box<Ty> {
let path = self.cx.std_path(&[sym::ptr, sym::Alignment]);
let path = self.cx.std_path(&[sym::mem, sym::Alignment]);
let path = self.cx.path(self.span, path);
self.cx.ty_path(path)
}
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2767,6 +2767,10 @@ fn add_order_independent_options(
cmd.pgo_gen();
}

if sess.opts.unstable_opts.instrument_mcount {
cmd.enable_profiling();
}

if sess.opts.cg.control_flow_guard != CFGuard::Disabled {
cmd.control_flow_guard();
}
Expand Down
14 changes: 14 additions & 0 deletions compiler/rustc_codegen_ssa/src/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ pub(crate) trait Linker {
fn add_no_exec(&mut self) {}
fn add_as_needed(&mut self) {}
fn reset_per_library_state(&mut self) {}
fn enable_profiling(&mut self) {}
}

impl dyn Linker + '_ {
Expand Down Expand Up @@ -732,6 +733,19 @@ impl<'a> Linker for GccLinker<'a> {
self.link_or_cc_args(&["-u", "__llvm_profile_runtime"]);
}

fn enable_profiling(&mut self) {
// This flag is also used when linking to choose target specific
// libraries needed to enable profiling.
self.cc_arg("-pg");
// On windows-gnu targets, libgmon also needs to be linked, and this
// requires readding libraries to satisfy its dependencies.
if self.sess.target.is_like_windows {
self.cc_arg("-lgmon");
self.cc_arg("-lkernel32");
self.cc_arg("-lmsvcrt");
}
}

fn control_flow_guard(&mut self) {}

fn ehcont_guard(&mut self) {}
Expand Down
10 changes: 8 additions & 2 deletions compiler/rustc_codegen_ssa/src/size_of_val.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ pub fn size_and_align_of_dst<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
// Furthermore, `align >= unsized_align`, and therefore we only need to do:
// let full_size = (unsized_offset_unadjusted + unsized_size).align_to(full_align);

let full_size = bx.add(unsized_offset_unadjusted, unsized_size);
// total <= isize::MAX, so nuw+nsw.
let unrounded_size = bx.unchecked_suadd(unsized_offset_unadjusted, unsized_size);

// Issue #27023: must add any necessary padding to `size`
// (to make it a multiple of `align`) before returning it.
Expand All @@ -173,10 +174,15 @@ pub fn size_and_align_of_dst<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
// `(size + (align-1)) & -align`
let one = bx.const_usize(1);
let addend = bx.sub(full_align, one);
let add = bx.add(full_size, addend);
let add = bx.add(unrounded_size, addend);
let neg = bx.neg(full_align);
let full_size = bx.and(add, neg);

// round_up(x, a) >= x for pow2 a; with nuw above LLVM deduces
// full_size >= unrounded_size >= offset > 0 (#152788).
let size_ge = bx.icmp(IntPredicate::IntUGE, full_size, unrounded_size);
bx.assume(size_ge);

(full_size, full_align)
}
_ => bug!("size_and_align_of_dst: {t} not supported"),
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_data_structures/src/aligned.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::marker::PointeeSized;
#[cfg(not(bootstrap))]
use std::mem::Alignment;
#[cfg(bootstrap)]
use std::ptr::Alignment;

/// Returns the ABI-required minimum alignment of a type in bytes.
Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_data_structures/src/tagged_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ pub unsafe trait Tag: Copy {
/// Returns the number of bits available for use for tags in a pointer to `T`
/// (this is based on `T`'s alignment).
pub const fn bits_for<T: ?Sized + Aligned>() -> u32 {
crate::aligned::align_of::<T>().as_nonzero().trailing_zeros()
let alignment = crate::aligned::align_of::<T>();
#[cfg(bootstrap)]
let alignment = alignment.as_nonzero();
#[cfg(not(bootstrap))]
let alignment = alignment.as_nonzero_usize();
alignment.trailing_zeros()
}

/// Returns the correct [`Tag::BITS`] constant for a set of tag values.
Expand Down
102 changes: 65 additions & 37 deletions compiler/rustc_hir_typeck/src/demand.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustc_errors::{Applicability, Diag, MultiSpan, listify};
use rustc_hir::def::Res;
use rustc_errors::{Applicability, Diag, MultiSpan, listify, pluralize};
use rustc_hir::def::{DefKind, Res};
use rustc_hir::intravisit::Visitor;
use rustc_hir::{self as hir, find_attr};
use rustc_infer::infer::DefineOpaqueTypes;
Expand Down Expand Up @@ -29,7 +29,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if expr_ty == expected {
return;
}
self.annotate_alternative_method_deref(err, expr, error);
self.annotate_alternative_method_deref_for_unop(err, expr, error);
self.explain_self_literal(err, expr, expected, expr_ty);

// Use `||` to give these suggestions a precedence
Expand Down Expand Up @@ -723,8 +723,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
hir::Path {
res:
hir::def::Res::Def(
hir::def::DefKind::Static { .. }
| hir::def::DefKind::Const { .. },
DefKind::Static { .. } | DefKind::Const { .. },
def_id,
),
..
Expand Down Expand Up @@ -899,7 +898,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
false
}

fn annotate_alternative_method_deref(
fn annotate_alternative_method_deref_for_unop(
&self,
err: &mut Diag<'_>,
expr: &hir::Expr<'_>,
Expand All @@ -919,7 +918,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let hir::ExprKind::Unary(hir::UnOp::Deref, deref) = lhs.kind else {
return;
};
let hir::ExprKind::MethodCall(path, base, args, _) = deref.kind else {
self.annotate_alternative_method_deref(err, deref, Some(expected))
}

#[tracing::instrument(skip(self, err), level = "debug")]
pub(crate) fn annotate_alternative_method_deref(
&self,
err: &mut Diag<'_>,
expr: &hir::Expr<'_>,
expected: Option<Ty<'tcx>>,
) {
let hir::ExprKind::MethodCall(path, base, args, _) = expr.kind else {
return;
};
let Some(self_ty) = self.typeck_results.borrow().expr_ty_adjusted_opt(base) else {
Expand All @@ -929,7 +938,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let Ok(pick) = self.lookup_probe_for_diagnostic(
path.ident,
self_ty,
deref,
expr,
probe::ProbeScope::TraitsInScope,
None,
) else {
Expand All @@ -939,10 +948,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let Ok(in_scope_methods) = self.probe_for_name_many(
probe::Mode::MethodCall,
path.ident,
Some(expected),
expected,
probe::IsSuggestion(true),
self_ty,
deref.hir_id,
expr.hir_id,
probe::ProbeScope::TraitsInScope,
) else {
return;
Expand All @@ -954,45 +963,62 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let Ok(all_methods) = self.probe_for_name_many(
probe::Mode::MethodCall,
path.ident,
Some(expected),
expected,
probe::IsSuggestion(true),
self_ty,
deref.hir_id,
expr.hir_id,
probe::ProbeScope::AllTraits,
) else {
return;
};

let suggestions: Vec<_> = all_methods
.into_iter()
.filter(|c| c.item.def_id != pick.item.def_id)
.map(|c| {
.filter_map(|c| {
if c.item.def_id == pick.item.def_id {
return None;
}
let m = c.item;
let generic_args = ty::GenericArgs::for_item(self.tcx, m.def_id, |param, _| {
self.var_for_def(deref.span, param)
self.var_for_def(expr.span, param)
});
let mutability =
match self.tcx.fn_sig(m.def_id).skip_binder().input(0).skip_binder().kind() {
ty::Ref(_, _, hir::Mutability::Mut) => "&mut ",
ty::Ref(_, _, _) => "&",
_ => "",
};
vec![
(
deref.span.until(base.span),
format!(
"{}({}",
with_no_trimmed_paths!(
self.tcx.def_path_str_with_args(m.def_id, generic_args,)
),
mutability,
),
),
let fn_sig = self.tcx.fn_sig(m.def_id);
if fn_sig.skip_binder().inputs().skip_binder().len() != args.len() + 1 {
return None;
}
let rcvr_ty = fn_sig.skip_binder().input(0).skip_binder();
let (mutability, ty) = match rcvr_ty.kind() {
ty::Ref(_, ty, hir::Mutability::Mut) => ("&mut ", ty),
ty::Ref(_, ty, _) => ("&", ty),
_ => ("", &rcvr_ty),
};
let path = match self.tcx.assoc_parent(m.def_id) {
Some((_, DefKind::Impl { of_trait: true })) => {
// We have `impl Trait for T {}`, suggest `<T as Trait>::method`.
self.tcx.def_path_str_with_args(m.def_id, generic_args).to_string()
}
Some((_, DefKind::Impl { of_trait: false })) => {
if let ty::Adt(def, _) = ty.kind() {
// We have `impl T {}`, suggest `T::method`.
format!("{}::{}", self.tcx.def_path_str(def.did()), path.ident)
} else {
// This should be unreachable, as `impl &'a T {}` is invalid.
format!("{ty}::{}", path.ident)
}
}
// Fallback for arbitrary self types.
_ => with_no_trimmed_paths!(
self.tcx.def_path_str_with_args(m.def_id, generic_args)
)
.to_string(),
};
Some(vec![
(expr.span.until(base.span), format!("{path}({}", mutability)),
match &args {
[] => (base.span.shrink_to_hi().with_hi(deref.span.hi()), ")".to_string()),
[] => (base.span.shrink_to_hi().with_hi(expr.span.hi()), ")".to_string()),
[first, ..] => (base.span.between(first.span), ", ".to_string()),
},
]
])
})
.collect();
if suggestions.is_empty() {
Expand Down Expand Up @@ -1046,9 +1072,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
),
);
if suggestions.len() > other_methods_in_scope.len() {
let n = suggestions.len() - other_methods_in_scope.len();
err.note(format!(
"additionally, there are {} other available methods that aren't in scope",
suggestions.len() - other_methods_in_scope.len()
"additionally, there {are} {n} other available method{s} that {are}n't in scope",
are = pluralize!("is", n),
s = pluralize!(n),
));
}
err.multipart_suggestions(
Expand Down Expand Up @@ -1263,7 +1291,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let hir::def::Res::Def(kind, def_id) = path.res else {
return;
};
let callable_kind = if matches!(kind, hir::def::DefKind::Ctor(_, _)) {
let callable_kind = if matches!(kind, DefKind::Ctor(_, _)) {
CallableKind::Constructor
} else {
CallableKind::Function
Expand Down
8 changes: 0 additions & 8 deletions compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1660,14 +1660,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expr: &'tcx hir::Expr<'tcx>,
) -> Ty<'tcx> {
let element_ty = if !args.is_empty() {
// This shouldn't happen unless there's another error
// (e.g., never patterns in inappropriate contexts).
if self.diverges.get() != Diverges::Maybe {
self.dcx()
.struct_span_err(expr.span, "unexpected divergence state in checking array")
.delay_as_bug();
}

let coerce_to = expected
.to_option(self)
.and_then(|uty| {
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2853,6 +2853,8 @@ impl<'a, 'b, 'tcx> ArgMatchingCtxt<'a, 'b, 'tcx> {
);
return;
}

self.annotate_alternative_method_deref(err, self.call_expr, None);
}

/// A "softer" version of the `demand_compatible`, which checks types without persisting them,
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_incremental/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ pub(crate) struct DeleteFull<'a> {
}

#[derive(Diagnostic)]
#[diag("error finalizing incremental compilation session directory `{$path}`: {$err}")]
#[diag("did not finalize incremental compilation session directory `{$path}`: {$err}")]
#[help("the next build will not be able to reuse work from this compilation")]
pub(crate) struct Finalize<'a> {
pub path: &'a Path,
pub err: std::io::Error,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_incremental/src/persist/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ pub fn finalize_session_directory(sess: &Session, svh: Option<Svh>) {
}
Err(e) => {
// Warn about the error. However, no need to abort compilation now.
sess.dcx().emit_warn(errors::Finalize { path: &incr_comp_session_dir, err: e });
sess.dcx().emit_note(errors::Finalize { path: &incr_comp_session_dir, err: e });

debug!("finalize_session_directory() - error, marking as invalid");
// Drop the file lock, so we can garage collect
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_middle/src/ty/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,10 @@ unsafe impl<H: DynSync, T: DynSync> DynSync for RawList<H, T> {}
// Layouts of `ListSkeleton<H, T>` and `RawList<H, T>` are the same, modulo opaque tail,
// thus aligns of `ListSkeleton<H, T>` and `RawList<H, T>` must be the same.
unsafe impl<H, T> Aligned for RawList<H, T> {
#[cfg(bootstrap)]
const ALIGN: ptr::Alignment = align_of::<ListSkeleton<H, T>>();
#[cfg(not(bootstrap))]
const ALIGN: mem::Alignment = align_of::<ListSkeleton<H, T>>();
}

/// A [`List`] that additionally stores type information inline to speed up
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,7 @@ symbols! {
maybe_uninit,
maybe_uninit_uninit,
maybe_uninit_zeroed,
mem,
mem_align_const,
mem_discriminant,
mem_drop,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/base/windows_gnu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ pub(crate) fn opts() -> TargetOptions {
// FIXME(davidtwco): Support Split DWARF on Windows GNU - may require LLVM changes to
// output DWO, despite using DWARF, doesn't use ELF..
supported_split_debuginfo: Cow::Borrowed(&[SplitDebuginfo::Off]),
mcount: "_mcount".into(),
..Default::default()
}
}
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/base/windows_gnullvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub(crate) fn opts() -> TargetOptions {
// FIXME(davidtwco): Support Split DWARF on Windows GNU - may require LLVM changes to
// output DWO, despite using DWARF, doesn't use ELF..
supported_split_debuginfo: Cow::Borrowed(&[SplitDebuginfo::Off]),
mcount: "_mcount".into(),
..Default::default()
}
}
3 changes: 2 additions & 1 deletion library/alloc/src/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#[stable(feature = "alloc_module", since = "1.28.0")]
#[doc(inline)]
pub use core::alloc::*;
use core::ptr::{self, Alignment, NonNull};
use core::mem::Alignment;
use core::ptr::{self, NonNull};
use core::{cmp, hint};

unsafe extern "Rust" {
Expand Down
6 changes: 3 additions & 3 deletions library/alloc/src/raw_vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// run the tests. See the comment there for an explanation why this is the case.

use core::marker::{Destruct, PhantomData};
use core::mem::{ManuallyDrop, MaybeUninit, SizedTypeProperties};
use core::ptr::{self, Alignment, NonNull, Unique};
use core::mem::{Alignment, ManuallyDrop, MaybeUninit, SizedTypeProperties};
use core::ptr::{self, NonNull, Unique};
use core::{cmp, hint};

#[cfg(not(no_global_oom_handling))]
Expand Down Expand Up @@ -570,7 +570,7 @@ const impl<A: [const] Allocator + [const] Destruct> RawVecInner<A> {
impl<A: Allocator> RawVecInner<A> {
#[inline]
const fn new_in(alloc: A, align: Alignment) -> Self {
let ptr = Unique::from_non_null(NonNull::without_provenance(align.as_nonzero()));
let ptr = Unique::from_non_null(NonNull::without_provenance(align.as_nonzero_usize()));
// `cap: 0` means "unallocated". zero-sized types are ignored.
Self { ptr, cap: ZERO_CAP, alloc }
}
Expand Down
Loading
Loading