Auto merge of #139390 - matthiaskrgr:rollup-l64euwx, r=matthiaskrgr

Rollup of 9 pull requests

Successful merges:

 - #139041 (Remove `rustc_middle::ty::util::ExplicitSelf`.)
 - #139328 (Fix 2024 edition doctest panic output)
 - #139339 (unstable book: document tait)
 - #139348 (AsyncDestructor: replace fields with impl_did)
 - #139353 (Fix `Debug` impl for `LateParamRegionKind`.)
 - #139366 (ToSocketAddrs: fix typo)
 - #139374 (Use the span of the whole bound when the diagnostic talks about a bound)
 - #139378 (Use target-agnostic LLD flags in bootstrap for `use-lld`)
 - #139384 (Add `compiletest` adhoc_group for `r? compiletest`)

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2025-04-04 23:03:57 +00:00
commit bad13a970a
32 changed files with 274 additions and 128 deletions

View file

@ -12,7 +12,6 @@ use rustc_hir::{self as hir, AmbigArg, GenericParamKind, ImplItemKind, intravisi
use rustc_infer::infer::{self, InferCtxt, TyCtxtInferExt};
use rustc_infer::traits::util;
use rustc_middle::ty::error::{ExpectedFound, TypeError};
use rustc_middle::ty::util::ExplicitSelf;
use rustc_middle::ty::{
self, BottomUpFolder, GenericArgs, GenericParamDefKind, Ty, TyCtxt, TypeFoldable, TypeFolder,
TypeSuperFoldable, TypeVisitableExt, TypingMode, Upcast,
@ -995,6 +994,26 @@ impl<'tcx> ty::FallibleTypeFolder<TyCtxt<'tcx>> for RemapHiddenTyRegions<'tcx> {
}
}
/// Gets the string for an explicit self declaration, e.g. "self", "&self",
/// etc.
fn get_self_string<'tcx, P>(self_arg_ty: Ty<'tcx>, is_self_ty: P) -> String
where
P: Fn(Ty<'tcx>) -> bool,
{
if is_self_ty(self_arg_ty) {
"self".to_owned()
} else if let ty::Ref(_, ty, mutbl) = self_arg_ty.kind()
&& is_self_ty(*ty)
{
match mutbl {
hir::Mutability::Not => "&self".to_owned(),
hir::Mutability::Mut => "&mut self".to_owned(),
}
} else {
format!("self: {self_arg_ty}")
}
}
fn report_trait_method_mismatch<'tcx>(
infcx: &InferCtxt<'tcx>,
mut cause: ObligationCause<'tcx>,
@ -1020,12 +1039,7 @@ fn report_trait_method_mismatch<'tcx>(
if trait_m.fn_has_self_parameter =>
{
let ty = trait_sig.inputs()[0];
let sugg = match ExplicitSelf::determine(ty, |ty| ty == impl_trait_ref.self_ty()) {
ExplicitSelf::ByValue => "self".to_owned(),
ExplicitSelf::ByReference(_, hir::Mutability::Not) => "&self".to_owned(),
ExplicitSelf::ByReference(_, hir::Mutability::Mut) => "&mut self".to_owned(),
_ => format!("self: {ty}"),
};
let sugg = get_self_string(ty, |ty| ty == impl_trait_ref.self_ty());
// When the `impl` receiver is an arbitrary self type, like `self: Box<Self>`, the
// span points only at the type `Box<Self`>, but we want to cover the whole
@ -1238,12 +1252,7 @@ fn compare_self_type<'tcx>(
.build_with_typing_env(ty::TypingEnv::non_body_analysis(tcx, method.def_id));
let self_arg_ty = tcx.liberate_late_bound_regions(method.def_id, self_arg_ty);
let can_eq_self = |ty| infcx.can_eq(param_env, untransformed_self_ty, ty);
match ExplicitSelf::determine(self_arg_ty, can_eq_self) {
ExplicitSelf::ByValue => "self".to_owned(),
ExplicitSelf::ByReference(_, hir::Mutability::Not) => "&self".to_owned(),
ExplicitSelf::ByReference(_, hir::Mutability::Mut) => "&mut self".to_owned(),
_ => format!("self: {self_arg_ty}"),
}
get_self_string(self_arg_ty, can_eq_self)
};
match (trait_m.fn_has_self_parameter, impl_m.fn_has_self_parameter) {

View file

@ -838,7 +838,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
| PredicateFilter::SelfOnly
| PredicateFilter::SelfAndAssociatedTypeBounds => {
match constness {
hir::BoundConstness::Always(span) => {
hir::BoundConstness::Always(_) => {
if polarity == ty::PredicatePolarity::Positive {
bounds.push((
poly_trait_ref
@ -864,7 +864,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
// in `lower_assoc_item_constraint`.
PredicateFilter::ConstIfConst | PredicateFilter::SelfConstIfConst => {
match constness {
hir::BoundConstness::Maybe(span) => {
hir::BoundConstness::Maybe(_) => {
if polarity == ty::PredicatePolarity::Positive {
bounds.push((
poly_trait_ref