Use an enum instead of a bool
This commit is contained in:
parent
4e0769956b
commit
1829aa631f
1 changed files with 17 additions and 10 deletions
|
@ -47,7 +47,7 @@ pub(super) fn find_opaque_ty_constraints_for_impl_trait_in_assoc_type(
|
|||
let assoc = tcx.associated_item(assoc_id);
|
||||
match assoc.kind {
|
||||
ty::AssocKind::Const | ty::AssocKind::Fn => {
|
||||
locator.check(assoc_id.expect_local(), true)
|
||||
locator.check(assoc_id.expect_local(), ImplTraitSource::AssocTy)
|
||||
}
|
||||
// Associated types don't have bodies, so they can't constrain hidden types
|
||||
ty::AssocKind::Type => {}
|
||||
|
@ -182,9 +182,15 @@ struct TaitConstraintLocator<'tcx> {
|
|||
typeck_types: Vec<ty::OpaqueHiddenType<'tcx>>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum ImplTraitSource {
|
||||
AssocTy,
|
||||
TyAlias,
|
||||
}
|
||||
|
||||
impl TaitConstraintLocator<'_> {
|
||||
#[instrument(skip(self), level = "debug")]
|
||||
fn check(&mut self, item_def_id: LocalDefId, impl_trait_in_assoc_type: bool) {
|
||||
fn check(&mut self, item_def_id: LocalDefId, source: ImplTraitSource) {
|
||||
// Don't try to check items that cannot possibly constrain the type.
|
||||
if !self.tcx.has_typeck_results(item_def_id) {
|
||||
debug!("no constraint: no typeck results");
|
||||
|
@ -236,10 +242,11 @@ impl TaitConstraintLocator<'_> {
|
|||
continue;
|
||||
}
|
||||
constrained = true;
|
||||
let opaque_types_defined_by = if impl_trait_in_assoc_type {
|
||||
self.tcx.impl_trait_in_assoc_types_defined_by(item_def_id)
|
||||
} else {
|
||||
self.tcx.opaque_types_defined_by(item_def_id)
|
||||
let opaque_types_defined_by = match source {
|
||||
ImplTraitSource::AssocTy => {
|
||||
self.tcx.impl_trait_in_assoc_types_defined_by(item_def_id)
|
||||
}
|
||||
ImplTraitSource::TyAlias => self.tcx.opaque_types_defined_by(item_def_id),
|
||||
};
|
||||
if !opaque_types_defined_by.contains(&self.def_id) {
|
||||
self.tcx.dcx().emit_err(TaitForwardCompat {
|
||||
|
@ -299,7 +306,7 @@ impl<'tcx> intravisit::Visitor<'tcx> for TaitConstraintLocator<'tcx> {
|
|||
}
|
||||
fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) {
|
||||
if let hir::ExprKind::Closure(closure) = ex.kind {
|
||||
self.check(closure.def_id, false);
|
||||
self.check(closure.def_id, ImplTraitSource::TyAlias);
|
||||
}
|
||||
intravisit::walk_expr(self, ex);
|
||||
}
|
||||
|
@ -307,7 +314,7 @@ impl<'tcx> intravisit::Visitor<'tcx> for TaitConstraintLocator<'tcx> {
|
|||
trace!(?it.owner_id);
|
||||
// The opaque type itself or its children are not within its reveal scope.
|
||||
if it.owner_id.def_id != self.def_id {
|
||||
self.check(it.owner_id.def_id, false);
|
||||
self.check(it.owner_id.def_id, ImplTraitSource::TyAlias);
|
||||
intravisit::walk_item(self, it);
|
||||
}
|
||||
}
|
||||
|
@ -315,13 +322,13 @@ impl<'tcx> intravisit::Visitor<'tcx> for TaitConstraintLocator<'tcx> {
|
|||
trace!(?it.owner_id);
|
||||
// The opaque type itself or its children are not within its reveal scope.
|
||||
if it.owner_id.def_id != self.def_id {
|
||||
self.check(it.owner_id.def_id, false);
|
||||
self.check(it.owner_id.def_id, ImplTraitSource::TyAlias);
|
||||
intravisit::walk_impl_item(self, it);
|
||||
}
|
||||
}
|
||||
fn visit_trait_item(&mut self, it: &'tcx TraitItem<'tcx>) {
|
||||
trace!(?it.owner_id);
|
||||
self.check(it.owner_id.def_id, false);
|
||||
self.check(it.owner_id.def_id, ImplTraitSource::TyAlias);
|
||||
intravisit::walk_trait_item(self, it);
|
||||
}
|
||||
fn visit_foreign_item(&mut self, it: &'tcx hir::ForeignItem<'tcx>) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue