Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Rename impl_defaultness to defaultness #112165

Merged
merged 1 commit into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
// "defaultness" from the grandparent, else they are final.
None => {
if tcx.impl_defaultness(parent_impl.def_id()).is_default() {
if tcx.defaultness(parent_impl.def_id()).is_default() {
None
} else {
Some(Err(parent_impl.def_id()))
Expand Down Expand Up @@ -803,7 +803,7 @@ fn check_impl_items_against_trait<'tcx>(
.as_ref()
.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));
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ fn trait_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::TraitDef {

match item {
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 {
span: item.span,
note_span: attr_span,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/collect/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
in_trait,
..
}) => {
if in_trait && !tcx.impl_defaultness(owner).has_value() {
if in_trait && !tcx.defaultness(owner).has_value() {
span_bug!(
tcx.def_span(def_id),
"tried to get type of this RPITIT with no definition"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ fn foo(&self) -> Self::T { String::new() }
// FIXME: account for returning some type in a trait fn impl that has
// an assoc type as a return type (#72076).
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();
if self.infcx.can_eq(param_env, assoc_ty, found) {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ provide! { tcx, def_id, other, cdata,
opt_def_kind => { table_direct }
impl_parent => { table }
impl_polarity => { table_direct }
impl_defaultness => { table_direct }
defaultness => { table_direct }
constness => { table_direct }
coerce_unsized_info => { table }
mir_const_qualif => { table }
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1437,8 +1437,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
debug!("EncodeContext::encode_info_for_trait_item({:?})", def_id);
let tcx = self.tcx;

let impl_defaultness = tcx.impl_defaultness(def_id.expect_local());
self.tables.impl_defaultness.set_some(def_id.index, impl_defaultness);
let defaultness = tcx.defaultness(def_id.expect_local());
self.tables.defaultness.set_some(def_id.index, defaultness);
let trait_item = tcx.associated_item(def_id);
self.tables.assoc_container.set_some(def_id.index, trait_item.container);

Expand Down Expand Up @@ -1466,8 +1466,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
debug!("EncodeContext::encode_info_for_impl_item({:?})", def_id);
let tcx = self.tcx;

let defaultness = self.tcx.impl_defaultness(def_id.expect_local());
self.tables.impl_defaultness.set_some(def_id.index, defaultness);
let defaultness = self.tcx.defaultness(def_id.expect_local());
self.tables.defaultness.set_some(def_id.index, defaultness);
let impl_item = self.tcx.associated_item(def_id);
self.tables.assoc_container.set_some(def_id.index, impl_item.container);

Expand Down Expand Up @@ -1653,7 +1653,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
);
}
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.impl_polarity.set_some(def_id.index, self.tcx.impl_polarity(def_id));

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/rmeta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ define_tables! {
impl_parent: Table<DefIndex, RawDefId>,
impl_polarity: Table<DefIndex, ty::ImplPolarity>,
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?
coerce_unsized_info: Table<DefIndex, LazyValue<ty::adjustment::CoerceUnsizedInfo>>,
mir_const_qualif: Table<DefIndex, LazyValue<mir::ConstQualifs>>,
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1475,8 +1475,9 @@ rustc_queries! {
desc { "getting traits in scope at a block" }
}

query impl_defaultness(def_id: DefId) -> hir::Defaultness {
desc { |tcx| "looking up whether `{}` is a default impl", tcx.def_path_str(def_id) }
/// Returns whether the impl or associated function has the `default` keyword.
query defaultness(def_id: DefId) -> hir::Defaultness {
desc { |tcx| "looking up whether `{}` has `default`", tcx.def_path_str(def_id) }
separate_provide_extern
feedable
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/traits/specialization_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ impl<'tcx> Ancestors<'tcx> {
if let Some(item) = node.item(tcx, trait_item_def_id) {
if finalizing_node.is_none() {
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 {
finalizing_node = Some(node);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/assoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl AssocItem {
///
/// [`type_of`]: crate::ty::TyCtxt::type_of
pub fn defaultness(&self, tcx: TyCtxt<'_>) -> hir::Defaultness {
tcx.impl_defaultness(self.def_id)
tcx.defaultness(self.def_id)
}

#[inline]
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_privacy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
reach.generics().predicates();

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.
} else {
Expand Down Expand Up @@ -1927,7 +1927,7 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'tcx> {

let (check_ty, is_assoc_ty) = match assoc_item_kind {
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.generics().predicates();
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_trait_selection/src/traits/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
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 {
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_ty_utils/src/assoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ fn associated_type_for_impl_trait_in_trait(
// Copy visility of the containing function.
trait_assoc_ty.visibility(tcx.visibility(fn_def_id));

// Copy impl_defaultness of the containing function.
trait_assoc_ty.impl_defaultness(tcx.impl_defaultness(fn_def_id));
// Copy defaultness of the containing function.
trait_assoc_ty.defaultness(tcx.defaultness(fn_def_id));

// Copy type_of of the opaque.
trait_assoc_ty.type_of(ty::EarlyBinder::bind(tcx.mk_opaque(
Expand Down Expand Up @@ -393,8 +393,8 @@ fn associated_type_for_impl_trait_in_impl(
// Copy visility of the containing function.
impl_assoc_ty.visibility(tcx.visibility(impl_fn_def_id));

// Copy impl_defaultness of the containing function.
impl_assoc_ty.impl_defaultness(tcx.impl_defaultness(impl_fn_def_id));
// Copy defaultness of the containing function.
impl_assoc_ty.defaultness(tcx.defaultness(impl_fn_def_id));

// 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
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ty_utils/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ fn resolve_associated_item<'tcx>(
} else {
// All other methods are default methods of the `Future` trait.
// (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))
}
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_ty_utils/src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ fn sized_constraint_for_ty<'tcx>(
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) {
hir::Node::Item(hir::Item { kind: hir::ItemKind::Impl(impl_), .. }) => impl_.defaultness,
hir::Node::ImplItem(hir::ImplItem { defaultness, .. })
| hir::Node::TraitItem(hir::TraitItem { defaultness, .. }) => *defaultness,
node => {
bug!("`impl_defaultness` called on {:?}", node);
bug!("`defaultness` called on {:?}", node);
}
}
}
Expand Down Expand Up @@ -574,7 +574,7 @@ pub fn provide(providers: &mut Providers) {
param_env_reveal_all_normalized,
instance_def_size_estimate,
issue33140_self_ty,
impl_defaultness,
defaultness,
unsizing_params_for_adt,
..*providers
};
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,7 @@ pub(crate) fn clean_impl_item<'tcx>(
}
hir::ImplItemKind::Fn(ref sig, 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))
}
hir::ImplItemKind::Type(hir_ty) => {
Expand Down Expand Up @@ -1258,7 +1258,7 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(

let provided = match assoc_item.container {
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 {
AssocConstItem(ty, ConstantKind::Extern { def_id: assoc_item.def_id })
Expand Down Expand Up @@ -1440,7 +1440,7 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
}
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(
Box::new(Typedef {
type_: clean_middle_ty(
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/passes/collect_intra_doc_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl UrlFragment {
&UrlFragment::Item(def_id) => {
let kind = match tcx.def_kind(def_id) {
DefKind::AssocFn => {
if tcx.impl_defaultness(def_id).has_value() {
if tcx.defaultness(def_id).has_value() {
"method."
} else {
"tymethod."
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/missing_inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
match tit_.kind {
hir::TraitItemKind::Const(..) | hir::TraitItemKind::Type(..) => {},
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
// an impl is not provided
let desc = "a default trait method";
Expand Down