From c855bf62d7adf3f016637d57423d7f84ef15c334 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 22 Mar 2024 13:13:04 -0400 Subject: [PATCH 1/2] Add a test --- .../auxiliary/implied-predicates.rs | 7 +++++++ .../implied-predicates.rs | 8 ++++++++ .../implied-predicates.stderr | 19 +++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 tests/ui/associated-type-bounds/auxiliary/implied-predicates.rs create mode 100644 tests/ui/associated-type-bounds/implied-predicates.rs create mode 100644 tests/ui/associated-type-bounds/implied-predicates.stderr diff --git a/tests/ui/associated-type-bounds/auxiliary/implied-predicates.rs b/tests/ui/associated-type-bounds/auxiliary/implied-predicates.rs new file mode 100644 index 0000000000000..fe74c64fbe2aa --- /dev/null +++ b/tests/ui/associated-type-bounds/auxiliary/implied-predicates.rs @@ -0,0 +1,7 @@ +pub trait Bar: Super {} + +pub trait Super { + type SuperAssoc; +} + +pub trait Bound {} diff --git a/tests/ui/associated-type-bounds/implied-predicates.rs b/tests/ui/associated-type-bounds/implied-predicates.rs new file mode 100644 index 0000000000000..91b8a94c64f26 --- /dev/null +++ b/tests/ui/associated-type-bounds/implied-predicates.rs @@ -0,0 +1,8 @@ +//@ aux-build:implied-predicates.rs + +extern crate implied_predicates; +use implied_predicates::Bar; + +fn bar() {} + +fn main() {} diff --git a/tests/ui/associated-type-bounds/implied-predicates.stderr b/tests/ui/associated-type-bounds/implied-predicates.stderr new file mode 100644 index 0000000000000..6527f9f36411d --- /dev/null +++ b/tests/ui/associated-type-bounds/implied-predicates.stderr @@ -0,0 +1,19 @@ +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`. From 33614886812c6c4a3b68a3cdd5b3bb5a3626ce49 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 22 Mar 2024 13:13:40 -0400 Subject: [PATCH 2/2] 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 1aabd296641d2..b69a295f010f3 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 @@ provide! { tcx, def_id, other, cdata, 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 @@ provide! { tcx, def_id, other, cdata, .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 42724f7dd2ba7..61060038b5006 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -1435,6 +1435,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { 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 91b8a94c64f26..e97d7a396c470 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 6527f9f36411d..0000000000000 --- 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`.