Encode whether foreign opaques are TAITs or not
This commit is contained in:
parent
79335f1ac4
commit
200f466d1a
8 changed files with 23 additions and 2 deletions
|
@ -2602,7 +2602,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
match path.res {
|
||||
Res::Def(DefKind::OpaqueTy | DefKind::ImplTraitPlaceholder, did) => {
|
||||
// Check for desugared `impl Trait`.
|
||||
assert!(ty::is_impl_trait_defn(tcx, did).is_none());
|
||||
assert!(tcx.is_type_alias_impl_trait(did));
|
||||
let item_segment = path.segments.split_last().unwrap();
|
||||
self.prohibit_generics(item_segment.1.iter(), |err| {
|
||||
err.note("`impl Trait` types can't have type parameters");
|
||||
|
|
|
@ -76,6 +76,7 @@ pub fn provide(providers: &mut Providers) {
|
|||
is_foreign_item,
|
||||
generator_kind,
|
||||
collect_mod_item_types,
|
||||
is_type_alias_impl_trait,
|
||||
..*providers
|
||||
};
|
||||
}
|
||||
|
@ -1537,3 +1538,13 @@ fn generator_kind(tcx: TyCtxt<'_>, def_id: DefId) -> Option<hir::GeneratorKind>
|
|||
_ => bug!("generator_kind applied to non-local def-id {:?}", def_id),
|
||||
}
|
||||
}
|
||||
|
||||
fn is_type_alias_impl_trait<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool {
|
||||
match tcx.hir().get_if_local(def_id) {
|
||||
Some(Node::Item(hir::Item { kind: hir::ItemKind::OpaqueTy(opaque), .. })) => {
|
||||
matches!(opaque.origin, hir::OpaqueTyOrigin::TyAlias)
|
||||
}
|
||||
Some(_) => bug!("tried getting opaque_ty_origin for non-opaque: {:?}", def_id),
|
||||
_ => bug!("tried getting opaque_ty_origin for non-local def-id {:?}", def_id),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -223,6 +223,7 @@ provide! { tcx, def_id, other, cdata,
|
|||
generator_kind => { table }
|
||||
trait_def => { table }
|
||||
deduced_param_attrs => { table }
|
||||
is_type_alias_impl_trait => { table }
|
||||
collect_return_position_impl_trait_in_trait_tys => {
|
||||
Ok(cdata
|
||||
.root
|
||||
|
|
|
@ -1514,6 +1514,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
|||
}
|
||||
hir::ItemKind::OpaqueTy(..) => {
|
||||
self.encode_explicit_item_bounds(def_id);
|
||||
record!(self.tables.is_type_alias_impl_trait[def_id] <- self.tcx.is_type_alias_impl_trait(def_id));
|
||||
}
|
||||
hir::ItemKind::Enum(..) => {
|
||||
let adt_def = self.tcx.adt_def(def_id);
|
||||
|
|
|
@ -404,6 +404,7 @@ define_tables! {
|
|||
proc_macro: Table<DefIndex, MacroKind>,
|
||||
module_reexports: Table<DefIndex, LazyArray<ModChild>>,
|
||||
deduced_param_attrs: Table<DefIndex, LazyArray<DeducedParamAttrs>>,
|
||||
is_type_alias_impl_trait: Table<DefIndex, LazyValue<bool>>,
|
||||
|
||||
trait_impl_trait_tys: Table<DefIndex, LazyValue<FxHashMap<DefId, Ty<'static>>>>,
|
||||
}
|
||||
|
|
|
@ -177,6 +177,12 @@ rustc_queries! {
|
|||
separate_provide_extern
|
||||
}
|
||||
|
||||
query is_type_alias_impl_trait(key: DefId) -> bool
|
||||
{
|
||||
desc { "determine whether the opaque is a type-alias impl trait" }
|
||||
separate_provide_extern
|
||||
}
|
||||
|
||||
query analysis(key: ()) -> Result<(), ErrorGuaranteed> {
|
||||
eval_always
|
||||
desc { "running analysis passes on this crate" }
|
||||
|
|
|
@ -52,6 +52,7 @@ trivially_parameterized_over_tcx! {
|
|||
usize,
|
||||
(),
|
||||
u32,
|
||||
bool,
|
||||
std::string::String,
|
||||
crate::metadata::ModChild,
|
||||
crate::middle::codegen_fn_attrs::CodegenFnAttrs,
|
||||
|
|
|
@ -654,7 +654,7 @@ impl<'tcx> WfPredicates<'tcx> {
|
|||
// All of the requirements on type parameters
|
||||
// have already been checked for `impl Trait` in
|
||||
// return position. We do need to check type-alias-impl-trait though.
|
||||
if ty::is_impl_trait_defn(self.tcx, def_id).is_none() {
|
||||
if self.tcx.is_type_alias_impl_trait(def_id) {
|
||||
let obligations = self.nominal_obligations(def_id, substs);
|
||||
self.out.extend(obligations);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue