Auto merge of #139845 - Zalathar:rollup-u5u5y1v, r=Zalathar
Rollup of 17 pull requests Successful merges: - #138374 (Enable contracts for const functions) - #138380 (ci: add runners for vanilla LLVM 20) - #138393 (Allow const patterns of matches to contain pattern types) - #139517 (std: sys: process: uefi: Use NULL stdin by default) - #139554 (std: add Output::exit_ok) - #139660 (compiletest: Add an experimental new executor to replace libtest) - #139669 (Overhaul `AssocItem`) - #139671 (Proc macro span API redesign: Replace proc_macro::SourceFile by Span::{file, local_file}) - #139750 (std/thread: Use default stack size from menuconfig for NuttX) - #139772 (Remove `hir::Map`) - #139785 (Let CStrings be either 1 or 2 byte aligned.) - #139789 (do not unnecessarily leak auto traits in item bounds) - #139791 (drop global where-bounds before merging candidates) - #139798 (normalize: prefer `ParamEnv` over `AliasBound` candidates) - #139822 (Fix: Map EOPNOTSUPP to ErrorKind::Unsupported on Unix) - #139833 (Fix some HIR pretty-printing problems) - #139836 (Basic tests of MPMC receiver cloning) r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
f433fa46b0
173 changed files with 2499 additions and 994 deletions
|
@ -2334,13 +2334,13 @@ impl<'tcx> ObligationCause<'tcx> {
|
|||
subdiags: Vec<TypeErrorAdditionalDiags>,
|
||||
) -> ObligationCauseFailureCode {
|
||||
match self.code() {
|
||||
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Fn, .. } => {
|
||||
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Fn { .. }, .. } => {
|
||||
ObligationCauseFailureCode::MethodCompat { span, subdiags }
|
||||
}
|
||||
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Type, .. } => {
|
||||
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Type { .. }, .. } => {
|
||||
ObligationCauseFailureCode::TypeCompat { span, subdiags }
|
||||
}
|
||||
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Const, .. } => {
|
||||
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Const { .. }, .. } => {
|
||||
ObligationCauseFailureCode::ConstCompat { span, subdiags }
|
||||
}
|
||||
ObligationCauseCode::BlockTailExpression(.., hir::MatchSource::TryDesugar(_)) => {
|
||||
|
@ -2398,13 +2398,13 @@ impl<'tcx> ObligationCause<'tcx> {
|
|||
|
||||
fn as_requirement_str(&self) -> &'static str {
|
||||
match self.code() {
|
||||
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Fn, .. } => {
|
||||
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Fn { .. }, .. } => {
|
||||
"method type is compatible with trait"
|
||||
}
|
||||
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Type, .. } => {
|
||||
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Type { .. }, .. } => {
|
||||
"associated type is compatible with trait"
|
||||
}
|
||||
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Const, .. } => {
|
||||
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Const { .. }, .. } => {
|
||||
"const is compatible with trait"
|
||||
}
|
||||
ObligationCauseCode::MainFunctionType => "`main` function has the correct type",
|
||||
|
@ -2422,9 +2422,13 @@ pub struct ObligationCauseAsDiagArg<'tcx>(pub ObligationCause<'tcx>);
|
|||
impl IntoDiagArg for ObligationCauseAsDiagArg<'_> {
|
||||
fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> rustc_errors::DiagArgValue {
|
||||
let kind = match self.0.code() {
|
||||
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Fn, .. } => "method_compat",
|
||||
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Type, .. } => "type_compat",
|
||||
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Const, .. } => {
|
||||
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Fn { .. }, .. } => {
|
||||
"method_compat"
|
||||
}
|
||||
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Type { .. }, .. } => {
|
||||
"type_compat"
|
||||
}
|
||||
ObligationCauseCode::CompareImplItem { kind: ty::AssocKind::Const { .. }, .. } => {
|
||||
"const_compat"
|
||||
}
|
||||
ObligationCauseCode::MainFunctionType => "fn_main_correct_type",
|
||||
|
|
|
@ -98,7 +98,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||
let assoc_item = self.tcx().associated_item(trait_item_def_id);
|
||||
let mut visitor = TypeParamSpanVisitor { tcx: self.tcx(), types: vec![] };
|
||||
match assoc_item.kind {
|
||||
ty::AssocKind::Fn => {
|
||||
ty::AssocKind::Fn { .. } => {
|
||||
if let Some(hir_id) =
|
||||
assoc_item.def_id.as_local().map(|id| self.tcx().local_def_id_to_hir_id(id))
|
||||
{
|
||||
|
|
|
@ -158,6 +158,6 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||
&& self
|
||||
.tcx()
|
||||
.opt_associated_item(scope_def_id.to_def_id())
|
||||
.is_some_and(|i| i.fn_has_self_parameter)
|
||||
.is_some_and(|i| i.is_method())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -782,8 +782,8 @@ fn foo(&self) -> Self::T { String::new() }
|
|||
let methods: Vec<(Span, String)> = items
|
||||
.in_definition_order()
|
||||
.filter(|item| {
|
||||
ty::AssocKind::Fn == item.kind
|
||||
&& Some(item.name) != current_method_ident
|
||||
item.is_fn()
|
||||
&& Some(item.name()) != current_method_ident
|
||||
&& !tcx.is_doc_hidden(item.def_id)
|
||||
})
|
||||
.filter_map(|item| {
|
||||
|
|
|
@ -1017,7 +1017,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
infer::BoundRegion(_, br, infer::AssocTypeProjection(def_id)) => format!(
|
||||
" for lifetime parameter {}in trait containing associated type `{}`",
|
||||
br_string(br),
|
||||
self.tcx.associated_item(def_id).name
|
||||
self.tcx.associated_item(def_id).name()
|
||||
),
|
||||
infer::RegionParameterDefinition(_, name) => {
|
||||
format!(" for lifetime parameter `{name}`")
|
||||
|
|
|
@ -348,11 +348,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
&& let None = self.tainted_by_errors()
|
||||
{
|
||||
let (verb, noun) = match self.tcx.associated_item(item_id).kind {
|
||||
ty::AssocKind::Const => ("refer to the", "constant"),
|
||||
ty::AssocKind::Fn => ("call", "function"),
|
||||
ty::AssocKind::Const { .. } => ("refer to the", "constant"),
|
||||
ty::AssocKind::Fn { .. } => ("call", "function"),
|
||||
// This is already covered by E0223, but this following single match
|
||||
// arm doesn't hurt here.
|
||||
ty::AssocKind::Type => ("refer to the", "type"),
|
||||
ty::AssocKind::Type { .. } => ("refer to the", "type"),
|
||||
};
|
||||
|
||||
// Replace the more general E0283 with a more specific error
|
||||
|
|
|
@ -2112,16 +2112,20 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||
trait_ref: DefId,
|
||||
) {
|
||||
if let Some(assoc_item) = self.tcx.opt_associated_item(item_def_id) {
|
||||
if let ty::AssocKind::Const | ty::AssocKind::Type = assoc_item.kind {
|
||||
if let ty::AssocKind::Const { .. } | ty::AssocKind::Type { .. } = assoc_item.kind {
|
||||
err.note(format!(
|
||||
"{}s cannot be accessed directly on a `trait`, they can only be \
|
||||
accessed through a specific `impl`",
|
||||
self.tcx.def_kind_descr(assoc_item.kind.as_def_kind(), item_def_id)
|
||||
self.tcx.def_kind_descr(assoc_item.as_def_kind(), item_def_id)
|
||||
));
|
||||
err.span_suggestion(
|
||||
span,
|
||||
"use the fully qualified path to an implementation",
|
||||
format!("<Type as {}>::{}", self.tcx.def_path_str(trait_ref), assoc_item.name),
|
||||
format!(
|
||||
"<Type as {}>::{}",
|
||||
self.tcx.def_path_str(trait_ref),
|
||||
assoc_item.name()
|
||||
),
|
||||
Applicability::HasPlaceholders,
|
||||
);
|
||||
}
|
||||
|
@ -5411,7 +5415,7 @@ fn point_at_assoc_type_restriction<G: EmissionGuarantee>(
|
|||
tcx.associated_items(data.impl_or_alias_def_id).find_by_ident_and_kind(
|
||||
tcx,
|
||||
Ident::with_dummy_span(name),
|
||||
ty::AssocKind::Type,
|
||||
ty::AssocTag::Type,
|
||||
data.impl_or_alias_def_id,
|
||||
)
|
||||
{
|
||||
|
|
|
@ -188,7 +188,7 @@ fn bounds_reference_self(tcx: TyCtxt<'_>, trait_def_id: DefId) -> SmallVec<[Span
|
|||
tcx.associated_items(trait_def_id)
|
||||
.in_definition_order()
|
||||
// We're only looking at associated type bounds
|
||||
.filter(|item| item.kind == ty::AssocKind::Type)
|
||||
.filter(|item| item.is_type())
|
||||
// Ignore GATs with `Self: Sized`
|
||||
.filter(|item| !tcx.generics_require_sized_self(item.def_id))
|
||||
.flat_map(|item| tcx.explicit_item_bounds(item.def_id).iter_identity_copied())
|
||||
|
@ -298,31 +298,33 @@ pub fn dyn_compatibility_violations_for_assoc_item(
|
|||
match item.kind {
|
||||
// Associated consts are never dyn-compatible, as they can't have `where` bounds yet at all,
|
||||
// and associated const bounds in trait objects aren't a thing yet either.
|
||||
ty::AssocKind::Const => {
|
||||
vec![DynCompatibilityViolation::AssocConst(item.name, item.ident(tcx).span)]
|
||||
ty::AssocKind::Const { name } => {
|
||||
vec![DynCompatibilityViolation::AssocConst(name, item.ident(tcx).span)]
|
||||
}
|
||||
ty::AssocKind::Fn => virtual_call_violations_for_method(tcx, trait_def_id, item)
|
||||
.into_iter()
|
||||
.map(|v| {
|
||||
let node = tcx.hir_get_if_local(item.def_id);
|
||||
// Get an accurate span depending on the violation.
|
||||
let span = match (&v, node) {
|
||||
(MethodViolationCode::ReferencesSelfInput(Some(span)), _) => *span,
|
||||
(MethodViolationCode::UndispatchableReceiver(Some(span)), _) => *span,
|
||||
(MethodViolationCode::ReferencesImplTraitInTrait(span), _) => *span,
|
||||
(MethodViolationCode::ReferencesSelfOutput, Some(node)) => {
|
||||
node.fn_decl().map_or(item.ident(tcx).span, |decl| decl.output.span())
|
||||
}
|
||||
_ => item.ident(tcx).span,
|
||||
};
|
||||
ty::AssocKind::Fn { name, .. } => {
|
||||
virtual_call_violations_for_method(tcx, trait_def_id, item)
|
||||
.into_iter()
|
||||
.map(|v| {
|
||||
let node = tcx.hir_get_if_local(item.def_id);
|
||||
// Get an accurate span depending on the violation.
|
||||
let span = match (&v, node) {
|
||||
(MethodViolationCode::ReferencesSelfInput(Some(span)), _) => *span,
|
||||
(MethodViolationCode::UndispatchableReceiver(Some(span)), _) => *span,
|
||||
(MethodViolationCode::ReferencesImplTraitInTrait(span), _) => *span,
|
||||
(MethodViolationCode::ReferencesSelfOutput, Some(node)) => {
|
||||
node.fn_decl().map_or(item.ident(tcx).span, |decl| decl.output.span())
|
||||
}
|
||||
_ => item.ident(tcx).span,
|
||||
};
|
||||
|
||||
DynCompatibilityViolation::Method(item.name, v, span)
|
||||
})
|
||||
.collect(),
|
||||
DynCompatibilityViolation::Method(name, v, span)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
// Associated types can only be dyn-compatible if they have `Self: Sized` bounds.
|
||||
ty::AssocKind::Type => {
|
||||
ty::AssocKind::Type { .. } => {
|
||||
if !tcx.generics_of(item.def_id).is_own_empty() && !item.is_impl_trait_in_trait() {
|
||||
vec![DynCompatibilityViolation::GAT(item.name, item.ident(tcx).span)]
|
||||
vec![DynCompatibilityViolation::GAT(item.name(), item.ident(tcx).span)]
|
||||
} else {
|
||||
// We will permit associated types if they are explicitly mentioned in the trait object.
|
||||
// We can't check this here, as here we only check if it is guaranteed to not be possible.
|
||||
|
@ -344,7 +346,7 @@ fn virtual_call_violations_for_method<'tcx>(
|
|||
let sig = tcx.fn_sig(method.def_id).instantiate_identity();
|
||||
|
||||
// The method's first parameter must be named `self`
|
||||
if !method.fn_has_self_parameter {
|
||||
if !method.is_method() {
|
||||
let sugg = if let Some(hir::Node::TraitItem(hir::TraitItem {
|
||||
generics,
|
||||
kind: hir::TraitItemKind::Fn(sig, _),
|
||||
|
|
|
@ -1393,7 +1393,7 @@ fn confirm_future_candidate<'cx, 'tcx>(
|
|||
coroutine_sig,
|
||||
);
|
||||
|
||||
debug_assert_eq!(tcx.associated_item(obligation.predicate.def_id).name, sym::Output);
|
||||
debug_assert_eq!(tcx.associated_item(obligation.predicate.def_id).name(), sym::Output);
|
||||
|
||||
let predicate = ty::ProjectionPredicate {
|
||||
projection_term: ty::AliasTerm::new_from_args(
|
||||
|
@ -1439,7 +1439,7 @@ fn confirm_iterator_candidate<'cx, 'tcx>(
|
|||
gen_sig,
|
||||
);
|
||||
|
||||
debug_assert_eq!(tcx.associated_item(obligation.predicate.def_id).name, sym::Item);
|
||||
debug_assert_eq!(tcx.associated_item(obligation.predicate.def_id).name(), sym::Item);
|
||||
|
||||
let predicate = ty::ProjectionPredicate {
|
||||
projection_term: ty::AliasTerm::new_from_args(
|
||||
|
@ -1485,7 +1485,7 @@ fn confirm_async_iterator_candidate<'cx, 'tcx>(
|
|||
gen_sig,
|
||||
);
|
||||
|
||||
debug_assert_eq!(tcx.associated_item(obligation.predicate.def_id).name, sym::Item);
|
||||
debug_assert_eq!(tcx.associated_item(obligation.predicate.def_id).name(), sym::Item);
|
||||
|
||||
let ty::Adt(_poll_adt, args) = *yield_ty.kind() else {
|
||||
bug!();
|
||||
|
@ -2005,7 +2005,8 @@ fn confirm_impl_candidate<'cx, 'tcx>(
|
|||
if !assoc_ty.item.defaultness(tcx).has_value() {
|
||||
debug!(
|
||||
"confirm_impl_candidate: no associated type {:?} for {:?}",
|
||||
assoc_ty.item.name, obligation.predicate
|
||||
assoc_ty.item.name(),
|
||||
obligation.predicate
|
||||
);
|
||||
if tcx.impl_self_is_guaranteed_unsized(impl_def_id) {
|
||||
// We treat this projection as rigid here, which is represented via
|
||||
|
|
|
@ -594,9 +594,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
// Associated types that require `Self: Sized` do not show up in the built-in
|
||||
// implementation of `Trait for dyn Trait`, and can be dropped here.
|
||||
.filter(|item| !tcx.generics_require_sized_self(item.def_id))
|
||||
.filter_map(
|
||||
|item| if item.kind == ty::AssocKind::Type { Some(item.def_id) } else { None },
|
||||
)
|
||||
.filter_map(|item| if item.is_type() { Some(item.def_id) } else { None })
|
||||
.collect();
|
||||
|
||||
for assoc_type in assoc_types {
|
||||
|
|
|
@ -197,10 +197,8 @@ fn own_existential_vtable_entries_iter(
|
|||
tcx: TyCtxt<'_>,
|
||||
trait_def_id: DefId,
|
||||
) -> impl Iterator<Item = DefId> {
|
||||
let trait_methods = tcx
|
||||
.associated_items(trait_def_id)
|
||||
.in_definition_order()
|
||||
.filter(|item| item.kind == ty::AssocKind::Fn);
|
||||
let trait_methods =
|
||||
tcx.associated_items(trait_def_id).in_definition_order().filter(|item| item.is_fn());
|
||||
|
||||
// Now list each method's DefId (for within its trait).
|
||||
let own_entries = trait_methods.filter_map(move |&trait_method| {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue