Rollup merge of #112165 - fee1-dead-contrib:rn-defualtness, r=compiler-errors

Rename `impl_defaultness` to `defaultness`

Since this isn't just about the `impl`.
This commit is contained in:
Matthias Krüger 2023-06-02 18:12:45 +02:00 committed by GitHub
commit f121f77d8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 33 additions and 32 deletions

View File

@ -704,7 +704,7 @@ pub(super) fn check_specialization_validity<'tcx>(
// grandparent. In that case, if parent is a `default impl`, inherited items use the // grandparent. In that case, if parent is a `default impl`, inherited items use the
// "defaultness" from the grandparent, else they are final. // "defaultness" from the grandparent, else they are final.
None => { None => {
if tcx.impl_defaultness(parent_impl.def_id()).is_default() { if tcx.defaultness(parent_impl.def_id()).is_default() {
None None
} else { } else {
Some(Err(parent_impl.def_id())) Some(Err(parent_impl.def_id()))
@ -803,7 +803,7 @@ fn check_impl_items_against_trait<'tcx>(
.as_ref() .as_ref()
.is_some_and(|node_item| node_item.item.defaultness(tcx).has_value()); .is_some_and(|node_item| node_item.item.defaultness(tcx).has_value());
if !is_implemented && tcx.impl_defaultness(impl_id).is_final() { if !is_implemented && tcx.defaultness(impl_id).is_final() {
missing_items.push(tcx.associated_item(trait_item_id)); missing_items.push(tcx.associated_item(trait_item_id));
} }

View File

@ -941,7 +941,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {
match item { match item {
Some(item) if matches!(item.kind, hir::AssocItemKind::Fn { .. }) => { Some(item) if matches!(item.kind, hir::AssocItemKind::Fn { .. }) => {
if !tcx.impl_defaultness(item.id.owner_id).has_value() { if !tcx.defaultness(item.id.owner_id).has_value() {
tcx.sess.emit_err(errors::FunctionNotHaveDefaultImplementation { tcx.sess.emit_err(errors::FunctionNotHaveDefaultImplementation {
span: item.span, span: item.span,
note_span: attr_span, note_span: attr_span,

View File

@ -435,7 +435,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
in_trait, in_trait,
.. ..
}) => { }) => {
if in_trait && !tcx.impl_defaultness(owner).has_value() { if in_trait && !tcx.defaultness(owner).has_value() {
span_bug!( span_bug!(
tcx.def_span(def_id), tcx.def_span(def_id),
"tried to get type of this RPITIT with no definition" "tried to get type of this RPITIT with no definition"

View File

@ -586,7 +586,7 @@ fn point_at_associated_type(
// FIXME: account for returning some type in a trait fn impl that has // FIXME: account for returning some type in a trait fn impl that has
// an assoc type as a return type (#72076). // an assoc type as a return type (#72076).
if let hir::Defaultness::Default { has_value: true } = if let hir::Defaultness::Default { has_value: true } =
tcx.impl_defaultness(item.id.owner_id) tcx.defaultness(item.id.owner_id)
{ {
let assoc_ty = tcx.type_of(item.id.owner_id).subst_identity(); let assoc_ty = tcx.type_of(item.id.owner_id).subst_identity();
if self.infcx.can_eq(param_env, assoc_ty, found) { if self.infcx.can_eq(param_env, assoc_ty, found) {

View File

@ -231,7 +231,7 @@ fn into_args(self) -> (DefId, SimplifiedType) {
opt_def_kind => { table_direct } opt_def_kind => { table_direct }
impl_parent => { table } impl_parent => { table }
impl_polarity => { table_direct } impl_polarity => { table_direct }
impl_defaultness => { table_direct } defaultness => { table_direct }
constness => { table_direct } constness => { table_direct }
coerce_unsized_info => { table } coerce_unsized_info => { table }
mir_const_qualif => { table } mir_const_qualif => { table }

View File

@ -1437,8 +1437,8 @@ fn encode_info_for_trait_item(&mut self, def_id: DefId) {
debug!("EncodeContext::encode_info_for_trait_item({:?})", def_id); debug!("EncodeContext::encode_info_for_trait_item({:?})", def_id);
let tcx = self.tcx; let tcx = self.tcx;
let impl_defaultness = tcx.impl_defaultness(def_id.expect_local()); let defaultness = tcx.defaultness(def_id.expect_local());
self.tables.impl_defaultness.set_some(def_id.index, impl_defaultness); self.tables.defaultness.set_some(def_id.index, defaultness);
let trait_item = tcx.associated_item(def_id); let trait_item = tcx.associated_item(def_id);
self.tables.assoc_container.set_some(def_id.index, trait_item.container); self.tables.assoc_container.set_some(def_id.index, trait_item.container);
@ -1466,8 +1466,8 @@ fn encode_info_for_impl_item(&mut self, def_id: DefId) {
debug!("EncodeContext::encode_info_for_impl_item({:?})", def_id); debug!("EncodeContext::encode_info_for_impl_item({:?})", def_id);
let tcx = self.tcx; let tcx = self.tcx;
let defaultness = self.tcx.impl_defaultness(def_id.expect_local()); let defaultness = self.tcx.defaultness(def_id.expect_local());
self.tables.impl_defaultness.set_some(def_id.index, defaultness); self.tables.defaultness.set_some(def_id.index, defaultness);
let impl_item = self.tcx.associated_item(def_id); let impl_item = self.tcx.associated_item(def_id);
self.tables.assoc_container.set_some(def_id.index, impl_item.container); self.tables.assoc_container.set_some(def_id.index, impl_item.container);
@ -1653,7 +1653,7 @@ fn encode_info_for_item(&mut self, item: &'tcx hir::Item<'tcx>) {
); );
} }
hir::ItemKind::Impl(hir::Impl { defaultness, constness, .. }) => { hir::ItemKind::Impl(hir::Impl { defaultness, constness, .. }) => {
self.tables.impl_defaultness.set_some(def_id.index, *defaultness); self.tables.defaultness.set_some(def_id.index, *defaultness);
self.tables.constness.set_some(def_id.index, *constness); self.tables.constness.set_some(def_id.index, *constness);
self.tables.impl_polarity.set_some(def_id.index, self.tcx.impl_polarity(def_id)); self.tables.impl_polarity.set_some(def_id.index, self.tcx.impl_polarity(def_id));

View File

@ -420,7 +420,7 @@ fn encode(&self, buf: &mut FileEncoder) -> LazyTables {
impl_parent: Table<DefIndex, RawDefId>, impl_parent: Table<DefIndex, RawDefId>,
impl_polarity: Table<DefIndex, ty::ImplPolarity>, impl_polarity: Table<DefIndex, ty::ImplPolarity>,
constness: Table<DefIndex, hir::Constness>, constness: Table<DefIndex, hir::Constness>,
impl_defaultness: Table<DefIndex, hir::Defaultness>, defaultness: Table<DefIndex, hir::Defaultness>,
// FIXME(eddyb) perhaps compute this on the fly if cheap enough? // FIXME(eddyb) perhaps compute this on the fly if cheap enough?
coerce_unsized_info: Table<DefIndex, LazyValue<ty::adjustment::CoerceUnsizedInfo>>, coerce_unsized_info: Table<DefIndex, LazyValue<ty::adjustment::CoerceUnsizedInfo>>,
mir_const_qualif: Table<DefIndex, LazyValue<mir::ConstQualifs>>, mir_const_qualif: Table<DefIndex, LazyValue<mir::ConstQualifs>>,

View File

@ -1475,8 +1475,9 @@
desc { "getting traits in scope at a block" } desc { "getting traits in scope at a block" }
} }
query impl_defaultness(def_id: DefId) -> hir::Defaultness { /// Returns whether the impl or associated function has the `default` keyword.
desc { |tcx| "looking up whether `{}` is a default impl", tcx.def_path_str(def_id) } query defaultness(def_id: DefId) -> hir::Defaultness {
desc { |tcx| "looking up whether `{}` has `default`", tcx.def_path_str(def_id) }
separate_provide_extern separate_provide_extern
feedable feedable
} }

View File

@ -228,7 +228,7 @@ pub fn leaf_def(mut self, tcx: TyCtxt<'tcx>, trait_item_def_id: DefId) -> Option
if let Some(item) = node.item(tcx, trait_item_def_id) { if let Some(item) = node.item(tcx, trait_item_def_id) {
if finalizing_node.is_none() { if finalizing_node.is_none() {
let is_specializable = item.defaultness(tcx).is_default() let is_specializable = item.defaultness(tcx).is_default()
|| tcx.impl_defaultness(node.def_id()).is_default(); || tcx.defaultness(node.def_id()).is_default();
if !is_specializable { if !is_specializable {
finalizing_node = Some(node); finalizing_node = Some(node);

View File

@ -48,7 +48,7 @@ pub fn ident(&self, tcx: TyCtxt<'_>) -> Ident {
/// ///
/// [`type_of`]: crate::ty::TyCtxt::type_of /// [`type_of`]: crate::ty::TyCtxt::type_of
pub fn defaultness(&self, tcx: TyCtxt<'_>) -> hir::Defaultness { pub fn defaultness(&self, tcx: TyCtxt<'_>) -> hir::Defaultness {
tcx.impl_defaultness(self.def_id) tcx.defaultness(self.def_id)
} }
#[inline] #[inline]

View File

@ -751,7 +751,7 @@ fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
reach.generics().predicates(); reach.generics().predicates();
if trait_item_ref.kind == AssocItemKind::Type if trait_item_ref.kind == AssocItemKind::Type
&& !tcx.impl_defaultness(trait_item_ref.id.owner_id).has_value() && !tcx.defaultness(trait_item_ref.id.owner_id).has_value()
{ {
// No type to visit. // No type to visit.
} else { } else {
@ -1927,7 +1927,7 @@ fn check_assoc_item(
let (check_ty, is_assoc_ty) = match assoc_item_kind { let (check_ty, is_assoc_ty) = match assoc_item_kind {
AssocItemKind::Const | AssocItemKind::Fn { .. } => (true, false), AssocItemKind::Const | AssocItemKind::Fn { .. } => (true, false),
AssocItemKind::Type => (self.tcx.impl_defaultness(def_id).has_value(), true), AssocItemKind::Type => (self.tcx.defaultness(def_id).has_value(), true),
}; };
check.in_assoc_ty = is_assoc_ty; check.in_assoc_ty = is_assoc_ty;
check.generics().predicates(); check.generics().predicates();

View File

@ -295,7 +295,7 @@ pub fn future_trait_ref_and_outputs<'tcx>(
pub fn impl_item_is_final(tcx: TyCtxt<'_>, assoc_item: &ty::AssocItem) -> bool { pub fn impl_item_is_final(tcx: TyCtxt<'_>, assoc_item: &ty::AssocItem) -> bool {
assoc_item.defaultness(tcx).is_final() assoc_item.defaultness(tcx).is_final()
&& tcx.impl_defaultness(assoc_item.container_id(tcx)).is_final() && tcx.defaultness(assoc_item.container_id(tcx)).is_final()
} }
pub enum TupleArgumentsFlag { pub enum TupleArgumentsFlag {

View File

@ -297,8 +297,8 @@ fn associated_type_for_impl_trait_in_trait(
// Copy visility of the containing function. // Copy visility of the containing function.
trait_assoc_ty.visibility(tcx.visibility(fn_def_id)); trait_assoc_ty.visibility(tcx.visibility(fn_def_id));
// Copy impl_defaultness of the containing function. // Copy defaultness of the containing function.
trait_assoc_ty.impl_defaultness(tcx.impl_defaultness(fn_def_id)); trait_assoc_ty.defaultness(tcx.defaultness(fn_def_id));
// Copy type_of of the opaque. // Copy type_of of the opaque.
trait_assoc_ty.type_of(ty::EarlyBinder::bind(tcx.mk_opaque( trait_assoc_ty.type_of(ty::EarlyBinder::bind(tcx.mk_opaque(
@ -393,8 +393,8 @@ fn associated_type_for_impl_trait_in_impl(
// Copy visility of the containing function. // Copy visility of the containing function.
impl_assoc_ty.visibility(tcx.visibility(impl_fn_def_id)); impl_assoc_ty.visibility(tcx.visibility(impl_fn_def_id));
// Copy impl_defaultness of the containing function. // Copy defaultness of the containing function.
impl_assoc_ty.impl_defaultness(tcx.impl_defaultness(impl_fn_def_id)); impl_assoc_ty.defaultness(tcx.defaultness(impl_fn_def_id));
// Copy generics_of the trait's associated item but the impl as the parent. // Copy generics_of the trait's associated item but the impl as the parent.
// FIXME(-Zlower-impl-trait-in-trait-to-assoc-ty) resolves to the trait instead of the impl // FIXME(-Zlower-impl-trait-in-trait-to-assoc-ty) resolves to the trait instead of the impl

View File

@ -204,7 +204,7 @@ fn resolve_associated_item<'tcx>(
} else { } else {
// All other methods are default methods of the `Future` trait. // All other methods are default methods of the `Future` trait.
// (this assumes that `ImplSource::Future` is only used for methods on `Future`) // (this assumes that `ImplSource::Future` is only used for methods on `Future`)
debug_assert!(tcx.impl_defaultness(trait_item_id).has_value()); debug_assert!(tcx.defaultness(trait_item_id).has_value());
Some(Instance::new(trait_item_id, rcvr_substs)) Some(Instance::new(trait_item_id, rcvr_substs))
} }
} }

View File

@ -75,13 +75,13 @@ fn sized_constraint_for_ty<'tcx>(
result result
} }
fn impl_defaultness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Defaultness { fn defaultness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Defaultness {
match tcx.hir().get_by_def_id(def_id) { match tcx.hir().get_by_def_id(def_id) {
hir::Node::Item(hir::Item { kind: hir::ItemKind::Impl(impl_), .. }) => impl_.defaultness, hir::Node::Item(hir::Item { kind: hir::ItemKind::Impl(impl_), .. }) => impl_.defaultness,
hir::Node::ImplItem(hir::ImplItem { defaultness, .. }) hir::Node::ImplItem(hir::ImplItem { defaultness, .. })
| hir::Node::TraitItem(hir::TraitItem { defaultness, .. }) => *defaultness, | hir::Node::TraitItem(hir::TraitItem { defaultness, .. }) => *defaultness,
node => { node => {
bug!("`impl_defaultness` called on {:?}", node); bug!("`defaultness` called on {:?}", node);
} }
} }
} }
@ -574,7 +574,7 @@ pub fn provide(providers: &mut Providers) {
param_env_reveal_all_normalized, param_env_reveal_all_normalized,
instance_def_size_estimate, instance_def_size_estimate,
issue33140_self_ty, issue33140_self_ty,
impl_defaultness, defaultness,
unsizing_params_for_adt, unsizing_params_for_adt,
..*providers ..*providers
}; };

View File

@ -1224,7 +1224,7 @@ pub(crate) fn clean_impl_item<'tcx>(
} }
hir::ImplItemKind::Fn(ref sig, body) => { hir::ImplItemKind::Fn(ref sig, body) => {
let m = clean_function(cx, sig, impl_.generics, FunctionArgs::Body(body)); let m = clean_function(cx, sig, impl_.generics, FunctionArgs::Body(body));
let defaultness = cx.tcx.impl_defaultness(impl_.owner_id); let defaultness = cx.tcx.defaultness(impl_.owner_id);
MethodItem(m, Some(defaultness)) MethodItem(m, Some(defaultness))
} }
hir::ImplItemKind::Type(hir_ty) => { hir::ImplItemKind::Type(hir_ty) => {
@ -1258,7 +1258,7 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
let provided = match assoc_item.container { let provided = match assoc_item.container {
ty::ImplContainer => true, ty::ImplContainer => true,
ty::TraitContainer => tcx.impl_defaultness(assoc_item.def_id).has_value(), ty::TraitContainer => tcx.defaultness(assoc_item.def_id).has_value(),
}; };
if provided { if provided {
AssocConstItem(ty, ConstantKind::Extern { def_id: assoc_item.def_id }) AssocConstItem(ty, ConstantKind::Extern { def_id: assoc_item.def_id })
@ -1440,7 +1440,7 @@ fn param_eq_arg(param: &GenericParamDef, arg: &GenericArg) -> bool {
} }
generics.where_predicates = where_predicates; generics.where_predicates = where_predicates;
if tcx.impl_defaultness(assoc_item.def_id).has_value() { if tcx.defaultness(assoc_item.def_id).has_value() {
AssocTypeItem( AssocTypeItem(
Box::new(Typedef { Box::new(Typedef {
type_: clean_middle_ty( type_: clean_middle_ty(

View File

@ -205,7 +205,7 @@ pub(crate) fn render(&self, s: &mut String, tcx: TyCtxt<'_>) {
&UrlFragment::Item(def_id) => { &UrlFragment::Item(def_id) => {
let kind = match tcx.def_kind(def_id) { let kind = match tcx.def_kind(def_id) {
DefKind::AssocFn => { DefKind::AssocFn => {
if tcx.impl_defaultness(def_id).has_value() { if tcx.defaultness(def_id).has_value() {
"method." "method."
} else { } else {
"tymethod." "tymethod."

View File

@ -105,7 +105,7 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx hir::Item<'_>) {
match tit_.kind { match tit_.kind {
hir::TraitItemKind::Const(..) | hir::TraitItemKind::Type(..) => {}, hir::TraitItemKind::Const(..) | hir::TraitItemKind::Type(..) => {},
hir::TraitItemKind::Fn(..) => { hir::TraitItemKind::Fn(..) => {
if cx.tcx.impl_defaultness(tit.id.owner_id).has_value() { if cx.tcx.defaultness(tit.id.owner_id).has_value() {
// trait method with default body needs inline in case // trait method with default body needs inline in case
// an impl is not provided // an impl is not provided
let desc = "a default trait method"; let desc = "a default trait method";