Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
180e599
use correct typing mode in mir building for the next solver
adwinwhite Jun 27, 2026
1316aa8
Instatiate binder instead of skipping when suggesting functiom arg error
ShoyuVanilla Jun 29, 2026
c61c52f
detect cycles during valtree construction for self-referential consts
sjwang05 Jul 3, 2026
74fa6b9
chore: add regression test for late-bound type method probe ICE
amirHdev Jul 5, 2026
1a98242
Distinguish null reference production from null pointer dereference
raushan728 Jul 5, 2026
dabab4f
move batch
zedddie Jul 5, 2026
082ff2f
bless batch
zedddie Jul 5, 2026
a99be5a
update perf
jdonszelmann Jul 6, 2026
a6bd564
allow new licenses for rustc_perf
jdonszelmann Jun 22, 2026
4011441
Delete `impl_def_id` field from `ImplHeader`
theemathas Jul 6, 2026
2740e11
Create simple non ICE-ing path for new trait solver
Jamesbarford Jul 6, 2026
84aa27d
Tests for `find_auto_trait_generics_next_solver` path
Jamesbarford Jul 6, 2026
35cbff9
rewrite `Align::max_for_target` in a more obvious way
WaffleLapkin Jul 6, 2026
690ae7d
borrowck: Inline free_region_constraint_info() to simplify the code
Enselic Jun 30, 2026
81a18e7
document blocking guarantees for `std::sync`
cyexclam Jul 2, 2026
1b75a0a
Update mdbook to 0.5.4
ehuss Jul 6, 2026
61ff1d7
Rollup merge of #158478 - adwinwhite:rigid-alias-ice, r=lcnr
jhpratt Jul 7, 2026
91fc16b
Rollup merge of #158796 - raushan728:issues/154044, r=saethlin
jhpratt Jul 7, 2026
57c4b97
Rollup merge of #158821 - amirHdev:add-test-non-lifetime-binders-ice,…
jhpratt Jul 7, 2026
96b5fba
Rollup merge of #158245 - jdonszelmann:update-rustc-perf, r=Kobzol
jhpratt Jul 7, 2026
1c4fe1a
Rollup merge of #158346 - Jamesbarford:fix/auto-trait-impl, r=lcnr
jhpratt Jul 7, 2026
2653bfb
Rollup merge of #158536 - ShoyuVanilla:issue-158317, r=lcnr
jhpratt Jul 7, 2026
ce811cd
Rollup merge of #158553 - sjwang05:issue-144719, r=oli-obk
jhpratt Jul 7, 2026
f2b7994
Rollup merge of #158679 - cyexclam:sync-document-blocking-guarantees,…
jhpratt Jul 7, 2026
41eeb9b
Rollup merge of #158826 - zedddie:gsoc-batch-19-meow, r=Teapot4195
jhpratt Jul 7, 2026
d15fee0
Rollup merge of #158860 - theemathas:del-impl-header-field, r=nnether…
jhpratt Jul 7, 2026
e546c54
Rollup merge of #158867 - WaffleLapkin:driveby, r=scottmcm
jhpratt Jul 7, 2026
86de60d
Rollup merge of #158878 - Enselic:inline-free_region_constraint_info,…
jhpratt Jul 7, 2026
6673d7d
Rollup merge of #158881 - ehuss:update-mdbook, r=Mark-Simulacrum
jhpratt Jul 7, 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
11 changes: 3 additions & 8 deletions compiler/rustc_abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ even other Rust compilers, such as rust-analyzer!

*/

