Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
d9b90b0
Rewrite safety requirements for `Allocator` impls
theemathas Jun 12, 2026
e9929d7
Address feedback comments.
theemathas Jun 15, 2026
2d79bb6
Fix sidebar heading order
tyilo Jun 18, 2026
0e252df
view types: add a few tests
scrabsha Apr 30, 2026
dcdf133
view-types: store view types in the AST
scrabsha Apr 28, 2026
310bfad
Enable Enzyme for x86_64-apple
sgasho Jun 3, 2026
34e0561
bump download-ci-llvm-stamp
sgasho Jun 3, 2026
d847075
Fix conditions of `&` API invalidating memory blocks.
theemathas Jul 1, 2026
bf03fc3
powerpc64le_unknown_freebsd.rs: link with -lgcc
pkubaj Jul 1, 2026
a00bdac
diagnostics: suggest type annotation for closure params on HRTB FnOnc…
Rohan-Singla Jul 2, 2026
155ead1
test: bless existing UI tests affected by new closure type annotation…
Rohan-Singla Jul 2, 2026
5817f14
test: bless remaining UI tests affected by new closure type annotatio…
Rohan-Singla Jul 2, 2026
b51d75e
Clarify that LocalKey::try_with may return AccessError
kpeis695 Jul 4, 2026
340e079
ci: use `ci-mirrors` in `armhf-gnu` for {busybox, ubuntu rootfs} arti…
jieyouxu Jul 5, 2026
0e0b98a
diagnostics: improve suggestion message and add rustfix test for clos…
Rohan-Singla Jul 5, 2026
049b3a3
test: bless nll UI tests affected by new closure type annotation sugg…
Rohan-Singla Jul 5, 2026
b50b5b2
Avoid unused braces lint for macro-provided call arguments
chenyukang Jul 4, 2026
448e0f8
add regression test for final RPITIT override panic
TaKO8Ki Jul 6, 2026
5a5f78d
avoid final override diagnostics for non-function associated items
TaKO8Ki Jul 6, 2026
de73ac0
Fix typetree generation for arguments, like slices and re-enable thei…
ZuseZ4 Jun 23, 2026
6bb1c07
Refactor the Type to TypeTree parser into a large match
ZuseZ4 Jul 6, 2026
f13657c
Rename some body_id vars to body_def_id
camsteffen Jun 28, 2026
f05ac1d
tests: catch up with LLVM returning f128 on the stack
durin42 Jul 7, 2026
3ed5f56
pattern-types: fix formatting in rustfmt
scrabsha Jul 7, 2026
66beceb
Add constraints to new delegation's generic args
aerooneqq Jul 7, 2026
831a2e8
delegation: support mapping of all arguments with `Self` type
aerooneqq Jul 7, 2026
4b90917
add wasm targets to unsupported abi test
folkertdev Jun 30, 2026
3decf25
disallow `extern "custom"` on wasm
folkertdev Jun 30, 2026
b10bdc4
add `extern "custom"` test to the naked functions tests
folkertdev Jun 30, 2026
5d925d7
disallow `extern "custom"` on spirv
folkertdev Jun 30, 2026
4674b5d
std: unconditionally use `preadv`/`pwritev` on AArch64 macOS
joboet Jul 7, 2026
49769af
QNX SDP 8 fixes.
japaric May 8, 2026
0a81c75
tests: clean up over-constraint on LLVM feature count
durin42 Jul 7, 2026
73cd65d
Rollup merge of #156016 - scrabsha:view-types/in-ast, r=oli-obk
JonathanBrouwer Jul 7, 2026
d82ce7d
Rollup merge of #157385 - sgasho:x86-mac-enzyme, r=ZuseZ4
JonathanBrouwer Jul 7, 2026
d4f3011
Rollup merge of #158179 - joboet:arm_macos_preadv, r=Darksonn
JonathanBrouwer Jul 7, 2026
15d0ce9
Rollup merge of #158621 - folkertdev:abi-custom-wasm, r=bjorn3
JonathanBrouwer Jul 7, 2026
9e8d31b
Rollup merge of #158690 - aerooneqq:delegation-self-type-arguments-wr…
JonathanBrouwer Jul 7, 2026
2ff42bf
Rollup merge of #158696 - camsteffen:body-id, r=oli-obk
JonathanBrouwer Jul 7, 2026
7fd8532
Rollup merge of #158697 - ferrocene:qnx-sdp-8-fixes, r=aapoalas
JonathanBrouwer Jul 7, 2026
c1d608b
Rollup merge of #158760 - kpeis695:fix/localkey-try-with-may-return, …
JonathanBrouwer Jul 7, 2026
d57f179
Rollup merge of #157801 - theemathas:allocator-safety-rewrite, r=Amanieu
JonathanBrouwer Jul 7, 2026
cae10bd
Rollup merge of #158085 - tyilo:fix-sidebar-heading-order, r=lolbinar…
JonathanBrouwer Jul 7, 2026
820771b
Rollup merge of #158333 - ZuseZ4:typetrees-for-enzyme3, r=oli-obk
JonathanBrouwer Jul 7, 2026
2b2a45c
Rollup merge of #158646 - pkubaj:patch-1, r=bjorn3
JonathanBrouwer Jul 7, 2026
b8df403
Rollup merge of #158701 - Rohan-Singla:fix/#158393, r=mejrs
JonathanBrouwer Jul 7, 2026
8e25cd2
Rollup merge of #158791 - chenyukang:yukang-fix-158747-unused-braces-…
JonathanBrouwer Jul 7, 2026
002e708
Rollup merge of #158802 - jieyouxu:jieyouxu/ci/armhf-gnu-mirror, r=ma…
JonathanBrouwer Jul 7, 2026
3df19af
Rollup merge of #158841 - TaKO8Ki:fix-final-rpitit-override-ice, r=mejrs
JonathanBrouwer Jul 7, 2026
3773982
Rollup merge of #158889 - durin42:llvm-23-win-x64-f128, r=folkertdev
JonathanBrouwer Jul 7, 2026
6669db3
Rollup merge of #158905 - aerooneqq:delegation-forgotten-constraints,…
JonathanBrouwer Jul 7, 2026
7ce91c5
Rollup merge of #158922 - durin42:llvm-23-clean-up-test-constraint, r…
JonathanBrouwer 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
2 changes: 2 additions & 0 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2564,6 +2564,8 @@ pub enum TyKind {
/// Usually not written directly in user code but indirectly via the macro
/// `core::field::field_of!(...)`.
FieldOf(Box<Ty>, Option<Ident>, Ident),
/// A view of a type. `T.{ field_1, field_2 }`.
View(Box<Ty>, #[visitable(ignore)] ThinVec<Ident>),
/// Sometimes we need a dummy value when no error has occurred.
Dummy,
/// Placeholder for a kind that has failed to be defined.
Expand Down
11 changes: 11 additions & 0 deletions compiler/rustc_ast/src/expand/typetree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ pub enum Kind {
Anything,
Integer,
Pointer,
// We prefer to directly lower to things that our Enzyme backend supports.
// However, it's sometimes convenient to pass ptr+int as one type.
RustSlice,
Half,
Float,
Double,
Expand Down Expand Up @@ -57,6 +60,9 @@ impl TypeTree {
}
Self(ints)
}
pub fn add_indirection(self) -> Self {
Self(vec![Type { offset: 0, size: 1, kind: Kind::Pointer, child: self }])
}
}

#[derive(Clone, Eq, PartialEq, Encodable, Decodable, Debug, StableHash)]
Expand All @@ -72,6 +78,11 @@ pub struct Type {
pub kind: Kind,
pub child: TypeTree,
}
impl Type {
pub fn from_ty(offset: isize, other: &Type) -> Self {
Self { offset, size: other.size, kind: other.kind, child: other.child.clone() }
}
}

impl Type {
pub fn add_offset(self, add: isize) -> Self {
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_ast/src/util/classify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ fn type_trailing_braced_mac_call(mut ty: &ast::Ty) -> Option<&ast::MacCall> {
| ast::TyKind::Pat(..)
| ast::TyKind::FieldOf(..)
| ast::TyKind::Dummy
| ast::TyKind::Err(..) => break None,
| ast::TyKind::Err(..)
| ast::TyKind::View(..) => break None,
}
}
}
Expand Down
23 changes: 11 additions & 12 deletions compiler/rustc_ast_lowering/src/delegation/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rustc_hir::def_id::DefId;
use rustc_middle::ty::{GenericParamDefKind, TyCtxt};
use rustc_middle::{bug, ty};
use rustc_span::symbol::kw;
use rustc_span::{Ident, Span, sym};
use rustc_span::{ErrorGuaranteed, Ident, Span, sym};

use crate::LoweringContext;
use crate::delegation::resolution::resolver::DelegationResolver;
Expand Down Expand Up @@ -281,7 +281,7 @@ impl<'hir> DelegationResolver<'_, 'hir> {
&self,
delegation: &'a Delegation,
sig_id: DefId,
) -> GenericsResolution<'a, 'hir> {
) -> Result<GenericsResolution<'a, 'hir>, ErrorGuaranteed> {
let tcx = self.tcx();
let delegation_parent_kind = tcx.def_kind(tcx.local_parent(self.owner_id()));

Expand All @@ -300,9 +300,8 @@ impl<'hir> DelegationResolver<'_, 'hir> {
let qself_is_none = delegation.qself.is_none();

let parent_args = if let [.., parent_segment, _] = &delegation.path.segments[..] {
if let Some(res) = self.get_resolution_id(parent_segment.id)
&& matches!(tcx.def_kind(res), DefKind::Trait | DefKind::TraitAlias)
{
let res = self.get_resolution_id(parent_segment.id)?;
if matches!(tcx.def_kind(res), DefKind::Trait | DefKind::TraitAlias) {
sig_parent_params = &tcx.generics_of(sig_parent).own_params;
self.get_user_args(parent_segment)
.map(|args| ParentSegmentArgs::Specified(args))
Expand All @@ -314,7 +313,7 @@ impl<'hir> DelegationResolver<'_, 'hir> {
ParentSegmentArgs::Invalid
};

GenericsResolution {
Ok(GenericsResolution {
parent_args,
sig_parent_params,
qself_is_none,
Expand All @@ -326,7 +325,7 @@ impl<'hir> DelegationResolver<'_, 'hir> {
child_args: self.get_user_args(
delegation.path.segments.last().expect("must be at least one segment"),
),
}
})
}

fn get_user_args<'a>(&self, segment: &'a PathSegment) -> Option<&'a AngleBracketedArgs> {
Expand All @@ -350,14 +349,14 @@ impl<'hir> DelegationResolver<'_, 'hir> {
&self,
delegation: &Delegation,
sig_id: DefId,
) -> GenericsGenerationResults<'hir> {
) -> Result<GenericsGenerationResults<'hir>, ErrorGuaranteed> {
let res @ GenericsResolution {
trait_impl,
generate_self,
sig_child_params,
sig_parent_params,
..
} = self.resolve_generics(delegation, sig_id);
} = self.resolve_generics(delegation, sig_id)?;

