From 8b9d41c435e95d5fd6573ff38ae208f0ac4611b4 Mon Sep 17 00:00:00 2001 From: "addie.sh" Date: Tue, 21 Jul 2026 11:49:20 -0400 Subject: [PATCH 01/41] Next steps for FnDef binder changes (instantiate most FnDef binders) --- .../rustc_hir_analysis/src/collect/type_of.rs | 47 +++++++++---------- .../src/hir_ty_lowering/mod.rs | 14 ++---- compiler/rustc_middle/src/mir/statement.rs | 8 ++-- compiler/rustc_middle/src/ty/sty.rs | 19 +++++++- .../rustc_mir_build/src/builder/expr/into.rs | 9 +--- .../src/builder/matches/test.rs | 13 ++--- compiler/rustc_mir_build/src/thir/cx/expr.rs | 42 +++++++---------- .../rustc_mir_transform/src/elaborate_drop.rs | 47 +++++++------------ compiler/rustc_mir_transform/src/shim.rs | 6 +-- .../src/shim/async_destructor_ctor.rs | 16 +------ .../src/canonical/mod.rs | 1 + compiler/rustc_type_ir/src/relate.rs | 19 ++++---- .../src/relate/solver_relating.rs | 1 + .../casts/confusing_method_to_numeric_cast.rs | 3 +- tests/crashes/133613.rs | 8 ---- .../incremental/hashes/function_interfaces.rs | 4 +- tests/incremental/hashes/inherent_impls.rs | 12 ++--- tests/incremental/hashes/trait_defs.rs | 8 ++-- tests/incremental/hashes/trait_impls.rs | 8 ++-- .../binder-arg-overflow-regression-133613.rs | 18 +++++++ ...nder-arg-overflow-regression-133613.stderr | 36 ++++++++++++++ .../ui/thir-print/thir-tree-match-for.stdout | 12 ++--- 22 files changed, 185 insertions(+), 166 deletions(-) delete mode 100644 tests/crashes/133613.rs create mode 100644 tests/ui/generics/binder-arg-overflow-regression-133613.rs create mode 100644 tests/ui/generics/binder-arg-overflow-regression-133613.stderr diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs index 68b7d50c2ee9b..6709fab48d9ab 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs @@ -63,13 +63,26 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_ let icx = ItemCtxt::new(tcx, def_id); + let new_bound_fn_def = |hir: HirId, did| { + let args = ty::GenericArgs::identity_for_item(tcx, def_id); + Ty::new_fn_def_raw( + tcx, + did, + match &tcx + .late_bound_vars_map(hir.owner) + .get(&hir.local_id) + .cloned() + .map(|x| tcx.mk_bound_variable_kinds(&x)) + { + Some(late_bound) => ty::Binder::bind_with_vars(args, late_bound), + None => ty::Binder::dummy(args), + }, + ) + }; + let output = match tcx.hir_node(hir_id) { Node::TraitItem(item) => match item.kind { - TraitItemKind::Fn(..) => { - let args = ty::GenericArgs::identity_for_item(tcx, def_id); - // FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes) - Ty::new_fn_def(tcx, def_id.to_def_id(), ty::Binder::dummy(args)) - } + TraitItemKind::Fn(_, _) => new_bound_fn_def(item.hir_id(), def_id.to_def_id()), TraitItemKind::Const(ty, rhs) => rhs .and_then(|rhs| { ty.is_suggestable_infer_ty().then(|| { @@ -92,11 +105,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_ }, Node::ImplItem(item) => match item.kind { - ImplItemKind::Fn(..) => { - let args = ty::GenericArgs::identity_for_item(tcx, def_id); - // FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes) - Ty::new_fn_def(tcx, def_id.to_def_id(), ty::Binder::dummy(args)) - } + ImplItemKind::Fn(_, _) => new_bound_fn_def(item.hir_id(), def_id.to_def_id()), ImplItemKind::Const(ty, rhs) => { if ty.is_suggestable_infer_ty() { infer_placeholder_type( @@ -171,11 +180,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_ } _ => icx.lower_ty(self_ty), }, - ItemKind::Fn { .. } => { - let args = ty::GenericArgs::identity_for_item(tcx, def_id); - // FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes) - Ty::new_fn_def(tcx, def_id.to_def_id(), ty::Binder::dummy(args)) - } + ItemKind::Fn { .. } => new_bound_fn_def(item.hir_id(), def_id.to_def_id()), ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) => { let def = tcx.adt_def(def_id); let args = ty::GenericArgs::identity_for_item(tcx, def_id); @@ -196,10 +201,8 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_ Node::OpaqueTy(..) => tcx.type_of_opaque(def_id).instantiate_identity().skip_norm_wip(), Node::ForeignItem(foreign_item) => match foreign_item.kind { - ForeignItemKind::Fn(..) => { - let args = ty::GenericArgs::identity_for_item(tcx, def_id); - // FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes) - Ty::new_fn_def(tcx, def_id.to_def_id(), ty::Binder::dummy(args)) + ForeignItemKind::Fn(_, _, _generics) => { + new_bound_fn_def(foreign_item.hir_id(), def_id.to_def_id()) } ForeignItemKind::Static(ty, _, _) => { let ty = icx.lower_ty(ty); @@ -219,11 +222,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_ VariantData::Unit(..) | VariantData::Struct { .. } => { tcx.type_of(tcx.hir_get_parent_item(hir_id)).instantiate_identity().skip_norm_wip() } - VariantData::Tuple(_, _, ctor) => { - let args = ty::GenericArgs::identity_for_item(tcx, def_id); - // FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes) - Ty::new_fn_def(tcx, ctor.to_def_id(), ty::Binder::dummy(args)) - } + VariantData::Tuple(_, hir_id, ctor) => new_bound_fn_def(*hir_id, ctor.to_def_id()), }, Node::Field(field) => icx.lower_ty(field.ty), diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs index 497ff02c9b407..fa3dca042ba0c 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs @@ -1483,13 +1483,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { Ok(ct) } TypeRelativePath::Ctor { ctor_def_id, args } => match tcx.def_kind(ctor_def_id) { - DefKind::Ctor(_, CtorKind::Fn) => { - // FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes) - Ok(ty::Const::zero_sized( - tcx, - Ty::new_fn_def(tcx, ctor_def_id, ty::Binder::dummy(args)), - )) - } + DefKind::Ctor(_, CtorKind::Fn) => Ok(ty::Const::zero_sized( + tcx, + tcx.type_of(ctor_def_id).instantiate(tcx, args).skip_norm_wip(), + )), DefKind::Ctor(ctor_of, CtorKind::Const) => { Ok(self.construct_const_ctor_value(ctor_def_id, ctor_of, args)) } @@ -2913,8 +2910,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { &path.segments[generic_segments[0].1], ); - // FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes) - ty::Const::zero_sized(tcx, Ty::new_fn_def(tcx, did, ty::Binder::dummy(args))) + ty::Const::zero_sized(tcx, tcx.type_of(did).instantiate(tcx, args).skip_norm_wip()) } Res::Def(DefKind::AssocConst { .. }, did) => { let trait_segment = if let [modules @ .., trait_, _item] = path.segments { diff --git a/compiler/rustc_middle/src/mir/statement.rs b/compiler/rustc_middle/src/mir/statement.rs index 5215dffed0717..9712ac02775d4 100644 --- a/compiler/rustc_middle/src/mir/statement.rs +++ b/compiler/rustc_middle/src/mir/statement.rs @@ -620,11 +620,13 @@ impl<'tcx> Operand<'tcx> { pub fn function_handle( tcx: TyCtxt<'tcx>, def_id: DefId, - args: ty::Binder<'tcx, impl IntoIterator>>, + args: &[GenericArg<'tcx>], span: Span, ) -> Self { - let ty = Ty::new_fn_def(tcx, def_id, args); - Operand::zero_sized_constant(ty, span) + Operand::zero_sized_constant( + tcx.type_of(def_id).instantiate(tcx, args).skip_norm_wip(), + span, + ) } /// Convenience helper to make a constant that refers to the given `DefId` and args. Since this diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index ff787c0ede7f7..f8fb476ca3ef1 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -725,6 +725,23 @@ impl<'tcx> Ty<'tcx> { T::collect_and_apply(iter, |ts| Ty::new_tup(tcx, ts)) } + /// Prefer using the [TyCtxt::type_of] query over this, that makes it easier to get all the pieces correct + #[inline] + pub fn new_fn_def_raw( + tcx: TyCtxt<'tcx>, + def_id: DefId, + args: ty::Binder<'tcx, impl IntoIterator>>>, + ) -> Ty<'tcx> { + debug_assert_matches!( + tcx.def_kind(def_id), + DefKind::AssocFn | DefKind::Fn | DefKind::Ctor(_, CtorKind::Fn) + ); + + let args = args.map_bound(|args| tcx.check_and_mk_args(def_id, args)); + + Ty::new(tcx, FnDef(def_id, args)) + } + #[inline] pub fn new_fn_def( tcx: TyCtxt<'tcx>, @@ -1113,7 +1130,7 @@ impl<'tcx> rustc_type_ir::inherent::Ty> for Ty<'tcx> { def_id: DefId, args: ty::Binder<'tcx, ty::GenericArgsRef<'tcx>>, ) -> Self { - Ty::new_fn_def(interner, def_id, args) + Ty::new_fn_def_raw(interner, def_id, args) } fn new_fn_ptr(interner: TyCtxt<'tcx>, sig: ty::Binder<'tcx, ty::FnSig<'tcx>>) -> Self { diff --git a/compiler/rustc_mir_build/src/builder/expr/into.rs b/compiler/rustc_mir_build/src/builder/expr/into.rs index f04247491ccfa..bdf45e0c85cb5 100644 --- a/compiler/rustc_mir_build/src/builder/expr/into.rs +++ b/compiler/rustc_mir_build/src/builder/expr/into.rs @@ -532,13 +532,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let success = this.cfg.start_new_block(); let clone_trait = this.tcx.require_lang_item(LangItem::Clone, span); let clone_fn = this.tcx.associated_item_def_ids(clone_trait)[0]; - // FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes) - let func = Operand::function_handle( - this.tcx, - clone_fn, - ty::Binder::dummy([ty.into()]), - expr_span, - ); + let func = + Operand::function_handle(this.tcx, clone_fn, &[ty.into()], expr_span); let ref_ty = Ty::new_imm_ref(this.tcx, this.tcx.lifetimes.re_erased, ty); let ref_place = this.temp(ref_ty, span); this.cfg.push_assign( diff --git a/compiler/rustc_mir_build/src/builder/matches/test.rs b/compiler/rustc_mir_build/src/builder/matches/test.rs index a1087b9ff98a0..1c234bb8d70dc 100644 --- a/compiler/rustc_mir_build/src/builder/matches/test.rs +++ b/compiler/rustc_mir_build/src/builder/matches/test.rs @@ -348,8 +348,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let source_info = self.source_info(span); let re_erased = self.tcx.lifetimes.re_erased; let trait_item = self.tcx.require_lang_item(trait_item, span); - // FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes) - let method = trait_method(self.tcx, trait_item, method, ty::Binder::dummy([ty])); + let method = trait_method(self.tcx, trait_item, method, &[ty.into()]); let ref_src = self.temp(Ty::new_ref(self.tcx, re_erased, ty, mutability), span); // `let ref_src = &src_place;` // or `let ref_src = &mut src_place;` @@ -422,9 +421,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { ) { let str_ty = self.tcx.types.str_; let eq_def_id = self.tcx.require_lang_item(LangItem::PartialEq, source_info.span); - let method = - // FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes) - trait_method(self.tcx, eq_def_id, sym::eq, ty::Binder::dummy([str_ty, str_ty])); + let method = trait_method(self.tcx, eq_def_id, sym::eq, &[str_ty.into(), str_ty.into()]); let bool_ty = self.tcx.types.bool; let eq_result = self.temp(bool_ty, source_info.span); @@ -471,7 +468,7 @@ fn trait_method<'tcx>( tcx: TyCtxt<'tcx>, trait_def_id: DefId, method_name: Symbol, - args: ty::Binder<'tcx, impl IntoIterator>>>, + args: &[GenericArg<'tcx>], ) -> Const<'tcx> { // The unhygienic comparison here is acceptable because this is only // used on known traits. @@ -481,7 +478,5 @@ fn trait_method<'tcx>( .find(|item| item.is_fn()) .expect("trait method not found"); - let method_ty = Ty::new_fn_def(tcx, item.def_id, args); - - Const::zero_sized(method_ty) + Const::zero_sized(tcx.type_of(item.def_id).instantiate(tcx, args).skip_norm_wip()) } diff --git a/compiler/rustc_mir_build/src/thir/cx/expr.rs b/compiler/rustc_mir_build/src/thir/cx/expr.rs index 10dc59a8950fd..2f39be4214e46 100644 --- a/compiler/rustc_mir_build/src/thir/cx/expr.rs +++ b/compiler/rustc_mir_build/src/thir/cx/expr.rs @@ -199,12 +199,11 @@ impl<'tcx> ThirBuildCx<'tcx> { // We don't need to do call adjust_span here since // deref coercions always start with a built-in deref. let call_def_id = deref.method_call(self.tcx); - // FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes) - let overloaded_callee = Ty::new_fn_def( - self.tcx, - call_def_id, - ty::Binder::dummy(self.tcx.mk_args(&[expr.ty.into()])), - ); + let overloaded_callee = self + .tcx + .type_of(call_def_id) + .instantiate(self.tcx, self.tcx.mk_args(&[expr.ty.into()])) + .skip_norm_wip(); expr = Expr { temp_scope_id, @@ -855,12 +854,10 @@ impl<'tcx> ThirBuildCx<'tcx> { }; let mk_call = |thir: &mut Thir<'tcx>, ty: Ty<'tcx>, variant: VariantIdx, field: FieldIdx| { - // FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes) - let fun_ty = Ty::new_fn_def( - tcx, - offset_of_intrinsic, - ty::Binder::dummy([ty::GenericArg::from(ty)]), - ); + let fun_ty = tcx + .type_of(offset_of_intrinsic) + .instantiate(tcx, &[ty.into()]) + .skip_norm_wip(); let fun = thir .exprs .push(mk_expr(ExprKind::ZstLiteral { user_ty: None }, fun_ty)); @@ -1211,12 +1208,10 @@ impl<'tcx> ThirBuildCx<'tcx> { let user_ty = self.user_args_applied_to_res(expr.hir_id, Res::Def(kind, def_id)); debug!("method_callee: user_ty={:?}", user_ty); ( - // FIXME: instantiate binder correctly (turbofish/fndex) - Ty::new_fn_def( - self.tcx, - def_id, - ty::Binder::dummy(self.typeck_results.node_args(expr.hir_id)), - ), + self.tcx + .type_of(def_id) + .instantiate(self.tcx, self.typeck_results.node_args(expr.hir_id)) + .skip_norm_wip(), user_ty, ) } @@ -1250,12 +1245,11 @@ impl<'tcx> ThirBuildCx<'tcx> { Expr { temp_scope_id: expr.hir_id.local_id, - // FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes) - ty: Ty::new_fn_def( - self.tcx, - def_id, - ty::Binder::dummy(self.typeck_results.node_args(expr.hir_id)), - ), + ty: self + .tcx + .type_of(def_id) + .instantiate(self.tcx, self.typeck_results.node_args(expr.hir_id)) + .skip_norm_wip(), span, kind: ExprKind::ZstLiteral { user_ty }, } diff --git a/compiler/rustc_mir_transform/src/elaborate_drop.rs b/compiler/rustc_mir_transform/src/elaborate_drop.rs index c2c702dbf2470..bc46c0f460aea 100644 --- a/compiler/rustc_mir_transform/src/elaborate_drop.rs +++ b/compiler/rustc_mir_transform/src/elaborate_drop.rs @@ -247,11 +247,19 @@ where // Resolving async_drop_in_place function for drop_ty tcx.require_lang_item(LangItem::AsyncDropInPlace, span) }; + let async_drop_fn_sig = tcx.fn_sig(async_drop_fn_def_id); let fut_ty = tcx .instantiate_bound_regions_with_erased( - // FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes) - Ty::new_fn_def(tcx, async_drop_fn_def_id, ty::Binder::dummy([drop_ty])).fn_sig(tcx), + Ty::new_fn_def_raw( + tcx, + async_drop_fn_def_id, + async_drop_fn_sig + .instantiate(tcx, &[drop_ty.into()]) + .skip_norm_wip() + .rebind([drop_ty]), + ) + .fn_sig(tcx), ) .output(); let fut = self.new_temp(fut_ty); @@ -373,13 +381,7 @@ where unwind_with_dead, vec![self.storage_live(fut)], TerminatorKind::Call { - // FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes) - func: Operand::function_handle( - tcx, - async_drop_fn_def_id, - ty::Binder::dummy([drop_ty.into()]), - span, - ), + func: Operand::function_handle(tcx, async_drop_fn_def_id, &[drop_ty.into()], span), args: [dummy_spanned(drop_arg)].into(), destination: fut.into(), target: Some(succ_yield_loop), @@ -407,8 +409,7 @@ where func: Operand::function_handle( tcx, pin_obj_new_unchecked_fn, - // FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes) - ty::Binder::dummy([obj_ref_ty.into()]), + &[obj_ref_ty.into()], span, ), args: [dummy_spanned(Operand::Move(obj_ref_place))].into(), @@ -573,13 +574,7 @@ where unwind, Vec::new(), TerminatorKind::Call { - // FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes) - func: Operand::function_handle( - tcx, - poll_fn, - ty::Binder::dummy([fut_ty.into()]), - source_info.span, - ), + func: Operand::function_handle(tcx, poll_fn, &[fut_ty.into()], source_info.span), args: [ dummy_spanned(Operand::Move(fut_pin_local.into())), dummy_spanned(Operand::Move(context_ref_local.into())), @@ -608,11 +603,7 @@ where func: Operand::function_handle( tcx, get_context_fn, - // FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes) - ty::Binder::dummy([ - tcx.lifetimes.re_erased.into(), - tcx.lifetimes.re_erased.into(), - ]), + &[tcx.lifetimes.re_erased.into(), tcx.lifetimes.re_erased.into()], source_info.span, ), args: [dummy_spanned(Operand::Move(entry_resume_local.into()))].into(), @@ -642,7 +633,7 @@ where func: Operand::function_handle( tcx, fut_pin_new_unchecked_fn, - ty::Binder::dummy([fut_ref_ty.into()]), + &[fut_ref_ty.into()], source_info.span, ), args: [dummy_spanned(Operand::Move(fut_ref_local.into()))].into(), @@ -1265,13 +1256,7 @@ where ), )], TerminatorKind::Call { - // FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes) - func: Operand::function_handle( - tcx, - drop_fn, - ty::Binder::dummy([ty.into()]), - self.source_info.span, - ), + func: Operand::function_handle(tcx, drop_fn, &[ty.into()], self.source_info.span), args: [dummy_spanned(Operand::Move(Place::from(ref_place)))].into(), destination: unit_temp, target: Some(succ), diff --git a/compiler/rustc_mir_transform/src/shim.rs b/compiler/rustc_mir_transform/src/shim.rs index 519e32baae75f..2ecc9822a84b6 100644 --- a/compiler/rustc_mir_transform/src/shim.rs +++ b/compiler/rustc_mir_transform/src/shim.rs @@ -327,11 +327,10 @@ pub fn build_drop_shim<'tcx>( start.terminator = Some(Terminator { source_info, kind: TerminatorKind::Call { - // FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes) func: Operand::function_handle( tcx, def_id, - ty::Binder::dummy([ty::GenericArg::from(slice_ty)]), + &[ty::GenericArg::from(slice_ty)], span, ), args: Box::new([Spanned { span, node: Operand::Move(Place::from(erased_local)) }]), @@ -624,8 +623,7 @@ impl<'tcx> CloneShimBuilder<'tcx> { let tcx = self.tcx; // `func == Clone::clone(&ty) -> ty` - // FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes) - let func_ty = Ty::new_fn_def(tcx, self.def_id, ty::Binder::dummy([ty])); + let func_ty = tcx.type_of(self.def_id).instantiate(tcx, &[ty.into()]).skip_norm_wip(); let func = Operand::Constant(Box::new(ConstOperand { span: self.span, user_ty: None, diff --git a/compiler/rustc_mir_transform/src/shim/async_destructor_ctor.rs b/compiler/rustc_mir_transform/src/shim/async_destructor_ctor.rs index ccb361cdb0804..194f242fe6cc7 100644 --- a/compiler/rustc_mir_transform/src/shim/async_destructor_ctor.rs +++ b/compiler/rustc_mir_transform/src/shim/async_destructor_ctor.rs @@ -371,13 +371,7 @@ fn build_adrop_for_adrop_shim<'tcx>( Some(Terminator { source_info, kind: TerminatorKind::Call { - // FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes) - func: Operand::function_handle( - tcx, - pin_fn, - ty::Binder::dummy([cor_ref.into()]), - span, - ), + func: Operand::function_handle(tcx, pin_fn, &[cor_ref.into()], span), args: [dummy_spanned(Operand::Move(cor_ref_place))].into(), destination: cor_pin_place, target: Some(call_bb), @@ -398,13 +392,7 @@ fn build_adrop_for_adrop_shim<'tcx>( Some(Terminator { source_info, kind: TerminatorKind::Call { - // FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes) - func: Operand::function_handle( - tcx, - poll_fn, - ty::Binder::dummy([impl_ty.into()]), - span, - ), + func: Operand::function_handle(tcx, poll_fn, &[impl_ty.into()], span), args: [ dummy_spanned(Operand::Move(cor_pin_place)), dummy_spanned(Operand::Move(resume_ctx)), diff --git a/compiler/rustc_next_trait_solver/src/canonical/mod.rs b/compiler/rustc_next_trait_solver/src/canonical/mod.rs index 1e4e3a90f9c4a..560bb15a4db30 100644 --- a/compiler/rustc_next_trait_solver/src/canonical/mod.rs +++ b/compiler/rustc_next_trait_solver/src/canonical/mod.rs @@ -294,6 +294,7 @@ where relate_args_invariantly(self, a_args, b_args)?; Ok(a_ty) } + fn relate_with_variance>( &mut self, _variance: ty::Variance, diff --git a/compiler/rustc_type_ir/src/relate.rs b/compiler/rustc_type_ir/src/relate.rs index fa2e6154ce4f2..d263a0cca9a1e 100644 --- a/compiler/rustc_type_ir/src/relate.rs +++ b/compiler/rustc_type_ir/src/relate.rs @@ -66,8 +66,8 @@ pub trait TypeRelation: Sized { a_ty: I::Ty, b_ty: I::Ty, ty_def_id: I::DefId, - a_arg: I::GenericArgs, - b_arg: I::GenericArgs, + a_args: I::GenericArgs, + b_args: I::GenericArgs, mk: impl FnOnce(I::GenericArgs) -> I::Ty, ) -> RelateResult; @@ -503,12 +503,15 @@ pub fn structurally_relate_tys>( if a_args.skip_binder().is_empty() { Ok(a) } else { - let a_args = a_args.no_bound_vars().unwrap(); - let b_args = b_args.no_bound_vars().unwrap(); - relation.relate_ty_args(a, b, a_def_id.into(), a_args, b_args, |args| { - // FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes) - Ty::new_fn_def(cx, a_def_id, ty::Binder::dummy(args)) - }) + let x = relation.relate_ty_args( + a, + b, + a_def_id.into(), + a_args.skip_binder(), + b_args.skip_binder(), + |args| Ty::new_fn_def(cx, a_def_id, a_args.rebind(args)), + ); + x } } diff --git a/compiler/rustc_type_ir/src/relate/solver_relating.rs b/compiler/rustc_type_ir/src/relate/solver_relating.rs index 930eaa965dfcf..d22f1bf038a7f 100644 --- a/compiler/rustc_type_ir/src/relate/solver_relating.rs +++ b/compiler/rustc_type_ir/src/relate/solver_relating.rs @@ -124,6 +124,7 @@ where combine_ty_args(self.infcx, self, a_ty, b_ty, variances, a_args, b_args, |_| a_ty) } } + fn relate_with_variance>( &mut self, variance: ty::Variance, diff --git a/src/tools/clippy/clippy_lints/src/casts/confusing_method_to_numeric_cast.rs b/src/tools/clippy/clippy_lints/src/casts/confusing_method_to_numeric_cast.rs index 740326d2f9420..93a08d3a12d49 100644 --- a/src/tools/clippy/clippy_lints/src/casts/confusing_method_to_numeric_cast.rs +++ b/src/tools/clippy/clippy_lints/src/casts/confusing_method_to_numeric_cast.rs @@ -65,8 +65,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, if let ty::FnDef(def_id, generics) = cast_from.kind() && let Some(method_name) = cx.tcx.opt_item_name(*def_id) - && let Some((const_name, ty_name)) = - get_const_name_and_ty_name(cx, method_name, *def_id, generics.no_bound_vars().unwrap().as_slice()) + && let Some((const_name, ty_name)) = get_const_name_and_ty_name(cx, method_name, *def_id, generics.no_bound_vars().unwrap().as_slice()) { let mut applicability = Applicability::MaybeIncorrect; let from_snippet = snippet_with_applicability(cx, cast_expr.span, "..", &mut applicability); diff --git a/tests/crashes/133613.rs b/tests/crashes/133613.rs deleted file mode 100644 index 066c50b494772..0000000000000 --- a/tests/crashes/133613.rs +++ /dev/null @@ -1,8 +0,0 @@ -//@ needs-rustc-debug-assertions -//@ known-bug: #133613 - -struct Wrapper<'a>(); - -trait IntFactory { - fn stream(&self) -> impl IntFactory>; -} diff --git a/tests/incremental/hashes/function_interfaces.rs b/tests/incremental/hashes/function_interfaces.rs index 8e9830e0d83d4..cb98d56534e1f 100644 --- a/tests/incremental/hashes/function_interfaces.rs +++ b/tests/incremental/hashes/function_interfaces.rs @@ -156,9 +156,9 @@ pub fn type_parameter() {} pub fn lifetime_parameter () {} #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(cfg = "bpass2", except = "hir_owner, generics_of,fn_sig")] +#[rustc_clean(cfg = "bpass2", except = "hir_owner, generics_of, fn_sig, type_of")] #[rustc_clean(cfg = "bpass3")] -#[rustc_clean(cfg = "bpass5", except = "hir_owner, generics_of,fn_sig")] +#[rustc_clean(cfg = "bpass5", except = "hir_owner, generics_of, fn_sig, type_of")] #[rustc_clean(cfg = "bpass6")] pub fn lifetime_parameter<'a>() {} diff --git a/tests/incremental/hashes/inherent_impls.rs b/tests/incremental/hashes/inherent_impls.rs index edda93ec55127..fa57fa4415fcf 100644 --- a/tests/incremental/hashes/inherent_impls.rs +++ b/tests/incremental/hashes/inherent_impls.rs @@ -146,12 +146,12 @@ impl Foo { impl Foo { #[rustc_clean( cfg="bpass2", - except="hir_owner,fn_sig,generics_of,typeck_root,associated_item,optimized_mir", + except="hir_owner,fn_sig,type_of,generics_of,typeck_root,associated_item,optimized_mir", )] #[rustc_clean(cfg="bpass3")] #[rustc_clean( cfg="bpass5", - except="hir_owner,fn_sig,generics_of,typeck_root,associated_item,optimized_mir", + except="hir_owner,fn_sig,type_of,generics_of,typeck_root,associated_item,optimized_mir", )] #[rustc_clean(cfg="bpass6")] pub fn method_selfness(&self) { } @@ -421,9 +421,9 @@ impl Foo { // ---------------------------------------------------------- // ----------------------------------------------------------- // ---------------------------------------------------------- - // -------------------------------------------------------------- + // ---------------------------------------------------------------------- // ------------------------- - // -------------------------------------------------------------------------- + // ---------------------------------------------------------------------------------- // ------------------------- pub fn add_lifetime_parameter_to_method (&self) { } } @@ -443,9 +443,9 @@ impl Foo { // if we lower generics before the body, then the `HirId` for // things in the body will be affected. So if you start to see // `typeck_root` appear dirty, that might be the cause. -nmatsakis - #[rustc_clean(cfg="bpass2", except="hir_owner,fn_sig")] + #[rustc_clean(cfg="bpass2", except="hir_owner,fn_sig,type_of")] #[rustc_clean(cfg="bpass3")] - #[rustc_clean(cfg="bpass5", except="hir_owner,fn_sig,generics_of")] + #[rustc_clean(cfg="bpass5", except="hir_owner,fn_sig,type_of,generics_of")] #[rustc_clean(cfg="bpass6")] pub fn add_lifetime_parameter_to_method<'a>(&self) { } } diff --git a/tests/incremental/hashes/trait_defs.rs b/tests/incremental/hashes/trait_defs.rs index bb66ad51d993e..e45f6654c3962 100644 --- a/tests/incremental/hashes/trait_defs.rs +++ b/tests/incremental/hashes/trait_defs.rs @@ -380,9 +380,9 @@ trait TraitChangeModeSelfOwnToRef { #[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitChangeModeSelfOwnToRef { - #[rustc_clean(except="hir_owner,fn_sig,generics_of", cfg="bpass2")] + #[rustc_clean(except="hir_owner,fn_sig,type_of,generics_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] - #[rustc_clean(except="hir_owner,fn_sig,generics_of", cfg="bpass5")] + #[rustc_clean(except="hir_owner,fn_sig,type_of,generics_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] fn method(&self); } @@ -509,9 +509,9 @@ trait TraitAddLifetimeParameterToMethod { #[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddLifetimeParameterToMethod { - #[rustc_clean(except="hir_owner,fn_sig,generics_of", cfg="bpass2")] + #[rustc_clean(except="hir_owner,fn_sig,type_of,generics_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] - #[rustc_clean(except="hir_owner,fn_sig,generics_of", cfg="bpass5")] + #[rustc_clean(except="hir_owner,fn_sig,type_of,generics_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] fn method<'a>(); } diff --git a/tests/incremental/hashes/trait_impls.rs b/tests/incremental/hashes/trait_impls.rs index 06b2934cb8a8f..9c773b2920e98 100644 --- a/tests/incremental/hashes/trait_impls.rs +++ b/tests/incremental/hashes/trait_impls.rs @@ -148,12 +148,12 @@ pub trait ChangeMethodSelfnessTrait { #[rustc_clean(cfg="bpass6")] impl ChangeMethodSelfnessTrait for Foo { #[rustc_clean( - except="hir_owner,associated_item,generics_of,fn_sig,typeck_root,optimized_mir", + except="hir_owner,associated_item,generics_of,fn_sig,type_of,typeck_root,optimized_mir", cfg="bpass2", )] #[rustc_clean(cfg="bpass3")] #[rustc_clean( - except="hir_owner,associated_item,generics_of,fn_sig,typeck_root,optimized_mir", + except="hir_owner,associated_item,generics_of,fn_sig,type_of,typeck_root,optimized_mir", cfg="bpass5", )] #[rustc_clean(cfg="bpass6")] @@ -186,12 +186,12 @@ pub trait RemoveMethodSelfnessTrait { #[rustc_clean(cfg="bpass6")] impl RemoveMethodSelfnessTrait for Foo { #[rustc_clean( - except="hir_owner,associated_item,generics_of,fn_sig,typeck_root,optimized_mir", + except="hir_owner,associated_item,generics_of,fn_sig,type_of,typeck_root,optimized_mir", cfg="bpass2", )] #[rustc_clean(cfg="bpass3")] #[rustc_clean( - except="hir_owner,associated_item,generics_of,fn_sig,typeck_root,optimized_mir", + except="hir_owner,associated_item,generics_of,fn_sig,type_of,typeck_root,optimized_mir", cfg="bpass5", )] #[rustc_clean(cfg="bpass6")] diff --git a/tests/ui/generics/binder-arg-overflow-regression-133613.rs b/tests/ui/generics/binder-arg-overflow-regression-133613.rs new file mode 100644 index 0000000000000..ad4e6c70eb8fe --- /dev/null +++ b/tests/ui/generics/binder-arg-overflow-regression-133613.rs @@ -0,0 +1,18 @@ +//! Regression test for #133613 +//! This was a crash regarding bound vars and generic arg indexing. +//! The bound var index was used to index self.args, and caused OOB. +//! Because of new changes to how the compiler handles binders, this was fixed. + +//@ needs-rustc-debug-assertions + +struct Wrapper<'a>(); + +// FIXME: these errors are probably wrong +trait IntFactory { + fn stream(&self) -> impl IntFactory>; + //~^ ERROR: cycle detected when looking up late bound vars inside `IntFactory::stream` [E0391] + //~^^ ERROR: return type notation is experimental + //~^^^ ERROR: return type notation is experimental +} + +fn main() {} diff --git a/tests/ui/generics/binder-arg-overflow-regression-133613.stderr b/tests/ui/generics/binder-arg-overflow-regression-133613.stderr new file mode 100644 index 0000000000000..e56467ea507e9 --- /dev/null +++ b/tests/ui/generics/binder-arg-overflow-regression-133613.stderr @@ -0,0 +1,36 @@ +error[E0658]: return type notation is experimental + --> $DIR/binder-arg-overflow-regression-133613.rs:12:47 + | +LL | fn stream(&self) -> impl IntFactory>; + | ^^^^ + | + = note: see issue #109417 for more information + = help: add `#![feature(return_type_notation)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: return type notation is experimental + --> $DIR/binder-arg-overflow-regression-133613.rs:12:70 + | +LL | fn stream(&self) -> impl IntFactory>; + | ^^^^ + | + = note: see issue #109417 for more information + = help: add `#![feature(return_type_notation)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0391]: cycle detected when looking up late bound vars inside `IntFactory::stream` + --> $DIR/binder-arg-overflow-regression-133613.rs:12:5 + | +LL | fn stream(&self) -> impl IntFactory>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: ...which requires resolving lifetimes for `IntFactory::stream`... + = note: ...which requires computing function signature of `IntFactory::stream`... + = note: ...which again requires looking up late bound vars inside `IntFactory::stream`, completing the cycle + = note: cycle used when computing type of `IntFactory::stream` + = note: for more information, see and + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0391, E0658. +For more information about an error, try `rustc --explain E0391`. diff --git a/tests/ui/thir-print/thir-tree-match-for.stdout b/tests/ui/thir-print/thir-tree-match-for.stdout index 0cf759c40c4ff..9d8f1677fe62f 100644 --- a/tests/ui/thir-print/thir-tree-match-for.stdout +++ b/tests/ui/thir-print/thir-tree-match-for.stdout @@ -560,12 +560,12 @@ body: span: $DIR/thir-tree-match-for.rs:16:12: 16:16 (#7) kind: Call { - ty: FnDef(DefId(N:M ~ core::iter::traits::iterator::Iterator::next), Binder { value: [std::ops::Range], bound_vars: [] }) + ty: FnDef(DefId(N:M ~ core::iter::traits::iterator::Iterator::next), Binder { value: [std::ops::Range], bound_vars: [Region(BrNamed(DefId(N:M ~ core::iter::traits::iterator::Iterator::next::'_)))] }) from_hir_call: true fn_span: $DIR/thir-tree-match-for.rs:16:12: 16:16 (#7) fun: Expr { - ty: FnDef(DefId(N:M ~ core::iter::traits::iterator::Iterator::next), Binder { value: [std::ops::Range], bound_vars: [] }) + ty: FnDef(DefId(N:M ~ core::iter::traits::iterator::Iterator::next), Binder { value: [std::ops::Range], bound_vars: [Region(BrNamed(DefId(N:M ~ core::iter::traits::iterator::Iterator::next::'_)))] }) temp_scope_id: 34 span: $DIR/thir-tree-match-for.rs:16:12: 16:16 (#7) kind: @@ -574,7 +574,7 @@ body: hir_id: HirId(DefId(N:M ~ thir_tree_match_for::match_from_for).34) value: Expr { - ty: FnDef(DefId(N:M ~ core::iter::traits::iterator::Iterator::next), Binder { value: [std::ops::Range], bound_vars: [] }) + ty: FnDef(DefId(N:M ~ core::iter::traits::iterator::Iterator::next), Binder { value: [std::ops::Range], bound_vars: [Region(BrNamed(DefId(N:M ~ core::iter::traits::iterator::Iterator::next::'_)))] }) temp_scope_id: 34 span: $DIR/thir-tree-match-for.rs:16:12: 16:16 (#7) kind: @@ -1117,12 +1117,12 @@ body: span: $DIR/thir-tree-match-for.rs:25:13: 25:38 (#0) kind: Call { - ty: FnDef(DefId(N:M ~ core::iter::traits::iterator::Iterator::next), Binder { value: [std::ops::Range], bound_vars: [] }) + ty: FnDef(DefId(N:M ~ core::iter::traits::iterator::Iterator::next), Binder { value: [std::ops::Range], bound_vars: [Region(BrNamed(DefId(N:M ~ core::iter::traits::iterator::Iterator::next::'_)))] }) from_hir_call: true fn_span: $DIR/thir-tree-match-for.rs:25:13: 25:38 (#0) fun: Expr { - ty: FnDef(DefId(N:M ~ core::iter::traits::iterator::Iterator::next), Binder { value: [std::ops::Range], bound_vars: [] }) + ty: FnDef(DefId(N:M ~ core::iter::traits::iterator::Iterator::next), Binder { value: [std::ops::Range], bound_vars: [Region(BrNamed(DefId(N:M ~ core::iter::traits::iterator::Iterator::next::'_)))] }) temp_scope_id: 25 span: $DIR/thir-tree-match-for.rs:25:13: 25:27 (#0) kind: @@ -1131,7 +1131,7 @@ body: hir_id: HirId(DefId(N:M ~ thir_tree_match_for::match_loop_nonfor).25) value: Expr { - ty: FnDef(DefId(N:M ~ core::iter::traits::iterator::Iterator::next), Binder { value: [std::ops::Range], bound_vars: [] }) + ty: FnDef(DefId(N:M ~ core::iter::traits::iterator::Iterator::next), Binder { value: [std::ops::Range], bound_vars: [Region(BrNamed(DefId(N:M ~ core::iter::traits::iterator::Iterator::next::'_)))] }) temp_scope_id: 25 span: $DIR/thir-tree-match-for.rs:25:13: 25:27 (#0) kind: From 4cf5791c124496d23704c7aff2c9312fa6593ac2 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 28 May 2026 11:36:15 +1000 Subject: [PATCH 02/41] Many "predicate"-to-"clause" renamings Lots of names weren't changed to account for the introduction of the `Clause` type as a specialized form of `Predicate`, presumably because it was tedious. This commit converts as many of them as I could find. It's mostly very tedious renamings of types, functions, variables, and queries. The more interesting ones are a couple of files (`predicates_of.rs`, `impossible_predicates.rs`) and a MIR pass (`ImpossiblePredicates`). --- .../src/diagnostics/conflict_errors.rs | 8 +- .../src/diagnostics/move_errors.rs | 12 +- .../src/diagnostics/mutability_errors.rs | 12 +- .../src/diagnostics/region_errors.rs | 8 +- .../src/diagnostics/region_name.rs | 12 +- .../src/type_check/canonical.rs | 10 +- compiler/rustc_borrowck/src/type_check/mod.rs | 28 +- .../rustc_const_eval/src/interpret/intern.rs | 2 +- .../src/check/always_applicable.rs | 2 +- .../rustc_hir_analysis/src/check/check.rs | 44 +-- .../src/check/compare_impl_item.rs | 153 +++++----- .../src/check/compare_impl_item/refine.rs | 8 +- .../rustc_hir_analysis/src/check/entry.rs | 6 +- compiler/rustc_hir_analysis/src/check/mod.rs | 26 +- .../rustc_hir_analysis/src/check/wfcheck.rs | 78 ++--- compiler/rustc_hir_analysis/src/collect.rs | 30 +- .../{predicates_of.rs => clauses_of.rs} | 288 +++++++++--------- .../rustc_hir_analysis/src/collect/dump.rs | 12 +- .../src/collect/generics_of.rs | 4 +- .../src/collect/item_bounds.rs | 16 +- .../src/constrained_generic_params.rs | 33 +- compiler/rustc_hir_analysis/src/delegation.rs | 76 +++-- .../rustc_hir_analysis/src/impl_wf_check.rs | 8 +- .../src/impl_wf_check/min_specialization.rs | 8 +- compiler/rustc_hir_analysis/src/lib.rs | 2 +- .../src/outlives/explicit.rs | 14 +- .../src/outlives/implicit_infer.rs | 15 +- compiler/rustc_hir_typeck/src/callee.rs | 14 +- compiler/rustc_hir_typeck/src/expr.rs | 10 +- .../rustc_hir_typeck/src/fn_ctxt/_impl.rs | 12 +- .../src/fn_ctxt/adjust_fulfillment_errors.rs | 29 +- .../rustc_hir_typeck/src/fn_ctxt/checks.rs | 6 +- compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs | 4 +- .../rustc_hir_typeck/src/method/confirm.rs | 46 +-- compiler/rustc_hir_typeck/src/method/mod.rs | 6 +- compiler/rustc_hir_typeck/src/method/probe.rs | 4 +- .../rustc_incremental/src/persist/clean.rs | 6 +- compiler/rustc_infer/src/traits/util.rs | 2 +- compiler/rustc_lint/src/builtin.rs | 10 +- compiler/rustc_lint/src/internal.rs | 17 +- compiler/rustc_lint/src/lints.rs | 14 +- .../src/multiple_supertrait_upcastable.rs | 4 +- compiler/rustc_lint/src/traits.rs | 8 +- .../src/rmeta/decoder/cstore_impl.rs | 6 +- compiler/rustc_metadata/src/rmeta/encoder.rs | 18 +- compiler/rustc_metadata/src/rmeta/mod.rs | 6 +- .../rustc_metadata/src/rmeta/parameterized.rs | 2 +- compiler/rustc_middle/src/mono.rs | 2 +- compiler/rustc_middle/src/queries.rs | 64 ++-- compiler/rustc_middle/src/query/erase.rs | 2 +- compiler/rustc_middle/src/traits/mod.rs | 8 +- compiler/rustc_middle/src/ty/adt.rs | 6 +- .../src/ty/context/impl_interner.rs | 18 +- compiler/rustc_middle/src/ty/generics.rs | 42 +-- compiler/rustc_middle/src/ty/mod.rs | 38 +-- compiler/rustc_middle/src/ty/print/pretty.rs | 4 +- .../src/coroutine/by_move_body.rs | 4 +- ...le_predicates.rs => impossible_clauses.rs} | 49 +-- compiler/rustc_mir_transform/src/lib.rs | 4 +- .../rustc_mir_transform/src/trivial_const.rs | 4 +- compiler/rustc_monomorphize/src/collector.rs | 6 +- .../src/solve/assembly/structural_traits.rs | 2 +- .../src/solve/effect_goals.rs | 8 +- .../src/solve/normalizes_to.rs | 16 +- .../src/solve/project_goals/free_alias.rs | 4 +- .../src/solve/project_goals/inherent.rs | 4 +- .../src/solve/trait_goals.rs | 8 +- compiler/rustc_privacy/src/lib.rs | 52 ++-- .../rustc_public/src/compiler_interface.rs | 18 +- compiler/rustc_public/src/ty.rs | 12 +- .../rustc_public_bridge/src/context/impls.rs | 23 +- compiler/rustc_query_impl/src/job.rs | 4 +- .../src/error_reporting/infer/region.rs | 14 +- .../src/error_reporting/traits/ambiguity.rs | 16 +- .../traits/fulfillment_errors.rs | 6 +- .../src/error_reporting/traits/mod.rs | 22 +- .../src/error_reporting/traits/suggestions.rs | 48 +-- .../src/solve/fulfill/derive_errors.rs | 6 +- .../src/traits/coherence.rs | 4 +- .../src/traits/const_evaluatable.rs | 2 +- .../src/traits/dyn_compatibility.rs | 46 +-- .../rustc_trait_selection/src/traits/mod.rs | 111 ++++--- .../src/traits/normalize.rs | 12 +- .../src/traits/project.rs | 24 +- .../traits/query/type_op/ascribe_user_type.rs | 16 +- .../src/traits/select/candidate_assembly.rs | 4 +- .../src/traits/select/confirmation.rs | 2 +- .../src/traits/select/mod.rs | 14 +- .../src/traits/specialize/mod.rs | 13 +- .../rustc_trait_selection/src/traits/util.rs | 2 +- .../src/traits/vtable.rs | 20 +- .../rustc_trait_selection/src/traits/wf.rs | 24 +- .../src/normalize_projection_ty.rs | 7 +- compiler/rustc_ty_utils/src/implied_bounds.rs | 2 +- compiler/rustc_ty_utils/src/instance.rs | 8 +- compiler/rustc_ty_utils/src/sig_types.rs | 18 +- compiler/rustc_ty_utils/src/ty.rs | 21 +- compiler/rustc_type_ir/src/binder.rs | 2 +- compiler/rustc_type_ir/src/elaborate.rs | 13 +- compiler/rustc_type_ir/src/interner.rs | 8 +- compiler/rustc_type_ir/src/unnormalized.rs | 2 +- .../rustc-dev-guide/src/compiler-debugging.md | 4 +- src/doc/rustc-dev-guide/src/effects.md | 10 +- .../return-position-impl-trait-in-trait.md | 14 +- .../src/traits/implied-bounds.md | 6 +- .../src/typing-parameter-envs.md | 4 +- src/librustdoc/clean/auto_trait.rs | 6 +- src/librustdoc/clean/blanket_impl.rs | 10 +- src/librustdoc/clean/mod.rs | 45 ++- src/librustdoc/clean/simplify.rs | 2 +- .../derive/derive_partial_eq_without_eq.rs | 8 +- .../src/implied_bounds_in_impls.rs | 2 +- .../clippy/clippy_lints/src/inherent_impl.rs | 16 +- .../clippy_lints/src/large_stack_frames.rs | 4 +- .../iter_on_single_or_empty_collections.rs | 4 +- .../src/methods/type_id_on_box.rs | 2 +- .../src/methods/unnecessary_to_owned.rs | 4 +- .../clippy_lints/src/missing_const_for_fn.rs | 4 +- .../src/missing_const_for_thread_local.rs | 4 +- .../clippy_lints/src/needless_maybe_sized.rs | 2 +- .../clippy_lints/src/redundant_clone.rs | 4 +- .../src/unit_return_expecting_ord.rs | 21 +- .../clippy_lints/src/useless_conversion.rs | 4 +- src/tools/clippy/clippy_utils/src/consts.rs | 2 +- .../clippy/clippy_utils/src/eager_or_lazy.rs | 4 +- src/tools/clippy/clippy_utils/src/lib.rs | 12 +- src/tools/clippy/clippy_utils/src/ty/mod.rs | 8 +- .../item-collection/drop-glue-eager.rs | 2 +- tests/incremental/clean.rs | 4 +- tests/incremental/cyclic-trait-hierarchy.rs | 2 +- tests/incremental/hashes/enum_defs.rs | 40 +-- .../incremental/hashes/function_interfaces.rs | 30 +- tests/incremental/hashes/inherent_impls.rs | 32 +- tests/incremental/hashes/struct_defs.rs | 28 +- tests/incremental/hashes/trait_defs.rs | 246 +++++++-------- tests/incremental/hashes/trait_impls.rs | 4 +- ....impossible_clause.ImpossibleClauses.diff} | 6 +- tests/mir-opt/impossible_clauses.rs | 10 + tests/mir-opt/impossible_predicates.rs | 10 - .../ambiguous-associated-type2.stderr | 2 +- .../implied-bounds-cycle.rs | 2 +- .../implied-bounds-cycle.stderr | 4 +- tests/ui/associated-types/issue-20825.stderr | 2 +- .../cycle-trait-supertrait-direct.stderr | 4 +- .../cycle-trait-supertrait-indirect.stderr | 8 +- tests/ui/cycle-trait/issue-12511.stderr | 6 +- .../trivially-unsatisfied-bounds.rs | 2 +- .../infinite-trait-alias-recursion.rs | 2 +- .../infinite-trait-alias-recursion.stderr | 8 +- .../generic_struct_field_projection.rs | 4 +- .../ui/traits/alias/infinite_normalization.rs | 2 +- .../alias/infinite_normalization.stderr | 4 +- .../solver-cycles/self-item-cycle.stderr | 2 +- .../cyclic-trait-resolution.rs | 4 +- .../cyclic-trait-resolution.stderr | 8 +- 155 files changed, 1339 insertions(+), 1373 deletions(-) rename compiler/rustc_hir_analysis/src/collect/{predicates_of.rs => clauses_of.rs} (83%) rename compiler/rustc_mir_transform/src/{impossible_predicates.rs => impossible_clauses.rs} (73%) rename tests/mir-opt/{impossible_predicates.impossible_predicate.ImpossiblePredicates.diff => impossible_clauses.impossible_clause.ImpossibleClauses.diff} (74%) create mode 100644 tests/mir-opt/impossible_clauses.rs delete mode 100644 tests/mir-opt/impossible_predicates.rs diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index 8a9db246d7c15..8d1f9cea853f9 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -671,7 +671,7 @@ impl<'diag, 'tcx> MirBorrowckCtxt<'_, 'diag, 'tcx> { ) -> Option { let tcx = self.infcx.tcx; let sig = tcx.fn_sig(callee_did).instantiate_identity().skip_binder(); - let clauses = tcx.predicates_of(callee_did); + let clauses = tcx.clauses_of(callee_did); let generic_args = match call_expr.kind { // For method calls, generic arguments are attached to the call node. @@ -688,7 +688,7 @@ impl<'diag, 'tcx> MirBorrowckCtxt<'_, 'diag, 'tcx> { // First, is there at least one method on one of `param`'s trait bounds? // This keeps us from suggesting borrowing the argument to `mem::drop`, e.g. - if !clauses.instantiate_identity(tcx).predicates.iter().any(|clause| { + if !clauses.instantiate_identity(tcx).clauses.iter().any(|clause| { clause.as_trait_clause().is_some_and(|tc| { tc.self_ty().skip_binder().is_param(param.index) && tc.polarity() == ty::PredicatePolarity::Positive @@ -738,8 +738,8 @@ impl<'diag, 'tcx> MirBorrowckCtxt<'_, 'diag, 'tcx> { return false; } - // Test the callee's predicates, substituting in `ref_ty` for the moved argument type. - clauses.instantiate(tcx, new_args).predicates.iter().all(|clause| { + // Test the callee's clauses, substituting in `ref_ty` for the moved argument type. + clauses.instantiate(tcx, new_args).clauses.iter().all(|clause| { // Normalize before testing to see through type aliases and projections. let normalized = tcx .try_normalize_erasing_regions( diff --git a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs index ed4e25f009aed..99cd7104692e1 100644 --- a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs @@ -643,26 +643,26 @@ impl<'diag, 'tcx> MirBorrowckCtxt<'_, 'diag, 'tcx> { let closure_hir_id = tcx.local_def_id_to_hir_id(def_id.expect_local()); let hir::Node::Expr(parent) = tcx.parent_hir_node(closure_hir_id) else { return None }; - let predicates = match parent.kind { + let gen_clauses = match parent.kind { hir::ExprKind::Call(callee, _) => { let ty = typeck_result.node_type_opt(callee.hir_id)?; let ty::FnDef(fn_def_id, args) = *ty.kind() else { return None }; - tcx.predicates_of(fn_def_id).instantiate(tcx, args.no_bound_vars().unwrap()) + tcx.clauses_of(fn_def_id).instantiate(tcx, args.no_bound_vars().unwrap()) } hir::ExprKind::MethodCall(..) => { let (_, method) = typeck_result.type_dependent_def(parent.hir_id)?; let args = typeck_result.node_args(parent.hir_id); - tcx.predicates_of(method).instantiate(tcx, args) + tcx.clauses_of(method).instantiate(tcx, args) } _ => return None, }; // Check whether one of the where-bounds requires the closure to impl `Fn[Mut]` // or `AsyncFn[Mut]`. - for (pred, span) in predicates.predicates.iter().zip(predicates.spans.iter()) { - let pred = pred.skip_norm_wip(); + for (clause, span) in gen_clauses.clauses.iter().zip(gen_clauses.spans.iter()) { + let clause = clause.skip_norm_wip(); let dominated_by_fn_trait = self - .closure_clause_kind(pred, def_id, asyncness) + .closure_clause_kind(clause, def_id, asyncness) .is_some_and(|kind| matches!(kind, ty::ClosureKind::Fn | ty::ClosureKind::FnMut)); if dominated_by_fn_trait { // Found `` or diff --git a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs index cce2bba7b3365..56dc3ed8c8600 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs @@ -1210,19 +1210,17 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> { return false; }; - tcx.predicates_of(callee_def_id) - .instantiate(tcx, generic_args) - .predicates - .iter() - .any(|predicate| { - predicate.as_trait_clause().is_some_and(|trait_pred| { + tcx.clauses_of(callee_def_id).instantiate(tcx, generic_args).clauses.iter().any( + |clause| { + clause.as_trait_clause().is_some_and(|trait_pred| { trait_pred.polarity() == ty::PredicatePolarity::Positive && tcx.fn_trait_kind_from_def_id(trait_pred.def_id()) == Some(ty::ClosureKind::Fn) && trait_pred.self_ty().skip_binder().peel_refs() == input_ty.peel_refs() }) - }) + }, + ) }; // If the HIR node is a function or method call, get the DefId diff --git a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs index 72eff72c7f9ed..e32ac17fd8016 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs @@ -1167,17 +1167,17 @@ impl<'diag, 'tcx> MirBorrowckCtxt<'_, 'diag, 'tcx> { } }); - let preds = tcx.predicates_of(method_def_id).instantiate(tcx, args); + let clauses = tcx.clauses_of(method_def_id).instantiate(tcx, args); let ocx = ObligationCtxt::new(&self.infcx); - ocx.register_obligations(preds.iter().map(|(pred, span)| { - trace!(?pred); + ocx.register_obligations(clauses.iter().map(|(clause, span)| { + trace!(?clause); Obligation::misc( tcx, span, self.mir_def_id(), self.infcx.param_env, - pred.skip_norm_wip(), + clause.skip_norm_wip(), ) })); diff --git a/compiler/rustc_borrowck/src/diagnostics/region_name.rs b/compiler/rustc_borrowck/src/diagnostics/region_name.rs index 1e15382c3e54b..822078da2c727 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_name.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_name.rs @@ -1065,12 +1065,12 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> { return None; }; - let predicates: Vec<_> = self + let clauses: Vec<_> = self .infcx .tcx - .predicates_of(self.body.source.def_id()) + .clauses_of(self.body.source.def_id()) .instantiate_identity(self.infcx.tcx) - .predicates + .clauses .into_iter() .map(Unnormalized::skip_norm_wip) .collect(); @@ -1081,7 +1081,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> { .defining_ty .upvar_tys() .iter() - .position(|ty| self.any_param_predicate_mentions(&predicates, ty, region)) + .position(|ty| self.any_param_clause_mentions(&clauses, ty, region)) { let (upvar_name, upvar_span) = self.regioncx.get_upvar_name_and_span_for_region( self.infcx.tcx, @@ -1099,7 +1099,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> { .universal_regions() .unnormalized_input_tys .iter() - .position(|ty| self.any_param_predicate_mentions(&predicates, *ty, region)) + .position(|ty| self.any_param_clause_mentions(&clauses, *ty, region)) { let (arg_name, arg_span) = self.regioncx.get_argument_name_and_span_for_region( self.body, @@ -1119,7 +1119,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> { } } - fn any_param_predicate_mentions( + fn any_param_clause_mentions( &self, clauses: &[ty::Clause<'tcx>], ty: Ty<'tcx>, diff --git a/compiler/rustc_borrowck/src/type_check/canonical.rs b/compiler/rustc_borrowck/src/type_check/canonical.rs index 08b0ec8edbca2..5931d6f7370b0 100644 --- a/compiler/rustc_borrowck/src/type_check/canonical.rs +++ b/compiler/rustc_borrowck/src/type_check/canonical.rs @@ -141,18 +141,18 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { } #[instrument(level = "debug", skip(self))] - pub(super) fn normalize_and_prove_instantiated_predicates( + pub(super) fn normalize_and_prove_instantiated_clauses( &mut self, // Keep this parameter for now, in case we start using // it in `ConstraintCategory` at some point. _def_id: DefId, - instantiated_predicates: ty::InstantiatedPredicates<'tcx>, + instantiated_clauses: ty::InstantiatedClauses<'tcx>, locations: Locations, ) { - for (predicate, span) in instantiated_predicates { - debug!(?span, ?predicate); + for (clause, span) in instantiated_clauses { + debug!(?span, ?clause); let category = ConstraintCategory::Predicate(span); - let clause = self.normalize_with_category(predicate, locations, category); + let clause = self.normalize_with_category(clause, locations, category); self.prove_clause(clause, locations, category); } } diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index 370d43d35d3ac..47ff62e9f85a8 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -1489,7 +1489,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { if self.infcx.type_is_sized_modulo_regions(self.infcx.param_env, dst.ty) { // Wide to thin ptr cast. This may even occur in an env with - // impossible predicates, such as `where dyn Trait: Sized`. + // impossible clauses, such as `where dyn Trait: Sized`. // In this case, we don't want to fall into the case below, // since the types may not actually be equatable, but it's // fine to perform this operation in an impossible env. @@ -1722,10 +1722,10 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { && tcx.anon_const_kind(def_id) == ty::AnonConstKind::NonTypeSystemInline { let def_id = def_id.expect_local(); - let predicates = self.prove_closure_bounds(tcx, def_id, uv.args, location); - self.normalize_and_prove_instantiated_predicates( + let clauses = self.prove_closure_bounds(tcx, def_id, uv.args, location); + self.normalize_and_prove_instantiated_clauses( def_id.to_def_id(), - predicates, + clauses, location.to_locations(), ); } @@ -1840,10 +1840,10 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { if let ty::FnDef(def_id, args) = *constant.const_.ty().kind() { let args = args.no_bound_vars().unwrap(); - let instantiated_predicates = tcx.predicates_of(def_id).instantiate(tcx, args); - self.normalize_and_prove_instantiated_predicates( + let instantiated_clauses = tcx.clauses_of(def_id).instantiate(tcx, args); + self.normalize_and_prove_instantiated_clauses( def_id, - instantiated_predicates, + instantiated_clauses, locations, ); @@ -2603,9 +2603,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { aggregate_kind, location ); - let (def_id, instantiated_predicates) = match *aggregate_kind { + let (def_id, instantiated_clauses) = match *aggregate_kind { AggregateKind::Adt(adt_did, _, args, _, _) => { - (adt_did, tcx.predicates_of(adt_did).instantiate(tcx, args)) + (adt_did, tcx.clauses_of(adt_did).instantiate(tcx, args)) } // For closures, we have some **extra requirements** we @@ -2634,13 +2634,13 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { } AggregateKind::Array(_) | AggregateKind::Tuple | AggregateKind::RawPtr(..) => { - (CRATE_DEF_ID.to_def_id(), ty::InstantiatedPredicates::empty()) + (CRATE_DEF_ID.to_def_id(), ty::InstantiatedClauses::empty()) } }; - self.normalize_and_prove_instantiated_predicates( + self.normalize_and_prove_instantiated_clauses( def_id, - instantiated_predicates, + instantiated_clauses, location.to_locations(), ); } @@ -2651,7 +2651,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { def_id: LocalDefId, args: GenericArgsRef<'tcx>, location: Location, - ) -> ty::InstantiatedPredicates<'tcx> { + ) -> ty::InstantiatedClauses<'tcx> { let root_def_id = self.root_cx.root_def_id(); // We will have to handle propagated closure requirements for this closure, // but need to defer this until the nested body has been fully borrow checked. @@ -2695,7 +2695,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { ); } - tcx.predicates_of(def_id).instantiate(tcx, args) + tcx.clauses_of(def_id).instantiate(tcx, args) } } diff --git a/compiler/rustc_const_eval/src/interpret/intern.rs b/compiler/rustc_const_eval/src/interpret/intern.rs index f74a85c7340ae..ecc00547e4599 100644 --- a/compiler/rustc_const_eval/src/interpret/intern.rs +++ b/compiler/rustc_const_eval/src/interpret/intern.rs @@ -172,7 +172,7 @@ fn intern_as_new_static<'tcx>( feed.eval_static_initializer(Ok(alloc)); feed.generics_of(tcx.generics_of(static_id).clone()); feed.def_ident_span(tcx.def_ident_span(static_id)); - feed.explicit_predicates_of(tcx.explicit_predicates_of(static_id)); + feed.explicit_clauses_of(tcx.explicit_clauses_of(static_id)); feed.feed_hir(); } diff --git a/compiler/rustc_hir_analysis/src/check/always_applicable.rs b/compiler/rustc_hir_analysis/src/check/always_applicable.rs index 9a8008214ed04..b9c0011d1a4ff 100644 --- a/compiler/rustc_hir_analysis/src/check/always_applicable.rs +++ b/compiler/rustc_hir_analysis/src/check/always_applicable.rs @@ -293,7 +293,7 @@ fn ensure_impl_predicates_are_implied_by_item_defn<'tcx>( ocx.eq(&ObligationCause::dummy_with_span(impl_span), adt_env, fresh_adt_ty, impl_adt_ty) .expect("equating fully generic trait ref should never fail"); - for (clause, span) in tcx.predicates_of(impl_def_id).instantiate(tcx, fresh_impl_args) { + for (clause, span) in tcx.clauses_of(impl_def_id).instantiate(tcx, fresh_impl_args) { let normalize_cause = traits::ObligationCause::misc(span, impl_def_id); let pred = ocx.normalize(&normalize_cause, adt_env, clause); let cause = traits::ObligationCause::new( diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index 626529cb6fc5b..26d289a0fc70c 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -792,7 +792,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), DefKind::Static { .. } => { tcx.ensure_ok().generics_of(def_id); tcx.ensure_ok().type_of(def_id); - tcx.ensure_ok().predicates_of(def_id); + tcx.ensure_ok().clauses_of(def_id); check_static_inhabited(tcx, def_id); check_static_linkage(tcx, def_id); @@ -809,7 +809,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), DefKind::Enum => { tcx.ensure_ok().generics_of(def_id); tcx.ensure_ok().type_of(def_id); - tcx.ensure_ok().predicates_of(def_id); + tcx.ensure_ok().clauses_of(def_id); crate::collect::check_enum_variant_types(tcx, def_id); check_enum(tcx, def_id); check_variances_for_type_defn(tcx, def_id); @@ -820,7 +820,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), DefKind::Fn => { tcx.ensure_ok().generics_of(def_id); tcx.ensure_ok().type_of(def_id); - tcx.ensure_ok().predicates_of(def_id); + tcx.ensure_ok().clauses_of(def_id); tcx.ensure_ok().fn_sig(def_id); tcx.ensure_ok().codegen_fn_attrs(def_id); if let Some(i) = tcx.intrinsic(def_id) { @@ -835,7 +835,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), DefKind::Impl { of_trait } => { tcx.ensure_ok().generics_of(def_id); tcx.ensure_ok().type_of(def_id); - tcx.ensure_ok().predicates_of(def_id); + tcx.ensure_ok().clauses_of(def_id); tcx.ensure_ok().associated_items(def_id); if of_trait { let impl_trait_header = tcx.impl_trait_header(def_id); @@ -853,8 +853,8 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), DefKind::Trait => { tcx.ensure_ok().generics_of(def_id); tcx.ensure_ok().trait_def(def_id); - tcx.ensure_ok().explicit_super_predicates_of(def_id); - tcx.ensure_ok().predicates_of(def_id); + tcx.ensure_ok().explicit_super_clauses_of(def_id); + tcx.ensure_ok().clauses_of(def_id); tcx.ensure_ok().associated_items(def_id); let assoc_items = tcx.associated_items(def_id); @@ -879,9 +879,9 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), } DefKind::TraitAlias => { tcx.ensure_ok().generics_of(def_id); - tcx.ensure_ok().explicit_implied_predicates_of(def_id); - tcx.ensure_ok().explicit_super_predicates_of(def_id); - tcx.ensure_ok().predicates_of(def_id); + tcx.ensure_ok().explicit_implied_clauses_of(def_id); + tcx.ensure_ok().explicit_super_clauses_of(def_id); + tcx.ensure_ok().clauses_of(def_id); res = res.and(wfcheck::check_trait(tcx, def_id)); // Trait aliases do not have hir checks anymore return res; @@ -889,13 +889,13 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), def_kind @ (DefKind::Struct | DefKind::Union) => { tcx.ensure_ok().generics_of(def_id); tcx.ensure_ok().type_of(def_id); - tcx.ensure_ok().predicates_of(def_id); + tcx.ensure_ok().clauses_of(def_id); let adt = tcx.adt_def(def_id).non_enum_variant(); for f in adt.fields.iter() { tcx.ensure_ok().generics_of(f.did); tcx.ensure_ok().type_of(f.did); - tcx.ensure_ok().predicates_of(f.did); + tcx.ensure_ok().clauses_of(f.did); } if let Some((_, ctor_def_id)) = adt.ctor { @@ -924,7 +924,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), check_opaque(tcx, def_id); } - tcx.ensure_ok().predicates_of(def_id); + tcx.ensure_ok().clauses_of(def_id); tcx.ensure_ok().explicit_item_bounds(def_id); tcx.ensure_ok().explicit_item_self_bounds(def_id); if tcx.is_conditionally_const(def_id) { @@ -940,7 +940,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), DefKind::Const { .. } => { tcx.ensure_ok().generics_of(def_id); tcx.ensure_ok().type_of(def_id); - tcx.ensure_ok().predicates_of(def_id); + tcx.ensure_ok().clauses_of(def_id); res = res.and(enter_wf_checking_ctxt(tcx, def_id, |wfcx| { let ty = tcx.type_of(def_id).instantiate_identity(); @@ -973,7 +973,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), DefKind::TyAlias => { tcx.ensure_ok().generics_of(def_id); tcx.ensure_ok().type_of(def_id); - tcx.ensure_ok().predicates_of(def_id); + tcx.ensure_ok().clauses_of(def_id); let ty = tcx.type_of(def_id).instantiate_identity(); let span = tcx.def_span(def_id); if tcx.type_alias_is_checked(def_id) { @@ -1069,7 +1069,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), tcx.ensure_ok().generics_of(def_id); tcx.ensure_ok().type_of(def_id); - tcx.ensure_ok().predicates_of(def_id); + tcx.ensure_ok().clauses_of(def_id); if tcx.is_conditionally_const(def_id) { tcx.ensure_ok().explicit_implied_const_bounds(def_id); tcx.ensure_ok().const_conditions(def_id); @@ -1109,7 +1109,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), tcx.ensure_ok().codegen_fn_attrs(def_id); tcx.ensure_ok().type_of(def_id); tcx.ensure_ok().fn_sig(def_id); - tcx.ensure_ok().predicates_of(def_id); + tcx.ensure_ok().clauses_of(def_id); res = res.and(check_associated_item(tcx, def_id)); let assoc_item = tcx.associated_item(def_id); match assoc_item.container { @@ -1126,7 +1126,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), } DefKind::AssocConst { .. } => { tcx.ensure_ok().type_of(def_id); - tcx.ensure_ok().predicates_of(def_id); + tcx.ensure_ok().clauses_of(def_id); res = res.and(check_associated_item(tcx, def_id)); let assoc_item = tcx.associated_item(def_id); match assoc_item.container { @@ -1142,7 +1142,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), return res; } DefKind::AssocTy => { - tcx.ensure_ok().predicates_of(def_id); + tcx.ensure_ok().clauses_of(def_id); res = res.and(check_associated_item(tcx, def_id)); let assoc_item = tcx.associated_item(def_id); @@ -2071,11 +2071,11 @@ fn check_type_alias_type_params_are_used<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalD // Lazily calculated because it is only needed in case of an error. let bounded_params = LazyCell::new(|| { - tcx.explicit_predicates_of(def_id) - .predicates + tcx.explicit_clauses_of(def_id) + .clauses .iter() - .filter_map(|(predicate, span)| { - let bounded_ty = match predicate.kind().skip_binder() { + .filter_map(|(clause, span)| { + let bounded_ty = match clause.kind().skip_binder() { ty::ClauseKind::Trait(pred) => pred.trait_ref.self_ty(), ty::ClauseKind::TypeOutlives(pred) => pred.0, _ => return None, diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs index 6489c626084a0..e9add5aa2c3bd 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs @@ -69,7 +69,7 @@ fn compare_impl_method<'tcx>( impl_trait_ref: ty::TraitRef<'tcx>, ) -> Result<(), ErrorGuaranteed> { check_method_is_structurally_compatible(tcx, impl_m, trait_m, impl_trait_ref, false)?; - compare_method_predicate_entailment(tcx, impl_m, trait_m, impl_trait_ref)?; + compare_method_clause_entailment(tcx, impl_m, trait_m, impl_trait_ref)?; Ok(()) } @@ -165,13 +165,13 @@ fn check_method_is_structurally_compatible<'tcx>( /// /// We do this by creating a parameter environment which contains a /// generic parameter corresponding to `impl_to_placeholder_args`. We then build -/// `trait_to_placeholder_args` and use it to convert the predicates contained +/// `trait_to_placeholder_args` and use it to convert the clauses contained /// in the `trait_m` generics to the placeholder form. /// -/// Finally we register each of these predicates as an obligation and check that +/// Finally we register each of these clauses as an obligation and check that /// they hold. #[instrument(level = "debug", skip(tcx, impl_trait_ref))] -fn compare_method_predicate_entailment<'tcx>( +fn compare_method_clause_entailment<'tcx>( tcx: TyCtxt<'tcx>, impl_m: ty::AssocItem, trait_m: ty::AssocItem, @@ -203,27 +203,26 @@ fn compare_method_predicate_entailment<'tcx>( ); debug!(?trait_to_impl_args); - let impl_m_predicates = tcx.predicates_of(impl_m.def_id); - let trait_m_predicates = tcx.predicates_of(trait_m.def_id); + let impl_m_clauses = tcx.clauses_of(impl_m.def_id); + let trait_m_clauses = tcx.clauses_of(trait_m.def_id); // This is the only tricky bit of the new way we check implementation methods - // We need to build a set of predicates where only the method-level bounds + // We need to build a set of clauses where only the method-level bounds // are from the trait and we assume all other bounds from the implementation // to be previously satisfied. // // We then register the obligations from the impl_m and check to see // if all constraints hold. - let impl_predicates = tcx.predicates_of(impl_m_predicates.parent.unwrap()); - let mut hybrid_preds = impl_predicates.instantiate_identity(tcx).predicates; - hybrid_preds.extend( - trait_m_predicates.instantiate_own(tcx, trait_to_impl_args).map(|(predicate, _)| predicate), - ); + let impl_clauses = tcx.clauses_of(impl_m_clauses.parent.unwrap()); + let mut hybrid_clauses = impl_clauses.instantiate_identity(tcx).clauses; + hybrid_clauses + .extend(trait_m_clauses.instantiate_own(tcx, trait_to_impl_args).map(|(clause, _)| clause)); let is_conditionally_const = tcx.is_conditionally_const(impl_m.def_id); if is_conditionally_const { // Augment the hybrid param-env with the const conditions // of the impl header and the trait method. - hybrid_preds.extend( + hybrid_clauses.extend( tcx.const_conditions(impl_def_id) .instantiate_identity(tcx) .into_iter() @@ -236,9 +235,9 @@ fn compare_method_predicate_entailment<'tcx>( ); } - let hybrid_preds = hybrid_preds.into_iter().map(Unnormalized::skip_norm_wip); + let hybrid_clauses = hybrid_clauses.into_iter().map(Unnormalized::skip_norm_wip); let normalize_cause = traits::ObligationCause::misc(impl_m_span, impl_m_def_id); - let param_env = ty::ParamEnv::new(tcx.mk_clauses_from_iter(hybrid_preds)); + let param_env = ty::ParamEnv::new(tcx.mk_clauses_from_iter(hybrid_clauses)); // NOTE(-Zhigher-ranked-assumptions): The `hybrid_preds` // should be well-formed. However, using them may result in // region errors as we currently don't track placeholder @@ -259,14 +258,14 @@ fn compare_method_predicate_entailment<'tcx>( let infcx = &tcx.infer_ctxt().build(TypingMode::non_body_analysis()); let ocx = ObligationCtxt::new_with_diagnostics(infcx); - // Create obligations for each predicate declared by the impl + // Create obligations for each clause declared by the impl // definition in the context of the hybrid param-env. This makes // sure that the impl's method's where clauses are not more // restrictive than the trait's method (and the impl itself). - let impl_m_own_bounds = impl_m_predicates.instantiate_own_identity(); - for (predicate, span) in impl_m_own_bounds { + let impl_m_own_bounds = impl_m_clauses.instantiate_own_identity(); + for (clause, span) in impl_m_own_bounds { let normalize_cause = traits::ObligationCause::misc(span, impl_m_def_id); - let predicate = ocx.normalize(&normalize_cause, param_env, predicate); + let clause = ocx.normalize(&normalize_cause, param_env, clause); let cause = ObligationCause::new( span, @@ -277,7 +276,7 @@ fn compare_method_predicate_entailment<'tcx>( kind: impl_m.kind, }, ); - ocx.register_obligation(traits::Obligation::new(tcx, cause, param_env, predicate)); + ocx.register_obligation(traits::Obligation::new(tcx, cause, param_env, clause)); } // If we're within a const implementation, we need to make sure that the method @@ -488,13 +487,13 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>( impl_trait_ref.args, ); - let hybrid_preds = tcx - .predicates_of(impl_m.container_id(tcx)) + let hybrid_clauses = tcx + .clauses_of(impl_m.container_id(tcx)) .instantiate_identity(tcx) .into_iter() - .chain(tcx.predicates_of(trait_m.def_id).instantiate_own(tcx, trait_to_impl_args)) + .chain(tcx.clauses_of(trait_m.def_id).instantiate_own(tcx, trait_to_impl_args)) .map(|(clause, _)| clause.skip_norm_wip()); - let param_env = ty::ParamEnv::new(tcx.mk_clauses_from_iter(hybrid_preds)); + let param_env = ty::ParamEnv::new(tcx.mk_clauses_from_iter(hybrid_clauses)); let param_env = traits::normalize_param_env_or_error( tcx, param_env, @@ -509,11 +508,11 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>( // We check these because if the where clauses of the signatures do not match // up, then we don't want to give spurious other errors that point at the RPITITs. // They're not necessary to check, though, because we already check them in - // `compare_method_predicate_entailment`. - let impl_m_own_bounds = tcx.predicates_of(impl_m_def_id).instantiate_own_identity(); - for (predicate, span) in impl_m_own_bounds { + // `compare_method_clause_entailment`. + let impl_m_own_bounds = tcx.clauses_of(impl_m_def_id).instantiate_own_identity(); + for (clause, span) in impl_m_own_bounds { let normalize_cause = traits::ObligationCause::misc(span, impl_m_def_id); - let predicate = ocx.normalize(&normalize_cause, param_env, predicate); + let clause = ocx.normalize(&normalize_cause, param_env, clause); let cause = ObligationCause::new( span, @@ -524,7 +523,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>( kind: impl_m.kind, }, ); - ocx.register_obligation(traits::Obligation::new(tcx, cause, param_env, predicate)); + ocx.register_obligation(traits::Obligation::new(tcx, cause, param_env, clause)); } // Normalize the impl signature with fresh variables for lifetime inference. @@ -648,13 +647,13 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>( // Unify the whole function signature. We need to do this to fully infer // the lifetimes of the return type, but do this after unifying just the // return types, since we want to avoid duplicating errors from - // `compare_method_predicate_entailment`. + // `compare_method_clause_entailment`. match ocx.eq(&cause, param_env, trait_sig, impl_sig) { Ok(()) => {} Err(terr) => { - // This function gets called during `compare_method_predicate_entailment` when normalizing a + // This function gets called during `compare_method_clause_entailment` when normalizing a // signature that contains RPITIT. When the method signatures don't match, we have to - // emit an error now because `compare_method_predicate_entailment` will not report the error + // emit an error now because `compare_method_clause_entailment` will not report the error // when normalization fails. let emitted = report_trait_method_mismatch( infcx, @@ -1375,9 +1374,7 @@ fn check_region_late_boundedness<'tcx>( tcx.def_span(trait_param_def_id), format!("`{}` is late-bound", tcx.item_name(trait_param_def_id)), ); - if let Some(span) = - find_region_in_predicates(tcx, impl_m.def_id, early_bound_region) - { + if let Some(span) = find_region_in_clauses(tcx, impl_m.def_id, early_bound_region) { multispan.push_span_label( span, format!( @@ -1415,8 +1412,7 @@ fn check_region_late_boundedness<'tcx>( tcx.def_span(trait_param_def_id), format!("`{}` is early-bound", tcx.item_name(trait_param_def_id)), ); - if let Some(span) = - find_region_in_predicates(tcx, trait_m.def_id, early_bound_region) + if let Some(span) = find_region_in_clauses(tcx, trait_m.def_id, early_bound_region) { multispan.push_span_label( span, @@ -1440,13 +1436,13 @@ fn check_region_late_boundedness<'tcx>( Some(diag.emit()) } -fn find_region_in_predicates<'tcx>( +fn find_region_in_clauses<'tcx>( tcx: TyCtxt<'tcx>, def_id: DefId, early_bound_region: ty::Region<'tcx>, ) -> Option { - for (pred, span) in tcx.explicit_predicates_of(def_id).instantiate_identity(tcx) { - if pred.skip_norm_wip().visit_with(&mut FindRegion(early_bound_region)).is_break() { + for (clause, span) in tcx.explicit_clauses_of(def_id).instantiate_identity(tcx) { + if clause.skip_norm_wip().visit_with(&mut FindRegion(early_bound_region)).is_break() { return Some(span); } } @@ -2150,7 +2146,7 @@ fn compare_impl_const<'tcx>( compare_number_of_generics(tcx, impl_const_item, trait_const_item, false)?; compare_generic_param_kinds(tcx, impl_const_item, trait_const_item, false)?; check_region_bounds_on_impl_item(tcx, impl_const_item, trait_const_item, false)?; - compare_const_predicate_entailment(tcx, impl_const_item, trait_const_item, impl_trait_ref) + compare_const_clause_entailment(tcx, impl_const_item, trait_const_item, impl_trait_ref) } fn compare_type_const<'tcx>( @@ -2182,11 +2178,12 @@ fn compare_type_const<'tcx>( Ok(()) } -/// The equivalent of [compare_method_predicate_entailment], but for associated constants +/// The equivalent of [compare_method_clause_entailment], but for associated constants /// instead of associated functions. -// FIXME(generic_const_items): If possible extract the common parts of `compare_{type,const}_predicate_entailment`. +// FIXME(generic_const_items): If possible extract the common parts of +// `compare_{type,const}_clause_entailment`. #[instrument(level = "debug", skip(tcx))] -fn compare_const_predicate_entailment<'tcx>( +fn compare_const_clause_entailment<'tcx>( tcx: TyCtxt<'tcx>, impl_ct: ty::AssocItem, trait_ct: ty::AssocItem, @@ -2218,21 +2215,19 @@ fn compare_const_predicate_entailment<'tcx>( }; let mut cause = ObligationCause::new(impl_ct_span, impl_ct_def_id, code.clone()); - let impl_ct_predicates = tcx.predicates_of(impl_ct.def_id); - let trait_ct_predicates = tcx.predicates_of(trait_ct.def_id); + let impl_ct_clauses = tcx.clauses_of(impl_ct.def_id); + let trait_ct_clauses = tcx.clauses_of(trait_ct.def_id); - // The predicates declared by the impl definition, the trait and the + // The clauses declared by the impl definition, the trait and the // associated const in the trait are assumed. - let impl_predicates = tcx.predicates_of(impl_ct_predicates.parent.unwrap()); - let mut hybrid_preds = impl_predicates.instantiate_identity(tcx).predicates; - hybrid_preds.extend( - trait_ct_predicates - .instantiate_own(tcx, trait_to_impl_args) - .map(|(predicate, _)| predicate), + let impl_clauses = tcx.clauses_of(impl_ct_clauses.parent.unwrap()); + let mut hybrid_clauses = impl_clauses.instantiate_identity(tcx).clauses; + hybrid_clauses.extend( + trait_ct_clauses.instantiate_own(tcx, trait_to_impl_args).map(|(clause, _)| clause), ); - let hybrid_preds = hybrid_preds.into_iter().map(Unnormalized::skip_norm_wip); + let hybrid_clauses = hybrid_clauses.into_iter().map(Unnormalized::skip_norm_wip); - let param_env = ty::ParamEnv::new(tcx.mk_clauses_from_iter(hybrid_preds)); + let param_env = ty::ParamEnv::new(tcx.mk_clauses_from_iter(hybrid_clauses)); let param_env = traits::normalize_param_env_or_error( tcx, param_env, @@ -2242,13 +2237,13 @@ fn compare_const_predicate_entailment<'tcx>( let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis()); let ocx = ObligationCtxt::new_with_diagnostics(&infcx); - let impl_ct_own_bounds = impl_ct_predicates.instantiate_own_identity(); - for (predicate, span) in impl_ct_own_bounds { + let impl_ct_own_bounds = impl_ct_clauses.instantiate_own_identity(); + for (clause, span) in impl_ct_own_bounds { let cause = ObligationCause::misc(span, impl_ct_def_id); - let predicate = ocx.normalize(&cause, param_env, predicate); + let clause = ocx.normalize(&cause, param_env, clause); let cause = ObligationCause::new(span, impl_ct_def_id, code.clone()); - ocx.register_obligation(traits::Obligation::new(tcx, cause, param_env, predicate)); + ocx.register_obligation(traits::Obligation::new(tcx, cause, param_env, clause)); } // There is no "body" here, so just pass dummy id. @@ -2316,14 +2311,14 @@ fn compare_impl_ty<'tcx>( compare_number_of_generics(tcx, impl_ty, trait_ty, false)?; compare_generic_param_kinds(tcx, impl_ty, trait_ty, false)?; check_region_bounds_on_impl_item(tcx, impl_ty, trait_ty, false)?; - compare_type_predicate_entailment(tcx, impl_ty, trait_ty, impl_trait_ref)?; + compare_type_clause_entailment(tcx, impl_ty, trait_ty, impl_trait_ref)?; check_type_bounds(tcx, trait_ty, impl_ty, impl_trait_ref) } -/// The equivalent of [compare_method_predicate_entailment], but for associated types +/// The equivalent of [compare_method_clause_entailment], but for associated types /// instead of associated functions. #[instrument(level = "debug", skip(tcx))] -fn compare_type_predicate_entailment<'tcx>( +fn compare_type_clause_entailment<'tcx>( tcx: TyCtxt<'tcx>, impl_ty: ty::AssocItem, trait_ty: ty::AssocItem, @@ -2336,10 +2331,10 @@ fn compare_type_predicate_entailment<'tcx>( impl_trait_ref.args, ); - let impl_ty_predicates = tcx.predicates_of(impl_ty.def_id); - let trait_ty_predicates = tcx.predicates_of(trait_ty.def_id); + let impl_ty_clauses = tcx.clauses_of(impl_ty.def_id); + let trait_ty_clauses = tcx.clauses_of(trait_ty.def_id); - let impl_ty_own_bounds = impl_ty_predicates.instantiate_own_identity(); + let impl_ty_own_bounds = impl_ty_clauses.instantiate_own_identity(); // If there are no bounds, then there are no const conditions, so no need to check that here. if impl_ty_own_bounds.len() == 0 { // Nothing to check. @@ -2352,16 +2347,14 @@ fn compare_type_predicate_entailment<'tcx>( let impl_ty_def_id = impl_ty.def_id.expect_local(); debug!(?trait_to_impl_args); - // The predicates declared by the impl definition, the trait and the + // The clauses declared by the impl definition, the trait and the // associated type in the trait are assumed. - let impl_predicates = tcx.predicates_of(impl_ty_predicates.parent.unwrap()); - let mut hybrid_preds = impl_predicates.instantiate_identity(tcx).predicates; - hybrid_preds.extend( - trait_ty_predicates - .instantiate_own(tcx, trait_to_impl_args) - .map(|(predicate, _)| predicate), + let impl_clauses = tcx.clauses_of(impl_ty_clauses.parent.unwrap()); + let mut hybrid_clauses = impl_clauses.instantiate_identity(tcx).clauses; + hybrid_clauses.extend( + trait_ty_clauses.instantiate_own(tcx, trait_to_impl_args).map(|(predicate, _)| predicate), ); - debug!(?hybrid_preds); + debug!(?hybrid_clauses); let impl_ty_span = tcx.def_span(impl_ty_def_id); let normalize_cause = ObligationCause::misc(impl_ty_span, impl_ty_def_id); @@ -2370,8 +2363,8 @@ fn compare_type_predicate_entailment<'tcx>( if is_conditionally_const { // Augment the hybrid param-env with the const conditions // of the impl header and the trait assoc type. - hybrid_preds.extend( - tcx.const_conditions(impl_ty_predicates.parent.unwrap()) + hybrid_clauses.extend( + tcx.const_conditions(impl_ty_clauses.parent.unwrap()) .instantiate_identity(tcx) .into_iter() .chain( @@ -2383,17 +2376,17 @@ fn compare_type_predicate_entailment<'tcx>( ); } - let hybrid_preds = hybrid_preds.into_iter().map(Unnormalized::skip_norm_wip); - let param_env = ty::ParamEnv::new(tcx.mk_clauses_from_iter(hybrid_preds)); + let hybrid_clauses = hybrid_clauses.into_iter().map(Unnormalized::skip_norm_wip); + let param_env = ty::ParamEnv::new(tcx.mk_clauses_from_iter(hybrid_clauses)); let param_env = traits::normalize_param_env_or_error(tcx, param_env, normalize_cause); debug!(caller_bounds=?param_env.caller_bounds()); let infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis()); let ocx = ObligationCtxt::new_with_diagnostics(&infcx); - for (predicate, span) in impl_ty_own_bounds { + for (clause, span) in impl_ty_own_bounds { let cause = ObligationCause::misc(span, impl_ty_def_id); - let predicate = ocx.normalize(&cause, param_env, predicate); + let clause = ocx.normalize(&cause, param_env, clause); let cause = ObligationCause::new( span, @@ -2404,7 +2397,7 @@ fn compare_type_predicate_entailment<'tcx>( kind: impl_ty.kind, }, ); - ocx.register_obligation(traits::Obligation::new(tcx, cause, param_env, predicate)); + ocx.register_obligation(traits::Obligation::new(tcx, cause, param_env, clause)); } if is_conditionally_const { diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs index 70ab2cc44e0c6..6b5313e4254fa 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs @@ -139,13 +139,13 @@ pub(crate) fn check_refining_return_position_impl_trait_in_trait<'tcx>( pairs.push((trait_projection, impl_opaque)); } - let hybrid_preds = tcx - .predicates_of(impl_def_id) + let hybrid_clauses = tcx + .clauses_of(impl_def_id) .instantiate_identity(tcx) .into_iter() - .chain(tcx.predicates_of(trait_m.def_id).instantiate_own(tcx, trait_m_to_impl_m_args)) + .chain(tcx.clauses_of(trait_m.def_id).instantiate_own(tcx, trait_m_to_impl_m_args)) .map(|(clause, _)| clause.skip_norm_wip()); - let param_env = ty::ParamEnv::new(tcx.mk_clauses_from_iter(hybrid_preds)); + let param_env = ty::ParamEnv::new(tcx.mk_clauses_from_iter(hybrid_clauses)); let param_env = normalize_param_env_or_error(tcx, param_env, ObligationCause::dummy()); let ref infcx = tcx.infer_ctxt().build(TypingMode::non_body_analysis()); diff --git a/compiler/rustc_hir_analysis/src/check/entry.rs b/compiler/rustc_hir_analysis/src/check/entry.rs index 9fae7ddaca64e..a18fdcfa6f5fe 100644 --- a/compiler/rustc_hir_analysis/src/check/entry.rs +++ b/compiler/rustc_hir_analysis/src/check/entry.rs @@ -166,15 +166,15 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) -> Result<(), ErrorGuar )?; let main_fn_generics = tcx.generics_of(main_def_id); - let main_fn_predicates = tcx.predicates_of(main_def_id); + let main_fn_clauses = tcx.clauses_of(main_def_id); if main_fn_generics.count() != 0 || !main_fnsig.bound_vars().is_empty() { let generics_param_span = main_fn_generics_params_span(tcx, main_def_id); return Err(tcx.dcx().emit_err(diagnostics::MainFunctionGenericParameters { span: generics_param_span.unwrap_or(main_span), label_span: generics_param_span, })); - } else if !main_fn_predicates.predicates.is_empty() { - // generics may bring in implicit predicates, so we skip this check if generics is present. + } else if !main_fn_clauses.clauses.is_empty() { + // Generics may bring in implicit clauses, so we skip this check if generics are present. let generics_where_clauses_span = main_fn_where_clauses_span(tcx, main_def_id); return Err(tcx.dcx().emit_err(diagnostics::WhereClauseOnMain { span: generics_where_clauses_span.unwrap_or(main_span), diff --git a/compiler/rustc_hir_analysis/src/check/mod.rs b/compiler/rustc_hir_analysis/src/check/mod.rs index a3bdd0bae7e77..451db9fd64aca 100644 --- a/compiler/rustc_hir_analysis/src/check/mod.rs +++ b/compiler/rustc_hir_analysis/src/check/mod.rs @@ -324,19 +324,19 @@ fn default_body_is_unstable( err.emit(); } -/// Re-sugar `ty::GenericPredicates` in a way suitable to be used in structured suggestions. -fn bounds_from_generic_predicates<'tcx>( +/// Re-sugar `ty::GenericClauses` in a way suitable to be used in structured suggestions. +fn bounds_from_generic_clauses<'tcx>( tcx: TyCtxt<'tcx>, - predicates: impl IntoIterator, Span)>, + clauses: impl IntoIterator, Span)>, assoc: ty::AssocItem, ) -> (String, String) { let mut types: FxIndexMap, Vec> = FxIndexMap::default(); let mut regions: FxIndexMap, Vec>> = FxIndexMap::default(); let mut projections = vec![]; - for (predicate, _) in predicates { - debug!("predicate {:?}", predicate); - let bound_predicate = predicate.kind(); - match bound_predicate.skip_binder() { + for (clause, _) in clauses { + debug!("clause {:?}", clause); + let bound_clause = clause.kind(); + match bound_clause.skip_binder() { ty::ClauseKind::Trait(trait_predicate) => { let entry = types.entry(trait_predicate.self_ty()).or_default(); let def_id = trait_predicate.def_id(); @@ -346,7 +346,7 @@ fn bounds_from_generic_predicates<'tcx>( } } ty::ClauseKind::Projection(projection_pred) => { - projections.push(bound_predicate.rebind(projection_pred)); + projections.push(bound_clause.rebind(projection_pred)); } ty::ClauseKind::RegionOutlives(OutlivesPredicate(a, b)) => { regions.entry(a).or_default().push(b); @@ -442,7 +442,7 @@ fn fn_sig_suggestion<'tcx>( tcx: TyCtxt<'tcx>, sig: ty::FnSig<'tcx>, ident: Ident, - predicates: impl IntoIterator, Span)>, + clauses: impl IntoIterator, Span)>, assoc: ty::AssocItem, ) -> String { let splatted_arg_index = sig.splatted().map(usize::from); @@ -502,7 +502,7 @@ fn fn_sig_suggestion<'tcx>( let output = if !output.is_unit() { format!(" -> {output}") } else { String::new() }; let safety = sig.safety().prefix_str(); - let (generics, where_clauses) = bounds_from_generic_predicates(tcx, predicates, assoc); + let (generics, where_clauses) = bounds_from_generic_clauses(tcx, clauses, assoc); // FIXME: this is not entirely correct, as the lifetimes from borrowed params will // not be present in the `fn` definition, nor will we account for renamed @@ -535,15 +535,15 @@ fn suggestion_signature<'tcx>( tcx.fn_sig(assoc.def_id).instantiate(tcx, args).skip_norm_wip(), ), assoc.ident(tcx), - tcx.predicates_of(assoc.def_id) + tcx.clauses_of(assoc.def_id) .instantiate_own(tcx, args) .map(|(c, s)| (c.skip_norm_wip(), s)), assoc, ), ty::AssocKind::Type { .. } => { - let (generics, where_clauses) = bounds_from_generic_predicates( + let (generics, where_clauses) = bounds_from_generic_clauses( tcx, - tcx.predicates_of(assoc.def_id) + tcx.clauses_of(assoc.def_id) .instantiate_own(tcx, args) .map(|(c, s)| (c.skip_norm_wip(), s)), assoc, diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index fd2944a122f03..213e55860a76c 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -1405,7 +1405,7 @@ pub(super) fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, def_id: let infcx = wfcx.infcx; let tcx = wfcx.tcx(); - let predicates = tcx.predicates_of(def_id.to_def_id()); + let gen_clauses = tcx.clauses_of(def_id.to_def_id()); let generics = tcx.generics_of(def_id); // Check that concrete defaults are well-formed. See test `type-check-defaults.rs`. @@ -1472,10 +1472,10 @@ pub(super) fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, def_id: } } - // Check that trait predicates are WF when params are instantiated with their defaults. - // We don't want to overly constrain the predicates that may be written but we want to + // Check that trait clauses are WF when params are instantiated with their defaults. + // We don't want to overly constrain the clauses that may be written but we want to // catch cases where a default my never be applied such as `struct Foo`. - // Therefore we check if a predicate which contains a single type param + // Therefore we check if a clause which contains a single type param // with a concrete default is WF with that default instantiated. // For more examples see tests `defaults-well-formedness.rs` and `type-check-defaults.rs`. // @@ -1493,11 +1493,11 @@ pub(super) fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, def_id: tcx.mk_param_from_def(param) }); - // Now we build the instantiated predicates. - let default_obligations = predicates - .predicates + // Now we build the instantiated clauses. + let default_obligations = gen_clauses + .clauses .iter() - .flat_map(|&(pred, sp)| { + .flat_map(|&(clause, sp)| { #[derive(Default)] struct CountParams { params: FxHashSet, @@ -1523,52 +1523,52 @@ pub(super) fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, def_id: } } let mut param_count = CountParams::default(); - let has_region = pred.visit_with(&mut param_count).is_break(); - let instantiated_pred = ty::EarlyBinder::bind(tcx, pred).instantiate(tcx, args); + let has_region = clause.visit_with(&mut param_count).is_break(); + let instantiated_clause = ty::EarlyBinder::bind(tcx, clause).instantiate(tcx, args); // Don't check non-defaulted params, dependent defaults (including lifetimes) - // or preds with multiple params. - if instantiated_pred.skip_normalization().has_non_region_param() + // or clauses with multiple params. + if instantiated_clause.skip_normalization().has_non_region_param() || param_count.params.len() > 1 || has_region { None - } else if predicates - .predicates + } else if gen_clauses + .clauses .iter() - .any(|&(p, _)| Unnormalized::new_wip(p) == instantiated_pred) + .any(|&(p, _)| Unnormalized::new_wip(p) == instantiated_clause) { - // Avoid duplication of predicates that contain no parameters, for example. + // Avoid duplication of clauses that contain no parameters, for example. None } else { - Some((instantiated_pred, sp)) + Some((instantiated_clause, sp)) } }) - .map(|(pred, sp)| { + .map(|(clause, sp)| { // Convert each of those into an obligation. So if you have // something like `struct Foo`, we would - // take that predicate `T: Copy`, instantiated with `String: Copy` + // take that clause `T: Copy`, instantiated with `String: Copy` // (actually that happens in the previous `flat_map` call), // and then try to prove it (in this case, we'll fail). // - // Note the subtle difference from how we handle `predicates` - // below: there, we are not trying to prove those predicates + // Note the subtle difference from how we handle `gen_clauses` + // below: there, we are not trying to prove those clauses // to be *true* but merely *well-formed*. - let pred = wfcx.normalize(sp, None, pred); + let clause = wfcx.normalize(sp, None, clause); let cause = traits::ObligationCause::new( sp, wfcx.body_def_id, ObligationCauseCode::WhereClause(def_id.to_def_id(), sp), ); - Obligation::new(tcx, cause, wfcx.param_env, pred) + Obligation::new(tcx, cause, wfcx.param_env, clause) }); - let predicates = predicates.instantiate_identity(tcx); + let gen_clauses = gen_clauses.instantiate_identity(tcx); - let assoc_const_obligations: Vec<_> = predicates - .predicates + let assoc_const_obligations: Vec<_> = gen_clauses + .clauses .iter() .copied() - .zip(predicates.spans.iter().copied()) + .zip(gen_clauses.spans.iter().copied()) .filter_map(|(clause, sp)| { let clause = clause.skip_norm_wip(); let proj = clause.as_projection_clause()?; @@ -1592,8 +1592,8 @@ pub(super) fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, def_id: }) .collect(); - assert_eq!(predicates.predicates.len(), predicates.spans.len()); - let wf_obligations = predicates.into_iter().flat_map(|(p, sp)| { + assert_eq!(gen_clauses.clauses.len(), gen_clauses.spans.len()); + let wf_obligations = gen_clauses.into_iter().flat_map(|(p, sp)| { traits::wf::clause_obligations( infcx, wfcx.param_env, @@ -1996,8 +1996,8 @@ pub(super) fn check_variances_for_type_defn<'tcx>(tcx: TyCtxt<'tcx>, def_id: Loc kind => span_bug!(tcx.def_span(def_id), "cannot compute the variances of {kind:?}"), } - let ty_predicates = tcx.predicates_of(def_id); - assert_eq!(ty_predicates.parent, None); + let ty_clauses = tcx.clauses_of(def_id); + assert_eq!(ty_clauses.parent, None); let variances = tcx.variances_of(def_id); let mut constrained_parameters: FxHashSet<_> = variances @@ -2007,7 +2007,7 @@ pub(super) fn check_variances_for_type_defn<'tcx>(tcx: TyCtxt<'tcx>, def_id: Loc .map(|(index, _)| Parameter(index as u32)) .collect(); - identify_constrained_generic_params(tcx, ty_predicates, None, &mut constrained_parameters); + identify_constrained_generic_params(tcx, ty_clauses, None, &mut constrained_parameters); // Lazily calculated because it is only needed in case of an error. let explicitly_bounded_params = LazyCell::new(|| { @@ -2287,12 +2287,12 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> { let mut span = tcx.def_span(self.body_def_id); let empty_env = ty::ParamEnv::empty(); - let predicates_with_span = tcx.predicates_of(self.body_def_id).predicates.iter().copied(); + let clauses_with_span = tcx.clauses_of(self.body_def_id).clauses.iter().copied(); // Check elaborated bounds. - let implied_obligations = traits::elaborate(tcx, predicates_with_span); + let implied_obligations = traits::elaborate(tcx, clauses_with_span); - for (pred, obligation_span) in implied_obligations { - match pred.kind().skip_binder() { + for (clause, obligation_span) in implied_obligations { + match clause.kind().skip_binder() { // We lower empty bounds like `Vec:` as // `WellFormed(Vec)`, which will later get checked by // regular WF checking @@ -2303,8 +2303,8 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> { } // Match the existing behavior. - if pred.is_global() && !pred.has_type_flags(TypeFlags::HAS_BINDER_VARS) { - let pred = self.normalize(span, None, Unnormalized::new_wip(pred)); + if clause.is_global() && !clause.has_type_flags(TypeFlags::HAS_BINDER_VARS) { + let clause = self.normalize(span, None, Unnormalized::new_wip(clause)); // only use the span of the predicate clause (#90869) let hir_node = tcx.hir_node_by_def_id(self.body_def_id); @@ -2325,7 +2325,7 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> { ObligationCauseCode::TrivialBound, ), empty_env, - pred, + clause, ); self.ocx.register_obligation(obligation); } diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index 6c393ed3dfc6b..bf17952313479 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -8,7 +8,7 @@ //! //! Collecting is ultimately defined by a bundle of queries that //! inquire after various facts about the items in the crate (e.g., -//! `type_of`, `generics_of`, `predicates_of`, etc). See the `provide` function +//! `type_of`, `generics_of`, `clauses_of`, etc). See the `provide` function //! for the full set. //! //! At present, however, we do run collection across all items in the @@ -47,10 +47,10 @@ use tracing::{debug, instrument}; use crate::diagnostics::{self, ElidedLifetimesAreNotAllowedInDelegations}; use crate::hir_ty_lowering::{HirTyLowerer, InherentAssocCandidate, RegionInferReason}; +mod clauses_of; pub(crate) mod dump; mod generics_of; mod item_bounds; -mod predicates_of; mod resolve_bound_vars; mod type_of; @@ -71,16 +71,16 @@ pub(crate) fn provide(providers: &mut Providers) { item_non_self_bounds: item_bounds::item_non_self_bounds, impl_super_outlives: item_bounds::impl_super_outlives, generics_of: generics_of::generics_of, - predicates_of: predicates_of::predicates_of, - explicit_predicates_of: predicates_of::explicit_predicates_of, - explicit_super_predicates_of: predicates_of::explicit_super_predicates_of, - explicit_implied_predicates_of: predicates_of::explicit_implied_predicates_of, + clauses_of: clauses_of::clauses_of, + explicit_clauses_of: clauses_of::explicit_clauses_of, + explicit_super_clauses_of: clauses_of::explicit_super_clauses_of, + explicit_implied_clauses_of: clauses_of::explicit_implied_clauses_of, explicit_supertraits_containing_assoc_item: - predicates_of::explicit_supertraits_containing_assoc_item, - trait_explicit_predicates_and_bounds: predicates_of::trait_explicit_predicates_and_bounds, - const_conditions: predicates_of::const_conditions, - explicit_implied_const_bounds: predicates_of::explicit_implied_const_bounds, - type_param_predicates: predicates_of::type_param_predicates, + clauses_of::explicit_supertraits_containing_assoc_item, + trait_explicit_clauses_and_bounds: clauses_of::trait_explicit_clauses_and_bounds, + const_conditions: clauses_of::const_conditions, + explicit_implied_const_bounds: clauses_of::explicit_implied_const_bounds, + type_param_clauses: clauses_of::type_param_clauses, trait_def, adt_def, fn_sig, @@ -391,7 +391,7 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> { def_id: LocalDefId, assoc_ident: Ident, ) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> { - self.tcx.at(span).type_param_predicates((self.item_def_id, def_id, assoc_ident)) + self.tcx.at(span).type_param_clauses((self.item_def_id, def_id, assoc_ident)) } #[instrument(level = "debug", skip(self, _span), ret)] @@ -634,7 +634,7 @@ fn get_new_lifetime_name<'tcx>( pub(super) fn check_ctor(tcx: TyCtxt<'_>, def_id: LocalDefId) { tcx.ensure_ok().generics_of(def_id); tcx.ensure_ok().type_of(def_id); - tcx.ensure_ok().predicates_of(def_id); + tcx.ensure_ok().clauses_of(def_id); } pub(super) fn check_enum_variant_types(tcx: TyCtxt<'_>, def_id: LocalDefId) { @@ -714,7 +714,7 @@ pub(super) fn check_enum_variant_types(tcx: TyCtxt<'_>, def_id: LocalDefId) { for f in &variant.fields { tcx.ensure_ok().generics_of(f.did); tcx.ensure_ok().type_of(f.did); - tcx.ensure_ok().predicates_of(f.did); + tcx.ensure_ok().clauses_of(f.did); } // Lower the ctor, if any. This also registers the variant as an item. @@ -1395,7 +1395,7 @@ pub fn suggest_impl_trait<'tcx>( fn impl_is_fully_generic_for_reflection(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool { tcx.impl_trait_header(def_id).is_fully_generic_for_reflection() - && tcx.explicit_predicates_of(def_id).is_fully_generic_for_reflection() + && tcx.explicit_clauses_of(def_id).is_fully_generic_for_reflection() } fn impl_trait_header(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::ImplTraitHeader<'_> { diff --git a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs b/compiler/rustc_hir_analysis/src/collect/clauses_of.rs similarity index 83% rename from compiler/rustc_hir_analysis/src/collect/predicates_of.rs rename to compiler/rustc_hir_analysis/src/collect/clauses_of.rs index 46f90ad160cac..3c91caf3d7eed 100644 --- a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/clauses_of.rs @@ -7,8 +7,8 @@ use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::find_attr; use rustc_middle::ty::{ - self, GenericPredicates, ImplTraitInTraitData, RegionExt, Ty, TyCtxt, TypeVisitable, - TypeVisitor, Upcast, + self, GenericClauses, ImplTraitInTraitData, RegionExt, Ty, TyCtxt, TypeVisitable, TypeVisitor, + Upcast, }; use rustc_middle::{bug, span_bug}; use rustc_span::{DUMMY_SP, Ident, Span}; @@ -17,46 +17,46 @@ use tracing::{debug, instrument, trace}; use super::item_bounds::explicit_item_bounds_with_filter; use crate::collect::ItemCtxt; use crate::constrained_generic_params as cgp; -use crate::delegation::inherit_predicates_for_delegation_item; +use crate::delegation::inherit_clauses_for_delegation_item; use crate::hir_ty_lowering::{ HirTyLowerer, ImpliedBoundsContext, OverlappingAsssocItemConstraints, PredicateFilter, RegionInferReason, }; -/// Returns a list of all type predicates (explicit and implicit) for the definition with -/// ID `def_id`. This includes all predicates returned by `explicit_predicates_of`, plus +/// Returns a list of all type clauses (explicit and implicit) for the definition with +/// ID `def_id`. This includes all clauses returned by `explicit_clauses_of`, plus /// inferred constraints concerning which regions outlive other regions. #[instrument(level = "debug", skip(tcx))] -pub(super) fn predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicates<'_> { - let mut result = tcx.explicit_predicates_of(def_id); - debug!("predicates_of: explicit_predicates_of({:?}) = {:?}", def_id, result); +pub(super) fn clauses_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericClauses<'_> { + let mut result = tcx.explicit_clauses_of(def_id); + debug!("clauses_of: explicit_clauses_of({:?}) = {:?}", def_id, result); let inferred_outlives = tcx.inferred_outlives_of(def_id); if !inferred_outlives.is_empty() { - debug!("predicates_of: inferred_outlives_of({:?}) = {:?}", def_id, inferred_outlives,); + debug!("clauses_of: inferred_outlives_of({:?}) = {:?}", def_id, inferred_outlives,); let inferred_outlives_iter = inferred_outlives.iter().map(|(clause, span)| ((*clause).upcast(tcx), *span)); - if result.predicates.is_empty() { - result.predicates = tcx.arena.alloc_from_iter(inferred_outlives_iter); + if result.clauses.is_empty() { + result.clauses = tcx.arena.alloc_from_iter(inferred_outlives_iter); } else { - result.predicates = tcx.arena.alloc_from_iter( - result.predicates.into_iter().copied().chain(inferred_outlives_iter), - ); + result.clauses = tcx + .arena + .alloc_from_iter(result.clauses.into_iter().copied().chain(inferred_outlives_iter)); } } if tcx.is_trait(def_id) { - // For traits, add `Self: Trait` predicate. This is - // not part of the predicates that a user writes, but it + // For traits, add `Self: Trait` clause. This is + // not part of the clauses that a user writes, but it // is something that one must prove in order to invoke a // method or project an associated type. // - // In the chalk setup, this predicate is not part of the - // "predicates" for a trait item. But it is useful in + // In the chalk setup, this clause is not part of the + // "clauses" for a trait item. But it is useful in // rustc because if you directly (e.g.) invoke a trait // method like `Trait::method(...)`, you must naturally // prove that the trait applies to the types that were - // used, and adding the predicate into this list ensures + // used, and adding the clause into this list ensures // that this is done. // // We use a DUMMY_SP here as a way to signal trait bounds that come @@ -65,60 +65,60 @@ pub(super) fn predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredic // `tcx.def_span(def_id);` let span = DUMMY_SP; - result.predicates = tcx.arena.alloc_from_iter( + result.clauses = tcx.arena.alloc_from_iter( result - .predicates + .clauses .iter() .copied() .chain(std::iter::once((ty::TraitRef::identity(tcx, def_id).upcast(tcx), span))), ); } - debug!("predicates_of({:?}) = {:?}", def_id, result); + debug!("clauses_of({:?}) = {:?}", def_id, result); result } -/// Returns a list of user-specified type predicates for the definition with ID `def_id`. +/// Returns a list of user-specified type clauses for the definition with ID `def_id`. /// N.B., this does not include any implied/inferred constraints. #[instrument(level = "trace", skip(tcx), ret)] -fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::GenericPredicates<'_> { +fn gather_explicit_clauses_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::GenericClauses<'_> { use rustc_hir::*; match tcx.opt_rpitit_info(def_id.to_def_id()) { Some(ImplTraitInTraitData::Trait { fn_def_id, .. }) => { - let mut predicates = Vec::new(); + let mut clauses = Vec::new(); - // RPITITs should inherit the predicates of their parent. This is + // RPITITs should inherit the clauses of their parent. This is // both to ensure that the RPITITs are only instantiated when the - // parent predicates would hold, and also so that the param-env - // inherits these predicates as assumptions. + // parent clauses would hold, and also so that the param-env + // inherits these clauses as assumptions. let identity_args = ty::GenericArgs::identity_for_item(tcx, def_id); - predicates.extend( - tcx.explicit_predicates_of(fn_def_id) + clauses.extend( + tcx.explicit_clauses_of(fn_def_id) .instantiate_own(tcx, identity_args) .map(|(c, s)| (c.skip_norm_wip(), s)), ); - // We also install bidirectional outlives predicates for the RPITIT + // We also install bidirectional outlives clauses for the RPITIT // to keep the duplicates lifetimes from opaque lowering in sync. // We only need to compute bidirectional outlives for the duplicated // opaque lifetimes, which explains the slicing below. - compute_bidirectional_outlives_predicates( + compute_bidirectional_outlives_clauses( tcx, &tcx.generics_of(def_id.to_def_id()).own_params [tcx.generics_of(fn_def_id).own_params.len()..], - &mut predicates, + &mut clauses, ); - return ty::GenericPredicates { + return ty::GenericClauses { parent: Some(tcx.local_parent(def_id).to_def_id()), - predicates: tcx.arena.alloc_from_iter(predicates), + clauses: tcx.arena.alloc_from_iter(clauses), }; } Some(ImplTraitInTraitData::Impl { fn_def_id }) => { let trait_item_def_id = tcx.trait_item_of(def_id).unwrap(); - let trait_assoc_predicates = tcx.explicit_predicates_of(trait_item_def_id); + let trait_assoc_clauses = tcx.explicit_clauses_of(trait_item_def_id); let impl_assoc_identity_args = ty::GenericArgs::identity_for_item(tcx, def_id); let impl_def_id = tcx.parent(fn_def_id); @@ -128,13 +128,13 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen let impl_assoc_args = impl_assoc_identity_args.rebase_onto(tcx, impl_def_id, impl_trait_ref_args); - let impl_predicates = trait_assoc_predicates + let impl_clauses = trait_assoc_clauses .instantiate_own(tcx, impl_assoc_args) .map(|(c, s)| (c.skip_norm_wip(), s)); - return ty::GenericPredicates { + return ty::GenericClauses { parent: Some(impl_def_id), - predicates: tcx.arena.alloc_from_iter(impl_predicates), + clauses: tcx.arena.alloc_from_iter(impl_clauses), }; } @@ -147,7 +147,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen if let Some(sig) = node.fn_sig() && let Some(sig_id) = sig.decl.opt_delegation_sig_id() { - return inherit_predicates_for_delegation_item(tcx, def_id, sig_id); + return inherit_clauses_for_delegation_item(tcx, def_id, sig_id); } let mut is_trait = None; @@ -159,7 +159,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen // We use an `IndexSet` to preserve order of insertion. // Preserving the order of insertion is important here so as not to break UI tests. - let mut predicates: FxIndexSet<(ty::Clause<'_>, Span)> = FxIndexSet::default(); + let mut clauses: FxIndexSet<(ty::Clause<'_>, Span)> = FxIndexSet::default(); let hir_generics = node.generics().unwrap_or(NO_GENERICS); if let Node::Item(item) = node { @@ -184,7 +184,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen let generics = tcx.generics_of(def_id); // Below we'll consider the bounds on the type parameters (including `Self`) - // and the explicit where-clauses, but to get the full set of predicates + // and the explicit where-clauses, but to get the full set of clauses // on a trait we must also consider the bounds that follow the trait's name, // like `trait Foo: A + B + C`. if let Some((self_bounds, span)) = is_trait { @@ -211,7 +211,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen ImpliedBoundsContext::TraitDef(def_id), span, ); - predicates.extend(bounds); + clauses.extend(bounds); } // In default impls, we can assume that the self type implements @@ -223,10 +223,10 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen // (see below). Recall that a default impl is not itself an impl, but rather a // set of defaults that can be incorporated into another impl. if let Some(trait_ref) = is_default_impl_trait { - predicates.insert((trait_ref.upcast(tcx), tcx.def_span(def_id))); + clauses.insert((trait_ref.upcast(tcx), tcx.def_span(def_id))); } - // Add implicit predicates that should be treated as if the user has written them, + // Add implicit clauses that should be treated as if the user has written them, // including the implicit `T: Sized` for all generic parameters, and `ConstArgHasType` // for const params. for param in hir_generics.params { @@ -251,20 +251,20 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen param.span, ); trace!(?bounds); - predicates.extend(bounds); - trace!(?predicates); + clauses.extend(bounds); + trace!(?clauses); } hir::GenericParamKind::Const { .. } => { let param_def_id = param.def_id.to_def_id(); let ct_ty = tcx.type_of(param_def_id).instantiate_identity().skip_norm_wip(); let ct = icx.lowerer().lower_const_param(param_def_id, param.hir_id); - predicates + clauses .insert((ty::ClauseKind::ConstArgHasType(ct, ct_ty).upcast(tcx), param.span)); } } } - trace!(?predicates); + trace!(?clauses); // Add inline `` bounds and bounds in the where clause. for predicate in hir_generics.predicates { match predicate.kind { @@ -281,11 +281,11 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen // noop (see #53696) and `Ty` is still checked for WF. let span = bound_pred.bounded_ty.span; - let predicate = ty::Binder::bind_with_vars( + let clause = ty::Binder::bind_with_vars( ty::ClauseKind::WellFormed(ty.into()), bound_vars, ); - predicates.insert((predicate.upcast(tcx), span)); + clauses.insert((clause.upcast(tcx), span)); } } @@ -298,14 +298,14 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen PredicateFilter::All, OverlappingAsssocItemConstraints::Allowed, ); - predicates.extend(bounds); + clauses.extend(bounds); } hir::WherePredicateKind::RegionPredicate(region_pred) => { let r1 = icx .lowerer() .lower_lifetime(region_pred.lifetime, RegionInferReason::RegionPredicate); - predicates.extend(region_pred.bounds.iter().map(|bound| { + clauses.extend(region_pred.bounds.iter().map(|bound| { let (r2, span) = match bound { hir::GenericBound::Outlives(lt) => ( icx.lowerer().lower_lifetime(lt, RegionInferReason::RegionPredicate), @@ -318,16 +318,16 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen ) } }; - let pred = + let clause = ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(r1, r2)).upcast(tcx); - (pred, span) + (clause, span) })) } } } if tcx.features().generic_const_exprs() { - predicates.extend(const_evaluatable_predicates_of(tcx, def_id, &predicates)); + clauses.extend(const_evaluatable_clauses_of(tcx, def_id, &clauses)); } let attrs = tcx.hir_attrs(tcx.local_def_id_to_hir_id(def_id)); @@ -338,15 +338,15 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen find_attr!(attrs, UnstableFeatureBound(i) => i).map(|i| i.as_slice()).unwrap_or_default(); for (feat_name, span) in allow_unstable_feature_attr { - predicates.insert((ty::ClauseKind::UnstableFeature(*feat_name).upcast(tcx), *span)); + clauses.insert((ty::ClauseKind::UnstableFeature(*feat_name).upcast(tcx), *span)); } - let mut predicates: Vec<_> = predicates.into_iter().collect(); + let mut clauses: Vec<_> = clauses.into_iter().collect(); - // Subtle: before we store the predicates into the tcx, we - // sort them so that predicates like `T: Foo` come + // Subtle: before we store the clauses into the tcx, we + // sort them so that clauses like `T: Foo` come // before uses of `U`. This avoids false ambiguity errors - // in trait checking. See `setup_constraining_predicates` + // in trait checking. See `setup_constraining_clauses` // for details. if let Node::Item(&Item { kind: ItemKind::Impl(impl_), .. }) = node { let self_ty = tcx.type_of(def_id).instantiate_identity().skip_norm_wip(); @@ -354,34 +354,31 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen .of_trait .is_some() .then(|| tcx.impl_trait_ref(def_id).instantiate_identity().skip_norm_wip()); - cgp::setup_constraining_predicates( + cgp::setup_constraining_clauses( tcx, - &mut predicates, + &mut clauses, trait_ref, &mut cgp::parameters_for_impl(tcx, self_ty, trait_ref), ); } // Opaque types duplicate some of their generic parameters. - // We create bi-directional Outlives predicates between the original + // We create bi-directional Outlives clauses between the original // and the duplicated parameter, to ensure that they do not get out of sync. if let Node::OpaqueTy(..) = node { - compute_bidirectional_outlives_predicates(tcx, &generics.own_params, &mut predicates); - debug!(?predicates); + compute_bidirectional_outlives_clauses(tcx, &generics.own_params, &mut clauses); + debug!(?clauses); } - ty::GenericPredicates { - parent: generics.parent, - predicates: tcx.arena.alloc_from_iter(predicates), - } + ty::GenericClauses { parent: generics.parent, clauses: tcx.arena.alloc_from_iter(clauses) } } -/// Opaques have duplicated lifetimes and we need to compute bidirectional outlives predicates to +/// Opaques have duplicated lifetimes and we need to compute bidirectional outlives clauses to /// enforce that these lifetimes stay in sync. -fn compute_bidirectional_outlives_predicates<'tcx>( +fn compute_bidirectional_outlives_clauses<'tcx>( tcx: TyCtxt<'tcx>, opaque_own_params: &[ty::GenericParamDef], - predicates: &mut Vec<(ty::Clause<'tcx>, Span)>, + clauses: &mut Vec<(ty::Clause<'tcx>, Span)>, ) { for param in opaque_own_params { let orig_lifetime = tcx.map_opaque_lifetime_to_parent_lifetime(param.def_id.expect_local()); @@ -391,12 +388,12 @@ fn compute_bidirectional_outlives_predicates<'tcx>( ty::EarlyParamRegion { index: param.index, name: param.name }, ); let span = tcx.def_span(param.def_id); - predicates.push(( + clauses.push(( ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(orig_lifetime, dup_lifetime)) .upcast(tcx), span, )); - predicates.push(( + clauses.push(( ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(dup_lifetime, orig_lifetime)) .upcast(tcx), span, @@ -405,15 +402,15 @@ fn compute_bidirectional_outlives_predicates<'tcx>( } } -#[instrument(level = "debug", skip(tcx, predicates), ret)] -fn const_evaluatable_predicates_of<'tcx>( +#[instrument(level = "debug", skip(tcx, clauses), ret)] +fn const_evaluatable_clauses_of<'tcx>( tcx: TyCtxt<'tcx>, def_id: LocalDefId, - predicates: &FxIndexSet<(ty::Clause<'tcx>, Span)>, + clauses: &FxIndexSet<(ty::Clause<'tcx>, Span)>, ) -> FxIndexSet<(ty::Clause<'tcx>, Span)> { struct ConstCollector<'tcx> { tcx: TyCtxt<'tcx>, - preds: FxIndexSet<(ty::Clause<'tcx>, Span)>, + clauses: FxIndexSet<(ty::Clause<'tcx>, Span)>, } fn is_const_param_default(tcx: TyCtxt<'_>, kind: ty::AliasConstKind<'_>) -> bool { @@ -452,7 +449,7 @@ fn const_evaluatable_predicates_of<'tcx>( } let span = alias_const.kind.def_span(self.tcx); - self.preds.insert((ty::ClauseKind::ConstEvaluatable(c).upcast(self.tcx), span)); + self.clauses.insert((ty::ClauseKind::ConstEvaluatable(c).upcast(self.tcx), span)); } } } @@ -460,9 +457,9 @@ fn const_evaluatable_predicates_of<'tcx>( let hir_id = tcx.local_def_id_to_hir_id(def_id); let node = tcx.hir_node(hir_id); - let mut collector = ConstCollector { tcx, preds: FxIndexSet::default() }; + let mut collector = ConstCollector { tcx, clauses: FxIndexSet::default() }; - for (clause, _sp) in predicates { + for (clause, _sp) in clauses { clause.visit_with(&mut collector); } @@ -488,26 +485,26 @@ fn const_evaluatable_predicates_of<'tcx>( fn_sig.visit_with(&mut collector); } - collector.preds + collector.clauses } -pub(super) fn trait_explicit_predicates_and_bounds( +pub(super) fn trait_explicit_clauses_and_bounds( tcx: TyCtxt<'_>, def_id: LocalDefId, -) -> ty::GenericPredicates<'_> { +) -> ty::GenericClauses<'_> { assert_eq!(tcx.def_kind(def_id), DefKind::Trait); - gather_explicit_predicates_of(tcx, def_id) + gather_explicit_clauses_of(tcx, def_id) } -pub(super) fn explicit_predicates_of<'tcx>( +pub(super) fn explicit_clauses_of<'tcx>( tcx: TyCtxt<'tcx>, def_id: LocalDefId, -) -> ty::GenericPredicates<'tcx> { +) -> ty::GenericClauses<'tcx> { let def_kind = tcx.def_kind(def_id); if let DefKind::Trait = def_kind { - // Remove bounds on associated types from the predicates, they will be + // Remove bounds on associated types from the clauses, they will be // returned by `explicit_item_bounds`. - let predicates_and_bounds = tcx.trait_explicit_predicates_and_bounds(def_id); + let clauses_and_bounds = tcx.trait_explicit_clauses_and_bounds(def_id); let trait_identity_args = ty::GenericArgs::identity_for_item(tcx, def_id); let is_assoc_item_ty = |ty: Ty<'tcx>| { @@ -534,11 +531,11 @@ pub(super) fn explicit_predicates_of<'tcx>( } }; - let predicates: Vec<_> = predicates_and_bounds - .predicates + let clauses: Vec<_> = clauses_and_bounds + .clauses .iter() .copied() - .filter(|(pred, _)| match pred.kind().skip_binder() { + .filter(|(clause, _)| match clause.kind().skip_binder() { ty::ClauseKind::Trait(tr) => !is_assoc_item_ty(tr.self_ty()), ty::ClauseKind::Projection(proj) => { !is_assoc_item_ty(proj.projection_term.self_ty()) @@ -547,12 +544,12 @@ pub(super) fn explicit_predicates_of<'tcx>( _ => true, }) .collect(); - if predicates.len() == predicates_and_bounds.predicates.len() { - predicates_and_bounds + if clauses.len() == clauses_and_bounds.clauses.len() { + clauses_and_bounds } else { - ty::GenericPredicates { - parent: predicates_and_bounds.parent, - predicates: tcx.arena.alloc_slice(&predicates), + ty::GenericClauses { + parent: clauses_and_bounds.parent, + clauses: tcx.arena.alloc_slice(&clauses), } } } else { @@ -562,28 +559,28 @@ pub(super) fn explicit_predicates_of<'tcx>( tcx.hir_opt_const_param_default_param_def_id(tcx.local_def_id_to_hir_id(def_id)) { // In `generics_of` we set the generics' parent to be our parent's parent which means that - // we lose out on the predicates of our actual parent if we dont return those predicates here. + // we lose out on the clauses of our actual parent if we dont return those clauses here. // (See comment in `generics_of` for more information on why the parent shenanigans is necessary) // // struct Foo::ASSOC }>(T) where T: Trait; // ^^^ ^^^^^^^^^^^^^^^^^^^^^^^ the def id we are calling - // ^^^ explicit_predicates_of on + // ^^^ explicit_clauses_of on // parent item we dont have set as the // parent of generics returned by `generics_of` // - // In the above code we want the anon const to have predicates in its param env for `T: Trait` - // and we would be calling `explicit_predicates_of(Foo)` here + // In the above code we want the anon const to have clauses in its param env for `T: Trait` + // and we would be calling `explicit_clauses_of(Foo)` here let parent_def_id = tcx.local_parent(def_id); - let parent_preds = tcx.explicit_predicates_of(parent_def_id); + let parent_clauses = tcx.explicit_clauses_of(parent_def_id); - // If we dont filter out `ConstArgHasType` predicates then every single defaulted const parameter + // If we dont filter out `ConstArgHasType` clauses then every single defaulted const parameter // will ICE because of #106994. FIXME(generic_const_exprs): remove this when a more general solution // to #106994 is implemented. - let filtered_predicates = parent_preds - .predicates + let filtered_clauses = parent_clauses + .clauses .into_iter() - .filter(|(pred, _)| { - if let ty::ClauseKind::ConstArgHasType(ct, _) = pred.kind().skip_binder() { + .filter(|(clause, _)| { + if let ty::ClauseKind::ConstArgHasType(ct, _) = clause.kind().skip_binder() { match ct.kind() { ty::ConstKind::Param(param_const) => { let defaulted_param_idx = tcx @@ -591,51 +588,50 @@ pub(super) fn explicit_predicates_of<'tcx>( .param_def_id_to_index[&defaulted_param_def_id.to_def_id()]; param_const.index < defaulted_param_idx } - _ => bug!( - "`ConstArgHasType` in `predicates_of`\ - that isn't a `Param` const" - ), + _ => { + bug!("`ConstArgHasType` in `clauses_of` that isn't a `Param` const") + } } } else { true } }) .cloned(); - return GenericPredicates { - parent: parent_preds.parent, - predicates: { tcx.arena.alloc_from_iter(filtered_predicates) }, + return GenericClauses { + parent: parent_clauses.parent, + clauses: { tcx.arena.alloc_from_iter(filtered_clauses) }, }; } - gather_explicit_predicates_of(tcx, def_id) + gather_explicit_clauses_of(tcx, def_id) } } -/// Ensures that the super-predicates of the trait with a `DefId` +/// Ensures that the super-clauses of the trait with a `DefId` /// of `trait_def_id` are lowered and stored. This also ensures that -/// the transitive super-predicates are lowered. -pub(super) fn explicit_super_predicates_of<'tcx>( +/// the transitive super-clauses are lowered. +pub(super) fn explicit_super_clauses_of<'tcx>( tcx: TyCtxt<'tcx>, trait_def_id: LocalDefId, ) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> { - implied_predicates_with_filter(tcx, trait_def_id.to_def_id(), PredicateFilter::SelfOnly) + implied_clauses_with_filter(tcx, trait_def_id.to_def_id(), PredicateFilter::SelfOnly) } pub(super) fn explicit_supertraits_containing_assoc_item<'tcx>( tcx: TyCtxt<'tcx>, (trait_def_id, assoc_ident): (DefId, Ident), ) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> { - implied_predicates_with_filter( + implied_clauses_with_filter( tcx, trait_def_id, PredicateFilter::SelfTraitThatDefines(assoc_ident), ) } -pub(super) fn explicit_implied_predicates_of<'tcx>( +pub(super) fn explicit_implied_clauses_of<'tcx>( tcx: TyCtxt<'tcx>, trait_def_id: LocalDefId, ) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> { - implied_predicates_with_filter( + implied_clauses_with_filter( tcx, trait_def_id.to_def_id(), if tcx.is_trait_alias(trait_def_id.to_def_id()) { @@ -646,10 +642,10 @@ pub(super) fn explicit_implied_predicates_of<'tcx>( ) } -/// Ensures that the super-predicates of the trait with a `DefId` +/// Ensures that the super-clauses of the trait with a `DefId` /// of `trait_def_id` are lowered and stored. This also ensures that -/// the transitive super-predicates are lowered. -pub(super) fn implied_predicates_with_filter<'tcx>( +/// the transitive super-clauses are lowered. +pub(super) fn implied_clauses_with_filter<'tcx>( tcx: TyCtxt<'tcx>, trait_def_id: DefId, filter: PredicateFilter, @@ -658,7 +654,7 @@ pub(super) fn implied_predicates_with_filter<'tcx>( // if `assoc_ident` is None, then the query should've been redirected to an // external provider assert_matches!(filter, PredicateFilter::SelfTraitThatDefines(_)); - return tcx.explicit_super_predicates_of(trait_def_id); + return tcx.explicit_super_clauses_of(trait_def_id); }; let Node::Item(item) = tcx.hir_node_by_def_id(trait_def_id) else { @@ -668,7 +664,7 @@ pub(super) fn implied_predicates_with_filter<'tcx>( let (generics, superbounds) = match item.kind { hir::ItemKind::Trait { generics, bounds: supertraits, .. } => (generics, supertraits), hir::ItemKind::TraitAlias(_, _, generics, supertraits) => (generics, supertraits), - _ => span_bug!(item.span, "super_predicates invoked on non-trait"), + _ => span_bug!(item.span, "super_clauses invoked on non-trait"), }; let icx = ItemCtxt::new(tcx, trait_def_id); @@ -721,29 +717,29 @@ pub(super) fn implied_predicates_with_filter<'tcx>( // make sure we walk into associated type bounds. match filter { PredicateFilter::SelfOnly => { - for &(pred, span) in implied_bounds { - debug!("superbound: {:?}", pred); - if let ty::ClauseKind::Trait(bound) = pred.kind().skip_binder() + for &(clause, span) in implied_bounds { + debug!("superbound: {:?}", clause); + if let ty::ClauseKind::Trait(bound) = clause.kind().skip_binder() && bound.polarity == ty::PredicatePolarity::Positive { - tcx.at(span).explicit_super_predicates_of(bound.def_id()); + tcx.at(span).explicit_super_clauses_of(bound.def_id()); } } } PredicateFilter::All | PredicateFilter::SelfAndAssociatedTypeBounds => { - for &(pred, span) in implied_bounds { - debug!("superbound: {:?}", pred); - if let ty::ClauseKind::Trait(bound) = pred.kind().skip_binder() + for &(clause, span) in implied_bounds { + debug!("superbound: {:?}", clause); + if let ty::ClauseKind::Trait(bound) = clause.kind().skip_binder() && bound.polarity == ty::PredicatePolarity::Positive { - tcx.at(span).explicit_implied_predicates_of(bound.def_id()); + tcx.at(span).explicit_implied_clauses_of(bound.def_id()); } } } _ => {} } - assert_only_contains_predicates_from(filter, implied_bounds, tcx.types.self_param); + assert_only_contains_clauses_from(filter, implied_bounds, tcx.types.self_param); ty::EarlyBinder::bind_iter(implied_bounds) } @@ -751,7 +747,7 @@ pub(super) fn implied_predicates_with_filter<'tcx>( // Make sure when elaborating supertraits, probing for associated types, etc., // we really truly are elaborating clauses that have `ty` as their self type. // This is very important since downstream code relies on this being correct. -pub(super) fn assert_only_contains_predicates_from<'tcx>( +pub(super) fn assert_only_contains_clauses_from<'tcx>( filter: PredicateFilter, bounds: &'tcx [(ty::Clause<'tcx>, Span)], ty: Ty<'tcx>, @@ -883,16 +879,16 @@ pub(super) fn assert_only_contains_predicates_from<'tcx>( } } -/// Returns the predicates defined on `item_def_id` of the form +/// Returns the clauses defined on `item_def_id` of the form /// `X: Foo` where `X` is the type parameter `def_id`. #[instrument(level = "trace", skip(tcx))] -pub(super) fn type_param_predicates<'tcx>( +pub(super) fn type_param_clauses<'tcx>( tcx: TyCtxt<'tcx>, (item_def_id, def_id, assoc_ident): (LocalDefId, LocalDefId, Ident), ) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> { match tcx.opt_rpitit_info(item_def_id.to_def_id()) { Some(ty::ImplTraitInTraitData::Trait { opaque_def_id, .. }) => { - return tcx.type_param_predicates((opaque_def_id.expect_local(), def_id, assoc_ident)); + return tcx.type_param_clauses((opaque_def_id.expect_local(), def_id, assoc_ident)); } Some(ty::ImplTraitInTraitData::Impl { .. }) => { unreachable!("should not be lowering bounds on RPITIT in impl") @@ -940,16 +936,16 @@ pub(super) fn type_param_predicates<'tcx>( } let icx = ItemCtxt::new(tcx, item_def_id); - let extra_predicates = extend.into_iter().chain(icx.probe_ty_param_bounds_in_generics( + let extra_clauses = extend.into_iter().chain(icx.probe_ty_param_bounds_in_generics( hir_generics, def_id, PredicateFilter::SelfTraitThatDefines(assoc_ident), )); let bounds = - &*tcx.arena.alloc_from_iter(result.skip_binder().iter().copied().chain(extra_predicates)); + &*tcx.arena.alloc_from_iter(result.skip_binder().iter().copied().chain(extra_clauses)); - // Double check that the bounds *only* contain `SelfTy: Trait` preds. + // Double check that the bounds *only* contain `SelfTy: Trait` clauses. let self_ty = match tcx.def_kind(def_id) { DefKind::TyParam => Ty::new_param( tcx, @@ -961,7 +957,7 @@ pub(super) fn type_param_predicates<'tcx>( DefKind::Trait | DefKind::TraitAlias => tcx.types.self_param, _ => unreachable!(), }; - assert_only_contains_predicates_from( + assert_only_contains_clauses_from( PredicateFilter::SelfTraitThatDefines(assoc_ident), bounds, self_ty, @@ -1193,7 +1189,7 @@ pub(super) fn explicit_implied_const_bounds<'tcx>( Node::Item(hir::Item { kind: hir::ItemKind::Trait { .. } | hir::ItemKind::TraitAlias(..), .. - }) => implied_predicates_with_filter( + }) => implied_clauses_with_filter( tcx, def_id.to_def_id(), PredicateFilter::SelfConstIfConst, diff --git a/compiler/rustc_hir_analysis/src/collect/dump.rs b/compiler/rustc_hir_analysis/src/collect/dump.rs index 09ec1084e9055..66968826e5275 100644 --- a/compiler/rustc_hir_analysis/src/collect/dump.rs +++ b/compiler/rustc_hir_analysis/src/collect/dump.rs @@ -45,23 +45,23 @@ pub(crate) fn opaque_hidden_types(tcx: TyCtxt<'_>) { } } -pub(crate) fn predicates_and_item_bounds(tcx: TyCtxt<'_>) { +pub(crate) fn clauses_and_item_bounds(tcx: TyCtxt<'_>) { for id in tcx.hir_crate_items(()).owners() { #[expect(deprecated)] // we don't want to unnecessarily retrieve the attrs twice in a row. let attrs = tcx.get_all_attrs(id); if find_attr!(attrs, RustcDumpPredicates) { - let preds = tcx - .predicates_of(id) + let clauses = tcx + .clauses_of(id) .instantiate_identity(tcx) - .predicates + .clauses .into_iter() .map(Unnormalized::skip_norm_wip); let span = tcx.def_span(id); let mut diag = tcx.dcx().struct_span_err(span, sym::rustc_dump_predicates.as_str()); - for pred in preds { - diag.note(format!("{pred:?}")); + for clause in clauses { + diag.note(format!("{clause:?}")); } diag.emit(); } diff --git a/compiler/rustc_hir_analysis/src/collect/generics_of.rs b/compiler/rustc_hir_analysis/src/collect/generics_of.rs index 0bdaa3dd10183..a986ae3964e26 100644 --- a/compiler/rustc_hir_analysis/src/collect/generics_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/generics_of.rs @@ -138,8 +138,8 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics { // the def id of the `{ N + 1 }` anon const // struct Foo; // - // This has some implications for how we get the predicates available to the anon const - // see `explicit_predicates_of` for more information on this + // This has some implications for how we get the clauses available to the anon const + // see `explicit_clauses_of` for more information on this let generics = tcx.generics_of(parent_did); let param_def_idx = generics.param_def_id_to_index[¶m_id.to_def_id()]; // In the above example this would be .params[..N#0] diff --git a/compiler/rustc_hir_analysis/src/collect/item_bounds.rs b/compiler/rustc_hir_analysis/src/collect/item_bounds.rs index 46007503539ca..4874eacd79b63 100644 --- a/compiler/rustc_hir_analysis/src/collect/item_bounds.rs +++ b/compiler/rustc_hir_analysis/src/collect/item_bounds.rs @@ -11,7 +11,7 @@ use rustc_span::def_id::{DefId, LocalDefId}; use tracing::{debug, instrument}; use super::ItemCtxt; -use super::predicates_of::assert_only_contains_predicates_from; +use super::clauses_of::assert_only_contains_clauses_from; use crate::hir_ty_lowering::{ HirTyLowerer, ImpliedBoundsContext, OverlappingAsssocItemConstraints, PredicateFilter, }; @@ -72,11 +72,11 @@ fn associated_type_bounds<'tcx>( // Also collect `where Self::Assoc: Trait` from the parent trait's where clauses. let trait_def_id = tcx.local_parent(assoc_item_def_id); - let trait_predicates = tcx.trait_explicit_predicates_and_bounds(trait_def_id); + let trait_clauses = tcx.trait_explicit_clauses_and_bounds(trait_def_id); let item_trait_ref = ty::TraitRef::identity(tcx, tcx.parent(assoc_item_def_id.to_def_id())); - bounds.extend(trait_predicates.predicates.iter().copied().filter_map( + bounds.extend(trait_clauses.clauses.iter().copied().filter_map( |(clause, span)| { remap_gat_vars_and_recurse_into_nested_projections( tcx, @@ -94,8 +94,8 @@ fn associated_type_bounds<'tcx>( // FIXME(const_trait_impl): We *could* uplift the // `where Self::Assoc: [const] Trait` bounds from the parent trait // here too, but we'd need to split `const_conditions` into two - // queries (like we do for `trait_explicit_predicates_and_bounds`) - // since we need to also filter the predicates *out* of the const + // queries (like we do for `trait_explicit_clauses_and_bounds`) + // since we need to also filter the clauses *out* of the const // conditions or they lead to cycles in the trait solver when // utilizing these bounds. For now, let's do nothing. } @@ -108,7 +108,7 @@ fn associated_type_bounds<'tcx>( bounds ); - assert_only_contains_predicates_from(filter, bounds, item_ty); + assert_only_contains_clauses_from(filter, bounds, item_ty); bounds }) @@ -465,7 +465,7 @@ pub(super) fn explicit_item_bounds_with_filter( .to_vec() .fold_with(&mut AssocTyToOpaque { tcx, fn_def_id: parent.to_def_id() }), ); - assert_only_contains_predicates_from(filter, bounds, item_ty); + assert_only_contains_clauses_from(filter, bounds, item_ty); bounds } rustc_hir::OpaqueTyOrigin::FnReturn { @@ -480,7 +480,7 @@ pub(super) fn explicit_item_bounds_with_filter( let args = GenericArgs::identity_for_item(tcx, def_id); let item_ty = Ty::new_opaque(tcx, ty::IsRigid::No, def_id.to_def_id(), args); let bounds = opaque_type_bounds(tcx, def_id, bounds, item_ty, *span, filter); - assert_only_contains_predicates_from(filter, bounds, item_ty); + assert_only_contains_clauses_from(filter, bounds, item_ty); bounds } }, diff --git a/compiler/rustc_hir_analysis/src/constrained_generic_params.rs b/compiler/rustc_hir_analysis/src/constrained_generic_params.rs index a392ff5d3a552..36777359076c3 100644 --- a/compiler/rustc_hir_analysis/src/constrained_generic_params.rs +++ b/compiler/rustc_hir_analysis/src/constrained_generic_params.rs @@ -109,22 +109,22 @@ impl<'tcx> TypeVisitor> for ParameterCollector { pub(crate) fn identify_constrained_generic_params<'tcx>( tcx: TyCtxt<'tcx>, - predicates: ty::GenericPredicates<'tcx>, + gen_clauses: ty::GenericClauses<'tcx>, impl_trait_ref: Option>, input_parameters: &mut FxHashSet, ) { - let mut predicates = predicates.predicates.to_vec(); - setup_constraining_predicates(tcx, &mut predicates, impl_trait_ref, input_parameters); + let mut clauses = gen_clauses.clauses.to_vec(); + setup_constraining_clauses(tcx, &mut clauses, impl_trait_ref, input_parameters); } -/// Order the predicates in `predicates` such that each parameter is +/// Order the clauses in `clauses` such that each parameter is /// constrained before it is used, if that is possible, and add the /// parameters so constrained to `input_parameters`. For example, /// imagine the following impl: /// ```ignore (illustrative) /// impl> Trait for U /// ``` -/// The impl's predicates are collected from left to right. Ignoring +/// The impl's clauses are collected from left to right. Ignoring /// the implicit `Sized` bounds, these are /// * `T: Debug` /// * `U: Iterator` @@ -135,9 +135,9 @@ pub(crate) fn identify_constrained_generic_params<'tcx>( /// variables and match them with the impl trait-ref, so we know that /// `$U = IntoIter`. /// -/// However, in order to process the `$T: Debug` predicate, we must first +/// However, in order to process the `$T: Debug` clause, we must first /// know the value of `$T` - which is only given by processing the -/// projection. As we occasionally want to process predicates in a single +/// projection. As we occasionally want to process clauses in a single /// pass, we want the projection to come first. In fact, as projections /// can (acyclically) depend on one another - see RFC447 for details - we /// need to topologically sort them. @@ -161,9 +161,9 @@ pub(crate) fn identify_constrained_generic_params<'tcx>( /// which is determined by 1, which requires `U`, that is determined /// by 0. I should probably pick a less tangled example, but I can't /// think of any. -pub(crate) fn setup_constraining_predicates<'tcx>( +pub(crate) fn setup_constraining_clauses<'tcx>( tcx: TyCtxt<'tcx>, - predicates: &mut [(ty::Clause<'tcx>, Span)], + clauses: &mut [(ty::Clause<'tcx>, Span)], impl_trait_ref: Option>, input_parameters: &mut FxHashSet, ) { @@ -192,19 +192,18 @@ pub(crate) fn setup_constraining_predicates<'tcx>( // * T: Debug // * U: Iterator debug!( - "setup_constraining_predicates: predicates={:?} \ - impl_trait_ref={:?} input_parameters={:?}", - predicates, impl_trait_ref, input_parameters + "setup_constraining_clauses: clauses={:?} impl_trait_ref={:?} input_parameters={:?}", + clauses, impl_trait_ref, input_parameters ); let mut i = 0; let mut changed = true; while changed { changed = false; - for j in i..predicates.len() { + for j in i..clauses.len() { // Note that we don't have to care about binders here, // as the impl trait ref never contains any late-bound regions. - if let ty::ClauseKind::Projection(projection) = predicates[j].0.kind().skip_binder() && + if let ty::ClauseKind::Projection(projection) = clauses[j].0.kind().skip_binder() && // Special case: watch out for some kind of sneaky attempt to // project out an associated type defined by this very trait. @@ -219,15 +218,15 @@ pub(crate) fn setup_constraining_predicates<'tcx>( { input_parameters.extend(parameters_for(tcx, projection.term, false)); - predicates.swap(i, j); + clauses.swap(i, j); i += 1; changed = true; } } debug!( - "setup_constraining_predicates: predicates={:?} \ + "setup_constraining_clauses: clauses={:?} \ i={} impl_trait_ref={:?} input_parameters={:?}", - predicates, i, impl_trait_ref, input_parameters + clauses, i, impl_trait_ref, input_parameters ); } } diff --git a/compiler/rustc_hir_analysis/src/delegation.rs b/compiler/rustc_hir_analysis/src/delegation.rs index 99480251e19ec..d33a1cf736738 100644 --- a/compiler/rustc_hir_analysis/src/delegation.rs +++ b/compiler/rustc_hir_analysis/src/delegation.rs @@ -405,35 +405,35 @@ fn create_generic_args<'tcx>( (args, delegation_parent_args) } -pub(crate) fn inherit_predicates_for_delegation_item<'tcx>( +pub(crate) fn inherit_clauses_for_delegation_item<'tcx>( tcx: TyCtxt<'tcx>, def_id: LocalDefId, sig_id: DefId, -) -> ty::GenericPredicates<'tcx> { - struct PredicatesCollector<'tcx> { +) -> ty::GenericClauses<'tcx> { + struct ClausesCollector<'tcx> { tcx: TyCtxt<'tcx>, - preds: Vec<(ty::Clause<'tcx>, Span)>, + clauses: Vec<(ty::Clause<'tcx>, Span)>, args: Vec>, folder: ParamIndexRemapper<'tcx>, - filter_self_preds: bool, + filter_self_clauses: bool, } - impl<'tcx> PredicatesCollector<'tcx> { - fn with_own_preds( + impl<'tcx> ClausesCollector<'tcx> { + fn with_own_clauses( mut self, - f: impl Fn(DefId) -> ty::GenericPredicates<'tcx>, + f: impl Fn(DefId) -> ty::GenericClauses<'tcx>, def_id: DefId, ) -> Self { - let preds = f(def_id); + let clauses = f(def_id); let args = self.args.as_slice(); - for pred in preds.predicates { + for clause in clauses.clauses { // If self ty is specified then there will be no generic param `Self`, - // so we do not need its predicates. - if self.filter_self_preds - && let Some(trait_pred) = pred.0.as_trait_clause() + // so we do not need its clauses. + if self.filter_self_clauses + && let Some(trait_clause) = clause.0.as_trait_clause() // Rely that `Self` has zero index. - && trait_pred.self_ty().skip_binder().is_param(0) + && trait_clause.self_ty().skip_binder().is_param(0) { continue; } @@ -446,27 +446,27 @@ pub(crate) fn inherit_predicates_for_delegation_item<'tcx>( // reuse Trait::, N>::foo; // } // ``` - // Then if we inherit const predicate from `Trait` then we end up with + // Then if we inherit const clause from `Trait` then we end up with // two `ConstArgHasType` for `N` constant: // 1) ConstArgHasType(N/#0, bool) from `Trait` // 2) ConstArgHasType(N/#0, usize) from delegation parent // So in case the constant came from delegation parent we will not inherit // ConstArgHasType from signature. // The check is so complicated because we build generic args for signature - // and predicates inheritance, for the example above it will be + // and clauses inheritance, for the example above it will be // `args = [S, N/#0, S, N/#0]`, where // args[0] - Self type, args[1] - delegation parent const, args[2] - first // arg of callee path, args[3] - second arg of callee path. - // When processing predicate ConstArgHasType(B/#2, bool) + // When processing clause ConstArgHasType(B/#2, bool) // from delegation signature (`Trait::foo`), we need to map `B/#2` into some // arg from `args`. The mapping which is built by `create_mapping` function is: // `{0: 0, 2: 3, 1: 2}`, so as `B/#2` has index `2` it is mapped into third // arg from `args` - `N/#0`. After we obtained mapped const param, we check if // it came from delegation parent, and if so we do not process its `ConstArgHasType` - // predicate. + // clause. // (Issue #158675). if let ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, _)) = - pred.0.as_predicate().fold_with(&mut self.folder).kind().skip_binder() + clause.0.as_predicate().fold_with(&mut self.folder).kind().skip_binder() { let unnorm_const = EarlyBinder::bind(self.tcx, ct).instantiate(self.tcx, args); if let ty::ConstKind::Param(param) = unnorm_const.skip_norm_wip().kind() @@ -476,60 +476,58 @@ pub(crate) fn inherit_predicates_for_delegation_item<'tcx>( } } - let new_pred = pred.0.fold_with(&mut self.folder); - self.preds.push(( - EarlyBinder::bind(self.tcx, new_pred) + let new_clause = clause.0.fold_with(&mut self.folder); + self.clauses.push(( + EarlyBinder::bind(self.tcx, new_clause) .instantiate(self.tcx, args) .skip_norm_wip(), - pred.1, + clause.1, )); } self } - fn with_preds( + fn with_clauses( mut self, - f: impl Fn(DefId) -> ty::GenericPredicates<'tcx> + Copy, + f: impl Fn(DefId) -> ty::GenericClauses<'tcx> + Copy, def_id: DefId, ) -> Self { let preds = f(def_id); if let Some(parent_def_id) = preds.parent { - self = self.with_own_preds(f, parent_def_id); + self = self.with_own_clauses(f, parent_def_id); } - self.with_own_preds(f, def_id) + self.with_own_clauses(f, def_id) } } let (parent_args, child_args) = tcx.delegation_user_specified_args(def_id); let (folder, args) = create_folder_and_args(tcx, def_id, sig_id, parent_args, child_args); let self_pos_kind = create_self_position_kind(tcx, def_id, sig_id); - let filter_self_preds = matches!( + let filter_self_clauses = matches!( self_pos_kind, SelfPositionKind::AfterLifetimes(Some(DelegationSelfTyPropagationKind::SelfTy(..))) ); - let collector = PredicatesCollector { tcx, preds: vec![], args, folder, filter_self_preds }; + let collector = ClausesCollector { tcx, clauses: vec![], args, folder, filter_self_clauses }; let (parent, inh_kind) = get_parent_and_inheritance_kind(tcx, def_id, sig_id); - // `explicit_predicates_of` is used here to avoid copying `Self: Trait` predicate. - // Note: `predicates_of` query can also add inferred outlives predicates, but that + // `explicit_clauses_of` is used here to avoid copying `Self: Trait` clause. + // Note: `clauses_of` query can also add inferred outlives clauses, but that // is not the case here as `sig_id` is either a trait or a function. - let preds = match inh_kind { + let clauses = match inh_kind { InheritanceKind::WithParent(false) => { - collector.with_preds(|def_id| tcx.explicit_predicates_of(def_id), sig_id) + collector.with_clauses(|def_id| tcx.explicit_clauses_of(def_id), sig_id) } InheritanceKind::WithParent(true) => { - collector.with_preds(|def_id| tcx.predicates_of(def_id), sig_id) - } - InheritanceKind::Own => { - collector.with_own_preds(|def_id| tcx.predicates_of(def_id), sig_id) + collector.with_clauses(|def_id| tcx.clauses_of(def_id), sig_id) } + InheritanceKind::Own => collector.with_own_clauses(|def_id| tcx.clauses_of(def_id), sig_id), } - .preds; + .clauses; - ty::GenericPredicates { parent, predicates: tcx.arena.alloc_from_iter(preds) } + ty::GenericClauses { parent, clauses: tcx.arena.alloc_from_iter(clauses) } } fn create_folder_and_args<'tcx>( diff --git a/compiler/rustc_hir_analysis/src/impl_wf_check.rs b/compiler/rustc_hir_analysis/src/impl_wf_check.rs index 9e4a06e95fd1f..e1a91292abe21 100644 --- a/compiler/rustc_hir_analysis/src/impl_wf_check.rs +++ b/compiler/rustc_hir_analysis/src/impl_wf_check.rs @@ -86,7 +86,7 @@ pub(crate) fn enforce_impl_lifetime_params_are_constrained( impl_self_ty.error_reported()?; let impl_generics = tcx.generics_of(impl_def_id); - let impl_predicates = tcx.predicates_of(impl_def_id); + let impl_clauses = tcx.clauses_of(impl_def_id); let impl_trait_ref = of_trait.then(|| tcx.impl_trait_ref(impl_def_id).instantiate_identity().skip_norm_wip()); @@ -95,7 +95,7 @@ pub(crate) fn enforce_impl_lifetime_params_are_constrained( let mut input_parameters = cgp::parameters_for_impl(tcx, impl_self_ty, impl_trait_ref); cgp::identify_constrained_generic_params( tcx, - impl_predicates, + impl_clauses, impl_trait_ref, &mut input_parameters, ); @@ -201,7 +201,7 @@ pub(crate) fn enforce_impl_non_lifetime_params_are_constrained( impl_self_ty.error_reported()?; let impl_generics = tcx.generics_of(impl_def_id); - let impl_predicates = tcx.predicates_of(impl_def_id); + let impl_clauses = tcx.clauses_of(impl_def_id); let impl_trait_ref = tcx .impl_opt_trait_ref(impl_def_id) .map(ty::EarlyBinder::instantiate_identity) @@ -212,7 +212,7 @@ pub(crate) fn enforce_impl_non_lifetime_params_are_constrained( let mut input_parameters = cgp::parameters_for_impl(tcx, impl_self_ty, impl_trait_ref); cgp::identify_constrained_generic_params( tcx, - impl_predicates, + impl_clauses, impl_trait_ref, &mut input_parameters, ); diff --git a/compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs b/compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs index d6166cf8ef42a..999105640fce2 100644 --- a/compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs +++ b/compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs @@ -213,7 +213,7 @@ fn unconstrained_parent_impl_args<'tcx>( impl_def_id: DefId, impl_args: GenericArgsRef<'tcx>, ) -> Vec> { - let impl_generic_predicates = tcx.predicates_of(impl_def_id); + let impl_generic_clauses = tcx.clauses_of(impl_def_id); let mut unconstrained_parameters = FxHashSet::default(); let mut constrained_params = FxHashSet::default(); let impl_trait_ref = tcx.impl_trait_ref(impl_def_id).instantiate_identity().skip_norm_wip(); @@ -222,7 +222,7 @@ fn unconstrained_parent_impl_args<'tcx>( // what we want here. We want only a list of constrained parameters while // the functions in `cgp` add the constrained parameters to a list of // unconstrained parameters. - for (clause, _) in impl_generic_predicates.predicates.iter() { + for (clause, _) in impl_generic_clauses.clauses.iter() { if let ty::ClauseKind::Projection(proj) = clause.kind().skip_binder() { let unbound_trait_ref = proj.projection_term.trait_ref(tcx); if unbound_trait_ref == impl_trait_ref { @@ -327,7 +327,7 @@ fn check_predicates<'tcx>( ) -> Result<(), ErrorGuaranteed> { let impl1_clauses: Vec<(ty::Clause<'_>, _)> = traits::elaborate( tcx, - tcx.predicates_of(impl1_def_id) + tcx.clauses_of(impl1_def_id) .instantiate(tcx, impl1_args) .into_iter() .map(|(c, s)| (c.skip_norm_wip(), s)), @@ -341,7 +341,7 @@ fn check_predicates<'tcx>( } else { traits::elaborate( tcx, - tcx.predicates_of(impl2_node.def_id()) + tcx.clauses_of(impl2_node.def_id()) .instantiate(tcx, impl2_args) .into_iter() .map(|(c, _s)| c.skip_norm_wip()), diff --git a/compiler/rustc_hir_analysis/src/lib.rs b/compiler/rustc_hir_analysis/src/lib.rs index 9ec74543719dc..1473b0d108fb3 100644 --- a/compiler/rustc_hir_analysis/src/lib.rs +++ b/compiler/rustc_hir_analysis/src/lib.rs @@ -209,7 +209,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) { variance::dump::variances(tcx); collect::dump::generics(tcx); collect::dump::opaque_hidden_types(tcx); - collect::dump::predicates_and_item_bounds(tcx); + collect::dump::clauses_and_item_bounds(tcx); collect::dump::def_parents(tcx); collect::dump::vtables(tcx); }); diff --git a/compiler/rustc_hir_analysis/src/outlives/explicit.rs b/compiler/rustc_hir_analysis/src/outlives/explicit.rs index 97ef6a2461495..fddb9182710d3 100644 --- a/compiler/rustc_hir_analysis/src/outlives/explicit.rs +++ b/compiler/rustc_hir_analysis/src/outlives/explicit.rs @@ -14,22 +14,22 @@ impl<'tcx> ExplicitPredicatesMap<'tcx> { ExplicitPredicatesMap { map: FxIndexMap::default() } } - pub(crate) fn explicit_predicates_of( + pub(crate) fn explicit_clauses_of( &mut self, tcx: TyCtxt<'tcx>, def_id: DefId, ) -> &ty::EarlyBinder<'tcx, RequiredPredicates<'tcx>> { self.map.entry(def_id).or_insert_with(|| { - let predicates = if def_id.is_local() { - tcx.explicit_predicates_of(def_id) + let gen_clauses = if def_id.is_local() { + tcx.explicit_clauses_of(def_id) } else { - tcx.predicates_of(def_id) + tcx.clauses_of(def_id) }; let mut required_predicates = RequiredPredicates::default(); - // process predicates and convert to `RequiredPredicates` entry, see below - for &(predicate, span) in predicates.predicates { - match predicate.kind().skip_binder() { + // Process clauses and convert to `RequiredPredicates` entry, see below. + for &(clause, span) in gen_clauses.clauses { + match clause.kind().skip_binder() { ty::ClauseKind::TypeOutlives(OutlivesPredicate(ty, reg)) => { insert_outlives_predicate( tcx, diff --git a/compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs b/compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs index 239a900afb4cf..8780d877dde50 100644 --- a/compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs +++ b/compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs @@ -255,23 +255,22 @@ fn check_explicit_predicates<'tcx>( explicit_map: &mut ExplicitPredicatesMap<'tcx>, ignore_preds_refing_self: IgnorePredicatesReferencingSelf, ) { - let explicit_predicates = explicit_map.explicit_predicates_of(tcx, def_id); + let explicit_clauses = explicit_map.explicit_clauses_of(tcx, def_id); - for (&predicate @ ty::OutlivesPredicate(arg, _), &span) in - explicit_predicates.as_ref().skip_binder() + for (&clause @ ty::OutlivesPredicate(arg, _), &span) in explicit_clauses.as_ref().skip_binder() { - debug!(?predicate); + debug!(?clause); if let IgnorePredicatesReferencingSelf::Yes = ignore_preds_refing_self && arg.walk().any(|arg| arg == tcx.types.self_param.into()) { - debug!("ignoring predicate since it references `Self`"); + debug!("ignoring clause since it references `Self`"); continue; } - let predicate @ ty::OutlivesPredicate(arg, region) = - explicit_predicates.rebind(predicate).instantiate(tcx, args).skip_norm_wip(); - debug!(?predicate); + let clause @ ty::OutlivesPredicate(arg, region) = + explicit_clauses.rebind(clause).instantiate(tcx, args).skip_norm_wip(); + debug!(?clause); insert_outlives_predicate(tcx, arg, region, span, required_predicates); } diff --git a/compiler/rustc_hir_typeck/src/callee.rs b/compiler/rustc_hir_typeck/src/callee.rs index 1ba299df23613..288a1903bf675 100644 --- a/compiler/rustc_hir_typeck/src/callee.rs +++ b/compiler/rustc_hir_typeck/src/callee.rs @@ -559,23 +559,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // `#[rustc_evaluate_where_clauses]` trigger special output // to let us test the trait evaluation system. if self.has_rustc_attrs && find_attr!(self.tcx, def_id, RustcEvaluateWhereClauses) { - let predicates = self.tcx.predicates_of(def_id); - let predicates = predicates.instantiate(self.tcx, args); - for (predicate, predicate_span) in predicates { - let predicate = predicate.skip_norm_wip(); + let clauses = self.tcx.clauses_of(def_id); + let clauses = clauses.instantiate(self.tcx, args); + for (clause, clause_span) in clauses { + let clause = clause.skip_norm_wip(); let obligation = Obligation::new( self.tcx, ObligationCause::dummy_with_span(callee_expr.span), self.param_env, - predicate, + clause, ); let result = self.evaluate_obligation(&obligation); self.dcx() .struct_span_err( callee_expr.span, - format!("evaluate({predicate:?}) = {result:?}"), + format!("evaluate({clause:?}) = {result:?}"), ) - .with_span_label(predicate_span, "predicate") + .with_span_label(clause_span, "predicate") .emit(); } } diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index 6ffbbed8fd642..c5fb813274992 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -3561,8 +3561,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Register the impl's predicates. One of these predicates // must be unsatisfied, or else we wouldn't have gotten here // in the first place. - let unnormalized_predicates = - self.tcx.predicates_of(impl_def_id).instantiate(self.tcx, impl_args); + let unnormalized_clauses = + self.tcx.clauses_of(impl_def_id).instantiate(self.tcx, impl_args); ocx.register_obligations(traits::predicates_for_generics( |idx, span| { cause.clone().derived_cause( @@ -3574,15 +3574,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ObligationCauseCode::ImplDerived(Box::new(traits::ImplDerivedCause { derived, impl_or_alias_def_id: impl_def_id, - impl_def_predicate_index: Some(idx), + impl_def_clause_index: Some(idx), span, })) }, ) }, - |pred| ocx.normalize(&cause, self.param_env, pred), + |clause| ocx.normalize(&cause, self.param_env, clause), self.param_env, - unnormalized_predicates, + unnormalized_clauses, )); // Normalize the output type, which we can use later on as the diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index b413d0c0bb2de..1886888c476a0 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -567,9 +567,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } - let mut clauses = CollectClauses { clauses: vec![], fcx: self }; - clauses.visit_ty_unambig(hir_ty); - self.tcx.mk_clauses(&clauses.clauses) + let mut collect_clauses = CollectClauses { clauses: vec![], fcx: self }; + collect_clauses.visit_ty_unambig(hir_ty); + self.tcx.mk_clauses(&collect_clauses.clauses) } #[instrument(level = "debug", skip_all)] @@ -1470,11 +1470,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) { let param_env = self.param_env; - let bounds = self.tcx.predicates_of(def_id).instantiate(self.tcx, args); + let bounds = self.tcx.clauses_of(def_id).instantiate(self.tcx, args); for obligation in traits::predicates_for_generics( - |idx, predicate_span| self.cause(span, code(idx, predicate_span)), - |pred| self.normalize(span, pred), + |idx, clause_span| self.cause(span, code(idx, clause_span)), + |clause| self.normalize(span, clause), param_env, bounds, ) { diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs index 5a1bab56b91f2..c0ec4249087c3 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs @@ -14,9 +14,9 @@ use rustc_trait_selection::traits; use crate::FnCtxt; enum ClauseFlavor { - /// Predicate comes from `predicates_of`. + /// Clause comes from `clauses_of`. Where, - /// Predicate comes from `const_conditions`. + /// Clause comes from `const_conditions`. Const, } @@ -54,17 +54,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { _ => return false, }; - let uninstantiated_pred = match flavor { + let uninstantiated_clause = match flavor { ClauseFlavor::Where - if let Some(pred) = self + if let Some(clause) = self .tcx - .predicates_of(def_id) + .clauses_of(def_id) .instantiate_identity(self.tcx) - .predicates + .clauses .into_iter() .nth(idx) => { - pred + clause } ClauseFlavor::Const if let Some((pred, _)) = self @@ -81,7 +81,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let generics = self.tcx.generics_of(def_id); let (predicate_args, predicate_self_type_to_point_at) = - match uninstantiated_pred.kind().skip_binder() { + match uninstantiated_clause.kind().skip_binder() { ty::ClauseKind::Trait(pred) => { (pred.trait_ref.args.to_vec(), Some(pred.self_ty().into())) } @@ -831,19 +831,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // We only really care about the `Self` type itself, which we extract from the ref. let impl_self_ty: Ty<'tcx> = impl_trait_self_ref.self_ty(); - let impl_predicates: ty::GenericPredicates<'tcx> = - self.tcx.predicates_of(obligation.impl_or_alias_def_id); - let Some(impl_predicate_index) = obligation.impl_def_predicate_index else { + let impl_clauses: ty::GenericClauses<'tcx> = + self.tcx.clauses_of(obligation.impl_or_alias_def_id); + let Some(impl_clause_index) = obligation.impl_def_clause_index else { // We don't have the index, so we can only guess. return Err(expr); }; - if impl_predicate_index >= impl_predicates.predicates.len() { - // This shouldn't happen, but since this is only a diagnostic improvement, avoid breaking things. + if impl_clause_index >= impl_clauses.clauses.len() { + // This shouldn't happen, but since this is only a diagnostic improvement, avoid + // breaking things. return Err(expr); } - match impl_predicates.predicates[impl_predicate_index].0.kind().skip_binder() { + match impl_clauses.clauses[impl_clause_index].0.kind().skip_binder() { ty::ClauseKind::Trait(broken_trait) => { // ... self.blame_specific_part_of_expr_corresponding_to_generic_param( diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index c76febd539ef8..9d300a86f9e12 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -1636,14 +1636,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // and point at that. let instantiated = self .tcx - .explicit_predicates_of(self.body_def_id) + .explicit_clauses_of(self.body_def_id) .instantiate_identity(self.tcx); // FIXME(compiler-errors): This could be problematic if something has two // fn-like predicates with different args, but callable types really never // do that, so it's OK. - for (predicate, span) in instantiated { + for (clause, span) in instantiated { if let ty::ClauseKind::Trait(pred) = - predicate.skip_norm_wip().kind().skip_binder() + clause.skip_norm_wip().kind().skip_binder() && pred.self_ty().peel_refs() == callee_ty && self.tcx.is_fn_trait(pred.def_id()) { diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs index b255951baefa6..287e3857087e7 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs @@ -335,10 +335,10 @@ impl<'tcx> HirTyLowerer<'tcx> for FnCtxt<'_, 'tcx> { } // Check whether the impl imposes obligations we have to worry about. - let impl_bounds = tcx.predicates_of(impl_).instantiate(tcx, impl_args); + let impl_bounds = tcx.clauses_of(impl_).instantiate(tcx, impl_args); let impl_obligations = traits::predicates_for_generics( |_, _| ObligationCause::dummy(), - |pred| ocx.normalize(&ObligationCause::dummy(), self.param_env, pred), + |clause| ocx.normalize(&ObligationCause::dummy(), self.param_env, clause), self.param_env, impl_bounds, ); diff --git a/compiler/rustc_hir_typeck/src/method/confirm.rs b/compiler/rustc_hir_typeck/src/method/confirm.rs index d5dc17837f1ed..05463cd9ae3f7 100644 --- a/compiler/rustc_hir_typeck/src/method/confirm.rs +++ b/compiler/rustc_hir_typeck/src/method/confirm.rs @@ -115,7 +115,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { debug!("rcvr_args={rcvr_args:?}, all_args={all_args:?}"); // Create the final signature for the method, replacing late-bound regions. - let (method_sig, method_predicates) = self.instantiate_method_sig(pick, all_args); + let (method_sig, method_clauses) = self.instantiate_method_sig(pick, all_args); // If there is a `Self: Sized` bound and `Self` is a trait object, it is possible that // something which derefs to `Self` actually implements the trait and the caller @@ -127,8 +127,8 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { // appropriate hint suggesting to import the trait. let filler_args = rcvr_args .extend_to(self.tcx, pick.item.def_id, |def, _| self.tcx.mk_param_from_def(def)); - let illegal_sized_bound = self.predicates_require_illegal_sized_bound( - self.tcx.predicates_of(pick.item.def_id).instantiate(self.tcx, filler_args), + let illegal_sized_bound = self.clauses_require_illegal_sized_bound( + self.tcx.clauses_of(pick.item.def_id).instantiate(self.tcx, filler_args), ); // Unify the (adjusted) self type with what the method expects. @@ -140,8 +140,8 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { let method_sig_rcvr = self.normalize(self.span, Unnormalized::new_wip(method_sig.inputs()[0])); debug!( - "confirm: self_ty={:?} method_sig_rcvr={:?} method_sig={:?} method_predicates={:?}", - self_ty, method_sig_rcvr, method_sig, method_predicates + "confirm: self_ty={:?} method_sig_rcvr={:?} method_sig={:?} method_clauses={:?}", + self_ty, method_sig_rcvr, method_sig, method_clauses ); self.unify_receivers(self_ty, method_sig_rcvr, pick); @@ -160,7 +160,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { // We won't add these if we encountered an illegal sized bound, so that we can use // a custom error in that case. if illegal_sized_bound.is_none() { - self.add_obligations(method_sig, all_args, method_predicates, pick.item.def_id); + self.add_obligations(method_sig, all_args, method_clauses, pick.item.def_id); } // Create the final `MethodCallee`. @@ -595,16 +595,16 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { &mut self, pick: &probe::Pick<'tcx>, all_args: GenericArgsRef<'tcx>, - ) -> (ty::FnSig<'tcx>, ty::InstantiatedPredicates<'tcx>) { + ) -> (ty::FnSig<'tcx>, ty::InstantiatedClauses<'tcx>) { debug!("instantiate_method_sig(pick={:?}, all_args={:?})", pick, all_args); // Instantiate the bounds on the method with the // type/early-bound-regions instantiations performed. There can // be no late-bound regions appearing here. let def_id = pick.item.def_id; - let method_predicates = self.tcx.predicates_of(def_id).instantiate(self.tcx, all_args); + let method_clauses = self.tcx.clauses_of(def_id).instantiate(self.tcx, all_args); - debug!("method_predicates after instantiation = {:?}", method_predicates); + debug!("method_clauses after instantiation = {:?}", method_clauses); let sig = self.tcx.fn_sig(def_id).instantiate(self.tcx, all_args).skip_norm_wip(); debug!("type scheme instantiated, sig={:?}", sig); @@ -612,22 +612,22 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { let sig = self.instantiate_binder_with_fresh_vars(sig); debug!("late-bound lifetimes from method instantiated, sig={:?}", sig); - (sig, method_predicates) + (sig, method_clauses) } fn add_obligations( &mut self, sig: ty::FnSig<'tcx>, all_args: GenericArgsRef<'tcx>, - method_predicates: ty::InstantiatedPredicates<'tcx>, + method_clauses: ty::InstantiatedClauses<'tcx>, def_id: DefId, ) { debug!( - "add_obligations: sig={:?} all_args={:?} method_predicates={:?} def_id={:?}", - sig, all_args, method_predicates, def_id + "add_obligations: sig={:?} all_args={:?} method_clauses={:?} def_id={:?}", + sig, all_args, method_clauses, def_id ); - // FIXME: could replace with the following, but we already calculated `method_predicates`, + // FIXME: could replace with the following, but we already calculated `method_clauses`, // so we just call `predicates_for_generics` directly to avoid redoing work. // `self.add_required_obligations(self.span, def_id, &all_args);` for obligation in traits::predicates_for_generics( @@ -640,9 +640,9 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { ); self.cause(self.span, code) }, - |pred| self.normalize(self.call_expr.span, pred), + |clause| self.normalize(self.call_expr.span, clause), self.param_env, - method_predicates, + method_clauses, ) { self.register_predicate(obligation); } @@ -666,22 +666,24 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { /////////////////////////////////////////////////////////////////////////// // MISCELLANY - fn predicates_require_illegal_sized_bound( + fn clauses_require_illegal_sized_bound( &self, - predicates: ty::InstantiatedPredicates<'tcx>, + inst_clauses: ty::InstantiatedClauses<'tcx>, ) -> Option { let sized_def_id = self.tcx.lang_items().sized_trait()?; traits::elaborate( self.tcx, - predicates.predicates.iter().copied().map(Unnormalized::skip_norm_wip), + inst_clauses.clauses.iter().copied().map(Unnormalized::skip_norm_wip), ) // We don't care about regions here. - .filter_map(|pred| match pred.kind().skip_binder() { + .filter_map(|clause| match clause.kind().skip_binder() { ty::ClauseKind::Trait(trait_pred) if trait_pred.def_id() == sized_def_id => { - let span = predicates + let span = inst_clauses .iter() - .find_map(|(p, span)| if p.skip_norm_wip() == pred { Some(span) } else { None }) + .find_map( + |(c, span)| if c.skip_norm_wip() == clause { Some(span) } else { None }, + ) .unwrap_or(DUMMY_SP); Some((trait_pred, span)) } diff --git a/compiler/rustc_hir_typeck/src/method/mod.rs b/compiler/rustc_hir_typeck/src/method/mod.rs index dd8ffc5a7fd46..3425ba5d747d6 100644 --- a/compiler/rustc_hir_typeck/src/method/mod.rs +++ b/compiler/rustc_hir_typeck/src/method/mod.rs @@ -440,15 +440,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // // Note that as the method comes from a trait, it should not have // any late-bound regions appearing in its bounds. - let bounds = self.tcx.predicates_of(def_id).instantiate(self.tcx, args); + let bounds = self.tcx.clauses_of(def_id).instantiate(self.tcx, args); let predicates_cause = obligation.cause.clone(); let mut normalization_obligations = PredicateObligations::new(); obligations.extend(traits::predicates_for_generics( move |_, _| predicates_cause.clone(), - |pred| { + |clause| { let InferOk { value: pred, obligations: o } = - self.at(&obligation.cause, self.param_env).normalize(pred); + self.at(&obligation.cause, self.param_env).normalize(clause); normalization_obligations.extend(o); assert!(!pred.has_escaping_bound_vars()); pred diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index dfb4647b5e6e2..eab4e1990455c 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -2037,7 +2037,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { // Check whether the impl imposes obligations we have to worry about. let impl_def_id = probe.item.container_id(self.tcx); let impl_bounds = - self.tcx.predicates_of(impl_def_id).instantiate(self.tcx, impl_args); + self.tcx.clauses_of(impl_def_id).instantiate(self.tcx, impl_args); // Convert the bounds into obligations. ocx.register_obligations(traits::predicates_for_generics( |idx, span| { @@ -2049,7 +2049,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { ); self.cause(self.span, code) }, - |pred| ocx.normalize(cause, self.param_env, pred), + |clause| ocx.normalize(cause, self.param_env, clause), self.param_env, impl_bounds, )); diff --git a/compiler/rustc_incremental/src/persist/clean.rs b/compiler/rustc_incremental/src/persist/clean.rs index a8eb1ff3d5a42..d3a04ab5946b7 100644 --- a/compiler/rustc_incremental/src/persist/clean.rs +++ b/compiler/rustc_incremental/src/persist/clean.rs @@ -45,7 +45,7 @@ const BASE_FN: &[&str] = &[ // Callers will depend on the signature of these items, so we better test label_strs::fn_sig, label_strs::generics_of, - label_strs::predicates_of, + label_strs::clauses_of, label_strs::type_of, // And a big part of compilation (that we eventually want to cache) is type inference // information: @@ -71,7 +71,7 @@ const BASE_MIR: &[&str] = &[label_strs::optimized_mir, label_strs::promoted_mir] /// Note that changing the type of a field does not change the type of the struct or enum, but /// adding/removing fields or changing a fields name or visibility does. const BASE_STRUCT: &[&str] = - &[label_strs::generics_of, label_strs::predicates_of, label_strs::type_of]; + &[label_strs::generics_of, label_strs::clauses_of, label_strs::type_of]; /// Trait definition `DepNode`s. /// Extra `DepNode`s for functions and methods. @@ -105,7 +105,7 @@ const LABELS_HIR_ONLY: &[&[&str]] = &[BASE_HIR]; /// Impl `DepNode`s. const LABELS_TRAIT: &[&[&str]] = &[ BASE_HIR, - &[label_strs::associated_item_def_ids, label_strs::predicates_of, label_strs::generics_of], + &[label_strs::associated_item_def_ids, label_strs::clauses_of, label_strs::generics_of], ]; /// Impl `DepNode`s. diff --git a/compiler/rustc_infer/src/traits/util.rs b/compiler/rustc_infer/src/traits/util.rs index 49e8d9a1f44fb..2630c8b125418 100644 --- a/compiler/rustc_infer/src/traits/util.rs +++ b/compiler/rustc_infer/src/traits/util.rs @@ -88,7 +88,7 @@ impl<'tcx> Elaboratable> for PredicateObligation<'tcx> { ObligationCauseCode::ImplDerived(Box::new(traits::ImplDerivedCause { derived, impl_or_alias_def_id: parent_trait_pred.def_id(), - impl_def_predicate_index: Some(index), + impl_def_clause_index: Some(index), span, })) }); diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index dd56b13cb2f5e..3506868402c99 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -1450,9 +1450,9 @@ impl<'tcx> LateLintPass<'tcx> for TrivialConstraints { use rustc_middle::ty::ClauseKind; if cx.tcx.features().trivial_bounds() { - let predicates = cx.tcx.predicates_of(item.owner_id); - for &(predicate, span) in predicates.predicates { - let predicate_kind_name = match predicate.kind().skip_binder() { + let gen_clauses = cx.tcx.clauses_of(item.owner_id); + for &(clause, span) in gen_clauses.clauses { + let clause_kind_name = match clause.kind().skip_binder() { ClauseKind::Trait(..) => "trait", ClauseKind::TypeOutlives(..) | ClauseKind::RegionOutlives(..) => "lifetime", @@ -1469,11 +1469,11 @@ impl<'tcx> LateLintPass<'tcx> for TrivialConstraints { // Users don't write this directly, only via another trait ref. | ty::ClauseKind::HostEffect(..) => continue, }; - if predicate.is_global() { + if clause.is_global() { cx.emit_span_lint( TRIVIAL_BOUNDS, span, - BuiltinTrivialBounds { predicate_kind_name, predicate }, + BuiltinTrivialBounds { clause_kind_name, clause }, ); } } diff --git a/compiler/rustc_lint/src/internal.rs b/compiler/rustc_lint/src/internal.rs index f8f229a372ceb..b2c063922e90e 100644 --- a/compiler/rustc_lint/src/internal.rs +++ b/compiler/rustc_lint/src/internal.rs @@ -129,19 +129,22 @@ fn has_unstable_into_iter_predicate<'tcx>( let Some(into_iter_fn_def_id) = cx.tcx.lang_items().into_iter_fn() else { return false; }; - let predicates = cx.tcx.predicates_of(callee_def_id).instantiate(cx.tcx, generic_args); - for (predicate, _) in predicates { - let Some(trait_pred) = predicate.as_trait_clause() else { + let clauses = cx.tcx.clauses_of(callee_def_id).instantiate(cx.tcx, generic_args); + for (clause, _) in clauses { + let Some(trait_clause) = clause.as_trait_clause() else { continue; }; - if trait_pred.def_id() != into_iterator_def_id - || trait_pred.polarity() != PredicatePolarity::Positive + if trait_clause.def_id() != into_iterator_def_id + || trait_clause.polarity() != PredicatePolarity::Positive { continue; } // `IntoIterator::into_iter` has no additional method args. - let into_iter_fn_args = - cx.tcx.instantiate_bound_regions_with_erased(trait_pred.skip_norm_wip()).trait_ref.args; + let into_iter_fn_args = cx + .tcx + .instantiate_bound_regions_with_erased(trait_clause.skip_norm_wip()) + .trait_ref + .args; let Ok(Some(instance)) = ty::Instance::try_resolve( cx.tcx, cx.typing_env(), diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index 76342272e7df0..a745da56357a4 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -384,12 +384,10 @@ impl<'a> Diagnostic<'a, ()> for BuiltinTypeAliasBounds<'_> { } #[derive(Diagnostic)] -#[diag( - "{$predicate_kind_name} bound {$predicate} does not depend on any type or lifetime parameters" -)] +#[diag("{$clause_kind_name} bound {$clause} does not depend on any type or lifetime parameters")] pub(crate) struct BuiltinTrivialBounds<'a> { - pub predicate_kind_name: &'a str, - pub predicate: Clause<'a>, + pub clause_kind_name: &'a str, + pub clause: Clause<'a>, } #[derive(Diagnostic)] @@ -1880,7 +1878,7 @@ pub(crate) struct RedundantSemicolonsSuggestion { // traits.rs pub(crate) struct DropTraitConstraintsDiag<'a> { - pub predicate: Clause<'a>, + pub clause: Clause<'a>, pub tcx: TyCtxt<'a>, pub def_id: DefId, } @@ -1888,8 +1886,8 @@ pub(crate) struct DropTraitConstraintsDiag<'a> { // Needed for def_path_str impl<'a> Diagnostic<'a, ()> for DropTraitConstraintsDiag<'_> { fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> { - Diag::new(dcx, level, msg!("bounds on `{$predicate}` are most likely incorrect, consider instead using `{$needs_drop}` to detect whether a type can be trivially dropped")) - .with_arg("predicate", self.predicate) + Diag::new(dcx, level, msg!("bounds on `{$clause}` are most likely incorrect, consider instead using `{$needs_drop}` to detect whether a type can be trivially dropped")) + .with_arg("clause", self.clause) .with_arg("needs_drop", self.tcx.def_path_str(self.def_id)) } } diff --git a/compiler/rustc_lint/src/multiple_supertrait_upcastable.rs b/compiler/rustc_lint/src/multiple_supertrait_upcastable.rs index be6bd68c8140f..7f0c615923ef1 100644 --- a/compiler/rustc_lint/src/multiple_supertrait_upcastable.rs +++ b/compiler/rustc_lint/src/multiple_supertrait_upcastable.rs @@ -45,10 +45,10 @@ impl<'tcx> LateLintPass<'tcx> for MultipleSupertraitUpcastable { { let direct_super_traits_iter = cx .tcx - .explicit_super_predicates_of(def_id) + .explicit_super_clauses_of(def_id) .iter_identity_copied() .map(Unnormalized::skip_norm_wip) - .filter_map(|(pred, _)| pred.as_trait_clause()) + .filter_map(|(clause, _)| clause.as_trait_clause()) .filter(|pred| !cx.tcx.is_lang_item(pred.def_id(), hir::LangItem::MetaSized)) .filter(|pred| !cx.tcx.is_default_trait(pred.def_id())); if direct_super_traits_iter.count() > 1 { diff --git a/compiler/rustc_lint/src/traits.rs b/compiler/rustc_lint/src/traits.rs index 9c2aada46c415..f5b21792af3ce 100644 --- a/compiler/rustc_lint/src/traits.rs +++ b/compiler/rustc_lint/src/traits.rs @@ -89,9 +89,9 @@ impl<'tcx> LateLintPass<'tcx> for DropTraitConstraints { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) { use rustc_middle::ty::ClauseKind; - let predicates = cx.tcx.explicit_predicates_of(item.owner_id); - for &(predicate, span) in predicates.predicates { - let ClauseKind::Trait(trait_predicate) = predicate.kind().skip_binder() else { + let gen_clauses = cx.tcx.explicit_clauses_of(item.owner_id); + for &(clause, span) in gen_clauses.clauses { + let ClauseKind::Trait(trait_predicate) = clause.kind().skip_binder() else { continue; }; let def_id = trait_predicate.trait_ref.def_id; @@ -104,7 +104,7 @@ impl<'tcx> LateLintPass<'tcx> for DropTraitConstraints { cx.emit_span_lint( DROP_BOUNDS, span, - DropTraitConstraintsDiag { predicate, tcx: cx.tcx, def_id }, + DropTraitConstraintsDiag { clause, tcx: cx.tcx, def_id }, ); } } diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index 9acebc1a4822f..ca78640f135f4 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -230,11 +230,11 @@ impl IntoArgs for (CrateNum, SimplifiedType) { provide! { tcx, def_id, other, cdata, explicit_item_bounds => { table_defaulted_array } explicit_item_self_bounds => { table_defaulted_array } - explicit_predicates_of => { table } + explicit_clauses_of => { table } generics_of => { table } inferred_outlives_of => { table_defaulted_array } - explicit_super_predicates_of => { table_defaulted_array } - explicit_implied_predicates_of => { table_defaulted_array } + explicit_super_clauses_of => { table_defaulted_array } + explicit_implied_clauses_of => { table_defaulted_array } type_of => { table } type_alias_is_checked => { table_direct } variances_of => { table } diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 53b825baae6a7..7209e3d8ec338 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -1481,7 +1481,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { if should_encode_generics(def_kind) { let g = tcx.generics_of(def_id); record!(self.tables.generics_of[def_id] <- g); - record!(self.tables.explicit_predicates_of[def_id] <- self.tcx.explicit_predicates_of(def_id)); + record!(self.tables.explicit_clauses_of[def_id] <- self.tcx.explicit_clauses_of(def_id)); let inferred_outlives = self.tcx.inferred_outlives_of(def_id); record_defaulted_array!(self.tables.inferred_outlives_of[def_id] <- inferred_outlives); @@ -1516,10 +1516,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { } if let DefKind::Trait = def_kind { record!(self.tables.trait_def[def_id] <- self.tcx.trait_def(def_id)); - record_defaulted_array!(self.tables.explicit_super_predicates_of[def_id] <- - self.tcx.explicit_super_predicates_of(def_id).skip_binder()); - record_defaulted_array!(self.tables.explicit_implied_predicates_of[def_id] <- - self.tcx.explicit_implied_predicates_of(def_id).skip_binder()); + record_defaulted_array!(self.tables.explicit_super_clauses_of[def_id] <- + self.tcx.explicit_super_clauses_of(def_id).skip_binder()); + record_defaulted_array!(self.tables.explicit_implied_clauses_of[def_id] <- + self.tcx.explicit_implied_clauses_of(def_id).skip_binder()); let module_children = self.tcx.module_children_local(local_id); record_array!(self.tables.module_children_non_reexports[def_id] <- module_children.iter().map(|child| child.res.def_id().index)); @@ -1530,10 +1530,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { } if let DefKind::TraitAlias = def_kind { record!(self.tables.trait_def[def_id] <- self.tcx.trait_def(def_id)); - record_defaulted_array!(self.tables.explicit_super_predicates_of[def_id] <- - self.tcx.explicit_super_predicates_of(def_id).skip_binder()); - record_defaulted_array!(self.tables.explicit_implied_predicates_of[def_id] <- - self.tcx.explicit_implied_predicates_of(def_id).skip_binder()); + record_defaulted_array!(self.tables.explicit_super_clauses_of[def_id] <- + self.tcx.explicit_super_clauses_of(def_id).skip_binder()); + record_defaulted_array!(self.tables.explicit_implied_clauses_of[def_id] <- + self.tcx.explicit_implied_clauses_of(def_id).skip_binder()); } if let DefKind::Trait | DefKind::Impl { .. } = def_kind { let associated_item_def_ids = self.tcx.associated_item_def_ids(def_id); diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index 237672878bb4c..63096ecd2c636 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -397,8 +397,8 @@ define_tables! { explicit_item_bounds: Table, Span)>>, explicit_item_self_bounds: Table, Span)>>, inferred_outlives_of: Table, Span)>>, - explicit_super_predicates_of: Table, Span)>>, - explicit_implied_predicates_of: Table, Span)>>, + explicit_super_clauses_of: Table, Span)>>, + explicit_implied_clauses_of: Table, Span)>>, explicit_implied_const_bounds: Table, Span)>>, inherent_impls: Table>, opt_rpitit_info: Table>>, @@ -429,7 +429,7 @@ define_tables! { lookup_const_stability: Table>, lookup_default_body_stability: Table>, lookup_deprecation_entry: Table>, - explicit_predicates_of: Table>>, + explicit_clauses_of: Table>>, generics_of: Table>, type_of: Table>>>, variances_of: Table>, diff --git a/compiler/rustc_metadata/src/rmeta/parameterized.rs b/compiler/rustc_metadata/src/rmeta/parameterized.rs index feb6859eabd5b..a156dbb21d6ba 100644 --- a/compiler/rustc_metadata/src/rmeta/parameterized.rs +++ b/compiler/rustc_metadata/src/rmeta/parameterized.rs @@ -168,7 +168,7 @@ parameterized_over_tcx! { rustc_middle::ty::Const, rustc_middle::ty::ConstConditions, rustc_middle::ty::FnSig, - rustc_middle::ty::GenericPredicates, + rustc_middle::ty::GenericClauses, rustc_middle::ty::ImplTraitHeader, rustc_middle::ty::TraitRef, rustc_middle::ty::Ty, diff --git a/compiler/rustc_middle/src/mono.rs b/compiler/rustc_middle/src/mono.rs index 00bb3a2ee66a4..dc9a94f79aa0f 100644 --- a/compiler/rustc_middle/src/mono.rs +++ b/compiler/rustc_middle/src/mono.rs @@ -278,7 +278,7 @@ impl<'tcx> MonoItem<'tcx> { MonoItem::GlobalAsm(..) => return true, }; - !tcx.instantiate_and_check_impossible_predicates((def_id, &args)) + !tcx.instantiate_and_check_impossible_clauses((def_id, &args)) } pub fn local_span(&self, tcx: TyCtxt<'tcx>) -> Option { diff --git a/compiler/rustc_middle/src/queries.rs b/compiler/rustc_middle/src/queries.rs index a72f7021b7768..7aeff35a965f2 100644 --- a/compiler/rustc_middle/src/queries.rs +++ b/compiler/rustc_middle/src/queries.rs @@ -413,15 +413,15 @@ rustc_queries! { feedable } - /// Returns the (elaborated) *predicates* of the definition given by `DefId` + /// Returns the (elaborated) *clauses* of the definition given by `DefId` /// that must be proven true at usage sites (and which can be assumed at definition site). /// - /// This is almost always *the* "predicates query" that you want. + /// This is almost always *the* predicates/clauses query that you want. /// /// **Tip**: You can use `#[rustc_dump_predicates]` on an item to basically print /// the result of this query for use in UI tests or for debugging purposes. - query predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> { - desc { "computing predicates of `{}`", tcx.def_path_str(key) } + query clauses_of(key: DefId) -> ty::GenericClauses<'tcx> { + desc { "computing clauses of `{}`", tcx.def_path_str(key) } } query opaque_types_defined_by( @@ -764,9 +764,9 @@ rustc_queries! { desc { "getting wasm import module map" } } - /// Returns the explicitly user-written *predicates and bounds* of the trait given by `DefId`. + /// Returns the explicitly user-written *clauses and bounds* of the trait given by `DefId`. /// - /// Traits are unusual, because predicates on associated types are + /// Traits are unusual, because clauses on associated types are /// converted into bounds on that type for backwards compatibility: /// /// ``` @@ -779,22 +779,22 @@ rustc_queries! { /// trait X { type U: Copy; } /// ``` /// - /// [`Self::explicit_predicates_of`] and [`Self::explicit_item_bounds`] will - /// then take the appropriate subsets of the predicates here. + /// [`Self::explicit_clauses_of`] and [`Self::explicit_item_bounds`] will + /// then take the appropriate subsets of the clauses here. /// /// # Panics /// /// This query will panic if the given definition is not a trait. - query trait_explicit_predicates_and_bounds(key: LocalDefId) -> ty::GenericPredicates<'tcx> { - desc { "computing explicit predicates of trait `{}`", tcx.def_path_str(key) } + query trait_explicit_clauses_and_bounds(key: LocalDefId) -> ty::GenericClauses<'tcx> { + desc { "computing explicit clauses of trait `{}`", tcx.def_path_str(key) } } - /// Returns the explicitly user-written *predicates* of the definition given by `DefId` + /// Returns the explicitly user-written *clauses* of the definition given by `DefId` /// that must be proven true at usage sites (and which can be assumed at definition site). /// - /// You should probably use [`TyCtxt::predicates_of`] unless you're looking for - /// predicates with explicit spans for diagnostics purposes. - query explicit_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> { + /// You should probably use [`TyCtxt::clauses_of`] unless you're looking for + /// clauses with explicit spans for diagnostics purposes. + query explicit_clauses_of(key: DefId) -> ty::GenericClauses<'tcx> { desc { "computing explicit predicates of `{}`", tcx.def_path_str(key) } cache_on_disk separate_provide_extern @@ -814,27 +814,27 @@ rustc_queries! { feedable } - /// Returns the explicitly user-written *super-predicates* of the trait given by `DefId`. + /// Returns the explicitly user-written *super-clauses* of the trait given by `DefId`. /// - /// These predicates are unelaborated and consequently don't contain transitive super-predicates. + /// These clauses are unelaborated and consequently don't contain transitive super-clauses. /// - /// This is a subset of the full list of predicates. We store these in a separate map + /// This is a subset of the full list of clauses. We store these in a separate map /// because we must evaluate them even during type conversion, often before the full - /// predicates are available (note that super-predicates must not be cyclic). - query explicit_super_predicates_of(key: DefId) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> { - desc { "computing the super predicates of `{}`", tcx.def_path_str(key) } + /// clauses are available (note that super-clauses must not be cyclic). + query explicit_super_clauses_of(key: DefId) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> { + desc { "computing the super clauses of `{}`", tcx.def_path_str(key) } cache_on_disk separate_provide_extern } - /// The predicates of the trait that are implied during elaboration. + /// The clauses of the trait that are implied during elaboration. /// - /// This is a superset of the super-predicates of the trait, but a subset of the predicates - /// of the trait. For regular traits, this includes all super-predicates and their + /// This is a superset of the super-clauses of the trait, but a subset of the clauses + /// of the trait. For regular traits, this includes all super-clauses and their /// associated type bounds. For trait aliases, currently, this includes all of the - /// predicates of the trait alias. - query explicit_implied_predicates_of(key: DefId) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> { - desc { "computing the implied predicates of `{}`", tcx.def_path_str(key) } + /// clauses of the trait alias. + query explicit_implied_clauses_of(key: DefId) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> { + desc { "computing the implied clauses of `{}`", tcx.def_path_str(key) } cache_on_disk separate_provide_extern } @@ -854,7 +854,7 @@ rustc_queries! { /// Compute the conditions that need to hold for a conditionally-const item to be const. /// That is, compute the set of `[const]` where clauses for a given item. /// - /// This can be thought of as the `[const]` equivalent of `predicates_of`. These are the + /// This can be thought of as the `[const]` equivalent of `clauses_of`. These are the /// predicates that need to be proven at usage sites, and can be assumed at definition. /// /// This query also computes the `[const]` where clauses for associated types, which are @@ -883,9 +883,9 @@ rustc_queries! { separate_provide_extern } - /// To avoid cycles within the predicates of a single item we compute - /// per-type-parameter predicates for resolving `T::AssocTy`. - query type_param_predicates( + /// To avoid cycles within the clauses of a single item we compute + /// per-type-parameter clauses for resolving `T::AssocTy`. + query type_param_clauses( key: (LocalDefId, LocalDefId, rustc_span::Ident) ) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> { desc { "computing the bounds for type parameter `{}`", tcx.hir_ty_param_name(key.1) } @@ -2602,9 +2602,9 @@ rustc_queries! { desc { "normalizing `{:?}`", goal.canonical.value.value.value.skip_normalization() } } - query instantiate_and_check_impossible_predicates(key: (DefId, GenericArgsRef<'tcx>)) -> bool { + query instantiate_and_check_impossible_clauses(key: (DefId, GenericArgsRef<'tcx>)) -> bool { desc { - "checking impossible instantiated predicates: `{}`", + "checking impossible instantiated clauses: `{}`", tcx.def_path_str(key.0) } } diff --git a/compiler/rustc_middle/src/query/erase.rs b/compiler/rustc_middle/src/query/erase.rs index 827ae5a8edbdf..9a6ab2732953a 100644 --- a/compiler/rustc_middle/src/query/erase.rs +++ b/compiler/rustc_middle/src/query/erase.rs @@ -242,7 +242,7 @@ impl_erasable_for_types_with_no_type_params! { rustc_middle::ty::ClosureTypeInfo<'_>, rustc_middle::ty::Const<'_>, rustc_middle::ty::ConstConditions<'_>, - rustc_middle::ty::GenericPredicates<'_>, + rustc_middle::ty::GenericClauses<'_>, rustc_middle::ty::ImplTraitHeader<'_>, rustc_middle::ty::ParamEnv<'_>, rustc_middle::ty::SymbolName<'_>, diff --git a/compiler/rustc_middle/src/traits/mod.rs b/compiler/rustc_middle/src/traits/mod.rs index 58a8eeeb242c0..4126531229b48 100644 --- a/compiler/rustc_middle/src/traits/mod.rs +++ b/compiler/rustc_middle/src/traits/mod.rs @@ -204,12 +204,12 @@ pub enum ObligationCauseCode<'tcx> { /// Like `WhereClause`, but also identifies the expression /// which requires the `where` clause to be proven, and also - /// identifies the index of the predicate in the `predicates_of` + /// identifies the index of the clause in the `clauses_of` /// list of the item. WhereClauseInExpr(DefId, Span, HirId, usize), /// Like `WhereClauseinExpr`, but indexes into the `const_conditions` - /// rather than the `predicates_of`. + /// rather than the `clauses_of`. HostEffectInExpr(DefId, Span, HirId, usize), /// A type like `&'a T` is WF only if `T: 'a`. @@ -592,8 +592,8 @@ pub struct ImplDerivedCause<'tcx> { /// impl, then this will be the `DefId` of that trait alias. Care should therefore be taken to /// handle that exceptional case where appropriate. pub impl_or_alias_def_id: DefId, - /// The index of the derived predicate in the parent impl's predicates. - pub impl_def_predicate_index: Option, + /// The index of the derived clause in the parent impl's clauses. + pub impl_def_clause_index: Option, pub span: Span, } diff --git a/compiler/rustc_middle/src/ty/adt.rs b/compiler/rustc_middle/src/ty/adt.rs index 09177b12ddced..bf8b650f4594e 100644 --- a/compiler/rustc_middle/src/ty/adt.rs +++ b/compiler/rustc_middle/src/ty/adt.rs @@ -23,7 +23,7 @@ use rustc_type_ir::solve::AdtDestructorKind; use tracing::{debug, info, trace}; use super::{ - AsyncDestructor, Destructor, FieldDef, GenericPredicates, Ty, TyCtxt, VariantDef, VariantDiscr, + AsyncDestructor, Destructor, FieldDef, GenericClauses, Ty, TyCtxt, VariantDef, VariantDiscr, }; use crate::mir::interpret::ErrorHandled; use crate::ty::util::{Discr, IntTypeExt}; @@ -562,8 +562,8 @@ impl<'tcx> AdtDef<'tcx> { } #[inline] - pub fn predicates(self, tcx: TyCtxt<'tcx>) -> GenericPredicates<'tcx> { - tcx.predicates_of(self.did()) + pub fn clauses(self, tcx: TyCtxt<'tcx>) -> GenericClauses<'tcx> { + tcx.clauses_of(self.did()) } /// Returns an iterator over all fields contained diff --git a/compiler/rustc_middle/src/ty/context/impl_interner.rs b/compiler/rustc_middle/src/ty/context/impl_interner.rs index 26bed229f4d5a..c43768b139e34 100644 --- a/compiler/rustc_middle/src/ty/context/impl_interner.rs +++ b/compiler/rustc_middle/src/ty/context/impl_interner.rs @@ -388,42 +388,42 @@ impl<'tcx> Interner for TyCtxt<'tcx> { self.item_non_self_bounds(def_id).map_bound(IntoIterator::into_iter) } - fn predicates_of( + fn clauses_of( self, def_id: DefId, ) -> ty::EarlyBinder<'tcx, impl IntoIterator>> { ty::EarlyBinder::bind_iter( - self.predicates_of(def_id) + self.clauses_of(def_id) .instantiate_identity(self) - .predicates + .clauses .into_iter() .map(Unnormalized::skip_normalization), ) } - fn own_predicates_of( + fn own_clauses_of( self, def_id: DefId, ) -> ty::EarlyBinder<'tcx, impl IntoIterator>> { ty::EarlyBinder::bind_iter( - self.predicates_of(def_id) + self.clauses_of(def_id) .instantiate_own_identity() .map(|(clause, _)| clause.skip_normalization()), ) } - fn explicit_super_predicates_of( + fn explicit_super_clauses_of( self, def_id: DefId, ) -> ty::EarlyBinder<'tcx, impl IntoIterator, Span)>> { - self.explicit_super_predicates_of(def_id).map_bound(|preds| preds.into_iter().copied()) + self.explicit_super_clauses_of(def_id).map_bound(|preds| preds.into_iter().copied()) } - fn explicit_implied_predicates_of( + fn explicit_implied_clauses_of( self, def_id: DefId, ) -> ty::EarlyBinder<'tcx, impl IntoIterator, Span)>> { - self.explicit_implied_predicates_of(def_id).map_bound(|preds| preds.into_iter().copied()) + self.explicit_implied_clauses_of(def_id).map_bound(|preds| preds.into_iter().copied()) } fn impl_super_outlives( diff --git a/compiler/rustc_middle/src/ty/generics.rs b/compiler/rustc_middle/src/ty/generics.rs index 9a6b3dbea1ef3..0599f51305575 100644 --- a/compiler/rustc_middle/src/ty/generics.rs +++ b/compiler/rustc_middle/src/ty/generics.rs @@ -8,7 +8,7 @@ use rustc_span::{Span, Symbol, kw}; use rustc_type_ir::{TypeSuperVisitable as _, TypeVisitable, TypeVisitor}; use tracing::instrument; -use super::{Clause, InstantiatedPredicates, ParamConst, ParamTy, Ty, TyCtxt, Unnormalized}; +use super::{Clause, InstantiatedClauses, ParamConst, ParamTy, Ty, TyCtxt, Unnormalized}; use crate::ty::region::RegionExt; use crate::ty::{self, ClauseKind, EarlyBinder, GenericArgsRef, Region, RegionKind, TyKind}; @@ -383,18 +383,18 @@ impl<'tcx> Generics { /// Bounds on generics. #[derive(Copy, Clone, Default, Debug, TyEncodable, TyDecodable, StableHash)] -pub struct GenericPredicates<'tcx> { +pub struct GenericClauses<'tcx> { pub parent: Option, - pub predicates: &'tcx [(Clause<'tcx>, Span)], + pub clauses: &'tcx [(Clause<'tcx>, Span)], } -impl<'tcx> GenericPredicates<'tcx> { +impl<'tcx> GenericClauses<'tcx> { pub fn instantiate( self, tcx: TyCtxt<'tcx>, args: GenericArgsRef<'tcx>, - ) -> InstantiatedPredicates<'tcx> { - let mut instantiated = InstantiatedPredicates::empty(); + ) -> InstantiatedClauses<'tcx> { + let mut instantiated = InstantiatedClauses::empty(); self.instantiate_into(tcx, &mut instantiated, args); instantiated } @@ -407,7 +407,7 @@ impl<'tcx> GenericPredicates<'tcx> { + DoubleEndedIterator + ExactSizeIterator + Clone { - EarlyBinder::bind_iter(self.predicates).iter_instantiated_copied(tcx, args).map(|u| { + EarlyBinder::bind_iter(self.clauses).iter_instantiated_copied(tcx, args).map(|u| { let (clause, span) = u.unzip(); (clause, span.skip_normalization()) }) @@ -419,7 +419,7 @@ impl<'tcx> GenericPredicates<'tcx> { + DoubleEndedIterator + ExactSizeIterator + Clone { - EarlyBinder::bind_iter(self.predicates).iter_identity_copied().map(|u| { + EarlyBinder::bind_iter(self.clauses).iter_identity_copied().map(|u| { let (clause, span) = u.unzip(); (clause, span.skip_normalization()) }) @@ -429,20 +429,20 @@ impl<'tcx> GenericPredicates<'tcx> { fn instantiate_into( self, tcx: TyCtxt<'tcx>, - instantiated: &mut InstantiatedPredicates<'tcx>, + instantiated: &mut InstantiatedClauses<'tcx>, args: GenericArgsRef<'tcx>, ) { if let Some(def_id) = self.parent { - tcx.predicates_of(def_id).instantiate_into(tcx, instantiated, args); + tcx.clauses_of(def_id).instantiate_into(tcx, instantiated, args); } - instantiated.predicates.extend( - self.predicates.iter().map(|(p, _)| EarlyBinder::bind(tcx, *p).instantiate(tcx, args)), + instantiated.clauses.extend( + self.clauses.iter().map(|(p, _)| EarlyBinder::bind(tcx, *p).instantiate(tcx, args)), ); - instantiated.spans.extend(self.predicates.iter().map(|(_, sp)| *sp)); + instantiated.spans.extend(self.clauses.iter().map(|(_, sp)| *sp)); } - pub fn instantiate_identity(self, tcx: TyCtxt<'tcx>) -> InstantiatedPredicates<'tcx> { - let mut instantiated = InstantiatedPredicates::empty(); + pub fn instantiate_identity(self, tcx: TyCtxt<'tcx>) -> InstantiatedClauses<'tcx> { + let mut instantiated = InstantiatedClauses::empty(); self.instantiate_identity_into(tcx, &mut instantiated); instantiated } @@ -450,13 +450,13 @@ impl<'tcx> GenericPredicates<'tcx> { fn instantiate_identity_into( self, tcx: TyCtxt<'tcx>, - instantiated: &mut InstantiatedPredicates<'tcx>, + instantiated: &mut InstantiatedClauses<'tcx>, ) { if let Some(def_id) = self.parent { - tcx.predicates_of(def_id).instantiate_identity_into(tcx, instantiated); + tcx.clauses_of(def_id).instantiate_identity_into(tcx, instantiated); } - instantiated.predicates.extend(self.predicates.iter().map(|(p, _)| Unnormalized::new(*p))); - instantiated.spans.extend(self.predicates.iter().map(|(_, s)| s)); + instantiated.clauses.extend(self.clauses.iter().map(|(p, _)| Unnormalized::new(*p))); + instantiated.spans.extend(self.clauses.iter().map(|(_, s)| s)); } /// Allow simple where bounds like `T: Debug`, but prevent any kind of @@ -501,7 +501,7 @@ impl<'tcx> GenericPredicates<'tcx> { // Pessimistic: if any of the parameters have where bounds // don't allow this impl to be used. - self.predicates.iter().all(|(clause, _)| { + self.clauses.iter().all(|(clause, _)| { match clause.kind().skip_binder() { ClauseKind::Trait(trait_predicate) => { // In a `T: Trait`, if the rhs bound does not contain any generic params @@ -531,7 +531,7 @@ impl<'tcx> GenericPredicates<'tcx> { } /// `[const]` bounds for a given item. This is represented using a struct much like -/// `GenericPredicates`, where you can either choose to only instantiate the "own" +/// `GenericClauses`, where you can either choose to only instantiate the "own" /// bounds or all of the bounds including those from the parent. This distinction /// is necessary for code like `compare_method_predicate_entailment`. #[derive(Copy, Clone, Default, Debug, TyEncodable, TyDecodable, StableHash)] diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 151ca10b85ef6..9bac570fb2db1 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -846,11 +846,11 @@ impl<'tcx> TermKind<'tcx> { /// Represents the bounds declared on a particular set of type /// parameters. Should eventually be generalized into a flag list of -/// where-clauses. You can obtain an `InstantiatedPredicates` list from a -/// `GenericPredicates` by using the `instantiate` method. Note that this method -/// reflects an important semantic invariant of `InstantiatedPredicates`: while -/// the `GenericPredicates` are expressed in terms of the bound type -/// parameters of the impl/trait/whatever, an `InstantiatedPredicates` instance +/// where-clauses. You can obtain an `InstantiatedClauses` list from a +/// `GenericClauses` by using the `instantiate` method. Note that this method +/// reflects an important semantic invariant of `InstantiatedClauses`: while +/// the `GenericClauses` are expressed in terms of the bound type +/// parameters of the impl/trait/whatever, an `InstantiatedClauses` instance /// represented a set of bounds for some particular instantiation, /// meaning that the generic parameters have been instantiated with /// their values. @@ -859,23 +859,23 @@ impl<'tcx> TermKind<'tcx> { /// ```ignore (illustrative) /// struct Foo> { ... } /// ``` -/// Here, the `GenericPredicates` for `Foo` would contain a list of bounds like +/// Here, the `GenericClauses` for `Foo` would contain a list of bounds like /// `[[], [U:Bar]]`. Now if there were some particular reference -/// like `Foo`, then the `InstantiatedPredicates` would be `[[], +/// like `Foo`, then the `InstantiatedClauses` would be `[[], /// [usize:Bar]]`. #[derive(Clone, Debug)] -pub struct InstantiatedPredicates<'tcx> { - pub predicates: Vec>>, +pub struct InstantiatedClauses<'tcx> { + pub clauses: Vec>>, pub spans: Vec, } -impl<'tcx> InstantiatedPredicates<'tcx> { - pub fn empty() -> InstantiatedPredicates<'tcx> { - InstantiatedPredicates { predicates: vec![], spans: vec![] } +impl<'tcx> InstantiatedClauses<'tcx> { + pub fn empty() -> InstantiatedClauses<'tcx> { + InstantiatedClauses { clauses: vec![], spans: vec![] } } pub fn is_empty(&self) -> bool { - self.predicates.is_empty() + self.clauses.is_empty() } pub fn iter(&self) -> <&Self as IntoIterator>::IntoIter { @@ -883,7 +883,7 @@ impl<'tcx> InstantiatedPredicates<'tcx> { } } -impl<'tcx> IntoIterator for InstantiatedPredicates<'tcx> { +impl<'tcx> IntoIterator for InstantiatedClauses<'tcx> { type Item = (Unnormalized<'tcx, Clause<'tcx>>, Span); type IntoIter = std::iter::Zip< @@ -892,12 +892,12 @@ impl<'tcx> IntoIterator for InstantiatedPredicates<'tcx> { >; fn into_iter(self) -> Self::IntoIter { - debug_assert_eq!(self.predicates.len(), self.spans.len()); - std::iter::zip(self.predicates, self.spans) + debug_assert_eq!(self.clauses.len(), self.spans.len()); + std::iter::zip(self.clauses, self.spans) } } -impl<'a, 'tcx> IntoIterator for &'a InstantiatedPredicates<'tcx> { +impl<'a, 'tcx> IntoIterator for &'a InstantiatedClauses<'tcx> { type Item = (Unnormalized<'tcx, Clause<'tcx>>, Span); type IntoIter = std::iter::Zip< @@ -906,8 +906,8 @@ impl<'a, 'tcx> IntoIterator for &'a InstantiatedPredicates<'tcx> { >; fn into_iter(self) -> Self::IntoIter { - debug_assert_eq!(self.predicates.len(), self.spans.len()); - std::iter::zip(self.predicates.iter().copied(), self.spans.iter().copied()) + debug_assert_eq!(self.clauses.len(), self.spans.len()); + std::iter::zip(self.clauses.iter().copied(), self.spans.iter().copied()) } } diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 3614a67b71045..2ea99496c9949 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -869,9 +869,9 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { ty::Placeholder(placeholder) => placeholder.print(self)?, ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, args, .. }) => { // We use verbose printing in 'NO_QUERIES' mode, to - // avoid needing to call `predicates_of`. This should + // avoid needing to call `clauses_of`. This should // only affect certain debug messages (e.g. messages printed - // from `rustc_middle::ty` during the computation of `tcx.predicates_of`), + // from `rustc_middle::ty` during the computation of `tcx.clauses_of`), // and should have no effect on any compiler output. // [Unless `-Zverbose-internals` is used, e.g. in the output of // `tests/ui/nll/ty-outlives/impl-trait-captures.rs`, for diff --git a/compiler/rustc_mir_transform/src/coroutine/by_move_body.rs b/compiler/rustc_mir_transform/src/coroutine/by_move_body.rs index a2148b1b8e9e3..259b4b813f6a1 100644 --- a/compiler/rustc_mir_transform/src/coroutine/by_move_body.rs +++ b/compiler/rustc_mir_transform/src/coroutine/by_move_body.rs @@ -241,10 +241,10 @@ pub(crate) fn coroutine_by_move_body_def_id<'tcx>( body_def.coroutine_kind(tcx.coroutine_kind(coroutine_def_id)); body_def.def_ident_span(tcx.def_ident_span(coroutine_def_id)); body_def.def_span(tcx.def_span(coroutine_def_id)); - body_def.explicit_predicates_of(tcx.explicit_predicates_of(coroutine_def_id)); + body_def.explicit_clauses_of(tcx.explicit_clauses_of(coroutine_def_id)); body_def.generics_of(tcx.generics_of(coroutine_def_id).clone()); body_def.param_env(tcx.param_env(coroutine_def_id)); - body_def.explicit_predicates_of(tcx.explicit_predicates_of(coroutine_def_id)); + body_def.explicit_clauses_of(tcx.explicit_clauses_of(coroutine_def_id)); // The type of the coroutine is the `by_move_coroutine_ty`. body_def.type_of(ty::EarlyBinder::bind(tcx, by_move_coroutine_ty)); diff --git a/compiler/rustc_mir_transform/src/impossible_predicates.rs b/compiler/rustc_mir_transform/src/impossible_clauses.rs similarity index 73% rename from compiler/rustc_mir_transform/src/impossible_predicates.rs rename to compiler/rustc_mir_transform/src/impossible_clauses.rs index f255d424eb4c5..dbe4c9caf5036 100644 --- a/compiler/rustc_mir_transform/src/impossible_predicates.rs +++ b/compiler/rustc_mir_transform/src/impossible_clauses.rs @@ -47,7 +47,7 @@ fn is_structurally_unsized<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool { } } -fn has_structurally_impossible_sized_predicate<'tcx>( +fn has_structurally_impossible_sized_clause<'tcx>( tcx: TyCtxt<'tcx>, sized_trait: DefId, predicate: ty::Clause<'tcx>, @@ -62,44 +62,47 @@ fn has_structurally_impossible_sized_predicate<'tcx>( && is_structurally_unsized(tcx, trait_predicate.self_ty()) } -pub(crate) struct ImpossiblePredicates; +pub(crate) struct ImpossibleClauses; -pub(crate) fn has_impossible_predicates<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool { - let predicates = tcx.predicates_of(def_id).instantiate_identity(tcx); - tracing::trace!(?predicates); +pub(crate) fn has_impossible_clauses<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool { + let clauses = tcx.clauses_of(def_id).instantiate_identity(tcx); + tracing::trace!(?clauses); - // Some `Sized` predicates that mention local generics are still impossible + // Some `Sized` clauses that mention local generics are still impossible // for every instantiation, e.g. `dyn Trait: Sized`. if let Some(sized_trait) = tcx.lang_items().sized_trait() { - if predicates.predicates.iter().copied().map(Unnormalized::skip_norm_wip).any(|predicate| { - has_structurally_impossible_sized_predicate(tcx, sized_trait, predicate) - }) { + if clauses + .clauses + .iter() + .copied() + .map(Unnormalized::skip_norm_wip) + .any(|clause| has_structurally_impossible_sized_clause(tcx, sized_trait, clause)) + { return true; } } - let predicates = - predicates.predicates.into_iter().map(Unnormalized::skip_norm_wip).filter(|p| { - !p.has_type_flags( - // Only consider global clauses to simplify. - TypeFlags::HAS_FREE_LOCAL_NAMES + let clauses = clauses.clauses.into_iter().map(Unnormalized::skip_norm_wip).filter(|c| { + !c.has_type_flags( + // Only consider global clauses to simplify. + TypeFlags::HAS_FREE_LOCAL_NAMES // Clauses that refer to alias constants as they cause cycles. | TypeFlags::HAS_CONST_ALIAS, - ) - }); - let predicates: Vec<_> = traits::elaborate(tcx, predicates).collect(); - tracing::trace!(?predicates); - predicates.references_error() || traits::impossible_predicates(tcx, predicates) + ) + }); + let clauses: Vec<_> = traits::elaborate(tcx, clauses).collect(); + tracing::trace!(?clauses); + clauses.references_error() || traits::impossible_clauses(tcx, clauses) } -impl<'tcx> MirPass<'tcx> for ImpossiblePredicates { +impl<'tcx> MirPass<'tcx> for ImpossibleClauses { #[tracing::instrument(level = "trace", skip(self, tcx, body))] fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { tracing::trace!(def_id = ?body.source.def_id()); - let impossible = body.tainted_by_errors.is_some() - || has_impossible_predicates(tcx, body.source.def_id()); + let impossible = + body.tainted_by_errors.is_some() || has_impossible_clauses(tcx, body.source.def_id()); if impossible { - trace!("found unsatisfiable predicates"); + trace!("found unsatisfiable clauses"); // Clear the body to only contain a single `unreachable` statement. let bbs = body.basic_blocks.as_mut(); bbs.raw.truncate(1); diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index 905907aa279ea..b6aacb882b98f 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -154,7 +154,7 @@ declare_passes! { // Made public so that `mir_drops_elaborated_and_const_checked` can be overridden // by custom rustc drivers, running all the steps by themselves. See #114628. pub mod inline : Inline, ForceInline; - mod impossible_predicates : ImpossiblePredicates; + mod impossible_clauses : ImpossibleClauses; mod instsimplify : InstSimplify { BeforeInline, AfterSimplifyCfg }; mod jump_threading : JumpThreading; mod known_panics_lint : KnownPanicsLint; @@ -631,7 +631,7 @@ pub fn run_analysis_to_runtime_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<' /// After this series of passes, no lifetime analysis based on borrowing can be done. fn run_analysis_cleanup_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { let passes: &[&dyn MirPass<'tcx>] = &[ - &impossible_predicates::ImpossiblePredicates, + &impossible_clauses::ImpossibleClauses, &cleanup_post_borrowck::CleanupPostBorrowck, &remove_noop_landing_pads::RemoveNoopLandingPads, &simplify::SimplifyCfg::PostAnalysis, diff --git a/compiler/rustc_mir_transform/src/trivial_const.rs b/compiler/rustc_mir_transform/src/trivial_const.rs index e517d29d19320..9fb070750fd04 100644 --- a/compiler/rustc_mir_transform/src/trivial_const.rs +++ b/compiler/rustc_mir_transform/src/trivial_const.rs @@ -58,11 +58,11 @@ where _ => return None, } - // If there are impossible predicates then MIR passes will replace the body with + // If there are impossible clauses then MIR passes will replace the body with // `unreachable` causing const eval errors when trying to evaluate the body. For // now we avoid using trivial consts for such bodies so that the behaviour doesn't // change. - if crate::impossible_predicates::has_impossible_predicates(tcx, def.into()) { + if crate::impossible_clauses::has_impossible_clauses(tcx, def.into()) { return None; } diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index 68d6c01f15e92..fae1ee7256683 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -1548,7 +1548,7 @@ impl<'v> RootCollector<'_, 'v> { // This type is impossible to instantiate, so we should not try to // generate a `drop_glue` instance for it. - if self.tcx.instantiate_and_check_impossible_predicates(( + if self.tcx.instantiate_and_check_impossible_clauses(( id.owner_id.to_def_id(), id_args, )) { @@ -1800,8 +1800,8 @@ fn create_mono_items_for_default_impls<'tcx>( // Even though this impl has no type or const generic parameters, because we don't // consider higher-ranked predicates such as `for<'a> &'a mut [u8]: Copy` to // be trivially false. We must now check that the impl has no impossible-to-satisfy - // predicates. - if tcx.instantiate_and_check_impossible_predicates((item.owner_id.to_def_id(), impl_args)) { + // clauses. + if tcx.instantiate_and_check_impossible_clauses((item.owner_id.to_def_id(), impl_args)) { return; } diff --git a/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs b/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs index 406e5a172c96d..ae78d68865de3 100644 --- a/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs +++ b/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs @@ -908,7 +908,7 @@ where // make impls coinductive always, since they'll always need to prove their supertraits. requirements.extend(elaborate::elaborate( cx, - cx.explicit_super_predicates_of(trait_ref.def_id) + cx.explicit_super_clauses_of(trait_ref.def_id) .iter_instantiated(cx, trait_ref.args) .map(Unnormalized::skip_norm_wip) .map(|(pred, _)| pred), diff --git a/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs b/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs index df9758d5d2ab7..c6dd456e3e39a 100644 --- a/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs +++ b/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs @@ -172,10 +172,10 @@ where ecx.eq(goal.param_env, goal.predicate.trait_ref, impl_trait_ref)?; let where_clause_bounds = cx - .predicates_of(impl_def_id.into()) + .clauses_of(impl_def_id.into()) .iter_instantiated(cx, impl_args) .map(Unnormalized::skip_norm_wip) - .map(|pred| goal.with(cx, pred)); + .map(|clause| goal.with(cx, clause)); ecx.add_goals(GoalSource::ImplWhereBound, where_clause_bounds)?; // For this impl to be `const`, we need to check its `[const]` bounds too. @@ -221,10 +221,10 @@ where ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| { let where_clause_bounds = cx - .predicates_of(goal.predicate.def_id().into()) + .clauses_of(goal.predicate.def_id().into()) .iter_instantiated(cx, goal.predicate.trait_ref.args) .map(Unnormalized::skip_norm_wip) - .map(|p| goal.with(cx, p)); + .map(|c| goal.with(cx, c)); let const_conditions = cx .const_conditions(goal.predicate.def_id().into()) diff --git a/compiler/rustc_next_trait_solver/src/solve/normalizes_to.rs b/compiler/rustc_next_trait_solver/src/solve/normalizes_to.rs index 069102f3db50b..a6a25766d6591 100644 --- a/compiler/rustc_next_trait_solver/src/solve/normalizes_to.rs +++ b/compiler/rustc_next_trait_solver/src/solve/normalizes_to.rs @@ -219,10 +219,10 @@ where // FIXME: We don't need these, since these are the type's own WF obligations. ecx.add_goals( GoalSource::AliasWellFormed, - cx.own_predicates_of(goal.predicate.alias.expect_projection_def_id().into()) + cx.own_clauses_of(goal.predicate.alias.expect_projection_def_id().into()) .iter_instantiated(cx, goal.predicate.alias.args) .map(Unnormalized::skip_norm_wip) - .map(|pred| goal.with(cx, pred)), + .map(|clause| goal.with(cx, clause)), )?; then(ecx) @@ -285,10 +285,10 @@ where ecx.eq(goal.param_env, goal_trait_ref, impl_trait_ref)?; let where_clause_bounds = cx - .predicates_of(impl_def_id.into()) + .clauses_of(impl_def_id.into()) .iter_instantiated(cx, impl_args) .map(Unnormalized::skip_norm_wip) - .map(|pred| goal.with(cx, pred)); + .map(|clause| goal.with(cx, clause)); ecx.add_goals(GoalSource::ImplWhereBound, where_clause_bounds)?; // Bail if the nested goals don't hold here. This is to avoid unnecessarily @@ -302,10 +302,10 @@ where // see tests/ui/generic-associated-types/must-prove-where-clauses-on-norm.rs. ecx.add_goals( GoalSource::AliasWellFormed, - cx.own_predicates_of(alias_def_id.into()) + cx.own_clauses_of(alias_def_id.into()) .iter_instantiated(cx, goal.predicate.alias.args) .map(Unnormalized::skip_norm_wip) - .map(|pred| goal.with(cx, pred)), + .map(|clause| goal.with(cx, clause)), )?; let error_response = |ecx: &mut EvalCtxt<'_, D>, guar| { @@ -1119,10 +1119,10 @@ where // target impl's params. self.add_goals( GoalSource::Misc, - cx.predicates_of(target_container_def_id) + cx.clauses_of(target_container_def_id) .iter_instantiated(cx, target_args) .map(Unnormalized::skip_norm_wip) - .map(|pred| goal.with(cx, pred)), + .map(|clause| goal.with(cx, clause)), )?; goal.predicate.alias.args.rebase_onto(cx, impl_trait_ref.def_id.into(), target_args) }) diff --git a/compiler/rustc_next_trait_solver/src/solve/project_goals/free_alias.rs b/compiler/rustc_next_trait_solver/src/solve/project_goals/free_alias.rs index c1867a224ac84..7f5d258ccc706 100644 --- a/compiler/rustc_next_trait_solver/src/solve/project_goals/free_alias.rs +++ b/compiler/rustc_next_trait_solver/src/solve/project_goals/free_alias.rs @@ -25,10 +25,10 @@ where // Check where clauses self.add_goals( GoalSource::Misc, - cx.predicates_of(free_alias.expect_free_def_id().into()) + cx.clauses_of(free_alias.expect_free_def_id().into()) .iter_instantiated(cx, free_alias.args) .map(Unnormalized::skip_norm_wip) - .map(|pred| goal.with(cx, pred)), + .map(|clause| goal.with(cx, clause)), )?; let actual = match free_alias.kind { diff --git a/compiler/rustc_next_trait_solver/src/solve/project_goals/inherent.rs b/compiler/rustc_next_trait_solver/src/solve/project_goals/inherent.rs index f2cd91574d641..afdc0c20a7132 100644 --- a/compiler/rustc_next_trait_solver/src/solve/project_goals/inherent.rs +++ b/compiler/rustc_next_trait_solver/src/solve/project_goals/inherent.rs @@ -47,10 +47,10 @@ where // to be very careful when changing the impl where-clauses to be productive. self.add_goals( GoalSource::Misc, - cx.predicates_of(def_id.into()) + cx.clauses_of(def_id.into()) .iter_instantiated(cx, inherent_args) .map(Unnormalized::skip_norm_wip) - .map(|pred| goal.with(cx, pred)), + .map(|clause| goal.with(cx, clause)), )?; let normalized: I::Term = match inherent.kind { diff --git a/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs b/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs index f29df578cd97b..ba5a809df5b0f 100644 --- a/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs +++ b/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs @@ -111,10 +111,10 @@ where ecx.eq(goal.param_env, goal.predicate.trait_ref, impl_trait_ref)?; let where_clause_bounds = cx - .predicates_of(impl_def_id.into()) + .clauses_of(impl_def_id.into()) .iter_instantiated(cx, impl_args) .map(Unnormalized::skip_norm_wip) - .map(|pred| goal.with(cx, pred)); + .map(|clause| goal.with(cx, clause)); ecx.add_goals(GoalSource::ImplWhereBound, where_clause_bounds)?; // We currently elaborate all supertrait outlives obligations from impls. @@ -287,10 +287,10 @@ where ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| { let nested_obligations = cx - .predicates_of(goal.predicate.def_id().into()) + .clauses_of(goal.predicate.def_id().into()) .iter_instantiated(cx, goal.predicate.trait_ref.args) .map(Unnormalized::skip_norm_wip) - .map(|p| goal.with(cx, p)); + .map(|c| goal.with(cx, c)); // While you could think of trait aliases to have a single builtin impl // which uses its implied trait bounds as where-clauses, using // `GoalSource::ImplWhereClause` here would be incorrect, as we also diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 29ee27bc102f9..96fb0c81a92d6 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -87,8 +87,8 @@ pub trait DefIdVisitor<'tcx> { fn visit_trait(&mut self, trait_ref: TraitRef<'tcx>) -> Self::Result { self.skeleton().visit_trait(trait_ref) } - fn visit_predicates(&mut self, predicates: ty::GenericPredicates<'tcx>) -> Self::Result { - self.skeleton().visit_clauses(predicates.predicates) + fn visit_gen_clauses(&mut self, gen_clauses: ty::GenericClauses<'tcx>) -> Self::Result { + self.skeleton().visit_clauses(gen_clauses.clauses) } fn visit_clauses(&mut self, clauses: &[(ty::Clause<'tcx>, Span)]) -> Self::Result { self.skeleton().visit_clauses(clauses) @@ -563,7 +563,7 @@ impl<'tcx> EmbargoVisitor<'tcx> { let def_id = item.def_id.expect_local(); let tcx = self.tcx; let mut reach = self.reach(def_id, item_ev); - reach.generics().predicates(); + reach.generics().clauses(); if assoc_has_type_of(tcx, item) { reach.ty(); } @@ -590,12 +590,12 @@ impl<'tcx> EmbargoVisitor<'tcx> { | DefKind::Fn | DefKind::TyAlias => { if let Some(item_ev) = item_ev { - self.reach(def_id, item_ev).generics().predicates().ty(); + self.reach(def_id, item_ev).generics().clauses().ty(); } } DefKind::Trait => { if let Some(item_ev) = item_ev { - self.reach(def_id, item_ev).generics().predicates(); + self.reach(def_id, item_ev).generics().clauses(); for assoc_item in self.tcx.associated_items(def_id).in_definition_order() { let def_id = assoc_item.def_id.expect_local(); @@ -607,7 +607,7 @@ impl<'tcx> EmbargoVisitor<'tcx> { } DefKind::TraitAlias => { if let Some(item_ev) = item_ev { - self.reach(def_id, item_ev).generics().predicates(); + self.reach(def_id, item_ev).generics().clauses(); } } DefKind::Impl { of_trait } => { @@ -632,7 +632,7 @@ impl<'tcx> EmbargoVisitor<'tcx> { { let mut reach = self.reach(def_id, item_ev); - reach.generics().predicates().ty(); + reach.generics().clauses().ty(); if of_trait { reach.trait_ref(); } @@ -651,7 +651,7 @@ impl<'tcx> EmbargoVisitor<'tcx> { } DefKind::Enum => { if let Some(item_ev) = item_ev { - self.reach(def_id, item_ev).generics().predicates(); + self.reach(def_id, item_ev).generics().clauses(); } let def = self.tcx.adt_def(def_id); for variant in def.variants() { @@ -683,7 +683,7 @@ impl<'tcx> EmbargoVisitor<'tcx> { DefKind::Struct | DefKind::Union => { let def = self.tcx.adt_def(def_id).non_enum_variant(); if let Some(item_ev) = item_ev { - self.reach(def_id, item_ev).generics().predicates(); + self.reach(def_id, item_ev).generics().clauses(); for field in &def.fields { let field = field.did.expect_local(); self.update(field, item_ev, Level::Reachable); @@ -740,8 +740,8 @@ impl ReachEverythingInTheInterfaceVisitor<'_, '_> { self } - fn predicates(&mut self) -> &mut Self { - self.visit_predicates(self.ev.tcx.explicit_predicates_of(self.item_def_id)); + fn clauses(&mut self) -> &mut Self { + self.visit_gen_clauses(self.ev.tcx.explicit_clauses_of(self.item_def_id)); self } @@ -1377,15 +1377,15 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> { self } - fn predicates(&mut self) -> &mut Self { + fn clauses(&mut self) -> &mut Self { self.in_primary_interface = false; - // N.B., we use `explicit_predicates_of` and not `predicates_of` + // N.B., we use `explicit_clauses_of` and not `clauses_of` // because we don't want to report privacy errors due to where // clauses that the compiler inferred. We only want to // consider the ones that the user wrote. This is important // for the inferred outlives rules; see // `tests/ui/rfc-2093-infer-outlives/privacy.rs`. - let _ = self.visit_predicates(self.tcx.explicit_predicates_of(self.item_def_id)); + let _ = self.visit_gen_clauses(self.tcx.explicit_clauses_of(self.item_def_id)); self } @@ -1584,7 +1584,7 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'_, 'tcx> { let is_assoc_ty = item.is_type(); check.hard_error = is_assoc_ty; - check.generics().predicates(); + check.generics().clauses(); if assoc_has_type_of(self.tcx, item) { check.ty(); } @@ -1612,7 +1612,7 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'_, 'tcx> { if let DefKind::TyAlias = def_kind { self.check_unnameable(def_id, effective_vis); } - self.check(def_id, item_visibility, effective_vis).generics().predicates().ty(); + self.check(def_id, item_visibility, effective_vis).generics().clauses().ty(); } DefKind::OpaqueTy => { // `ty()` for opaque types is the underlying type, @@ -1622,18 +1622,18 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'_, 'tcx> { DefKind::Trait => { self.check_unnameable(def_id, effective_vis); - self.check(def_id, item_visibility, effective_vis).generics().predicates(); + self.check(def_id, item_visibility, effective_vis).generics().clauses(); for assoc_item in tcx.associated_items(id.owner_id).in_definition_order() { self.check_assoc_item(assoc_item, item_visibility, effective_vis); } } DefKind::TraitAlias => { - self.check(def_id, item_visibility, effective_vis).generics().predicates(); + self.check(def_id, item_visibility, effective_vis).generics().clauses(); } DefKind::Enum => { self.check_unnameable(def_id, effective_vis); - self.check(def_id, item_visibility, effective_vis).generics().predicates(); + self.check(def_id, item_visibility, effective_vis).generics().clauses(); let adt = tcx.adt_def(id.owner_id); for field in adt.all_fields() { @@ -1643,7 +1643,7 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'_, 'tcx> { // Subitems of structs and unions have their own publicity. DefKind::Struct | DefKind::Union => { self.check_unnameable(def_id, effective_vis); - self.check(def_id, item_visibility, effective_vis).generics().predicates(); + self.check(def_id, item_visibility, effective_vis).generics().clauses(); let adt = tcx.adt_def(id.owner_id); for field in adt.all_fields() { @@ -1683,10 +1683,10 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'_, 'tcx> { let mut check = self.check(def_id, impl_vis, Some(impl_ev)); - // Generics and predicates of trait impls are intentionally not checked + // Generics and clauses of trait impls are intentionally not checked // for private components (#90586). if !of_trait { - check.generics().predicates(); + check.generics().clauses(); } // Skip checking private components in associated types, due to lack of full @@ -1729,7 +1729,7 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'_, 'tcx> { self.check_unnameable(def_id, effective_vis); } - self.check(def_id, item_visibility, effective_vis).generics().predicates().ty(); + self.check(def_id, item_visibility, effective_vis).generics().clauses().ty(); } } @@ -1825,11 +1825,7 @@ fn effective_visibilities(tcx: TyCtxt<'_>, (): ()) -> &EffectiveVisibilities { // in the reachability pass (`middle/reachable.rs`). Types are marked as link-time // reachable if they are returned via `impl Trait`, even from private functions. let pub_ev = EffectiveVisibility::from_vis(ty::Visibility::Public); - visitor - .reach_through_impl_trait(opaque.def_id, pub_ev) - .generics() - .predicates() - .ty(); + visitor.reach_through_impl_trait(opaque.def_id, pub_ev).generics().clauses().ty(); } } diff --git a/compiler/rustc_public/src/compiler_interface.rs b/compiler/rustc_public/src/compiler_interface.rs index 7abc07505d1fc..f11a592029367 100644 --- a/compiler/rustc_public/src/compiler_interface.rs +++ b/compiler/rustc_public/src/compiler_interface.rs @@ -19,7 +19,7 @@ use crate::target::{MachineInfo, MachineSize}; use crate::ty::{ AdtDef, AdtKind, Allocation, AssocItem, Asyncness, ClosureDef, ClosureKind, Constness, CoroutineDef, Discr, FieldDef, FloatTy, FnDef, ForeignDef, ForeignItemKind, ForeignModule, - ForeignModuleDef, GenericArgs, GenericPredicates, Generics, ImplDef, ImplTrait, IntrinsicDef, + ForeignModuleDef, GenericArgs, GenericClauses, Generics, ImplDef, ImplTrait, IntrinsicDef, LineInfo, MirConst, PolyFnSig, RigidTy, Span, TraitDecl, TraitDef, TraitRef, Ty, TyConst, TyConstId, TyKind, UintTy, VariantDef, VariantIdx, VtblEntry, }; @@ -218,13 +218,13 @@ impl<'tcx> CompilerInterface<'tcx> { }) } - pub(crate) fn predicates_of(&self, def_id: DefId) -> GenericPredicates { + pub(crate) fn clauses_of(&self, def_id: DefId) -> GenericClauses { self.with_cx(|tables, cx| { let did = tables[def_id]; - let (parent, kinds) = cx.predicates_of(did); - crate::ty::GenericPredicates { + let (parent, kinds) = cx.clauses_of(did); + crate::ty::GenericClauses { parent: parent.map(|did| tables.trait_def(did)), - predicates: kinds + clauses: kinds .iter() .map(|(kind, span)| (kind.stable(tables, cx), span.stable(tables, cx))) .collect(), @@ -232,13 +232,13 @@ impl<'tcx> CompilerInterface<'tcx> { }) } - pub(crate) fn explicit_predicates_of(&self, def_id: DefId) -> GenericPredicates { + pub(crate) fn explicit_clauses_of(&self, def_id: DefId) -> GenericClauses { self.with_cx(|tables, cx| { let did = tables[def_id]; - let (parent, kinds) = cx.explicit_predicates_of(did); - crate::ty::GenericPredicates { + let (parent, kinds) = cx.explicit_clauses_of(did); + crate::ty::GenericClauses { parent: parent.map(|did| tables.trait_def(did)), - predicates: kinds + clauses: kinds .iter() .map(|(kind, span)| (kind.stable(tables, cx), span.stable(tables, cx))) .collect(), diff --git a/compiler/rustc_public/src/ty.rs b/compiler/rustc_public/src/ty.rs index e9f2ff9a8bb3f..68fd152921cf7 100644 --- a/compiler/rustc_public/src/ty.rs +++ b/compiler/rustc_public/src/ty.rs @@ -1466,12 +1466,12 @@ impl TraitDecl { with(|cx| cx.generics_of(self.def_id.0)) } - pub fn predicates_of(&self) -> GenericPredicates { - with(|cx| cx.predicates_of(self.def_id.0)) + pub fn clauses_of(&self) -> GenericClauses { + with(|cx| cx.clauses_of(self.def_id.0)) } - pub fn explicit_predicates_of(&self) -> GenericPredicates { - with(|cx| cx.explicit_predicates_of(self.def_id.0)) + pub fn explicit_clauses_of(&self) -> GenericClauses { + with(|cx| cx.explicit_clauses_of(self.def_id.0)) } } @@ -1550,9 +1550,9 @@ pub struct GenericParamDef { pub kind: GenericParamDefKind, } -pub struct GenericPredicates { +pub struct GenericClauses { pub parent: Option, - pub predicates: Vec<(PredicateKind, Span)>, + pub clauses: Vec<(ClauseKind, Span)>, } #[derive(Clone, Debug, Eq, PartialEq, Serialize)] diff --git a/compiler/rustc_public_bridge/src/context/impls.rs b/compiler/rustc_public_bridge/src/context/impls.rs index 6b12da9d9c4ed..4a2fbb8f8b7af 100644 --- a/compiler/rustc_public_bridge/src/context/impls.rs +++ b/compiler/rustc_public_bridge/src/context/impls.rs @@ -214,31 +214,22 @@ impl<'tcx, B: Bridge> CompilerCtxt<'tcx, B> { self.tcx.generics_of(def_id) } - pub fn predicates_of( - &self, - def_id: DefId, - ) -> (Option, Vec<(ty::PredicateKind<'tcx>, Span)>) { - let ty::GenericPredicates { parent, predicates } = self.tcx.predicates_of(def_id); + pub fn clauses_of(&self, def_id: DefId) -> (Option, Vec<(ty::ClauseKind<'tcx>, Span)>) { + let ty::GenericClauses { parent, clauses } = self.tcx.clauses_of(def_id); ( parent, - predicates - .iter() - .map(|(clause, span)| (clause.as_predicate().kind().skip_binder(), *span)) - .collect(), + clauses.iter().map(|(clause, span)| (clause.kind().skip_binder(), *span)).collect(), ) } - pub fn explicit_predicates_of( + pub fn explicit_clauses_of( &self, def_id: DefId, - ) -> (Option, Vec<(ty::PredicateKind<'tcx>, Span)>) { - let ty::GenericPredicates { parent, predicates } = self.tcx.explicit_predicates_of(def_id); + ) -> (Option, Vec<(ty::ClauseKind<'tcx>, Span)>) { + let ty::GenericClauses { parent, clauses } = self.tcx.explicit_clauses_of(def_id); ( parent, - predicates - .iter() - .map(|(clause, span)| (clause.as_predicate().kind().skip_binder(), *span)) - .collect(), + clauses.iter().map(|(clause, span)| (clause.kind().skip_binder(), *span)).collect(), ) } diff --git a/compiler/rustc_query_impl/src/job.rs b/compiler/rustc_query_impl/src/job.rs index 5760f05c4a367..4922a17253c45 100644 --- a/compiler/rustc_query_impl/src/job.rs +++ b/compiler/rustc_query_impl/src/job.rs @@ -450,10 +450,10 @@ pub(crate) fn create_cycle_error<'tcx>( let is_all_def_kind = |def_kind| { // Trivial type alias and trait alias cycles consists of `type_of` and - // `explicit_implied_predicates_of` queries, so we just check just these here. + // `explicit_implied_clauses_of` queries, so we just check just these here. frames.iter().all(|frame| match frame.tagged_key { TaggedQueryKey::type_of(def_id) - | TaggedQueryKey::explicit_implied_predicates_of(def_id) + | TaggedQueryKey::explicit_implied_clauses_of(def_id) if tcx.def_kind(def_id) == def_kind => { true diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/region.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/region.rs index 2c959acbc2a86..e951ac7237e5f 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/region.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/region.rs @@ -450,7 +450,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { && let Some(def_id) = preds.principal_def_id() { for (clause, span) in - self.tcx.predicates_of(def_id).instantiate_identity(self.tcx).into_iter() + self.tcx.clauses_of(def_id).instantiate_identity(self.tcx).into_iter() { if let ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate(a, b)) = clause.kind().skip_binder() @@ -610,11 +610,15 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { let Ok(trait_predicates) = self .tcx - .explicit_predicates_of(trait_item_def_id) + .explicit_clauses_of(trait_item_def_id) .instantiate_own(self.tcx, trait_item_args) - .map(|(pred, _)| { - let pred = pred.skip_norm_wip(); - if pred.is_suggestable(self.tcx, false) { Ok(pred.to_string()) } else { Err(()) } + .map(|(clause, _)| { + let clause = clause.skip_norm_wip(); + if clause.is_suggestable(self.tcx, false) { + Ok(clause.to_string()) + } else { + Err(()) + } }) .collect::, ()>>() else { diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs index 5e2e9f67103dd..95c42b34499b6 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/ambiguity.rs @@ -74,15 +74,15 @@ pub fn compute_applicable_impls_for_diagnostics<'tcx>( if !ignore_predicates_of_impls { let obligations = tcx - .predicates_of(impl_def_id) + .clauses_of(impl_def_id) .instantiate(tcx, impl_args) .into_iter() - .map(|(predicate, _)| { + .map(|(clause, _)| { Obligation::new( tcx, ObligationCause::dummy(), param_env, - predicate.skip_norm_wip(), + clause.skip_norm_wip(), ) }) // Kinda hacky, but let's just throw away obligations that overflow. @@ -147,15 +147,15 @@ pub fn compute_applicable_impls_for_diagnostics<'tcx>( // If our `body_def_id` has been set (and isn't just from a dummy obligation cause), // then try to look for a param-env clause that would apply. The way we compute // this is somewhat manual, since we need the spans, so we elaborate this directly - // from `predicates_of` rather than actually looking at the param-env which + // from `clauses_of` rather than actually looking at the param-env which // otherwise would be more appropriate. let body_def_id = obligation.cause.body_def_id; if body_def_id != CRATE_DEF_ID { - let predicates = tcx.predicates_of(body_def_id.to_def_id()).instantiate_identity(tcx); - for (pred, span) in - elaborate(tcx, predicates.into_iter().map(|(c, s)| (c.skip_norm_wip(), s))) + let clauses = tcx.clauses_of(body_def_id.to_def_id()).instantiate_identity(tcx); + for (clause, span) in + elaborate(tcx, clauses.into_iter().map(|(c, s)| (c.skip_norm_wip(), s))) { - let kind = pred.kind(); + let kind = clause.kind(); if let ty::ClauseKind::Trait(trait_pred) = kind.skip_binder() && param_env_candidate_may_apply(kind.rebind(trait_pred)) { diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs index 5f456edb8d7f6..81f19529418a5 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs @@ -2155,7 +2155,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { ocx.register_obligations( self.tcx - .predicates_of(single.impl_def_id) + .clauses_of(single.impl_def_id) .instantiate(self.tcx, impl_args) .into_iter() .map(|(clause, _)| { @@ -2357,7 +2357,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { } ocx.register_obligations( self.tcx - .predicates_of(def_id) + .clauses_of(def_id) .instantiate(self.tcx, impl_args) .into_iter() .map(|(clause, span)| { @@ -2373,7 +2373,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { }) }; let failing_obligations = - if !self.tcx.predicates_of(def_id).predicates.is_empty() { + if !self.tcx.clauses_of(def_id).clauses.is_empty() { self.probe(|_| evaluate_obligations()) } else { Vec::new() diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs index b50ace11bbd75..b072c6d3565eb 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs @@ -489,15 +489,15 @@ pub(crate) fn to_pretty_impl_header(tcx: TyCtxt<'_>, impl_def_id: DefId) -> Opti ) .unwrap(); - let predicates = tcx.predicates_of(impl_def_id).predicates; - let mut pretty_predicates = Vec::with_capacity(predicates.len()); + let clauses = tcx.clauses_of(impl_def_id).clauses; + let mut pretty_clauses = Vec::with_capacity(clauses.len()); let sized_trait = tcx.lang_items().sized_trait(); let meta_sized_trait = tcx.lang_items().meta_sized_trait(); - for (p, _) in predicates { + for (c, _) in clauses { // Accumulate the sizedness bounds for each self ty. - if let Some(trait_clause) = p.as_trait_clause() { + if let Some(trait_clause) = c.as_trait_clause() { let self_ty = trait_clause.self_ty().skip_binder(); let sizedness_of = types_with_sizedness_bounds.entry(self_ty).or_default(); if Some(trait_clause.def_id()) == sized_trait { @@ -509,7 +509,7 @@ pub(crate) fn to_pretty_impl_header(tcx: TyCtxt<'_>, impl_def_id: DefId) -> Opti } } - pretty_predicates.push(p.to_string()); + pretty_clauses.push(c.to_string()); } for (ty, sizedness) in types_with_sizedness_bounds { @@ -517,22 +517,22 @@ pub(crate) fn to_pretty_impl_header(tcx: TyCtxt<'_>, impl_def_id: DefId) -> Opti if sizedness.sized { // Maybe a default bound, don't write anything. } else { - pretty_predicates.push(format!("{ty}: ?Sized")); + pretty_clauses.push(format!("{ty}: ?Sized")); } } else { if sizedness.sized { // Maybe a default bound, don't write anything. - pretty_predicates.push(format!("{ty}: Sized")); + pretty_clauses.push(format!("{ty}: Sized")); } else if sizedness.meta_sized { - pretty_predicates.push(format!("{ty}: MetaSized")); + pretty_clauses.push(format!("{ty}: MetaSized")); } else { - pretty_predicates.push(format!("{ty}: PointeeSized")); + pretty_clauses.push(format!("{ty}: PointeeSized")); } } } - if !pretty_predicates.is_empty() { - write!(w, "\n where {}", pretty_predicates.join(", ")).unwrap(); + if !pretty_clauses.is_empty() { + write!(w, "\n where {}", pretty_clauses.join(", ")).unwrap(); } w.push(';'); diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs index b4f55e27048e2..8c72f0d90bb58 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs @@ -2875,49 +2875,50 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { cause: &ObligationCauseCode<'tcx>, err: &mut Diag<'_>, ) { - // First, look for an `WhereClauseInExpr`, which means we can get + // First, look for a `WhereClauseInExpr`, which means we can get // the uninstantiated predicate list of the called function. And check // that the predicate that we failed to satisfy is a `Fn`-like trait. if let ObligationCauseCode::WhereClauseInExpr(def_id, _, _, idx) = *cause - && let predicates = self.tcx.predicates_of(def_id).instantiate_identity(self.tcx) - && let Some(pred) = predicates.predicates.get(idx).map(|p| p.as_ref().skip_norm_wip()) - && let ty::ClauseKind::Trait(trait_pred) = pred.kind().skip_binder() + && let gen_clauses = self.tcx.clauses_of(def_id).instantiate_identity(self.tcx) + && let Some(clause) = gen_clauses.clauses.get(idx).map(|c| c.as_ref().skip_norm_wip()) + && let ty::ClauseKind::Trait(trait_pred) = clause.kind().skip_binder() && self.tcx.is_fn_trait(trait_pred.def_id()) { let expected_self = - self.tcx.anonymize_bound_vars(pred.kind().rebind(trait_pred.self_ty())); + self.tcx.anonymize_bound_vars(clause.kind().rebind(trait_pred.self_ty())); let expected_args = - self.tcx.anonymize_bound_vars(pred.kind().rebind(trait_pred.trait_ref.args)); + self.tcx.anonymize_bound_vars(clause.kind().rebind(trait_pred.trait_ref.args)); - // Find another predicate whose self-type is equal to the expected self type, + // Find another clause whose self-type is equal to the expected self type, // but whose args don't match. - let other_pred = predicates.into_iter().enumerate().find(|&(other_idx, (pred, _))| { - let pred = pred.skip_norm_wip(); - match pred.kind().skip_binder() { - ty::ClauseKind::Trait(trait_pred) - if self.tcx.is_fn_trait(trait_pred.def_id()) + let other_clause = + gen_clauses.into_iter().enumerate().find(|&(other_idx, (clause, _))| { + let clause = clause.skip_norm_wip(); + match clause.kind().skip_binder() { + ty::ClauseKind::Trait(trait_pred) + if self.tcx.is_fn_trait(trait_pred.def_id()) && other_idx != idx // Make sure that the self type matches // (i.e. constraining this closure) && expected_self == self.tcx.anonymize_bound_vars( - pred.kind().rebind(trait_pred.self_ty()), + clause.kind().rebind(trait_pred.self_ty()), ) // But the args don't match (i.e. incompatible args) && expected_args != self.tcx.anonymize_bound_vars( - pred.kind().rebind(trait_pred.trait_ref.args), + clause.kind().rebind(trait_pred.trait_ref.args), ) => - { - true + { + true + } + _ => false, } - _ => false, - } - }); + }); // If we found one, then it's very likely the cause of the error. - if let Some((_, (_, other_pred_span))) = other_pred { + if let Some((_, (_, other_clause_span))) = other_clause { err.span_note( - other_pred_span, + other_clause_span, "closure inferred to have a different signature due to this bound", ); } @@ -4897,9 +4898,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { let mut type_diffs = vec![]; if let ObligationCauseCode::WhereClauseInExpr(def_id, _, _, idx) = *parent_code && let Some(node_args) = typeck_results.node_args_opt(call_hir_id) - && let where_clauses = - self.tcx.predicates_of(def_id).instantiate(self.tcx, node_args) - && let Some(where_pred) = where_clauses.predicates.get(idx) + && let where_clauses = self.tcx.clauses_of(def_id).instantiate(self.tcx, node_args) + && let Some(where_pred) = where_clauses.clauses.get(idx) { let where_pred = where_pred.as_ref().skip_norm_wip(); if let Some(where_pred) = where_pred.as_trait_clause() diff --git a/compiler/rustc_trait_selection/src/solve/fulfill/derive_errors.rs b/compiler/rustc_trait_selection/src/solve/fulfill/derive_errors.rs index 0c365e9dea707..18c228d5ddc55 100644 --- a/compiler/rustc_trait_selection/src/solve/fulfill/derive_errors.rs +++ b/compiler/rustc_trait_selection/src/solve/fulfill/derive_errors.rs @@ -576,13 +576,13 @@ fn derive_cause<'tcx>( result: _, } => { if let Some((_, span)) = - tcx.predicates_of(impl_def_id).instantiate_identity(tcx).iter().nth(idx) + tcx.clauses_of(impl_def_id).instantiate_identity(tcx).iter().nth(idx) { cause = cause.derived_cause(parent_trait_pred, |derived| { ObligationCauseCode::ImplDerived(Box::new(traits::ImplDerivedCause { derived, impl_or_alias_def_id: impl_def_id, - impl_def_predicate_index: Some(idx), + impl_def_clause_index: Some(idx), span, })) }) @@ -612,7 +612,7 @@ fn derive_host_cause<'tcx>( result: _, } => { if let Some((_, span)) = tcx - .predicates_of(impl_def_id) + .clauses_of(impl_def_id) .instantiate_identity(tcx) .into_iter() .chain(tcx.const_conditions(impl_def_id).instantiate_identity(tcx).into_iter().map( diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index 837be27bfba89..b21650da3b288 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -211,7 +211,7 @@ fn fresh_impl_header<'tcx>( trait_ref: is_of_trait .then(|| tcx.impl_trait_ref(impl_def_id).instantiate(tcx, impl_args).skip_norm_wip()), predicates: tcx - .predicates_of(impl_def_id) + .clauses_of(impl_def_id) .instantiate(tcx, impl_args) .iter() .map(|(c, _)| c.skip_norm_wip().as_predicate()) @@ -551,7 +551,7 @@ fn impl_intersection_has_negative_obligation( util::elaborate( tcx, - tcx.predicates_of(impl2_def_id) + tcx.clauses_of(impl2_def_id) .instantiate(tcx, impl2_header.impl_args) .into_iter() .map(|(c, s)| (c.skip_norm_wip(), s)), diff --git a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs index b8d0e31b55d3b..ab2965a345360 100644 --- a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs +++ b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs @@ -191,7 +191,7 @@ fn satisfied_from_param_env<'tcx>( // with its own `ConstEvaluatable` bound in the param env which we will visit separately. // // If we start allowing directly writing `ConstKind::Expr` without an intermediate anon const - // this will be incorrect. It might be worth investigating making `predicates_of` elaborate + // this will be incorrect. It might be worth investigating making `clauses_of` elaborate // all of the `ConstEvaluatable` bounds rather than having a visitor here. } } diff --git a/compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs b/compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs index 7b45dfe48a7fe..76a9956619dae 100644 --- a/compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs +++ b/compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs @@ -174,14 +174,14 @@ fn predicates_reference_self( supertraits_only: bool, ) -> SmallVec<[Span; 1]> { let trait_ref = ty::Binder::dummy(ty::TraitRef::identity(tcx, trait_def_id)); - let predicates = if supertraits_only { - tcx.explicit_super_predicates_of(trait_def_id).skip_binder() + let clauses = if supertraits_only { + tcx.explicit_super_clauses_of(trait_def_id).skip_binder() } else { - tcx.predicates_of(trait_def_id).predicates + tcx.clauses_of(trait_def_id).clauses }; - predicates + clauses .iter() - .map(|&(predicate, sp)| (predicate.instantiate_supertrait(tcx, trait_ref), sp)) + .map(|&(clause, sp)| (clause.instantiate_supertrait(tcx, trait_ref), sp)) .filter_map(|(clause, sp)| { // Super predicates cannot allow self projections, since they're // impossible to make into existential bounds without eager resolution @@ -282,7 +282,7 @@ fn super_predicates_have_non_lifetime_binders( tcx: TyCtxt<'_>, trait_def_id: DefId, ) -> SmallVec<[Span; 1]> { - tcx.explicit_super_predicates_of(trait_def_id) + tcx.explicit_super_clauses_of(trait_def_id) .iter_identity_copied() .map(Unnormalized::skip_norm_wip) .filter_map(|(pred, span)| pred.has_non_region_bound_vars().then_some(span)) @@ -296,7 +296,7 @@ fn super_predicates_are_unconditionally_const( tcx: TyCtxt<'_>, trait_def_id: DefId, ) -> SmallVec<[Span; 1]> { - tcx.explicit_super_predicates_of(trait_def_id) + tcx.explicit_super_clauses_of(trait_def_id) .iter_identity_copied() .map(Unnormalized::skip_norm_wip) .filter_map(|(pred, span)| { @@ -318,15 +318,15 @@ fn generics_require_sized_self(tcx: TyCtxt<'_>, def_id: DefId) -> bool { return false; /* No Sized trait, can't require it! */ }; - // Search for a predicate like `Self: Sized` amongst the trait bounds. - let predicates: Vec<_> = tcx - .predicates_of(def_id) + // Search for a clause like `Self: Sized` amongst the trait bounds. + let clauses: Vec<_> = tcx + .clauses_of(def_id) .instantiate_identity(tcx) - .predicates + .clauses .into_iter() .map(Unnormalized::skip_norm_wip) .collect(); - elaborate(tcx, predicates).any(|pred| match pred.kind().skip_binder() { + elaborate(tcx, clauses).any(|pred| match pred.kind().skip_binder() { ty::ClauseKind::Trait(ref trait_pred) => { trait_pred.def_id() == sized_def_id && trait_pred.self_ty().is_param(0) } @@ -536,7 +536,7 @@ fn virtual_call_violations_for_method<'tcx>( // NOTE: This check happens last, because it results in a lint, and not a // hard error. - if tcx.predicates_of(method.def_id).predicates.iter().any(|&(pred, _span)| { + if tcx.clauses_of(method.def_id).clauses.iter().any(|&(clause, _span)| { // dyn Trait is okay: // // trait Trait { @@ -546,7 +546,7 @@ fn virtual_call_violations_for_method<'tcx>( // because a trait object can't claim to live longer than the concrete // type. If the lifetime bound holds on dyn Trait then it's guaranteed // to hold as well on the concrete type. - if pred.as_type_outlives_clause().is_some() { + if clause.as_type_outlives_clause().is_some() { return false; } @@ -566,7 +566,7 @@ fn virtual_call_violations_for_method<'tcx>( if let ty::ClauseKind::Trait(ty::TraitPredicate { trait_ref: pred_trait_ref, polarity: ty::PredicatePolarity::Positive, - }) = pred.kind().skip_binder() + }) = clause.kind().skip_binder() && pred_trait_ref.self_ty() == tcx.types.self_param && tcx.trait_is_auto(pred_trait_ref.def_id) { @@ -583,7 +583,7 @@ fn virtual_call_violations_for_method<'tcx>( return false; } - contains_illegal_self_type_reference(tcx, trait_def_id, pred, AllowSelfProjections::Yes) + contains_illegal_self_type_reference(tcx, trait_def_id, clause, AllowSelfProjections::Yes) }) { errors.push(MethodViolation::WhereClauseReferencesSelf); } @@ -703,10 +703,10 @@ fn receiver_is_dispatchable<'tcx>( // are not constructing a param-env for "inside" of the body of the defaulted // method, so we don't really care about projecting to a specific RPIT type, // and because RPITITs are not dyn compatible (yet). - let mut predicates: Vec<_> = tcx - .predicates_of(method.def_id) + let mut clauses: Vec<_> = tcx + .clauses_of(method.def_id) .instantiate_identity(tcx) - .predicates + .clauses .into_iter() .map(Unnormalized::skip_norm_wip) .collect(); @@ -714,7 +714,7 @@ fn receiver_is_dispatchable<'tcx>( // Self: Unsize let unsize_predicate = ty::TraitRef::new(tcx, unsize_did, [tcx.types.self_param, unsized_self_ty]); - predicates.push(unsize_predicate.upcast(tcx)); + clauses.push(unsize_predicate.upcast(tcx)); // U: Trait let trait_def_id = method.trait_container(tcx).unwrap(); @@ -722,17 +722,17 @@ fn receiver_is_dispatchable<'tcx>( if param.index == 0 { unsized_self_ty.into() } else { tcx.mk_param_from_def(param) } }); let trait_predicate = ty::TraitRef::new_from_args(tcx, trait_def_id, args); - predicates.push(trait_predicate.upcast(tcx)); + clauses.push(trait_predicate.upcast(tcx)); let meta_sized_predicate = { let meta_sized_did = tcx.require_lang_item(LangItem::MetaSized, DUMMY_SP); ty::TraitRef::new(tcx, meta_sized_did, [unsized_self_ty]).upcast(tcx) }; - predicates.push(meta_sized_predicate); + clauses.push(meta_sized_predicate); normalize_param_env_or_error( tcx, - ty::ParamEnv::new(tcx.mk_clauses(&predicates)), + ty::ParamEnv::new(tcx.mk_clauses(&clauses)), ObligationCause::dummy_with_span(tcx.def_span(method.def_id)), ) }; diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index 919bc3cdcc3d9..f1b22f46d57b4 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -177,18 +177,18 @@ pub enum TraitQueryMode { } /// Creates predicate obligations from the generic bounds. -#[instrument(level = "debug", skip(cause, param_env, normalize_predicate))] +#[instrument(level = "debug", skip(cause, param_env, normalize_clause))] pub fn predicates_for_generics<'tcx>( cause: impl Fn(usize, Span) -> ObligationCause<'tcx>, - mut normalize_predicate: impl FnMut(Unnormalized<'tcx, Clause<'tcx>>) -> Clause<'tcx>, + mut normalize_clause: impl FnMut(Unnormalized<'tcx, Clause<'tcx>>) -> Clause<'tcx>, param_env: ty::ParamEnv<'tcx>, - generic_bounds: ty::InstantiatedPredicates<'tcx>, + generic_bounds: ty::InstantiatedClauses<'tcx>, ) -> impl Iterator> { generic_bounds.into_iter().enumerate().map(move |(idx, (clause, span))| Obligation { cause: cause(idx, span), recursion_depth: 0, param_env, - predicate: normalize_predicate(clause).as_predicate(), + predicate: normalize_clause(clause).as_predicate(), }) } @@ -270,11 +270,11 @@ fn set_projection_term_to_non_rigid<'tcx>( } #[instrument(level = "debug", skip(tcx, elaborated_env))] -fn do_normalize_predicates<'tcx>( +fn do_normalize_clauses<'tcx>( tcx: TyCtxt<'tcx>, cause: ObligationCause<'tcx>, elaborated_env: ty::ParamEnv<'tcx>, - predicates: Vec>, + clauses: Vec>, ) -> Result>, ErrorGuaranteed> { // FIXME. We should really... do something with these region // obligations. But this call just continues the older @@ -303,24 +303,24 @@ fn do_normalize_predicates<'tcx>( } else { elaborated_env }; - let predicates = ocx.normalize(&cause, elaborated_env, Unnormalized::new_wip(predicates)); - let predicates = if tcx.next_trait_solver_globally() { + let clauses = ocx.normalize(&cause, elaborated_env, Unnormalized::new_wip(clauses)); + let clauses = if tcx.next_trait_solver_globally() { if !tcx.disable_param_env_normalization_hack() { - let predicates: Vec<_> = set_projection_term_to_non_rigid(tcx, predicates).collect(); + let clauses: Vec<_> = set_projection_term_to_non_rigid(tcx, clauses).collect(); // FIXME(type_alias_impl_trait): opaque types in param env might be // in defining scope but we're using non body analysis here. // So the rigidness marker is wrong. - ty::set_opaques_to_non_rigid(tcx, predicates).skip_norm_wip() + ty::set_opaques_to_non_rigid(tcx, clauses).skip_norm_wip() } else { // Param env is used in different typing modes but itself // is normalized in `non_body_analysis`. // That not only makes the rigidness of opaques types wrong, // other aliases can be indirectly affected as well. // So we conservatively set everything to be non-rigid. - ty::set_aliases_to_non_rigid(tcx, predicates).skip_norm_wip() + ty::set_aliases_to_non_rigid(tcx, clauses).skip_norm_wip() } } else { - predicates + clauses }; let errors = ocx.evaluate_obligations_error_on_ambiguity(); @@ -329,7 +329,7 @@ fn do_normalize_predicates<'tcx>( return Err(reported); } - debug!("do_normalize_predicates: normalized predicates = {:?}", predicates); + debug!("do_normalize_clauses: normalized clauses = {:?}", clauses); // We can use the `elaborated_env` here; the region code only // cares about declarations like `'a: 'b`. @@ -347,8 +347,8 @@ fn do_normalize_predicates<'tcx>( // This is required by trait-system-refactor-initiative#166. The new solver encounters // this more frequently as we entirely ignore outlives predicates with the old solver. let _errors = infcx.resolve_regions(cause.body_def_id, elaborated_env, []); - match infcx.fully_resolve(predicates) { - Ok(predicates) => Ok(predicates), + match infcx.fully_resolve(clauses) { + Ok(clauses) => Ok(clauses), Err(fixup_err) => { // If we encounter a fixup error, it means that some type // variable wound up unconstrained. That can happen for @@ -385,7 +385,7 @@ pub fn normalize_param_env_or_error<'tcx>( // parameter environments once for every fn as it goes, // and errors will get reported then; so outside of type inference we // can be sure that no errors should occur. - let mut predicates: Vec<_> = util::elaborate( + let mut clauses: Vec<_> = util::elaborate( tcx, unnormalized_env.caller_bounds().into_iter().map(|clause| { if tcx.features().generic_const_exprs() || tcx.next_trait_solver_globally() { @@ -458,9 +458,9 @@ pub fn normalize_param_env_or_error<'tcx>( ) .collect(); - debug!("normalize_param_env_or_error: elaborated-predicates={:?}", predicates); + debug!("normalize_param_env_or_error: elaborated-clauses={:?}", clauses); - let elaborated_env = ty::ParamEnv::new(tcx.mk_clauses(&predicates)); + let elaborated_env = ty::ParamEnv::new(tcx.mk_clauses(&clauses)); if !elaborated_env.has_aliases() { return elaborated_env; } @@ -483,44 +483,43 @@ pub fn normalize_param_env_or_error<'tcx>( // // This works fairly well because trait matching does not actually care about param-env // TypeOutlives predicates - these are normally used by regionck. - let outlives_predicates: Vec<_> = predicates - .extract_if(.., |predicate| { - matches!(predicate.kind().skip_binder(), ty::ClauseKind::TypeOutlives(..)) + let outlives_clauses: Vec<_> = clauses + .extract_if(.., |clause| { + matches!(clause.kind().skip_binder(), ty::ClauseKind::TypeOutlives(..)) }) .collect(); debug!( "normalize_param_env_or_error: predicates=(non-outlives={:?}, outlives={:?})", - predicates, outlives_predicates + clauses, outlives_clauses ); - let Ok(non_outlives_predicates) = - do_normalize_predicates(tcx, cause.clone(), elaborated_env, predicates) + let Ok(non_outlives_clauses) = + do_normalize_clauses(tcx, cause.clone(), elaborated_env, clauses) else { // An unnormalized env is better than nothing. - debug!("normalize_param_env_or_error: errored resolving non-outlives predicates"); + debug!("normalize_param_env_or_error: errored resolving non-outlives clauses"); return elaborated_env; }; - debug!("normalize_param_env_or_error: non-outlives predicates={:?}", non_outlives_predicates); + debug!("normalize_param_env_or_error: non-outlives clauses={:?}", non_outlives_clauses); // Not sure whether it is better to include the unnormalized TypeOutlives predicates // here. I believe they should not matter, because we are ignoring TypeOutlives param-env // predicates here anyway. Keeping them here anyway because it seems safer. - let outlives_env = non_outlives_predicates.iter().chain(&outlives_predicates).cloned(); + let outlives_env = non_outlives_clauses.iter().chain(&outlives_clauses).cloned(); let outlives_env = ty::ParamEnv::new(tcx.mk_clauses_from_iter(outlives_env)); - let Ok(outlives_predicates) = - do_normalize_predicates(tcx, cause, outlives_env, outlives_predicates) + let Ok(outlives_clauses) = do_normalize_clauses(tcx, cause, outlives_env, outlives_clauses) else { // An unnormalized env is better than nothing. - debug!("normalize_param_env_or_error: errored resolving outlives predicates"); + debug!("normalize_param_env_or_error: errored resolving outlives clauses"); return elaborated_env; }; - debug!("normalize_param_env_or_error: outlives predicates={:?}", outlives_predicates); + debug!("normalize_param_env_or_error: outlives clauses={:?}", outlives_clauses); - let mut predicates = non_outlives_predicates; - predicates.extend(outlives_predicates); - debug!("normalize_param_env_or_error: final predicates={:?}", predicates); - ty::ParamEnv::new(tcx.mk_clauses(&predicates)) + let mut clauses = non_outlives_clauses; + clauses.extend(outlives_clauses); + debug!("normalize_param_env_or_error: final clauses={:?}", clauses); + ty::ParamEnv::new(tcx.mk_clauses(&clauses)) } #[derive(Debug)] @@ -780,12 +779,12 @@ fn replace_param_and_infer_args_with_placeholder<'tcx>( args.fold_with(&mut ReplaceParamAndInferWithPlaceholder { tcx, idx: ty::BoundVar::ZERO }) } -/// Normalizes the predicates and checks whether they hold in an empty environment. If this +/// Normalizes the clauses and checks whether they hold in an empty environment. If this /// returns true, then either normalize encountered an error or one of the predicates did not /// hold. Used when creating vtables to check for unsatisfiable methods. This should not be /// used during analysis. -pub fn impossible_predicates<'tcx>(tcx: TyCtxt<'tcx>, predicates: Vec>) -> bool { - debug!("impossible_predicates(predicates={:?})", predicates); +pub fn impossible_clauses<'tcx>(tcx: TyCtxt<'tcx>, clauses: Vec>) -> bool { + debug!("impossible_clauses(clauses={:?})", clauses); let (infcx, param_env) = tcx .infer_ctxt() .with_next_trait_solver(true) @@ -793,10 +792,10 @@ pub fn impossible_predicates<'tcx>(tcx: TyCtxt<'tcx>, predicates: Vec(tcx: TyCtxt<'tcx>, predicates: Vec( +fn instantiate_and_check_impossible_clauses<'tcx>( tcx: TyCtxt<'tcx>, key: (DefId, GenericArgsRef<'tcx>), ) -> bool { - debug!("instantiate_and_check_impossible_predicates(key={:?})", key); + debug!("instantiate_and_check_impossible_clauses(key={:?})", key); - let mut predicates: Vec<_> = tcx - .predicates_of(key.0) + let mut clauses: Vec<_> = tcx + .clauses_of(key.0) .instantiate(tcx, key.1) - .predicates + .clauses .into_iter() .map(Unnormalized::skip_norm_wip) .collect(); @@ -832,13 +831,13 @@ fn instantiate_and_check_impossible_predicates<'tcx>( // associated items. if let Some(trait_def_id) = tcx.trait_of_assoc(key.0) { let trait_ref = ty::TraitRef::from_assoc(tcx, trait_def_id, key.1); - predicates.push(trait_ref.upcast(tcx)); + clauses.push(trait_ref.upcast(tcx)); } - predicates.retain(|predicate| !predicate.has_param()); - let result = impossible_predicates(tcx, predicates); + clauses.retain(|clause| !clause.has_param()); + let result = impossible_clauses(tcx, clauses); - debug!("instantiate_and_check_impossible_predicates(key={:?}) = {:?}", key, result); + debug!("instantiate_and_check_impossible_clauses(key={:?}) = {:?}", key, result); result } @@ -888,7 +887,7 @@ fn is_impossible_associated_item( } let generics = tcx.generics_of(trait_item_def_id); - let predicates = tcx.predicates_of(trait_item_def_id); + let gen_clauses = tcx.clauses_of(trait_item_def_id); // Be conservative in cases where we have `W` and a method like `Self: Sized`, // since that method *may* have some substitutions where the predicates hold. @@ -907,13 +906,13 @@ fn is_impossible_associated_item( tcx.impl_trait_ref(impl_def_id).instantiate(tcx, fresh_args).skip_norm_wip(); let mut visitor = ReferencesOnlyParentGenerics { tcx, generics, trait_item_def_id }; - let predicates_for_trait = predicates.predicates.iter().filter_map(|(pred, span)| { - pred.visit_with(&mut visitor).is_continue().then(|| { + let predicates_for_trait = gen_clauses.clauses.iter().filter_map(|(clause, span)| { + clause.visit_with(&mut visitor).is_continue().then(|| { Obligation::new( tcx, ObligationCause::dummy_with_span(*span), param_env, - ty::EarlyBinder::bind(tcx, *pred) + ty::EarlyBinder::bind(tcx, *clause) .instantiate(tcx, impl_trait_ref.args) .skip_norm_wip(), ) @@ -932,7 +931,7 @@ pub fn provide(providers: &mut Providers) { specialization_graph_of: specialize::specialization_graph_provider, specializes: specialize::specializes, specialization_enabled_in: specialize::specialization_enabled_in, - instantiate_and_check_impossible_predicates, + instantiate_and_check_impossible_clauses, is_impossible_associated_item, live_args_for_alias_from_outlives_bounds: outlives_for_liveness::live_args_for_alias_from_outlives_bounds, diff --git a/compiler/rustc_trait_selection/src/traits/normalize.rs b/compiler/rustc_trait_selection/src/traits/normalize.rs index b822c713bfabb..dfdf99cc904c6 100644 --- a/compiler/rustc_trait_selection/src/traits/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/normalize.rs @@ -324,20 +324,20 @@ impl<'a, 'b, 'tcx> AssocTypeNormalizer<'a, 'b, 'tcx> { self.obligations.extend( infcx .tcx - .predicates_of(def_id) + .clauses_of(def_id) .instantiate_own(infcx.tcx, free.args) - .map(|(pred, span)| (pred.skip_norm_wip(), span)) - .map(|(mut predicate, span)| { + .map(|(clause, span)| (clause.skip_norm_wip(), span)) + .map(|(mut clause, span)| { if free.has_escaping_bound_vars() { - (predicate, ..) = BoundVarReplacer::replace_bound_vars( + (clause, ..) = BoundVarReplacer::replace_bound_vars( infcx, &mut self.universes, - predicate, + clause, ); } let mut cause = self.cause.clone(); cause.map_code(|code| ObligationCauseCode::TypeAlias(code, span, def_id)); - Obligation::new(infcx.tcx, cause, self.param_env, predicate) + Obligation::new(infcx.tcx, cause, self.param_env, clause) }), ); self.depth += 1; diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index 79b531afbe2ae..71cbe0a28c780 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -549,14 +549,14 @@ pub fn normalize_inherent_projection<'a, 'b, 'tcx>( // Register the obligations arising from the impl and from the associated type itself. let def_id = alias_term.expect_inherent_def_id(); - let predicates = tcx.predicates_of(def_id).instantiate(tcx, args); - for (predicate, span) in predicates { - let predicate = normalize_with_depth_to( + let clauses = tcx.clauses_of(def_id).instantiate(tcx, args); + for (clause, span) in clauses { + let clause = normalize_with_depth_to( selcx, param_env, cause.clone(), depth + 1, - predicate, + clause, obligations, ); @@ -570,13 +570,7 @@ pub fn normalize_inherent_projection<'a, 'b, 'tcx>( ObligationCauseCode::WhereClause(def_id, span), ); - obligations.push(Obligation::with_depth( - tcx, - nested_cause, - depth + 1, - param_env, - predicate, - )); + obligations.push(Obligation::with_depth(tcx, nested_cause, depth + 1, param_env, clause)); } let term = if alias_term.kind.is_type() { @@ -2031,7 +2025,7 @@ fn confirm_impl_candidate<'cx, 'tcx>( // This means that the impl is missing a definition for the // associated type. This is either because the associate item - // has impossible-to-satisfy predicates (since those were + // has impossible-to-satisfy clauses (since those were // allowed in ), // or because the impl is literally missing the definition. if !assoc_term.item.defaultness(tcx).has_value() { @@ -2114,14 +2108,14 @@ fn assoc_term_own_obligations<'cx, 'tcx>( ) { let tcx = selcx.tcx(); let def_id = obligation.predicate.expect_projection_def_id(); - let predicates = tcx.predicates_of(def_id).instantiate_own(tcx, obligation.predicate.args); - for (predicate, span) in predicates { + let clauses = tcx.clauses_of(def_id).instantiate_own(tcx, obligation.predicate.args); + for (clause, span) in clauses { let normalized = normalize_with_depth_to( selcx, obligation.param_env, obligation.cause.clone(), obligation.recursion_depth + 1, - predicate, + clause, nested, ); diff --git a/compiler/rustc_trait_selection/src/traits/query/type_op/ascribe_user_type.rs b/compiler/rustc_trait_selection/src/traits/query/type_op/ascribe_user_type.rs index 1d5c6be2687f0..4daffc6e1e0da 100644 --- a/compiler/rustc_trait_selection/src/traits/query/type_op/ascribe_user_type.rs +++ b/compiler/rustc_trait_selection/src/traits/query/type_op/ascribe_user_type.rs @@ -128,22 +128,22 @@ fn relate_mir_and_user_args<'tcx>( // Prove the predicates coming along with `def_id`. // - // Also, normalize the `instantiated_predicates` + // Also, normalize the `instantiated_clauses` // because otherwise we wind up with duplicate "type // outlives" error messages. - let instantiated_predicates = tcx.predicates_of(def_id).instantiate(tcx, args); + let instantiated_clauses = tcx.clauses_of(def_id).instantiate(tcx, args); - debug!(?instantiated_predicates); - for (instantiated_predicate, predicate_span) in instantiated_predicates { - let span = if span == DUMMY_SP { predicate_span } else { span }; + debug!(?instantiated_clauses); + for (instantiated_clause, clause_span) in instantiated_clauses { + let span = if span == DUMMY_SP { clause_span } else { span }; let cause = ObligationCause::new( span, CRATE_DEF_ID, - ObligationCauseCode::AscribeUserTypeProvePredicate(predicate_span), + ObligationCauseCode::AscribeUserTypeProvePredicate(clause_span), ); - let instantiated_predicate = ocx.normalize(&cause, param_env, instantiated_predicate); + let instantiated_clause = ocx.normalize(&cause, param_env, instantiated_clause); - ocx.register_obligation(Obligation::new(tcx, cause, param_env, instantiated_predicate)); + ocx.register_obligation(Obligation::new(tcx, cause, param_env, instantiated_clause)); } // Now prove the well-formedness of `def_id` with `args`. diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index d4027fcf388b1..84b51f42c411e 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -665,8 +665,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { return false; }; - for &(predicate, _) in self.tcx().predicates_of(impl_def_id).predicates { - let ty::ClauseKind::Trait(pred) = predicate.kind().skip_binder() else { continue }; + for &(clause, _) in self.tcx().clauses_of(impl_def_id).clauses { + let ty::ClauseKind::Trait(pred) = clause.kind().skip_binder() else { continue }; if fn_ptr_trait != pred.trait_ref.def_id { continue; } diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index 49c277b39289b..22fb714cfd33c 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -539,7 +539,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // Check supertraits hold. This is so that their associated type bounds // will be checked in the code below. for supertrait in tcx - .explicit_super_predicates_of(trait_predicate.def_id()) + .explicit_super_clauses_of(trait_predicate.def_id()) .iter_instantiated_copied(tcx, trait_predicate.trait_ref.args) .map(|pred| pred.unzip().0) { diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 58f2d0c7f33ac..f3382df7c11da 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -2884,11 +2884,11 @@ impl<'tcx> SelectionContext<'_, 'tcx> { // obligation will normalize to `<$0 as Iterator>::Item = $1` and // `$1: Copy`, so we must ensure the obligations are emitted in // that order. - let predicates = tcx.predicates_of(def_id); - assert_eq!(predicates.parent, None); - let predicates = predicates.instantiate_own(tcx, args); - let mut obligations = PredicateObligations::with_capacity(predicates.len()); - for (index, (predicate, span)) in predicates.into_iter().enumerate() { + let clauses = tcx.clauses_of(def_id); + assert_eq!(clauses.parent, None); + let clauses = clauses.instantiate_own(tcx, args); + let mut obligations = PredicateObligations::with_capacity(clauses.len()); + for (index, (clause, span)) in clauses.into_iter().enumerate() { let cause = if tcx.is_lang_item(parent_trait_pred.def_id(), LangItem::CoerceUnsized) { cause.clone() } else { @@ -2896,7 +2896,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> { ObligationCauseCode::ImplDerived(Box::new(ImplDerivedCause { derived, impl_or_alias_def_id: def_id, - impl_def_predicate_index: Some(index), + impl_def_clause_index: Some(index), span, })) }) @@ -2906,7 +2906,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> { param_env, cause.clone(), recursion_depth, - predicate, + clause, &mut obligations, ); obligations.push(Obligation { diff --git a/compiler/rustc_trait_selection/src/traits/specialize/mod.rs b/compiler/rustc_trait_selection/src/traits/specialize/mod.rs index 506d38c17bc9a..6abdaf404f103 100644 --- a/compiler/rustc_trait_selection/src/traits/specialize/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/specialize/mod.rs @@ -187,12 +187,12 @@ fn fulfill_implication<'tcx>( // Now check that the source trait ref satisfies all the where clauses of the target impl. // This is not just for correctness; we also need this to constrain any params that may // only be referenced via projection predicates. - let predicates = infcx.tcx.predicates_of(target_impl).instantiate(infcx.tcx, target_args); + let clauses = infcx.tcx.clauses_of(target_impl).instantiate(infcx.tcx, target_args); let obligations = predicates_for_generics( |_, _| cause.clone(), - |pred| ocx.normalize(cause, param_env, pred), + |clause| ocx.normalize(cause, param_env, clause), param_env, - predicates, + clauses, ); ocx.register_obligations(obligations); @@ -318,13 +318,12 @@ pub(super) fn specializes( // Now check that the source trait ref satisfies all the where clauses of the target impl. // This is not just for correctness; we also need this to constrain any params that may // only be referenced via projection predicates. - let predicates = - infcx.tcx.predicates_of(parent_impl_def_id).instantiate(infcx.tcx, parent_args); + let clauses = infcx.tcx.clauses_of(parent_impl_def_id).instantiate(infcx.tcx, parent_args); let obligations = predicates_for_generics( |_, _| cause.clone(), - |pred| ocx.normalize(cause, param_env, pred), + |clause| ocx.normalize(cause, param_env, clause), param_env, - predicates, + clauses, ); ocx.register_obligations(obligations); diff --git a/compiler/rustc_trait_selection/src/traits/util.rs b/compiler/rustc_trait_selection/src/traits/util.rs index e4da1fd1598f7..019214c210e7d 100644 --- a/compiler/rustc_trait_selection/src/traits/util.rs +++ b/compiler/rustc_trait_selection/src/traits/util.rs @@ -49,7 +49,7 @@ pub fn expand_trait_aliases<'tcx>( ty::ClauseKind::Trait(trait_pred) => { if tcx.is_trait_alias(trait_pred.def_id()) { queue.extend( - tcx.explicit_super_predicates_of(trait_pred.def_id()) + tcx.explicit_super_clauses_of(trait_pred.def_id()) .iter_identity_copied() .map(Unnormalized::skip_norm_wip) .map(|(super_clause, span)| { diff --git a/compiler/rustc_trait_selection/src/traits/vtable.rs b/compiler/rustc_trait_selection/src/traits/vtable.rs index 83d493f077539..7113169555d10 100644 --- a/compiler/rustc_trait_selection/src/traits/vtable.rs +++ b/compiler/rustc_trait_selection/src/traits/vtable.rs @@ -122,7 +122,7 @@ fn prepare_vtable_segments_inner<'tcx, T>( let &(inner_most_trait_ref, _, _) = stack.last().unwrap(); let mut direct_super_traits_iter = tcx - .explicit_super_predicates_of(inner_most_trait_ref.def_id) + .explicit_super_clauses_of(inner_most_trait_ref.def_id) .iter_identity_copied() .map(Unnormalized::skip_norm_wip) .filter_map(move |(pred, _)| { @@ -275,8 +275,8 @@ fn vtable_entries<'tcx>( // do not hold for this particular set of type parameters. // Note that this method could then never be called, so we // do not want to try and codegen it, in that case (see #23435). - if tcx.instantiate_and_check_impossible_predicates((def_id, args)) { - debug!("vtable_entries: predicates do not hold"); + if tcx.instantiate_and_check_impossible_clauses((def_id, args)) { + debug!("vtable_entries: clauses do not hold"); return VtblEntry::Vacant; } @@ -321,10 +321,9 @@ pub(crate) fn first_method_vtable_slot<'tcx>(tcx: TyCtxt<'tcx>, key: ty::TraitRe ); // We're monomorphizing a call to a dyn trait object that can never be constructed. - if tcx.instantiate_and_check_impossible_predicates(( - source_principal.def_id, - source_principal.args, - )) { + if tcx + .instantiate_and_check_impossible_clauses((source_principal.def_id, source_principal.args)) + { return 0; } @@ -390,10 +389,9 @@ pub(crate) fn supertrait_vtable_slot<'tcx>( ); // We're monomorphizing a dyn trait object upcast that can never be constructed. - if tcx.instantiate_and_check_impossible_predicates(( - source_principal.def_id, - source_principal.args, - )) { + if tcx + .instantiate_and_check_impossible_clauses((source_principal.def_id, source_principal.args)) + { return None; } diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index 95043385cf17a..6231f781db2c5 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -579,20 +579,20 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { return Default::default(); } - let predicates = self.tcx().predicates_of(def_id); - let mut origins = vec![def_id; predicates.predicates.len()]; - let mut head = predicates; + let gen_clauses = self.tcx().clauses_of(def_id); + let mut origins = vec![def_id; gen_clauses.clauses.len()]; + let mut head = gen_clauses; while let Some(parent) = head.parent { - head = self.tcx().predicates_of(parent); - origins.extend(iter::repeat(parent).take(head.predicates.len())); + head = self.tcx().clauses_of(parent); + origins.extend(iter::repeat(parent).take(head.clauses.len())); } - let predicates = predicates.instantiate(self.tcx(), args); - trace!("{:#?}", predicates); - debug_assert_eq!(predicates.predicates.len(), origins.len()); + let gen_clauses = gen_clauses.instantiate(self.tcx(), args); + trace!("{:#?}", gen_clauses); + debug_assert_eq!(gen_clauses.clauses.len(), origins.len()); - iter::zip(predicates, origins.into_iter().rev()) - .map(|((pred, span), origin_def_id)| { + iter::zip(gen_clauses, origins.into_iter().rev()) + .map(|((clause, span), origin_def_id)| { let code = ObligationCauseCode::WhereClause(origin_def_id, span); let cause = self.cause(code); traits::Obligation::with_depth( @@ -600,10 +600,10 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { cause, self.recursion_depth, self.param_env, - pred.skip_norm_wip(), + clause.skip_norm_wip(), ) }) - .filter(|pred| !pred.has_escaping_bound_vars()) + .filter(|clause| !clause.has_escaping_bound_vars()) .collect() } diff --git a/compiler/rustc_traits/src/normalize_projection_ty.rs b/compiler/rustc_traits/src/normalize_projection_ty.rs index 2b904c2710464..c6f759fb7937d 100644 --- a/compiler/rustc_traits/src/normalize_projection_ty.rs +++ b/compiler/rustc_traits/src/normalize_projection_ty.rs @@ -101,16 +101,15 @@ fn normalize_canonicalized_free_alias<'tcx>( &goal, |ocx, ParamEnvAnd { param_env, value: goal }| { let def_id = goal.expect_free_def_id(); - let obligations = tcx.predicates_of(def_id).instantiate_own(tcx, goal.args).map( - |(predicate, span)| { + let obligations = + tcx.clauses_of(def_id).instantiate_own(tcx, goal.args).map(|(predicate, span)| { traits::Obligation::new( tcx, ObligationCause::dummy_with_span(span), param_env, predicate.skip_norm_wip(), ) - }, - ); + }); ocx.register_obligations(obligations); let normalized_term: ty::Term<'tcx> = if goal.kind.is_type() { tcx.type_of(def_id).instantiate(tcx, goal.args).skip_norm_wip().into() diff --git a/compiler/rustc_ty_utils/src/implied_bounds.rs b/compiler/rustc_ty_utils/src/implied_bounds.rs index 7b36fcc483c58..c397982461a30 100644 --- a/compiler/rustc_ty_utils/src/implied_bounds.rs +++ b/compiler/rustc_ty_utils/src/implied_bounds.rs @@ -66,7 +66,7 @@ fn assumed_wf_types<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx [(Ty<' // // Side-note: We don't really need to do this remapping for early-bound // lifetimes because they're already "linked" by the bidirectional outlives - // predicates we insert in the `explicit_predicates_of` query for RPITITs. + // predicates we insert in the `explicit_clauses_of` query for RPITITs. let mut mapping = FxHashMap::default(); let generics = tcx.generics_of(def_id); diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index b5a82793dcc97..3862f043fea09 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -199,14 +199,12 @@ fn resolve_associated_item<'tcx>( // and const-prop (and also some lints). let self_ty = rcvr_args.type_at(0); if !self_ty.is_known_rigid() { - let predicates = tcx - .predicates_of(impl_data.impl_def_id) - .instantiate(tcx, impl_data.args) - .predicates; + let clauses = + tcx.clauses_of(impl_data.impl_def_id).instantiate(tcx, impl_data.args).clauses; let sized_def_id = tcx.lang_items().sized_trait(); // If we find a `Self: Sized` bound on the item, then we know // that `dyn Trait` can certainly never apply here. - if !predicates.into_iter().filter_map(|p| p.as_trait_clause()).any(|clause| { + if !clauses.into_iter().filter_map(|p| p.as_trait_clause()).any(|clause| { Some(clause.def_id()) == sized_def_id && clause.skip_binder().self_ty() == self_ty }) { diff --git a/compiler/rustc_ty_utils/src/sig_types.rs b/compiler/rustc_ty_utils/src/sig_types.rs index d46a280875f96..b010b6ec9144b 100644 --- a/compiler/rustc_ty_utils/src/sig_types.rs +++ b/compiler/rustc_ty_utils/src/sig_types.rs @@ -34,7 +34,7 @@ pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>( visitor.visit(ty.span, tcx.type_of(item).instantiate_identity().skip_norm_wip()) ); } - for (pred, span) in tcx.explicit_predicates_of(item).instantiate_identity(tcx) { + for (pred, span) in tcx.explicit_clauses_of(item).instantiate_identity(tcx) { try_visit!(visitor.visit(span, pred.skip_norm_wip())); } V::Result::output() @@ -55,8 +55,8 @@ pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>( for (hir, ty) in hir_sig.inputs.iter().zip(ty_sig.inputs().iter()) { try_visit!(visitor.visit(hir.span, ty.map_bound(|x| *x))); } - for (pred, span) in tcx.explicit_predicates_of(item).instantiate_identity(tcx) { - try_visit!(visitor.visit(span, pred.skip_norm_wip())); + for (clause, span) in tcx.explicit_clauses_of(item).instantiate_identity(tcx) { + try_visit!(visitor.visit(span, clause.skip_norm_wip())); } } // Walk over the type behind the alias or the type of the item @@ -96,8 +96,8 @@ pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>( let ty = field.ty(tcx, args); try_visit!(visitor.visit(span, ty)); } - for (pred, span) in tcx.explicit_predicates_of(item).instantiate_identity(tcx) { - try_visit!(visitor.visit(span, pred.skip_norm_wip())); + for (clause, span) in tcx.explicit_clauses_of(item).instantiate_identity(tcx) { + try_visit!(visitor.visit(span, clause.skip_norm_wip())); } } DefKind::Impl { of_trait } => { @@ -122,13 +122,13 @@ pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>( try_visit!( visitor.visit(span, tcx.type_of(item).instantiate_identity().skip_norm_wip()) ); - for (pred, span) in tcx.explicit_predicates_of(item).instantiate_identity(tcx) { - try_visit!(visitor.visit(span, pred.skip_norm_wip())); + for (clause, span) in tcx.explicit_clauses_of(item).instantiate_identity(tcx) { + try_visit!(visitor.visit(span, clause.skip_norm_wip())); } } DefKind::TraitAlias | DefKind::Trait => { - for (pred, span) in tcx.explicit_predicates_of(item).instantiate_identity(tcx) { - try_visit!(visitor.visit(span, pred.skip_norm_wip())); + for (clause, span) in tcx.explicit_clauses_of(item).instantiate_identity(tcx) { + try_visit!(visitor.visit(span, clause.skip_norm_wip())); } } DefKind::Variant diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index 8e67b97c4f21c..39f0da47942e4 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -134,9 +134,9 @@ fn adt_sizedness_constraint<'tcx>( // perf hack: if there is a `constraint_ty: {Meta,}Sized` bound, then we know // that the type is sized and do not need to check it on the impl. let sizedness_trait_def_id = sizedness.require_lang_item(tcx); - let predicates = tcx.predicates_of(def.did()).predicates; - if predicates.iter().any(|(p, _)| { - p.as_trait_clause().is_some_and(|trait_pred| { + let clauses = tcx.clauses_of(def.did()).clauses; + if clauses.iter().any(|(c, _)| { + c.as_trait_clause().is_some_and(|trait_pred| { trait_pred.def_id() == sizedness_trait_def_id && trait_pred.self_ty().skip_binder() == constraint_ty }) @@ -153,9 +153,8 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> { return tcx.param_env(tcx.typeck_root_def_id(def_id)); } // Compute the bounds on Self and the type parameters. - let ty::InstantiatedPredicates { predicates, .. } = - tcx.predicates_of(def_id).instantiate_identity(tcx); - let mut predicates: Vec<_> = predicates.into_iter().map(Unnormalized::skip_norm_wip).collect(); + let ty::InstantiatedClauses { clauses, .. } = tcx.clauses_of(def_id).instantiate_identity(tcx); + let mut clauses: Vec<_> = clauses.into_iter().map(Unnormalized::skip_norm_wip).collect(); // Finally, we have to normalize the bounds in the environment, in // case they contain any associated type projections. This process @@ -180,7 +179,7 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> { tcx, fn_def_id: def_id, bound_vars: sig.bound_vars(), - predicates: &mut predicates, + clauses: &mut clauses, seen: FxHashSet::default(), depth: ty::INNERMOST, }); @@ -189,7 +188,7 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> { // We extend the param-env of our item with the const conditions of the item, // since we're allowed to assume `[const]` bounds hold within the item itself. if tcx.is_conditionally_const(def_id) { - predicates.extend(tcx.const_conditions(def_id).instantiate_identity(tcx).into_iter().map( + clauses.extend(tcx.const_conditions(def_id).instantiate_identity(tcx).into_iter().map( |(trait_ref, _)| { trait_ref.to_host_effect_clause(tcx, ty::BoundConstness::Maybe).skip_norm_wip() }, @@ -198,7 +197,7 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> { let local_did = def_id.as_local().unwrap_or(CRATE_DEF_ID); - let unnormalized_env = ty::ParamEnv::new(tcx.mk_clauses(&predicates)); + let unnormalized_env = ty::ParamEnv::new(tcx.mk_clauses(&clauses)); let cause = traits::ObligationCause::misc(tcx.def_span(def_id), local_did); traits::normalize_param_env_or_error(tcx, unnormalized_env, cause) @@ -210,7 +209,7 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> { /// its corresponding opaque within the body of a default-body trait method. struct ImplTraitInTraitFinder<'a, 'tcx> { tcx: TyCtxt<'tcx>, - predicates: &'a mut Vec>, + clauses: &'a mut Vec>, fn_def_id: DefId, bound_vars: &'tcx ty::List>, seen: FxHashSet, @@ -261,7 +260,7 @@ impl<'tcx> TypeVisitor> for ImplTraitInTraitFinder<'_, 'tcx> { .instantiate(self.tcx, shifted_alias_ty.args) .skip_norm_wip(); - self.predicates.push( + self.clauses.push( ty::Binder::bind_with_vars( ty::ProjectionPredicate { projection_term: shifted_alias_ty.projection_to_alias_ty().into(), diff --git a/compiler/rustc_type_ir/src/binder.rs b/compiler/rustc_type_ir/src/binder.rs index c11532c798a42..4eb28bb1f8920 100644 --- a/compiler/rustc_type_ir/src/binder.rs +++ b/compiler/rustc_type_ir/src/binder.rs @@ -666,7 +666,7 @@ impl> ty::EarlyBinder { // is unnecessary. We may want to track explicitly whether `EarlyBinder` // contains something that has been normalized already. // Also do that for other types who have `instantiate_identity` method, - // e.g., `GenericPredicates` and `ConstConditions`. + // e.g., `GenericClauses` and `ConstConditions`. // // This is annoying, as e.g. `type_of` for opaque types is normalized, // while `type_of` for free type aliases is not. diff --git a/compiler/rustc_type_ir/src/elaborate.rs b/compiler/rustc_type_ir/src/elaborate.rs index 03d5fc1ff8330..0f050b0bed894 100644 --- a/compiler/rustc_type_ir/src/elaborate.rs +++ b/compiler/rustc_type_ir/src/elaborate.rs @@ -165,17 +165,18 @@ impl> Elaborator { ) }; - // Get predicates implied by the trait, or only super predicates if we only care about self predicates. + // Get predicates implied by the trait, or only super predicates if we only care + // about self predicates. match self.mode { Filter::All => self.extend_deduped( - cx.explicit_implied_predicates_of(data.def_id().into()) + cx.explicit_implied_clauses_of(data.def_id().into()) .iter_identity() .map(Unnormalized::skip_norm_wip) .enumerate() .map(map_to_child_clause), ), Filter::OnlySelf => self.extend_deduped( - cx.explicit_super_predicates_of(data.def_id()) + cx.explicit_super_clauses_of(data.def_id()) .iter_identity() .map(Unnormalized::skip_norm_wip) .enumerate() @@ -329,12 +330,12 @@ pub fn supertrait_def_ids( std::iter::from_fn(move || { let trait_def_id = stack.pop()?; - for (predicate, _) in cx - .explicit_super_predicates_of(trait_def_id) + for (clause, _) in cx + .explicit_super_clauses_of(trait_def_id) .iter_identity() .map(Unnormalized::skip_norm_wip) { - if let ty::ClauseKind::Trait(data) = predicate.kind().skip_binder() + if let ty::ClauseKind::Trait(data) = clause.kind().skip_binder() && set.insert(data.def_id()) { stack.push(data.def_id()); diff --git a/compiler/rustc_type_ir/src/interner.rs b/compiler/rustc_type_ir/src/interner.rs index 136a14ce8448a..1fa698a4faeaf 100644 --- a/compiler/rustc_type_ir/src/interner.rs +++ b/compiler/rustc_type_ir/src/interner.rs @@ -320,22 +320,22 @@ pub trait Interner: def_id: Self::DefId, ) -> ty::EarlyBinder>; - fn predicates_of( + fn clauses_of( self, def_id: Self::DefId, ) -> ty::EarlyBinder>; - fn own_predicates_of( + fn own_clauses_of( self, def_id: Self::DefId, ) -> ty::EarlyBinder>; - fn explicit_super_predicates_of( + fn explicit_super_clauses_of( self, def_id: Self::TraitId, ) -> ty::EarlyBinder>; - fn explicit_implied_predicates_of( + fn explicit_implied_clauses_of( self, def_id: Self::DefId, ) -> ty::EarlyBinder>; diff --git a/compiler/rustc_type_ir/src/unnormalized.rs b/compiler/rustc_type_ir/src/unnormalized.rs index a685f32bced2c..8ac567f7ef65b 100644 --- a/compiler/rustc_type_ir/src/unnormalized.rs +++ b/compiler/rustc_type_ir/src/unnormalized.rs @@ -40,7 +40,7 @@ pub struct Unnormalized { impl Unnormalized { /// Should only be used in limited situations where you produce an potentially - /// unnormalized value, like in (Early)Binder/GenericPredicates instantiation. + /// unnormalized value, like in (Early)Binder/GenericClauses instantiation. pub fn new(value: T) -> Unnormalized { Unnormalized { value, _tcx: PhantomData } } diff --git a/src/doc/rustc-dev-guide/src/compiler-debugging.md b/src/doc/rustc-dev-guide/src/compiler-debugging.md index 49a965d49df33..26b56688091e9 100644 --- a/src/doc/rustc-dev-guide/src/compiler-debugging.md +++ b/src/doc/rustc-dev-guide/src/compiler-debugging.md @@ -281,7 +281,7 @@ Here are some notable ones: | `rustc_dump_item_bounds` | Dumps the [`item_bounds`] of an item. | | `rustc_dump_layout` | [See this section](#debugging-type-layouts). | | `rustc_dump_object_lifetime_defaults` | Dumps the [object lifetime defaults] of an item. | -| `rustc_dump_predicates` | Dumps the [`predicates_of`] an item. | +| `rustc_dump_predicates` | Dumps the [`clauses_of`] an item. | | `rustc_dump_symbol_name` | Dumps the mangled & demangled [`symbol_name`] of an item. | | `rustc_dump_variances` | Dumps the [variances] of an item. | | `rustc_dump_vtable` | Dumps the vtable layout of an impl, or a type alias of a dyn type. | @@ -293,7 +293,7 @@ Right below you can find elaborate explainers on a selected few. [`def_path_str`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TyCtxt.html#method.def_path_str [`inferred_outlives_of`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TyCtxt.html#method.inferred_outlives_of [`item_bounds`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TyCtxt.html#method.item_bounds -[`predicates_of`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TyCtxt.html#method.predicates_of +[`clauses_of`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TyCtxt.html#method.clauses_of [`symbol_name`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TyCtxt.html#method.symbol_name [object lifetime defaults]: https://doc.rust-lang.org/reference/lifetime-elision.html#default-trait-object-lifetimes [opaq]: ./opaque-types-impl-trait-inference.md diff --git a/src/doc/rustc-dev-guide/src/effects.md b/src/doc/rustc-dev-guide/src/effects.md index edbb1688e3da5..4096c85a59f7a 100644 --- a/src/doc/rustc-dev-guide/src/effects.md +++ b/src/doc/rustc-dev-guide/src/effects.md @@ -9,22 +9,22 @@ Because `[const] Tr`, or rather `Maybe` bounds apply differently based on whichever contexts they are in, they have different behavior than normal bounds. Where normal trait bounds on a function such as -`T: Tr` are collected within the [`predicates_of`] query to be proven when a +`T: Tr` are collected within the [`clauses_of`] query to be proven when a function is called and to be assumed within the function, bounds such as `T: [const] Tr` will behave as a normal trait bound and add `T: Tr` to the result -from `predicates_of`, but also adds a `HostEffectPredicate` to the [`const_conditions`] query. +from `clauses_of`, but also adds a `HostEffectPredicate` to the [`const_conditions`] query. On the other hand, `T: const Tr` bounds do not change meaning across contexts, therefore they will result in `HostEffect(T: Tr, const)` being added to -`predicates_of`, and not `const_conditions`. +`clauses_of`, and not `const_conditions`. [`HostEffectPredicate`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_type_ir/predicate/struct.HostEffectPredicate.html -[`predicates_of`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.predicates_of +[`clauses_of`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.clauses_of [`const_conditions`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.const_conditions ## The `const_conditions` query -`predicates_of` represents a set of predicates that need to be proven to use an item. +`clauses_of` represents a set of clauses that need to be proven to use an item. For example, to use `foo` in the example below: ```rust diff --git a/src/doc/rustc-dev-guide/src/return-position-impl-trait-in-trait.md b/src/doc/rustc-dev-guide/src/return-position-impl-trait-in-trait.md index 85cece2acd445..e82a0bdbf4be2 100644 --- a/src/doc/rustc-dev-guide/src/return-position-impl-trait-in-trait.md +++ b/src/doc/rustc-dev-guide/src/return-position-impl-trait-in-trait.md @@ -47,7 +47,7 @@ The main addition for RPITITs is that during lowering we track the relationship between the captured lifetimes and the corresponding duplicated lifetimes in an additional field, [`OpaqueTy::lifetime_mapping`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/struct.OpaqueTy.html#structfield.lifetime_mapping). -We use this lifetime mapping later on in `predicates_of` to install +We use this lifetime mapping later on in `clauses_of` to install bounds that enforce equality between these duplicated lifetimes and their source lifetimes in order to properly typecheck these GATs, which will be discussed below. @@ -171,18 +171,18 @@ perhaps by a interested new contributor. ##### `opt_rpitit_info` Some queries rely on computing information that would result in cycles -if we were to feed them eagerly, like `explicit_predicates_of`. -Therefore we defer to the `predicates_of` provider to return the right +if we were to feed them eagerly, like `explicit_clauses_of`. +Therefore we defer to the `clauses_of` provider to return the right value for our RPITIT's GAT. We do this by detecting early on in the query if the associated type is synthetic by using [`opt_rpitit_info`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TyCtxt.html#method.opt_rpitit_info), which returns `Some` if the associated type is synthetic. -Then, during a query like `explicit_predicates_of`, we can detect if an +Then, during a query like `explicit_clauses_of`, we can detect if an associated type is synthetic like: ```rust -fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ... { +fn explicit_clauses_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ... { if let Some(rpitit_info) = tcx.opt_rpitit_info(def_id) { // Do something special for RPITITs... return ...; @@ -192,7 +192,7 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ... { } ``` -##### `explicit_predicates_of` +##### `explicit_clauses_of` RPITITs begin by copying the predicates of the method that defined it, both on the trait and impl side. @@ -378,7 +378,7 @@ error[E0308]: mismatched types We check well-formedness of RPITITs just like regular associated types. -Since we added lifetime bounds in `predicates_of` that link the +Since we added lifetime bounds in `clauses_of` that link the duplicated early-bound lifetimes to their original lifetimes, and we implemented `assumed_wf_types` which inherits the WF types of the method from which the RPITIT originates ([#113704]), we have no issues diff --git a/src/doc/rustc-dev-guide/src/traits/implied-bounds.md b/src/doc/rustc-dev-guide/src/traits/implied-bounds.md index cdcb90d3e2edf..3a419dd1193cd 100644 --- a/src/doc/rustc-dev-guide/src/traits/implied-bounds.md +++ b/src/doc/rustc-dev-guide/src/traits/implied-bounds.md @@ -4,7 +4,7 @@ We currently add implied region bounds to avoid explicit annotations. e.g. `fn foo<'a, T>(x: &'a T)` can freely assume that `T: 'a` holds without specifying it. There are two kinds of implied bounds: explicit and implicit. Explicit implied bounds -get added to the `fn predicates_of` of the relevant item while implicit ones are +get added to the `fn clauses_of` of the relevant item while implicit ones are handled... well... implicitly. ## explicit implied bounds @@ -18,7 +18,7 @@ This function computes the outlives bounds for each component of the field using separate implementation. For ADTs, trait objects, and associated types the initially required predicates are -computed in [`fn check_explicit_predicates`]. This simply uses `fn explicit_predicates_of` +computed in [`fn check_explicit_predicates`]. This simply uses `fn explicit_clauses_of` without elaborating them. Region predicates are added via [`fn insert_outlives_predicate`]. This function takes @@ -65,7 +65,7 @@ lexical region resolution [only uses the unnormalized types][notnorm]. ### proving implicit implied bounds -As the implicit implied bounds are not included in `fn predicates_of` we have to +As the implicit implied bounds are not included in `fn clauses_of` we have to separately make sure they actually hold. We generally handle this by checking that all used types are well formed by emitting `WellFormed` predicates. diff --git a/src/doc/rustc-dev-guide/src/typing-parameter-envs.md b/src/doc/rustc-dev-guide/src/typing-parameter-envs.md index db9f369d2659e..f5a19ea328696 100644 --- a/src/doc/rustc-dev-guide/src/typing-parameter-envs.md +++ b/src/doc/rustc-dev-guide/src/typing-parameter-envs.md @@ -20,7 +20,7 @@ whereas different `ParamEnv`s can be used on a per-goal basis. The [`ParamEnv`][penv] is a list of in-scope where-clauses, it typically corresponds to a specific item's where clauses. -Some clauses are not explicitly written but are instead implicitly added in the [`predicates_of`][predicates_of] query, +Some clauses are not explicitly written but are instead implicitly added in the [`clauses_of`][clauses_of] query, such as `ConstArgHasType` or (some) implied bounds. In most cases `ParamEnv`s are initially created via the [`param_env` query][query] which returns a `ParamEnv` derived from the provided item's where clauses. @@ -75,7 +75,7 @@ fn foo2(a: T) { } ``` -[predicates_of]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir_analysis/collect/predicates_of/fn.predicates_of.html +[clauses_of]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir_analysis/collect/clauses_of/fn.clauses_of.html [method_pred_entailment]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir_analysis/check/compare_impl_item/fn.compare_method_predicate_entailment.html [query]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TyCtxt.html#method.param_env [normalization]: normalization.md diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index f759cd9a0b0a8..75f6db0400edd 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -10,7 +10,7 @@ use rustc_trait_selection::traits::auto_trait::{self, RegionTarget}; use tracing::{debug, instrument}; use crate::clean::{ - self, Lifetime, clean_generic_param_def, clean_middle_ty, clean_predicate, + self, Lifetime, clean_clause, clean_generic_param_def, clean_middle_ty, clean_trait_ref_with_constraints, clean_ty_generics_inner, simplify, }; use crate::core::DocContext; @@ -104,7 +104,7 @@ fn synthesize_auto_trait_impl<'tcx>( let mut generics = clean_ty_generics_inner( cx, tcx.generics_of(item_def_id), - ty::GenericPredicates::default(), + ty::GenericClauses::default(), ); generics.where_predicates.clear(); @@ -200,7 +200,7 @@ fn clean_param_env<'tcx>( } }) }) - .flat_map(|clause| clean_predicate(clause, cx)) + .flat_map(|clause| clean_clause(clause, cx)) .chain(clean_region_outlives_constraints(®ion_data, generics)) .collect() }); diff --git a/src/librustdoc/clean/blanket_impl.rs b/src/librustdoc/clean/blanket_impl.rs index 6cf7c553c76bb..7b4af6ac0dbcb 100644 --- a/src/librustdoc/clean/blanket_impl.rs +++ b/src/librustdoc/clean/blanket_impl.rs @@ -59,19 +59,19 @@ pub(crate) fn synthesize_blanket_impls( // FIXME(eddyb) ignoring `obligations` might cause false positives. drop(obligations); - let predicates = tcx - .predicates_of(impl_def_id) + let clauses = tcx + .clauses_of(impl_def_id) .instantiate(tcx, impl_args) - .predicates + .clauses .into_iter() .map(Unnormalized::skip_norm_wip) .chain(Some(impl_trait_ref.upcast(tcx))); - for predicate in predicates { + for clause in clauses { let obligation = traits::Obligation::new( tcx, traits::ObligationCause::dummy(), param_env, - predicate, + clause, ); match infcx.evaluate_obligation(&obligation) { Ok(eval_result) if eval_result.may_apply() => {} diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index a81d56e708173..d03bf56fb9c33 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -425,19 +425,19 @@ fn clean_where_predicate<'tcx>( }) } -pub(crate) fn clean_predicate<'tcx>( - predicate: ty::Clause<'tcx>, +pub(crate) fn clean_clause<'tcx>( + clause: ty::Clause<'tcx>, cx: &mut DocContext<'tcx>, ) -> Option { - let bound_predicate = predicate.kind(); - match bound_predicate.skip_binder() { - ty::ClauseKind::Trait(pred) => clean_poly_trait_predicate(bound_predicate.rebind(pred), cx), + let bound_clause = clause.kind(); + match bound_clause.skip_binder() { + ty::ClauseKind::Trait(pred) => clean_poly_trait_predicate(bound_clause.rebind(pred), cx), ty::ClauseKind::RegionOutlives(pred) => Some(clean_region_outlives_predicate(pred, cx.tcx)), ty::ClauseKind::TypeOutlives(pred) => { - Some(clean_type_outlives_predicate(bound_predicate.rebind(pred), cx)) + Some(clean_type_outlives_predicate(bound_clause.rebind(pred), cx)) } ty::ClauseKind::Projection(pred) => { - Some(clean_projection_predicate(bound_predicate.rebind(pred), cx)) + Some(clean_projection_predicate(bound_clause.rebind(pred), cx)) } // FIXME(generic_const_exprs): should this do something? ty::ClauseKind::ConstEvaluatable(..) @@ -855,13 +855,13 @@ pub(crate) fn clean_generics<'tcx>( } fn clean_ty_generics<'tcx>(cx: &mut DocContext<'tcx>, def_id: DefId) -> Generics { - clean_ty_generics_inner(cx, cx.tcx.generics_of(def_id), cx.tcx.explicit_predicates_of(def_id)) + clean_ty_generics_inner(cx, cx.tcx.generics_of(def_id), cx.tcx.explicit_clauses_of(def_id)) } fn clean_ty_generics_inner<'tcx>( cx: &mut DocContext<'tcx>, gens: &ty::Generics, - preds: ty::GenericPredicates<'tcx>, + gen_clauses: ty::GenericClauses<'tcx>, ) -> Generics { // Don't populate `cx.impl_trait_bounds` before cleaning where clauses, // since `clean_predicate` would consume them. @@ -892,14 +892,14 @@ fn clean_ty_generics_inner<'tcx>( let mut impl_trait_proj = FxHashMap::>)>>::default(); - let where_predicates = preds - .predicates + let where_clauses = gen_clauses + .clauses .iter() - .flat_map(|(pred, _)| { + .flat_map(|(clause, _)| { let mut proj_pred = None; let param_idx = { - let bound_p = pred.kind(); - match bound_p.skip_binder() { + let bound_c = clause.kind(); + match bound_c.skip_binder() { ty::ClauseKind::Trait(pred) if let ty::Param(param) = pred.self_ty().kind() => { Some(param.index) } @@ -911,7 +911,7 @@ fn clean_ty_generics_inner<'tcx>( ty::ClauseKind::Projection(p) if let ty::Param(param) = p.projection_term.self_ty().kind() => { - proj_pred = Some(bound_p.rebind(p)); + proj_pred = Some(bound_c.rebind(p)); Some(param.index) } _ => None, @@ -921,9 +921,9 @@ fn clean_ty_generics_inner<'tcx>( if let Some(param_idx) = param_idx && let Some(bounds) = impl_trait.get_mut(¶m_idx) { - let pred = clean_predicate(*pred, cx)?; + let clause = clean_clause(*clause, cx)?; - bounds.extend(pred.get_bounds().into_iter().flatten().cloned()); + bounds.extend(clause.get_bounds().into_iter().flatten().cloned()); if let Some(pred) = proj_pred { let lhs = clean_projection(pred.map_bound(|p| p.projection_term), cx, None); @@ -937,7 +937,7 @@ fn clean_ty_generics_inner<'tcx>( return None; } - Some(pred) + Some(clause) }) .collect::>(); @@ -980,8 +980,7 @@ fn clean_ty_generics_inner<'tcx>( // Now that `cx.impl_trait_bounds` is populated, we can process // remaining predicates which could contain `impl Trait`. - let where_predicates = - where_predicates.into_iter().flat_map(|p| clean_predicate(*p, cx)).collect(); + let where_predicates = where_clauses.into_iter().flat_map(|c| clean_clause(*c, cx)).collect(); let mut generics = Generics { params, where_predicates }; simplify::sizedness_bounds(cx, &mut generics); @@ -1469,18 +1468,18 @@ pub(crate) fn clean_middle_assoc_item(assoc_item: &ty::AssocItem, cx: &mut DocCo } } - let mut predicates = tcx.explicit_predicates_of(assoc_item.def_id).predicates; + let mut clauses = tcx.explicit_clauses_of(assoc_item.def_id).clauses; if let ty::AssocContainer::Trait = assoc_item.container { let bounds = tcx .explicit_item_bounds(assoc_item.def_id) .iter_identity_copied() .map(Unnormalized::skip_norm_wip); - predicates = tcx.arena.alloc_from_iter(bounds.chain(predicates.iter().copied())); + clauses = tcx.arena.alloc_from_iter(bounds.chain(clauses.iter().copied())); } let mut generics = clean_ty_generics_inner( cx, tcx.generics_of(assoc_item.def_id), - ty::GenericPredicates { parent: None, predicates }, + ty::GenericClauses { parent: None, clauses }, ); simplify::move_bounds_to_generic_parameters(&mut generics); diff --git a/src/librustdoc/clean/simplify.rs b/src/librustdoc/clean/simplify.rs index fecbc913771b2..3b00e2b3ac48b 100644 --- a/src/librustdoc/clean/simplify.rs +++ b/src/librustdoc/clean/simplify.rs @@ -113,7 +113,7 @@ fn trait_is_same_or_supertrait(tcx: TyCtxt<'_>, child: DefId, trait_: DefId) -> if child == trait_ { return true; } - let predicates = tcx.explicit_super_predicates_of(child); + let predicates = tcx.explicit_super_clauses_of(child); predicates .iter_identity_copied() .map(Unnormalized::skip_norm_wip) diff --git a/src/tools/clippy/clippy_lints/src/derive/derive_partial_eq_without_eq.rs b/src/tools/clippy/clippy_lints/src/derive/derive_partial_eq_without_eq.rs index 612d552a75408..1056929405035 100644 --- a/src/tools/clippy/clippy_lints/src/derive/derive_partial_eq_without_eq.rs +++ b/src/tools/clippy/clippy_lints/src/derive/derive_partial_eq_without_eq.rs @@ -65,9 +65,9 @@ fn typing_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) -> .map(|p| (p, matches!(p.kind, GenericParamDefKind::Type { .. }))) .collect::>(); - let ty_predicates = tcx.predicates_of(did).predicates; - for (p, _) in ty_predicates { - if let ClauseKind::Trait(p) = p.kind().skip_binder() + let ty_clauses = tcx.clauses_of(did).clauses; + for (c, _) in ty_clauses { + if let ClauseKind::Trait(p) = c.kind().skip_binder() && p.trait_ref.def_id == eq_trait_id && let ty::Param(self_ty) = p.trait_ref.self_ty().kind() { @@ -76,7 +76,7 @@ fn typing_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) -> } } - let param_env = ParamEnv::new(tcx.mk_clauses_from_iter(ty_predicates.iter().map(|&(p, _)| p).chain( + let param_env = ParamEnv::new(tcx.mk_clauses_from_iter(ty_clauses.iter().map(|&(c, _)| c).chain( params.iter().filter(|&&(_, needs_eq)| needs_eq).map(|&(param, _)| { ClauseKind::Trait(TraitPredicate { trait_ref: ty::TraitRef::new(tcx, eq_trait_id, [tcx.mk_param_from_def(param)]), diff --git a/src/tools/clippy/clippy_lints/src/implied_bounds_in_impls.rs b/src/tools/clippy/clippy_lints/src/implied_bounds_in_impls.rs index 780c789d4fe38..04a7c6a74e3c7 100644 --- a/src/tools/clippy/clippy_lints/src/implied_bounds_in_impls.rs +++ b/src/tools/clippy/clippy_lints/src/implied_bounds_in_impls.rs @@ -241,7 +241,7 @@ fn collect_supertrait_bounds<'tcx>(cx: &LateContext<'tcx>, bounds: GenericBounds && let [.., path] = poly_trait.trait_ref.path.segments && poly_trait.bound_generic_params.is_empty() && let Some(trait_def_id) = path.res.opt_def_id() - && let predicates = cx.tcx.explicit_super_predicates_of(trait_def_id).skip_binder() + && let predicates = cx.tcx.explicit_super_clauses_of(trait_def_id).skip_binder() // If the trait has no supertrait, there is no need to collect anything from that bound && !predicates.is_empty() { diff --git a/src/tools/clippy/clippy_lints/src/inherent_impl.rs b/src/tools/clippy/clippy_lints/src/inherent_impl.rs index 7475897852177..7f653d08a66f5 100644 --- a/src/tools/clippy/clippy_lints/src/inherent_impl.rs +++ b/src/tools/clippy/clippy_lints/src/inherent_impl.rs @@ -101,21 +101,21 @@ impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl { InherentImplLintScope::Crate => Criterion::Crate, }; let is_test = is_cfg_test(cx.tcx, hir_id) || is_in_cfg_test(cx.tcx, hir_id); - let predicates = { - // Gets the predicates (bounds) for the given impl block, + let clauses = { + // Gets the clauses (bounds) for the given impl block, // sorted for consistent comparison to allow distinguishing between impl blocks // with different generic bounds. - let mut predicates = cx + let mut clauses = cx .tcx - .predicates_of(impl_id) - .predicates + .clauses_of(impl_id) + .clauses .iter() .map(|(clause, _)| *clause) .collect::>(); - predicates.sort_by_key(|c| format!("{c:?}")); - predicates + clauses.sort_by_key(|c| format!("{c:?}")); + clauses }; - match type_map.entry((impl_ty, predicates, criterion, is_test)) { + match type_map.entry((impl_ty, clauses, criterion, is_test)) { Entry::Vacant(e) => { // Store the id for the first impl block of this type. The span is retrieved lazily. e.insert(IdOrSpan::Id(impl_id)); diff --git a/src/tools/clippy/clippy_lints/src/large_stack_frames.rs b/src/tools/clippy/clippy_lints/src/large_stack_frames.rs index dec3f3bcae895..bf4d37ad570e0 100644 --- a/src/tools/clippy/clippy_lints/src/large_stack_frames.rs +++ b/src/tools/clippy/clippy_lints/src/large_stack_frames.rs @@ -3,7 +3,7 @@ use std::{fmt, ops}; use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::source::SpanExt; -use clippy_utils::{fn_has_unsatisfiable_preds, is_entrypoint_fn, is_in_test}; +use clippy_utils::{fn_has_unsatisfiable_clauses, is_entrypoint_fn, is_in_test}; use rustc_errors::Diag; use rustc_hir::def_id::LocalDefId; use rustc_hir::intravisit::FnKind; @@ -148,7 +148,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeStackFrames { ) { let def_id = local_def_id.to_def_id(); // Building MIR for `fn`s with unsatisfiable preds results in ICE. - if fn_has_unsatisfiable_preds(cx, def_id) { + if fn_has_unsatisfiable_clauses(cx, def_id) { return; } diff --git a/src/tools/clippy/clippy_lints/src/methods/iter_on_single_or_empty_collections.rs b/src/tools/clippy/clippy_lints/src/methods/iter_on_single_or_empty_collections.rs index b217aba78ca6c..0aa7342a600a3 100644 --- a/src/tools/clippy/clippy_lints/src/methods/iter_on_single_or_empty_collections.rs +++ b/src/tools/clippy/clippy_lints/src/methods/iter_on_single_or_empty_collections.rs @@ -43,9 +43,9 @@ fn is_arg_ty_unified_in_fn<'tcx>( fn_sig .predicates_id() - .map(|def_id| cx.tcx.predicates_of(def_id)) + .map(|def_id| cx.tcx.clauses_of(def_id)) .is_some_and(|generics| { - generics.predicates.iter().any(|(clause, _)| { + generics.clauses.iter().any(|(clause, _)| { clause .as_projection_clause() .and_then(|p| p.map_bound(|p| p.term.as_type()).transpose()) diff --git a/src/tools/clippy/clippy_lints/src/methods/type_id_on_box.rs b/src/tools/clippy/clippy_lints/src/methods/type_id_on_box.rs index 3e4eae9e53668..2ffe364ff3fed 100644 --- a/src/tools/clippy/clippy_lints/src/methods/type_id_on_box.rs +++ b/src/tools/clippy/clippy_lints/src/methods/type_id_on_box.rs @@ -25,7 +25,7 @@ fn is_subtrait_of_any(cx: &LateContext<'_>, ty: Ty<'_>) -> bool { cx.tcx.is_diagnostic_item(sym::Any, tr.def_id) || cx .tcx - .explicit_super_predicates_of(tr.def_id) + .explicit_super_clauses_of(tr.def_id) .iter_identity_copied() .map(Unnormalized::skip_norm_wip) .any(|(clause, _)| { diff --git a/src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs b/src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs index 9c6f307cc6594..c454c9e87a3f2 100644 --- a/src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -737,8 +737,8 @@ fn check_borrow_predicate<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>) { && let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id) && cx.tcx.trait_of_assoc(method_def_id).is_none() && let Some(borrow_id) = cx.tcx.get_diagnostic_item(sym::Borrow) - && cx.tcx.predicates_of(method_def_id).predicates.iter().any(|(pred, _)| { - if let ClauseKind::Trait(trait_pred) = pred.kind().skip_binder() + && cx.tcx.clauses_of(method_def_id).clauses.iter().any(|(clause, _)| { + if let ClauseKind::Trait(trait_pred) = clause.kind().skip_binder() && trait_pred.polarity == ty::PredicatePolarity::Positive && trait_pred.trait_ref.def_id == borrow_id { diff --git a/src/tools/clippy/clippy_lints/src/missing_const_for_fn.rs b/src/tools/clippy/clippy_lints/src/missing_const_for_fn.rs index 743b5123fed6d..d032d53b69902 100644 --- a/src/tools/clippy/clippy_lints/src/missing_const_for_fn.rs +++ b/src/tools/clippy/clippy_lints/src/missing_const_for_fn.rs @@ -2,7 +2,7 @@ use clippy_config::Conf; use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::msrvs::{self, Msrv}; use clippy_utils::qualify_min_const_fn::is_min_const_fn; -use clippy_utils::{fn_has_unsatisfiable_preds, is_entrypoint_fn, is_from_proc_macro, is_in_test, trait_ref_of_method}; +use clippy_utils::{fn_has_unsatisfiable_clauses, is_entrypoint_fn, is_from_proc_macro, is_in_test, trait_ref_of_method}; use rustc_abi::ExternAbi; use rustc_errors::Applicability; use rustc_hir::def_id::CRATE_DEF_ID; @@ -104,7 +104,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn { } // Building MIR for `fn`s with unsatisfiable preds results in ICE. - if fn_has_unsatisfiable_preds(cx, def_id.to_def_id()) { + if fn_has_unsatisfiable_clauses(cx, def_id.to_def_id()) { return; } diff --git a/src/tools/clippy/clippy_lints/src/missing_const_for_thread_local.rs b/src/tools/clippy/clippy_lints/src/missing_const_for_thread_local.rs index bb5396c7cac91..a7be1e4760230 100644 --- a/src/tools/clippy/clippy_lints/src/missing_const_for_thread_local.rs +++ b/src/tools/clippy/clippy_lints/src/missing_const_for_thread_local.rs @@ -4,7 +4,7 @@ use clippy_utils::macros::macro_backtrace; use clippy_utils::msrvs::{self, Msrv}; use clippy_utils::qualify_min_const_fn::is_min_const_fn; use clippy_utils::source::snippet; -use clippy_utils::{fn_has_unsatisfiable_preds, peel_blocks, sym}; +use clippy_utils::{fn_has_unsatisfiable_clauses, peel_blocks, sym}; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind, intravisit}; use rustc_lint::{LateContext, LateLintPass}; @@ -90,7 +90,7 @@ fn is_unreachable(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { #[inline] fn initializer_can_be_made_const(cx: &LateContext<'_>, defid: rustc_span::def_id::DefId, msrv: Msrv) -> bool { // Building MIR for `fn`s with unsatisfiable preds results in ICE. - if !fn_has_unsatisfiable_preds(cx, defid) + if !fn_has_unsatisfiable_clauses(cx, defid) && let mir = cx.tcx.optimized_mir(defid) && let Ok(()) = is_min_const_fn(cx, mir, msrv) { diff --git a/src/tools/clippy/clippy_lints/src/needless_maybe_sized.rs b/src/tools/clippy/clippy_lints/src/needless_maybe_sized.rs index 600e4beba7d2f..b8e40cbf05049 100644 --- a/src/tools/clippy/clippy_lints/src/needless_maybe_sized.rs +++ b/src/tools/clippy/clippy_lints/src/needless_maybe_sized.rs @@ -94,7 +94,7 @@ fn path_to_sized_bound(cx: &LateContext<'_>, trait_bound: &PolyTraitRef<'_>) -> for (predicate, _) in cx .tcx - .explicit_super_predicates_of(trait_def_id) + .explicit_super_clauses_of(trait_def_id) .iter_identity_copied() .map(Unnormalized::skip_norm_wip) { diff --git a/src/tools/clippy/clippy_lints/src/redundant_clone.rs b/src/tools/clippy/clippy_lints/src/redundant_clone.rs index db3be9e64f147..e2fddfd50279c 100644 --- a/src/tools/clippy/clippy_lints/src/redundant_clone.rs +++ b/src/tools/clippy/clippy_lints/src/redundant_clone.rs @@ -3,7 +3,7 @@ use clippy_utils::mir::{LocalUsage, PossibleBorrowerMap, visit_local_usage}; use clippy_utils::res::MaybeDef; use clippy_utils::source::SpanExt; use clippy_utils::ty::{has_drop, is_copy, peel_and_count_ty_refs}; -use clippy_utils::{fn_has_unsatisfiable_preds, sym}; +use clippy_utils::{fn_has_unsatisfiable_clauses, sym}; use rustc_errors::Applicability; use rustc_hir::intravisit::FnKind; use rustc_hir::{Body, FnDecl, LangItem, def_id}; @@ -74,7 +74,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantClone { def_id: LocalDefId, ) { // Building MIR for `fn`s with unsatisfiable preds results in ICE. - if fn_has_unsatisfiable_preds(cx, def_id.to_def_id()) { + if fn_has_unsatisfiable_clauses(cx, def_id.to_def_id()) { return; } diff --git a/src/tools/clippy/clippy_lints/src/unit_return_expecting_ord.rs b/src/tools/clippy/clippy_lints/src/unit_return_expecting_ord.rs index 13baa378910d9..66f5bad854027 100644 --- a/src/tools/clippy/clippy_lints/src/unit_return_expecting_ord.rs +++ b/src/tools/clippy/clippy_lints/src/unit_return_expecting_ord.rs @@ -3,7 +3,7 @@ use rustc_hir::def_id::DefId; use rustc_hir::{Closure, Expr, ExprKind, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; -use rustc_middle::ty::{ClauseKind, GenericPredicates, ProjectionPredicate, TraitPredicate}; +use rustc_middle::ty::{ClauseKind, GenericClauses, ProjectionPredicate, TraitPredicate}; use rustc_session::declare_lint_pass; use rustc_span::{BytePos, Span, Symbol, sym}; @@ -36,19 +36,18 @@ declare_clippy_lint! { declare_lint_pass!(UnitReturnExpectingOrd => [UNIT_RETURN_EXPECTING_ORD]); -// For each fn get_trait_predicates_for_trait_ids<'tcx>( cx: &LateContext<'tcx>, - generics: GenericPredicates<'tcx>, + generics: GenericClauses<'tcx>, trait_ids: &[Option], // At least 2 ids ) -> [Vec>; 3] { debug_assert!(trait_ids.len() >= 2); let mut preds = [Vec::new(), Vec::new(), Vec::new()]; - for (pred, _) in generics.predicates { - if let ClauseKind::Trait(poly_trait_pred) = pred.kind().skip_binder() { + for (clause, _) in generics.clauses { + if let ClauseKind::Trait(poly_trait_pred) = clause.kind().skip_binder() { let trait_pred = cx .tcx - .instantiate_bound_regions_with_erased(pred.kind().rebind(poly_trait_pred)); + .instantiate_bound_regions_with_erased(clause.kind().rebind(poly_trait_pred)); for (i, tid) in trait_ids.iter().enumerate() { if let Some(tid) = tid && *tid == trait_pred.trait_ref.def_id @@ -63,14 +62,14 @@ fn get_trait_predicates_for_trait_ids<'tcx>( fn get_projection_pred<'tcx>( cx: &LateContext<'tcx>, - generics: GenericPredicates<'tcx>, + generics: GenericClauses<'tcx>, trait_pred: TraitPredicate<'tcx>, ) -> Option> { - generics.predicates.iter().find_map(|(proj_pred, _)| { - if let ClauseKind::Projection(pred) = proj_pred.kind().skip_binder() { + generics.clauses.iter().find_map(|(clause, _)| { + if let ClauseKind::Projection(pred) = clause.kind().skip_binder() { let projection_pred = cx .tcx - .instantiate_bound_regions_with_erased(proj_pred.kind().rebind(pred)); + .instantiate_bound_regions_with_erased(clause.kind().rebind(pred)); if projection_pred.projection_term.args == trait_pred.trait_ref.args { return Some(projection_pred); } @@ -90,7 +89,7 @@ fn get_args_to_check<'tcx>( let mut args_to_check = Vec::new(); if let Some(def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id) { let fn_sig = cx.tcx.fn_sig(def_id).instantiate_identity().skip_norm_wip(); - let generics = cx.tcx.predicates_of(def_id); + let generics = cx.tcx.clauses_of(def_id); let [fn_mut_preds, ord_preds, partial_ord_preds] = get_trait_predicates_for_trait_ids(cx, generics, &[Some(fn_mut_trait), ord_trait, partial_ord_trait]); if fn_mut_preds.is_empty() { diff --git a/src/tools/clippy/clippy_lints/src/useless_conversion.rs b/src/tools/clippy/clippy_lints/src/useless_conversion.rs index 2961ee7081533..e2dd0a8d2f3dd 100644 --- a/src/tools/clippy/clippy_lints/src/useless_conversion.rs +++ b/src/tools/clippy/clippy_lints/src/useless_conversion.rs @@ -90,8 +90,8 @@ fn into_iter_bound<'tcx>( ) -> Option { let mut into_iter_span = None; - for (pred, span) in cx.tcx.explicit_predicates_of(fn_did).predicates { - if let ty::ClauseKind::Trait(tr) = pred.kind().skip_binder() + for (clause, span) in cx.tcx.explicit_clauses_of(fn_did).clauses { + if let ty::ClauseKind::Trait(tr) = clause.kind().skip_binder() && tr.self_ty().is_param(param_index) { if tr.def_id() == into_iter_did { diff --git a/src/tools/clippy/clippy_utils/src/consts.rs b/src/tools/clippy/clippy_utils/src/consts.rs index b6dc5dc38cd17..cb04f4373ec4f 100644 --- a/src/tools/clippy/clippy_utils/src/consts.rs +++ b/src/tools/clippy/clippy_utils/src/consts.rs @@ -893,7 +893,7 @@ impl<'tcx> ConstEvalCtxt<'tcx> { // Don't try to fully evaluate consts inside code whose bounds can't be satisfied. if self .tcx - .instantiate_and_check_impossible_predicates((owner_def_id, identity_args)) + .instantiate_and_check_impossible_clauses((owner_def_id, identity_args)) { return None; } diff --git a/src/tools/clippy/clippy_utils/src/eager_or_lazy.rs b/src/tools/clippy/clippy_utils/src/eager_or_lazy.rs index 1c133fccdb308..9e9ae945ee16f 100644 --- a/src/tools/clippy/clippy_utils/src/eager_or_lazy.rs +++ b/src/tools/clippy/clippy_utils/src/eager_or_lazy.rs @@ -11,7 +11,7 @@ use crate::consts::{ConstEvalCtxt, FullInt}; use crate::sym; -use crate::ty::all_predicates_of; +use crate::ty::all_clauses_of; use crate::visitors::is_const_evaluatable; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::DefId; @@ -78,7 +78,7 @@ fn fn_eagerness(tcx: TyCtxt<'_>, fn_id: DefId, name: Symbol, have_one_arg: bool) .kind(), ty::Param(_) ) - }) && all_predicates_of(tcx, fn_id).all(|(pred, _)| match pred.kind().skip_binder() { + }) && all_clauses_of(tcx, fn_id).all(|(pred, _)| match pred.kind().skip_binder() { ty::ClauseKind::Trait(pred) => tcx.trait_def(pred.trait_ref.def_id).is_marker, _ => true, }) && subs.types().all(|x| matches!(x.peel_refs().kind(), ty::Param(_))) diff --git a/src/tools/clippy/clippy_utils/src/lib.rs b/src/tools/clippy/clippy_utils/src/lib.rs index e1b58a6cbb890..a5fa7dd7ae996 100644 --- a/src/tools/clippy/clippy_utils/src/lib.rs +++ b/src/tools/clippy/clippy_utils/src/lib.rs @@ -2094,15 +2094,15 @@ pub fn is_trait_impl_item(cx: &LateContext<'_>, hir_id: HirId) -> bool { /// for _ in 2i32 {} /// } /// ``` -pub fn fn_has_unsatisfiable_preds(cx: &LateContext<'_>, did: DefId) -> bool { +pub fn fn_has_unsatisfiable_clauses(cx: &LateContext<'_>, did: DefId) -> bool { use rustc_trait_selection::traits; - let predicates = cx + let clauses = cx .tcx - .predicates_of(did) - .predicates + .clauses_of(did) + .clauses .iter() - .filter_map(|(p, _)| if p.is_global() { Some(*p) } else { None }); - traits::impossible_predicates(cx.tcx, traits::elaborate(cx.tcx, predicates).collect::>()) + .filter_map(|(c, _)| if c.is_global() { Some(*c) } else { None }); + traits::impossible_clauses(cx.tcx, traits::elaborate(cx.tcx, clauses).collect::>()) } /// Returns the `DefId` of the callee if the given expression is a function or method call. diff --git a/src/tools/clippy/clippy_utils/src/ty/mod.rs b/src/tools/clippy/clippy_utils/src/ty/mod.rs index f9a21deeca19d..1ce756da41afc 100644 --- a/src/tools/clippy/clippy_utils/src/ty/mod.rs +++ b/src/tools/clippy/clippy_utils/src/ty/mod.rs @@ -617,13 +617,13 @@ fn is_uninit_value_valid_for_ty_fallback<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'t } /// Gets an iterator over all predicates which apply to the given item. -pub fn all_predicates_of(tcx: TyCtxt<'_>, id: DefId) -> impl Iterator, Span)> { +pub fn all_clauses_of(tcx: TyCtxt<'_>, id: DefId) -> impl Iterator, Span)> { let mut next_id = Some(id); iter::from_fn(move || { next_id.take().map(|id| { - let preds = tcx.predicates_of(id); - next_id = preds.parent; - preds.predicates.iter() + let gen_clauses = tcx.clauses_of(id); + next_id = gen_clauses.parent; + gen_clauses.clauses.iter() }) }) .flatten() diff --git a/tests/codegen-units/item-collection/drop-glue-eager.rs b/tests/codegen-units/item-collection/drop-glue-eager.rs index ae9536887917e..7039dbbbe679a 100644 --- a/tests/codegen-units/item-collection/drop-glue-eager.rs +++ b/tests/codegen-units/item-collection/drop-glue-eager.rs @@ -45,7 +45,7 @@ struct StructWithDropAndLt<'a> { x: &'a i32, } -// Make sure we don't ICE when checking impossible predicates for the struct. +// Make sure we don't ICE when checking impossible clauses for the struct. // Regression test for . //~ MONO_ITEM fn std::ptr::drop_glue::> - shim(Some(StructWithLtAndPredicate<'_>)) struct StructWithLtAndPredicate<'a: 'a> { diff --git a/tests/incremental/clean.rs b/tests/incremental/clean.rs index 1ec34ff9c9046..64db90210ebc7 100644 --- a/tests/incremental/clean.rs +++ b/tests/incremental/clean.rs @@ -27,13 +27,13 @@ mod y { use x; #[rustc_clean( - except="hir_owner,generics_of,predicates_of,type_of,fn_sig", + except="hir_owner,generics_of,clauses_of,type_of,fn_sig", cfg="bfail2", )] pub fn y() { //[bfail2]~^ ERROR `hir_owner(y)` should be dirty but is not //[bfail2]~| ERROR `generics_of(y)` should be dirty but is not - //[bfail2]~| ERROR `predicates_of(y)` should be dirty but is not + //[bfail2]~| ERROR `clauses_of(y)` should be dirty but is not //[bfail2]~| ERROR `type_of(y)` should be dirty but is not //[bfail2]~| ERROR `fn_sig(y)` should be dirty but is not //[bfail2]~| ERROR `typeck_root(y)` should be clean but is not diff --git a/tests/incremental/cyclic-trait-hierarchy.rs b/tests/incremental/cyclic-trait-hierarchy.rs index 4b0570361c1b7..68a65715a8624 100644 --- a/tests/incremental/cyclic-trait-hierarchy.rs +++ b/tests/incremental/cyclic-trait-hierarchy.rs @@ -6,7 +6,7 @@ pub trait T2 {} #[cfg(bfail2)] pub trait T2: T1 {} -//[bfail2]~^ ERROR cycle detected when computing the super predicates of `T2` +//[bfail2]~^ ERROR cycle detected when computing the super clauses of `T2` pub trait T1: T2 {} diff --git a/tests/incremental/hashes/enum_defs.rs b/tests/incremental/hashes/enum_defs.rs index ed239b301a36d..93b90ab5b5653 100644 --- a/tests/incremental/hashes/enum_defs.rs +++ b/tests/incremental/hashes/enum_defs.rs @@ -412,9 +412,9 @@ enum EnumChangeNameOfTypeParameter { } #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(cfg="bpass2", except="hir_owner,generics_of,predicates_of,type_of")] +#[rustc_clean(cfg="bpass2", except="hir_owner,generics_of,clauses_of,type_of")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(cfg="bpass5", except="hir_owner,generics_of,predicates_of,type_of")] +#[rustc_clean(cfg="bpass5", except="hir_owner,generics_of,clauses_of,type_of")] #[rustc_clean(cfg="bpass6")] enum EnumChangeNameOfTypeParameter { Variant1(T), @@ -430,9 +430,9 @@ enum EnumAddTypeParameter { } #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(cfg="bpass2", except="hir_owner,generics_of,predicates_of,type_of")] +#[rustc_clean(cfg="bpass2", except="hir_owner,generics_of,clauses_of,type_of")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(cfg="bpass5", except="hir_owner,generics_of,predicates_of,type_of")] +#[rustc_clean(cfg="bpass5", except="hir_owner,generics_of,clauses_of,type_of")] #[rustc_clean(cfg="bpass6")] enum EnumAddTypeParameter { Variant1(S), @@ -485,9 +485,9 @@ enum EnumAddLifetimeParameterBound<'a, 'b> { } #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(cfg="bpass2", except="hir_owner,predicates_of")] +#[rustc_clean(cfg="bpass2", except="hir_owner,clauses_of")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(cfg="bpass5", except="hir_owner,predicates_of")] +#[rustc_clean(cfg="bpass5", except="hir_owner,clauses_of")] #[rustc_clean(cfg="bpass6")] enum EnumAddLifetimeParameterBound<'a, 'b: 'a> { Variant1(&'a u32), @@ -502,9 +502,9 @@ enum EnumAddLifetimeBoundToParameter<'a, T> { } #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(cfg="bpass2", except="hir_owner,predicates_of")] +#[rustc_clean(cfg="bpass2", except="hir_owner,clauses_of")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(cfg="bpass5", except="hir_owner,predicates_of")] +#[rustc_clean(cfg="bpass5", except="hir_owner,clauses_of")] #[rustc_clean(cfg="bpass6")] enum EnumAddLifetimeBoundToParameter<'a, T: 'a> { Variant1(T), @@ -520,9 +520,9 @@ enum EnumAddTraitBound { } #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(cfg="bpass2", except="hir_owner,generics_of,predicates_of,type_of")] +#[rustc_clean(cfg="bpass2", except="hir_owner,generics_of,clauses_of,type_of")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(cfg="bpass5", except="hir_owner,generics_of,predicates_of,type_of")] +#[rustc_clean(cfg="bpass5", except="hir_owner,generics_of,clauses_of,type_of")] #[rustc_clean(cfg="bpass6")] enum EnumAddTraitBound { Variant1(T), @@ -538,9 +538,9 @@ enum EnumAddLifetimeParameterBoundWhere<'a, 'b> { } #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(cfg="bpass2", except="hir_owner,predicates_of")] +#[rustc_clean(cfg="bpass2", except="hir_owner,clauses_of")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(cfg="bpass5", except="hir_owner,predicates_of")] +#[rustc_clean(cfg="bpass5", except="hir_owner,clauses_of")] #[rustc_clean(cfg="bpass6")] enum EnumAddLifetimeParameterBoundWhere<'a, 'b> where 'b: 'a { Variant1(&'a u32), @@ -557,9 +557,9 @@ enum EnumAddLifetimeBoundToParameterWhere<'a, T> { } #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(cfg="bpass2", except="hir_owner,predicates_of")] +#[rustc_clean(cfg="bpass2", except="hir_owner,clauses_of")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(cfg="bpass5", except="hir_owner,predicates_of")] +#[rustc_clean(cfg="bpass5", except="hir_owner,clauses_of")] #[rustc_clean(cfg="bpass6")] enum EnumAddLifetimeBoundToParameterWhere<'a, T> where T: 'a { Variant1(T), @@ -575,9 +575,9 @@ enum EnumAddTraitBoundWhere { } #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(cfg="bpass2", except="hir_owner,generics_of,predicates_of,type_of")] +#[rustc_clean(cfg="bpass2", except="hir_owner,generics_of,clauses_of,type_of")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(cfg="bpass5", except="hir_owner,generics_of,predicates_of,type_of")] +#[rustc_clean(cfg="bpass5", except="hir_owner,generics_of,clauses_of,type_of")] #[rustc_clean(cfg="bpass6")] enum EnumAddTraitBoundWhere where T: Sync { Variant1(T), @@ -688,9 +688,9 @@ mod change_trait_bound_indirectly { #[cfg(not(any(bpass1,bpass4)))] use super::ReferencedTrait2 as Trait; - #[rustc_clean(cfg="bpass2", except="hir_owner,predicates_of")] + #[rustc_clean(cfg="bpass2", except="hir_owner,clauses_of")] #[rustc_clean(cfg="bpass3")] - #[rustc_clean(cfg="bpass5", except="hir_owner,predicates_of")] + #[rustc_clean(cfg="bpass5", except="hir_owner,clauses_of")] #[rustc_clean(cfg="bpass6")] enum Enum { Variant1(T) @@ -706,9 +706,9 @@ mod change_trait_bound_indirectly_where { #[cfg(not(any(bpass1,bpass4)))] use super::ReferencedTrait2 as Trait; - #[rustc_clean(cfg="bpass2", except="hir_owner,predicates_of")] + #[rustc_clean(cfg="bpass2", except="hir_owner,clauses_of")] #[rustc_clean(cfg="bpass3")] - #[rustc_clean(cfg="bpass5", except="hir_owner,predicates_of")] + #[rustc_clean(cfg="bpass5", except="hir_owner,clauses_of")] #[rustc_clean(cfg="bpass6")] enum Enum where T: Trait { Variant1(T) diff --git a/tests/incremental/hashes/function_interfaces.rs b/tests/incremental/hashes/function_interfaces.rs index cb98d56534e1f..8847c6a69bb79 100644 --- a/tests/incremental/hashes/function_interfaces.rs +++ b/tests/incremental/hashes/function_interfaces.rs @@ -140,12 +140,12 @@ pub fn type_parameter () {} #[cfg(not(any(bpass1,bpass4)))] #[rustc_clean( cfg = "bpass2", - except = "hir_owner, generics_of, type_of, predicates_of" + except = "hir_owner, generics_of, type_of, clauses_of" )] #[rustc_clean(cfg = "bpass3")] #[rustc_clean( cfg = "bpass5", - except = "hir_owner, generics_of, type_of, predicates_of" + except = "hir_owner, generics_of, type_of, clauses_of" )] #[rustc_clean(cfg = "bpass6")] pub fn type_parameter() {} @@ -168,7 +168,7 @@ pub fn lifetime_parameter<'a>() {} pub fn trait_bound() {} #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(cfg = "bpass2", except = "hir_owner, predicates_of")] +#[rustc_clean(cfg = "bpass2", except = "hir_owner, clauses_of")] #[rustc_clean(cfg = "bpass3")] pub fn trait_bound() {} @@ -178,9 +178,9 @@ pub fn trait_bound() {} pub fn builtin_bound() {} #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(cfg = "bpass2", except = "hir_owner, predicates_of")] +#[rustc_clean(cfg = "bpass2", except = "hir_owner, clauses_of")] #[rustc_clean(cfg = "bpass3")] -#[rustc_clean(cfg = "bpass5", except = "hir_owner, predicates_of")] +#[rustc_clean(cfg = "bpass5", except = "hir_owner, clauses_of")] #[rustc_clean(cfg = "bpass6")] pub fn builtin_bound() {} @@ -192,12 +192,12 @@ pub fn lifetime_bound<'a, T>() {} #[cfg(not(any(bpass1,bpass4)))] #[rustc_clean( cfg = "bpass2", - except = "hir_owner, generics_of, type_of, predicates_of,fn_sig" + except = "hir_owner, generics_of, type_of, clauses_of,fn_sig" )] #[rustc_clean(cfg = "bpass3")] #[rustc_clean( cfg = "bpass5", - except = "hir_owner, generics_of, type_of, predicates_of,fn_sig,optimized_mir" + except = "hir_owner, generics_of, type_of, clauses_of,fn_sig,optimized_mir" )] #[rustc_clean(cfg = "bpass6")] pub fn lifetime_bound<'a, T: 'a>() {} @@ -208,7 +208,7 @@ pub fn lifetime_bound<'a, T: 'a>() {} pub fn second_trait_bound() {} #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(cfg = "bpass2", except = "hir_owner, predicates_of")] +#[rustc_clean(cfg = "bpass2", except = "hir_owner, clauses_of")] #[rustc_clean(cfg = "bpass3")] pub fn second_trait_bound() {} @@ -220,7 +220,7 @@ pub fn second_builtin_bound() {} #[cfg(not(any(bpass1,bpass4)))] #[rustc_clean(cfg = "bpass2", except = "hir_owner")] #[rustc_clean(cfg = "bpass3")] -#[rustc_clean(cfg = "bpass5", except = "hir_owner, predicates_of")] +#[rustc_clean(cfg = "bpass5", except = "hir_owner, clauses_of")] #[rustc_clean(cfg = "bpass6")] pub fn second_builtin_bound() {} @@ -232,12 +232,12 @@ pub fn second_lifetime_bound<'a, 'b, T: 'a >() {} #[cfg(not(any(bpass1,bpass4)))] #[rustc_clean( cfg = "bpass2", - except = "hir_owner, generics_of, type_of, predicates_of,fn_sig" + except = "hir_owner, generics_of, type_of, clauses_of,fn_sig" )] #[rustc_clean(cfg = "bpass3")] #[rustc_clean( cfg = "bpass5", - except = "hir_owner, generics_of, type_of, predicates_of,fn_sig" + except = "hir_owner, generics_of, type_of, clauses_of,fn_sig" )] #[rustc_clean(cfg = "bpass6")] pub fn second_lifetime_bound<'a, 'b, T: 'a + 'b>() {} @@ -385,9 +385,9 @@ pub mod change_trait_bound_indirectly { #[cfg(not(any(bpass1,bpass4)))] use super::ReferencedTrait2 as Trait; - #[rustc_clean(cfg = "bpass2", except = "hir_owner, predicates_of")] + #[rustc_clean(cfg = "bpass2", except = "hir_owner, clauses_of")] #[rustc_clean(cfg = "bpass3")] - #[rustc_clean(cfg = "bpass5", except = "hir_owner, predicates_of")] + #[rustc_clean(cfg = "bpass5", except = "hir_owner, clauses_of")] #[rustc_clean(cfg = "bpass6")] pub fn indirect_trait_bound(p: T) {} } @@ -400,9 +400,9 @@ pub mod change_trait_bound_indirectly_in_where_clause { #[cfg(not(any(bpass1,bpass4)))] use super::ReferencedTrait2 as Trait; - #[rustc_clean(cfg = "bpass2", except = "hir_owner, predicates_of")] + #[rustc_clean(cfg = "bpass2", except = "hir_owner, clauses_of")] #[rustc_clean(cfg = "bpass3")] - #[rustc_clean(cfg = "bpass5", except = "hir_owner, predicates_of")] + #[rustc_clean(cfg = "bpass5", except = "hir_owner, clauses_of")] #[rustc_clean(cfg = "bpass6")] pub fn indirect_trait_bound_where(p: T) where diff --git a/tests/incremental/hashes/inherent_impls.rs b/tests/incremental/hashes/inherent_impls.rs index fa57fa4415fcf..e2261f779a2e8 100644 --- a/tests/incremental/hashes/inherent_impls.rs +++ b/tests/incremental/hashes/inherent_impls.rs @@ -466,12 +466,12 @@ impl Foo { // ------------------------------------------------- // ----------- // -------------- - // ---------------------------------------------------------------- + // ------------------------------------------------------------- // // ------------------------- // ----------- // -------------- - // ---------------------------------------------------------------- + // ------------------------------------------------------------- // // ------------------------- pub fn add_type_parameter_to_method (&self) { } @@ -494,12 +494,12 @@ impl Foo { // appear dirty, that might be the cause. -nmatsakis #[rustc_clean( cfg="bpass2", - except="hir_owner,generics_of,predicates_of,type_of", + except="hir_owner,generics_of,clauses_of,type_of", )] #[rustc_clean(cfg="bpass3")] #[rustc_clean( cfg="bpass5", - except="hir_owner,generics_of,predicates_of,type_of", + except="hir_owner,generics_of,clauses_of,type_of", )] #[rustc_clean(cfg="bpass6")] pub fn add_type_parameter_to_method(&self) { } @@ -512,12 +512,12 @@ impl Foo { impl Foo { //------------ //--------------- - //----------------------------------------------------------------------- + //-------------------------------------------------------------------- // //-------------------------- //------------ //--------------- - //----------------------------------------------------------------------- + //-------------------------------------------------------------------- // //-------------------------- pub fn add_lifetime_bound_to_lifetime_param_of_method<'a, 'b >(&self) { } @@ -531,12 +531,12 @@ impl Foo { impl Foo { #[rustc_clean( cfg="bpass2", - except="hir_owner,generics_of,predicates_of,type_of,fn_sig" + except="hir_owner,generics_of,clauses_of,type_of,fn_sig" )] #[rustc_clean(cfg="bpass3")] #[rustc_clean( cfg="bpass5", - except="hir_owner,generics_of,predicates_of,type_of,fn_sig" + except="hir_owner,generics_of,clauses_of,type_of,fn_sig" )] #[rustc_clean(cfg="bpass6")] pub fn add_lifetime_bound_to_lifetime_param_of_method<'a, 'b: 'a>(&self) { } @@ -558,12 +558,12 @@ impl Foo { // ------------------------------------------------- // ----------- // -------------- - // ---------------------------------------------------------------------- + // ------------------------------------------------------------------- // // ------------------------- // ----------- // -------------- - // ---------------------------------------------------------------------- + // ------------------------------------------------------------------- // // ------------------------- pub fn add_lifetime_bound_to_type_param_of_method<'a, T >(&self) { } @@ -586,12 +586,12 @@ impl Foo { // appear dirty, that might be the cause. -nmatsakis #[rustc_clean( cfg="bpass2", - except="hir_owner,generics_of,predicates_of,type_of,fn_sig" + except="hir_owner,generics_of,clauses_of,type_of,fn_sig" )] #[rustc_clean(cfg="bpass3")] #[rustc_clean( cfg="bpass5", - except="hir_owner,generics_of,predicates_of,type_of,fn_sig" + except="hir_owner,generics_of,clauses_of,type_of,fn_sig" )] #[rustc_clean(cfg="bpass6")] pub fn add_lifetime_bound_to_type_param_of_method<'a, T: 'a>(&self) { } @@ -611,9 +611,9 @@ impl Foo { // ------------------------------------------------------------ // ------------------------------------------------------ // ------------------------------------------------- - // --------------------------------------------------------------------- + // ------------------------------------------------------------------ // ------------------------- - // --------------------------------------------------------------------- + // ------------------------------------------------------------------ // ------------------------- pub fn add_trait_bound_to_type_param_of_method(&self) { } } @@ -633,9 +633,9 @@ impl Foo { // generics before the body, then the `HirId` for things in the // body will be affected. So if you start to see `typeck_root` // appear dirty, that might be the cause. -nmatsakis - #[rustc_clean(cfg="bpass2", except="hir_owner,predicates_of")] + #[rustc_clean(cfg="bpass2", except="hir_owner,clauses_of")] #[rustc_clean(cfg="bpass3")] - #[rustc_clean(cfg="bpass5", except="hir_owner,predicates_of")] + #[rustc_clean(cfg="bpass5", except="hir_owner,clauses_of")] #[rustc_clean(cfg="bpass6")] pub fn add_trait_bound_to_type_param_of_method(&self) { } } diff --git a/tests/incremental/hashes/struct_defs.rs b/tests/incremental/hashes/struct_defs.rs index f3e6a62294619..a1fd82fca2f27 100644 --- a/tests/incremental/hashes/struct_defs.rs +++ b/tests/incremental/hashes/struct_defs.rs @@ -169,9 +169,9 @@ struct AddLifetimeParameter<'a, 'b>(&'a f32, &'b f64); struct AddLifetimeParameterBound<'a, 'b>(&'a f32, &'b f64); #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass2")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] struct AddLifetimeParameterBound<'a, 'b: 'a>( &'a f32, @@ -182,9 +182,9 @@ struct AddLifetimeParameterBound<'a, 'b: 'a>( struct AddLifetimeParameterBoundWhereClause<'a, 'b>(&'a f32, &'b f64); #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass2")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] struct AddLifetimeParameterBoundWhereClause<'a, 'b>( &'a f32, @@ -198,9 +198,9 @@ struct AddLifetimeParameterBoundWhereClause<'a, 'b>( struct AddTypeParameter(T1, T1); #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(except="hir_owner,type_of,generics_of,predicates_of", cfg="bpass2")] +#[rustc_clean(except="hir_owner,type_of,generics_of,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,type_of,generics_of,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,type_of,generics_of,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] struct AddTypeParameter( // The field contains the parent's Generics, so it's dirty even though its @@ -216,9 +216,9 @@ struct AddTypeParameter( struct AddTypeParameterBound(T); #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass2")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] struct AddTypeParameterBound( T @@ -229,9 +229,9 @@ struct AddTypeParameterBound( struct AddTypeParameterBoundWhereClause(T); #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass2")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] struct AddTypeParameterBoundWhereClause( T @@ -311,9 +311,9 @@ mod change_trait_bound_indirectly { #[cfg(not(any(bpass1,bpass4)))] use super::ReferencedTrait2 as Trait; - #[rustc_clean(except="hir_owner,predicates_of", cfg="bpass2")] + #[rustc_clean(except="hir_owner,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] - #[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] + #[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] struct Struct(T); } @@ -325,9 +325,9 @@ mod change_trait_bound_indirectly_in_where_clause { #[cfg(not(any(bpass1,bpass4)))] use super::ReferencedTrait2 as Trait; - #[rustc_clean(except="hir_owner,predicates_of", cfg="bpass2")] + #[rustc_clean(except="hir_owner,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] - #[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] + #[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] struct Struct(T) where T : Trait; } diff --git a/tests/incremental/hashes/trait_defs.rs b/tests/incremental/hashes/trait_defs.rs index e45f6654c3962..f9c1be94d5e30 100644 --- a/tests/incremental/hashes/trait_defs.rs +++ b/tests/incremental/hashes/trait_defs.rs @@ -31,7 +31,7 @@ trait TraitVisibility { } #[cfg(not(any(bpass1,bpass4)))] #[rustc_clean(cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(cfg="bpass5", except="hir_owner,predicates_of")] +#[rustc_clean(cfg="bpass5", except="hir_owner,clauses_of")] #[rustc_clean(cfg="bpass6")] pub trait TraitVisibility { } @@ -44,7 +44,7 @@ trait TraitUnsafety { } #[cfg(not(any(bpass1,bpass4)))] #[rustc_clean(except="hir_owner", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] unsafe trait TraitUnsafety { } @@ -58,7 +58,7 @@ trait TraitAddMethod { #[cfg(not(any(bpass1,bpass4)))] #[rustc_clean(except="hir_owner,associated_item_def_ids", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,associated_item_def_ids,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,associated_item_def_ids,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] pub trait TraitAddMethod { fn method(); @@ -75,7 +75,7 @@ trait TraitChangeMethodName { #[cfg(not(any(bpass1,bpass4)))] #[rustc_clean(except="hir_owner,associated_item_def_ids", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,associated_item_def_ids,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,associated_item_def_ids,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitChangeMethodName { fn methodChanged(); @@ -96,7 +96,7 @@ trait TraitAddReturnType { #[cfg(not(any(bpass1,bpass4)))] #[rustc_clean(cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddReturnType { #[rustc_clean(except="hir_owner,fn_sig", cfg="bpass2")] @@ -121,7 +121,7 @@ trait TraitChangeReturnType { #[cfg(not(any(bpass1,bpass4)))] #[rustc_clean(cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitChangeReturnType { #[rustc_clean(except="hir_owner,fn_sig", cfg="bpass2")] @@ -146,7 +146,7 @@ trait TraitAddParameterToMethod { #[cfg(not(any(bpass1,bpass4)))] #[rustc_clean(cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddParameterToMethod { #[rustc_clean(except="hir_owner,fn_sig", cfg="bpass2")] @@ -178,7 +178,7 @@ trait TraitChangeMethodParameterName { #[cfg(not(any(bpass1,bpass4)))] #[rustc_clean(cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitChangeMethodParameterName { // FIXME(#38501) This should preferably always be clean. @@ -210,7 +210,7 @@ trait TraitChangeMethodParameterType { #[cfg(not(any(bpass1,bpass4)))] #[rustc_clean(cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitChangeMethodParameterType { #[rustc_clean(except="hir_owner,fn_sig", cfg="bpass2")] @@ -235,7 +235,7 @@ trait TraitChangeMethodParameterTypeRef { #[cfg(not(any(bpass1,bpass4)))] #[rustc_clean(cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitChangeMethodParameterTypeRef { #[rustc_clean(except="hir_owner,fn_sig", cfg="bpass2")] @@ -260,7 +260,7 @@ trait TraitChangeMethodParametersOrder { #[cfg(not(any(bpass1,bpass4)))] #[rustc_clean(cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitChangeMethodParametersOrder { #[rustc_clean(except="hir_owner,fn_sig", cfg="bpass2")] @@ -285,7 +285,7 @@ trait TraitAddMethodAutoImplementation { #[cfg(not(any(bpass1,bpass4)))] #[rustc_clean(cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddMethodAutoImplementation { #[rustc_clean(except="hir_owner", cfg="bpass2")] @@ -329,7 +329,7 @@ trait TraitChangeModeSelfRefToMut { #[cfg(not(any(bpass1,bpass4)))] #[rustc_clean(cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitChangeModeSelfRefToMut { #[rustc_clean(except="hir_owner,fn_sig", cfg="bpass2")] @@ -377,7 +377,7 @@ trait TraitChangeModeSelfOwnToRef { #[cfg(not(any(bpass1,bpass4)))] #[rustc_clean(cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitChangeModeSelfOwnToRef { #[rustc_clean(except="hir_owner,fn_sig,type_of,generics_of", cfg="bpass2")] @@ -402,7 +402,7 @@ trait TraitAddUnsafeModifier { #[cfg(not(any(bpass1,bpass4)))] #[rustc_clean(cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddUnsafeModifier { #[rustc_clean(except="hir_owner,fn_sig", cfg="bpass2")] @@ -427,7 +427,7 @@ trait TraitAddExternModifier { #[cfg(not(any(bpass1,bpass4)))] #[rustc_clean(cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddExternModifier { #[rustc_clean(except="hir_owner,fn_sig", cfg="bpass2")] @@ -452,7 +452,7 @@ trait TraitChangeExternCToExternSystem { #[cfg(not(any(bpass1,bpass4)))] #[rustc_clean(cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitChangeExternCToRustIntrinsic { #[rustc_clean(except="hir_owner,fn_sig", cfg="bpass2")] @@ -467,10 +467,10 @@ trait TraitChangeExternCToRustIntrinsic { // Add type parameter to method #[cfg(any(bpass1,bpass4))] trait TraitAddTypeParameterToMethod { - // -------------------------------------------------------------------------- + // ----------------------------------------------------------------------- // --------------- // ------------------------- - // -------------------------------------------------------------------------- + // ----------------------------------------------------------------------- // --------------- // ------------------------- fn method (); @@ -479,13 +479,13 @@ trait TraitAddTypeParameterToMethod { #[cfg(not(any(bpass1,bpass4)))] #[rustc_clean(cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddTypeParameterToMethod { - #[rustc_clean(except="hir_owner,generics_of,predicates_of,type_of", + #[rustc_clean(except="hir_owner,generics_of,clauses_of,type_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] - #[rustc_clean(except="hir_owner,generics_of,predicates_of,type_of", + #[rustc_clean(except="hir_owner,generics_of,clauses_of,type_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] fn method(); @@ -506,7 +506,7 @@ trait TraitAddLifetimeParameterToMethod { #[cfg(not(any(bpass1,bpass4)))] #[rustc_clean(cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddLifetimeParameterToMethod { #[rustc_clean(except="hir_owner,fn_sig,type_of,generics_of", cfg="bpass2")] @@ -525,9 +525,9 @@ trait ReferencedTrait1 { } // Add trait bound to method type parameter #[cfg(any(bpass1,bpass4))] trait TraitAddTraitBoundToMethodTypeParameter { - // --------------------------------------------------------------------- + // ------------------------------------------------------------------ // ------------------------- - // --------------------------------------------------------------------- + // ------------------------------------------------------------------ // ------------------------- fn method(); } @@ -535,12 +535,12 @@ trait TraitAddTraitBoundToMethodTypeParameter { #[cfg(not(any(bpass1,bpass4)))] #[rustc_clean(cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddTraitBoundToMethodTypeParameter { - #[rustc_clean(except="hir_owner,predicates_of", cfg="bpass2")] + #[rustc_clean(except="hir_owner,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] - #[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] + #[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] fn method(); } @@ -552,7 +552,7 @@ trait TraitAddTraitBoundToMethodTypeParameter { trait TraitAddBuiltinBoundToMethodTypeParameter { // --------------------------------------------------------------------- // ------------------------- - // --------------------------------------------------------------------- + // ------------------------------------------------------------------ // ------------------------- fn method(); } @@ -560,12 +560,12 @@ trait TraitAddBuiltinBoundToMethodTypeParameter { #[cfg(not(any(bpass1,bpass4)))] #[rustc_clean(cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddBuiltinBoundToMethodTypeParameter { #[rustc_clean(except="hir_owner", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] - #[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] + #[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] fn method(); } @@ -576,12 +576,12 @@ trait TraitAddBuiltinBoundToMethodTypeParameter { #[cfg(any(bpass1,bpass4))] trait TraitAddLifetimeBoundToMethodLifetimeParameter { // ----------- - // ----------------------------------------------------------------------- + // -------------------------------------------------------------------- // -------------- // // ------------------------- // ----------- - // ----------------------------------------------------------------------- + // -------------------------------------------------------------------- // -------------- // // ------------------------- @@ -591,16 +591,16 @@ trait TraitAddLifetimeBoundToMethodLifetimeParameter { #[cfg(not(any(bpass1,bpass4)))] #[rustc_clean(cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddLifetimeBoundToMethodLifetimeParameter { #[rustc_clean( - except="hir_owner,generics_of,predicates_of,fn_sig,type_of", + except="hir_owner,generics_of,clauses_of,fn_sig,type_of", cfg="bpass2", )] #[rustc_clean(cfg="bpass3")] #[rustc_clean( - except="hir_owner,generics_of,predicates_of,fn_sig,type_of", + except="hir_owner,generics_of,clauses_of,fn_sig,type_of", cfg="bpass5", )] #[rustc_clean(cfg="bpass6")] @@ -612,9 +612,9 @@ trait TraitAddLifetimeBoundToMethodLifetimeParameter { // Add second trait bound to method type parameter #[cfg(any(bpass1,bpass4))] trait TraitAddSecondTraitBoundToMethodTypeParameter { - // --------------------------------------------------------------------- + // ------------------------------------------------------------------ // ------------------------- - // --------------------------------------------------------------------- + // ------------------------------------------------------------------ // ------------------------- fn method(); } @@ -622,12 +622,12 @@ trait TraitAddSecondTraitBoundToMethodTypeParameter { #[cfg(not(any(bpass1,bpass4)))] #[rustc_clean(cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddSecondTraitBoundToMethodTypeParameter { - #[rustc_clean(except="hir_owner,predicates_of", cfg="bpass2")] + #[rustc_clean(except="hir_owner,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] - #[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] + #[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] fn method(); } @@ -637,9 +637,9 @@ trait TraitAddSecondTraitBoundToMethodTypeParameter { // Add second builtin bound to method type parameter #[cfg(any(bpass1,bpass4))] trait TraitAddSecondBuiltinBoundToMethodTypeParameter { - // --------------------------------------------------------------------- + // ------------------------------------------------------------------ // ------------------------- - // --------------------------------------------------------------------- + // ------------------------------------------------------------------ // ------------------------- fn method(); } @@ -647,12 +647,12 @@ trait TraitAddSecondBuiltinBoundToMethodTypeParameter { #[cfg(not(any(bpass1,bpass4)))] #[rustc_clean(cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddSecondBuiltinBoundToMethodTypeParameter { - #[rustc_clean(except="hir_owner,predicates_of", cfg="bpass2")] + #[rustc_clean(except="hir_owner,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] - #[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] + #[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] fn method(); } @@ -663,12 +663,12 @@ trait TraitAddSecondBuiltinBoundToMethodTypeParameter { #[cfg(any(bpass1,bpass4))] trait TraitAddSecondLifetimeBoundToMethodLifetimeParameter { // ----------- - // ----------------------------------------------------------------------- + // -------------------------------------------------------------------- // -------------- // // ------------------------- // ----------- - // ----------------------------------------------------------------------- + // -------------------------------------------------------------------- // -------------- // // ------------------------- @@ -678,16 +678,16 @@ trait TraitAddSecondLifetimeBoundToMethodLifetimeParameter { #[cfg(not(any(bpass1,bpass4)))] #[rustc_clean(cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddSecondLifetimeBoundToMethodLifetimeParameter { #[rustc_clean( - except="hir_owner,generics_of,predicates_of,fn_sig,type_of", + except="hir_owner,generics_of,clauses_of,fn_sig,type_of", cfg="bpass2", )] #[rustc_clean(cfg="bpass3")] #[rustc_clean( - except="hir_owner,generics_of,predicates_of,fn_sig,type_of", + except="hir_owner,generics_of,clauses_of,fn_sig,type_of", cfg="bpass5", )] #[rustc_clean(cfg="bpass6")] @@ -747,7 +747,7 @@ trait TraitAddTraitBoundToAssociatedType { #[cfg(not(any(bpass1,bpass4)))] #[rustc_clean(cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddTraitBoundToAssociatedType { #[rustc_clean(except="hir_owner", cfg="bpass2")] @@ -776,7 +776,7 @@ trait TraitAddLifetimeBoundToAssociatedType<'a> { #[cfg(not(any(bpass1,bpass4)))] #[rustc_clean(cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddLifetimeBoundToAssociatedType<'a> { #[rustc_clean(except="hir_owner", cfg="bpass2")] @@ -805,7 +805,7 @@ trait TraitAddDefaultToAssociatedType { #[cfg(not(any(bpass1,bpass4)))] #[rustc_clean(cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddDefaultToAssociatedType { #[rustc_clean(except="hir_owner", cfg="bpass2")] @@ -828,7 +828,7 @@ trait TraitAddAssociatedConstant { #[cfg(not(any(bpass1,bpass4)))] #[rustc_clean(except="hir_owner,associated_item_def_ids", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,associated_item_def_ids,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,associated_item_def_ids,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddAssociatedConstant { const Value: u32; @@ -857,7 +857,7 @@ trait TraitAddInitializerToAssociatedConstant { #[cfg(not(any(bpass1,bpass4)))] #[rustc_clean(cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddInitializerToAssociatedConstant { #[rustc_clean(except="hir_owner", cfg="bpass2")] @@ -894,7 +894,7 @@ trait TraitChangeTypeOfAssociatedConstant { #[cfg(not(any(bpass1,bpass4)))] #[rustc_clean(cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitChangeTypeOfAssociatedConstant { #[rustc_clean(except="hir_owner,type_of", cfg="bpass2")] @@ -917,9 +917,9 @@ trait TraitChangeTypeOfAssociatedConstant { trait TraitAddSuperTrait { } #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass2")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddSuperTrait : ReferencedTrait0 { } @@ -930,9 +930,9 @@ trait TraitAddSuperTrait : ReferencedTrait0 { } trait TraitAddBuiltiBound { } #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass2")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddBuiltiBound : Send { } @@ -943,9 +943,9 @@ trait TraitAddBuiltiBound : Send { } trait TraitAddStaticLifetimeBound { } #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass2")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddStaticLifetimeBound : 'static { } @@ -956,9 +956,9 @@ trait TraitAddStaticLifetimeBound : 'static { } trait TraitAddTraitAsSecondBound : ReferencedTrait0 { } #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass2")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddTraitAsSecondBound : ReferencedTrait0 + ReferencedTrait1 { } @@ -966,9 +966,9 @@ trait TraitAddTraitAsSecondBound : ReferencedTrait0 + ReferencedTrait1 { } trait TraitAddTraitAsSecondBoundFromBuiltin : Send { } #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass2")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddTraitAsSecondBoundFromBuiltin : Send + ReferencedTrait0 { } @@ -979,9 +979,9 @@ trait TraitAddTraitAsSecondBoundFromBuiltin : Send + ReferencedTrait0 { } trait TraitAddBuiltinBoundAsSecondBound : ReferencedTrait0 { } #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass2")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddBuiltinBoundAsSecondBound : ReferencedTrait0 + Send { } @@ -989,9 +989,9 @@ trait TraitAddBuiltinBoundAsSecondBound : ReferencedTrait0 + Send { } trait TraitAddBuiltinBoundAsSecondBoundFromBuiltin : Send { } #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass2")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddBuiltinBoundAsSecondBoundFromBuiltin: Send + Copy { } @@ -1002,9 +1002,9 @@ trait TraitAddBuiltinBoundAsSecondBoundFromBuiltin: Send + Copy { } trait TraitAddStaticBoundAsSecondBound : ReferencedTrait0 { } #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass2")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddStaticBoundAsSecondBound : ReferencedTrait0 + 'static { } @@ -1012,9 +1012,9 @@ trait TraitAddStaticBoundAsSecondBound : ReferencedTrait0 + 'static { } trait TraitAddStaticBoundAsSecondBoundFromBuiltin : Send { } #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass2")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddStaticBoundAsSecondBoundFromBuiltin : Send + 'static { } @@ -1025,9 +1025,9 @@ trait TraitAddStaticBoundAsSecondBoundFromBuiltin : Send + 'static { } trait TraitAddTypeParameterToTrait { } #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(except="hir_owner,generics_of,predicates_of", cfg="bpass2")] +#[rustc_clean(except="hir_owner,generics_of,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,generics_of,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,generics_of,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddTypeParameterToTrait { } @@ -1038,9 +1038,9 @@ trait TraitAddTypeParameterToTrait { } trait TraitAddLifetimeParameterToTrait { } #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(except="hir_owner,generics_of,predicates_of", cfg="bpass2")] +#[rustc_clean(except="hir_owner,generics_of,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,generics_of,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,generics_of,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddLifetimeParameterToTrait<'a> { } @@ -1051,9 +1051,9 @@ trait TraitAddLifetimeParameterToTrait<'a> { } trait TraitAddTraitBoundToTypeParameterOfTrait { } #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass2")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddTraitBoundToTypeParameterOfTrait { } @@ -1064,9 +1064,9 @@ trait TraitAddTraitBoundToTypeParameterOfTrait { } trait TraitAddLifetimeBoundToTypeParameterOfTrait<'a, T> { } #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass2")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddLifetimeBoundToTypeParameterOfTrait<'a, T: 'a> { } @@ -1077,9 +1077,9 @@ trait TraitAddLifetimeBoundToTypeParameterOfTrait<'a, T: 'a> { } trait TraitAddLifetimeBoundToLifetimeParameterOfTrait<'a, 'b> { } #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass2")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddLifetimeBoundToLifetimeParameterOfTrait<'a: 'b, 'b> { } @@ -1090,9 +1090,9 @@ trait TraitAddLifetimeBoundToLifetimeParameterOfTrait<'a: 'b, 'b> { } trait TraitAddBuiltinBoundToTypeParameterOfTrait { } #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass2")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddBuiltinBoundToTypeParameterOfTrait { } @@ -1103,9 +1103,9 @@ trait TraitAddBuiltinBoundToTypeParameterOfTrait { } trait TraitAddSecondTypeParameterToTrait { } #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(except="hir_owner,generics_of,predicates_of", cfg="bpass2")] +#[rustc_clean(except="hir_owner,generics_of,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,generics_of,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,generics_of,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddSecondTypeParameterToTrait { } @@ -1116,9 +1116,9 @@ trait TraitAddSecondTypeParameterToTrait { } trait TraitAddSecondLifetimeParameterToTrait<'a> { } #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(except="hir_owner,generics_of,predicates_of", cfg="bpass2")] +#[rustc_clean(except="hir_owner,generics_of,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,generics_of,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,generics_of,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddSecondLifetimeParameterToTrait<'a, 'b> { } @@ -1129,9 +1129,9 @@ trait TraitAddSecondLifetimeParameterToTrait<'a, 'b> { } trait TraitAddSecondTraitBoundToTypeParameterOfTrait { } #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass2")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddSecondTraitBoundToTypeParameterOfTrait { } @@ -1142,9 +1142,9 @@ trait TraitAddSecondTraitBoundToTypeParameterOfTrait { } #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass2")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddSecondLifetimeBoundToTypeParameterOfTrait<'a, 'b, T: 'a + 'b> { } @@ -1155,9 +1155,9 @@ trait TraitAddSecondLifetimeBoundToTypeParameterOfTrait<'a, 'b, T: 'a + 'b> { } trait TraitAddSecondLifetimeBoundToLifetimeParameterOfTrait<'a: 'b, 'b, 'c> { } #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass2")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddSecondLifetimeBoundToLifetimeParameterOfTrait<'a: 'b + 'c, 'b, 'c> { } @@ -1168,9 +1168,9 @@ trait TraitAddSecondLifetimeBoundToLifetimeParameterOfTrait<'a: 'b + 'c, 'b, 'c> trait TraitAddSecondBuiltinBoundToTypeParameterOfTrait { } #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass2")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddSecondBuiltinBoundToTypeParameterOfTrait { } @@ -1186,9 +1186,9 @@ struct ReferenceType1 {} trait TraitAddTraitBoundToTypeParameterOfTraitWhere { } #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass2")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddTraitBoundToTypeParameterOfTraitWhere where T: ReferencedTrait0 { } @@ -1199,9 +1199,9 @@ trait TraitAddTraitBoundToTypeParameterOfTraitWhere where T: ReferencedTrait0 trait TraitAddLifetimeBoundToTypeParameterOfTraitWhere<'a, T> { } #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass2")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddLifetimeBoundToTypeParameterOfTraitWhere<'a, T> where T: 'a { } @@ -1212,9 +1212,9 @@ trait TraitAddLifetimeBoundToTypeParameterOfTraitWhere<'a, T> where T: 'a { } trait TraitAddLifetimeBoundToLifetimeParameterOfTraitWhere<'a, 'b> { } #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass2")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddLifetimeBoundToLifetimeParameterOfTraitWhere<'a, 'b> where 'a: 'b { } @@ -1225,9 +1225,9 @@ trait TraitAddLifetimeBoundToLifetimeParameterOfTraitWhere<'a, 'b> where 'a: 'b trait TraitAddBuiltinBoundToTypeParameterOfTraitWhere { } #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass2")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddBuiltinBoundToTypeParameterOfTraitWhere where T: Send { } @@ -1238,9 +1238,9 @@ trait TraitAddBuiltinBoundToTypeParameterOfTraitWhere where T: Send { } trait TraitAddSecondTraitBoundToTypeParameterOfTraitWhere where T: ReferencedTrait0 { } #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass2")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddSecondTraitBoundToTypeParameterOfTraitWhere where T: ReferencedTrait0 + ReferencedTrait1 { } @@ -1252,9 +1252,9 @@ trait TraitAddSecondTraitBoundToTypeParameterOfTraitWhere trait TraitAddSecondLifetimeBoundToTypeParameterOfTraitWhere<'a, 'b, T> where T: 'a { } #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass2")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddSecondLifetimeBoundToTypeParameterOfTraitWhere<'a, 'b, T> where T: 'a + 'b { } @@ -1265,9 +1265,9 @@ trait TraitAddSecondLifetimeBoundToTypeParameterOfTraitWhere<'a, 'b, T> where T: trait TraitAddSecondLifetimeBoundToLifetimeParameterOfTraitWhere<'a, 'b, 'c> where 'a: 'b { } #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass2")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddSecondLifetimeBoundToLifetimeParameterOfTraitWhere<'a, 'b, 'c> where 'a: 'b + 'c { } @@ -1278,9 +1278,9 @@ trait TraitAddSecondLifetimeBoundToLifetimeParameterOfTraitWhere<'a, 'b, 'c> whe trait TraitAddSecondBuiltinBoundToTypeParameterOfTraitWhere where T: Send { } #[cfg(not(any(bpass1,bpass4)))] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass2")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitAddSecondBuiltinBoundToTypeParameterOfTraitWhere where T: Send + Sync { } @@ -1341,9 +1341,9 @@ mod change_method_parameter_type_bound_indirectly_by_use { #[rustc_clean(cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitChangeBoundOfMethodTypeParameter { - #[rustc_clean(except="hir_owner,predicates_of", cfg="bpass2")] + #[rustc_clean(except="hir_owner,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] - #[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] + #[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] fn method(a: T); } @@ -1364,9 +1364,9 @@ mod change_method_parameter_type_bound_indirectly_by_use_where { #[rustc_clean(cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitChangeBoundOfMethodTypeParameterWhere { - #[rustc_clean(except="hir_owner,predicates_of", cfg="bpass2")] + #[rustc_clean(except="hir_owner,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] - #[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] + #[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] fn method(a: T) where T: Bound; } @@ -1381,9 +1381,9 @@ mod change_method_type_parameter_bound_indirectly { #[cfg(not(any(bpass1,bpass4)))] use super::ReferencedTrait1 as Bound; - #[rustc_clean(except="hir_owner,predicates_of", cfg="bpass2")] + #[rustc_clean(except="hir_owner,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] - #[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] + #[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitChangeTraitBound { fn method(a: T); @@ -1400,9 +1400,9 @@ mod change_method_type_parameter_bound_indirectly_where { #[cfg(not(any(bpass1,bpass4)))] use super::ReferencedTrait1 as Bound; - #[rustc_clean(except="hir_owner,predicates_of", cfg="bpass2")] + #[rustc_clean(except="hir_owner,clauses_of", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] - #[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] + #[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] trait TraitChangeTraitBoundWhere where T: Bound { fn method(a: T); diff --git a/tests/incremental/hashes/trait_impls.rs b/tests/incremental/hashes/trait_impls.rs index 9c773b2920e98..9698ec0473c4b 100644 --- a/tests/incremental/hashes/trait_impls.rs +++ b/tests/incremental/hashes/trait_impls.rs @@ -35,7 +35,7 @@ impl ChangeMethodNameTrait for Foo { #[cfg(not(any(bpass1,bpass4)))] #[rustc_clean(except="hir_owner,associated_item_def_ids", cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,associated_item_def_ids,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,associated_item_def_ids,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] pub trait ChangeMethodNameTrait { #[rustc_clean(cfg="bpass3")] @@ -333,7 +333,7 @@ impl ChangeHasValueTrait for Foo { #[cfg(not(any(bpass1,bpass4)))] #[rustc_clean(cfg="bpass2")] #[rustc_clean(cfg="bpass3")] -#[rustc_clean(except="hir_owner,predicates_of", cfg="bpass5")] +#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")] #[rustc_clean(cfg="bpass6")] pub trait ChangeHasValueTrait { #[rustc_clean(except="hir_owner", cfg="bpass2")] diff --git a/tests/mir-opt/impossible_predicates.impossible_predicate.ImpossiblePredicates.diff b/tests/mir-opt/impossible_clauses.impossible_clause.ImpossibleClauses.diff similarity index 74% rename from tests/mir-opt/impossible_predicates.impossible_predicate.ImpossiblePredicates.diff rename to tests/mir-opt/impossible_clauses.impossible_clause.ImpossibleClauses.diff index 46d1ca7464cdc..fb75249af3dc2 100644 --- a/tests/mir-opt/impossible_predicates.impossible_predicate.ImpossiblePredicates.diff +++ b/tests/mir-opt/impossible_clauses.impossible_clause.ImpossibleClauses.diff @@ -1,7 +1,7 @@ -- // MIR for `impossible_predicate` before ImpossiblePredicates -+ // MIR for `impossible_predicate` after ImpossiblePredicates +- // MIR for `impossible_clause` before ImpossibleClauses ++ // MIR for `impossible_clause` after ImpossibleClauses - fn impossible_predicate(_1: &mut i32) -> (&mut i32, &mut i32) { + fn impossible_clause(_1: &mut i32) -> (&mut i32, &mut i32) { - debug x => _1; let mut _0: (&mut i32, &mut i32); - let _2: &mut i32; diff --git a/tests/mir-opt/impossible_clauses.rs b/tests/mir-opt/impossible_clauses.rs new file mode 100644 index 0000000000000..24684a83027a7 --- /dev/null +++ b/tests/mir-opt/impossible_clauses.rs @@ -0,0 +1,10 @@ +//@ skip-filecheck +// EMIT_MIR impossible_clauses.impossible_clause.ImpossibleClauses.diff + +pub fn impossible_clause(x: &mut i32) -> (&mut i32, &mut i32) +where + for<'a> &'a mut i32: Copy, +{ + let y = x; + (y, x) +} diff --git a/tests/mir-opt/impossible_predicates.rs b/tests/mir-opt/impossible_predicates.rs deleted file mode 100644 index 3858bb657635d..0000000000000 --- a/tests/mir-opt/impossible_predicates.rs +++ /dev/null @@ -1,10 +0,0 @@ -//@ skip-filecheck -// EMIT_MIR impossible_predicates.impossible_predicate.ImpossiblePredicates.diff - -pub fn impossible_predicate(x: &mut i32) -> (&mut i32, &mut i32) -where - for<'a> &'a mut i32: Copy, -{ - let y = x; - (y, x) -} diff --git a/tests/ui/associated-type-bounds/ambiguous-associated-type2.stderr b/tests/ui/associated-type-bounds/ambiguous-associated-type2.stderr index 166bdc988f947..6afa00c7c74e9 100644 --- a/tests/ui/associated-type-bounds/ambiguous-associated-type2.stderr +++ b/tests/ui/associated-type-bounds/ambiguous-associated-type2.stderr @@ -5,7 +5,7 @@ LL | trait Baz: Foo + Bar {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: ...which immediately requires computing the super traits of `Baz` with associated type name `Item` again - = note: cycle used when computing the super predicates of `Baz` + = note: cycle used when computing the super clauses of `Baz` = note: for more information, see and error: aborting due to 1 previous error diff --git a/tests/ui/associated-type-bounds/implied-bounds-cycle.rs b/tests/ui/associated-type-bounds/implied-bounds-cycle.rs index 8f2bec889eac5..620999d33e8de 100644 --- a/tests/ui/associated-type-bounds/implied-bounds-cycle.rs +++ b/tests/ui/associated-type-bounds/implied-bounds-cycle.rs @@ -3,6 +3,6 @@ trait A { } trait B: A {} -//~^ ERROR cycle detected when computing the implied predicates of `B` +//~^ ERROR cycle detected when computing the implied clauses of `B` fn main() {} diff --git a/tests/ui/associated-type-bounds/implied-bounds-cycle.stderr b/tests/ui/associated-type-bounds/implied-bounds-cycle.stderr index b794a4ec01d4d..125739f275e98 100644 --- a/tests/ui/associated-type-bounds/implied-bounds-cycle.stderr +++ b/tests/ui/associated-type-bounds/implied-bounds-cycle.stderr @@ -1,10 +1,10 @@ -error[E0391]: cycle detected when computing the implied predicates of `B` +error[E0391]: cycle detected when computing the implied clauses of `B` --> $DIR/implied-bounds-cycle.rs:5:15 | LL | trait B: A {} | ^ | - = note: ...which immediately requires computing the implied predicates of `B` again + = note: ...which immediately requires computing the implied clauses of `B` again note: cycle used when computing normalized predicates of `B` --> $DIR/implied-bounds-cycle.rs:5:1 | diff --git a/tests/ui/associated-types/issue-20825.stderr b/tests/ui/associated-types/issue-20825.stderr index a833c5f69f906..dcf0b26cf15ad 100644 --- a/tests/ui/associated-types/issue-20825.stderr +++ b/tests/ui/associated-types/issue-20825.stderr @@ -5,7 +5,7 @@ LL | pub trait Processor: Subscriber { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: ...which immediately requires computing the super traits of `Processor` with associated type name `Input` again - = note: cycle used when computing the super predicates of `Processor` + = note: cycle used when computing the super clauses of `Processor` = note: for more information, see and error: aborting due to 1 previous error diff --git a/tests/ui/cycle-trait/cycle-trait-supertrait-direct.stderr b/tests/ui/cycle-trait/cycle-trait-supertrait-direct.stderr index afb12aaad832c..b639d45dc157d 100644 --- a/tests/ui/cycle-trait/cycle-trait-supertrait-direct.stderr +++ b/tests/ui/cycle-trait/cycle-trait-supertrait-direct.stderr @@ -1,10 +1,10 @@ -error[E0391]: cycle detected when computing the super predicates of `Chromosome` +error[E0391]: cycle detected when computing the super clauses of `Chromosome` --> $DIR/cycle-trait-supertrait-direct.rs:3:19 | LL | trait Chromosome: Chromosome { | ^^^^^^^^^^ | - = note: ...which immediately requires computing the super predicates of `Chromosome` again + = note: ...which immediately requires computing the super clauses of `Chromosome` again note: cycle used when checking that `Chromosome` is well-formed --> $DIR/cycle-trait-supertrait-direct.rs:3:1 | diff --git a/tests/ui/cycle-trait/cycle-trait-supertrait-indirect.stderr b/tests/ui/cycle-trait/cycle-trait-supertrait-indirect.stderr index 233961858d142..ec9c77568b827 100644 --- a/tests/ui/cycle-trait/cycle-trait-supertrait-indirect.stderr +++ b/tests/ui/cycle-trait/cycle-trait-supertrait-indirect.stderr @@ -1,16 +1,16 @@ -error[E0391]: cycle detected when computing the super predicates of `B` +error[E0391]: cycle detected when computing the super clauses of `B` --> $DIR/cycle-trait-supertrait-indirect.rs:7:10 | LL | trait B: C { | ^ | -note: ...which requires computing the super predicates of `C`... +note: ...which requires computing the super clauses of `C`... --> $DIR/cycle-trait-supertrait-indirect.rs:11:10 | LL | trait C: B { } | ^ - = note: ...which again requires computing the super predicates of `B`, completing the cycle -note: cycle used when computing the super predicates of `A` + = note: ...which again requires computing the super clauses of `B`, completing the cycle +note: cycle used when computing the super clauses of `A` --> $DIR/cycle-trait-supertrait-indirect.rs:4:10 | LL | trait A: B { diff --git a/tests/ui/cycle-trait/issue-12511.stderr b/tests/ui/cycle-trait/issue-12511.stderr index 078f2eadc45a9..1ea82b694d55e 100644 --- a/tests/ui/cycle-trait/issue-12511.stderr +++ b/tests/ui/cycle-trait/issue-12511.stderr @@ -1,15 +1,15 @@ -error[E0391]: cycle detected when computing the super predicates of `T1` +error[E0391]: cycle detected when computing the super clauses of `T1` --> $DIR/issue-12511.rs:1:12 | LL | trait T1 : T2 { | ^^ | -note: ...which requires computing the super predicates of `T2`... +note: ...which requires computing the super clauses of `T2`... --> $DIR/issue-12511.rs:5:12 | LL | trait T2 : T1 { | ^^ - = note: ...which again requires computing the super predicates of `T1`, completing the cycle + = note: ...which again requires computing the super clauses of `T1`, completing the cycle note: cycle used when checking that `T1` is well-formed --> $DIR/issue-12511.rs:1:1 | diff --git a/tests/ui/generic-const-items/trivially-unsatisfied-bounds.rs b/tests/ui/generic-const-items/trivially-unsatisfied-bounds.rs index 9a0c6d0feeca8..884911ecbc115 100644 --- a/tests/ui/generic-const-items/trivially-unsatisfied-bounds.rs +++ b/tests/ui/generic-const-items/trivially-unsatisfied-bounds.rs @@ -6,7 +6,7 @@ #![feature(generic_const_items)] // FIXME(generic_const_items): Try to get rid of error "entering unreachable error", it's -// unnecessary and actually caused by MIR pass `ImpossiblePredicates` replacing the body with the +// unnecessary and actually caused by MIR pass `ImpossibleClauses` replacing the body with the // terminator `Unreachable` due to the unsatisfied bound which is subsequently reached. // // NOTE(#142293): However, don't think about suppressing the evaluation of the initializer if the diff --git a/tests/ui/infinite/infinite-trait-alias-recursion.rs b/tests/ui/infinite/infinite-trait-alias-recursion.rs index df884cca22b77..e5c3a1eea0a24 100644 --- a/tests/ui/infinite/infinite-trait-alias-recursion.rs +++ b/tests/ui/infinite/infinite-trait-alias-recursion.rs @@ -1,7 +1,7 @@ #![feature(trait_alias)] //@ ignore-parallel-frontend query cycle trait T1 = T2; -//~^ ERROR cycle detected when computing the implied predicates of `T1` +//~^ ERROR cycle detected when computing the implied clauses of `T1` trait T2 = T3; diff --git a/tests/ui/infinite/infinite-trait-alias-recursion.stderr b/tests/ui/infinite/infinite-trait-alias-recursion.stderr index a47754b142083..fc19fc0115811 100644 --- a/tests/ui/infinite/infinite-trait-alias-recursion.stderr +++ b/tests/ui/infinite/infinite-trait-alias-recursion.stderr @@ -1,20 +1,20 @@ -error[E0391]: cycle detected when computing the implied predicates of `T1` +error[E0391]: cycle detected when computing the implied clauses of `T1` --> $DIR/infinite-trait-alias-recursion.rs:3:12 | LL | trait T1 = T2; | ^^ | -note: ...which requires computing the implied predicates of `T2`... +note: ...which requires computing the implied clauses of `T2`... --> $DIR/infinite-trait-alias-recursion.rs:6:12 | LL | trait T2 = T3; | ^^ -note: ...which requires computing the implied predicates of `T3`... +note: ...which requires computing the implied clauses of `T3`... --> $DIR/infinite-trait-alias-recursion.rs:8:12 | LL | trait T3 = T1 + T3; | ^^ - = note: ...which again requires computing the implied predicates of `T1`, completing the cycle + = note: ...which again requires computing the implied clauses of `T1`, completing the cycle = note: trait aliases cannot be recursive note: cycle used when checking that `T1` is well-formed --> $DIR/infinite-trait-alias-recursion.rs:3:1 diff --git a/tests/ui/privacy/generic_struct_field_projection.rs b/tests/ui/privacy/generic_struct_field_projection.rs index c5bb1233c27b9..a6a5f6332abe4 100644 --- a/tests/ui/privacy/generic_struct_field_projection.rs +++ b/tests/ui/privacy/generic_struct_field_projection.rs @@ -1,12 +1,12 @@ //! To determine all the types that need to be private when looking at `Struct`, we -//! used to invoke `predicates_of` to also look at types in `where` bounds. +//! used to invoke `clauses_of` to also look at types in `where` bounds. //! Unfortunately this also computes the inferred outlives bounds, which means for //! every field we check that if it is of type `&'a T` then `T: 'a` and if it is of //! struct type, we check that the struct satisfies its lifetime parameters by looking //! at its inferred outlives bounds. This means we end up with a `::Assoc: 'a` //! in the outlives bounds of `Struct`. While this is trivially provable, privacy //! only sees `Foo` and `Trait` and determines that `Foo` is private and then errors. -//! So now we invoke `explicit_predicates_of` to make sure we only care about user-written +//! So now we invoke `explicit_clauses_of` to make sure we only care about user-written //! predicates. //@ check-pass diff --git a/tests/ui/traits/alias/infinite_normalization.rs b/tests/ui/traits/alias/infinite_normalization.rs index 9e3b7df7085b6..e78d8d12846fd 100644 --- a/tests/ui/traits/alias/infinite_normalization.rs +++ b/tests/ui/traits/alias/infinite_normalization.rs @@ -6,6 +6,6 @@ #![feature(trait_alias)] fn foo>() {} trait Baz = Baz>; -//~^ ERROR: cycle detected when computing the implied predicates of `Baz` +//~^ ERROR: cycle detected when computing the implied clauses of `Baz` fn main() {} diff --git a/tests/ui/traits/alias/infinite_normalization.stderr b/tests/ui/traits/alias/infinite_normalization.stderr index 049f55d1ab40d..1df4fd8129f27 100644 --- a/tests/ui/traits/alias/infinite_normalization.stderr +++ b/tests/ui/traits/alias/infinite_normalization.stderr @@ -1,10 +1,10 @@ -error[E0391]: cycle detected when computing the implied predicates of `Baz` +error[E0391]: cycle detected when computing the implied clauses of `Baz` --> $DIR/infinite_normalization.rs:8:16 | LL | trait Baz = Baz>; | ^^^^^^^^^^^^^^ | - = note: ...which immediately requires computing the implied predicates of `Baz` again + = note: ...which immediately requires computing the implied clauses of `Baz` again = note: trait aliases cannot be recursive note: cycle used when computing normalized predicates of `foo` --> $DIR/infinite_normalization.rs:7:1 diff --git a/tests/ui/traits/solver-cycles/self-item-cycle.stderr b/tests/ui/traits/solver-cycles/self-item-cycle.stderr index 179d2d2bb7e05..13fcf36b5d2e2 100644 --- a/tests/ui/traits/solver-cycles/self-item-cycle.stderr +++ b/tests/ui/traits/solver-cycles/self-item-cycle.stderr @@ -5,7 +5,7 @@ LL | trait T: Iterator | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: ...which immediately requires computing the super traits of `T` with associated type name `Item` again - = note: cycle used when computing the super predicates of `T` + = note: cycle used when computing the super clauses of `T` = note: for more information, see and error: aborting due to 1 previous error diff --git a/tests/ui/traits/trait-upcasting/cyclic-trait-resolution.rs b/tests/ui/traits/trait-upcasting/cyclic-trait-resolution.rs index 6211c7fac4158..3b20ac94e8c62 100644 --- a/tests/ui/traits/trait-upcasting/cyclic-trait-resolution.rs +++ b/tests/ui/traits/trait-upcasting/cyclic-trait-resolution.rs @@ -1,6 +1,6 @@ trait A: B + A {} -//~^ ERROR cycle detected when computing the super predicates of `A` [E0391] -//~| ERROR cycle detected when computing the implied predicates of `A` [E0391] +//~^ ERROR cycle detected when computing the super clauses of `A` [E0391] +//~| ERROR cycle detected when computing the implied clauses of `A` [E0391] trait B {} diff --git a/tests/ui/traits/trait-upcasting/cyclic-trait-resolution.stderr b/tests/ui/traits/trait-upcasting/cyclic-trait-resolution.stderr index bbd2e56285f48..1b16ec76d2b92 100644 --- a/tests/ui/traits/trait-upcasting/cyclic-trait-resolution.stderr +++ b/tests/ui/traits/trait-upcasting/cyclic-trait-resolution.stderr @@ -1,10 +1,10 @@ -error[E0391]: cycle detected when computing the super predicates of `A` +error[E0391]: cycle detected when computing the super clauses of `A` --> $DIR/cyclic-trait-resolution.rs:1:14 | LL | trait A: B + A {} | ^ | - = note: ...which immediately requires computing the super predicates of `A` again + = note: ...which immediately requires computing the super clauses of `A` again note: cycle used when checking that `A` is well-formed --> $DIR/cyclic-trait-resolution.rs:1:1 | @@ -12,13 +12,13 @@ LL | trait A: B + A {} | ^^^^^^^^^^^^^^ = note: for more information, see and -error[E0391]: cycle detected when computing the implied predicates of `A` +error[E0391]: cycle detected when computing the implied clauses of `A` --> $DIR/cyclic-trait-resolution.rs:1:14 | LL | trait A: B + A {} | ^ | - = note: ...which immediately requires computing the implied predicates of `A` again + = note: ...which immediately requires computing the implied clauses of `A` again note: cycle used when checking that `` is well-formed --> $DIR/cyclic-trait-resolution.rs:7:1 | From b35f9b35c232a0f09b8d50c2419967d98ae92a04 Mon Sep 17 00:00:00 2001 From: "addie.sh" Date: Tue, 21 Jul 2026 11:49:20 -0400 Subject: [PATCH 03/41] Replace most `Ty::new_fn_def` calls with `type_of` queries directly --- compiler/rustc_middle/src/ty/sty.rs | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index f8fb476ca3ef1..06b2c621eda00 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -726,22 +726,6 @@ impl<'tcx> Ty<'tcx> { } /// Prefer using the [TyCtxt::type_of] query over this, that makes it easier to get all the pieces correct - #[inline] - pub fn new_fn_def_raw( - tcx: TyCtxt<'tcx>, - def_id: DefId, - args: ty::Binder<'tcx, impl IntoIterator>>>, - ) -> Ty<'tcx> { - debug_assert_matches!( - tcx.def_kind(def_id), - DefKind::AssocFn | DefKind::Fn | DefKind::Ctor(_, CtorKind::Fn) - ); - - let args = args.map_bound(|args| tcx.check_and_mk_args(def_id, args)); - - Ty::new(tcx, FnDef(def_id, args)) - } - #[inline] pub fn new_fn_def( tcx: TyCtxt<'tcx>, From 6c802c86ac66c97fcfb61e7076cb024b449ac883 Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Tue, 21 Jul 2026 20:18:35 +0000 Subject: [PATCH 04/41] rustdoc: Set tracing max_level_info when debug-logging is false This matches rustc and should improve performance for the published versions of rustdoc. We shouldn't be including all our debug! calls in builds for users. --- src/bootstrap/src/core/build_steps/tool.rs | 3 +++ src/librustdoc/Cargo.toml | 1 + src/tools/rustdoc/Cargo.toml | 1 + 3 files changed, 5 insertions(+) diff --git a/src/bootstrap/src/core/build_steps/tool.rs b/src/bootstrap/src/core/build_steps/tool.rs index 89143c8e74333..d5c2ecf7e93f5 100644 --- a/src/bootstrap/src/core/build_steps/tool.rs +++ b/src/bootstrap/src/core/build_steps/tool.rs @@ -770,6 +770,9 @@ impl CommandLineStep for Rustdoc { if let Some(allocator) = builder.config.override_allocator(target) { extra_features.push(allocator.feature_name().to_string()); } + if !builder.config.rust_debug_logging { + extra_features.push("max_level_info".to_string()) + } let compilers = RustcPrivateCompilers::from_target_compiler(builder, target_compiler); let tool_path = builder diff --git a/src/librustdoc/Cargo.toml b/src/librustdoc/Cargo.toml index 45d084b2f9bf7..084a8ea8ffcff 100644 --- a/src/librustdoc/Cargo.toml +++ b/src/librustdoc/Cargo.toml @@ -44,6 +44,7 @@ expect-test = "1.4.0" [features] jemalloc = [] +max_level_info = ["tracing/max_level_info", "tracing/release_max_level_info"] [package.metadata.rust-analyzer] rustc_private = true diff --git a/src/tools/rustdoc/Cargo.toml b/src/tools/rustdoc/Cargo.toml index d1682758d3626..6b0491ef47a84 100644 --- a/src/tools/rustdoc/Cargo.toml +++ b/src/tools/rustdoc/Cargo.toml @@ -15,3 +15,4 @@ rustdoc = { path = "../../librustdoc" } [features] jemalloc = ['rustdoc/jemalloc'] +max_level_info = ["rustdoc/max_level_info"] From ba44eb8ffbbb260b110851e89146769cbaacfbd9 Mon Sep 17 00:00:00 2001 From: Jamie Hill-Daniel Date: Tue, 28 Jul 2026 09:17:24 +0100 Subject: [PATCH 05/41] refactor(mir-transform): Calculate optimization status inside `run_passes_inner` --- .../rustc_mir_transform/src/coverage/mod.rs | 2 +- compiler/rustc_mir_transform/src/lib.rs | 31 ++----------------- .../rustc_mir_transform/src/pass_manager.rs | 17 +++++++--- compiler/rustc_mir_transform/src/shim.rs | 2 -- .../src/shim/async_destructor_ctor.rs | 1 - tests/mir-opt/optimize_none.rs | 6 ++-- 6 files changed, 20 insertions(+), 39 deletions(-) diff --git a/compiler/rustc_mir_transform/src/coverage/mod.rs b/compiler/rustc_mir_transform/src/coverage/mod.rs index be8b02f61133d..c3b7cc45c88ec 100644 --- a/compiler/rustc_mir_transform/src/coverage/mod.rs +++ b/compiler/rustc_mir_transform/src/coverage/mod.rs @@ -56,7 +56,7 @@ impl<'tcx> crate::MirPass<'tcx> for InstrumentCoverage { } fn is_required(&self) -> bool { - false + true } } diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index b6aacb882b98f..30c35ced95498 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -422,7 +422,6 @@ fn mir_built(tcx: TyCtxt<'_>, def: LocalDefId) -> &Steal> { &Lint(sanity_check::SanityCheck), ], None, - pm::Optimizations::Allowed, ); tcx.alloc_steal_mir(body) } @@ -479,7 +478,6 @@ fn mir_promoted( &mut body, &[&promote_pass, &simplify::SimplifyCfg::PromoteConsts, &coverage::InstrumentCoverage], Some(MirPhase::Analysis(AnalysisPhase::Initial)), - pm::Optimizations::Allowed, ); lint_tail_expr_drop_order::run_lint(tcx, def, &body); @@ -526,7 +524,7 @@ fn inner_mir_for_ctfe(tcx: TyCtxt<'_>, def: LocalDefId) -> Body<'_> { } else { &[&ctfe_limit::CtfeLimit] }; - pm::run_passes(tcx, &mut body, passes, None, pm::Optimizations::Allowed); + pm::run_passes(tcx, &mut body, passes, None); body } @@ -613,7 +611,6 @@ pub fn run_analysis_to_runtime_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<' &Lint(post_drop_elaboration::CheckLiveDrops), ], None, - pm::Optimizations::Allowed, ); } @@ -638,13 +635,7 @@ fn run_analysis_cleanup_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { &deref_separator::Derefer, ]; - pm::run_passes( - tcx, - body, - passes, - Some(MirPhase::Analysis(AnalysisPhase::PostCleanup)), - pm::Optimizations::Allowed, - ); + pm::run_passes(tcx, body, passes, Some(MirPhase::Analysis(AnalysisPhase::PostCleanup))); } /// Returns the sequence of passes that lowers analysis to runtime MIR. @@ -682,13 +673,7 @@ fn run_runtime_cleanup_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { &simplify::SimplifyCfg::PreOptimizations, ]; - pm::run_passes( - tcx, - body, - passes, - Some(MirPhase::Runtime(RuntimePhase::PostCleanup)), - pm::Optimizations::Allowed, - ); + pm::run_passes(tcx, body, passes, Some(MirPhase::Runtime(RuntimePhase::PostCleanup))); // Clear this by anticipation. Optimizations and runtime MIR have no reason to look // into this information, which is meant for borrowck diagnostics. @@ -702,15 +687,6 @@ pub(crate) fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<' WithMinOptLevel(1, x) } - let def_id = body.source.def_id(); - let optimizations = if tcx.def_kind(def_id).has_codegen_attrs() - && tcx.codegen_fn_attrs(def_id).optimize.do_not_optimize() - { - pm::Optimizations::Suppressed - } else { - pm::Optimizations::Allowed - }; - // The main optimizations that we do on MIR. pm::run_passes( tcx, @@ -793,7 +769,6 @@ pub(crate) fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<' &prettify::ReorderLocals, ], Some(MirPhase::Runtime(RuntimePhase::Optimized)), - optimizations, ); } diff --git a/compiler/rustc_mir_transform/src/pass_manager.rs b/compiler/rustc_mir_transform/src/pass_manager.rs index 72af7b846861e..ef4f64cb6c87d 100644 --- a/compiler/rustc_mir_transform/src/pass_manager.rs +++ b/compiler/rustc_mir_transform/src/pass_manager.rs @@ -185,7 +185,9 @@ where /// [required]: MirPass::is_required #[derive(Copy, Clone, Debug, PartialEq, Eq)] pub(crate) enum Optimizations { + /// The current function has `#[optimize(none)]`. Suppressed, + /// Normal optimizations may run. Allowed, } @@ -197,7 +199,7 @@ pub(super) fn run_passes_no_validate<'tcx>( passes: &[&dyn MirPass<'tcx>], phase_change: Option, ) { - run_passes_inner(tcx, body, passes, phase_change, false, Optimizations::Allowed); + run_passes_inner(tcx, body, passes, phase_change, false); } /// The optional `phase_change` is applied after executing all the passes, if present @@ -206,9 +208,8 @@ pub(super) fn run_passes<'tcx>( body: &mut Body<'tcx>, passes: &[&dyn MirPass<'tcx>], phase_change: Option, - optimizations: Optimizations, ) { - run_passes_inner(tcx, body, passes, phase_change, true, optimizations); + run_passes_inner(tcx, body, passes, phase_change, true); } pub(super) fn should_run_pass<'tcx, P>( @@ -245,7 +246,6 @@ fn run_passes_inner<'tcx>( passes: &[&dyn MirPass<'tcx>], phase_change: Option, validate_each: bool, - optimizations: Optimizations, ) { let overridden_passes = &tcx.sess.opts.unstable_opts.mir_enable_passes; trace!(?overridden_passes); @@ -287,6 +287,15 @@ fn run_passes_inner<'tcx>( let validate = validate_each & tcx.sess.opts.unstable_opts.validate_mir; let lint = tcx.sess.opts.unstable_opts.lint_mir; + let def_id = body.source.def_id(); + let optimizations = if tcx.def_kind(def_id).has_codegen_attrs() + && tcx.codegen_fn_attrs(def_id).optimize.do_not_optimize() + { + Optimizations::Suppressed + } else { + Optimizations::Allowed + }; + for pass in passes { let pass_name = pass.name(); diff --git a/compiler/rustc_mir_transform/src/shim.rs b/compiler/rustc_mir_transform/src/shim.rs index 2ecc9822a84b6..bbe36166686d5 100644 --- a/compiler/rustc_mir_transform/src/shim.rs +++ b/compiler/rustc_mir_transform/src/shim.rs @@ -119,7 +119,6 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, shim: ty::ShimKind<'tcx>) -> Body<'tcx> { &add_call_guards::CriticalCallEdges, ], Some(MirPhase::Runtime(RuntimePhase::Optimized)), - pm::Optimizations::Allowed, ); return body; @@ -143,7 +142,6 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, shim: ty::ShimKind<'tcx>) -> Body<'tcx> { &add_call_guards::CriticalCallEdges, ], Some(MirPhase::Runtime(RuntimePhase::PostCleanup)), - pm::Optimizations::Allowed, ); run_optimization_passes(tcx, &mut body); debug!("make_shim({:?}) = {:?}", shim, body); diff --git a/compiler/rustc_mir_transform/src/shim/async_destructor_ctor.rs b/compiler/rustc_mir_transform/src/shim/async_destructor_ctor.rs index 194f242fe6cc7..be1a7e1419a29 100644 --- a/compiler/rustc_mir_transform/src/shim/async_destructor_ctor.rs +++ b/compiler/rustc_mir_transform/src/shim/async_destructor_ctor.rs @@ -37,7 +37,6 @@ pub(super) fn build_async_destructor_ctor_shim<'tcx>( &add_call_guards::CriticalCallEdges, ], None, - pm::Optimizations::Allowed, ); body } diff --git a/tests/mir-opt/optimize_none.rs b/tests/mir-opt/optimize_none.rs index 99efcc35e5955..23245f6cc687e 100644 --- a/tests/mir-opt/optimize_none.rs +++ b/tests/mir-opt/optimize_none.rs @@ -16,12 +16,12 @@ pub fn add_noopt() -> i32 { pub fn const_branch() -> i32 { // CHECK-LABEL: fn const_branch( // CHECK: [[BOOL:_[0-9]+]] = const true; - // CHECK: switchInt(move [[BOOL]]) -> [0: [[BB_FALSE:bb[0-9]+]], otherwise: [[BB_TRUE:bb[0-9]+]]]; + // CHECK: switchInt(move [[BOOL]]) -> [0: [[BB_FALSE_SHIM:bb[0-9]+]], otherwise: [[BB_TRUE:bb[0-9]+]]]; // CHECK-NEXT: } + // CHECK: [[BB_FALSE_SHIM]]: { + // CHECK-NEXT: goto -> [[BB_FALSE:bb[0-9]+]] // CHECK: [[BB_FALSE]]: { // CHECK-NEXT: _0 = const 0 - // CHECK-NEXT: goto - // CHECK-NEXT: } // CHECK: [[BB_TRUE]]: { // CHECK-NEXT: _0 = const 1 // CHECK-NEXT: goto From 9c65f1c26ba86d16ab4feea8827ec90380ebbff2 Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Tue, 28 Jul 2026 18:47:34 +0900 Subject: [PATCH 06/41] Revert "codegen: handle OperandValue::Uninit in codegen_return_terminator" This reverts commit 9e9467adc6736c45326d44ba8f5eb3809e3b9749. --- compiler/rustc_codegen_ssa/src/mir/block.rs | 8 ++++---- tests/codegen-llvm/uninit-return-value.rs | 13 ------------- 2 files changed, 4 insertions(+), 17 deletions(-) delete mode 100644 tests/codegen-llvm/uninit-return-value.rs diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index 20d6c01f12f73..5dbaae44a441e 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -581,10 +581,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { PassMode::Direct(_) | PassMode::Pair(..) => { let op = self.codegen_consume(bx, mir::Place::return_place().as_ref()); - match op.val { - Ref(place_val) => bx.load_from_place(bx.backend_type(op.layout), place_val), - Uninit => bx.cx().const_undef(bx.cx().immediate_backend_type(op.layout)), - _ => op.immediate_or_packed_pair(bx), + if let Ref(place_val) = op.val { + bx.load_from_place(bx.backend_type(op.layout), place_val) + } else { + op.immediate_or_packed_pair(bx) } } diff --git a/tests/codegen-llvm/uninit-return-value.rs b/tests/codegen-llvm/uninit-return-value.rs deleted file mode 100644 index 3a4debb1d4f78..0000000000000 --- a/tests/codegen-llvm/uninit-return-value.rs +++ /dev/null @@ -1,13 +0,0 @@ -// Regression test for https://github.com/rust-lang/rust/issues/159815 - -#![crate_type = "lib"] - -use std::mem::MaybeUninit; - -// CHECK-LABEL: @f -#[no_mangle] -pub fn f() -> MaybeUninit<*const ()> { - // CHECK: start: - // CHECK-NEXT: ret ptr undef - const { MaybeUninit::uninit() } -} From c912b1fff8b61f51486431f18316ba80a46d56d2 Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Tue, 28 Jul 2026 18:47:39 +0900 Subject: [PATCH 07/41] Revert "codegen: add OperandValue::Uninit to skip stores for entirely-uninit constants" This reverts commit ed9de1e4663c73242710235ff343895e16a4d539. --- .../rustc_codegen_gcc/src/intrinsic/mod.rs | 2 +- compiler/rustc_codegen_llvm/src/intrinsic.rs | 3 +- compiler/rustc_codegen_ssa/src/base.rs | 2 +- compiler/rustc_codegen_ssa/src/mir/block.rs | 16 ++-------- .../rustc_codegen_ssa/src/mir/constant.rs | 6 +--- .../rustc_codegen_ssa/src/mir/debuginfo.rs | 2 +- compiler/rustc_codegen_ssa/src/mir/operand.rs | 23 ++------------ compiler/rustc_codegen_ssa/src/mir/retag.rs | 3 -- compiler/rustc_codegen_ssa/src/mir/rvalue.rs | 31 ++++++++++++++----- tests/codegen-llvm/uninit-aggregate-field.rs | 30 ------------------ 10 files changed, 34 insertions(+), 84 deletions(-) delete mode 100644 tests/codegen-llvm/uninit-aggregate-field.rs diff --git a/compiler/rustc_codegen_gcc/src/intrinsic/mod.rs b/compiler/rustc_codegen_gcc/src/intrinsic/mod.rs index 986c04e6b4813..09ad3254e5714 100644 --- a/compiler/rustc_codegen_gcc/src/intrinsic/mod.rs +++ b/compiler/rustc_codegen_gcc/src/intrinsic/mod.rs @@ -629,7 +629,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc for arg in args { match arg.val { - OperandValue::ZeroSized | OperandValue::Uninit => {} + OperandValue::ZeroSized => {} OperandValue::Immediate(_) => call_args.push(arg.immediate()), OperandValue::Pair(a, b) => { call_args.push(a); diff --git a/compiler/rustc_codegen_llvm/src/intrinsic.rs b/compiler/rustc_codegen_llvm/src/intrinsic.rs index 4f80e5c6e81e1..edf943c81a755 100644 --- a/compiler/rustc_codegen_llvm/src/intrinsic.rs +++ b/compiler/rustc_codegen_llvm/src/intrinsic.rs @@ -962,7 +962,6 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> { for arg in args { match arg.val { OperandValue::ZeroSized => {} - OperandValue::Uninit => {} OperandValue::Immediate(a) => llargs.push(a), OperandValue::Pair(a, b) => { llargs.push(a); @@ -1940,7 +1939,7 @@ fn get_args_from_tuple<'ll, 'tcx>( result } - OperandValue::ZeroSized | OperandValue::Uninit => vec![], + OperandValue::ZeroSized => vec![], } } diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index 339c0a968e9d3..d3af6eba33374 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -287,7 +287,7 @@ pub(crate) fn coerce_unsized_into<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( let (base, info) = match bx.load_operand(src).val { OperandValue::Pair(base, info) => unsize_ptr(bx, base, src_ty, dst_ty, Some(info)), OperandValue::Immediate(base) => unsize_ptr(bx, base, src_ty, dst_ty, None), - OperandValue::Ref(..) | OperandValue::ZeroSized | OperandValue::Uninit => bug!(), + OperandValue::Ref(..) | OperandValue::ZeroSized => bug!(), }; OperandValue::Pair(base, info).store(bx, dst); } diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index 5dbaae44a441e..aab4259b6b41d 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -23,7 +23,7 @@ use rustc_target::callconv::{ArgAbi, ArgAttributes, CastTarget, FnAbi, PassMode} use tracing::{debug, info}; use super::operand::OperandRef; -use super::operand::OperandValue::{self, Immediate, Pair, Ref, Uninit, ZeroSized}; +use super::operand::OperandValue::{self, Immediate, Pair, Ref, ZeroSized}; use super::place::{PlaceRef, PlaceValue}; use super::{CachedLlbb, FunctionCx, LocalRef}; use crate::base::{self, is_call_from_compiler_builtins_to_upstream_monomorphization}; @@ -613,9 +613,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { place_val.llval } ZeroSized => bug!("ZST return value shouldn't be in PassMode::Cast"), - OperandValue::Uninit => { - bug!("uninit return value shouldn't be in PassMode::Cast") - } }; if self.fn_abi.conv == CanonAbi::Arm(ArmCall::CCmseNonSecureEntry) { @@ -1964,7 +1961,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { // Force by-ref if we have to load through a cast pointer. let (mut llval, align, by_ref) = match op.val { - Immediate(_) | Pair(..) | Uninit => match arg.mode { + Immediate(_) | Pair(..) => match arg.mode { PassMode::Indirect { attrs, .. } => { // Indirect argument may have higher alignment requirements than the type's // alignment. This can happen, e.g. when passing types with <4 byte alignment @@ -1984,14 +1981,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { op.store_with_annotation(bx, scratch); (scratch.val.llval, scratch.val.align, true) } - PassMode::Direct(_) => { - if let Uninit = op.val { - let ibty = bx.cx().immediate_backend_type(arg.layout); - (bx.cx().const_undef(ibty), arg.layout.align.abi, false) - } else { - (op.immediate(), arg.layout.align.abi, false) - } - } + PassMode::Direct(_) => (op.immediate(), arg.layout.align.abi, false), PassMode::Ignore | PassMode::Pair(..) => unreachable!("handled above"), }, Ref(op_place_val) => match arg.mode { diff --git a/compiler/rustc_codegen_ssa/src/mir/constant.rs b/compiler/rustc_codegen_ssa/src/mir/constant.rs index 68893c7ac8fb2..7d35d4b72bd1e 100644 --- a/compiler/rustc_codegen_ssa/src/mir/constant.rs +++ b/compiler/rustc_codegen_ssa/src/mir/constant.rs @@ -6,7 +6,7 @@ use rustc_middle::{bug, mir, span_bug}; use super::FunctionCx; use crate::diagnostics; -use crate::mir::operand::{OperandRef, OperandValue}; +use crate::mir::operand::OperandRef; use crate::traits::*; impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { @@ -17,10 +17,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { ) -> OperandRef<'tcx, Bx::Value> { let val = self.eval_mir_constant(constant); let ty = self.monomorphize(constant.ty()); - if val.all_bytes_uninit(self.cx.tcx()) { - let layout = bx.layout_of(ty); - return OperandRef { val: OperandValue::Uninit, layout, move_annotation: None }; - } OperandRef::from_const(bx, val, ty) } diff --git a/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs b/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs index 7be2850aced90..c586b8080ef30 100644 --- a/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs +++ b/compiler/rustc_codegen_ssa/src/mir/debuginfo.rs @@ -390,7 +390,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { bx.set_var_name(a, &(name.clone() + ".0")); bx.set_var_name(b, &(name.clone() + ".1")); } - OperandValue::ZeroSized | OperandValue::Uninit => { + OperandValue::ZeroSized => { // These never have a value to talk about } }, diff --git a/compiler/rustc_codegen_ssa/src/mir/operand.rs b/compiler/rustc_codegen_ssa/src/mir/operand.rs index 552c0b58a194e..1dbbc3fd28fb9 100644 --- a/compiler/rustc_codegen_ssa/src/mir/operand.rs +++ b/compiler/rustc_codegen_ssa/src/mir/operand.rs @@ -86,12 +86,6 @@ pub enum OperandValue { /// `is_zst` on its `Layout` returns `true`. Note however that /// these values can still require alignment. ZeroSized, - /// A value for which all bytes are entirely uninitialized. - /// - /// Storing this value is a no-op; it propagates through field extraction. - /// Used to avoid emitting memcpys from uninit globals (which LLVM may - /// otherwise materialize as zero-fills) for `const ` operands. - Uninit, } impl OperandValue { @@ -101,7 +95,7 @@ impl OperandValue { match self { OperandValue::Immediate(llptr) => Some((llptr, None)), OperandValue::Pair(llptr, llextra) => Some((llptr, Some(llextra))), - OperandValue::Ref(_) | OperandValue::ZeroSized | OperandValue::Uninit => None, + OperandValue::Ref(_) | OperandValue::ZeroSized => None, } } @@ -129,7 +123,6 @@ impl OperandValue { #[must_use] pub(crate) fn is_expected_variant_for_type<'tcx>(&self, ty: TyAndLayout<'tcx>) -> bool { match (self, ty.backend_repr) { - (OperandValue::Uninit, _) => true, (OperandValue::ZeroSized, BackendRepr::Memory { .. }) => ty.is_zst(), (OperandValue::Ref(_), BackendRepr::Memory { .. }) => !ty.is_zst(), ( @@ -404,9 +397,7 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> { ); } - let val = if let OperandValue::Uninit = self.val { - OperandValue::Uninit - } else if field.is_zst() { + let val = if field.is_zst() { OperandValue::ZeroSized } else if field.size == self.layout.size { assert_eq!(offset.bytes(), 0); @@ -505,7 +496,6 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> { // Read the tag/niche-encoded discriminant from memory. let tag_op = match self.val { OperandValue::ZeroSized => bug!(), - OperandValue::Uninit => return bx.cx().const_poison(cast_to), OperandValue::Immediate(_) | OperandValue::Pair(_, _) => { self.extract_field(fx, bx, tag_field.as_usize()) } @@ -788,15 +778,12 @@ impl<'a, 'tcx, V: CodegenObject> OperandRefBuilder<'tcx, V> { field: FieldIdx, field_operand: OperandRef<'tcx, V>, ) { - if matches!(field_operand.val, OperandValue::ZeroSized | OperandValue::Uninit) { + if let OperandValue::ZeroSized = field_operand.val { // A ZST never adds any state, so just ignore it. // This special-casing is worth it because of things like // `Result` where `Ok(never)` is legal to write, // but the type shows as FieldShape::Primitive so we can't // actually look at the layout for the field being set. - // - // Likewise, an uninit field does not contribute any value; - // the builder's unset slots will produce `const_undef` in `build()`. return; } @@ -1032,10 +1019,6 @@ impl<'a, 'tcx, V: CodegenObject> OperandValue { // Avoid generating stores of zero-sized values, because the only way to have a // zero-sized value is through `undef`/`poison`, and the store itself is useless. } - OperandValue::Uninit => { - // Storing an entirely uninit value is a no-op: the destination is left - // uninitialized, which is valid since the value itself is uninit. - } OperandValue::Ref(val) => { assert!(dest.layout.is_sized(), "cannot directly store unsized values"); if val.llextra.is_some() { diff --git a/compiler/rustc_codegen_ssa/src/mir/retag.rs b/compiler/rustc_codegen_ssa/src/mir/retag.rs index c10302eff0d9b..680f0b44d70dd 100644 --- a/compiler/rustc_codegen_ssa/src/mir/retag.rs +++ b/compiler/rustc_codegen_ssa/src/mir/retag.rs @@ -298,9 +298,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { builder.update_imm(offset, fst); builder.update_imm(offset + Size::from_bytes(1), snd) } - OperandValue::Uninit => { - unreachable!("load_operand never produces Uninit") - } } } } diff --git a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs index 4270073b29894..6786ee9a18e4f 100644 --- a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs +++ b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs @@ -100,6 +100,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { ) { match *rvalue { mir::Rvalue::Use(ref operand, with_retag) => { + if let mir::Operand::Constant(const_op) = operand { + let val = self.eval_mir_constant(&const_op); + if val.all_bytes_uninit(self.cx.tcx()) { + return; + } + } let cg_operand = self.codegen_operand(bx, operand); // Crucially, we do *not* use `OperandValue::Ref` for types with // `BackendRepr::Scalar | BackendRepr::ScalarPair`. This ensures we match the MIR @@ -170,9 +176,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { OperandValue::ZeroSized => { bug!("unsized coercion on a ZST rvalue"); } - OperandValue::Uninit => { - bug!("unsized coercion on an uninit rvalue"); - } } } @@ -191,12 +194,25 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { return; } - let cg_elem = self.codegen_operand(bx, elem); - - if let OperandValue::Uninit = cg_elem.val { - return; + // When the element is a const with all bytes uninit, emit a single memset that + // writes undef to the entire destination. + if let mir::Operand::Constant(const_op) = elem { + let val = self.eval_mir_constant(const_op); + if val.all_bytes_uninit(self.cx.tcx()) { + let size = bx.const_usize(dest.layout.size.bytes()); + bx.memset( + dest.val.llval, + bx.const_undef(bx.type_i8()), + size, + dest.val.align, + MemFlags::empty(), + ); + return; + } } + let cg_elem = self.codegen_operand(bx, elem); + let try_init_all_same = |bx: &mut Bx, v| { let start = dest.val.llval; let size = bx.const_usize(dest.layout.size.bytes()); @@ -356,7 +372,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { let cx = bx.cx(); match (operand.val, operand.layout.backend_repr, cast.backend_repr) { _ if cast.is_zst() => OperandValue::ZeroSized, - (OperandValue::Uninit, _, _) => OperandValue::Uninit, (OperandValue::Ref(source_place_val), abi::BackendRepr::Memory { .. }, _) => { assert_eq!(source_place_val.llextra, None); // The existing alignment is part of `source_place_val`, diff --git a/tests/codegen-llvm/uninit-aggregate-field.rs b/tests/codegen-llvm/uninit-aggregate-field.rs deleted file mode 100644 index f36ea05f0c8fd..0000000000000 --- a/tests/codegen-llvm/uninit-aggregate-field.rs +++ /dev/null @@ -1,30 +0,0 @@ -// Regression test for https://github.com/rust-lang/rust/issues/157743 -// -// At opt-level >= 1, MIR GVN inlines MaybeUninit::uninit() and propagates the -// result as `const ` in aggregate constructions. Without the fix, this -// caused codegen to emit a memcpy from an `[N x i8] undef` global constant for -// the uninit field, which LLVM would materialize as zero-initialization. -// -// The fix skips emitting any IR for entirely-uninit constant aggregate fields. - -//@ compile-flags: -C no-prepopulate-passes -C opt-level=2 - -#![crate_type = "lib"] - -use std::mem::MaybeUninit; - -pub struct Inner { - cap: usize, - data: MaybeUninit<[u64; 2]>, -} - -// CHECK-LABEL: @make_inner -// The non-uninit field must be stored. -// CHECK: store i{{(32|64)}} -// The entirely-uninit `data` field must not cause a memcpy from an undef global. -// CHECK-NOT: call void @llvm.memcpy -// CHECK: ret void -#[no_mangle] -pub fn make_inner(cap: usize) -> Inner { - Inner { cap, data: MaybeUninit::uninit() } -} From bbb02d67c81b0ff8d9644b82d83925bad10bc7aa Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Tue, 28 Jul 2026 09:31:07 +0000 Subject: [PATCH 08/41] codegen: skip stores for entirely-uninit constant aggregate fields MIR GVN propagates MaybeUninit::uninit() as `const ` in aggregate constructions and codegen emits a memcpy from an `[N x i8] undef` global for each such field, which LLVM materializes as zero-initialization. We extract the existing `all_bytes_uninit` skip already present for `Rvalue::Use` and `Rvalue::Repeat` to a separate helper function, and use it in the `Rvalue::Aggregate` field loop. --- compiler/rustc_codegen_ssa/src/mir/rvalue.rs | 40 +++++++++++--------- tests/codegen-llvm/uninit-aggregate-field.rs | 30 +++++++++++++++ 2 files changed, 52 insertions(+), 18 deletions(-) create mode 100644 tests/codegen-llvm/uninit-aggregate-field.rs diff --git a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs index 6786ee9a18e4f..a5d78fc8a7f35 100644 --- a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs +++ b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs @@ -91,6 +91,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { true } + fn is_entirely_uninit_const(&self, operand: &mir::Operand<'tcx>) -> bool { + let mir::Operand::Constant(const_op) = operand else { return false }; + self.eval_mir_constant(const_op).all_bytes_uninit(self.cx.tcx()) + } + #[instrument(level = "trace", skip(self, bx))] pub(crate) fn codegen_rvalue( &mut self, @@ -100,11 +105,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { ) { match *rvalue { mir::Rvalue::Use(ref operand, with_retag) => { - if let mir::Operand::Constant(const_op) = operand { - let val = self.eval_mir_constant(&const_op); - if val.all_bytes_uninit(self.cx.tcx()) { - return; - } + if self.is_entirely_uninit_const(operand) { + return; } let cg_operand = self.codegen_operand(bx, operand); // Crucially, we do *not* use `OperandValue::Ref` for types with @@ -196,19 +198,16 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { // When the element is a const with all bytes uninit, emit a single memset that // writes undef to the entire destination. - if let mir::Operand::Constant(const_op) = elem { - let val = self.eval_mir_constant(const_op); - if val.all_bytes_uninit(self.cx.tcx()) { - let size = bx.const_usize(dest.layout.size.bytes()); - bx.memset( - dest.val.llval, - bx.const_undef(bx.type_i8()), - size, - dest.val.align, - MemFlags::empty(), - ); - return; - } + if self.is_entirely_uninit_const(elem) { + let size = bx.const_usize(dest.layout.size.bytes()); + bx.memset( + dest.val.llval, + bx.const_undef(bx.type_i8()), + size, + dest.val.align, + MemFlags::empty(), + ); + return; } let cg_elem = self.codegen_operand(bx, elem); @@ -270,6 +269,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { assert_eq!(operands.len(), 1); } for (i, operand) in operands.iter_enumerated() { + // Do not generate stores for entirely uninit constant fields, for the same + // reason as in `Rvalue::Use` above. + if self.is_entirely_uninit_const(operand) { + continue; + } let op = self.codegen_operand(bx, operand); // Do not generate stores and GEPis for zero-sized fields. if !op.layout.is_zst() { diff --git a/tests/codegen-llvm/uninit-aggregate-field.rs b/tests/codegen-llvm/uninit-aggregate-field.rs new file mode 100644 index 0000000000000..f36ea05f0c8fd --- /dev/null +++ b/tests/codegen-llvm/uninit-aggregate-field.rs @@ -0,0 +1,30 @@ +// Regression test for https://github.com/rust-lang/rust/issues/157743 +// +// At opt-level >= 1, MIR GVN inlines MaybeUninit::uninit() and propagates the +// result as `const ` in aggregate constructions. Without the fix, this +// caused codegen to emit a memcpy from an `[N x i8] undef` global constant for +// the uninit field, which LLVM would materialize as zero-initialization. +// +// The fix skips emitting any IR for entirely-uninit constant aggregate fields. + +//@ compile-flags: -C no-prepopulate-passes -C opt-level=2 + +#![crate_type = "lib"] + +use std::mem::MaybeUninit; + +pub struct Inner { + cap: usize, + data: MaybeUninit<[u64; 2]>, +} + +// CHECK-LABEL: @make_inner +// The non-uninit field must be stored. +// CHECK: store i{{(32|64)}} +// The entirely-uninit `data` field must not cause a memcpy from an undef global. +// CHECK-NOT: call void @llvm.memcpy +// CHECK: ret void +#[no_mangle] +pub fn make_inner(cap: usize) -> Inner { + Inner { cap, data: MaybeUninit::uninit() } +} From e04907a20e023a66c9a3e24e988dc00fae7542ee Mon Sep 17 00:00:00 2001 From: Makro Date: Tue, 28 Jul 2026 06:35:50 +0000 Subject: [PATCH 09/41] Fix ICE when dumping the dep graph with the parallel frontend --- .../rustc_middle/src/dep_graph/retained.rs | 4 +++- tests/run-make/dep-graph/rmake.rs | 24 +++++++++++-------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_middle/src/dep_graph/retained.rs b/compiler/rustc_middle/src/dep_graph/retained.rs index 7949a47346845..e02b2773e8645 100644 --- a/compiler/rustc_middle/src/dep_graph/retained.rs +++ b/compiler/rustc_middle/src/dep_graph/retained.rs @@ -26,6 +26,8 @@ impl RetainedDepGraph { Self { inner, indices } } + /// Adds `node` at its dep-graph index. Indices are allocated to threads in batches, so the + /// index space is sparse and the slots skipped over hold no node. pub fn push(&mut self, index: DepNodeIndex, node: DepNode, edges: &[DepNodeIndex]) { let source = NodeIndex(index.as_usize()); self.inner.add_node_with_idx(source, node); @@ -37,7 +39,7 @@ impl RetainedDepGraph { } pub fn nodes(&self) -> Vec<&DepNode> { - self.inner.all_nodes().iter().map(|n| n.data.as_ref().unwrap()).collect() + self.inner.all_nodes().iter().filter_map(|n| n.data.as_ref()).collect() } pub fn edges(&self) -> Vec<(&DepNode, &DepNode)> { diff --git a/tests/run-make/dep-graph/rmake.rs b/tests/run-make/dep-graph/rmake.rs index 351418997f1dd..db2570ad82f61 100644 --- a/tests/run-make/dep-graph/rmake.rs +++ b/tests/run-make/dep-graph/rmake.rs @@ -1,18 +1,22 @@ -// Just verify that we successfully run and produce dep graphs when requested. +// Just verify that we successfully run and produce dep graphs when requested. The parallel +// frontend is covered too, because it leaves unused dep-graph indices that the dump must skip. //@ ignore-cross-compile use run_make_support::{path, rustc}; fn main() { - rustc() - .input("foo.rs") - .incremental(path("incr")) - .arg("-Zquery-dep-graph") - .arg("-Zdump-dep-graph") - .env("RUST_DEP_GRAPH", path("dep-graph")) - .run(); + for threads in ["1", "2"] { + rustc() + .input("foo.rs") + .incremental(path(format!("incr-{threads}"))) + .arg("-Zquery-dep-graph") + .arg("-Zdump-dep-graph") + .arg(format!("-Zthreads={threads}")) + .env("RUST_DEP_GRAPH", path(format!("dep-graph-{threads}"))) + .run(); - assert!(path("dep-graph.txt").is_file()); - assert!(path("dep-graph.dot").is_file()); + assert!(path(format!("dep-graph-{threads}.txt")).is_file()); + assert!(path(format!("dep-graph-{threads}.dot")).is_file()); + } } From 8e09973474cc3be4a454f9bedbdaee6fe985953b Mon Sep 17 00:00:00 2001 From: Makro Date: Tue, 28 Jul 2026 11:05:57 +0000 Subject: [PATCH 10/41] Distinguish the dep-graph index space from the live node count --- compiler/rustc_middle/src/dep_graph/graph.rs | 14 +++++++------- .../rustc_middle/src/dep_graph/serialized.rs | 17 ++++++++++++++--- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_middle/src/dep_graph/graph.rs b/compiler/rustc_middle/src/dep_graph/graph.rs index 7892404badef3..66ccde118a6f7 100644 --- a/compiler/rustc_middle/src/dep_graph/graph.rs +++ b/compiler/rustc_middle/src/dep_graph/graph.rs @@ -178,12 +178,12 @@ impl DepGraph { prev_work_products: WorkProductMap, encoder: FileEncoder<'static>, ) -> DepGraph { - let prev_graph_node_count = prev_graph.node_count(); + let prev_index_space_len = prev_graph.index_space_len(); let current = - CurrentDepGraph::new(session, prev_graph_node_count, encoder, Arc::clone(&prev_graph)); + CurrentDepGraph::new(session, prev_index_space_len, encoder, Arc::clone(&prev_graph)); - let colors = DepNodeColorMap::new(prev_graph_node_count); + let colors = DepNodeColorMap::new(prev_index_space_len); // Instantiate a node with zero dependencies only once for anonymous queries. let _green_node_index = current.alloc_new_node( @@ -202,7 +202,7 @@ impl DepGraph { Fingerprint::ZERO, ); assert_eq!(red_node_index, DepNodeIndex::FOREVER_RED_NODE); - if prev_graph_node_count > 0 { + if prev_index_space_len > 0 { let prev_index = const { SerializedDepNodeIndex::from_u32(DepNodeIndex::FOREVER_RED_NODE.as_u32()) }; let result = colors.try_set_color(prev_index, DesiredColor::Red); @@ -1199,7 +1199,7 @@ pub(super) struct CurrentDepGraph { impl CurrentDepGraph { fn new( session: &Session, - prev_graph_node_count: usize, + prev_index_space_len: usize, encoder: FileEncoder<'static>, previous: Arc, ) -> Self { @@ -1216,10 +1216,10 @@ impl CurrentDepGraph { Err(_) => None, }; - let new_node_count_estimate = 102 * prev_graph_node_count / 100 + 200; + let new_node_count_estimate = 102 * previous.live_node_count() / 100 + 200; CurrentDepGraph { - encoder: GraphEncoder::new(session, encoder, prev_graph_node_count, previous), + encoder: GraphEncoder::new(session, encoder, prev_index_space_len, previous), anon_node_to_index: ShardedHashMap::with_capacity( // FIXME: The count estimate is off as anon nodes are only a portion of the nodes. new_node_count_estimate / sharded::shards(), diff --git a/compiler/rustc_middle/src/dep_graph/serialized.rs b/compiler/rustc_middle/src/dep_graph/serialized.rs index 64275290fb8e6..daebc887055ac 100644 --- a/compiler/rustc_middle/src/dep_graph/serialized.rs +++ b/compiler/rustc_middle/src/dep_graph/serialized.rs @@ -116,6 +116,9 @@ pub struct SerializedDepGraph { /// [`SerializedDepNodeIndex`] via the node's key fingerprint. See /// [`LazyNodeIndex`]. reverse_index: LazyNodeIndex, + /// The number of nodes actually encoded, which is below [`Self::index_space_len`] + /// whenever a thread left part of its batch of indices unused. + live_node_count: usize, /// The number of previous compilation sessions. This is used to generate /// unique anon dep nodes per session. session_count: u64, @@ -133,6 +136,7 @@ impl std::fmt::Debug for SerializedDepGraph { .field("edge_list_indices", &self.edge_list_indices) .field("edge_list_data", &self.edge_list_data) .field("reverse_index", &self.reverse_index) + .field("live_node_count", &self.live_node_count) .field("session_count", &self.session_count) .finish_non_exhaustive() } @@ -251,11 +255,17 @@ impl SerializedDepGraph { self.value_fingerprints[dep_node_index] } + /// The number of dep-node indices, counting those that hold no node. #[inline] - pub fn node_count(&self) -> usize { + pub fn index_space_len(&self) -> usize { self.nodes.len() } + #[inline] + pub fn live_node_count(&self) -> usize { + self.live_node_count + } + #[inline] pub fn session_count(&self) -> u64 { self.session_count @@ -414,6 +424,7 @@ impl SerializedDepGraph { edge_list_indices, edge_list_data, reverse_index, + live_node_count: node_count, session_count, profiler: Some(profiler.clone()), }) @@ -892,14 +903,14 @@ impl GraphEncoder { pub(crate) fn new( sess: &Session, encoder: FileEncoder<'static>, - prev_node_count: usize, + prev_index_space_len: usize, previous: Arc, ) -> Self { let retained_graph = sess .opts .unstable_opts .query_dep_graph - .then(|| Lock::new(RetainedDepGraph::new(prev_node_count))); + .then(|| Lock::new(RetainedDepGraph::new(prev_index_space_len))); let status = EncoderState::new(encoder, sess.opts.unstable_opts.incremental_info, previous); GraphEncoder { status, retained_graph, profiler: sess.prof.clone() } } From 04d772fa04242dc1d86ab7b58253fcbc5cbf7467 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Fri, 19 Jun 2026 15:24:21 +0100 Subject: [PATCH 11/41] Make `AttributeParser::parse_limited` accept filters instead of symbol The existing API is preserved as `parse_limited_sym` as a simple helper. Similarly, `parse_limited_should_emit` is preserved as `parse_limited_sym_should_emit`. I've noted that all users targets crate, so the `target_node_id` and `target` parameters are removed from it. --- compiler/rustc_ast_passes/src/feature_gate.rs | 2 +- compiler/rustc_attr_parsing/src/interface.rs | 70 +++++++++++++------ .../src/deriving/generic/mod.rs | 2 +- .../src/proc_macro_harness.rs | 2 +- compiler/rustc_builtin_macros/src/test.rs | 2 +- .../rustc_builtin_macros/src/test_harness.rs | 2 +- compiler/rustc_expand/src/config.rs | 2 +- compiler/rustc_interface/src/passes.rs | 16 ++--- compiler/rustc_lint/src/builtin.rs | 2 +- compiler/rustc_lint/src/nonstandard_style.rs | 2 +- .../rustc_passes/src/debugger_visualizer.rs | 2 +- .../rustc_resolve/src/build_reduced_graph.rs | 2 +- .../rustc_resolve/src/diagnostics/impls.rs | 2 +- compiler/rustc_resolve/src/macros.rs | 2 +- 14 files changed, 65 insertions(+), 45 deletions(-) diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index bec96621fbfed..d1c1d172bef9e 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -634,7 +634,7 @@ fn maybe_stage_features(sess: &Session, features: &Features, krate: &ast::Crate) let mut errored = false; if let Some(Attribute::Parsed(AttributeKind::Feature(feature_idents, first_span))) = - AttributeParser::parse_limited(sess, &krate.attrs, &[sym::feature]) + AttributeParser::parse_limited_sym(sess, &krate.attrs, &[sym::feature]) { // `feature(...)` used on non-nightly. This is definitely an error. let mut err = diagnostics::FeatureOnNonNightly { diff --git a/compiler/rustc_attr_parsing/src/interface.rs b/compiler/rustc_attr_parsing/src/interface.rs index 30ff962c8bded..11048a9daa262 100644 --- a/compiler/rustc_attr_parsing/src/interface.rs +++ b/compiler/rustc_attr_parsing/src/interface.rs @@ -43,10 +43,10 @@ pub struct AttributeParser<'sess> { pub(crate) sess: &'sess Session, pub(crate) should_emit: ShouldEmit, - /// *Only* parse attributes with this symbol. + /// *Only* parse attributes that passes this filter. /// - /// Used in cases where we want the lowering infrastructure for parse just a single attribute. - parse_only: Option<&'static [Symbol]>, + /// Used in cases where we want the lowering infrastructure for parse just limited attributes. + parse_filter: Option<&'sess dyn Fn(&ast::Attribute) -> bool>, } impl<'sess> AttributeParser<'sess> { @@ -58,8 +58,8 @@ impl<'sess> AttributeParser<'sess> { /// `rustc_ast_lowering`. Some attributes require access to features to parse, which would /// crash if you tried to do so through [`parse_limited`](Self::parse_limited). /// - /// To make sure use is limited, supply a `Symbol` you'd like to parse. Only attributes with - /// that symbol are picked out of the list of instructions and parsed. Those are returned. + /// To make sure use is limited, supply a filter. Only attributes that passes the filter are + /// picked out of the list of instructions and parsed. Those are returned. /// /// No diagnostics will be emitted when parsing limited. Lints are not emitted at all, while /// errors will be emitted as a delayed bugs. in other words, we *expect* attributes parsed @@ -69,21 +69,29 @@ impl<'sess> AttributeParser<'sess> { pub fn parse_limited( sess: &'sess Session, attrs: &[ast::Attribute], - sym: &'static [Symbol], + parse_filter: &dyn Fn(&ast::Attribute) -> bool, ) -> Option { Self::parse_limited_should_emit( sess, attrs, - sym, + parse_filter, // Because we're not emitting warnings/errors, the target should not matter DUMMY_SP, - CRATE_NODE_ID, - Target::Crate, None, ShouldEmit::Nothing, ) } + /// This does the same as `parse_limited`, except that it takes a fixed symbol instead of a + /// filter. + pub fn parse_limited_sym( + sess: &'sess Session, + attrs: &[ast::Attribute], + sym: &'static [Symbol], + ) -> Option { + Self::parse_limited(sess, attrs, &|attr| attr.path_matches(sym)) + } + /// This does the same as `parse_limited`, except it has a `should_emit` parameter which allows it to emit errors. /// Usually you want `parse_limited`, which emits no errors. /// @@ -91,20 +99,18 @@ impl<'sess> AttributeParser<'sess> { pub fn parse_limited_should_emit( sess: &'sess Session, attrs: &[ast::Attribute], - sym: &'static [Symbol], + parse_filter: &dyn Fn(&ast::Attribute) -> bool, target_span: Span, - target_node_id: NodeId, - target: Target, features: Option<&'sess Features>, should_emit: ShouldEmit, ) -> Option { let mut parsed = Self::parse_limited_all( sess, attrs, - Some(sym), - target, + Some(parse_filter), + Target::Crate, target_span, - target_node_id, + CRATE_NODE_ID, features, should_emit, None, @@ -113,17 +119,37 @@ impl<'sess> AttributeParser<'sess> { parsed.pop() } + /// This does the same as `parse_limited_should_emit`, except that it takes a fixed symbol + /// instead of a filter. + pub fn parse_limited_sym_should_emit( + sess: &'sess Session, + attrs: &[ast::Attribute], + sym: &'static [Symbol], + target_span: Span, + features: Option<&'sess Features>, + should_emit: ShouldEmit, + ) -> Option { + Self::parse_limited_should_emit( + sess, + attrs, + &|attr| attr.path_matches(sym), + target_span, + features, + should_emit, + ) + } + /// This method allows you to parse a list of attributes *before* `rustc_ast_lowering`. /// This can be used for attributes that would be removed before `rustc_ast_lowering`, such as attributes on macro calls. /// /// Try to use this as little as possible. Attributes *should* be lowered during /// `rustc_ast_lowering`. Some attributes require access to features to parse, which would /// crash if you tried to do so through [`parse_limited_all`](Self::parse_limited_all). - /// Therefore, if `parse_only` is None, then features *must* be provided. + /// Therefore, if `parse_filter` is None, then features *must* be provided. pub fn parse_limited_all( sess: &'sess Session, attrs: &[ast::Attribute], - parse_only: Option<&'static [Symbol]>, + parse_filter: Option<&dyn Fn(&ast::Attribute) -> bool>, target: Target, target_span: Span, target_node_id: NodeId, @@ -131,7 +157,7 @@ impl<'sess> AttributeParser<'sess> { should_emit: ShouldEmit, tools: Option<&'sess RegisteredTools>, ) -> Vec { - let mut p = Self { features, tools, parse_only, sess, should_emit }; + let mut p = AttributeParser { features, tools, parse_filter, sess, should_emit }; p.parse_attribute_list( attrs, target_span, @@ -210,7 +236,7 @@ impl<'sess> AttributeParser<'sess> { parse_fn: fn(cx: &mut AcceptContext<'_, '_>, item: &I) -> T, template: &AttributeTemplate, ) -> T { - let mut parser = Self { features, tools: None, parse_only: None, sess, should_emit }; + let mut parser = Self { features, tools: None, parse_filter: None, sess, should_emit }; let mut emit_lint = |lint_id: LintId, span: MultiSpan, kind: EmitAttribute| { sess.psess.dyn_buffer_lint_sess(lint_id.lint, span, target_node_id, kind.0) }; @@ -253,7 +279,7 @@ impl<'sess> AttributeParser<'sess> { tools: &'sess RegisteredTools, should_emit: ShouldEmit, ) -> Self { - Self { features: Some(features), tools: Some(tools), parse_only: None, sess, should_emit } + Self { features: Some(features), tools: Some(tools), parse_filter: None, sess, should_emit } } pub(crate) fn sess(&self) -> &'sess Session { @@ -297,8 +323,8 @@ impl<'sess> AttributeParser<'sess> { for attr in attrs { // If we're only looking for a single attribute, skip all the ones we don't care about. - if let Some(expected) = self.parse_only { - if !attr.path_matches(expected) { + if let Some(filter) = self.parse_filter { + if !filter(attr) { continue; } } diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs index 1a0a65d4f7c64..cc036fab83c9d 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs @@ -493,7 +493,7 @@ impl<'a> TraitDef<'a> { match item { Annotatable::Item(item) => { let is_packed = matches!( - AttributeParser::parse_limited(cx.sess, &item.attrs, &[sym::repr]), + AttributeParser::parse_limited_sym(cx.sess, &item.attrs, &[sym::repr]), Some(Attribute::Parsed(AttributeKind::Repr { reprs, .. })) if reprs.iter().any(|(x, _)| matches!(x, ReprPacked(..))) ); diff --git a/compiler/rustc_builtin_macros/src/proc_macro_harness.rs b/compiler/rustc_builtin_macros/src/proc_macro_harness.rs index 404f2358ab863..8259758272e7e 100644 --- a/compiler/rustc_builtin_macros/src/proc_macro_harness.rs +++ b/compiler/rustc_builtin_macros/src/proc_macro_harness.rs @@ -100,7 +100,7 @@ impl<'a> CollectProcMacros<'a> { attr: &'a ast::Attribute, ) { let Some(rustc_hir::Attribute::Parsed(AttributeKind::ProcMacroDerive { .. })) = - AttributeParser::parse_limited( + AttributeParser::parse_limited_sym( self.session, slice::from_ref(attr), &[sym::proc_macro_derive], diff --git a/compiler/rustc_builtin_macros/src/test.rs b/compiler/rustc_builtin_macros/src/test.rs index 25ba01b275964..78d8f89b57f9e 100644 --- a/compiler/rustc_builtin_macros/src/test.rs +++ b/compiler/rustc_builtin_macros/src/test.rs @@ -486,7 +486,7 @@ fn should_ignore_message(i: &ast::Item) -> Option { fn should_panic(cx: &ExtCtxt<'_>, i: &ast::Item) -> ShouldPanic { if let Some(Attribute::Parsed(AttributeKind::ShouldPanic { reason, .. })) = - AttributeParser::parse_limited(cx.sess, &i.attrs, &[sym::should_panic]) + AttributeParser::parse_limited_sym(cx.sess, &i.attrs, &[sym::should_panic]) { ShouldPanic::Yes(reason) } else { diff --git a/compiler/rustc_builtin_macros/src/test_harness.rs b/compiler/rustc_builtin_macros/src/test_harness.rs index af0c9ed7ee656..ff9d9f10dd4e1 100644 --- a/compiler/rustc_builtin_macros/src/test_harness.rs +++ b/compiler/rustc_builtin_macros/src/test_harness.rs @@ -391,7 +391,7 @@ fn get_test_name(i: &ast::Item) -> Option { } fn get_test_runner(sess: &Session, krate: &ast::Crate) -> Option { - match AttributeParser::parse_limited(sess, &krate.attrs, &[sym::test_runner]) { + match AttributeParser::parse_limited_sym(sess, &krate.attrs, &[sym::test_runner]) { Some(rustc_hir::Attribute::Parsed(AttributeKind::TestRunner(path))) => Some(path), _ => None, } diff --git a/compiler/rustc_expand/src/config.rs b/compiler/rustc_expand/src/config.rs index 39d8afbba3c9d..af017bea67697 100644 --- a/compiler/rustc_expand/src/config.rs +++ b/compiler/rustc_expand/src/config.rs @@ -52,7 +52,7 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute], crate_name: Symbol) - let mut features = Features::default(); if let Some(hir::Attribute::Parsed(AttributeKind::Feature(feature_idents, _))) = - AttributeParser::parse_limited(sess, krate_attrs, &[sym::feature]) + AttributeParser::parse_limited_sym(sess, krate_attrs, &[sym::feature]) { for feature_ident in feature_idents { // If the enabled feature has been removed, issue an error. diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 2f32a6b208b6c..292b00a2d30ae 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -5,7 +5,7 @@ use std::path::{Path, PathBuf}; use std::sync::{Arc, LazyLock, OnceLock}; use std::{env, fs, iter}; -use rustc_ast::{self as ast, CRATE_NODE_ID}; +use rustc_ast as ast; use rustc_attr_parsing::{AttributeParser, ShouldEmit}; use rustc_codegen_ssa::traits::CodegenBackend; use rustc_codegen_ssa::{CompiledModules, CrateInfo}; @@ -23,7 +23,7 @@ use rustc_fs_util::try_canonicalize; use rustc_hir::attrs::AttributeKind; use rustc_hir::def_id::{LOCAL_CRATE, StableCrateId, StableCrateIdMap}; use rustc_hir::definitions::Definitions; -use rustc_hir::{Attribute, Target, find_attr}; +use rustc_hir::{Attribute, find_attr}; use rustc_incremental::setup_dep_graph; use rustc_lint::{BufferedEarlyLint, EarlyCheckNode, LintStore, unerased_lint_store}; use rustc_metadata::EncodedMetadata; @@ -1378,13 +1378,11 @@ pub(crate) fn parse_crate_name( emit_errors: ShouldEmit, ) -> Option<(Symbol, Span)> { let rustc_hir::Attribute::Parsed(AttributeKind::CrateName { name, name_span, .. }) = - AttributeParser::parse_limited_should_emit( + AttributeParser::parse_limited_sym_should_emit( sess, attrs, &[sym::crate_name], DUMMY_SP, - rustc_ast::node_id::CRATE_NODE_ID, - Target::Crate, None, emit_errors, )? @@ -1428,13 +1426,11 @@ pub fn collect_crate_types( let mut base = session.opts.crate_types.clone(); if base.is_empty() { if let Some(Attribute::Parsed(AttributeKind::CrateType(crate_type))) = - AttributeParser::parse_limited_should_emit( + AttributeParser::parse_limited_sym_should_emit( session, attrs, &[sym::crate_type], crate_span, - CRATE_NODE_ID, - Target::Crate, None, ShouldEmit::EarlyFatal { also_emit_lints: false }, ) @@ -1485,13 +1481,11 @@ fn default_output_for_target(sess: &Session) -> CrateType { } fn get_recursion_limit(krate_attrs: &[ast::Attribute], sess: &Session) -> Limit { - let attr = AttributeParser::parse_limited_should_emit( + let attr = AttributeParser::parse_limited_sym_should_emit( sess, &krate_attrs, &[sym::recursion_limit], DUMMY_SP, - rustc_ast::node_id::CRATE_NODE_ID, - Target::Crate, None, // errors are fatal here, but lints aren't. // If things aren't fatal we continue, and will parse this again. diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 3506868402c99..9b8398f755f64 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -243,7 +243,7 @@ impl EarlyLintPass for UnsafeCode { ast::ItemKind::MacroDef(..) => { if let Some(hir::Attribute::Parsed(AttributeKind::AllowInternalUnsafe(span))) = - AttributeParser::parse_limited( + AttributeParser::parse_limited_sym( cx.builder.sess(), &it.attrs, &[sym::allow_internal_unsafe], diff --git a/compiler/rustc_lint/src/nonstandard_style.rs b/compiler/rustc_lint/src/nonstandard_style.rs index f7f5708bd424e..5a1b56f004be0 100644 --- a/compiler/rustc_lint/src/nonstandard_style.rs +++ b/compiler/rustc_lint/src/nonstandard_style.rs @@ -160,7 +160,7 @@ impl NonCamelCaseTypes { impl EarlyLintPass for NonCamelCaseTypes { fn check_item(&mut self, cx: &EarlyContext<'_>, it: &ast::Item) { let has_repr_c = matches!( - AttributeParser::parse_limited(cx.sess(), &it.attrs, &[sym::repr]), + AttributeParser::parse_limited_sym(cx.sess(), &it.attrs, &[sym::repr]), Some(Attribute::Parsed(AttributeKind::Repr { reprs, ..})) if reprs.iter().any(|(r, _)| r == &ReprAttr::ReprC) ); diff --git a/compiler/rustc_passes/src/debugger_visualizer.rs b/compiler/rustc_passes/src/debugger_visualizer.rs index 493abd74cbfb8..459e6da7d961b 100644 --- a/compiler/rustc_passes/src/debugger_visualizer.rs +++ b/compiler/rustc_passes/src/debugger_visualizer.rs @@ -16,7 +16,7 @@ use crate::diagnostics::DebugVisualizerUnreadable; impl DebuggerVisualizerCollector<'_> { fn check_for_debugger_visualizer(&mut self, attrs: &[ast::Attribute]) { if let Some(Attribute::Parsed(AttributeKind::DebuggerVisualizer(visualizers))) = - AttributeParser::parse_limited(&self.sess, attrs, &[sym::debugger_visualizer]) + AttributeParser::parse_limited_sym(&self.sess, attrs, &[sym::debugger_visualizer]) { for DebugVisualizer { span, visualizer_type, path } in visualizers { let file = match resolve_path(&self.sess, path.as_str(), span) { diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index 970d7486d640c..4ce07ffe45ed7 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -1148,7 +1148,7 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> { let mut import_all = None; let mut single_imports = ThinVec::new(); if let Some(Attribute::Parsed(AttributeKind::MacroUse { span, arguments })) = - AttributeParser::parse_limited(self.r.tcx.sess, &item.attrs, &[sym::macro_use]) + AttributeParser::parse_limited_sym(self.r.tcx.sess, &item.attrs, &[sym::macro_use]) { if self.parent_scope.module.expect_local().parent.is_some() { self.r.dcx().emit_err(diagnostics::ExternCrateLoadingMacroNotAtCrateRoot { diff --git a/compiler/rustc_resolve/src/diagnostics/impls.rs b/compiler/rustc_resolve/src/diagnostics/impls.rs index 0b6b9899f48a6..96d926864fc87 100644 --- a/compiler/rustc_resolve/src/diagnostics/impls.rs +++ b/compiler/rustc_resolve/src/diagnostics/impls.rs @@ -4214,7 +4214,7 @@ impl OnUnknownData { ) -> Option { if r.features.diagnostic_on_unknown() && let Some(Attribute::Parsed(AttributeKind::OnUnknown { directive, .. })) = - AttributeParser::parse_limited( + AttributeParser::parse_limited_sym( r.tcx.sess, attrs, &[sym::diagnostic, sym::on_unknown], diff --git a/compiler/rustc_resolve/src/macros.rs b/compiler/rustc_resolve/src/macros.rs index f2c26caa58aab..9027b5a38c8b6 100644 --- a/compiler/rustc_resolve/src/macros.rs +++ b/compiler/rustc_resolve/src/macros.rs @@ -135,7 +135,7 @@ pub fn registered_tools_ast( let mut registered_tools = RegisteredTools::default(); if let Some(Attribute::Parsed(AttributeKind::RegisterTool(tools))) = - AttributeParser::parse_limited(sess, pre_configured_attrs, &[sym::register_tool]) + AttributeParser::parse_limited_sym(sess, pre_configured_attrs, &[sym::register_tool]) { for tool in tools { if let Some(old_tool) = registered_tools.replace(tool) { From 862dfb17e0192d181bcb04a97681769eedad8750 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Wed, 17 Jun 2026 15:32:42 +0100 Subject: [PATCH 12/41] Stop mentioning `register_attr` feature from `custom_attribute` It is also removed. --- compiler/rustc_feature/src/removed.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_feature/src/removed.rs b/compiler/rustc_feature/src/removed.rs index 6191269b24857..43de680bfa747 100644 --- a/compiler/rustc_feature/src/removed.rs +++ b/compiler/rustc_feature/src/removed.rs @@ -95,7 +95,7 @@ declare_features! ( (removed, crate_visibility_modifier, "1.63.0", Some(53120), Some("removed in favor of `pub(crate)`"), 97254), /// Allows using custom attributes (RFC 572). (removed, custom_attribute, "1.0.0", Some(29642), - Some("removed in favor of `#![register_tool]` and `#![register_attr]`"), 66070), + Some("removed in favor of `#![register_tool]`"), 66070), /// Allows the use of `#[derive(Anything)]` as sugar for `#[derive_Anything]`. (removed, custom_derive, "1.32.0", Some(29644), Some("subsumed by `#[proc_macro_derive]`")), From e15ac98c539a10b2bf64ebb99a960a4635ebdaf6 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Fri, 19 Jun 2026 14:56:12 +0100 Subject: [PATCH 13/41] Make `RegisterToolParser` implement `AttributeParser` directly --- .../src/attributes/crate_level.rs | 91 +++++++++++-------- compiler/rustc_attr_parsing/src/context.rs | 2 +- .../rustc_attr_parsing/src/diagnostics.rs | 12 ++- compiler/rustc_resolve/src/diagnostics/mod.rs | 10 -- compiler/rustc_resolve/src/macros.rs | 20 ++-- 5 files changed, 73 insertions(+), 62 deletions(-) diff --git a/compiler/rustc_attr_parsing/src/attributes/crate_level.rs b/compiler/rustc_attr_parsing/src/attributes/crate_level.rs index 4e10a2060b812..82bb6fd1aeb3b 100644 --- a/compiler/rustc_attr_parsing/src/attributes/crate_level.rs +++ b/compiler/rustc_attr_parsing/src/attributes/crate_level.rs @@ -1,3 +1,4 @@ +use rustc_data_structures::fx::FxIndexSet; use rustc_feature::AttributeStability; use rustc_hir::attrs::{CrateType, WindowsSubsystemKind}; use rustc_session::lint::builtin::UNKNOWN_CRATE_TYPES; @@ -5,7 +6,9 @@ use rustc_span::Symbol; use rustc_span::edit_distance::find_best_match_for_name_with_substrings; use super::prelude::*; -use crate::diagnostics::{UnknownCrateTypes, UnknownCrateTypesSuggestion}; +use crate::diagnostics::{ + ToolWasAlreadyRegistered, UnknownCrateTypes, UnknownCrateTypesSuggestion, +}; pub(crate) struct CrateNameParser; @@ -317,49 +320,65 @@ impl CombineAttributeParser for FeatureParser { } } -pub(crate) struct RegisterToolParser; +#[derive(Default)] +pub(crate) struct RegisterToolParser { + tools: FxIndexSet, +} -impl CombineAttributeParser for RegisterToolParser { - const PATH: &[Symbol] = &[sym::register_tool]; - type Item = Ident; - const CONVERT: ConvertFn = |tools, _span| AttributeKind::RegisterTool(tools); - const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[Allow(Target::Crate)]); - const TEMPLATE: AttributeTemplate = template!(List: &["tool1, tool2, ..."]); - const STABILITY: AttributeStability = unstable!(register_tool); +fn parse_register_tool( + tools: &mut FxIndexSet, + cx: &mut AcceptContext<'_, '_>, + args: &ArgParser, +) { + let Some(list) = cx.expect_list(args, cx.attr_span) else { + return; + }; + + if list.is_empty() { + let attr_span = cx.attr_span; + cx.adcx().warn_empty_attribute(attr_span); + } - fn extend( - cx: &mut AcceptContext<'_, '_>, - args: &ArgParser, - ) -> impl IntoIterator { - let Some(list) = cx.expect_list(args, cx.attr_span) else { - return Vec::new(); + for elem in list.mixed() { + let Some(elem) = elem.meta_item() else { + cx.adcx().expected_identifier(elem.span()); + continue; + }; + let Some(()) = cx.expect_no_args(elem.args()) else { + continue; }; - if list.is_empty() { - let attr_span = cx.attr_span; - cx.adcx().warn_empty_attribute(attr_span); - } + let path = elem.path(); + let Some(ident) = path.word() else { + cx.adcx().expected_identifier(path.span()); + continue; + }; - let mut res = Vec::new(); + if let Some(old_ident) = tools.replace(ident) { + cx.dcx().emit_err(ToolWasAlreadyRegistered { + span: ident.span, + tool: ident, + old_ident_span: old_ident.span, + }); + } + } +} - for elem in list.mixed() { - let Some(elem) = elem.meta_item() else { - cx.adcx().expected_identifier(elem.span()); - continue; - }; - let Some(()) = cx.expect_no_args(elem.args()) else { - continue; - }; +impl AttributeParser for RegisterToolParser { + const ATTRIBUTES: AcceptMapping = &[( + &[sym::register_tool], + template!(List: &["tool1, tool2, ..."]), + unstable!(register_tool), + |this, cx, args| parse_register_tool(&mut this.tools, cx, args), + )]; - let path = elem.path(); - let Some(ident) = path.word() else { - cx.adcx().expected_identifier(path.span()); - continue; - }; + const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[Allow(Target::Crate)]); - res.push(ident); + fn finalize(self, _cx: &FinalizeContext<'_, '_>) -> Option { + if self.tools.is_empty() { + None + } else { + Some(AttributeKind::RegisterTool(self.tools.into_iter().collect())) } - - res } } diff --git a/compiler/rustc_attr_parsing/src/context.rs b/compiler/rustc_attr_parsing/src/context.rs index ac65c6d581b9f..6254dd73f3263 100644 --- a/compiler/rustc_attr_parsing/src/context.rs +++ b/compiler/rustc_attr_parsing/src/context.rs @@ -174,6 +174,7 @@ attribute_parsers!( OnUnknownParser, OnUnmatchedArgsParser, OpaqueParser, + RegisterToolParser, RustcAlignParser, RustcAlignStaticParser, RustcCguTestAttributeParser, @@ -188,7 +189,6 @@ attribute_parsers!( Combine, Combine, Combine, - Combine, Combine, Combine, Combine, diff --git a/compiler/rustc_attr_parsing/src/diagnostics.rs b/compiler/rustc_attr_parsing/src/diagnostics.rs index fa7a5bc4e5078..3707d669bf36b 100644 --- a/compiler/rustc_attr_parsing/src/diagnostics.rs +++ b/compiler/rustc_attr_parsing/src/diagnostics.rs @@ -1,7 +1,7 @@ use rustc_errors::{Applicability, DiagArgValue, E0232, E0264, MultiSpan}; use rustc_hir::AttrPath; use rustc_macros::{Diagnostic, Subdiagnostic}; -use rustc_span::{Span, Symbol}; +use rustc_span::{Ident, Span, Symbol}; #[derive(Diagnostic)] #[diag("`{$name}` attribute cannot be used at crate level")] @@ -828,3 +828,13 @@ pub(crate) struct UnknownExternLangItem { pub span: Span, pub lang_item: Symbol, } + +#[derive(Diagnostic)] +#[diag("tool `{$tool}` was already registered")] +pub(crate) struct ToolWasAlreadyRegistered { + #[primary_span] + pub(crate) span: Span, + pub(crate) tool: Ident, + #[label("already registered here")] + pub(crate) old_ident_span: Span, +} diff --git a/compiler/rustc_resolve/src/diagnostics/mod.rs b/compiler/rustc_resolve/src/diagnostics/mod.rs index 9de2a682dc1fd..cadfab22c8862 100644 --- a/compiler/rustc_resolve/src/diagnostics/mod.rs +++ b/compiler/rustc_resolve/src/diagnostics/mod.rs @@ -1230,16 +1230,6 @@ pub(crate) struct CannotFindBuiltinMacroWithName { pub(crate) ident: Ident, } -#[derive(Diagnostic)] -#[diag("tool `{$tool}` was already registered")] -pub(crate) struct ToolWasAlreadyRegistered { - #[primary_span] - pub(crate) span: Span, - pub(crate) tool: Ident, - #[label("already registered here")] - pub(crate) old_ident_span: Span, -} - #[derive(Subdiagnostic)] pub(crate) enum DefinedHere { #[label("similarly named {$candidate_descr} `{$candidate}` defined here")] diff --git a/compiler/rustc_resolve/src/macros.rs b/compiler/rustc_resolve/src/macros.rs index 9027b5a38c8b6..9d1fbd642212a 100644 --- a/compiler/rustc_resolve/src/macros.rs +++ b/compiler/rustc_resolve/src/macros.rs @@ -128,25 +128,17 @@ pub(crate) fn registered_tools(tcx: TyCtxt<'_>, (): ()) -> RegisteredTools { } pub fn registered_tools_ast( - dcx: DiagCtxtHandle<'_>, + _dcx: DiagCtxtHandle<'_>, pre_configured_attrs: &[ast::Attribute], sess: &Session, ) -> RegisteredTools { - let mut registered_tools = RegisteredTools::default(); - - if let Some(Attribute::Parsed(AttributeKind::RegisterTool(tools))) = + let mut registered_tools = if let Some(Attribute::Parsed(AttributeKind::RegisterTool(tools))) = AttributeParser::parse_limited_sym(sess, pre_configured_attrs, &[sym::register_tool]) { - for tool in tools { - if let Some(old_tool) = registered_tools.replace(tool) { - dcx.emit_err(diagnostics::ToolWasAlreadyRegistered { - span: tool.span, - tool, - old_ident_span: old_tool.span, - }); - } - } - } + tools.into_iter().collect::() + } else { + Default::default() + }; // We implicitly add `rustfmt`, `clippy`, `diagnostic`, `miri` and `rust_analyzer` to known // tools, but it's not an error to register them explicitly. From 0c9efaa14b9806fd2763460a8ae8cd0f096bc2e7 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Wed, 17 Jun 2026 16:05:05 +0100 Subject: [PATCH 14/41] Split register_tool into register_attribute_tool and register_lint_tool This splits the functionality to two parts per RFC. The `#![register_tool]` attribute registers the tool in both ways. Semantics remain unchanged and will be adjusted in later commit. --- compiler/rustc_ast_lowering/src/lib.rs | 2 +- .../src/attributes/codegen_attrs.rs | 2 +- .../src/attributes/crate_level.rs | 54 ++++++++++----- compiler/rustc_attr_parsing/src/interface.rs | 18 +++-- compiler/rustc_driver_impl/src/lib.rs | 4 +- compiler/rustc_expand/src/base.rs | 9 ++- compiler/rustc_expand/src/expand.rs | 4 +- compiler/rustc_feature/src/builtin_attrs.rs | 2 + .../rustc_hir/src/attrs/data_structures.rs | 7 +- .../rustc_hir/src/attrs/encode_cross_crate.rs | 2 +- compiler/rustc_interface/src/passes.rs | 15 +++-- compiler/rustc_lint/src/context.rs | 8 +-- compiler/rustc_lint/src/early.rs | 4 +- compiler/rustc_lint/src/levels.rs | 19 +++--- compiler/rustc_middle/src/queries.rs | 12 +++- compiler/rustc_passes/src/check_attr.rs | 2 +- compiler/rustc_resolve/src/def_collector.rs | 2 +- .../rustc_resolve/src/diagnostics/impls.rs | 4 +- compiler/rustc_resolve/src/ident.rs | 8 +-- compiler/rustc_resolve/src/lib.rs | 24 ++++--- compiler/rustc_resolve/src/macros.rs | 67 +++++++++++++------ compiler/rustc_span/src/symbol.rs | 2 + 22 files changed, 174 insertions(+), 97 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 8a6a2aceedd2f..e9d3610cdde69 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -291,7 +291,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { attribute_parser: AttributeParser::new( tcx.sess, tcx.features(), - tcx.registered_tools(()), + tcx.registered_attr_tools(()), ShouldEmit::ErrorsAndLints { recovery: Recovery::Allowed }, ), delayed_lints: Vec::new(), diff --git a/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs b/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs index 28016aec48a50..ffa067479773f 100644 --- a/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs +++ b/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs @@ -280,7 +280,7 @@ impl AttributeParser for NakedParser { let span = self.span?; - let Some(tools) = cx.tools else { + let Some(tools) = cx.attr_tools else { unreachable!("tools required while parsing attributes"); }; diff --git a/compiler/rustc_attr_parsing/src/attributes/crate_level.rs b/compiler/rustc_attr_parsing/src/attributes/crate_level.rs index 82bb6fd1aeb3b..ba91fe2520d12 100644 --- a/compiler/rustc_attr_parsing/src/attributes/crate_level.rs +++ b/compiler/rustc_attr_parsing/src/attributes/crate_level.rs @@ -322,11 +322,12 @@ impl CombineAttributeParser for FeatureParser { #[derive(Default)] pub(crate) struct RegisterToolParser { - tools: FxIndexSet, + attr_tools: FxIndexSet, + lint_tools: FxIndexSet, } fn parse_register_tool( - tools: &mut FxIndexSet, + tools: &mut [&mut FxIndexSet], cx: &mut AcceptContext<'_, '_>, args: &ArgParser, ) { @@ -354,31 +355,52 @@ fn parse_register_tool( continue; }; - if let Some(old_ident) = tools.replace(ident) { - cx.dcx().emit_err(ToolWasAlreadyRegistered { - span: ident.span, - tool: ident, - old_ident_span: old_ident.span, - }); + for tools in tools.iter_mut() { + if let Some(old_ident) = tools.replace(ident) { + cx.dcx().emit_err(ToolWasAlreadyRegistered { + span: ident.span, + tool: ident, + old_ident_span: old_ident.span, + }); + } } } } impl AttributeParser for RegisterToolParser { - const ATTRIBUTES: AcceptMapping = &[( - &[sym::register_tool], - template!(List: &["tool1, tool2, ..."]), - unstable!(register_tool), - |this, cx, args| parse_register_tool(&mut this.tools, cx, args), - )]; + const ATTRIBUTES: AcceptMapping = &[ + ( + &[sym::register_tool], + template!(List: &["tool1, tool2, ..."]), + unstable!(register_tool), + |this, cx, args| { + parse_register_tool(&mut [&mut this.attr_tools, &mut this.lint_tools], cx, args) + }, + ), + ( + &[sym::register_attribute_tool], + template!(List: &["tool1, tool2, ..."]), + unstable!(register_tool), + |this, cx, args| parse_register_tool(&mut [&mut this.attr_tools], cx, args), + ), + ( + &[sym::register_lint_tool], + template!(List: &["tool1, tool2, ..."]), + unstable!(register_tool), + |this, cx, args| parse_register_tool(&mut [&mut this.lint_tools], cx, args), + ), + ]; const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[Allow(Target::Crate)]); fn finalize(self, _cx: &FinalizeContext<'_, '_>) -> Option { - if self.tools.is_empty() { + if self.attr_tools.is_empty() && self.lint_tools.is_empty() { None } else { - Some(AttributeKind::RegisterTool(self.tools.into_iter().collect())) + Some(AttributeKind::RegisterTool { + attr_tools: self.attr_tools.into_iter().collect(), + lint_tools: self.lint_tools.into_iter().collect(), + }) } } } diff --git a/compiler/rustc_attr_parsing/src/interface.rs b/compiler/rustc_attr_parsing/src/interface.rs index 11048a9daa262..cea549e310476 100644 --- a/compiler/rustc_attr_parsing/src/interface.rs +++ b/compiler/rustc_attr_parsing/src/interface.rs @@ -38,7 +38,7 @@ pub struct EmitAttribute( /// Context created once, for example as part of the ast lowering /// context, through which all attributes can be lowered. pub struct AttributeParser<'sess> { - pub(crate) tools: Option<&'sess RegisteredTools>, + pub(crate) attr_tools: Option<&'sess RegisteredTools>, pub(crate) features: Option<&'sess Features>, pub(crate) sess: &'sess Session, pub(crate) should_emit: ShouldEmit, @@ -155,9 +155,9 @@ impl<'sess> AttributeParser<'sess> { target_node_id: NodeId, features: Option<&'sess Features>, should_emit: ShouldEmit, - tools: Option<&'sess RegisteredTools>, + attr_tools: Option<&'sess RegisteredTools>, ) -> Vec { - let mut p = AttributeParser { features, tools, parse_filter, sess, should_emit }; + let mut p = AttributeParser { features, attr_tools, parse_filter, sess, should_emit }; p.parse_attribute_list( attrs, target_span, @@ -236,7 +236,7 @@ impl<'sess> AttributeParser<'sess> { parse_fn: fn(cx: &mut AcceptContext<'_, '_>, item: &I) -> T, template: &AttributeTemplate, ) -> T { - let mut parser = Self { features, tools: None, parse_filter: None, sess, should_emit }; + let mut parser = Self { features, attr_tools: None, parse_filter: None, sess, should_emit }; let mut emit_lint = |lint_id: LintId, span: MultiSpan, kind: EmitAttribute| { sess.psess.dyn_buffer_lint_sess(lint_id.lint, span, target_node_id, kind.0) }; @@ -276,10 +276,16 @@ impl<'sess> AttributeParser<'sess> { pub fn new( sess: &'sess Session, features: &'sess Features, - tools: &'sess RegisteredTools, + attr_tools: &'sess RegisteredTools, should_emit: ShouldEmit, ) -> Self { - Self { features: Some(features), tools: Some(tools), parse_filter: None, sess, should_emit } + Self { + features: Some(features), + attr_tools: Some(attr_tools), + parse_filter: None, + sess, + should_emit, + } } pub(crate) fn sess(&self) -> &'sess Session { diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs index 4411ecb4f128b..7b4c5626a79e1 100644 --- a/compiler/rustc_driver_impl/src/lib.rs +++ b/compiler/rustc_driver_impl/src/lib.rs @@ -712,13 +712,13 @@ fn print_crate_info( let crate_name = passes::get_crate_name(sess, attrs); let lint_store = crate::unerased_lint_store(sess); let features = rustc_expand::config::features(sess, attrs, crate_name); - let registered_tools = rustc_resolve::registered_tools_ast(sess.dcx(), attrs, sess); + let registered_lint_tools = rustc_resolve::registered_lint_tools_ast(sess, attrs); let builder = rustc_lint::LintLevelsBuilder::crate_root( sess, &features, true, lint_store, - ®istered_tools, + ®istered_lint_tools, attrs, ); for lint in lint_store.get_lints() { diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index 5c42f94f51ef8..f15b005960c9f 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -1111,8 +1111,11 @@ pub trait ResolverExpand { cfg_span: Span, ); - /// Tools registered with `#![register_tool]` and used by tool attributes and lints. - fn registered_tools(&self) -> &RegisteredTools; + /// Tools registered with `#![register_tool]` or `#![register_attribute_tool]`. + fn registered_attr_tools(&self) -> &RegisteredTools; + + /// Tools registered with `#![register_tool]` or `#![register_lint_tool]`. + fn registered_lint_tools(&self) -> &RegisteredTools; /// Mark this invocation id as a glob delegation. fn register_glob_delegation(&mut self, invoc_id: LocalExpnId); @@ -1139,7 +1142,7 @@ pub trait LintStoreExpand { &self, sess: &Session, features: &Features, - registered_tools: &RegisteredTools, + registered_lint_tools: &RegisteredTools, node_id: NodeId, attrs: &[Attribute], items: &[Box], diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 4f55e0506e799..187dcea4f91a5 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -1378,7 +1378,7 @@ impl InvocationCollectorNode for Box { lint_store.pre_expansion_lint( ecx.sess, ecx.ecfg.features, - ecx.resolver.registered_tools(), + ecx.resolver.registered_lint_tools(), ecx.current_expansion.lint_node_id, &node.attrs, &items, @@ -2231,7 +2231,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> { self.cx.current_expansion.lint_node_id, Some(self.cx.ecfg.features), ShouldEmit::ErrorsAndLints { recovery: Recovery::Allowed }, - Some(self.cx.resolver.registered_tools()), + Some(self.cx.resolver.registered_attr_tools()), ); let current_span = if let Some(sp) = span { sp.to(attr.span) } else { attr.span }; diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs index f966a547d7ed4..f4b3696a9d56e 100644 --- a/compiler/rustc_feature/src/builtin_attrs.rs +++ b/compiler/rustc_feature/src/builtin_attrs.rs @@ -185,6 +185,8 @@ pub static BUILTIN_ATTRIBUTES: &[Symbol] = &[ sym::ffi_pure, sym::ffi_const, + sym::register_attribute_tool, + sym::register_lint_tool, sym::register_tool, // `#[cfi_encoding = ""]` sym::cfi_encoding, diff --git a/compiler/rustc_hir/src/attrs/data_structures.rs b/compiler/rustc_hir/src/attrs/data_structures.rs index ff2e06eaca1d7..c86b04370e46d 100644 --- a/compiler/rustc_hir/src/attrs/data_structures.rs +++ b/compiler/rustc_hir/src/attrs/data_structures.rs @@ -1306,8 +1306,11 @@ pub enum AttributeKind { /// Represents `#[reexport_test_harness_main]` ReexportTestHarnessMain(Symbol), - /// Represents `#[register_tool]` - RegisterTool(ThinVec), + /// Represents `#[register_attribute_tool]`, `#[register_lint_tool]` and `#[register_tool]` + RegisterTool { + attr_tools: ThinVec, + lint_tools: ThinVec, + }, /// Represents [`#[repr]`](https://doc.rust-lang.org/stable/reference/type-layout.html#representations). Repr { diff --git a/compiler/rustc_hir/src/attrs/encode_cross_crate.rs b/compiler/rustc_hir/src/attrs/encode_cross_crate.rs index e2f46f360dd29..dded70ccd08ef 100644 --- a/compiler/rustc_hir/src/attrs/encode_cross_crate.rs +++ b/compiler/rustc_hir/src/attrs/encode_cross_crate.rs @@ -97,7 +97,7 @@ impl AttributeKind { ProfilerRuntime => No, RecursionLimit { .. } => No, ReexportTestHarnessMain(..) => No, - RegisterTool(..) => No, + RegisterTool { .. } => No, Repr { .. } => No, RustcAbi { .. } => No, RustcAlign { .. } => No, diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 292b00a2d30ae..20e2fc833c88d 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -87,7 +87,7 @@ fn pre_expansion_lint<'a>( sess: &Session, features: &Features, lint_store: &LintStore, - registered_tools: &RegisteredTools, + registered_lint_tools: &RegisteredTools, check_node: EarlyCheckNode<'a>, node_name: Symbol, ) { @@ -98,7 +98,7 @@ fn pre_expansion_lint<'a>( features, true, lint_store, - registered_tools, + registered_lint_tools, None, check_node, ); @@ -114,14 +114,14 @@ impl LintStoreExpand for LintStoreExpandImpl<'_> { &self, sess: &Session, features: &Features, - registered_tools: &RegisteredTools, + registered_lint_tools: &RegisteredTools, node_id: ast::NodeId, attrs: &[ast::Attribute], items: &[Box], name: Symbol, ) { let check_node = EarlyCheckNode::LoadedMod(node_id, attrs, items); - pre_expansion_lint(sess, features, self.0, registered_tools, check_node, name); + pre_expansion_lint(sess, features, self.0, registered_lint_tools, check_node, name); } } @@ -144,7 +144,7 @@ fn configure_and_expand( sess, features, lint_store, - tcx.registered_tools(()), + tcx.registered_lint_tools(()), EarlyCheckNode::CrateRoot(&krate, pre_configured_attrs), crate_name, ); @@ -475,7 +475,7 @@ fn early_lint_checks(tcx: TyCtxt<'_>, (): ()) { tcx.features(), false, lint_store, - tcx.registered_tools(()), + tcx.registered_lint_tools(()), Some(lint_buffer), EarlyCheckNode::CrateRoot(&*krate, &*krate.attrs), ) @@ -791,7 +791,8 @@ fn resolver_for_lowering_raw<'tcx>( &'tcx ty::ResolverGlobalCtxt, ) { let arenas = WorkerLocal::new(|_| Resolver::arenas()); - let _ = tcx.registered_tools(()); // Uses `crate_for_resolver`. + let _ = tcx.registered_attr_tools(()); // Uses `crate_for_resolver`. + let _ = tcx.registered_lint_tools(()); // Uses `crate_for_resolver`. let (krate, pre_configured_attrs) = tcx.crate_for_resolver(()).steal(); let mut resolver = Resolver::new( tcx, diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index 62db3208d521b..e32f04308b3d6 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -346,13 +346,13 @@ impl LintStore { &self, lint_name: &str, tool_name: Option, - registered_tools: &RegisteredTools, + registered_lint_tools: &RegisteredTools, ) -> CheckLintNameResult<'_> { if let Some(tool_name) = tool_name { // FIXME: rustc and rustdoc are considered tools for lints, but not for attributes. if tool_name != sym::rustc && tool_name != sym::rustdoc - && !registered_tools.contains(&Ident::with_dummy_span(tool_name)) + && !registered_lint_tools.contains(&Ident::with_dummy_span(tool_name)) { return CheckLintNameResult::NoTool; } @@ -572,7 +572,7 @@ impl<'a> EarlyContext<'a> { features: &'a Features, lint_added_lints: bool, lint_store: &'a LintStore, - registered_tools: &'a RegisteredTools, + registered_lint_tools: &'a RegisteredTools, buffered: LintBuffer, ) -> EarlyContext<'a> { EarlyContext { @@ -581,7 +581,7 @@ impl<'a> EarlyContext<'a> { features, lint_added_lints, lint_store, - registered_tools, + registered_lint_tools, ), buffered, } diff --git a/compiler/rustc_lint/src/early.rs b/compiler/rustc_lint/src/early.rs index 9c123f67abd5f..e7459eb86e4db 100644 --- a/compiler/rustc_lint/src/early.rs +++ b/compiler/rustc_lint/src/early.rs @@ -314,7 +314,7 @@ pub fn check_ast_node<'a>( features: &Features, pre_expansion: bool, lint_store: &LintStore, - registered_tools: &RegisteredTools, + registered_lint_tools: &RegisteredTools, lint_buffer: Option, check_node: EarlyCheckNode<'a>, ) { @@ -323,7 +323,7 @@ pub fn check_ast_node<'a>( features, !pre_expansion, lint_store, - registered_tools, + registered_lint_tools, lint_buffer.unwrap_or_default(), ); diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs index ef23085417352..5671e86283f9b 100644 --- a/compiler/rustc_lint/src/levels.rs +++ b/compiler/rustc_lint/src/levels.rs @@ -171,7 +171,7 @@ fn shallow_lint_levels_on(tcx: TyCtxt<'_>, owner: hir::OwnerId) -> ShallowLintLe }, lint_added_lints: false, store, - registered_tools: tcx.registered_tools(()), + registered_lint_tools: tcx.registered_lint_tools(()), }; if owner == hir::CRATE_OWNER_ID { @@ -389,7 +389,7 @@ pub struct LintLevelsBuilder<'s, P> { provider: P, lint_added_lints: bool, store: &'s LintStore, - registered_tools: &'s RegisteredTools, + registered_lint_tools: &'s RegisteredTools, } pub(crate) struct BuilderPush { @@ -402,7 +402,7 @@ impl<'s> LintLevelsBuilder<'s, TopDown> { features: &'s Features, lint_added_lints: bool, store: &'s LintStore, - registered_tools: &'s RegisteredTools, + registered_lint_tools: &'s RegisteredTools, ) -> Self { let mut builder = LintLevelsBuilder { sess, @@ -410,7 +410,7 @@ impl<'s> LintLevelsBuilder<'s, TopDown> { provider: TopDown { sets: LintLevelSets::new(), cur: COMMAND_LINE }, lint_added_lints, store, - registered_tools, + registered_lint_tools, }; builder.process_command_line(); assert_eq!(builder.provider.sets.list.len(), 1); @@ -422,10 +422,10 @@ impl<'s> LintLevelsBuilder<'s, TopDown> { features: &'s Features, lint_added_lints: bool, store: &'s LintStore, - registered_tools: &'s RegisteredTools, + registered_lint_tools: &'s RegisteredTools, crate_attrs: &[ast::Attribute], ) -> Self { - let mut builder = Self::new(sess, features, lint_added_lints, store, registered_tools); + let mut builder = Self::new(sess, features, lint_added_lints, store, registered_lint_tools); builder.add(crate_attrs, true); builder } @@ -503,7 +503,8 @@ where .dcx() .emit_err(UnsupportedGroup { lint_group: crate::WARNINGS.name_lower() }); } - match self.store.check_lint_name(lint_name_only, tool_name, self.registered_tools) { + match self.store.check_lint_name(lint_name_only, tool_name, self.registered_lint_tools) + { CheckLintNameResult::Renamed(ref replace) => { let name = lint_name.as_str(); let suggestion = RenamedLintSuggestion::WithoutSpan { replace }; @@ -768,7 +769,7 @@ where let tool_name = tool_ident.map(|ident| ident.name); let name = pprust::path_to_string(&meta_item.path); let lint_result = - self.store.check_lint_name(&name, tool_name, self.registered_tools); + self.store.check_lint_name(&name, tool_name, self.registered_lint_tools); let (ids, name) = match lint_result { CheckLintNameResult::Ok(ids) => { @@ -837,7 +838,7 @@ where // NOTE: `new_name` already includes the tool name, so we don't // have to add it again. let CheckLintNameResult::Ok(ids) = - self.store.check_lint_name(replace, None, self.registered_tools) + self.store.check_lint_name(replace, None, self.registered_lint_tools) else { panic!("renamed lint does not exist: {replace}"); }; diff --git a/compiler/rustc_middle/src/queries.rs b/compiler/rustc_middle/src/queries.rs index 7aeff35a965f2..d455abeaf23ac 100644 --- a/compiler/rustc_middle/src/queries.rs +++ b/compiler/rustc_middle/src/queries.rs @@ -150,10 +150,16 @@ rustc_queries! { desc { "triggering a delayed bug for testing incremental" } } - /// Collects the list of all tools registered using `#![register_tool]`. - query registered_tools(_: ()) -> &'tcx ty::RegisteredTools { + /// Collects the list of all tools registered using `#![register_tool]` or `#![register_attribute_tool]`. + query registered_attr_tools(_: ()) -> &'tcx ty::RegisteredTools { arena_cache - desc { "compute registered tools for crate" } + desc { "compute registered attribute tools for crate" } + } + + /// Collects the list of all tools registered using `#![register_tool]` or `#![register_lint_tool]`. + query registered_lint_tools(_: ()) -> &'tcx ty::RegisteredTools { + arena_cache + desc { "compute registered lint tools for crate" } } query early_lint_checks(_: ()) { diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 572d9cd1da957..6a02a52cddde8 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -300,7 +300,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { AttributeKind::ProfilerRuntime => (), AttributeKind::RecursionLimit { .. } => (), AttributeKind::ReexportTestHarnessMain(..) => (), - AttributeKind::RegisterTool(..) => (), + AttributeKind::RegisterTool { .. } => (), // handled below this loop and elsewhere AttributeKind::Repr { .. } => (), AttributeKind::RustcAbi { .. } => (), diff --git a/compiler/rustc_resolve/src/def_collector.rs b/compiler/rustc_resolve/src/def_collector.rs index 0b54b265fcee7..63bff7a3f4498 100644 --- a/compiler/rustc_resolve/src/def_collector.rs +++ b/compiler/rustc_resolve/src/def_collector.rs @@ -180,7 +180,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> { let mut parser = AttributeParser::new( &self.r.tcx.sess, self.r.features, - self.r.tcx().registered_tools(()), + self.r.tcx().registered_attr_tools(()), ShouldEmit::Nothing, ); let attrs = parser.parse_attribute_list( diff --git a/compiler/rustc_resolve/src/diagnostics/impls.rs b/compiler/rustc_resolve/src/diagnostics/impls.rs index 96d926864fc87..5ff31f5d90834 100644 --- a/compiler/rustc_resolve/src/diagnostics/impls.rs +++ b/compiler/rustc_resolve/src/diagnostics/impls.rs @@ -1526,10 +1526,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { })); } Scope::ExternPreludeFlags => {} - Scope::ToolPrelude => { + Scope::ToolAttributePrelude => { let res = Res::NonMacroAttr(NonMacroAttrKind::Tool); suggestions.extend( - this.registered_tools + this.registered_attr_tools .iter() .map(|ident| TypoSuggestion::new(ident.name, ident.span, res)), ); diff --git a/compiler/rustc_resolve/src/ident.rs b/compiler/rustc_resolve/src/ident.rs index d18180ea64afc..1c94779a6009a 100644 --- a/compiler/rustc_resolve/src/ident.rs +++ b/compiler/rustc_resolve/src/ident.rs @@ -159,7 +159,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { Scope::ExternPreludeItems | Scope::ExternPreludeFlags => { use_prelude || module_and_extern_prelude || extern_prelude } - Scope::ToolPrelude => use_prelude, + Scope::ToolAttributePrelude => use_prelude, Scope::StdLibPrelude => use_prelude || ns == MacroNS, Scope::BuiltinTypes => true, }; @@ -225,8 +225,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { Scope::BuiltinAttrs => break, // nowhere else to search Scope::ExternPreludeItems => Scope::ExternPreludeFlags, Scope::ExternPreludeFlags if module_and_extern_prelude || extern_prelude => break, - Scope::ExternPreludeFlags => Scope::ToolPrelude, - Scope::ToolPrelude => Scope::StdLibPrelude, + Scope::ExternPreludeFlags => Scope::ToolAttributePrelude, + Scope::ToolAttributePrelude => Scope::StdLibPrelude, Scope::StdLibPrelude => match ns { TypeNS => Scope::BuiltinTypes, ValueNS => break, // nowhere else to search @@ -738,7 +738,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { None => Err(Determinacy::Determined), } } - Scope::ToolPrelude => match self.registered_tool_decls.get(&ident) { + Scope::ToolAttributePrelude => match self.registered_attr_tool_decls.get(&ident) { Some(decl) => Ok(*decl), None => Err(Determinacy::Determined), }, diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 111eae6a4134f..2dbf32dc20288 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -35,7 +35,7 @@ use late::{ ForwardGenericParamBanReason, HasGenericParams, PathSource, PatternSource, UnnecessaryQualification, }; -pub use macros::registered_tools_ast; +pub use macros::registered_lint_tools_ast; use macros::{MacroRulesDecl, MacroRulesScope, MacroRulesScopeRef}; use rustc_arena::{DroplessArena, TypedArena}; use rustc_ast::node_id::NodeMap; @@ -135,8 +135,8 @@ enum Scope<'ra> { ExternPreludeItems, /// Extern prelude names introduced by `--extern` flags. ExternPreludeFlags, - /// Tool modules introduced with `#![register_tool]`. - ToolPrelude, + /// Tool modules introduced with `#![register_tool]` or `#![register_attribute_tool]`. + ToolAttributePrelude, /// Standard library prelude introduced with an internal `#[prelude_import]` import. StdLibPrelude, /// Built-in types. @@ -1403,10 +1403,11 @@ pub struct Resolver<'ra, 'tcx> { dummy_decl: Decl<'ra>, builtin_type_decls: FxHashMap>, builtin_attr_decls: FxHashMap>, - registered_tool_decls: FxHashMap>, + registered_attr_tool_decls: FxHashMap>, macro_names: FxHashSet = default::fx_hash_set(), builtin_macros: FxHashMap = default::fx_hash_map(), - registered_tools: &'tcx RegisteredTools, + registered_attr_tools: &'tcx RegisteredTools, + registered_lint_tools: &'tcx RegisteredTools, macro_use_prelude: FxIndexMap>, /// Eagerly populated map of all local macro definitions. local_macro_map: FxHashMap> = default::fx_hash_map(), @@ -1786,7 +1787,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { invocation_parents.insert(LocalExpnId::ROOT, InvocationParent::ROOT); let extern_prelude = build_extern_prelude(tcx, attrs); - let registered_tools = tcx.registered_tools(()); + let registered_attr_tools = tcx.registered_attr_tools(()); + let registered_lint_tools = tcx.registered_lint_tools(()); let edition = tcx.sess.edition(); let mut resolver = Resolver { @@ -1824,7 +1826,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { (*builtin_attr, decl) }) .collect(), - registered_tool_decls: registered_tools + registered_attr_tool_decls: registered_attr_tools .iter() .map(|&ident| { let res = Res::ToolMod; @@ -1832,7 +1834,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { (IdentKey::new(ident), decl) }) .collect(), - registered_tools, + registered_attr_tools, + registered_lint_tools, macro_use_prelude: Default::default(), extern_macro_map: Default::default(), dummy_ext_bang: arenas.alloc_macro(SyntaxExtension::dummy_bang(edition)), @@ -2092,7 +2095,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { } Scope::ExternPreludeItems | Scope::ExternPreludeFlags - | Scope::ToolPrelude + | Scope::ToolAttributePrelude | Scope::BuiltinTypes => {} _ => unreachable!(), } @@ -2780,7 +2783,8 @@ impl Finalize { } pub fn provide(providers: &mut Providers) { - providers.registered_tools = macros::registered_tools; + providers.registered_attr_tools = macros::registered_attr_tools; + providers.registered_lint_tools = macros::registered_lint_tools; } /// A wrapper around `&mut Resolver` that may be mutable or immutable, depending on a conditions. diff --git a/compiler/rustc_resolve/src/macros.rs b/compiler/rustc_resolve/src/macros.rs index 9d1fbd642212a..54f9aa8e914ec 100644 --- a/compiler/rustc_resolve/src/macros.rs +++ b/compiler/rustc_resolve/src/macros.rs @@ -7,7 +7,7 @@ use std::sync::Arc; use rustc_ast::{self as ast, Crate, DelegationSuffixes, NodeId}; use rustc_ast_pretty::pprust; use rustc_attr_parsing::AttributeParser; -use rustc_errors::{Applicability, DiagCtxtHandle, StashKey}; +use rustc_errors::{Applicability, StashKey}; use rustc_expand::base::{ Annotatable, DeriveResolution, Indeterminate, ResolverExpand, SyntaxExtension, SyntaxExtensionKind, @@ -122,29 +122,52 @@ fn fast_print_path(path: &ast::Path) -> Symbol { } } -pub(crate) fn registered_tools(tcx: TyCtxt<'_>, (): ()) -> RegisteredTools { +const PREDEFINED_TOOLS: &[Symbol] = + &[sym::clippy, sym::rustfmt, sym::diagnostic, sym::miri, sym::rust_analyzer]; + +pub(crate) fn registered_attr_tools(tcx: TyCtxt<'_>, (): ()) -> RegisteredTools { let (_, pre_configured_attrs) = &*tcx.crate_for_resolver(()).borrow(); - registered_tools_ast(tcx.dcx(), pre_configured_attrs, tcx.sess) + + let mut registered_tools = + if let Some(Attribute::Parsed(AttributeKind::RegisterTool { attr_tools, .. })) = + AttributeParser::parse_limited(tcx.sess, pre_configured_attrs, &|attr| { + attr.path_matches(&[sym::register_tool]) + || attr.path_matches(&[sym::register_attribute_tool]) + }) + { + attr_tools.into_iter().collect::() + } else { + Default::default() + }; + + // We implicitly add predefined tools, but it's not an error to register them explicitly. + registered_tools.extend(PREDEFINED_TOOLS.iter().cloned().map(Ident::with_dummy_span)); + registered_tools } -pub fn registered_tools_ast( - _dcx: DiagCtxtHandle<'_>, - pre_configured_attrs: &[ast::Attribute], +pub(crate) fn registered_lint_tools(tcx: TyCtxt<'_>, (): ()) -> RegisteredTools { + let (_, pre_configured_attrs) = &*tcx.crate_for_resolver(()).borrow(); + registered_lint_tools_ast(tcx.sess, pre_configured_attrs) +} + +pub fn registered_lint_tools_ast( sess: &Session, + pre_configured_attrs: &[ast::Attribute], ) -> RegisteredTools { - let mut registered_tools = if let Some(Attribute::Parsed(AttributeKind::RegisterTool(tools))) = - AttributeParser::parse_limited_sym(sess, pre_configured_attrs, &[sym::register_tool]) - { - tools.into_iter().collect::() - } else { - Default::default() - }; + let mut registered_tools = + if let Some(Attribute::Parsed(AttributeKind::RegisterTool { lint_tools, .. })) = + AttributeParser::parse_limited(sess, pre_configured_attrs, &|attr| { + attr.path_matches(&[sym::register_tool]) + || attr.path_matches(&[sym::register_lint_tool]) + }) + { + lint_tools.into_iter().collect::() + } else { + Default::default() + }; - // We implicitly add `rustfmt`, `clippy`, `diagnostic`, `miri` and `rust_analyzer` to known - // tools, but it's not an error to register them explicitly. - let predefined_tools = - [sym::clippy, sym::rustfmt, sym::diagnostic, sym::miri, sym::rust_analyzer]; - registered_tools.extend(predefined_tools.iter().cloned().map(Ident::with_dummy_span)); + // We implicitly add predefined tools, but it's not an error to register them explicitly. + registered_tools.extend(PREDEFINED_TOOLS.iter().cloned().map(Ident::with_dummy_span)); registered_tools } @@ -520,8 +543,12 @@ impl<'ra, 'tcx> ResolverExpand for Resolver<'ra, 'tcx> { }); } - fn registered_tools(&self) -> &RegisteredTools { - self.registered_tools + fn registered_attr_tools(&self) -> &RegisteredTools { + self.registered_attr_tools + } + + fn registered_lint_tools(&self) -> &RegisteredTools { + self.registered_lint_tools } fn register_glob_delegation(&mut self, invoc_id: LocalExpnId) { diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index e533458ab53aa..39e6f7445b09c 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1692,6 +1692,8 @@ symbols! { reg_ptr, reg_upper, register_attr, + register_attribute_tool, + register_lint_tool, register_tool, relaxed_adts, relaxed_struct_unsize, From ade1d273b8f4154f46d9cfb18a759bb127270b39 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Wed, 17 Jun 2026 16:45:50 +0100 Subject: [PATCH 15/41] Remove duplicate tool error and add reserved error Under the RFC, it's not an error to register tool multiple times, but it is an error to register "rustc" tool. --- .../src/attributes/crate_level.rs | 18 ++++++++---------- compiler/rustc_attr_parsing/src/diagnostics.rs | 6 ++---- tests/ui/tool-attributes/duplicate-tool.rs | 15 +++++++++++++++ tests/ui/tool-attributes/predefined-tool.rs | 11 +++++++++++ .../ui/tool-attributes/predefined-tool.stderr | 8 ++++++++ 5 files changed, 44 insertions(+), 14 deletions(-) create mode 100644 tests/ui/tool-attributes/duplicate-tool.rs create mode 100644 tests/ui/tool-attributes/predefined-tool.rs create mode 100644 tests/ui/tool-attributes/predefined-tool.stderr diff --git a/compiler/rustc_attr_parsing/src/attributes/crate_level.rs b/compiler/rustc_attr_parsing/src/attributes/crate_level.rs index ba91fe2520d12..930f87e697c04 100644 --- a/compiler/rustc_attr_parsing/src/attributes/crate_level.rs +++ b/compiler/rustc_attr_parsing/src/attributes/crate_level.rs @@ -6,9 +6,7 @@ use rustc_span::Symbol; use rustc_span::edit_distance::find_best_match_for_name_with_substrings; use super::prelude::*; -use crate::diagnostics::{ - ToolWasAlreadyRegistered, UnknownCrateTypes, UnknownCrateTypesSuggestion, -}; +use crate::diagnostics::{ToolReserved, UnknownCrateTypes, UnknownCrateTypesSuggestion}; pub(crate) struct CrateNameParser; @@ -355,14 +353,14 @@ fn parse_register_tool( continue; }; + if ident.name == sym::rustc { + cx.should_emit + .emit_err(cx.dcx().create_err(ToolReserved { span: ident.span, tool: ident })); + continue; + } + for tools in tools.iter_mut() { - if let Some(old_ident) = tools.replace(ident) { - cx.dcx().emit_err(ToolWasAlreadyRegistered { - span: ident.span, - tool: ident, - old_ident_span: old_ident.span, - }); - } + tools.insert(ident); } } } diff --git a/compiler/rustc_attr_parsing/src/diagnostics.rs b/compiler/rustc_attr_parsing/src/diagnostics.rs index 3707d669bf36b..d5ea103dd1ae3 100644 --- a/compiler/rustc_attr_parsing/src/diagnostics.rs +++ b/compiler/rustc_attr_parsing/src/diagnostics.rs @@ -830,11 +830,9 @@ pub(crate) struct UnknownExternLangItem { } #[derive(Diagnostic)] -#[diag("tool `{$tool}` was already registered")] -pub(crate) struct ToolWasAlreadyRegistered { +#[diag("tool `{$tool}` is reserved and cannot be registered")] +pub(crate) struct ToolReserved { #[primary_span] pub(crate) span: Span, pub(crate) tool: Ident, - #[label("already registered here")] - pub(crate) old_ident_span: Span, } diff --git a/tests/ui/tool-attributes/duplicate-tool.rs b/tests/ui/tool-attributes/duplicate-tool.rs new file mode 100644 index 0000000000000..603292d1eb3cd --- /dev/null +++ b/tests/ui/tool-attributes/duplicate-tool.rs @@ -0,0 +1,15 @@ +//@ check-pass +#![feature(register_tool)] +// Register a tool multiple times is okay. +#![register_tool(foo)] +#![register_tool(foo)] +#![register_tool(bar)] +#![register_attribute_tool(bar)] +#![register_tool(baz)] +#![register_lint_tool(baz)] +#![register_attribute_tool(qux)] +#![register_attribute_tool(qux)] +#![register_lint_tool(quux)] +#![register_lint_tool(quux)] + +fn main() {} diff --git a/tests/ui/tool-attributes/predefined-tool.rs b/tests/ui/tool-attributes/predefined-tool.rs new file mode 100644 index 0000000000000..7181012d6827e --- /dev/null +++ b/tests/ui/tool-attributes/predefined-tool.rs @@ -0,0 +1,11 @@ +#![feature(register_tool)] +// Registering predefined tool is okay. +#![register_tool(clippy)] +#![register_attribute_tool(miri)] +#![register_lint_tool(rustfmt)] +#![register_tool(diagnostic)] +#![register_attribute_tool(rust_analyzer)] +// Registering "rustc" is an error. +#![register_tool(rustc)] //~ ERROR reserved + +fn main() {} diff --git a/tests/ui/tool-attributes/predefined-tool.stderr b/tests/ui/tool-attributes/predefined-tool.stderr new file mode 100644 index 0000000000000..d9b19f2177ab9 --- /dev/null +++ b/tests/ui/tool-attributes/predefined-tool.stderr @@ -0,0 +1,8 @@ +error: tool `rustc` is reserved and cannot be registered + --> $DIR/predefined-tool.rs:9:18 + | +LL | #![register_tool(rustc)] + | ^^^^^ + +error: aborting due to 1 previous error + From 294100dd24594444a26895728b88a7fd7f779ee7 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Wed, 17 Jun 2026 16:57:32 +0100 Subject: [PATCH 16/41] Add test for `register_{attribute,lint}_tool` with cfg --- tests/ui/tool-attributes/cfg-register.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 tests/ui/tool-attributes/cfg-register.rs diff --git a/tests/ui/tool-attributes/cfg-register.rs b/tests/ui/tool-attributes/cfg-register.rs new file mode 100644 index 0000000000000..c835e6bd54740 --- /dev/null +++ b/tests/ui/tool-attributes/cfg-register.rs @@ -0,0 +1,12 @@ +//@ check-pass +// +//@revisions: tool split_attr_lint + +#![feature(register_tool)] +#![cfg_attr(tool, register_tool(foo, bar))] +#![cfg_attr(split_attr_lint, register_attribute_tool(foo))] +#![cfg_attr(split_attr_lint, register_lint_tool(bar))] + +#[foo::a] +#[allow(bar::b)] +fn main() {} From 9784797078e0b97278f00ac6f4058c397584724f Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Mon, 27 Jul 2026 20:05:56 +0100 Subject: [PATCH 17/41] Expand register_tool feature gate test to cover attr and lint tool --- .../feature-gate-register_tool.rs | 2 ++ .../feature-gate-register_tool.stderr | 22 ++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/ui/feature-gates/feature-gate-register_tool.rs b/tests/ui/feature-gates/feature-gate-register_tool.rs index 82f757a03af10..4034a95e8fb65 100644 --- a/tests/ui/feature-gates/feature-gate-register_tool.rs +++ b/tests/ui/feature-gates/feature-gate-register_tool.rs @@ -1,3 +1,5 @@ #![register_tool(tool)] //~ ERROR the `register_tool` attribute is an experimental feature +#![register_attribute_tool(attr_tool)] //~ ERROR the `register_attribute_tool` attribute is an experimental feature +#![register_lint_tool(lint_tool)] //~ ERROR the `register_lint_tool` attribute is an experimental feature fn main() {} diff --git a/tests/ui/feature-gates/feature-gate-register_tool.stderr b/tests/ui/feature-gates/feature-gate-register_tool.stderr index fdb556926f6f7..678ae48a00143 100644 --- a/tests/ui/feature-gates/feature-gate-register_tool.stderr +++ b/tests/ui/feature-gates/feature-gate-register_tool.stderr @@ -8,6 +8,26 @@ LL | #![register_tool(tool)] = help: add `#![feature(register_tool)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date -error: aborting due to 1 previous error +error[E0658]: the `register_attribute_tool` attribute is an experimental feature + --> $DIR/feature-gate-register_tool.rs:2:4 + | +LL | #![register_attribute_tool(attr_tool)] + | ^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #66079 for more information + = help: add `#![feature(register_tool)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: the `register_lint_tool` attribute is an experimental feature + --> $DIR/feature-gate-register_tool.rs:3:4 + | +LL | #![register_lint_tool(lint_tool)] + | ^^^^^^^^^^^^^^^^^^ + | + = note: see issue #66079 for more information + = help: add `#![feature(register_tool)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0658`. From 1e68dafa04f28616a74d37d94d015f5339b908a6 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Mon, 27 Jul 2026 20:09:12 +0100 Subject: [PATCH 18/41] Add register_{attribute,lint}_tool test with crate-attr --- tests/ui/tool-attributes/crate-attr.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/ui/tool-attributes/crate-attr.rs b/tests/ui/tool-attributes/crate-attr.rs index c6d7974945f4a..b2fd0dbd2ad2c 100644 --- a/tests/ui/tool-attributes/crate-attr.rs +++ b/tests/ui/tool-attributes/crate-attr.rs @@ -1,5 +1,7 @@ //@ check-pass //@ compile-flags: -Z crate-attr=feature(register_tool) -Z crate-attr=register_tool(foo) +//@ compile-flags: -Z crate-attr=register_attribute_tool(bar) -Z crate-attr=register_lint_tool(baz) -#[allow(foo::bar)] +#[allow(foo::bar, baz::quuxx)] +#[bar::qux] fn main() {} From e8243184c025f293406a4208337c9d838609d283 Mon Sep 17 00:00:00 2001 From: Syvraa <66771495+Syvraa@users.noreply.github.com> Date: Thu, 23 Jul 2026 15:33:33 +0200 Subject: [PATCH 19/41] remove const hack in alloc --- library/alloc/src/raw_vec/mod.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/library/alloc/src/raw_vec/mod.rs b/library/alloc/src/raw_vec/mod.rs index 843d0346ff5de..5d4ad3ac4bf98 100644 --- a/library/alloc/src/raw_vec/mod.rs +++ b/library/alloc/src/raw_vec/mod.rs @@ -560,11 +560,7 @@ const impl RawVecInner { self.alloc.allocate(new_layout) }; - // FIXME(const-hack): switch back to `map_err` - match memory { - Ok(memory) => Ok(memory), - Err(_) => Err(AllocError { layout: new_layout, non_exhaustive: () }.into()), - } + memory.map_err(const |_| AllocError { layout: new_layout, non_exhaustive: () }.into()) } } From 062480a089a7f48b7bf89d8219896ba0065cffa5 Mon Sep 17 00:00:00 2001 From: xonx <119700621+xonx4l@users.noreply.github.com> Date: Sun, 26 Jul 2026 18:07:29 +0000 Subject: [PATCH 20/41] run intrinsic-test by default on x86_64-gnu --- src/ci/docker/host-x86_64/x86_64-gnu/Dockerfile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ci/docker/host-x86_64/x86_64-gnu/Dockerfile b/src/ci/docker/host-x86_64/x86_64-gnu/Dockerfile index 207dbed681faa..1d411bc2fab55 100644 --- a/src/ci/docker/host-x86_64/x86_64-gnu/Dockerfile +++ b/src/ci/docker/host-x86_64/x86_64-gnu/Dockerfile @@ -34,6 +34,7 @@ ENV RUST_CONFIGURE_ARGS="--build=x86_64-unknown-linux-gnu \ --enable-sanitizers \ --enable-profiler \ --enable-compiler-docs \ - --set llvm.libzstd=true" -ENV SCRIPT="python3 ../x.py --stage 2 test && \ - python3 ../x.py --stage 2 test library/stdarch/crates/intrinsic-test" \ No newline at end of file + --set llvm.libzstd=true \ + --set build.sde=/intel-sde/sde64" +ENV SCRIPT="python3 ../x.py --stage 2 test" + \ No newline at end of file From 7f2ea789e013a72917640d7ff3ef09d474c2b353 Mon Sep 17 00:00:00 2001 From: xonx <119700621+xonx4l@users.noreply.github.com> Date: Tue, 28 Jul 2026 10:02:10 +0000 Subject: [PATCH 21/41] add build.sde to bootstrap.example.toml --- bootstrap.example.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bootstrap.example.toml b/bootstrap.example.toml index 8229538ca3ce0..a8bab85fda087 100644 --- a/bootstrap.example.toml +++ b/bootstrap.example.toml @@ -351,6 +351,10 @@ # Set this to "discover" to automatically discover LLDB from the environment. #build.lldb = "lldb" +# The path to (or name of) the Intel SDE executable, used to run the +# intrinsic-test suite for x86 target features the host CPU may not support. +#build.sde = "sde64" + # The node.js executable to use. Note that this is only used for the emscripten # target when running tests, otherwise this can be omitted. #build.nodejs = "node" From d83e4f409c5ae6c6ee9141a1dc161f2ccb94e277 Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Mon, 27 Jul 2026 20:19:39 +0900 Subject: [PATCH 22/41] add regression test for stale closure recovery state --- .../missing-braces-before-close-brace.rs | 11 +++++ .../missing-braces-before-close-brace.stderr | 45 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 tests/ui/expr/malformed_closure/missing-braces-before-close-brace.rs create mode 100644 tests/ui/expr/malformed_closure/missing-braces-before-close-brace.stderr diff --git a/tests/ui/expr/malformed_closure/missing-braces-before-close-brace.rs b/tests/ui/expr/malformed_closure/missing-braces-before-close-brace.rs new file mode 100644 index 0000000000000..778d4a3442248 --- /dev/null +++ b/tests/ui/expr/malformed_closure/missing-braces-before-close-brace.rs @@ -0,0 +1,11 @@ +// Regression test for https://github.com/rust-lang/rust/issues/159989 + +fn main() { + for<> || -> () {}; + //~^ ERROR `for<...>` binders for closures are experimental + for<'a> || -> () |_; + //~^ ERROR expected one of `,`, `:`, or `|`, found `;` + //~| ERROR expected one of `,`, `:`, or `|`, found `;` + //~| ERROR expected `{`, found `|` + //~| ERROR `for<...>` binders for closures are experimental +} diff --git a/tests/ui/expr/malformed_closure/missing-braces-before-close-brace.stderr b/tests/ui/expr/malformed_closure/missing-braces-before-close-brace.stderr new file mode 100644 index 0000000000000..baf6a9dd9f4c9 --- /dev/null +++ b/tests/ui/expr/malformed_closure/missing-braces-before-close-brace.stderr @@ -0,0 +1,45 @@ +error: expected one of `,`, `:`, or `|`, found `;` + --> $DIR/missing-braces-before-close-brace.rs:6:24 + | +LL | for<'a> || -> () |_; + | ^ expected one of `,`, `:`, or `|` + +error: expected one of `,`, `:`, or `|`, found `;` + --> $DIR/missing-braces-before-close-brace.rs:6:24 + | +LL | for<'a> || -> () |_; + | ^ expected one of `,`, `:`, or `|` + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: expected `{`, found `|` + --> $DIR/missing-braces-before-close-brace.rs:6:22 + | +LL | for<'a> || -> () |_; + | ^ expected `{` + +error[E0658]: `for<...>` binders for closures are experimental + --> $DIR/missing-braces-before-close-brace.rs:4:5 + | +LL | for<> || -> () {}; + | ^^^^^ + | + = note: see issue #97362 for more information + = help: add `#![feature(closure_lifetime_binder)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + = help: consider removing `for<...>` + +error[E0658]: `for<...>` binders for closures are experimental + --> $DIR/missing-braces-before-close-brace.rs:6:5 + | +LL | for<'a> || -> () |_; + | ^^^^^^^ + | + = note: see issue #97362 for more information + = help: add `#![feature(closure_lifetime_binder)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + = help: consider removing `for<...>` + +error: aborting due to 5 previous errors + +For more information about this error, try `rustc --explain E0658`. From 826b4eca33aebd3021bd7cffcec19be1d6e852bf Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Mon, 27 Jul 2026 20:19:58 +0900 Subject: [PATCH 23/41] reset closure recovery state before parsing a statement --- compiler/rustc_parse/src/parser/stmt.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/compiler/rustc_parse/src/parser/stmt.rs b/compiler/rustc_parse/src/parser/stmt.rs index 6dddc8b2407dc..067101a6446a1 100644 --- a/compiler/rustc_parse/src/parser/stmt.rs +++ b/compiler/rustc_parse/src/parser/stmt.rs @@ -54,6 +54,8 @@ impl<'a> Parser<'a> { force_collect: ForceCollect, force_full_expr: bool, ) -> PResult<'a, Stmt> { + self.current_closure.take(); + let pre_attr_pos = self.collect_pos(); let attrs = self.parse_outer_attributes()?; let lo = self.token.span; From f3b14f3c0a67ad9ce3fc93156fcf06cfd3598307 Mon Sep 17 00:00:00 2001 From: zakrad <49591476+zakrad@users.noreply.github.com> Date: Mon, 27 Jul 2026 18:29:52 +0330 Subject: [PATCH 24/41] Add regression test for fn-ptr coercion normalization ICE Coercing the fn item `bar` to a fn pointer while `Foo::value` holds the associated-type projection `<::Ret as Id>::Assoc` used to ICE during normalization ("maybe try to call `try_normalize_erasing_regions` instead"). It now reports the ordinary `u32: Id` trait-bound error instead of crashing. --- .../fn-ptr-coercion-normalize-ice-132767.rs | 45 +++++++++++++++++++ ...n-ptr-coercion-normalize-ice-132767.stderr | 18 ++++++++ 2 files changed, 63 insertions(+) create mode 100644 tests/ui/associated-types/fn-ptr-coercion-normalize-ice-132767.rs create mode 100644 tests/ui/associated-types/fn-ptr-coercion-normalize-ice-132767.stderr diff --git a/tests/ui/associated-types/fn-ptr-coercion-normalize-ice-132767.rs b/tests/ui/associated-types/fn-ptr-coercion-normalize-ice-132767.rs new file mode 100644 index 0000000000000..6e181de0d3f87 --- /dev/null +++ b/tests/ui/associated-types/fn-ptr-coercion-normalize-ice-132767.rs @@ -0,0 +1,45 @@ +// Regression test for #132767. Coercing the fn item `bar` to a fn pointer while +// `Foo::value` holds the associated-type projection `<::Ret as Id>::Assoc` +// used to ICE during normalization ("maybe try to call `try_normalize_erasing_regions` +// instead"). It should now report the ordinary `u32: Id` trait error instead of crashing. + +use std::hint::black_box; + +trait Func { + type Ret: Id; +} + +trait Id { + type Assoc; +} + +impl Id for i32 { + type Assoc = i32; +} + +impl R, R: Id> Func for F { + type Ret = R; +} + +fn bar() -> impl Copy + Id { + //~^ ERROR the trait bound `u32: Id` is not satisfied + 0u32 +} + +struct Foo { + _func: T, + value: Option<<::Ret as Id>::Assoc>, +} + +fn main() { + let mut fn_def = black_box(Foo { + _func: bar, + value: None, + }); + let fn_ptr = black_box(Foo { + _func: bar as fn() -> _, + value: None, + }); + fn_def.value = fn_ptr.value; + black_box(fn_def); +} diff --git a/tests/ui/associated-types/fn-ptr-coercion-normalize-ice-132767.stderr b/tests/ui/associated-types/fn-ptr-coercion-normalize-ice-132767.stderr new file mode 100644 index 0000000000000..fb9f3d4829b8c --- /dev/null +++ b/tests/ui/associated-types/fn-ptr-coercion-normalize-ice-132767.stderr @@ -0,0 +1,18 @@ +error[E0277]: the trait bound `u32: Id` is not satisfied + --> $DIR/fn-ptr-coercion-normalize-ice-132767.rs:24:13 + | +LL | fn bar() -> impl Copy + Id { + | ^^^^^^^^^^^^^^ the trait `Id` is not implemented for `u32` +LL | +LL | 0u32 + | ---- return type was inferred to be `u32` here + | +help: the trait `Id` is implemented for `i32` + --> $DIR/fn-ptr-coercion-normalize-ice-132767.rs:16:1 + | +LL | impl Id for i32 { + | ^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0277`. From 0768bd9470e2c163b8e95071f350ec13a1d0cc30 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 27 Jul 2026 23:54:58 +0200 Subject: [PATCH 25/41] Update `browser-ui-test` version to `0.25.0` --- package.json | 2 +- yarn.lock | 126 +++++++++++++++++++++++++++------------------------ 2 files changed, 68 insertions(+), 60 deletions(-) diff --git a/package.json b/package.json index 6bd8a5be6a105..d9a3ced805ba5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "dependencies": { - "browser-ui-test": "^0.24.1", + "browser-ui-test": "^0.25.0", "es-check": "^9.4.4", "eslint": "^8.57.1", "typescript": "^5.8.3" diff --git a/yarn.lock b/yarn.lock index 3d5855dec80cc..c62a4c75f949b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -76,7 +76,7 @@ "@puppeteer/browsers@3.0.6": version "3.0.6" - resolved "https://registry.npmjs.org/@puppeteer/browsers/-/browsers-3.0.6.tgz" + resolved "https://registry.yarnpkg.com/@puppeteer/browsers/-/browsers-3.0.6.tgz#6b772e0fc11deb255c8a3c14219e34a16a2ab23d" integrity sha512-B/gKoqlFkzhvzsI6jo9K1cZz9o5ypviVv/xu8CwA4grZzyVwN+XfkT+tu8T1zrauuEXv6VhS2oGX+6NL95WcKA== dependencies: modern-tar "^0.7.6" @@ -114,7 +114,7 @@ ansi-regex@^5.0.1: ansi-regex@^6.2.2: version "6.2.2" - resolved "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.2.2.tgz" + resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-6.2.2.tgz#60216eea464d864597ce2832000738a0589650c1" integrity sha512-Bq3SmSpyFHaWjPk8If9yc6svM8c56dB5BAtW4Qbw5jHTwwXXcTLoRMkpDJp6VL0XzlWaCHTXrkFURMYmD0sLqg== ansi-styles@^4.1.0: @@ -126,7 +126,7 @@ ansi-styles@^4.1.0: ansi-styles@^6.2.1: version "6.2.3" - resolved "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.3.tgz" + resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-6.2.3.tgz#c044d5dcc521a076413472597a1acb1f103c4041" integrity sha512-4Dj6M28JB+oAH8kFkTLUo+a2jwOFkuqb3yucU0CANcRRUbxS0cP0nZYCGjcc3BNXwRIsUVmDGgzawme7zvJHvg== argparse@^2.0.1: @@ -154,10 +154,10 @@ braces@^3.0.3: dependencies: fill-range "^7.1.1" -browser-ui-test@^0.24.1: - version "0.24.1" - resolved "https://registry.yarnpkg.com/browser-ui-test/-/browser-ui-test-0.24.1.tgz#1b186b652e2c6593ae1d698408d0e6ba0f32bff5" - integrity sha512-+S+gDOxc7GGfDUmZeRUcCAUzBVbD6qS7TzZSg1CFN/lgJyXf2MCG8CUbvHTsEi/oG5Iuuza1XzKDPpAAvfSUNw== +browser-ui-test@^0.25.0: + version "0.25.0" + resolved "https://registry.yarnpkg.com/browser-ui-test/-/browser-ui-test-0.25.0.tgz#e24352d63009f07ec42583c96330a1ca57487d88" + integrity sha512-DBSpC3UFzQTKhj9cc11AiRliCUiWut1GAJ6sLPEYYPCmF6gTQGg/eynwev0NXPiDpuawiVxSpXPttHQePRK6Ug== dependencies: css-unit-converter "^1.1.2" pngjs "^3.4.0" @@ -177,17 +177,17 @@ chalk@^4.0.0: ansi-styles "^4.1.0" supports-color "^7.1.0" -chromium-bidi@16.0.1: - version "16.0.1" - resolved "https://registry.npmjs.org/chromium-bidi/-/chromium-bidi-16.0.1.tgz" - integrity sha512-J63PGu/9PpeCwLIcKYyzWP6yaVL5pxuBc0shlYCYM8BaAkmlwiQboXO1iNbOgSDbVklEyYFfNEcHD8oOAWacUA== +chromium-bidi@17.0.2: + version "17.0.2" + resolved "https://registry.yarnpkg.com/chromium-bidi/-/chromium-bidi-17.0.2.tgz#921a586deecd0c2d8b9242c4c1b73c3aa39ff77c" + integrity sha512-5v9GQFhTktFvotn/OFNJBmKLKRAb6n9r0bVCwf7sHgWc3/JryK0bj1nn93L3pHFrfgcsu6Be6EWsDi+1XHTGDg== dependencies: mitt "^3.0.1" zod "^3.24.1" cliui@^9.0.1: version "9.0.1" - resolved "https://registry.npmjs.org/cliui/-/cliui-9.0.1.tgz" + resolved "https://registry.yarnpkg.com/cliui/-/cliui-9.0.1.tgz#6f7890f386f6f1f79953adc1f78dec46fcc2d291" integrity sha512-k7ndgKhwoQveBL+/1tqGJYNz097I7WOvwbmmU2AR5+magtbjPWQTS1C5vzGkBC8Ym8UWRzfKUzUUqFLypY4Q+w== dependencies: string-width "^7.2.0" @@ -222,7 +222,7 @@ cross-spawn@^7.0.2: css-unit-converter@^1.1.2: version "1.1.2" - resolved "https://registry.npmjs.org/css-unit-converter/-/css-unit-converter-1.1.2.tgz" + resolved "https://registry.yarnpkg.com/css-unit-converter/-/css-unit-converter-1.1.2.tgz#4c77f5a1954e6dbff60695ecb214e3270436ab21" integrity sha512-IiJwMC8rdZE0+xiEZHeru6YoONC4rfPMqGm2W85jMIbkFvv5nFTwJVFHam2eFrN6txmoUYFAFXiv8ICVeTO0MA== debug@^4.3.1, debug@^4.3.2: @@ -237,10 +237,10 @@ deep-is@^0.1.3: resolved "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz" integrity sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ== -devtools-protocol@0.0.1638949: - version "0.0.1638949" - resolved "https://registry.npmjs.org/devtools-protocol/-/devtools-protocol-0.0.1638949.tgz" - integrity sha512-mXwg4Fqnv0WR4iuAT/gYUmctNkjILwXFHyZ+m7Ty1dfr0ezZt2U3gnrrJTfRobJTHoXf+IbuFvFITzLrLFjwJA== +devtools-protocol@0.0.1653615: + version "0.0.1653615" + resolved "https://registry.yarnpkg.com/devtools-protocol/-/devtools-protocol-0.0.1653615.tgz#c600e0c619612156b2422a66d958ba188d87dbe8" + integrity sha512-pGVkY3T/qXxAp2nFPodwYqOevk6ncNMSmvL8QfRCx5ZWGd6Vor7AFNmyaA8Zs6uJyP1QAfjuLandCgvSix1BNA== doctrine@^3.0.0: version "3.0.0" @@ -251,7 +251,7 @@ doctrine@^3.0.0: emoji-regex@^10.3.0: version "10.6.0" - resolved "https://registry.npmjs.org/emoji-regex/-/emoji-regex-10.6.0.tgz" + resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-10.6.0.tgz#bf3d6e8f7f8fd22a65d9703475bc0147357a6b0d" integrity sha512-toUI84YS5YmxW219erniWD0CIVOo46xGKColeNQRgOzDorgBi1v4D71/OFzgD9GO2UGKIv1C3Sp8DAn0+j5w7A== es-check@^9.4.4: @@ -264,7 +264,7 @@ es-check@^9.4.4: escalade@^3.1.1: version "3.2.0" - resolved "https://registry.npmjs.org/escalade/-/escalade-3.2.0.tgz" + resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.2.0.tgz#011a3f69856ba189dffa7dc8fcce99d2a87903e5" integrity sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA== escape-string-regexp@^4.0.0: @@ -438,12 +438,12 @@ fs.realpath@^1.0.0: get-caller-file@^2.0.5: version "2.0.5" - resolved "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz" + resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e" integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg== -get-east-asian-width@^1.0.0: +get-east-asian-width@^1.0.0, get-east-asian-width@^1.5.0: version "1.6.0" - resolved "https://registry.npmjs.org/get-east-asian-width/-/get-east-asian-width-1.6.0.tgz" + resolved "https://registry.yarnpkg.com/get-east-asian-width/-/get-east-asian-width-1.6.0.tgz#216900f91df11a8b2c198c3e1d93d6c035a776b9" integrity sha512-QRbvDIbx6YklUe6RxeTeleMR0yv3cYH6PsPZHcnVn7xv7zO1BHN8r0XETu8n6Ye3Q+ahtSarc3WgtNWmehIBfA== glob-parent@^5.1.2: @@ -586,7 +586,7 @@ levn@^0.4.1: lilconfig@^3.1.3: version "3.1.3" - resolved "https://registry.npmjs.org/lilconfig/-/lilconfig-3.1.3.tgz" + resolved "https://registry.yarnpkg.com/lilconfig/-/lilconfig-3.1.3.tgz#a1bcfd6257f9585bf5ae14ceeebb7b559025e4c4" integrity sha512-/vlFKAoH5Cgt3Ie+JLhRbwOsCQePABiU3tJ1egGvyQ+33R/vcwM2Zl2QR/LzjsBeItPt3oSVXapn+m4nQDvpzw== locate-path@^6.0.0: @@ -623,13 +623,13 @@ minimatch@^3.0.5, minimatch@^3.1.1, minimatch@^3.1.2: mitt@^3.0.1: version "3.0.1" - resolved "https://registry.npmjs.org/mitt/-/mitt-3.0.1.tgz" + resolved "https://registry.yarnpkg.com/mitt/-/mitt-3.0.1.tgz#ea36cf0cc30403601ae074c8f77b7092cdab36d1" integrity sha512-vKivATfr97l2/QBCYAkXYDbrIWPM2IIKEl7YPhjCvKlG3kE2gm+uBo6nEXK3M5/Ffh/FLpKExzOQ3JJoJGFKBw== modern-tar@^0.7.6: - version "0.7.6" - resolved "https://registry.npmjs.org/modern-tar/-/modern-tar-0.7.6.tgz" - integrity sha512-sweCIVXzx1aIGTCdzcMlSZt1h8k5Tmk08VNAuRk3IU28XamGiOH5ypi11g6De2CH7PhYqSSnGy2A/EFhbWnVKg== + version "0.7.7" + resolved "https://registry.yarnpkg.com/modern-tar/-/modern-tar-0.7.7.tgz#ca71d79603630076b10733b0751ccab284bbc1ef" + integrity sha512-t9VmxaqrmANnEOBhpSDI6HD192Ge48k8vmWqQQL7hSFEqHEYwZbbsu49+aKLWZeRvFs3j1pMhXOqqF4kPlvjkQ== ms@^2.1.3: version "2.1.3" @@ -703,7 +703,7 @@ picomatch@^2.3.1: pngjs@^3.4.0: version "3.4.0" - resolved "https://registry.npmjs.org/pngjs/-/pngjs-3.4.0.tgz" + resolved "https://registry.yarnpkg.com/pngjs/-/pngjs-3.4.0.tgz#99ca7d725965fb655814eaf65f38f12bbdbf555f" integrity sha512-NCrCHhWmnQklfH4MtJMRjZ2a8c80qXeMlQMv2uVp9ISJMTt562SbGd6n2oq0PaPgKm7Z6pL9E2UlLIhC+SHL3w== prelude-ls@^1.2.1: @@ -716,28 +716,28 @@ punycode@^2.1.0: resolved "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz" integrity sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg== -puppeteer-core@25.3.0: - version "25.3.0" - resolved "https://registry.npmjs.org/puppeteer-core/-/puppeteer-core-25.3.0.tgz" - integrity sha512-fm+wpUr2oigH1PXZvwgATrM2tYWHMDG8ASzTEe9uukCye4X5Ldx1K5BTHPFKITrIWvQQAQ256d1NpbEveBcKjA== +puppeteer-core@25.4.0: + version "25.4.0" + resolved "https://registry.yarnpkg.com/puppeteer-core/-/puppeteer-core-25.4.0.tgz#2fcba53a9ab94d55f196e1e42dbe794bbadf8759" + integrity sha512-K1plkLOdeoUnGeT1OvdqF3qxl33v+Ra/uH5VyPEhXdMcpvGiEskHzxxEU3fgpccJpJLIipB/rPUsvkZRWeKqOA== dependencies: "@puppeteer/browsers" "3.0.6" - chromium-bidi "16.0.1" - devtools-protocol "0.0.1638949" + chromium-bidi "17.0.2" + devtools-protocol "0.0.1653615" typed-query-selector "^2.12.2" webdriver-bidi-protocol "0.4.2" - ws "^8.21.0" + ws "^8.21.1" puppeteer@^25.1.0: - version "25.3.0" - resolved "https://registry.npmjs.org/puppeteer/-/puppeteer-25.3.0.tgz" - integrity sha512-O1tx8S315aw8eI99HZ5ZNcVEzJ9+jKF//eO5UvfZ3cXJ6okZ5sX3Y50u7DJaM+ewEK4LqXP068tBhfRaWikj+g== + version "25.4.0" + resolved "https://registry.yarnpkg.com/puppeteer/-/puppeteer-25.4.0.tgz#87b549a666ffc4f68fee2f195c42d67eba9b8168" + integrity sha512-xfQp8dFBcGaLc1hEMaVr7s+oW4ZkAurr8Y9H81ilKhu6QoLfSTkZjU7IavnyJ/VWpB9ni3KNJUQHUatslLWyGw== dependencies: "@puppeteer/browsers" "3.0.6" - chromium-bidi "16.0.1" - devtools-protocol "0.0.1638949" + chromium-bidi "17.0.2" + devtools-protocol "0.0.1653615" lilconfig "^3.1.3" - puppeteer-core "25.3.0" + puppeteer-core "25.4.0" typed-query-selector "^2.12.2" queue-microtask@^1.2.2: @@ -747,7 +747,7 @@ queue-microtask@^1.2.2: readline-sync@^1.4.10: version "1.4.10" - resolved "https://registry.npmjs.org/readline-sync/-/readline-sync-1.4.10.tgz" + resolved "https://registry.yarnpkg.com/readline-sync/-/readline-sync-1.4.10.tgz#41df7fbb4b6312d673011594145705bf56d8873b" integrity sha512-gNva8/6UAe8QYepIQH/jQ2qn91Qj0B9sYjMBBs3QOB8F2CXcKgLxQaJRP76sWVRQt+QU+8fAkCbCvjjMFu7Ycw== resolve-from@^4.0.0: @@ -788,13 +788,21 @@ shebang-regex@^3.0.0: string-width@^7.0.0, string-width@^7.2.0: version "7.2.0" - resolved "https://registry.npmjs.org/string-width/-/string-width-7.2.0.tgz" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-7.2.0.tgz#b5bb8e2165ce275d4d43476dd2700ad9091db6dc" integrity sha512-tsaTIkKW9b4N+AEj+SVA+WhJzV7/zMhcSu78mLKWSk7cXMOSHsBKFWUs0fWwq8QyK3MgJBQRX6Gbi4kYbdvGkQ== dependencies: emoji-regex "^10.3.0" get-east-asian-width "^1.0.0" strip-ansi "^7.1.0" +string-width@^8.2.1: + version "8.2.2" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-8.2.2.tgz#7310516493df575742fe98af6fae87d85d5ed0ac" + integrity sha512-GaPUh5gfdrYzqeVNZvUfT23vYYxXzKYidUcnMtJg/3rxRV63EFZy3k6xfKlmfeJD0176lnUV/Usr3XcwSvFzpg== + dependencies: + get-east-asian-width "^1.5.0" + strip-ansi "^7.1.2" + strip-ansi@^6.0.1: version "6.0.1" resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz" @@ -802,9 +810,9 @@ strip-ansi@^6.0.1: dependencies: ansi-regex "^5.0.1" -strip-ansi@^7.1.0: +strip-ansi@^7.1.0, strip-ansi@^7.1.2: version "7.2.0" - resolved "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.2.0.tgz" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.2.0.tgz#d22a269522836a627af8d04b5c3fd2c7fa3e32e3" integrity sha512-yDPMNjp4WyfYBkHnjIRLfca1i6KMyGCtsVgoKe/z1+6vukgaENdgGBZt+ZmKPc4gavvEZ5OgHfHdrazhgNyG7w== dependencies: ansi-regex "^6.2.2" @@ -847,7 +855,7 @@ type-fest@^0.20.2: typed-query-selector@^2.12.2: version "2.12.2" - resolved "https://registry.npmjs.org/typed-query-selector/-/typed-query-selector-2.12.2.tgz" + resolved "https://registry.yarnpkg.com/typed-query-selector/-/typed-query-selector-2.12.2.tgz#65e2462ac6b0aecfae1bfac1a4f3027070dbabaa" integrity sha512-EOPFbyIub4ngnEdqi2yOcNeDLaX/0jcE1JoAXQDDMIthap7FoN795lc/SHfIq2d416VufXpM8z/lD+WRm2gfOQ== typescript@^5.8.3: @@ -864,7 +872,7 @@ uri-js@^4.2.2: webdriver-bidi-protocol@0.4.2: version "0.4.2" - resolved "https://registry.npmjs.org/webdriver-bidi-protocol/-/webdriver-bidi-protocol-0.4.2.tgz" + resolved "https://registry.yarnpkg.com/webdriver-bidi-protocol/-/webdriver-bidi-protocol-0.4.2.tgz#f51bb71c2606e90e3d5727607c728b25d617b58b" integrity sha512-VSV+fzfChirL3e7jay2yUC7B4HQCGtEWEg/MSSQbK+qWbqeGlRLlXTzPpYr3XGUvbpDHumWZBJxgesg4N7dbtA== which@^2.0.1: @@ -881,7 +889,7 @@ word-wrap@^1.2.5: wrap-ansi@^9.0.0: version "9.0.2" - resolved "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-9.0.2.tgz" + resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-9.0.2.tgz#956832dea9494306e6d209eb871643bb873d7c98" integrity sha512-42AtmgqjV+X1VpdOfyTGOYRi0/zsoLqtXQckTmqTeybT+BDIbM/Guxo7x3pE2vtpr1ok6xRqM9OpBe+Jyoqyww== dependencies: ansi-styles "^6.2.1" @@ -893,30 +901,30 @@ wrappy@1: resolved "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz" integrity sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ== -ws@^8.21.0: - version "8.21.0" - resolved "https://registry.npmjs.org/ws/-/ws-8.21.0.tgz" - integrity sha512-Vsp28b7DRcimFQvrqu2Wek3z1iYxDCWqHYB8Qsnk/S4RfaCQzPGPyBNuVjJV3cd6UiKtUtp6sNM77gWvzcCH+g== +ws@^8.21.1: + version "8.21.1" + resolved "https://registry.yarnpkg.com/ws/-/ws-8.21.1.tgz#045650cd4b1207809e7547146223c3814a9af586" + integrity sha512-+0NTnW77fFN/DjQi6k/Sq/Yvk4Sgajw7urW8V+asjXnRgDs9gyGkdb7EzgfhA4goXsRIZKE28fzIXBHEzhuiWw== y18n@^5.0.5: version "5.0.8" - resolved "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz" + resolved "https://registry.yarnpkg.com/y18n/-/y18n-5.0.8.tgz#7f4934d0f7ca8c56f95314939ddcd2dd91ce1d55" integrity sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA== yargs-parser@^22.0.0: version "22.0.0" - resolved "https://registry.npmjs.org/yargs-parser/-/yargs-parser-22.0.0.tgz" + resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-22.0.0.tgz#87b82094051b0567717346ecd00fd14804b357c8" integrity sha512-rwu/ClNdSMpkSrUb+d6BRsSkLUq1fmfsY6TOpYzTwvwkg1/NRG85KBy3kq++A8LKQwX6lsu+aWad+2khvuXrqw== yargs@^18.0.0: - version "18.0.0" - resolved "https://registry.npmjs.org/yargs/-/yargs-18.0.0.tgz" - integrity sha512-4UEqdc2RYGHZc7Doyqkrqiln3p9X2DZVxaGbwhn2pi7MrRagKaOcIKe8L3OxYcbhXLgLFUS3zAYuQjKBQgmuNg== + version "18.1.0" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-18.1.0.tgz#cd7e98c703ef51695bbbf062ed58f28e94291b56" + integrity sha512-2rAgRKu54VsHkqI0/tYkmluGXHD4KW7yZoycuqDQ15QOTnc2VVfy0nN/1eMhnQLO00A+dwtK20xuCnc1YGeUyg== dependencies: cliui "^9.0.1" escalade "^3.1.1" get-caller-file "^2.0.5" - string-width "^7.2.0" + string-width "^8.2.1" y18n "^5.0.5" yargs-parser "^22.0.0" @@ -927,5 +935,5 @@ yocto-queue@^0.1.0: zod@^3.24.1: version "3.25.76" - resolved "https://registry.npmjs.org/zod/-/zod-3.25.76.tgz" + resolved "https://registry.yarnpkg.com/zod/-/zod-3.25.76.tgz#26841c3f6fd22a6a2760e7ccb719179768471e34" integrity sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ== From c7162384fdf93107382719286135ee39da2193af Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Tue, 28 Jul 2026 11:11:00 +0200 Subject: [PATCH 26/41] Add missing `"clipboard-read"` permission --- tests/rustdoc-gui/code-example-buttons.goml | 1 + tests/rustdoc-gui/copy-code.goml | 1 + tests/rustdoc-gui/copy-path.goml | 1 + 3 files changed, 3 insertions(+) diff --git a/tests/rustdoc-gui/code-example-buttons.goml b/tests/rustdoc-gui/code-example-buttons.goml index 1429f978a28ae..844e2cdda6c95 100644 --- a/tests/rustdoc-gui/code-example-buttons.goml +++ b/tests/rustdoc-gui/code-example-buttons.goml @@ -1,5 +1,6 @@ // This test ensures that code blocks buttons are displayed on hover and when you click on them. go-to: "file://" + |DOC_PATH| + "/test_docs/fn.foo.html" +permissions: ["clipboard-read"] include: "utils.goml" // First we check we "hover". diff --git a/tests/rustdoc-gui/copy-code.goml b/tests/rustdoc-gui/copy-code.goml index eb003ef5e1ca8..13cf2290d7791 100644 --- a/tests/rustdoc-gui/copy-code.goml +++ b/tests/rustdoc-gui/copy-code.goml @@ -2,6 +2,7 @@ // isn't broken. include: "utils.goml" go-to: "file://" + |DOC_PATH| + "/test_docs/fn.foo.html" +permissions: ["clipboard-read"] define-function: ( "check-copy-button", diff --git a/tests/rustdoc-gui/copy-path.goml b/tests/rustdoc-gui/copy-path.goml index 61e63d7822c73..1350531514443 100644 --- a/tests/rustdoc-gui/copy-path.goml +++ b/tests/rustdoc-gui/copy-path.goml @@ -1,6 +1,7 @@ // Checks that the "copy path" button is not triggering JS error and its display // isn't broken and the copied path is as expected. go-to: "file://" + |DOC_PATH| + "/test_docs/foreign_impl_order/trait.Foo.html" +permissions: ["clipboard-read"] // We ensure that the clipboard is empty. assert-clipboard: "" From bf116a2a58ab0df21e9ab2f58fbdf46b265142e0 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 28 Jul 2026 12:38:08 +1000 Subject: [PATCH 27/41] Improve consistency of proc macro attribute error messages --- .../rustc_builtin_macros/src/diagnostics.rs | 2 +- .../src/proc_macro_harness.rs | 3 ++- tests/rustdoc-ui/proc_macro_bug.rs | 2 +- tests/rustdoc-ui/proc_macro_bug.stderr | 6 ++--- tests/ui/attributes/malformed-attrs.rs | 6 ++--- tests/ui/attributes/malformed-attrs.stderr | 18 +++++++------- .../unsafe/proc-unsafe-attributes.stderr | 24 +++++++++---------- ...issue-43106-gating-of-proc_macro_derive.rs | 2 +- ...e-43106-gating-of-proc_macro_derive.stderr | 6 ++--- .../illegal-proc-macro-derive-use.stderr | 6 ++--- 10 files changed, 38 insertions(+), 37 deletions(-) diff --git a/compiler/rustc_builtin_macros/src/diagnostics.rs b/compiler/rustc_builtin_macros/src/diagnostics.rs index 6ae0f908a88a0..71dc17b108a97 100644 --- a/compiler/rustc_builtin_macros/src/diagnostics.rs +++ b/compiler/rustc_builtin_macros/src/diagnostics.rs @@ -1036,7 +1036,7 @@ pub(crate) struct TakesNoArguments<'a> { } #[derive(Diagnostic)] -#[diag("the `#[{$path}]` attribute is only usable with crates of the `proc-macro` crate type")] +#[diag("the `{$path}` attribute is only usable with crates of the `proc-macro` crate type")] pub(crate) struct AttributeOnlyUsableWithCrateType<'a> { #[primary_span] pub span: Span, diff --git a/compiler/rustc_builtin_macros/src/proc_macro_harness.rs b/compiler/rustc_builtin_macros/src/proc_macro_harness.rs index 8259758272e7e..88f380fa9ef64 100644 --- a/compiler/rustc_builtin_macros/src/proc_macro_harness.rs +++ b/compiler/rustc_builtin_macros/src/proc_macro_harness.rs @@ -230,9 +230,10 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> { } if !self.is_proc_macro_crate { + let path = &attr.get_normal_item().path; self.dcx .create_err(diagnostics::AttributeOnlyUsableWithCrateType { - span: attr.span, + span: path.span, path: &pprust::path_to_string(&attr.get_normal_item().path), }) .emit(); diff --git a/tests/rustdoc-ui/proc_macro_bug.rs b/tests/rustdoc-ui/proc_macro_bug.rs index e384e4863adb9..d54e091d51906 100644 --- a/tests/rustdoc-ui/proc_macro_bug.rs +++ b/tests/rustdoc-ui/proc_macro_bug.rs @@ -6,7 +6,7 @@ extern crate proc_macro; use proc_macro::TokenStream; #[proc_macro_derive(DeriveA)] -//~^ ERROR the `#[proc_macro_derive]` attribute is only usable with crates of the `proc-macro` crate type +//~^ ERROR the `proc_macro_derive` attribute is only usable with crates of the `proc-macro` crate type pub fn a_derive(input: TokenStream) -> TokenStream { input } diff --git a/tests/rustdoc-ui/proc_macro_bug.stderr b/tests/rustdoc-ui/proc_macro_bug.stderr index 77bdf201924f9..522f54e2b47f1 100644 --- a/tests/rustdoc-ui/proc_macro_bug.stderr +++ b/tests/rustdoc-ui/proc_macro_bug.stderr @@ -1,8 +1,8 @@ -error: the `#[proc_macro_derive]` attribute is only usable with crates of the `proc-macro` crate type - --> $DIR/proc_macro_bug.rs:8:1 +error: the `proc_macro_derive` attribute is only usable with crates of the `proc-macro` crate type + --> $DIR/proc_macro_bug.rs:8:3 | LL | #[proc_macro_derive(DeriveA)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/attributes/malformed-attrs.rs b/tests/ui/attributes/malformed-attrs.rs index 332ed63aadbee..d5f663020f3e0 100644 --- a/tests/ui/attributes/malformed-attrs.rs +++ b/tests/ui/attributes/malformed-attrs.rs @@ -105,7 +105,7 @@ //~| WARN previously accepted #[proc_macro = 18] //~^ ERROR malformed -//~| ERROR the `#[proc_macro]` attribute is only usable with crates of the `proc-macro` crate type +//~| ERROR the `proc_macro` attribute is only usable with crates of the `proc-macro` crate type #[cfg] //~^ ERROR malformed #[cfg_attr] @@ -122,14 +122,14 @@ fn test() { #[proc_macro_attribute = 19] //~^ ERROR malformed -//~| ERROR the `#[proc_macro_attribute]` attribute is only usable with crates of the `proc-macro` crate type +//~| ERROR the `proc_macro_attribute` attribute is only usable with crates of the `proc-macro` crate type #[must_use = 1] //~^ ERROR malformed fn test2() { } #[proc_macro_derive] //~^ ERROR malformed `proc_macro_derive` attribute -//~| ERROR the `#[proc_macro_derive]` attribute is only usable with crates of the `proc-macro` crate type +//~| ERROR the `proc_macro_derive` attribute is only usable with crates of the `proc-macro` crate type pub fn test3() {} #[must_not_suspend()] diff --git a/tests/ui/attributes/malformed-attrs.stderr b/tests/ui/attributes/malformed-attrs.stderr index 5b8c823581f1a..213e017a6be4d 100644 --- a/tests/ui/attributes/malformed-attrs.stderr +++ b/tests/ui/attributes/malformed-attrs.stderr @@ -108,23 +108,23 @@ LL | #[forbid(lint1, lint2, ...)] LL | #[forbid(lint1, lint2, lint3, reason = "...")] | +++++++++++++++++++++++++++++++++++++ -error: the `#[proc_macro]` attribute is only usable with crates of the `proc-macro` crate type - --> $DIR/malformed-attrs.rs:106:1 +error: the `proc_macro` attribute is only usable with crates of the `proc-macro` crate type + --> $DIR/malformed-attrs.rs:106:3 | LL | #[proc_macro = 18] - | ^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^ -error: the `#[proc_macro_attribute]` attribute is only usable with crates of the `proc-macro` crate type - --> $DIR/malformed-attrs.rs:123:1 +error: the `proc_macro_attribute` attribute is only usable with crates of the `proc-macro` crate type + --> $DIR/malformed-attrs.rs:123:3 | LL | #[proc_macro_attribute = 19] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^ -error: the `#[proc_macro_derive]` attribute is only usable with crates of the `proc-macro` crate type - --> $DIR/malformed-attrs.rs:130:1 +error: the `proc_macro_derive` attribute is only usable with crates of the `proc-macro` crate type + --> $DIR/malformed-attrs.rs:130:3 | LL | #[proc_macro_derive] - | ^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^ error[E0539]: malformed `windows_subsystem` attribute input --> $DIR/malformed-attrs.rs:26:4 diff --git a/tests/ui/attributes/unsafe/proc-unsafe-attributes.stderr b/tests/ui/attributes/unsafe/proc-unsafe-attributes.stderr index bf4d8ad34f35b..3b5baaace1a50 100644 --- a/tests/ui/attributes/unsafe/proc-unsafe-attributes.stderr +++ b/tests/ui/attributes/unsafe/proc-unsafe-attributes.stderr @@ -23,29 +23,29 @@ help: escape `unsafe` to use it as an identifier LL | #[unsafe(allow(r#unsafe(dead_code)))] | ++ -error: the `#[proc_macro]` attribute is only usable with crates of the `proc-macro` crate type - --> $DIR/proc-unsafe-attributes.rs:1:1 +error: the `proc_macro` attribute is only usable with crates of the `proc-macro` crate type + --> $DIR/proc-unsafe-attributes.rs:1:10 | LL | #[unsafe(proc_macro)] - | ^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^ -error: the `#[proc_macro_derive]` attribute is only usable with crates of the `proc-macro` crate type - --> $DIR/proc-unsafe-attributes.rs:7:1 +error: the `proc_macro_derive` attribute is only usable with crates of the `proc-macro` crate type + --> $DIR/proc-unsafe-attributes.rs:7:10 | LL | #[unsafe(proc_macro_derive(Foo))] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^ -error: the `#[proc_macro_derive]` attribute is only usable with crates of the `proc-macro` crate type - --> $DIR/proc-unsafe-attributes.rs:12:1 +error: the `proc_macro_derive` attribute is only usable with crates of the `proc-macro` crate type + --> $DIR/proc-unsafe-attributes.rs:12:3 | LL | #[proc_macro_derive(unsafe(Foo))] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^ -error: the `#[proc_macro_attribute]` attribute is only usable with crates of the `proc-macro` crate type - --> $DIR/proc-unsafe-attributes.rs:18:1 +error: the `proc_macro_attribute` attribute is only usable with crates of the `proc-macro` crate type + --> $DIR/proc-unsafe-attributes.rs:18:10 | LL | #[unsafe(proc_macro_attribute)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^ error[E0452]: malformed lint attribute input --> $DIR/proc-unsafe-attributes.rs:27:16 diff --git a/tests/ui/feature-gates/issue-43106-gating-of-proc_macro_derive.rs b/tests/ui/feature-gates/issue-43106-gating-of-proc_macro_derive.rs index 35392b4eff697..6fdf390387559 100644 --- a/tests/ui/feature-gates/issue-43106-gating-of-proc_macro_derive.rs +++ b/tests/ui/feature-gates/issue-43106-gating-of-proc_macro_derive.rs @@ -14,7 +14,7 @@ mod proc_macro_derive2 { //~^ ERROR attribute cannot be used on #[proc_macro_derive(Test)] fn f() { } - //~^ ERROR the `#[proc_macro_derive]` attribute is only usable with crates of the `proc-macro` + //~^ ERROR the `proc_macro_derive` attribute is only usable with crates of the `proc-macro` #[proc_macro_derive(Test)] struct S; //~^ ERROR attribute cannot be used on diff --git a/tests/ui/feature-gates/issue-43106-gating-of-proc_macro_derive.stderr b/tests/ui/feature-gates/issue-43106-gating-of-proc_macro_derive.stderr index b341036d1f6f7..e42c3ca651569 100644 --- a/tests/ui/feature-gates/issue-43106-gating-of-proc_macro_derive.stderr +++ b/tests/ui/feature-gates/issue-43106-gating-of-proc_macro_derive.stderr @@ -1,8 +1,8 @@ -error: the `#[proc_macro_derive]` attribute is only usable with crates of the `proc-macro` crate type - --> $DIR/issue-43106-gating-of-proc_macro_derive.rs:16:5 +error: the `proc_macro_derive` attribute is only usable with crates of the `proc-macro` crate type + --> $DIR/issue-43106-gating-of-proc_macro_derive.rs:16:7 | LL | #[proc_macro_derive(Test)] fn f() { } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^ error: the `proc_macro_derive` attribute cannot be used on modules --> $DIR/issue-43106-gating-of-proc_macro_derive.rs:5:3 diff --git a/tests/ui/proc-macro/illegal-proc-macro-derive-use.stderr b/tests/ui/proc-macro/illegal-proc-macro-derive-use.stderr index b8f8f535d4058..1925eefe98c9a 100644 --- a/tests/ui/proc-macro/illegal-proc-macro-derive-use.stderr +++ b/tests/ui/proc-macro/illegal-proc-macro-derive-use.stderr @@ -1,8 +1,8 @@ -error: the `#[proc_macro_derive]` attribute is only usable with crates of the `proc-macro` crate type - --> $DIR/illegal-proc-macro-derive-use.rs:3:1 +error: the `proc_macro_derive` attribute is only usable with crates of the `proc-macro` crate type + --> $DIR/illegal-proc-macro-derive-use.rs:3:3 | LL | #[proc_macro_derive(Foo)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^ error: the `proc_macro_derive` attribute cannot be used on structs --> $DIR/illegal-proc-macro-derive-use.rs:10:3 From 31e4019417d31dc164cd0be70db03840a4aaebf9 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 28 Jul 2026 13:16:51 +1000 Subject: [PATCH 28/41] Improve consistency of `rustc_abi` attribute error messages --- compiler/rustc_passes/src/diagnostics.rs | 2 +- tests/ui/abi/debug.generic.stderr | 4 ++-- tests/ui/abi/debug.loongarch64.stderr | 4 ++-- tests/ui/abi/debug.riscv64.stderr | 4 ++-- tests/ui/abi/debug.rs | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_passes/src/diagnostics.rs b/compiler/rustc_passes/src/diagnostics.rs index cdb14737ad90d..cc3a6643f38c7 100644 --- a/compiler/rustc_passes/src/diagnostics.rs +++ b/compiler/rustc_passes/src/diagnostics.rs @@ -405,7 +405,7 @@ pub(crate) struct AbiNe { #[derive(Diagnostic)] #[diag( - "`#[rustc_abi]` can only be applied to function items, type aliases, and associated functions" + "the `rustc_abi` attribute can only be applied to function items, type aliases, and associated functions" )] pub(crate) struct AbiInvalidAttribute { #[primary_span] diff --git a/tests/ui/abi/debug.generic.stderr b/tests/ui/abi/debug.generic.stderr index 52727aee9d5a7..6242d93b09534 100644 --- a/tests/ui/abi/debug.generic.stderr +++ b/tests/ui/abi/debug.generic.stderr @@ -264,7 +264,7 @@ error: fn_abi_of(test_generic) = FnAbi { LL | fn test_generic(_x: *const T) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: `#[rustc_abi]` can only be applied to function items, type aliases, and associated functions +error: the `rustc_abi` attribute can only be applied to function items, type aliases, and associated functions --> $DIR/debug.rs:43:1 | LL | const C: () = (); @@ -845,7 +845,7 @@ LL | type TestAbiEqNonsense = (fn((str, str)), fn((str, str))); = help: the trait `Sized` is not implemented for `str` = note: only the last element of a tuple may have a dynamically sized type -error: `#[rustc_abi]` can only be applied to function items, type aliases, and associated functions +error: the `rustc_abi` attribute can only be applied to function items, type aliases, and associated functions --> $DIR/debug.rs:47:5 | LL | const C: () = (); diff --git a/tests/ui/abi/debug.loongarch64.stderr b/tests/ui/abi/debug.loongarch64.stderr index 1bf0cdbd23720..176c68ecd4c7b 100644 --- a/tests/ui/abi/debug.loongarch64.stderr +++ b/tests/ui/abi/debug.loongarch64.stderr @@ -264,7 +264,7 @@ error: fn_abi_of(test_generic) = FnAbi { LL | fn test_generic(_x: *const T) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: `#[rustc_abi]` can only be applied to function items, type aliases, and associated functions +error: the `rustc_abi` attribute can only be applied to function items, type aliases, and associated functions --> $DIR/debug.rs:43:1 | LL | const C: () = (); @@ -845,7 +845,7 @@ LL | type TestAbiEqNonsense = (fn((str, str)), fn((str, str))); = help: the trait `Sized` is not implemented for `str` = note: only the last element of a tuple may have a dynamically sized type -error: `#[rustc_abi]` can only be applied to function items, type aliases, and associated functions +error: the `rustc_abi` attribute can only be applied to function items, type aliases, and associated functions --> $DIR/debug.rs:47:5 | LL | const C: () = (); diff --git a/tests/ui/abi/debug.riscv64.stderr b/tests/ui/abi/debug.riscv64.stderr index 1bf0cdbd23720..176c68ecd4c7b 100644 --- a/tests/ui/abi/debug.riscv64.stderr +++ b/tests/ui/abi/debug.riscv64.stderr @@ -264,7 +264,7 @@ error: fn_abi_of(test_generic) = FnAbi { LL | fn test_generic(_x: *const T) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: `#[rustc_abi]` can only be applied to function items, type aliases, and associated functions +error: the `rustc_abi` attribute can only be applied to function items, type aliases, and associated functions --> $DIR/debug.rs:43:1 | LL | const C: () = (); @@ -845,7 +845,7 @@ LL | type TestAbiEqNonsense = (fn((str, str)), fn((str, str))); = help: the trait `Sized` is not implemented for `str` = note: only the last element of a tuple may have a dynamically sized type -error: `#[rustc_abi]` can only be applied to function items, type aliases, and associated functions +error: the `rustc_abi` attribute can only be applied to function items, type aliases, and associated functions --> $DIR/debug.rs:47:5 | LL | const C: () = (); diff --git a/tests/ui/abi/debug.rs b/tests/ui/abi/debug.rs index 45755a93d74a9..68228979d6900 100644 --- a/tests/ui/abi/debug.rs +++ b/tests/ui/abi/debug.rs @@ -40,11 +40,11 @@ type TestFnPtr = fn(bool) -> u8; //~ ERROR: fn_abi fn test_generic(_x: *const T) {} //~ ERROR: fn_abi #[rustc_abi(debug)] //~ ERROR: the `rustc_abi` attribute cannot be used on constants -const C: () = (); //~ ERROR: `#[rustc_abi]` can only be applied to +const C: () = (); //~ ERROR: the `rustc_abi` attribute can only be applied to impl S { #[rustc_abi(debug)] //~ ERROR: the `rustc_abi` attribute cannot be used on assoc - const C: () = (); //~ ERROR: `#[rustc_abi]` can only be applied to + const C: () = (); //~ ERROR: the `rustc_abi` attribute can only be applied to } impl S { From c70f76a453f6234c2df28b79312027af52c3f5a2 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 28 Jul 2026 13:32:31 +1000 Subject: [PATCH 29/41] Improve consistency of `rustc_const_stable` attribute error messages --- compiler/rustc_attr_parsing/src/attributes/stability.rs | 4 ++-- compiler/rustc_hir/src/attrs/data_structures.rs | 3 ++- compiler/rustc_passes/src/diagnostics.rs | 4 ++-- compiler/rustc_passes/src/stability.rs | 4 ++-- tests/ui/consts/rustc-const-stability-require-const.rs | 4 ++-- .../ui/consts/rustc-const-stability-require-const.stderr | 8 ++++---- .../const-stability-attribute-implies-missing.stderr | 4 ++-- 7 files changed, 16 insertions(+), 15 deletions(-) diff --git a/compiler/rustc_attr_parsing/src/attributes/stability.rs b/compiler/rustc_attr_parsing/src/attributes/stability.rs index 1ff0cb26ac8d9..62f16d9719d23 100644 --- a/compiler/rustc_attr_parsing/src/attributes/stability.rs +++ b/compiler/rustc_attr_parsing/src/attributes/stability.rs @@ -210,7 +210,7 @@ impl AttributeParser for ConstStabilityParser { { this.stability = Some(( PartialConstStability { level, feature, promotable: false }, - cx.attr_span, + cx.attr_path.span, )); } }, @@ -225,7 +225,7 @@ impl AttributeParser for ConstStabilityParser { { this.stability = Some(( PartialConstStability { level, feature, promotable: false }, - cx.attr_span, + cx.attr_path.span, )); } }, diff --git a/compiler/rustc_hir/src/attrs/data_structures.rs b/compiler/rustc_hir/src/attrs/data_structures.rs index c86b04370e46d..81830e7ef3515 100644 --- a/compiler/rustc_hir/src/attrs/data_structures.rs +++ b/compiler/rustc_hir/src/attrs/data_structures.rs @@ -1394,7 +1394,8 @@ pub enum AttributeKind { /// Represents `#[rustc_const_stable]` and `#[rustc_const_unstable]`. RustcConstStability { stability: PartialConstStability, - /// Span of the `#[rustc_const_stable(...)]` or `#[rustc_const_unstable(...)]` attribute + /// Path span of the `#[rustc_const_stable(...)]` or `#[rustc_const_unstable(...)]` + /// attribute. span: Span, }, diff --git a/compiler/rustc_passes/src/diagnostics.rs b/compiler/rustc_passes/src/diagnostics.rs index cc3a6643f38c7..14812a6393678 100644 --- a/compiler/rustc_passes/src/diagnostics.rs +++ b/compiler/rustc_passes/src/diagnostics.rs @@ -810,13 +810,13 @@ pub(crate) struct MissingConstErr { #[derive(Diagnostic)] #[diag( - "attribute `#[rustc_const_stable]` can only be applied to functions that are declared `#[stable]`" + "the `rustc_const_stable` attribute can only be applied to functions marked with the `stable` attribute" )] pub(crate) struct ConstStableNotStable { #[primary_span] pub fn_sig_span: Span, #[label("attribute specified here")] - pub const_span: Span, + pub path_span: Span, } #[derive(Diagnostic)] diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index 3482e7320ef96..5d388bd44ecac 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -397,11 +397,11 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> { && let Some(fn_sig) = fn_sig && const_stab.is_const_stable() && !stab.is_some_and(|s| s.is_stable()) - && let Some(const_span) = find_attr_span!(RustcConstStability) + && let Some(path_span) = find_attr_span!(RustcConstStability) { self.tcx.dcx().emit_err(diagnostics::ConstStableNotStable { fn_sig_span: fn_sig.span, - const_span, + path_span, }); } diff --git a/tests/ui/consts/rustc-const-stability-require-const.rs b/tests/ui/consts/rustc-const-stability-require-const.rs index ad27fcf6cb97f..f01e2864c3fe0 100644 --- a/tests/ui/consts/rustc-const-stability-require-const.rs +++ b/tests/ui/consts/rustc-const-stability-require-const.rs @@ -50,9 +50,9 @@ pub const fn barfoo() {} #[rustc_const_stable(feature = "barfoo_const", since = "1.0.0")] const fn barfoo_unmarked() {} -//~^ ERROR can only be applied to functions that are declared `#[stable]` +//~^ ERROR can only be applied to functions marked with the `stable` attribute #[unstable(feature = "unstable", issue = "none")] #[rustc_const_stable(feature = "barfoo_const", since = "1.0.0")] pub const fn barfoo_unstable() {} -//~^ ERROR can only be applied to functions that are declared `#[stable]` +//~^ ERROR can only be applied to functions marked with the `stable` attribute diff --git a/tests/ui/consts/rustc-const-stability-require-const.stderr b/tests/ui/consts/rustc-const-stability-require-const.stderr index 8d10bddaa45fa..63662b725cfe3 100644 --- a/tests/ui/consts/rustc-const-stability-require-const.stderr +++ b/tests/ui/consts/rustc-const-stability-require-const.stderr @@ -46,19 +46,19 @@ help: make the function or method const LL | pub extern "C" fn foo_c() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ -error: attribute `#[rustc_const_stable]` can only be applied to functions that are declared `#[stable]` +error: the `rustc_const_stable` attribute can only be applied to functions marked with the `stable` attribute --> $DIR/rustc-const-stability-require-const.rs:52:1 | LL | #[rustc_const_stable(feature = "barfoo_const", since = "1.0.0")] - | ---------------------------------------------------------------- attribute specified here + | ------------------ attribute specified here LL | const fn barfoo_unmarked() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: attribute `#[rustc_const_stable]` can only be applied to functions that are declared `#[stable]` +error: the `rustc_const_stable` attribute can only be applied to functions marked with the `stable` attribute --> $DIR/rustc-const-stability-require-const.rs:57:1 | LL | #[rustc_const_stable(feature = "barfoo_const", since = "1.0.0")] - | ---------------------------------------------------------------- attribute specified here + | ------------------ attribute specified here LL | pub const fn barfoo_unstable() {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/stability-attribute/const-stability-attribute-implies-missing.stderr b/tests/ui/stability-attribute/const-stability-attribute-implies-missing.stderr index 232de41c769e2..d9419506b67ff 100644 --- a/tests/ui/stability-attribute/const-stability-attribute-implies-missing.stderr +++ b/tests/ui/stability-attribute/const-stability-attribute-implies-missing.stderr @@ -1,8 +1,8 @@ error: feature `const_bar` implying `const_foobar` does not exist - --> $DIR/const-stability-attribute-implies-missing.rs:10:1 + --> $DIR/const-stability-attribute-implies-missing.rs:10:3 | LL | #[rustc_const_unstable(feature = "const_foobar", issue = "1", implied_by = "const_bar")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^ error: aborting due to 1 previous error From 8be13e405661e53ef68a1dd44cedeb0da6db1fbf Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 28 Jul 2026 13:38:11 +1000 Subject: [PATCH 30/41] Improve consistency of `diagnostic::on_const` attribute error messages --- .../src/attributes/diagnostic/on_const.rs | 15 +++++++++------ compiler/rustc_hir/src/attrs/data_structures.rs | 1 + compiler/rustc_passes/src/check_attr.rs | 8 +++++--- .../on_const/misplaced_attr.rs | 2 +- .../on_const/misplaced_attr.stderr | 6 +++--- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_attr_parsing/src/attributes/diagnostic/on_const.rs b/compiler/rustc_attr_parsing/src/attributes/diagnostic/on_const.rs index a7b71b9080dca..20c0ac7cc8554 100644 --- a/compiler/rustc_attr_parsing/src/attributes/diagnostic/on_const.rs +++ b/compiler/rustc_attr_parsing/src/attributes/diagnostic/on_const.rs @@ -5,7 +5,7 @@ use crate::attributes::diagnostic::*; use crate::attributes::prelude::*; #[derive(Default)] pub(crate) struct OnConstParser { - span: Option, + path_span: Option, directive: Option<(Span, Directive)>, } @@ -21,8 +21,8 @@ impl AttributeParser for OnConstParser { return; } - let span = cx.attr_span; - this.span = Some(span); + let path_span = cx.attr_path.span; + this.path_span = Some(path_span); let mode = Mode::DiagnosticOnConst; @@ -31,7 +31,7 @@ impl AttributeParser for OnConstParser { let Some(directive) = parse_directive_items(cx, mode, items.mixed(), true) else { return; }; - merge_directives(cx, &mut this.directive, (span, directive)); + merge_directives(cx, &mut this.directive, (path_span, directive)); }, )]; @@ -44,8 +44,11 @@ impl AttributeParser for OnConstParser { ]); fn finalize(self, _cx: &FinalizeContext<'_, '_>) -> Option { - if let Some(span) = self.span { - Some(AttributeKind::OnConst { span, directive: self.directive.map(|d| Box::new(d.1)) }) + if let Some(path_span) = self.path_span { + Some(AttributeKind::OnConst { + span: path_span, + directive: self.directive.map(|d| Box::new(d.1)), + }) } else { None } diff --git a/compiler/rustc_hir/src/attrs/data_structures.rs b/compiler/rustc_hir/src/attrs/data_structures.rs index 81830e7ef3515..fd94f64ef4269 100644 --- a/compiler/rustc_hir/src/attrs/data_structures.rs +++ b/compiler/rustc_hir/src/attrs/data_structures.rs @@ -1219,6 +1219,7 @@ pub enum AttributeKind { /// Represents `#[diagnostic::on_const]`. OnConst { + /// The attribute path span. span: Span, /// None if the directive was malformed in some way. directive: Option>, diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 6a02a52cddde8..e1147fcbe0167 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -52,7 +52,9 @@ use rustc_trait_selection::traits::ObligationCtxt; use crate::diagnostics; #[derive(Diagnostic)] -#[diag("`#[diagnostic::on_const]` can only be applied to non-const trait implementations")] +#[diag( + "the `diagnostic::on_const` attribute can only be applied to non-const trait implementations" +)] struct DiagnosticOnConstOnlyForNonConstTraitImpls { #[label("this is a const trait implementation")] item_span: Span, @@ -569,7 +571,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { /// Checks if `#[diagnostic::on_const]` is applied to a on-const trait impl fn check_diagnostic_on_const( &self, - attr_span: Span, + attr_path_span: Span, hir_id: HirId, target: Target, item: Option<&'tcx Item<'tcx>>, @@ -609,7 +611,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { self.tcx.emit_node_span_lint( MISPLACED_DIAGNOSTIC_ATTRIBUTES, hir_id, - attr_span, + attr_path_span, DiagnosticOnConstOnlyForNonConstTraitImpls { item_span }, ); return; diff --git a/tests/ui/diagnostic_namespace/on_const/misplaced_attr.rs b/tests/ui/diagnostic_namespace/on_const/misplaced_attr.rs index 21b7dc32f6f8e..4e8ac9a94945a 100644 --- a/tests/ui/diagnostic_namespace/on_const/misplaced_attr.rs +++ b/tests/ui/diagnostic_namespace/on_const/misplaced_attr.rs @@ -6,7 +6,7 @@ pub struct Foo; #[diagnostic::on_const(message = "tadaa", note = "boing")] -//~^ ERROR: `#[diagnostic::on_const]` can only be applied to non-const trait implementations +//~^ ERROR: the `diagnostic::on_const` attribute can only be applied to non-const trait implementations const impl PartialEq for Foo { fn eq(&self, _other: &Foo) -> bool { true diff --git a/tests/ui/diagnostic_namespace/on_const/misplaced_attr.stderr b/tests/ui/diagnostic_namespace/on_const/misplaced_attr.stderr index 8509b251a1b39..2f125078d458e 100644 --- a/tests/ui/diagnostic_namespace/on_const/misplaced_attr.stderr +++ b/tests/ui/diagnostic_namespace/on_const/misplaced_attr.stderr @@ -1,8 +1,8 @@ -error: `#[diagnostic::on_const]` can only be applied to non-const trait implementations - --> $DIR/misplaced_attr.rs:8:1 +error: the `diagnostic::on_const` attribute can only be applied to non-const trait implementations + --> $DIR/misplaced_attr.rs:8:3 | LL | #[diagnostic::on_const(message = "tadaa", note = "boing")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^ LL | LL | const impl PartialEq for Foo { | ---------------------------- this is a const trait implementation From 845600cca0273a94999f397c8f4ecf83ce670f15 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 28 Jul 2026 14:16:55 +1000 Subject: [PATCH 31/41] Improve consistency of `test`/`bench` attribute error messages The carets should ideally point to the path, not the entire attribute, but that's hard to achieve with the current code structure. --- compiler/rustc_builtin_macros/src/test.rs | 8 ++-- .../ui/feature-gates/gating-of-test-attrs.rs | 20 ++++---- .../feature-gates/gating-of-test-attrs.stderr | 40 ++++++++-------- tests/ui/macros/issue-111749.rs | 2 +- tests/ui/macros/issue-111749.stderr | 4 +- tests/ui/macros/test-on-crate-root.rs | 2 +- tests/ui/macros/test-on-crate-root.stderr | 4 +- tests/ui/test-attrs/issue-109816.rs | 2 +- tests/ui/test-attrs/issue-109816.stderr | 4 +- .../test-attr-non-associated-functions.rs | 4 +- .../test-attr-non-associated-functions.stderr | 8 ++-- tests/ui/test-attrs/test-on-not-fn.rs | 24 +++++----- tests/ui/test-attrs/test-on-not-fn.stderr | 48 +++++++++---------- 13 files changed, 85 insertions(+), 85 deletions(-) diff --git a/compiler/rustc_builtin_macros/src/test.rs b/compiler/rustc_builtin_macros/src/test.rs index 78d8f89b57f9e..5206df563ec10 100644 --- a/compiler/rustc_builtin_macros/src/test.rs +++ b/compiler/rustc_builtin_macros/src/test.rs @@ -96,13 +96,13 @@ pub(crate) fn expand_test( pub(crate) fn expand_bench( cx: &mut ExtCtxt<'_>, - attr_sp: Span, + attr_path_sp: Span, meta_item: &ast::MetaItem, item: Annotatable, ) -> Vec { check_builtin_macro_attribute(cx, meta_item, sym::bench); warn_on_duplicate_attribute(cx, &item, sym::bench); - expand_test_or_bench(cx, attr_sp, item, true) + expand_test_or_bench(cx, attr_path_sp, item, true) } pub(crate) fn expand_test_or_bench( @@ -413,7 +413,7 @@ pub(crate) fn expand_test_or_bench( fn not_testable_error(cx: &ExtCtxt<'_>, is_bench: bool, attr_sp: Span, item: Option<&ast::Item>) { let dcx = cx.dcx(); let name = if is_bench { "bench" } else { "test" }; - let msg = format!("the `#[{name}]` attribute may only be used on a free function"); + let msg = format!("the `{name}` attribute may only be used on a free function"); let level = match item.map(|i| &i.kind) { // These were a warning before #92959 and need to continue being that to avoid breaking // stable user code (#94508). @@ -432,7 +432,7 @@ fn not_testable_error(cx: &ExtCtxt<'_>, is_bench: bool, attr_sp: Span, item: Opt ), ); } - err.span_label(attr_sp, format!("the `#[{name}]` macro causes a function to be run as a test and has no effect on non-functions")); + err.span_label(attr_sp, format!("the `{name}` attribute causes a function to be run as a test and has no effect on non-functions")); if !is_bench { err.with_span_suggestion(attr_sp, diff --git a/tests/ui/feature-gates/gating-of-test-attrs.rs b/tests/ui/feature-gates/gating-of-test-attrs.rs index 3b07e2ad03c9f..4222c443a61be 100644 --- a/tests/ui/feature-gates/gating-of-test-attrs.rs +++ b/tests/ui/feature-gates/gating-of-test-attrs.rs @@ -3,22 +3,22 @@ // test is a built-in macro, not a built-in attribute, but it kind of acts like both. // check its target checking anyway here #[test] -//~^ ERROR the `#[test]` attribute may only be used on a free function +//~^ ERROR the `test` attribute may only be used on a free function mod test { mod inner { #![test] } //~^ ERROR inner macro attributes are unstable - //~| ERROR the `#[test]` attribute may only be used on a free function + //~| ERROR the `test` attribute may only be used on a free function #[test] - //~^ ERROR the `#[test]` attribute may only be used on a free function + //~^ ERROR the `test` attribute may only be used on a free function struct S; #[test] - //~^ ERROR the `#[test]` attribute may only be used on a free function + //~^ ERROR the `test` attribute may only be used on a free function type T = S; #[test] - //~^ ERROR the `#[test]` attribute may only be used on a free function + //~^ ERROR the `test` attribute may only be used on a free function impl S { } } @@ -26,22 +26,22 @@ mod test { // non-crate-level #[bench] attributes seem to be ignored. #[bench] -//~^ ERROR the `#[bench]` attribute may only be used on a free function +//~^ ERROR the `bench` attribute may only be used on a free function mod bench { mod inner { #![bench] } //~^ ERROR inner macro attributes are unstable - //~| ERROR the `#[bench]` attribute may only be used on a free function + //~| ERROR the `bench` attribute may only be used on a free function #[bench] - //~^ ERROR the `#[bench]` attribute may only be used on a free function + //~^ ERROR the `bench` attribute may only be used on a free function struct S; #[bench] - //~^ ERROR the `#[bench]` attribute may only be used on a free function + //~^ ERROR the `bench` attribute may only be used on a free function type T = S; #[bench] - //~^ ERROR the `#[bench]` attribute may only be used on a free function + //~^ ERROR the `bench` attribute may only be used on a free function impl S { } } diff --git a/tests/ui/feature-gates/gating-of-test-attrs.stderr b/tests/ui/feature-gates/gating-of-test-attrs.stderr index 0f47ab85dc18e..3cc209f46c051 100644 --- a/tests/ui/feature-gates/gating-of-test-attrs.stderr +++ b/tests/ui/feature-gates/gating-of-test-attrs.stderr @@ -1,8 +1,8 @@ -error: the `#[test]` attribute may only be used on a free function +error: the `test` attribute may only be used on a free function --> $DIR/gating-of-test-attrs.rs:5:1 | LL | #[test] - | ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions + | ^^^^^^^ the `test` attribute causes a function to be run as a test and has no effect on non-functions LL | LL | / mod test { LL | | mod inner { #![test] } @@ -27,13 +27,13 @@ LL | mod inner { #![test] } = help: add `#![feature(custom_inner_attributes)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date -error: the `#[test]` attribute may only be used on a free function +error: the `test` attribute may only be used on a free function --> $DIR/gating-of-test-attrs.rs:8:17 | LL | mod inner { #![test] } | ------------^^^^^^^^-- | | | - | | the `#[test]` macro causes a function to be run as a test and has no effect on non-functions + | | the `test` attribute causes a function to be run as a test and has no effect on non-functions | expected a non-associated function, found a module | help: replace with conditional compilation to make the item only exist when tests are being run @@ -42,11 +42,11 @@ LL - mod inner { #![test] } LL + mod inner { #[cfg(test)] } | -error: the `#[test]` attribute may only be used on a free function +error: the `test` attribute may only be used on a free function --> $DIR/gating-of-test-attrs.rs:12:5 | LL | #[test] - | ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions + | ^^^^^^^ the `test` attribute causes a function to be run as a test and has no effect on non-functions LL | LL | struct S; | --------- expected a non-associated function, found a struct @@ -57,11 +57,11 @@ LL - #[test] LL + #[cfg(test)] | -error: the `#[test]` attribute may only be used on a free function +error: the `test` attribute may only be used on a free function --> $DIR/gating-of-test-attrs.rs:16:5 | LL | #[test] - | ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions + | ^^^^^^^ the `test` attribute causes a function to be run as a test and has no effect on non-functions LL | LL | type T = S; | ----------- expected a non-associated function, found a type alias @@ -72,11 +72,11 @@ LL - #[test] LL + #[cfg(test)] | -error: the `#[test]` attribute may only be used on a free function +error: the `test` attribute may only be used on a free function --> $DIR/gating-of-test-attrs.rs:20:5 | LL | #[test] - | ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions + | ^^^^^^^ the `test` attribute causes a function to be run as a test and has no effect on non-functions LL | LL | impl S { } | ---------- expected a non-associated function, found an implementation @@ -87,11 +87,11 @@ LL - #[test] LL + #[cfg(test)] | -error: the `#[bench]` attribute may only be used on a free function +error: the `bench` attribute may only be used on a free function --> $DIR/gating-of-test-attrs.rs:28:1 | LL | #[bench] - | ^^^^^^^^ the `#[bench]` macro causes a function to be run as a test and has no effect on non-functions + | ^^^^^^^^ the `bench` attribute causes a function to be run as a test and has no effect on non-functions LL | LL | / mod bench { LL | | mod inner { #![bench] } @@ -110,38 +110,38 @@ LL | mod inner { #![bench] } = help: add `#![feature(custom_inner_attributes)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date -error: the `#[bench]` attribute may only be used on a free function +error: the `bench` attribute may only be used on a free function --> $DIR/gating-of-test-attrs.rs:31:17 | LL | mod inner { #![bench] } | ------------^^^^^^^^^-- | | | - | | the `#[bench]` macro causes a function to be run as a test and has no effect on non-functions + | | the `bench` attribute causes a function to be run as a test and has no effect on non-functions | expected a non-associated function, found a module -error: the `#[bench]` attribute may only be used on a free function +error: the `bench` attribute may only be used on a free function --> $DIR/gating-of-test-attrs.rs:35:5 | LL | #[bench] - | ^^^^^^^^ the `#[bench]` macro causes a function to be run as a test and has no effect on non-functions + | ^^^^^^^^ the `bench` attribute causes a function to be run as a test and has no effect on non-functions LL | LL | struct S; | --------- expected a non-associated function, found a struct -error: the `#[bench]` attribute may only be used on a free function +error: the `bench` attribute may only be used on a free function --> $DIR/gating-of-test-attrs.rs:39:5 | LL | #[bench] - | ^^^^^^^^ the `#[bench]` macro causes a function to be run as a test and has no effect on non-functions + | ^^^^^^^^ the `bench` attribute causes a function to be run as a test and has no effect on non-functions LL | LL | type T = S; | ----------- expected a non-associated function, found a type alias -error: the `#[bench]` attribute may only be used on a free function +error: the `bench` attribute may only be used on a free function --> $DIR/gating-of-test-attrs.rs:43:5 | LL | #[bench] - | ^^^^^^^^ the `#[bench]` macro causes a function to be run as a test and has no effect on non-functions + | ^^^^^^^^ the `bench` attribute causes a function to be run as a test and has no effect on non-functions LL | LL | impl S { } | ---------- expected a non-associated function, found an implementation diff --git a/tests/ui/macros/issue-111749.rs b/tests/ui/macros/issue-111749.rs index e92b9e4ccff82..f009a69fe2535 100644 --- a/tests/ui/macros/issue-111749.rs +++ b/tests/ui/macros/issue-111749.rs @@ -6,7 +6,7 @@ macro_rules! cbor_map { fn main() { cbor_map! { #[test(test)] 4i32}; - //~^ ERROR the `#[test]` attribute may only be used on a free function + //~^ ERROR the `test` attribute may only be used on a free function //~| ERROR attribute must be of the form `#[test]` //~| WARNING this was previously accepted by the compiler but is being phased out } diff --git a/tests/ui/macros/issue-111749.stderr b/tests/ui/macros/issue-111749.stderr index ead01f87eaec0..267f939602b5b 100644 --- a/tests/ui/macros/issue-111749.stderr +++ b/tests/ui/macros/issue-111749.stderr @@ -1,8 +1,8 @@ -error: the `#[test]` attribute may only be used on a free function +error: the `test` attribute may only be used on a free function --> $DIR/issue-111749.rs:8:17 | LL | cbor_map! { #[test(test)] 4i32}; - | ^^^^^^^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions + | ^^^^^^^^^^^^^ the `test` attribute causes a function to be run as a test and has no effect on non-functions | help: replace with conditional compilation to make the item only exist when tests are being run | diff --git a/tests/ui/macros/test-on-crate-root.rs b/tests/ui/macros/test-on-crate-root.rs index 88d6ec40af840..5bf965e32a282 100644 --- a/tests/ui/macros/test-on-crate-root.rs +++ b/tests/ui/macros/test-on-crate-root.rs @@ -4,7 +4,7 @@ // when referring to the attribute with full path specifically. #![core::prelude::v1::test] //~^ ERROR inner macro attributes are unstable -//~| ERROR the `#[test]` attribute may only be used on a free function +//~| ERROR the `test` attribute may only be used on a free function fn main() {} diff --git a/tests/ui/macros/test-on-crate-root.stderr b/tests/ui/macros/test-on-crate-root.stderr index 750c510ecbca1..b69dcb0a02a76 100644 --- a/tests/ui/macros/test-on-crate-root.stderr +++ b/tests/ui/macros/test-on-crate-root.stderr @@ -8,11 +8,11 @@ LL | #![core::prelude::v1::test] = help: add `#![feature(custom_inner_attributes)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date -error: the `#[test]` attribute may only be used on a free function +error: the `test` attribute may only be used on a free function --> $DIR/test-on-crate-root.rs:5:1 | LL | #![core::prelude::v1::test] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the `test` attribute causes a function to be run as a test and has no effect on non-functions | help: replace with conditional compilation to make the item only exist when tests are being run | diff --git a/tests/ui/test-attrs/issue-109816.rs b/tests/ui/test-attrs/issue-109816.rs index f40f99946da14..60d014afdf3ea 100644 --- a/tests/ui/test-attrs/issue-109816.rs +++ b/tests/ui/test-attrs/issue-109816.rs @@ -3,6 +3,6 @@ fn align_offset_weird_strides() { #[test] - //~^ ERROR the `#[test]` attribute may only be used on a free function + //~^ ERROR the `test` attribute may only be used on a free function struct A5(u32, u8); } diff --git a/tests/ui/test-attrs/issue-109816.stderr b/tests/ui/test-attrs/issue-109816.stderr index 118c8d8782905..b3e414b9dbe2e 100644 --- a/tests/ui/test-attrs/issue-109816.stderr +++ b/tests/ui/test-attrs/issue-109816.stderr @@ -1,8 +1,8 @@ -error: the `#[test]` attribute may only be used on a free function +error: the `test` attribute may only be used on a free function --> $DIR/issue-109816.rs:5:5 | LL | #[test] - | ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions + | ^^^^^^^ the `test` attribute causes a function to be run as a test and has no effect on non-functions LL | LL | struct A5(u32, u8); | ------------------- expected a non-associated function, found a struct diff --git a/tests/ui/test-attrs/test-attr-non-associated-functions.rs b/tests/ui/test-attrs/test-attr-non-associated-functions.rs index 9d28f59888a0c..7adfb3189c773 100644 --- a/tests/ui/test-attrs/test-attr-non-associated-functions.rs +++ b/tests/ui/test-attrs/test-attr-non-associated-functions.rs @@ -5,12 +5,12 @@ struct A {} impl A { #[test] - //~^ ERROR the `#[test]` attribute may only be used on a free function + //~^ ERROR the `test` attribute may only be used on a free function fn new() -> A { A {} } #[test] - //~^ ERROR the `#[test]` attribute may only be used on a free function + //~^ ERROR the `test` attribute may only be used on a free function fn recovery_witness() -> A { A {} } diff --git a/tests/ui/test-attrs/test-attr-non-associated-functions.stderr b/tests/ui/test-attrs/test-attr-non-associated-functions.stderr index fda28ee28a07c..3d8c963517f43 100644 --- a/tests/ui/test-attrs/test-attr-non-associated-functions.stderr +++ b/tests/ui/test-attrs/test-attr-non-associated-functions.stderr @@ -1,8 +1,8 @@ -error: the `#[test]` attribute may only be used on a free function +error: the `test` attribute may only be used on a free function --> $DIR/test-attr-non-associated-functions.rs:7:5 | LL | #[test] - | ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions + | ^^^^^^^ the `test` attribute causes a function to be run as a test and has no effect on non-functions | help: replace with conditional compilation to make the item only exist when tests are being run | @@ -10,11 +10,11 @@ LL - #[test] LL + #[cfg(test)] | -error: the `#[test]` attribute may only be used on a free function +error: the `test` attribute may only be used on a free function --> $DIR/test-attr-non-associated-functions.rs:12:5 | LL | #[test] - | ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions + | ^^^^^^^ the `test` attribute causes a function to be run as a test and has no effect on non-functions | help: replace with conditional compilation to make the item only exist when tests are being run | diff --git a/tests/ui/test-attrs/test-on-not-fn.rs b/tests/ui/test-attrs/test-on-not-fn.rs index 57ae2b19cf5fb..23b6cdb02ebd3 100644 --- a/tests/ui/test-attrs/test-on-not-fn.rs +++ b/tests/ui/test-attrs/test-on-not-fn.rs @@ -1,10 +1,10 @@ //@ compile-flags: --test //@ reference: attributes.testing.test.allowed-positions -#[test] //~ ERROR: the `#[test]` attribute may only be used on a free function +#[test] //~ ERROR: the `test` attribute may only be used on a free function mod test {} -#[test] //~ ERROR: the `#[test]` attribute may only be used on a free function +#[test] //~ ERROR: the `test` attribute may only be used on a free function mod loooooooooooooong_teeeeeeeeeest { /* this is a comment @@ -18,37 +18,37 @@ mod loooooooooooooong_teeeeeeeeeest { */ } -#[test] //~ ERROR: the `#[test]` attribute may only be used on a free function +#[test] //~ ERROR: the `test` attribute may only be used on a free function extern "C" {} -#[test] //~ ERROR: the `#[test]` attribute may only be used on a free function +#[test] //~ ERROR: the `test` attribute may only be used on a free function trait Foo {} -#[test] //~ ERROR: the `#[test]` attribute may only be used on a free function +#[test] //~ ERROR: the `test` attribute may only be used on a free function impl Foo for i32 {} -#[test] //~ ERROR: the `#[test]` attribute may only be used on a free function +#[test] //~ ERROR: the `test` attribute may only be used on a free function const FOO: i32 = -1_i32; -#[test] //~ ERROR: the `#[test]` attribute may only be used on a free function +#[test] //~ ERROR: the `test` attribute may only be used on a free function static BAR: u64 = 10_000_u64; -#[test] //~ ERROR: the `#[test]` attribute may only be used on a free function +#[test] //~ ERROR: the `test` attribute may only be used on a free function enum MyUnit { Unit, } -#[test] //~ ERROR: the `#[test]` attribute may only be used on a free function +#[test] //~ ERROR: the `test` attribute may only be used on a free function struct NewI32(i32); -#[test] //~ ERROR: the `#[test]` attribute may only be used on a free function +#[test] //~ ERROR: the `test` attribute may only be used on a free function union Spooky { x: i32, y: u32, } #[repr(C, align(64))] -#[test] //~ ERROR: the `#[test]` attribute may only be used on a free function +#[test] //~ ERROR: the `test` attribute may only be used on a free function #[derive(Copy, Clone, Debug)] struct MoreAttrs { a: i32, @@ -59,7 +59,7 @@ macro_rules! foo { () => {}; } -#[test] //~ WARN: the `#[test]` attribute may only be used on a free function +#[test] //~ WARN: the `test` attribute may only be used on a free function foo!(); // make sure it doesn't erroneously trigger on a real test diff --git a/tests/ui/test-attrs/test-on-not-fn.stderr b/tests/ui/test-attrs/test-on-not-fn.stderr index 22e4792688563..3a97d0da4ff8c 100644 --- a/tests/ui/test-attrs/test-on-not-fn.stderr +++ b/tests/ui/test-attrs/test-on-not-fn.stderr @@ -1,8 +1,8 @@ -error: the `#[test]` attribute may only be used on a free function +error: the `test` attribute may only be used on a free function --> $DIR/test-on-not-fn.rs:4:1 | LL | #[test] - | ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions + | ^^^^^^^ the `test` attribute causes a function to be run as a test and has no effect on non-functions LL | mod test {} | ----------- expected a non-associated function, found a module | @@ -12,11 +12,11 @@ LL - #[test] LL + #[cfg(test)] | -error: the `#[test]` attribute may only be used on a free function +error: the `test` attribute may only be used on a free function --> $DIR/test-on-not-fn.rs:7:1 | LL | #[test] - | ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions + | ^^^^^^^ the `test` attribute causes a function to be run as a test and has no effect on non-functions LL | / mod loooooooooooooong_teeeeeeeeeest { LL | | /* LL | | this is a comment @@ -32,11 +32,11 @@ LL - #[test] LL + #[cfg(test)] | -error: the `#[test]` attribute may only be used on a free function +error: the `test` attribute may only be used on a free function --> $DIR/test-on-not-fn.rs:21:1 | LL | #[test] - | ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions + | ^^^^^^^ the `test` attribute causes a function to be run as a test and has no effect on non-functions LL | extern "C" {} | ------------- expected a non-associated function, found an extern block | @@ -46,11 +46,11 @@ LL - #[test] LL + #[cfg(test)] | -error: the `#[test]` attribute may only be used on a free function +error: the `test` attribute may only be used on a free function --> $DIR/test-on-not-fn.rs:24:1 | LL | #[test] - | ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions + | ^^^^^^^ the `test` attribute causes a function to be run as a test and has no effect on non-functions LL | trait Foo {} | ------------ expected a non-associated function, found a trait | @@ -60,11 +60,11 @@ LL - #[test] LL + #[cfg(test)] | -error: the `#[test]` attribute may only be used on a free function +error: the `test` attribute may only be used on a free function --> $DIR/test-on-not-fn.rs:27:1 | LL | #[test] - | ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions + | ^^^^^^^ the `test` attribute causes a function to be run as a test and has no effect on non-functions LL | impl Foo for i32 {} | ------------------- expected a non-associated function, found an implementation | @@ -74,11 +74,11 @@ LL - #[test] LL + #[cfg(test)] | -error: the `#[test]` attribute may only be used on a free function +error: the `test` attribute may only be used on a free function --> $DIR/test-on-not-fn.rs:30:1 | LL | #[test] - | ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions + | ^^^^^^^ the `test` attribute causes a function to be run as a test and has no effect on non-functions LL | const FOO: i32 = -1_i32; | ------------------------ expected a non-associated function, found a constant item | @@ -88,11 +88,11 @@ LL - #[test] LL + #[cfg(test)] | -error: the `#[test]` attribute may only be used on a free function +error: the `test` attribute may only be used on a free function --> $DIR/test-on-not-fn.rs:33:1 | LL | #[test] - | ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions + | ^^^^^^^ the `test` attribute causes a function to be run as a test and has no effect on non-functions LL | static BAR: u64 = 10_000_u64; | ----------------------------- expected a non-associated function, found a static item | @@ -102,11 +102,11 @@ LL - #[test] LL + #[cfg(test)] | -error: the `#[test]` attribute may only be used on a free function +error: the `test` attribute may only be used on a free function --> $DIR/test-on-not-fn.rs:36:1 | LL | #[test] - | ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions + | ^^^^^^^ the `test` attribute causes a function to be run as a test and has no effect on non-functions LL | / enum MyUnit { LL | | Unit, LL | | } @@ -118,11 +118,11 @@ LL - #[test] LL + #[cfg(test)] | -error: the `#[test]` attribute may only be used on a free function +error: the `test` attribute may only be used on a free function --> $DIR/test-on-not-fn.rs:41:1 | LL | #[test] - | ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions + | ^^^^^^^ the `test` attribute causes a function to be run as a test and has no effect on non-functions LL | struct NewI32(i32); | ------------------- expected a non-associated function, found a struct | @@ -132,11 +132,11 @@ LL - #[test] LL + #[cfg(test)] | -error: the `#[test]` attribute may only be used on a free function +error: the `test` attribute may only be used on a free function --> $DIR/test-on-not-fn.rs:44:1 | LL | #[test] - | ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions + | ^^^^^^^ the `test` attribute causes a function to be run as a test and has no effect on non-functions LL | / union Spooky { LL | | x: i32, LL | | y: u32, @@ -149,11 +149,11 @@ LL - #[test] LL + #[cfg(test)] | -error: the `#[test]` attribute may only be used on a free function +error: the `test` attribute may only be used on a free function --> $DIR/test-on-not-fn.rs:51:1 | LL | #[test] - | ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions + | ^^^^^^^ the `test` attribute causes a function to be run as a test and has no effect on non-functions LL | #[derive(Copy, Clone, Debug)] LL | / struct MoreAttrs { LL | | a: i32, @@ -167,11 +167,11 @@ LL - #[test] LL + #[cfg(test)] | -warning: the `#[test]` attribute may only be used on a free function +warning: the `test` attribute may only be used on a free function --> $DIR/test-on-not-fn.rs:62:1 | LL | #[test] - | ^^^^^^^ the `#[test]` macro causes a function to be run as a test and has no effect on non-functions + | ^^^^^^^ the `test` attribute causes a function to be run as a test and has no effect on non-functions LL | foo!(); | ------- expected a non-associated function, found an item macro invocation | From 57b38a4b84c8f4ee7bb3a73d30c08e8da45ba3c1 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 28 Jul 2026 14:27:24 +1000 Subject: [PATCH 32/41] Improve consistency of unsafe attribute error messages The carets already point to just the attribute path, which is what we want. --- .../rustc_attr_parsing/src/diagnostics.rs | 2 +- tests/ui/lint/lint-unsafe-code.rs | 48 +++++++++---------- tests/ui/lint/lint-unsafe-code.stderr | 48 +++++++++---------- 3 files changed, 49 insertions(+), 49 deletions(-) diff --git a/compiler/rustc_attr_parsing/src/diagnostics.rs b/compiler/rustc_attr_parsing/src/diagnostics.rs index d5ea103dd1ae3..bd99e370c70e5 100644 --- a/compiler/rustc_attr_parsing/src/diagnostics.rs +++ b/compiler/rustc_attr_parsing/src/diagnostics.rs @@ -814,7 +814,7 @@ pub(crate) enum InvalidOnClause { pub(crate) struct DupesNotAllowed; #[derive(Diagnostic)] -#[diag("usage of the unsafe `#[{$attr_path}]` attribute")] +#[diag("usage of the unsafe `{$attr_path}` attribute")] #[note("{$note}")] pub(crate) struct UnsafeAttribute { pub attr_path: AttrPath, diff --git a/tests/ui/lint/lint-unsafe-code.rs b/tests/ui/lint/lint-unsafe-code.rs index 1f032fdca1315..f614883ce5320 100644 --- a/tests/ui/lint/lint-unsafe-code.rs +++ b/tests/ui/lint/lint-unsafe-code.rs @@ -25,18 +25,18 @@ mod allowed_unsafe { macro_rules! unsafe_in_macro { () => {{ - #[no_mangle] fn foo() {} //~ ERROR: usage of the unsafe `#[no_mangle]` attribute - #[no_mangle] static FOO: u32 = 5; //~ ERROR: usage of the unsafe `#[no_mangle]` attribute + #[no_mangle] fn foo() {} //~ ERROR: usage of the unsafe `no_mangle` attribute + #[no_mangle] static FOO: u32 = 5; //~ ERROR: usage of the unsafe `no_mangle` attribute #[export_name = "bar"] fn bar() {} - //~^ ERROR: usage of the unsafe `#[export_name]` attribute + //~^ ERROR: usage of the unsafe `export_name` attribute #[export_name = "BAR"] static BAR: u32 = 5; - //~^ ERROR: usage of the unsafe `#[export_name]` attribute + //~^ ERROR: usage of the unsafe `export_name` attribute unsafe {} //~ ERROR: usage of an `unsafe` block }} } -#[no_mangle] fn foo() {} //~ ERROR: usage of the unsafe `#[no_mangle]` attribute -#[no_mangle] static FOO: u32 = 5; //~ ERROR: usage of the unsafe `#[no_mangle]` attribute +#[no_mangle] fn foo() {} //~ ERROR: usage of the unsafe `no_mangle` attribute +#[no_mangle] static FOO: u32 = 5; //~ ERROR: usage of the unsafe `no_mangle` attribute trait AssocFnTrait { fn foo(); @@ -45,27 +45,27 @@ trait AssocFnTrait { struct AssocFnFoo; impl AssocFnFoo { - #[no_mangle] fn foo() {} //~ ERROR: usage of the unsafe `#[no_mangle]` attribute + #[no_mangle] fn foo() {} //~ ERROR: usage of the unsafe `no_mangle` attribute } impl AssocFnTrait for AssocFnFoo { - #[no_mangle] fn foo() {} //~ ERROR: usage of the unsafe `#[no_mangle]` attribute + #[no_mangle] fn foo() {} //~ ERROR: usage of the unsafe `no_mangle` attribute } -#[export_name = "bar"] fn bar() {} //~ ERROR: usage of the unsafe `#[export_name]` attribute -#[export_name = "BAR"] static BAR: u32 = 5; //~ ERROR: usage of the unsafe `#[export_name]` attribute +#[export_name = "bar"] fn bar() {} //~ ERROR: usage of the unsafe `export_name` attribute +#[export_name = "BAR"] static BAR: u32 = 5; //~ ERROR: usage of the unsafe `export_name` attribute -#[link_section = "__TEXT,__text"] fn uwu() {} //~ ERROR: usage of the unsafe `#[link_section]` attribute -#[link_section = "__TEXT,__text"] static UWU: u32 = 5; //~ ERROR: usage of the unsafe `#[link_section]` attribute +#[link_section = "__TEXT,__text"] fn uwu() {} //~ ERROR: usage of the unsafe `link_section` attribute +#[link_section = "__TEXT,__text"] static UWU: u32 = 5; //~ ERROR: usage of the unsafe `link_section` attribute struct AssocFnBar; impl AssocFnBar { - #[export_name = "bar"] fn bar() {} //~ ERROR: usage of the unsafe `#[export_name]` attribute + #[export_name = "bar"] fn bar() {} //~ ERROR: usage of the unsafe `export_name` attribute } impl AssocFnTrait for AssocFnBar { - #[export_name = "bar"] fn foo() {} //~ ERROR: usage of the unsafe `#[export_name]` attribute + #[export_name = "bar"] fn foo() {} //~ ERROR: usage of the unsafe `export_name` attribute } unsafe fn baz() {} //~ ERROR: declaration of an `unsafe` function @@ -137,48 +137,48 @@ fn main() { } #[unsafe(naked)] fn naked1() { naked_asm!("halt") } -//~^ ERROR usage of the unsafe `#[naked]` attribute +//~^ ERROR usage of the unsafe `naked` attribute struct Naked; impl Naked { #[unsafe(naked)] fn naked2() { naked_asm!("halt") } - //~^ ERROR usage of the unsafe `#[naked]` attribute + //~^ ERROR usage of the unsafe `naked` attribute } trait NakedTrait { #[unsafe(naked)] fn naked3() { naked_asm!("halt") } - //~^ ERROR usage of the unsafe `#[naked]` attribute + //~^ ERROR usage of the unsafe `naked` attribute fn naked4(); } impl NakedTrait for Naked { #[unsafe(naked)] fn naked4() { naked_asm!("halt") } - //~^ ERROR usage of the unsafe `#[naked]` attribute + //~^ ERROR usage of the unsafe `naked` attribute } extern "C" { #[unsafe(ffi_pure)] - //~^ ERROR usage of the unsafe `#[ffi_pure]` attribute + //~^ ERROR usage of the unsafe `ffi_pure` attribute fn ffi_pure(); #[unsafe(ffi_const)] - //~^ ERROR usage of the unsafe `#[ffi_const]` attribute + //~^ ERROR usage of the unsafe `ffi_const` attribute fn ffi_const(); } #[unsafe(force_target_feature(enable = "avx2"))] fn force_target_feature() { } -//~^ ERROR usage of the unsafe `#[force_target_feature]` attribute +//~^ ERROR usage of the unsafe `force_target_feature` attribute struct ForceTargetFeature; impl ForceTargetFeature { #[unsafe(force_target_feature(enable = "avx2"))] fn force_target_feature() { } - //~^ ERROR usage of the unsafe `#[force_target_feature]` attribute + //~^ ERROR usage of the unsafe `force_target_feature` attribute } trait ForceTargetFeatureTrait { #[unsafe(force_target_feature(enable = "avx2"))] fn force_target_feature() { } - //~^ ERROR usage of the unsafe `#[force_target_feature]` attribute + //~^ ERROR usage of the unsafe `force_target_feature` attribute } impl ForceTargetFeatureTrait for ForceTargetFeature { #[unsafe(force_target_feature(enable = "avx2"))] fn force_target_feature() { } - //~^ ERROR usage of the unsafe `#[force_target_feature]` attribute + //~^ ERROR usage of the unsafe `force_target_feature` attribute } diff --git a/tests/ui/lint/lint-unsafe-code.stderr b/tests/ui/lint/lint-unsafe-code.stderr index 7580756d612eb..9b4df1273acbc 100644 --- a/tests/ui/lint/lint-unsafe-code.stderr +++ b/tests/ui/lint/lint-unsafe-code.stderr @@ -93,7 +93,7 @@ LL | unsafe_in_macro!() | = note: this error originates in the macro `unsafe_in_macro` (in Nightly builds, run with -Z macro-backtrace for more info) -error: usage of the unsafe `#[no_mangle]` attribute +error: usage of the unsafe `no_mangle` attribute --> $DIR/lint-unsafe-code.rs:38:3 | LL | #[no_mangle] fn foo() {} @@ -101,7 +101,7 @@ LL | #[no_mangle] fn foo() {} | = note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them -error: usage of the unsafe `#[no_mangle]` attribute +error: usage of the unsafe `no_mangle` attribute --> $DIR/lint-unsafe-code.rs:39:3 | LL | #[no_mangle] static FOO: u32 = 5; @@ -109,7 +109,7 @@ LL | #[no_mangle] static FOO: u32 = 5; | = note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them -error: usage of the unsafe `#[export_name]` attribute +error: usage of the unsafe `export_name` attribute --> $DIR/lint-unsafe-code.rs:55:3 | LL | #[export_name = "bar"] fn bar() {} @@ -117,7 +117,7 @@ LL | #[export_name = "bar"] fn bar() {} | = note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them -error: usage of the unsafe `#[export_name]` attribute +error: usage of the unsafe `export_name` attribute --> $DIR/lint-unsafe-code.rs:56:3 | LL | #[export_name = "BAR"] static BAR: u32 = 5; @@ -125,7 +125,7 @@ LL | #[export_name = "BAR"] static BAR: u32 = 5; | = note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them -error: usage of the unsafe `#[link_section]` attribute +error: usage of the unsafe `link_section` attribute --> $DIR/lint-unsafe-code.rs:58:3 | LL | #[link_section = "__TEXT,__text"] fn uwu() {} @@ -133,7 +133,7 @@ LL | #[link_section = "__TEXT,__text"] fn uwu() {} | = note: the program's behavior with overridden link sections on items is unpredictable and Rust cannot provide guarantees when you manually override them -error: usage of the unsafe `#[link_section]` attribute +error: usage of the unsafe `link_section` attribute --> $DIR/lint-unsafe-code.rs:59:3 | LL | #[link_section = "__TEXT,__text"] static UWU: u32 = 5; @@ -141,7 +141,7 @@ LL | #[link_section = "__TEXT,__text"] static UWU: u32 = 5; | = note: the program's behavior with overridden link sections on items is unpredictable and Rust cannot provide guarantees when you manually override them -error: usage of the unsafe `#[no_mangle]` attribute +error: usage of the unsafe `no_mangle` attribute --> $DIR/lint-unsafe-code.rs:28:11 | LL | #[no_mangle] fn foo() {} @@ -153,7 +153,7 @@ LL | unsafe_in_macro!() = note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them = note: this error originates in the macro `unsafe_in_macro` (in Nightly builds, run with -Z macro-backtrace for more info) -error: usage of the unsafe `#[no_mangle]` attribute +error: usage of the unsafe `no_mangle` attribute --> $DIR/lint-unsafe-code.rs:29:11 | LL | #[no_mangle] static FOO: u32 = 5; @@ -165,7 +165,7 @@ LL | unsafe_in_macro!() = note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them = note: this error originates in the macro `unsafe_in_macro` (in Nightly builds, run with -Z macro-backtrace for more info) -error: usage of the unsafe `#[export_name]` attribute +error: usage of the unsafe `export_name` attribute --> $DIR/lint-unsafe-code.rs:30:11 | LL | #[export_name = "bar"] fn bar() {} @@ -177,7 +177,7 @@ LL | unsafe_in_macro!() = note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them = note: this error originates in the macro `unsafe_in_macro` (in Nightly builds, run with -Z macro-backtrace for more info) -error: usage of the unsafe `#[export_name]` attribute +error: usage of the unsafe `export_name` attribute --> $DIR/lint-unsafe-code.rs:32:11 | LL | #[export_name = "BAR"] static BAR: u32 = 5; @@ -189,7 +189,7 @@ LL | unsafe_in_macro!() = note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them = note: this error originates in the macro `unsafe_in_macro` (in Nightly builds, run with -Z macro-backtrace for more info) -error: usage of the unsafe `#[naked]` attribute +error: usage of the unsafe `naked` attribute --> $DIR/lint-unsafe-code.rs:139:3 | LL | #[unsafe(naked)] fn naked1() { naked_asm!("halt") } @@ -197,7 +197,7 @@ LL | #[unsafe(naked)] fn naked1() { naked_asm!("halt") } | = note: the `#[naked]` attribute adds the safety obligation that the function's body must respect the function’s calling convention, uphold its signature, and either return or diverge (i.e., not fall through past the end of the assembly code). -error: usage of the unsafe `#[force_target_feature]` attribute +error: usage of the unsafe `force_target_feature` attribute --> $DIR/lint-unsafe-code.rs:168:3 | LL | #[unsafe(force_target_feature(enable = "avx2"))] fn force_target_feature() { } @@ -205,7 +205,7 @@ LL | #[unsafe(force_target_feature(enable = "avx2"))] fn force_target_feature() | = note: a function with the signature of the function the attribute is applied to must only be callable if the force-enabled features are guaranteed to be present -error: usage of the unsafe `#[naked]` attribute +error: usage of the unsafe `naked` attribute --> $DIR/lint-unsafe-code.rs:149:7 | LL | #[unsafe(naked)] fn naked3() { naked_asm!("halt") } @@ -213,7 +213,7 @@ LL | #[unsafe(naked)] fn naked3() { naked_asm!("halt") } | = note: the `#[naked]` attribute adds the safety obligation that the function's body must respect the function’s calling convention, uphold its signature, and either return or diverge (i.e., not fall through past the end of the assembly code). -error: usage of the unsafe `#[force_target_feature]` attribute +error: usage of the unsafe `force_target_feature` attribute --> $DIR/lint-unsafe-code.rs:178:7 | LL | #[unsafe(force_target_feature(enable = "avx2"))] fn force_target_feature() { } @@ -221,7 +221,7 @@ LL | #[unsafe(force_target_feature(enable = "avx2"))] fn force_target_featur | = note: a function with the signature of the function the attribute is applied to must only be callable if the force-enabled features are guaranteed to be present -error: usage of the unsafe `#[no_mangle]` attribute +error: usage of the unsafe `no_mangle` attribute --> $DIR/lint-unsafe-code.rs:48:7 | LL | #[no_mangle] fn foo() {} @@ -229,7 +229,7 @@ LL | #[no_mangle] fn foo() {} | = note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them -error: usage of the unsafe `#[no_mangle]` attribute +error: usage of the unsafe `no_mangle` attribute --> $DIR/lint-unsafe-code.rs:52:7 | LL | #[no_mangle] fn foo() {} @@ -237,7 +237,7 @@ LL | #[no_mangle] fn foo() {} | = note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them -error: usage of the unsafe `#[export_name]` attribute +error: usage of the unsafe `export_name` attribute --> $DIR/lint-unsafe-code.rs:64:7 | LL | #[export_name = "bar"] fn bar() {} @@ -245,7 +245,7 @@ LL | #[export_name = "bar"] fn bar() {} | = note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them -error: usage of the unsafe `#[export_name]` attribute +error: usage of the unsafe `export_name` attribute --> $DIR/lint-unsafe-code.rs:68:7 | LL | #[export_name = "bar"] fn foo() {} @@ -253,7 +253,7 @@ LL | #[export_name = "bar"] fn foo() {} | = note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them -error: usage of the unsafe `#[naked]` attribute +error: usage of the unsafe `naked` attribute --> $DIR/lint-unsafe-code.rs:144:7 | LL | #[unsafe(naked)] fn naked2() { naked_asm!("halt") } @@ -261,7 +261,7 @@ LL | #[unsafe(naked)] fn naked2() { naked_asm!("halt") } | = note: the `#[naked]` attribute adds the safety obligation that the function's body must respect the function’s calling convention, uphold its signature, and either return or diverge (i.e., not fall through past the end of the assembly code). -error: usage of the unsafe `#[naked]` attribute +error: usage of the unsafe `naked` attribute --> $DIR/lint-unsafe-code.rs:154:7 | LL | #[unsafe(naked)] fn naked4() { naked_asm!("halt") } @@ -269,7 +269,7 @@ LL | #[unsafe(naked)] fn naked4() { naked_asm!("halt") } | = note: the `#[naked]` attribute adds the safety obligation that the function's body must respect the function’s calling convention, uphold its signature, and either return or diverge (i.e., not fall through past the end of the assembly code). -error: usage of the unsafe `#[force_target_feature]` attribute +error: usage of the unsafe `force_target_feature` attribute --> $DIR/lint-unsafe-code.rs:173:7 | LL | #[unsafe(force_target_feature(enable = "avx2"))] fn force_target_feature() { } @@ -277,7 +277,7 @@ LL | #[unsafe(force_target_feature(enable = "avx2"))] fn force_target_featur | = note: a function with the signature of the function the attribute is applied to must only be callable if the force-enabled features are guaranteed to be present -error: usage of the unsafe `#[force_target_feature]` attribute +error: usage of the unsafe `force_target_feature` attribute --> $DIR/lint-unsafe-code.rs:182:7 | LL | #[unsafe(force_target_feature(enable = "avx2"))] fn force_target_feature() { } @@ -285,7 +285,7 @@ LL | #[unsafe(force_target_feature(enable = "avx2"))] fn force_target_featur | = note: a function with the signature of the function the attribute is applied to must only be callable if the force-enabled features are guaranteed to be present -error: usage of the unsafe `#[ffi_pure]` attribute +error: usage of the unsafe `ffi_pure` attribute --> $DIR/lint-unsafe-code.rs:159:7 | LL | #[unsafe(ffi_pure)] @@ -293,7 +293,7 @@ LL | #[unsafe(ffi_pure)] | = note: `#[ffi_pure]` functions shall have no effects except for its return value, which shall not change across two consecutive function calls with the same parameters. -error: usage of the unsafe `#[ffi_const]` attribute +error: usage of the unsafe `ffi_const` attribute --> $DIR/lint-unsafe-code.rs:163:7 | LL | #[unsafe(ffi_const)] From 63805c34be31b77f80642c6f047ed9cbbae573de Mon Sep 17 00:00:00 2001 From: Yukang Date: Tue, 28 Jul 2026 12:09:37 +0800 Subject: [PATCH 33/41] Add regression test for generic associated function suggestions --- tests/ui/methods/issue-159813.rs | 15 +++++++++++++++ tests/ui/methods/issue-159813.stderr | 21 +++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 tests/ui/methods/issue-159813.rs create mode 100644 tests/ui/methods/issue-159813.stderr diff --git a/tests/ui/methods/issue-159813.rs b/tests/ui/methods/issue-159813.rs new file mode 100644 index 0000000000000..3d847882663e4 --- /dev/null +++ b/tests/ui/methods/issue-159813.rs @@ -0,0 +1,15 @@ +// The associated-function suggestion must use turbofish syntax for a generic ADT. + +trait Kind { + fn kind(); +} + +impl Kind for Option { + fn kind() {} +} + +fn main() { + let value = Some(2_i32); + value.kind(); + //~^ ERROR no method named `kind` found for enum `Option` +} diff --git a/tests/ui/methods/issue-159813.stderr b/tests/ui/methods/issue-159813.stderr new file mode 100644 index 0000000000000..35b604220a6c9 --- /dev/null +++ b/tests/ui/methods/issue-159813.stderr @@ -0,0 +1,21 @@ +error[E0599]: no method named `kind` found for enum `Option` in the current scope + --> $DIR/issue-159813.rs:13:11 + | +LL | value.kind(); + | ^^^^ this is an associated function, not a method + | + = note: found the following associated functions; to be used as methods, functions must have a `self` parameter +note: the candidate is defined in the trait `Kind` + --> $DIR/issue-159813.rs:4:5 + | +LL | fn kind(); + | ^^^^^^^^^^ +help: use associated function syntax instead + | +LL - value.kind(); +LL + Option::kind(); + | + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0599`. From 83dd3ce937c8f49f9ae157d5478d8c2b153a86b9 Mon Sep 17 00:00:00 2001 From: Yukang Date: Tue, 28 Jul 2026 12:39:34 +0800 Subject: [PATCH 34/41] Use value syntax for associated function suggestions --- compiler/rustc_hir_typeck/src/method/suggest.rs | 4 ++-- .../associated-fn-turbofish-issue-159813.fixed | 17 +++++++++++++++++ ... => associated-fn-turbofish-issue-159813.rs} | 6 ++++-- ...associated-fn-turbofish-issue-159813.stderr} | 12 ++++++------ 4 files changed, 29 insertions(+), 10 deletions(-) create mode 100644 tests/ui/methods/associated-fn-turbofish-issue-159813.fixed rename tests/ui/methods/{issue-159813.rs => associated-fn-turbofish-issue-159813.rs} (78%) rename tests/ui/methods/{issue-159813.stderr => associated-fn-turbofish-issue-159813.stderr} (64%) diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index 4365a95b4bd81..f4c084022a845 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -3399,7 +3399,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return; }; - let name = self.ty_to_value_string(actual); + let name = self.ty_to_string(actual); let inner_id = kind.did(); let mutable = if let Some(AutorefOrPtrAdjustment::Autoref { mutbl, .. }) = pick.autoref_or_ptr_adjustment @@ -3868,7 +3868,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// Print out the type for use in value namespace. fn ty_to_value_string(&self, ty: Ty<'tcx>) -> String { match ty.kind() { - ty::Adt(def, args) => self.tcx.def_path_str_with_args(def.did(), args), + ty::Adt(def, args) => self.tcx.value_path_str_with_args(def.did(), args), _ => self.ty_to_string(ty), } } diff --git a/tests/ui/methods/associated-fn-turbofish-issue-159813.fixed b/tests/ui/methods/associated-fn-turbofish-issue-159813.fixed new file mode 100644 index 0000000000000..bf712ba3fdbce --- /dev/null +++ b/tests/ui/methods/associated-fn-turbofish-issue-159813.fixed @@ -0,0 +1,17 @@ +//@ run-rustfix + +// The associated-function suggestion must use turbofish syntax for a generic ADT. + +trait Kind { + fn kind(); +} + +impl Kind for Option { + fn kind() {} +} + +fn main() { + let _value = Some(2_i32); + Option::::kind(); + //~^ ERROR no method named `kind` found for enum `Option` +} diff --git a/tests/ui/methods/issue-159813.rs b/tests/ui/methods/associated-fn-turbofish-issue-159813.rs similarity index 78% rename from tests/ui/methods/issue-159813.rs rename to tests/ui/methods/associated-fn-turbofish-issue-159813.rs index 3d847882663e4..8a29b3dbaf80c 100644 --- a/tests/ui/methods/issue-159813.rs +++ b/tests/ui/methods/associated-fn-turbofish-issue-159813.rs @@ -1,3 +1,5 @@ +//@ run-rustfix + // The associated-function suggestion must use turbofish syntax for a generic ADT. trait Kind { @@ -9,7 +11,7 @@ impl Kind for Option { } fn main() { - let value = Some(2_i32); - value.kind(); + let _value = Some(2_i32); + _value.kind(); //~^ ERROR no method named `kind` found for enum `Option` } diff --git a/tests/ui/methods/issue-159813.stderr b/tests/ui/methods/associated-fn-turbofish-issue-159813.stderr similarity index 64% rename from tests/ui/methods/issue-159813.stderr rename to tests/ui/methods/associated-fn-turbofish-issue-159813.stderr index 35b604220a6c9..34bf14db735f9 100644 --- a/tests/ui/methods/issue-159813.stderr +++ b/tests/ui/methods/associated-fn-turbofish-issue-159813.stderr @@ -1,19 +1,19 @@ error[E0599]: no method named `kind` found for enum `Option` in the current scope - --> $DIR/issue-159813.rs:13:11 + --> $DIR/associated-fn-turbofish-issue-159813.rs:15:12 | -LL | value.kind(); - | ^^^^ this is an associated function, not a method +LL | _value.kind(); + | ^^^^ this is an associated function, not a method | = note: found the following associated functions; to be used as methods, functions must have a `self` parameter note: the candidate is defined in the trait `Kind` - --> $DIR/issue-159813.rs:4:5 + --> $DIR/associated-fn-turbofish-issue-159813.rs:6:5 | LL | fn kind(); | ^^^^^^^^^^ help: use associated function syntax instead | -LL - value.kind(); -LL + Option::kind(); +LL - _value.kind(); +LL + Option::::kind(); | error: aborting due to 1 previous error From d2615b6024ebe0df3bf1392701d2b6bc2a3f2002 Mon Sep 17 00:00:00 2001 From: Mend Renovate Date: Tue, 28 Jul 2026 11:53:34 +0000 Subject: [PATCH 35/41] Update Rust crate tracing-subscriber to v0.3.23 [SECURITY] --- Cargo.lock | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f426607920f4c..ae767ea192d1b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -848,7 +848,7 @@ version = "3.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "faf9468729b8cbcea668e36183cb69d317348c2e08e994829fb56ebfdfbaac34" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -1261,7 +1261,7 @@ dependencies = [ "libc", "option-ext", "redox_users", - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -1388,7 +1388,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -2166,7 +2166,7 @@ dependencies = [ "portable-atomic", "portable-atomic-util", "serde_core", - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -2653,7 +2653,7 @@ version = "0.50.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -5084,7 +5084,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -5516,7 +5516,7 @@ dependencies = [ "getrandom 0.3.3", "once_cell", "rustix", - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -5535,7 +5535,7 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8c27177b12a6399ffc08b98f76f7c9a1f4fe9fc967c784c5a071fa8d93cf7e1" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] @@ -5905,9 +5905,9 @@ dependencies = [ [[package]] name = "tracing-subscriber" -version = "0.3.22" +version = "0.3.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f30143827ddab0d256fd843b7a66d164e9f271cfa0dde49142c5ca0ca291f1e" +checksum = "cb7f578e5945fb242538965c2d0b04418d38ec25c79d160cd279bf0731c8d319" dependencies = [ "matchers", "nu-ansi-term", @@ -6513,7 +6513,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.59.0", ] [[package]] From c81b591b3de0f01fb8c5aec69477deea64038adb Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 28 Jul 2026 15:03:16 +0200 Subject: [PATCH 36/41] sanitize_standard_fds: clarify macos comment --- library/std/src/sys/pal/unix/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/sys/pal/unix/mod.rs b/library/std/src/sys/pal/unix/mod.rs index 1f9b86e1eb75e..2bd28ba498370 100644 --- a/library/std/src/sys/pal/unix/mod.rs +++ b/library/std/src/sys/pal/unix/mod.rs @@ -84,7 +84,7 @@ pub unsafe fn init(argc: isize, argv: *const *const u8, sigpipe: u8) { target_os = "horizon", target_os = "vita", target_os = "rtems", - // The poll on Darwin doesn't set POLLNVAL for closed fds. + // The poll on Darwin doesn't set POLLNVAL for closed fds when `events == 0`. target_vendor = "apple", )))] 'poll: { From 7c113838d4430c304c9ff1b5756322657cc554df Mon Sep 17 00:00:00 2001 From: MarcoIeni <11428655+MarcoIeni@users.noreply.github.com> Date: Tue, 28 Jul 2026 15:20:44 +0200 Subject: [PATCH 37/41] use unstable features when updating dependencies --- .github/renovate.json5 | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/.github/renovate.json5 b/.github/renovate.json5 index e060dfd3b638b..89862ba553144 100644 --- a/.github/renovate.json5 +++ b/.github/renovate.json5 @@ -9,6 +9,17 @@ // (still gated by dashboard approval for now) ":maintainLockFilesMonthly", ], + // Cargo manifests in this repository use unstable features. + "env": { + "RUSTC_BOOTSTRAP": "1" + }, + // The compiler and rustbook workspaces have path dependencies in these + // submodules. + "cloneSubmodules": true, + "cloneSubmodulesFilter": [ + "src/doc/book", + "src/doc/reference" + ], // Require manual approval from the Dependency Dashboard before opening PRs "dependencyDashboardApproval": true, // Renovate shouldn't update a PR if it is in the bors merge queue. @@ -18,6 +29,22 @@ // No dashboard approval necessary for GitHub Actions updates "matchManagers": ["github-actions"], "dependencyDashboardApproval": false + }, + { + // Only maintain the Cargo lockfiles managed by update-lockfile.sh. + "matchManagers": ["cargo"], + "matchUpdateTypes": ["lockFileMaintenance"], + "enabled": false + }, + { + "matchManagers": ["cargo"], + "matchUpdateTypes": ["lockFileMaintenance"], + "matchFileNames": [ + "Cargo.toml", + "library/Cargo.toml", + "src/tools/rustbook/Cargo.toml" + ], + "enabled": true } ], // Don't manage dependencies inside subtrees. They are updated upstream and From 9e3d23a3db1f7ffa2318358f154fddc470af95c2 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 28 Jul 2026 18:23:30 +0200 Subject: [PATCH 38/41] miri ui tests: don't run native tests on stage 0 --- src/tools/miri/tests/ui.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/tools/miri/tests/ui.rs b/src/tools/miri/tests/ui.rs index 3e46ee17c8a65..b2fda8e0c62c9 100644 --- a/src/tools/miri/tests/ui.rs +++ b/src/tools/miri/tests/ui.rs @@ -440,7 +440,10 @@ fn main() -> Result<()> { ui(Mode::Pass { native: false }, "tests/pass", &target, WithoutDeps, tmpdir.path())?; ui(Mode::Pass { native: false }, "tests/pass-dep", &target, WithDeps, tmpdir.path())?; - if target == host { + if target == host + // Skip native test execution during bootstrap as the sysroot is not quite right there. + && env::var("RUSTC_STAGE").ok().is_none_or(|s| s != "0") + { ui(Mode::Pass { native: true }, "tests/pass", &target, WithoutDeps, tmpdir.path())?; ui(Mode::Pass { native: true }, "tests/pass-dep", &target, WithDeps, tmpdir.path())?; } From 24a1d5159aa6b4905e6a9f09f59ca02022e0dbb1 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 28 Jul 2026 09:32:52 -0700 Subject: [PATCH 39/41] Switch cargo assignments to weihanglo --- triagebot.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/triagebot.toml b/triagebot.toml index 707d54941aeee..511aa3f6bc270 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -1160,7 +1160,7 @@ cc = [ ] [mentions."src/tools/cargo"] -cc = ["@ehuss"] +cc = ["@weihanglo"] [mentions."src/tools/clippy"] message = """ @@ -1713,7 +1713,7 @@ dep-bumps = [ "/tests/ui" = ["compiler"] "/tests/ui-fulldeps" = ["compiler"] "/src/tools/build-manifest" = ["bootstrap"] -"/src/tools/cargo" = ["@ehuss"] +"/src/tools/cargo" = ["@weihanglo"] "/src/tools/compiletest" = ["bootstrap", "@wesleywiser", "@oli-obk", "@jieyouxu"] "/src/tools/linkchecker" = ["@ehuss"] "/src/tools/opt-dist" = ["@kobzol"] From a0bed95407a4520033b8cdccc8036c343417b88a Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 28 Jul 2026 09:45:50 -0700 Subject: [PATCH 40/41] Update assignment for docs I'm updating the docs to point to lang-docs instead of just myself. --- src/tools/publish_toolstate.py | 12 ++++++------ triagebot.toml | 21 ++++++++++----------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/tools/publish_toolstate.py b/src/tools/publish_toolstate.py index 3688513987dc8..fd67bbe0b11bd 100755 --- a/src/tools/publish_toolstate.py +++ b/src/tools/publish_toolstate.py @@ -30,18 +30,18 @@ # These should be collaborators of the rust-lang/rust repository (with at least # read privileges on it). CI will fail otherwise. MAINTAINERS = { - "book": {"ehuss", "chriskrycho", "carols10cents"}, - "nomicon": {"ehuss", "JohnTitor"}, - "reference": {"ehuss"}, - "rust-by-example": {"ehuss", "marioidival"}, + "book": {"traviscross", "chriskrycho", "carols10cents"}, + "nomicon": {"traviscross", "JohnTitor"}, + "reference": {"traviscross"}, + "rust-by-example": {"traviscross", "marioidival"}, "embedded-book": { - "ehuss", + "traviscross", "adamgreig", "andre-richter", "jamesmunns", "therealprof", }, - "edition-guide": {"ehuss"}, + "edition-guide": {"traviscross"}, } LABELS = { diff --git a/triagebot.toml b/triagebot.toml index 511aa3f6bc270..5882e217430e9 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -1417,7 +1417,7 @@ message = """If the Unicode version changes are intentional, it should also be updated in the reference at https://github.com/rust-lang/reference/blob/HEAD/src/identifiers.md. """ -cc = ["@ehuss"] +cc = ["@rust-lang/lang-docs"] [mentions."src/doc/rustc-dev-guide"] message = """ @@ -1551,7 +1551,6 @@ infra-ci = [ "@jieyouxu", ] docs = [ - "@ehuss", "@GuillaumeGomez", ] codegen = [ @@ -1674,13 +1673,13 @@ dep-bumps = [ "/src/bootstrap" = ["bootstrap"] "/src/ci" = ["infra-ci"] "/src/doc" = ["docs"] -"/src/doc/book" = ["@ehuss"] -"/src/doc/edition-guide" = ["@ehuss"] -"/src/doc/embedded-book" = ["@ehuss"] -"/src/doc/nomicon" = ["@ehuss"] -"/src/doc/reference" = ["@ehuss"] -"/src/doc/rust-by-example" = ["@ehuss"] -"/src/doc/rustc" = ["compiler", "@ehuss"] +"/src/doc/book" = ["lang-docs"] +"/src/doc/edition-guide" = ["lang-docs"] +"/src/doc/embedded-book" = ["lang-docs"] +"/src/doc/nomicon" = ["lang-docs"] +"/src/doc/reference" = ["lang-docs"] +"/src/doc/rust-by-example" = ["lang-docs"] +"/src/doc/rustc" = ["compiler"] "/src/doc/rustc-dev-guide" = ["compiler"] "/src/doc/rustdoc" = ["rustdoc"] "/src/doc/style-guide" = ["style-team"] @@ -1715,11 +1714,11 @@ dep-bumps = [ "/src/tools/build-manifest" = ["bootstrap"] "/src/tools/cargo" = ["@weihanglo"] "/src/tools/compiletest" = ["bootstrap", "@wesleywiser", "@oli-obk", "@jieyouxu"] -"/src/tools/linkchecker" = ["@ehuss"] +"/src/tools/linkchecker" = ["lang-docs"] "/src/tools/opt-dist" = ["@kobzol"] "/src/tools/run-make-support" = ["@jieyouxu"] "/src/tools/rust-installer" = ["bootstrap"] -"/src/tools/rustbook" = ["@ehuss"] +"/src/tools/rustbook" = ["lang-docs"] "/src/tools/rustdoc" = ["rustdoc"] "/src/tools/rustdoc-js" = ["rustdoc"] "/src/tools/rustdoc-themes" = ["rustdoc"] From 1047fdb4d360feee9e3c47884abeb81ba3a4e15c Mon Sep 17 00:00:00 2001 From: "addie.sh" Date: Tue, 21 Jul 2026 11:49:20 -0400 Subject: [PATCH 41/41] Next steps for FnDef binder changes (instantiate most FnDef binders) --- compiler/rustc_middle/src/ty/sty.rs | 16 +++++++++++ .../binder-arg-overflow-regression-133613.rs | 3 +-- ...nder-arg-overflow-regression-133613.stderr | 27 +++---------------- 3 files changed, 20 insertions(+), 26 deletions(-) diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 06b2c621eda00..f8fb476ca3ef1 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -726,6 +726,22 @@ impl<'tcx> Ty<'tcx> { } /// Prefer using the [TyCtxt::type_of] query over this, that makes it easier to get all the pieces correct + #[inline] + pub fn new_fn_def_raw( + tcx: TyCtxt<'tcx>, + def_id: DefId, + args: ty::Binder<'tcx, impl IntoIterator>>>, + ) -> Ty<'tcx> { + debug_assert_matches!( + tcx.def_kind(def_id), + DefKind::AssocFn | DefKind::Fn | DefKind::Ctor(_, CtorKind::Fn) + ); + + let args = args.map_bound(|args| tcx.check_and_mk_args(def_id, args)); + + Ty::new(tcx, FnDef(def_id, args)) + } + #[inline] pub fn new_fn_def( tcx: TyCtxt<'tcx>, diff --git a/tests/ui/generics/binder-arg-overflow-regression-133613.rs b/tests/ui/generics/binder-arg-overflow-regression-133613.rs index ad4e6c70eb8fe..5d911ca5d3aa9 100644 --- a/tests/ui/generics/binder-arg-overflow-regression-133613.rs +++ b/tests/ui/generics/binder-arg-overflow-regression-133613.rs @@ -2,6 +2,7 @@ //! This was a crash regarding bound vars and generic arg indexing. //! The bound var index was used to index self.args, and caused OOB. //! Because of new changes to how the compiler handles binders, this was fixed. +#![feature(return_type_notation)] //@ needs-rustc-debug-assertions @@ -11,8 +12,6 @@ struct Wrapper<'a>(); trait IntFactory { fn stream(&self) -> impl IntFactory>; //~^ ERROR: cycle detected when looking up late bound vars inside `IntFactory::stream` [E0391] - //~^^ ERROR: return type notation is experimental - //~^^^ ERROR: return type notation is experimental } fn main() {} diff --git a/tests/ui/generics/binder-arg-overflow-regression-133613.stderr b/tests/ui/generics/binder-arg-overflow-regression-133613.stderr index e56467ea507e9..c8f5ffb5978c6 100644 --- a/tests/ui/generics/binder-arg-overflow-regression-133613.stderr +++ b/tests/ui/generics/binder-arg-overflow-regression-133613.stderr @@ -1,25 +1,5 @@ -error[E0658]: return type notation is experimental - --> $DIR/binder-arg-overflow-regression-133613.rs:12:47 - | -LL | fn stream(&self) -> impl IntFactory>; - | ^^^^ - | - = note: see issue #109417 for more information - = help: add `#![feature(return_type_notation)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error[E0658]: return type notation is experimental - --> $DIR/binder-arg-overflow-regression-133613.rs:12:70 - | -LL | fn stream(&self) -> impl IntFactory>; - | ^^^^ - | - = note: see issue #109417 for more information - = help: add `#![feature(return_type_notation)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - error[E0391]: cycle detected when looking up late bound vars inside `IntFactory::stream` - --> $DIR/binder-arg-overflow-regression-133613.rs:12:5 + --> $DIR/binder-arg-overflow-regression-133613.rs:13:5 | LL | fn stream(&self) -> impl IntFactory>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -30,7 +10,6 @@ LL | fn stream(&self) -> impl IntFactory and -error: aborting due to 3 previous errors +error: aborting due to 1 previous error -Some errors have detailed explanations: E0391, E0658. -For more information about an error, try `rustc --explain E0391`. +For more information about this error, try `rustc --explain E0391`.