about summary refs log tree commit diff
path: root/compiler/rustc_hir_analysis/src
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2024-11-30 16:44:58 +0000
committerMichael Goulet <michael@errs.io>2024-11-30 16:45:01 +0000
commit1e655ef21385eee0a3c224523eac316c7c20e8ed (patch)
tree37ba194b99370307781d1e3127e34b33e90745d0 /compiler/rustc_hir_analysis/src
parenta3623f20ae18996f31cc4a5a431d8afaa382247e (diff)
downloadrust-1e655ef21385eee0a3c224523eac316c7c20e8ed.tar.gz
rust-1e655ef21385eee0a3c224523eac316c7c20e8ed.zip
Move refinement check out of compare_impl_item
Diffstat (limited to 'compiler/rustc_hir_analysis/src')
-rw-r--r--compiler/rustc_hir_analysis/src/check/check.rs19
-rw-r--r--compiler/rustc_hir_analysis/src/check/compare_impl_item.rs8
-rw-r--r--compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs2
3 files changed, 20 insertions, 9 deletions
diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs
index 34ff9c1ec43..e1f4ccca97e 100644
--- a/compiler/rustc_hir_analysis/src/check/check.rs
+++ b/compiler/rustc_hir_analysis/src/check/check.rs
@@ -1045,7 +1045,24 @@ fn check_impl_items_against_trait<'tcx>(
             continue;
         };
 
-        let _ = tcx.ensure().compare_impl_item(impl_item.expect_local());
+        let res = tcx.ensure().compare_impl_item(impl_item.expect_local());
+
+        if res.is_ok() {
+            match ty_impl_item.kind {
+                ty::AssocKind::Fn => {
+                    compare_impl_item::refine::check_refining_return_position_impl_trait_in_trait(
+                        tcx,
+                        ty_impl_item,
+                        ty_trait_item,
+                        tcx.impl_trait_ref(ty_impl_item.container_id(tcx))
+                            .unwrap()
+                            .instantiate_identity(),
+                    );
+                }
+                ty::AssocKind::Const => {}
+                ty::AssocKind::Type => {}
+            }
+        }
 
         check_specialization_validity(
             tcx,
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 16f156a925e..e176fc58999 100644
--- a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs
+++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs
@@ -33,7 +33,7 @@ use tracing::{debug, instrument};
 use super::potentially_plural_count;
 use crate::errors::{LifetimesOrBoundsMismatchOnTrait, MethodShouldReturnFuture};
 
-mod refine;
+pub(super) mod refine;
 
 /// Call the query `tcx.compare_impl_item()` directly instead.
 pub(super) fn compare_impl_item(
@@ -70,12 +70,6 @@ fn compare_impl_method<'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)?;
-    refine::check_refining_return_position_impl_trait_in_trait(
-        tcx,
-        impl_m,
-        trait_m,
-        impl_trait_ref,
-    );
     Ok(())
 }
 
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 67cbcc1566a..6eac4ac3baf 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
@@ -17,7 +17,7 @@ use rustc_trait_selection::traits::outlives_bounds::InferCtxtExt;
 use rustc_trait_selection::traits::{ObligationCtxt, elaborate, normalize_param_env_or_error};
 
 /// Check that an implementation does not refine an RPITIT from a trait method signature.
-pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
+pub(crate) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
     tcx: TyCtxt<'tcx>,
     impl_m: ty::AssocItem,
     trait_m: ty::AssocItem,