use std::cmp::min;
use std::fmt;
#[cfg(feature = "nightly")]
use std::iter::Step;
Expand Down Expand Up @@ -1060,14 +1061,8 @@ impl Align {
/// Either `1 << (pointer_bits - 1)` or [`Align::MAX`], whichever is smaller.
#[inline]
pub fn max_for_target(tdl: &TargetDataLayout) -> Align {
let pointer_bits = tdl.pointer_size().bits();
if let Ok(pointer_bits) = u8::try_from(pointer_bits)
&& pointer_bits <= Align::MAX.pow2
{
Align { pow2: pointer_bits - 1 }
} else {
Align::MAX
}
let pointer_bits = u8::try_from(tdl.pointer_size().bits()).unwrap();
min(Align { pow2: pointer_bits - 1 }, Align::MAX)
}

#[inline]
Expand Down
31 changes: 9 additions & 22 deletions compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rustc_middle::mir::{
Operand, Place, Rvalue, Statement, StatementKind, TerminatorKind,
};
use rustc_middle::ty::adjustment::PointerCoercion;
use rustc_middle::ty::{self, RegionVid, Ty, TyCtxt};
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_span::{DesugaringKind, Span, kw, sym};
use rustc_trait_selection::error_reporting::traits::FindExprBySpan;
use rustc_trait_selection::error_reporting::traits::call_kind::CallKind;
Expand Down Expand Up @@ -574,24 +574,6 @@ fn suggest_rewrite_if_let<G: EmissionGuarantee>(
}

impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
fn free_region_constraint_info(
&self,
borrow_region: RegionVid,
outlived_region: RegionVid,
) -> (ConstraintCategory<'tcx>, bool, Span, Option<RegionName>, Vec<OutlivesConstraint<'tcx>>)
{
let (blame_constraint, path) = self.regioncx.best_blame_constraint(
borrow_region,
NllRegionVariableOrigin::FreeRegion,
outlived_region,
);
let BlameConstraint { category, from_closure, span, .. } = blame_constraint;

let outlived_fr_name = self.give_region_a_name(outlived_region);

(category, from_closure, span, outlived_fr_name, path)
}

/// Returns structured explanation for *why* the borrow contains the
/// point from `location`. This is key for the "3-point errors"
/// [described in the NLL RFC][d].
Expand Down Expand Up @@ -707,9 +689,14 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
// Here, under NLL: no cause was found. Under polonius: no cause was found, or a
// boring local was found, which we ignore like NLLs do to match its diagnostics.
if let Some(region) = self.regioncx.to_error_region_vid(borrow_region_vid) {
let (category, from_closure, span, region_name, path) =
self.free_region_constraint_info(borrow_region_vid, region);
if let Some(region_name) = region_name {
let (blame_constraint, path) = self.regioncx.best_blame_constraint(
borrow_region_vid,
NllRegionVariableOrigin::FreeRegion,
region,
);
let BlameConstraint { category, from_closure, span, .. } = blame_constraint;

if let Some(region_name) = self.give_region_a_name(region) {
let opt_place_desc = self.describe_place(borrow.borrowed_place.as_ref());
BorrowExplanation::MustBeValidFor {
category,
Expand Down
11 changes: 11 additions & 0 deletions compiler/rustc_codegen_cranelift/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,17 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
source_info.span,
)
}
AssertKind::NullReferenceConstructed => {
let location = fx.get_caller_location(source_info).load_scalar(fx);

codegen_panic_inner(
fx,
rustc_hir::LangItem::PanicNullReferenceConstructed,
&[location],
*unwind,
source_info.span,
)
}
AssertKind::InvalidEnumConstruction(source) => {
let source = codegen_operand(fx, source).load_scalar(fx);
let location = fx.get_caller_location(source_info).load_scalar(fx);
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_codegen_ssa/src/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
// `#[track_caller]` adds an implicit argument.
(LangItem::PanicNullPointerDereference, vec![location])
}
AssertKind::NullReferenceConstructed => {
// It's `fn panic_null_reference_constructed()`,
// `#[track_caller]` adds an implicit argument.
(LangItem::PanicNullReferenceConstructed, vec![location])
}
AssertKind::InvalidEnumConstruction(source) => {
let source = self.codegen_operand(bx, source).immediate();
// It's `fn panic_invalid_enum_construction(source: u128)`,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_const_eval/src/const_eval/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,7 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
found: eval_to_int(found)?,
},
NullPointerDereference => NullPointerDereference,
NullReferenceConstructed => NullReferenceConstructed,
InvalidEnumConstruction(source) => InvalidEnumConstruction(eval_to_int(source)?),
};
Err(ConstEvalErrKind::AssertFailure(err)).into()
Expand Down
91 changes: 60 additions & 31 deletions compiler/rustc_const_eval/src/const_eval/valtrees.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use rustc_abi::{BackendRepr, FieldIdx, VariantIdx};
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::stack::ensure_sufficient_stack;
use rustc_middle::mir::interpret::{EvalToValTreeResult, GlobalId, ValTreeCreationError};
use rustc_middle::traits::ObligationCause;
Expand All @@ -17,13 +18,15 @@ use crate::interpret::{
intern_const_alloc_recursive,
};

#[instrument(skip(ecx), level = "debug")]
#[instrument(skip(ecx, visited, settled), level = "debug")]
fn branches<'tcx>(
ecx: &CompileTimeInterpCx<'tcx>,
place: &MPlaceTy<'tcx>,
field_count: usize,
variant: Option<VariantIdx>,
num_nodes: &mut usize,
visited: &mut FxHashSet<MPlaceTy<'tcx>>,
settled: &mut FxHashMap<MPlaceTy<'tcx>, EvalToValTreeResult<'tcx>>,
) -> EvalToValTreeResult<'tcx> {
let place = match variant {
Some(variant) => ecx.project_downcast(place, variant).unwrap(),
Expand All @@ -45,7 +48,7 @@ fn branches<'tcx>(

for i in 0..field_count {
let field = ecx.project_field(&place, FieldIdx::from_usize(i)).unwrap();
let valtree = const_to_valtree_inner(ecx, &field, num_nodes)?;
let valtree = const_to_valtree_inner(ecx, &field, num_nodes, visited, settled)?;
branches.push(ty::Const::new_value(*ecx.tcx, valtree, field.layout.ty));
}

Expand All @@ -57,39 +60,53 @@ fn branches<'tcx>(
Ok(ty::ValTree::from_branches(*ecx.tcx, branches))
}

#[instrument(skip(ecx), level = "debug")]
#[instrument(skip(ecx, visited, settled), level = "debug")]
fn slice_branches<'tcx>(
ecx: &CompileTimeInterpCx<'tcx>,
place: &MPlaceTy<'tcx>,
num_nodes: &mut usize,
visited: &mut FxHashSet<MPlaceTy<'tcx>>,
settled: &mut FxHashMap<MPlaceTy<'tcx>, EvalToValTreeResult<'tcx>>,
) -> EvalToValTreeResult<'tcx> {
let n = place.len(ecx).unwrap_or_else(|_| panic!("expected to use len of place {place:?}"));