// If we are in trait impl always generate function whose generics matches
// those that are defined in trait.
Expand All @@ -374,7 +373,7 @@ impl<'hir> DelegationResolver<'_, 'hir> {

let child = GenericsGenerationResult::new(child);

return GenericsGenerationResults { parent, child, self_ty_propagation_kind: None };
return Ok(GenericsGenerationResults { parent, child, self_ty_propagation_kind: None });
}

let tcx = self.tcx();
Expand Down Expand Up @@ -421,7 +420,7 @@ impl<'hir> DelegationResolver<'_, 'hir> {
DelegationGenerics::generate_all(sig_child_params, GenericsPosition::Child, trait_impl)
};

GenericsGenerationResults {
Ok(GenericsGenerationResults {
parent: GenericsGenerationResult::new(parent_generics),
child: GenericsGenerationResult::new(child_generics),
self_ty_propagation_kind: match res.free_to_trait_delegation {
Expand All @@ -435,7 +434,7 @@ impl<'hir> DelegationResolver<'_, 'hir> {
}),
false => None,
},
}
})
}

/// Generates generic argument slots for user-specified `args` and
Expand Down
130 changes: 89 additions & 41 deletions compiler/rustc_ast_lowering/src/delegation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ use hir::def::Res;
use rustc_abi::ExternAbi;
use rustc_ast as ast;
use rustc_ast::*;
use rustc_hir::def::DefKind;
use rustc_hir::{self as hir, FnDeclFlags};
use rustc_middle::ty::Asyncness;
use rustc_span::def_id::DefId;
Expand Down Expand Up @@ -249,20 +250,19 @@ impl<'hir> LoweringContext<'_, 'hir> {
let mut unused_target_expr = false;

