about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-03-01 19:06:39 +0000
committerbors <bors@rust-lang.org>2024-03-01 19:06:39 +0000
commit2dceda4f32b97f60b122f2b32491e0267ef5cc0c (patch)
tree4989e8c8638ecb5f15eb0f2435bc8fa4dc1d634c /compiler/rustc_trait_selection
parent17edacef07e8afc3b580ed8feead6c5e90d24a56 (diff)
parentff22925e500e767ffcc5485d006174f7d74e21f0 (diff)
downloadrust-2dceda4f32b97f60b122f2b32491e0267ef5cc0c.tar.gz
rust-2dceda4f32b97f60b122f2b32491e0267ef5cc0c.zip
Auto merge of #121859 - matthiaskrgr:rollup-i724wpm, r=matthiaskrgr
Rollup of 12 pull requests

Successful merges:

 - #120646 (Fix incorrect suggestion for uninitialized binding in pattern)
 - #121416 (Improve error messages for generics with default parameters)
 - #121475 (Add tidy check for .stderr/.stdout files for non-existent test revisions)
 - #121580 (make unused_imports less assertive in test modules)
 - #121736 (Remove `Mutex::unlock` Function)
 - #121784 (Make the success arms of `if lhs || rhs` meet up in a separate block)
 - #121818 (CFI: Remove unused `typeid_for_fnsig`)
 - #121819 (Handle stashing of delayed bugs)
 - #121828 (Remove unused fluent messages)
 - #121831 (Fix typo in comment)
 - #121850 (Make `ZeroablePrimitive` trait unsafe.)
 - #121853 (normalizes-to: handle negative impls)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_trait_selection')
-rw-r--r--compiler/rustc_trait_selection/src/solve/normalizes_to/mod.rs19
1 files changed, 16 insertions, 3 deletions
diff --git a/compiler/rustc_trait_selection/src/solve/normalizes_to/mod.rs b/compiler/rustc_trait_selection/src/solve/normalizes_to/mod.rs
index 3aba5c85abc..248985715c2 100644
--- a/compiler/rustc_trait_selection/src/solve/normalizes_to/mod.rs
+++ b/compiler/rustc_trait_selection/src/solve/normalizes_to/mod.rs
@@ -162,15 +162,28 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
         let tcx = ecx.tcx();
 
         let goal_trait_ref = goal.predicate.alias.trait_ref(tcx);
-        let impl_trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
+        let impl_trait_header = tcx.impl_trait_header(impl_def_id).unwrap();
         let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::ForLookup };
-        if !drcx.args_may_unify(goal_trait_ref.args, impl_trait_ref.skip_binder().args) {
+        if !drcx.args_may_unify(
+            goal.predicate.trait_ref(tcx).args,
+            impl_trait_header.skip_binder().trait_ref.args,
+        ) {
             return Err(NoSolution);
         }
 
+        // We have to ignore negative impls when projecting.
+        let impl_polarity = impl_trait_header.skip_binder().polarity;
+        match impl_polarity {
+            ty::ImplPolarity::Negative => return Err(NoSolution),
+            ty::ImplPolarity::Reservation => {
+                unimplemented!("reservation impl for trait with assoc item: {:?}", goal)
+            }
+            ty::ImplPolarity::Positive => {}
+        };
+
         ecx.probe_trait_candidate(CandidateSource::Impl(impl_def_id)).enter(|ecx| {
             let impl_args = ecx.fresh_args_for_item(impl_def_id);
-            let impl_trait_ref = impl_trait_ref.instantiate(tcx, impl_args);
+            let impl_trait_ref = impl_trait_header.instantiate(tcx, impl_args).trait_ref;
 
             ecx.eq(goal.param_env, goal_trait_ref, impl_trait_ref)?;