Skip to content

Commit 62ed577

Browse files
compiler-errorsMark-Simulacrum
authored andcommitted
Encode whether foreign opaques are TAITs or not
1 parent b7a6d74 commit 62ed577

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
@@ -2418,7 +2418,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
24182418
match path.res {
24192419
Res::Def(DefKind::OpaqueTy | DefKind::ImplTraitPlaceholder, did) => {
24202420
// Check for desugared `impl Trait`.
2421-
assert!(ty::is_impl_trait_defn(tcx, did).is_none());
2421+
assert!(tcx.is_type_alias_impl_trait(did));
24222422
let item_segment = path.segments.split_last().unwrap();
24232423
self.prohibit_generics(item_segment.1.iter(), |err| {
24242424
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
@@ -82,6 +82,7 @@ pub fn provide(providers: &mut Providers) {
8282
asm_target_features,
8383
collect_mod_item_types,
8484
should_inherit_track_caller,
85+
is_type_alias_impl_trait,
8586
..*providers
8687
};
8788
}
@@ -2250,3 +2251,13 @@ fn check_target_feature_trait_unsafe(tcx: TyCtxt<'_>, id: LocalDefId, attr_span:
22502251
}
22512252
}
22522253
}
2254+
2255+
fn is_type_alias_impl_trait<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool {
2256+
match tcx.hir().get_if_local(def_id) {
2257+
Some(Node::Item(hir::Item { kind: hir::ItemKind::OpaqueTy(opaque), .. })) => {
2258+
matches!(opaque.origin, hir::OpaqueTyOrigin::TyAlias)
2259+
}
2260+
Some(_) => bug!("tried getting opaque_ty_origin for non-opaque: {:?}", def_id),
2261+
_ => bug!("tried getting opaque_ty_origin for non-local def-id {:?}", def_id),
2262+
}
2263+
}

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_trait_impl_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
@@ -1537,6 +1537,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
15371537
}
15381538
hir::ItemKind::OpaqueTy(..) => {
15391539
self.encode_explicit_item_bounds(def_id);
1540+
record!(self.tables.is_type_alias_impl_trait[def_id] <- self.tcx.is_type_alias_impl_trait(def_id));
15401541
}
15411542
hir::ItemKind::Enum(..) => {
15421543
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
@@ -175,6 +175,12 @@ rustc_queries! {
175175
separate_provide_extern
176176
}
177177

178+
query is_type_alias_impl_trait(key: DefId) -> bool
179+
{
180+
desc { "determine whether the opaque is a type-alias impl trait" }
181+
separate_provide_extern
182+
}
183+
178184
query analysis(key: ()) -> Result<(), ErrorGuaranteed> {
179185
eval_always
180186
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
@@ -53,6 +53,7 @@ trivially_parameterized_over_tcx! {
5353
usize,
5454
(),
5555
u32,
56+
bool,
5657
std::string::String,
5758
crate::metadata::ModChild,
5859
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
@@ -652,7 +652,7 @@ impl<'tcx> WfPredicates<'tcx> {
652652
// All of the requirements on type parameters
653653
// have already been checked for `impl Trait` in
654654
// return position. We do need to check type-alias-impl-trait though.
655-
if ty::is_impl_trait_defn(self.tcx, did).is_none() {
655+
if self.tcx.is_type_alias_impl_trait(did) {
656656
let obligations = self.nominal_obligations(did, substs);
657657
self.out.extend(obligations);
658658
}

0 commit comments

Comments
 (0)