Skip to content

Rollup of 9 pull requests #139390

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Apr 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
7876836
Remove `rustc_middle::ty::util::ExplicitSelf`.
nnethercote Mar 28, 2025
a91e97c
Fix 2024 edition doctest panic output
GuillaumeGomez Apr 3, 2025
fff2484
Add regression test for #137970
GuillaumeGomez Apr 3, 2025
f9927ee
Use `eprint!` instead of `eprintln!`
GuillaumeGomez Apr 3, 2025
897f9e5
unstable book: document tait
mejrs Apr 3, 2025
b98760b
Fix links
mejrs Apr 3, 2025
a2618e1
AsyncDestructor: replace fields with impl_did
meithecatte Apr 4, 2025
fadf910
Fix `Debug` impl for `LateParamRegionKind`.
nnethercote Apr 4, 2025
0f12a2c
ToSocketAddrs: fix typo
RalfJung Apr 4, 2025
a69a219
Use the span of the whole bound when the diagnostic talks about a bound
oli-obk Apr 1, 2025
76e1302
Use target-agnostic LLD flags in bootstrap for use-lld
Kobzol Apr 4, 2025
00f0ce2
triagebot: add `compiletest` adhoc_group for `r? compiletest`
jieyouxu Apr 4, 2025
00f608a
Rollup merge of #139041 - nnethercote:rm-rustc_middle-ty-util-Explici…
matthiaskrgr Apr 4, 2025
cfc2297
Rollup merge of #139328 - GuillaumeGomez:fix-panic-output-137970, r=f…
matthiaskrgr Apr 4, 2025
8b86782
Rollup merge of #139339 - mejrs:tait, r=oli-obk
matthiaskrgr Apr 4, 2025
d61a473
Rollup merge of #139348 - meithecatte:async-destructor-minify, r=petr…
matthiaskrgr Apr 4, 2025
e3c73c7
Rollup merge of #139353 - nnethercote:LateAnon, r=compiler-errors
matthiaskrgr Apr 4, 2025
fa7d66e
Rollup merge of #139366 - RalfJung:ToSocketAddrs, r=jieyouxu
matthiaskrgr Apr 4, 2025
f074bbf
Rollup merge of #139374 - oli-obk:const-trait-bound, r=compiler-errors
matthiaskrgr Apr 4, 2025
bad6b7b
Rollup merge of #139378 - Kobzol:bootstrap-use-lld-fix, r=petrochenkov
matthiaskrgr Apr 4, 2025
a612ee7
Rollup merge of #139384 - jieyouxu:compiletest-reviewers, r=Kobzol
matthiaskrgr Apr 4, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
}
};

// If we can detect the expression to be an function or method call where the closure was
// If we can detect the expression to be a function or method call where the closure was
// an argument, we point at the function or method definition argument...
if let Some((callee_def_id, call_span, call_args)) = get_call_details() {
let arg_pos = call_args
Expand Down
35 changes: 22 additions & 13 deletions compiler/rustc_hir_analysis/src/check/compare_impl_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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>,
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1124,10 +1124,8 @@ pub struct Destructor {
// FIXME: consider combining this definition with regular `Destructor`
#[derive(Copy, Clone, Debug, HashStable, Encodable, Decodable)]
pub struct AsyncDestructor {
/// The `DefId` of the async destructor future constructor
pub ctor: DefId,
/// The `DefId` of the async destructor future type
pub future: DefId,
/// The `DefId` of the `impl AsyncDrop`
pub impl_did: LocalDefId,
}

#[derive(Clone, Copy, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/significant_drop_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ pub fn ty_dtor_span<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<Span> {
let dtor = if let Some(dtor) = tcx.adt_destructor(did) {
dtor.did
} else if let Some(dtor) = tcx.adt_async_destructor(did) {
dtor.future
return Some(tcx.source_span(dtor.impl_did));
} else {
return Some(try_local_did_span(did));
};
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_middle/src/ty/structural_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ impl fmt::Debug for ty::LateParamRegion {
impl fmt::Debug for ty::LateParamRegionKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
ty::LateParamRegionKind::Anon(idx) => write!(f, "BrAnon({idx})"),
ty::LateParamRegionKind::Anon(idx) => write!(f, "LateAnon({idx})"),
ty::LateParamRegionKind::Named(did, name) => {
if did.is_crate_root() {
write!(f, "BrNamed({name})")
write!(f, "LateNamed({name})")
} else {
write!(f, "BrNamed({did:?}, {name})")
write!(f, "LateNamed({did:?}, {name})")
}
}
ty::LateParamRegionKind::ClosureEnv => write!(f, "BrEnv"),
ty::LateParamRegionKind::ClosureEnv => write!(f, "LateEnv"),
}
}
}
Expand Down
64 changes: 3 additions & 61 deletions compiler/rustc_middle/src/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,26 +455,17 @@ impl<'tcx> TyCtxt<'tcx> {
continue;
}

