about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-07-26 15:28:02 +0200
committerGitHub <noreply@github.com>2025-07-26 15:28:02 +0200
commitd88aa06cd96aa52a602fec76c24e932cf27f97a3 (patch)
treeb97846e12460ec59a99b993a44d2d37bcd8ec26d
parente2a5862d229e4293e4597d6fe0648ea0f991c4da (diff)
parentcf4d7938cff6efd89c2605421a43600a7a5bb6c7 (diff)
downloadrust-d88aa06cd96aa52a602fec76c24e932cf27f97a3.tar.gz
rust-d88aa06cd96aa52a602fec76c24e932cf27f97a3.zip
Rollup merge of #144448 - camsteffen:defaultness-impl-trait-only, r=compiler-errors
Limit defaultness query to impl of trait

I separated this out from https://github.com/rust-lang/rust/pull/144386.
-rw-r--r--compiler/rustc_metadata/src/rmeta/encoder.rs4
-rw-r--r--compiler/rustc_ty_utils/src/ty.rs7
2 files changed, 7 insertions, 4 deletions
diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs
index 5cd98038fc6..24a3a6e0c4f 100644
--- a/compiler/rustc_metadata/src/rmeta/encoder.rs
+++ b/compiler/rustc_metadata/src/rmeta/encoder.rs
@@ -2124,11 +2124,11 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
             };
             let def_id = id.owner_id.to_def_id();
 
-            self.tables.defaultness.set_some(def_id.index, tcx.defaultness(def_id));
-
             if of_trait && let Some(header) = tcx.impl_trait_header(def_id) {
                 record!(self.tables.impl_trait_header[def_id] <- header);
 
+                self.tables.defaultness.set_some(def_id.index, tcx.defaultness(def_id));
+
                 let trait_ref = header.trait_ref.instantiate_identity();
                 let simplified_self_ty = fast_reject::simplify_type(
                     self.tcx,
diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs
index f8d793464a9..18f10da8505 100644
--- a/compiler/rustc_ty_utils/src/ty.rs
+++ b/compiler/rustc_ty_utils/src/ty.rs
@@ -80,8 +80,11 @@ fn sizedness_constraint_for_ty<'tcx>(
 
 fn defaultness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Defaultness {
     match tcx.hir_node_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::Item(hir::Item {
+            kind: hir::ItemKind::Impl(hir::Impl { defaultness, of_trait: Some(_), .. }),
+            ..
+        })
+        | hir::Node::ImplItem(hir::ImplItem { defaultness, .. })
         | hir::Node::TraitItem(hir::TraitItem { defaultness, .. }) => *defaultness,
         node => {
             bug!("`defaultness` called on {:?}", node);