let block_id = self.lower_body(|this| {
let &DelegationResolution {
param_info, span, should_generate_block, is_method, ..
} = res;

let &DelegationResolution { param_info, span, is_method, .. } = res;
let ParamInfo { param_count, .. } = param_info;
let arguments_to_map = &res.sig_mapping.arguments_to_map;

let mut parameters: Vec<hir::Param<'_>> = Vec::with_capacity(param_count);
let mut args: Vec<hir::Expr<'_>> = Vec::with_capacity(param_count);
let mut stmts: &[hir::Stmt<'hir>] = &[];
let mut stmts = vec![];

// Consider non-specified target expression as generated,
// as we do not want to emit error when target expression is
// not specified.
unused_target_expr = block.is_some() && (param_count == 0 || !should_generate_block);
unused_target_expr =
block.is_some() && (param_count == 0 || arguments_to_map.is_empty());

for idx in 0..param_count {
let (param, pat_node_id) = this.generate_param(is_method, idx, span);
Expand All @@ -271,41 +271,38 @@ impl<'hir> LoweringContext<'_, 'hir> {
let generate_arg =
|this: &mut Self| this.generate_arg(is_method, idx, param.pat.hir_id, span);

let arg = if let Some(block) = block
&& idx == 0
&& should_generate_block
{
let mut self_resolver = SelfResolver {
ctxt: this,
path_id: delegation.id,
self_param_id: pat_node_id,
};
self_resolver.visit_block(block);
// Target expr needs to lower `self` path.
this.ident_and_label_to_local_id.insert(pat_node_id, param.pat.hir_id.local_id);

// Lower with `HirId::INVALID` as we will use only expr and stmts.
// FIXME(fn_delegation): Alternatives for target expression lowering:
// https://github.com/rust-lang/rfcs/pull/3530#issuecomment-2197170600.
let block = this.lower_block_noalloc(HirId::INVALID, block, false);

stmts = block.stmts;

// The behavior of the delegation's target expression differs from the
// behavior of the usual block, where if there is no final expression
// the `()` is returned. In case of the similar situation in delegation
// (no final expression) we propagate first argument instead of replacing
// it with `()`.
if let Some(&expr) = block.expr { expr } else { generate_arg(this) }
} else {
generate_arg(this)
};
let arg = block
.filter(|_| arguments_to_map.contains(&idx))
.and_then(|block| {
let block = this.lower_block_maybe_more_than_once(
block,
pat_node_id,
param.pat.hir_id.local_id,
delegation.id,
);

stmts.push(block.stmts);

// The behavior of the delegation's target expression differs from the
// behavior of the usual block, where if there is no final expression
// the `()` is returned. In case of the similar situation in delegation
// (no final expression) we propagate first argument instead of replacing
// it with `()`.
block.expr.copied()
})
.unwrap_or_else(|| generate_arg(this));

args.push(arg);
}

let (final_expr, hir_id) =
this.finalize_body_lowering(delegation, stmts, args, res, generics, span);
let (final_expr, hir_id) = this.finalize_body_lowering(
delegation,
this.arena.alloc_from_iter(stmts.into_iter().flatten().copied()),
args,
res,
generics,
span,
);

call_expr_id = hir_id;

Expand All @@ -317,6 +314,48 @@ impl<'hir> LoweringContext<'_, 'hir> {
(block_id, call_expr_id, unused_target_expr)
}

fn lower_block_maybe_more_than_once(
&mut self,
block: &Block,
pat_node_id: NodeId,
param_local_id: hir::ItemLocalId,
delegation_id: NodeId,
) -> hir::Block<'hir> {
let mut self_resolver = SelfResolver {
ctxt: self,
path_id: delegation_id,
self_param_id: pat_node_id,
overwrites: vec![],
};

self_resolver.visit_block(block);

let overwrites = self_resolver.overwrites;

// Target expr needs to lower `self` path.
self.ident_and_label_to_local_id.insert(pat_node_id, param_local_id);

let block = cfg_select! {
debug_assertions => {
crate::re_lowering::ReloweringChecker::allow_relowering(self, |this| {
this.lower_block_noalloc(HirId::INVALID, block, false)
})
},
_ => self.lower_block_noalloc(HirId::INVALID, block, false)
};

// Remove node ids for which we overwrote resolution to generated param
// before block lowering as block can be relowered. We need to do it because
// check in `SelfResolver` uses `get_partial_res` to decide whether to overwrite
// resolution, and if it is already overwritten from previous block lowering this
// check will not pass.
for id in overwrites {
self.partial_res_overrides.remove(&id);
}

block
}

fn finalize_body_lowering(
&mut self,
delegation: &Delegation,
Expand Down Expand Up @@ -392,8 +431,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
let args = self.arena.alloc_from_iter(args);
let call = self.mk_expr(hir::ExprKind::Call(callee_path, args), span);

let expr = if let Some((parent, of_trait)) = res.output_self_mapping {
let res = Res::SelfTyAlias { alias_to: parent.to_def_id(), is_trait_impl: of_trait };
let expr = if res.sig_mapping.map_return {
let res = Res::SelfTyAlias {
alias_to: res.parent.to_def_id(),
is_trait_impl: self.tcx.def_kind(res.parent) == DefKind::Impl { of_trait: true },
};

let ident = Ident::new(kw::SelfUpper, span);
let path = self.create_resolved_path(res, ident, span);

Expand Down Expand Up @@ -453,11 +496,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
})
.unwrap_or_else(|| self.arena.alloc_from_iter(args_iter.consume_all(self)));

// Do not omit constraints as there might be some and they must be present in HIR (#158812).
let has_constraints = segment.args.is_some_and(|a| !a.constraints.is_empty());

// Needed for better error messages (`trait-impl-wrong-args-count.rs` test).
segment.args = (!new_args.is_empty()).then(|| {
segment.args = (has_constraints || !new_args.is_empty()).then(|| {
&*self.arena.alloc(hir::GenericArgs {
args: new_args,
constraints: &[],
constraints: segment.args.map(|a| a.constraints).unwrap_or(&[]),
parenthesized: hir::GenericArgsParentheses::No,
span_ext: segment.args.map_or(span, |args| args.span_ext),
})
Expand Down Expand Up @@ -538,6 +584,7 @@ struct SelfResolver<'a, 'b, 'hir> {
ctxt: &'a mut LoweringContext<'b, 'hir>,
path_id: NodeId,
self_param_id: NodeId,
overwrites: Vec<NodeId>,
}

impl SelfResolver<'_, '_, '_> {
Expand All @@ -546,6 +593,7 @@ impl SelfResolver<'_, '_, '_> {
&& let Some(Res::Local(sig_id)) = res.full_res()
&& sig_id == self.path_id
{
self.overwrites.push(id);
self.ctxt.partial_res_overrides.insert(id, self.self_param_id);
}
}
Expand Down
Loading
Loading