let [future, ctor] = self.associated_item_def_ids(impl_did) else {
self.dcx().span_delayed_bug(
self.def_span(impl_did),
"AsyncDrop impl without async_drop function or Dropper type",
);
continue;
};

if let Some((_, _, old_impl_did)) = dtor_candidate {
if let Some(old_impl_did) = dtor_candidate {
self.dcx()
.struct_span_err(self.def_span(impl_did), "multiple async drop impls found")
.with_span_note(self.def_span(old_impl_did), "other impl here")
.delay_as_bug();
}

dtor_candidate = Some((*future, *ctor, impl_did));
dtor_candidate = Some(impl_did);
}

let (future, ctor, _) = dtor_candidate?;
Some(ty::AsyncDestructor { future, ctor })
Some(ty::AsyncDestructor { impl_did: dtor_candidate? })
}

/// Returns async drop glue morphology for a definition. To get async drop
Expand Down Expand Up @@ -1561,55 +1552,6 @@ impl<'tcx> Ty<'tcx> {
}
}

pub enum ExplicitSelf<'tcx> {
ByValue,
ByReference(ty::Region<'tcx>, hir::Mutability),
ByRawPointer(hir::Mutability),
ByBox,
Other,
}

impl<'tcx> ExplicitSelf<'tcx> {
/// Categorizes an explicit self declaration like `self: SomeType`
/// into either `self`, `&self`, `&mut self`, `Box<Self>`, or
/// `Other`.
/// This is mainly used to require the arbitrary_self_types feature
/// in the case of `Other`, to improve error messages in the common cases,
/// and to make `Other` dyn-incompatible.
///
/// Examples:
///
/// ```ignore (illustrative)
/// impl<'a> Foo for &'a T {
/// // Legal declarations:
/// fn method1(self: &&'a T); // ExplicitSelf::ByReference
/// fn method2(self: &'a T); // ExplicitSelf::ByValue
/// fn method3(self: Box<&'a T>); // ExplicitSelf::ByBox
/// fn method4(self: Rc<&'a T>); // ExplicitSelf::Other
///
/// // Invalid cases will be caught by `check_method_receiver`:
/// fn method_err1(self: &'a mut T); // ExplicitSelf::Other
/// fn method_err2(self: &'static T) // ExplicitSelf::ByValue
/// fn method_err3(self: &&T) // ExplicitSelf::ByReference
/// }
/// ```
///
pub fn determine<P>(self_arg_ty: Ty<'tcx>, is_self_ty: P) -> ExplicitSelf<'tcx>
where
P: Fn(Ty<'tcx>) -> bool,
{
use self::ExplicitSelf::*;

match *self_arg_ty.kind() {
_ if is_self_ty(self_arg_ty) => ByValue,
ty::Ref(region, ty, mutbl) if is_self_ty(ty) => ByReference(region, mutbl),
ty::RawPtr(ty, mutbl) if is_self_ty(ty) => ByRawPointer(mutbl),
_ if self_arg_ty.boxed_ty().is_some_and(is_self_ty) => ByBox,
_ => Other,
}
}
}

/// Returns a list of types such that the given type needs drop if and only if
/// *any* of the returned types need drop. Returns `Err(AlwaysRequiresDrop)` if
/// this type always needs drop.
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/net/socket_addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ use crate::{io, iter, option, slice, vec};
/// assert_eq!(err.kind(), io::ErrorKind::InvalidInput);
/// ```
///
/// [`TcpStream::connect`] is an example of an function that utilizes
/// [`TcpStream::connect`] is an example of a function that utilizes
/// `ToSocketAddrs` as a trait bound on its parameter in order to accept
/// different types:
///
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/src/utils/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,13 +474,13 @@ pub fn linker_flags(
if stage == 0 && target.is_windows() {
args.push("-Clink-arg=-fuse-ld=lld".to_string());
} else {
args.push("-Clinker-flavor=gnu-lld-cc".to_string());
args.push("-Zlinker-features=+lld".to_string());
}
// FIXME(kobzol): remove this flag once MCP510 gets stabilized
args.push("-Zunstable-options".to_string());
}
LldMode::SelfContained => {
args.push("-Clinker-flavor=gnu-lld-cc".to_string());
args.push("-Zlinker-features=+lld".to_string());
args.push("-Clink-self-contained=+linker".to_string());
// FIXME(kobzol): remove this flag once MCP510 gets stabilized
args.push("-Zunstable-options".to_string());
Expand Down
Loading
Loading