let mut elems = Vec::with_capacity(n as usize);
for i in 0..n {
let place_elem = ecx.project_index(place, i).unwrap();
let valtree = const_to_valtree_inner(ecx, &place_elem, num_nodes)?;
let valtree = const_to_valtree_inner(ecx, &place_elem, num_nodes, visited, settled)?;
elems.push(ty::Const::new_value(*ecx.tcx, valtree, place_elem.layout.ty));
}

Ok(ty::ValTree::from_branches(*ecx.tcx, elems))
}

#[instrument(skip(ecx), level = "debug")]
#[instrument(skip(ecx, visited, settled), level = "debug")]
fn const_to_valtree_inner<'tcx>(
ecx: &CompileTimeInterpCx<'tcx>,
place: &MPlaceTy<'tcx>,
num_nodes: &mut usize,
visited: &mut FxHashSet<MPlaceTy<'tcx>>,
settled: &mut FxHashMap<MPlaceTy<'tcx>, EvalToValTreeResult<'tcx>>,
) -> EvalToValTreeResult<'tcx> {
let tcx = *ecx.tcx;
let ty = place.layout.ty;
debug!("ty kind: {:?}", ty.kind());

if let Some(&result) = settled.get(place) {
return result;
}

if visited.contains(place) {
return Err(ValTreeCreationError::CyclicConst);
}

if *num_nodes >= VALTREE_MAX_NODES {
return Err(ValTreeCreationError::NodesOverflow);
}

