From 33614886812c6c4a3b68a3cdd5b3bb5a3626ce49 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 22 Mar 2024 13:13:40 -0400 Subject: [PATCH] Always encode implied_predicates query for traits With associated type bounds enabled, the implied_predicates and super_predicates queries may differ for traits, since associated type bounds are also implied but are not counted as super predicates. --- .../src/rmeta/decoder/cstore_impl.rs | 13 +------------ compiler/rustc_metadata/src/rmeta/encoder.rs | 1 + .../implied-predicates.rs | 1 + .../implied-predicates.stderr | 19 ------------------- 4 files changed, 3 insertions(+), 31 deletions(-) delete mode 100644 tests/ui/associated-type-bounds/implied-predicates.stderr diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index 1aabd296641..b69a295f010 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -211,6 +211,7 @@ fn into_args(self) -> (DefId, SimplifiedType) { generics_of => { table } inferred_outlives_of => { table_defaulted_array } super_predicates_of => { table } + implied_predicates_of => { table } type_of => { table } type_alias_is_lazy => { cdata.root.tables.type_alias_is_lazy.get(cdata, def_id.index) } variances_of => { table } @@ -276,18 +277,6 @@ fn into_args(self) -> (DefId, SimplifiedType) { .map(|lazy| lazy.decode((cdata, tcx))) .process_decoded(tcx, || panic!("{def_id:?} does not have trait_impl_trait_tys"))) } - implied_predicates_of => { - cdata - .root - .tables - .implied_predicates_of - .get(cdata, def_id.index) - .map(|lazy| lazy.decode((cdata, tcx))) - .unwrap_or_else(|| { - debug_assert_eq!(tcx.def_kind(def_id), DefKind::Trait); - tcx.super_predicates_of(def_id) - }) - } associated_types_for_impl_traits_in_associated_fn => { table_defaulted_array } diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 42724f7dd2b..61060038b50 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -1435,6 +1435,7 @@ fn encode_def_ids(&mut self) { if let DefKind::Trait = def_kind { record!(self.tables.trait_def[def_id] <- self.tcx.trait_def(def_id)); record!(self.tables.super_predicates_of[def_id] <- self.tcx.super_predicates_of(def_id)); + record!(self.tables.implied_predicates_of[def_id] <- self.tcx.implied_predicates_of(def_id)); let module_children = self.tcx.module_children_local(local_id); record_array!(self.tables.module_children_non_reexports[def_id] <- diff --git a/tests/ui/associated-type-bounds/implied-predicates.rs b/tests/ui/associated-type-bounds/implied-predicates.rs index 91b8a94c64f..e97d7a396c4 100644 --- a/tests/ui/associated-type-bounds/implied-predicates.rs +++ b/tests/ui/associated-type-bounds/implied-predicates.rs @@ -1,4 +1,5 @@ //@ aux-build:implied-predicates.rs +//@ check-pass extern crate implied_predicates; use implied_predicates::Bar; diff --git a/tests/ui/associated-type-bounds/implied-predicates.stderr b/tests/ui/associated-type-bounds/implied-predicates.stderr deleted file mode 100644 index 6527f9f3641..00000000000 --- a/tests/ui/associated-type-bounds/implied-predicates.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0277]: the trait bound `::SuperAssoc: implied_predicates::Bound` is not satisfied - --> $DIR/implied-predicates.rs:6:11 - | -LL | fn bar() {} - | ^^^ the trait `implied_predicates::Bound` is not implemented for `::SuperAssoc` - | -note: required by a bound in `Bar` - --> $DIR/auxiliary/implied-predicates.rs:1:34 - | -LL | pub trait Bar: Super {} - | ^^^^^ required by this bound in `Bar` -help: consider further restricting the associated type - | -LL | fn bar() where ::SuperAssoc: implied_predicates::Bound {} - | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0277`.