Skip to content

Commit 76a8b0e

Browse files
committed
Auto merge of #160667 - jhpratt:rollup-JUufhLd, r=<try>
Rollup of 14 pull requests try-job: dist-various-1 try-job: test-various try-job: x86_64-gnu-aux try-job: x86_64-gnu-llvm-21-3 try-job: x86_64-msvc-1 try-job: aarch64-apple-* try-job: x86_64-mingw-1 try-job: i686-msvc-*
2 parents 84b36a7 + a996a4d commit 76a8b0e

217 files changed

Lines changed: 5360 additions & 2829 deletions

File tree

Some content is hidden

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

compiler/rustc_ast_lowering/src/asm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
9393
match asm::InlineAsmClobberAbi::parse(
9494
asm_arch,
9595
&self.tcx.sess.target,
96-
&self.tcx.sess.unstable_target_features,
96+
&self.tcx.sess.internal_target_features,
9797
*abi_name,
9898
) {
9999
Ok(abi) => {

compiler/rustc_ast_lowering/src/delegation/generics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,10 +662,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
662662
p.def_id.to_def_id(),
663663
);
664664

665-
self.create_resolved_path(res, p.name.ident(), p.span)
665+
self.create_resolved_qpath(res, p.name.ident(), p.span)
666666
}
667667

668-
pub(super) fn create_resolved_path(
668+
pub(super) fn create_resolved_qpath(
669669
&mut self,
670670
res: Res,
671671
ident: Ident,

compiler/rustc_ast_lowering/src/delegation/mod.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
439439
};
440440

441441
let ident = Ident::new(kw::SelfUpper, span);
442-
let path = self.create_resolved_path(res, ident, span);
442+
let path = self.create_resolved_qpath(res, ident, span);
443443

444444
// FIXME(fn_delegation): add default `..` for all other fields.
445445
let initializer = hir::ExprKind::Struct(
@@ -454,7 +454,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
454454
hir::StructTailExpr::None,
455455
);
456456

457-
self.arena.alloc(self.mk_expr(initializer, span))
457+
let expr = self.mk_expr(initializer, span);
458+
459+
let path = self.make_lang_item_qpath(hir::LangItem::FromFn, span, None);
460+
let path = self.arena.alloc(self.mk_expr(hir::ExprKind::Path(path), span));
461+
462+
let call = hir::ExprKind::Call(path, self.arena.alloc_slice(&[expr]));
463+
464+
self.arena.alloc(self.mk_expr(call, span))
458465
} else {
459466
self.arena.alloc(call)
460467
};

compiler/rustc_ast_lowering/src/delegation/resolution.rs

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use hir::def::DefKind;
55
use rustc_ast::{self as ast, Delegation, DelegationSource, NodeId};
66
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
77
use rustc_hir as hir;
8-
use rustc_middle::ty::Ty;
8+
use rustc_middle::ty::{Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor};
99
use rustc_middle::{span_bug, ty};
1010
use rustc_span::def_id::{DefId, LocalDefId};
11-
use rustc_span::{ErrorGuaranteed, Span, kw};
11+
use rustc_span::{ErrorGuaranteed, Span};
1212

1313
use crate::delegation::generics::GenericsGenerationResults;
1414
use crate::delegation::resolution::resolver::DelegationResolver;
@@ -31,7 +31,7 @@ pub(super) struct ParamInfo {
3131
pub splatted: Option<u8>,
3232
}
3333

34-
#[derive(Default)]
34+
#[derive(Default, Debug)]
3535
pub(super) struct SigMapping {
3636
pub map_return: bool,
3737
pub arguments_to_map: FxIndexSet<usize>,
@@ -254,17 +254,52 @@ impl<'tcx> DelegationResolver<'_, 'tcx> {
254254
}
255255

256256
if self.can_perform_self_mapping(delegation, parent)? {
257-
// FIXME(fn_delegation): support heuristics for mapping of complex
258-
// return types: `Self` -> `Box<Arc<Rc<Self>>>`
259-
mapping.map_return = sig.output().is_param(0);
257+
/// Finds `Self` generic param only in ADT or references, so we avoid cases like
258+
/// `Self::Item` which will return true if `output.contains(...)` will be used.
259+
struct SelfFinder;
260+
261+
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for SelfFinder {
262+
type Result = ControlFlow<()>;
263+
264+
fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result {
265+
match t.kind() {
266+
ty::Adt(_, args) => {
267+
if args
268+
.iter()
269+
.flat_map(|arg| arg.as_type())
270+
.any(|type_arg| type_arg.is_self_param())
271+
{
272+
return ControlFlow::Break(());
273+
}
274+
275+
t.super_visit_with(self)
276+
}
277+
ty::Ref(_, ref_t, _) => {
278+
if ref_t.is_self_param() {
279+
return ControlFlow::Break(());
280+
}
281+
282+
t.super_visit_with(self)
283+
}
284+
_ => ControlFlow::Continue(()),
285+
}
286+
}
287+
}
288+
289+
impl SelfFinder {
290+
fn contains_self(t: Ty<'_>) -> bool {
291+
t.is_self_param() || t.visit_with(&mut SelfFinder).is_break()
292+
}
293+
}
294+
295+
mapping.map_return = SelfFinder::contains_self(sig.output());
260296

261-
let self_param = Ty::new_param(self.tcx(), 0, kw::SelfUpper);
262297
let arguments_to_map = sig
263298
.inputs()
264299
.iter()
265300
.enumerate()
266301
.skip(1) // Already checked above.
267-
.filter_map(|(idx, param)| param.contains(self_param).then_some(idx));
302+
.filter_map(|(idx, &param)| SelfFinder::contains_self(param).then_some(idx));
268303

269304
mapping.arguments_to_map.extend(arguments_to_map);
270305
}

0 commit comments

Comments
 (0)