match ty.kind() {
visited.insert(place.clone());

let result = ensure_sufficient_stack(|| match ty.kind() {
ty::FnDef(..) => {
*num_nodes += 1;
Ok(ty::ValTree::zst(tcx))
Expand All @@ -108,7 +125,7 @@ fn const_to_valtree_inner<'tcx>(
// Since the returned valtree does not contain the type or layout, we can just
// switch to the base type.
place.layout = ecx.layout_of(*base).unwrap();
ensure_sufficient_stack(|| const_to_valtree_inner(ecx, &place, num_nodes))
const_to_valtree_inner(ecx, &place, num_nodes, visited, settled)
}

ty::RawPtr(_, _) => {
Expand All @@ -120,16 +137,16 @@ fn const_to_valtree_inner<'tcx>(
// We could allow wide raw pointers where both sides are integers in the future,
// but for now we reject them.
if matches!(val.layout.backend_repr, BackendRepr::ScalarPair(..)) {
return Err(ValTreeCreationError::NonSupportedType(ty));
Err(ValTreeCreationError::NonSupportedType(ty))
} else {
let val = val.to_scalar();
// We are in the CTFE machine, so ptr-to-int casts will fail.
// This can only be `Ok` if `val` already is an integer.
match val.try_to_scalar_int() {
Ok(val) => Ok(ty::ValTree::from_scalar_int(tcx, val)),
Err(_) => Err(ValTreeCreationError::NonSupportedType(ty)),
}
}
let val = val.to_scalar();
// We are in the CTFE machine, so ptr-to-int casts will fail.
// This can only be `Ok` if `val` already is an integer.
let Ok(val) = val.try_to_scalar_int() else {
return Err(ValTreeCreationError::NonSupportedType(ty));
};
// It's just a ScalarInt!
Ok(ty::ValTree::from_scalar_int(tcx, val))
}

// Technically we could allow function pointers (represented as `ty::Instance`), but this is not guaranteed to
Expand All @@ -138,33 +155,39 @@ fn const_to_valtree_inner<'tcx>(

ty::Ref(_, _, _) => {
let derefd_place = ecx.deref_pointer(place).report_err()?;
const_to_valtree_inner(ecx, &derefd_place, num_nodes)
const_to_valtree_inner(ecx, &derefd_place, num_nodes, visited, settled)
}

ty::Str | ty::Slice(_) | ty::Array(_, _) => slice_branches(ecx, place, num_nodes),
ty::Str | ty::Slice(_) | ty::Array(_, _) => {
slice_branches(ecx, place, num_nodes, visited, settled)
}
// Trait objects are not allowed in type level constants, as we have no concept for
// resolving their backing type, even if we can do that at const eval time. We may
// hypothetically be able to allow `dyn StructuralPartialEq` trait objects in the future,
// but it is unclear if this is useful.
ty::Dynamic(..) => Err(ValTreeCreationError::NonSupportedType(ty)),

ty::Tuple(elem_tys) => branches(ecx, place, elem_tys.len(), None, num_nodes),
ty::Tuple(elem_tys) => {
branches(ecx, place, elem_tys.len(), None, num_nodes, visited, settled)
}

ty::Adt(def, _) => {
if def.is_union() {
return Err(ValTreeCreationError::NonSupportedType(ty));
Err(ValTreeCreationError::NonSupportedType(ty))
} else if def.variants().is_empty() {
bug!("uninhabited types should have errored and never gotten converted to valtree")
} else {
let variant = ecx.read_discriminant(place).report_err()?;
branches(
ecx,
place,
def.variant(variant).fields.len(),
def.is_enum().then_some(variant),
num_nodes,
visited,
settled,
)
}

let variant = ecx.read_discriminant(place).report_err()?;
branches(
ecx,
place,
def.variant(variant).fields.len(),
def.is_enum().then_some(variant),
num_nodes,
)
}

// FIXME(oli-obk): we could look behind opaque types
Expand All @@ -186,7 +209,11 @@ fn const_to_valtree_inner<'tcx>(
| ty::Coroutine(..)
| ty::CoroutineWitness(..)
| ty::UnsafeBinder(_) => Err(ValTreeCreationError::NonSupportedType(ty)),
}
});

visited.remove(place);
settled.insert(place.clone(), result);
result
}

/// Valtrees don't store the `MemPlaceMeta` that all dynamically sized values have in the interpreter.
Expand Down Expand Up @@ -257,7 +284,9 @@ pub(crate) fn eval_to_valtree<'tcx>(
debug!(?place);

let mut num_nodes = 0;
const_to_valtree_inner(&ecx, &place, &mut num_nodes)
let mut visited = FxHashSet::default();
let mut settled = FxHashMap::default();
const_to_valtree_inner(&ecx, &place, &mut num_nodes, &mut visited, &mut settled)
}

