Skip to content

Commit 4871303

Browse files
borsRenjiSann
authored andcommitted
Auto merge of rust-lang#122891 - compiler-errors:encode-implied-predicates-always, r=oli-obk
Encode implied predicates for traits In rust-lang#112629, we decided to make associated type bounds in the "supertrait" AST position *implied* even though they're not supertraits themselves. This means that the `super_predicates` and `implied_predicates` queries now differ for regular traits. The assumption that they didn't differ was hard-coded in rust-lang#107614, so in cross-crate positions this means that we forget the implied predicates from associated type bounds. This isn't unsound, just kind of annoying. This should be backported since associated type bounds are slated to stabilize for 1.78 -- either that, or associated type bounds can be reverted on beta and re-shipped in 1.79 with this patch. Fixes rust-lang#122859
2 parents 8db63b3 + 3361488 commit 4871303

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

+1-12
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ provide! { tcx, def_id, other, cdata,
211211
generics_of => { table }
212212
inferred_outlives_of => { table_defaulted_array }
213213
super_predicates_of => { table }
214+
implied_predicates_of => { table }
214215
type_of => { table }
215216
type_alias_is_lazy => { cdata.root.tables.type_alias_is_lazy.get(cdata, def_id.index) }
216217
variances_of => { table }
@@ -276,18 +277,6 @@ provide! { tcx, def_id, other, cdata,
276277
.map(|lazy| lazy.decode((cdata, tcx)))
277278
.process_decoded(tcx, || panic!("{def_id:?} does not have trait_impl_trait_tys")))
278279
}
279-
implied_predicates_of => {
280-
cdata
281-
.root
282-
.tables
283-
.implied_predicates_of
284-
.get(cdata, def_id.index)
285-
.map(|lazy| lazy.decode((cdata, tcx)))
286-
.unwrap_or_else(|| {
287-
debug_assert_eq!(tcx.def_kind(def_id), DefKind::Trait);
288-
tcx.super_predicates_of(def_id)
289-
})
290-
}
291280

292281
associated_types_for_impl_traits_in_associated_fn => { table_defaulted_array }
293282

compiler/rustc_metadata/src/rmeta/encoder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1435,6 +1435,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14351435
if let DefKind::Trait = def_kind {
14361436
record!(self.tables.trait_def[def_id] <- self.tcx.trait_def(def_id));
14371437
record!(self.tables.super_predicates_of[def_id] <- self.tcx.super_predicates_of(def_id));
1438+
record!(self.tables.implied_predicates_of[def_id] <- self.tcx.implied_predicates_of(def_id));
14381439

14391440
let module_children = self.tcx.module_children_local(local_id);
14401441
record_array!(self.tables.module_children_non_reexports[def_id] <-
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pub trait Bar: Super<SuperAssoc: Bound> {}
2+
3+
pub trait Super {
4+
type SuperAssoc;
5+
}
6+
7+
pub trait Bound {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//@ aux-build:implied-predicates.rs
2+
//@ check-pass
3+
4+
extern crate implied_predicates;
5+
use implied_predicates::Bar;
6+
7+
fn bar<B: Bar>() {}
8+
9+
fn main() {}

0 commit comments

Comments
 (0)