Skip to content

Commit 200f466

Browse files
Encode whether foreign opaques are TAITs or not
1 parent 79335f1 commit 200f466

File tree

8 files changed

+23
-2
lines changed

8 files changed

+23
-2
lines changed

compiler/rustc_hir_analysis/src/astconv/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2602,7 +2602,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
26022602
match path.res {
26032603
Res::Def(DefKind::OpaqueTy | DefKind::ImplTraitPlaceholder, did) => {
26042604
// Check for desugared `impl Trait`.
2605-
assert!(ty::is_impl_trait_defn(tcx, did).is_none());
2605+
assert!(tcx.is_type_alias_impl_trait(did));
26062606
let item_segment = path.segments.split_last().unwrap();
26072607
self.prohibit_generics(item_segment.1.iter(), |err| {
26082608
err.note("`impl Trait` types can't have type parameters");

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ pub fn provide(providers: &mut Providers) {
7676
is_foreign_item,
7777
generator_kind,
7878
collect_mod_item_types,
79+
is_type_alias_impl_trait,
7980
..*providers
8081
};
8182
}
@@ -1537,3 +1538,13 @@ fn generator_kind(tcx: TyCtxt<'_>, def_id: DefId) -> Option<hir::GeneratorKind>
15371538
_ => bug!("generator_kind applied to non-local def-id {:?}", def_id),
15381539
}
15391540
}
1541+
1542+
fn is_type_alias_impl_trait<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool {
1543+
match tcx.hir().get_if_local(def_id) {
1544+
Some(Node::Item(hir::Item { kind: hir::ItemKind::OpaqueTy(opaque), .. })) => {
1545+
matches!(opaque.origin, hir::OpaqueTyOrigin::TyAlias)
1546+
}
1547+
Some(_) => bug!("tried getting opaque_ty_origin for non-opaque: {:?}", def_id),
1548+
_ => bug!("tried getting opaque_ty_origin for non-local def-id {:?}", def_id),
1549+
}
1550+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ provide! { tcx, def_id, other, cdata,
223223
generator_kind => { table }
224224
trait_def => { table }
225225
deduced_param_attrs => { table }
226+
is_type_alias_impl_trait => { table }
226227
collect_return_position_impl_trait_in_trait_tys => {
227228
Ok(cdata
228229
.root

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,6 +1514,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
15141514
}
15151515
hir::ItemKind::OpaqueTy(..) => {
15161516
self.encode_explicit_item_bounds(def_id);
1517+
record!(self.tables.is_type_alias_impl_trait[def_id] <- self.tcx.is_type_alias_impl_trait(def_id));
15171518
}
15181519
hir::ItemKind::Enum(..) => {
15191520
let adt_def = self.tcx.adt_def(def_id);

compiler/rustc_metadata/src/rmeta/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ define_tables! {
404404
proc_macro: Table<DefIndex, MacroKind>,
405405
module_reexports: Table<DefIndex, LazyArray<ModChild>>,
406406
deduced_param_attrs: Table<DefIndex, LazyArray<DeducedParamAttrs>>,
407+
is_type_alias_impl_trait: Table<DefIndex, LazyValue<bool>>,
407408

408409
trait_impl_trait_tys: Table<DefIndex, LazyValue<FxHashMap<DefId, Ty<'static>>>>,
409410
}

compiler/rustc_middle/src/query/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,12 @@ rustc_queries! {
177177
separate_provide_extern
178178
}
179179

180+
query is_type_alias_impl_trait(key: DefId) -> bool
181+
{
182+
desc { "determine whether the opaque is a type-alias impl trait" }
183+
separate_provide_extern
184+
}
185+
180186
query analysis(key: ()) -> Result<(), ErrorGuaranteed> {
181187
eval_always
182188
desc { "running analysis passes on this crate" }

compiler/rustc_middle/src/ty/parameterized.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ trivially_parameterized_over_tcx! {
5252
usize,
5353
(),
5454
u32,
55+
bool,
5556
std::string::String,
5657
crate::metadata::ModChild,
5758
crate::middle::codegen_fn_attrs::CodegenFnAttrs,

compiler/rustc_trait_selection/src/traits/wf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ impl<'tcx> WfPredicates<'tcx> {
654654
// All of the requirements on type parameters
655655
// have already been checked for `impl Trait` in
656656
// return position. We do need to check type-alias-impl-trait though.
657-
if ty::is_impl_trait_defn(self.tcx, def_id).is_none() {
657+
if self.tcx.is_type_alias_impl_trait(def_id) {
658658
let obligations = self.nominal_obligations(def_id, substs);
659659
self.out.extend(obligations);
660660
}

0 commit comments

Comments
 (0)