/// Converts a `ValTree` to a `ConstValue`, which is needed after mir
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir/src/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ language_item_table! {
PanicAsyncGenFnResumedPanic, sym::panic_const_async_gen_fn_resumed_panic, panic_const_async_gen_fn_resumed_panic, Target::Fn, GenericRequirement::None;
PanicGenFnNonePanic, sym::panic_const_gen_fn_none_panic, panic_const_gen_fn_none_panic, Target::Fn, GenericRequirement::None;
PanicNullPointerDereference, sym::panic_null_pointer_dereference, panic_null_pointer_dereference, Target::Fn, GenericRequirement::None;
PanicNullReferenceConstructed, sym::panic_null_reference_constructed, panic_null_reference_constructed, Target::Fn, GenericRequirement::None;
PanicInvalidEnumConstruction, sym::panic_invalid_enum_construction, panic_invalid_enum_construction, Target::Fn, GenericRequirement::None;
PanicCoroutineResumedDrop, sym::panic_const_coroutine_resumed_drop, panic_const_coroutine_resumed_drop, Target::Fn, GenericRequirement::None;
PanicAsyncFnResumedDrop, sym::panic_const_async_fn_resumed_drop, panic_const_async_fn_resumed_drop, Target::Fn, GenericRequirement::None;
Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_middle/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ pub(crate) struct InvalidConstInValtree {
pub global_const_id: String,
}

#[derive(Diagnostic)]
#[diag("constant {$global_const_id} cannot be used as pattern")]
#[note("constants whose type references itself cannot be used as patterns")]
pub(crate) struct CyclicConstInValtree {
#[primary_span]
pub span: Span,
pub global_const_id: String,
}

#[derive(Diagnostic)]
#[diag("internal compiler error: reentrant incremental verify failure, suppressing message")]
pub(crate) struct Reentrant;
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_middle/src/mir/interpret/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ pub enum ValTreeCreationError<'tcx> {
InvalidConst,
/// Values of this type, or this particular value, are not supported as valtrees.
NonSupportedType(Ty<'tcx>),
/// Trying to valtree this constant would cause the valtree to have cycles.
CyclicConst,
/// The error has already been handled by const evaluation.
ErrorHandled(ErrorHandled),
}
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_middle/src/mir/interpret/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,13 @@ impl<'tcx> TyCtxt<'tcx> {
});
Err(ReportedErrorInfo::allowed_in_infallible(handled).into())
}
ValTreeCreationError::CyclicConst => {
let handled = self.dcx().emit_err(error::CyclicConstInValtree {
span,
global_const_id: cid.display(self),
});
Err(ReportedErrorInfo::allowed_in_infallible(handled).into())
}
ValTreeCreationError::ErrorHandled(handled) => Err(handled),
}
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/mir/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,7 @@ pub enum AssertKind<O> {
ResumedAfterDrop(CoroutineKind),
MisalignedPointerDereference { required: O, found: O },
NullPointerDereference,
NullReferenceConstructed,
InvalidEnumConstruction(O),
}

Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_middle/src/mir/terminator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ impl<O> AssertKind<O> {
LangItem::PanicGenFnNonePanic
}
NullPointerDereference => LangItem::PanicNullPointerDereference,
NullReferenceConstructed => LangItem::PanicNullReferenceConstructed,
InvalidEnumConstruction(_) => LangItem::PanicInvalidEnumConstruction,
ResumedAfterDrop(CoroutineKind::Coroutine(_)) => LangItem::PanicCoroutineResumedDrop,
ResumedAfterDrop(CoroutineKind::Desugared(CoroutineDesugaring::Async, _)) => {
Expand Down Expand Up @@ -287,6 +288,7 @@ impl<O> AssertKind<O> {
)
}
NullPointerDereference => write!(f, "\"null pointer dereference occurred\""),
NullReferenceConstructed => write!(f, "\"null reference produced\""),
InvalidEnumConstruction(source) => {
write!(f, "\"trying to construct an enum from an invalid value {{}}\", {source:?}")
}
Expand Down Expand Up @@ -387,6 +389,7 @@ impl<O: fmt::Debug> fmt::Display for AssertKind<O> {
write!(f, "coroutine resumed after panicking")
}
NullPointerDereference => write!(f, "null pointer dereference occurred"),
NullReferenceConstructed => write!(f, "null reference produced"),
InvalidEnumConstruction(source) => {
write!(f, "trying to construct an enum from an invalid value `{source:#?}`")
}
Expand Down
Loading
Loading