Just pass the checker instead of individual fields
This commit is contained in:
parent
251c33ce2a
commit
7320623f3a
1 changed files with 33 additions and 39 deletions
|
@ -32,45 +32,42 @@ pub fn check_trait<'tcx>(
|
||||||
impl_header: ty::ImplTraitHeader<'tcx>,
|
impl_header: ty::ImplTraitHeader<'tcx>,
|
||||||
) -> Result<(), ErrorGuaranteed> {
|
) -> Result<(), ErrorGuaranteed> {
|
||||||
let lang_items = tcx.lang_items();
|
let lang_items = tcx.lang_items();
|
||||||
let checker = Checker { tcx, trait_def_id, impl_def_id };
|
let checker = Checker { tcx, trait_def_id, impl_def_id, impl_header };
|
||||||
let mut res = checker.check(lang_items.drop_trait(), |tcx, id| {
|
let mut res = checker.check(lang_items.drop_trait(), visit_implementation_of_drop);
|
||||||
visit_implementation_of_drop(tcx, id, impl_header)
|
res = res.and(checker.check(lang_items.copy_trait(), visit_implementation_of_copy));
|
||||||
});
|
res = res.and(
|
||||||
res = res.and(checker.check(lang_items.copy_trait(), |tcx, id| {
|
checker.check(lang_items.const_param_ty_trait(), visit_implementation_of_const_param_ty),
|
||||||
visit_implementation_of_copy(tcx, id, impl_header)
|
);
|
||||||
}));
|
|
||||||
res = res.and(checker.check(lang_items.const_param_ty_trait(), |tcx, id| {
|
|
||||||
visit_implementation_of_const_param_ty(tcx, id, impl_header)
|
|
||||||
}));
|
|
||||||
res = res.and(
|
res = res.and(
|
||||||
checker.check(lang_items.coerce_unsized_trait(), visit_implementation_of_coerce_unsized),
|
checker.check(lang_items.coerce_unsized_trait(), visit_implementation_of_coerce_unsized),
|
||||||
);
|
);
|
||||||
res.and(checker.check(lang_items.dispatch_from_dyn_trait(), |tcx, id| {
|
res.and(
|
||||||
visit_implementation_of_dispatch_from_dyn(tcx, id, impl_header.trait_ref)
|
checker
|
||||||
}))
|
.check(lang_items.dispatch_from_dyn_trait(), visit_implementation_of_dispatch_from_dyn),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Checker<'tcx> {
|
struct Checker<'tcx> {
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
trait_def_id: DefId,
|
trait_def_id: DefId,
|
||||||
impl_def_id: LocalDefId,
|
impl_def_id: LocalDefId,
|
||||||
|
impl_header: ty::ImplTraitHeader<'tcx>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> Checker<'tcx> {
|
impl<'tcx> Checker<'tcx> {
|
||||||
fn check(
|
fn check(
|
||||||
&self,
|
&self,
|
||||||
trait_def_id: Option<DefId>,
|
trait_def_id: Option<DefId>,
|
||||||
f: impl FnOnce(TyCtxt<'tcx>, LocalDefId) -> Result<(), ErrorGuaranteed>,
|
f: impl FnOnce(&Self) -> Result<(), ErrorGuaranteed>,
|
||||||
) -> Result<(), ErrorGuaranteed> {
|
) -> Result<(), ErrorGuaranteed> {
|
||||||
if Some(self.trait_def_id) == trait_def_id { f(self.tcx, self.impl_def_id) } else { Ok(()) }
|
if Some(self.trait_def_id) == trait_def_id { f(self) } else { Ok(()) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_implementation_of_drop<'tcx>(
|
fn visit_implementation_of_drop(checker: &Checker<'_>) -> Result<(), ErrorGuaranteed> {
|
||||||
tcx: TyCtxt<'tcx>,
|
let tcx = checker.tcx;
|
||||||
impl_did: LocalDefId,
|
let header = checker.impl_header;
|
||||||
header: ty::ImplTraitHeader<'tcx>,
|
let impl_did = checker.impl_def_id;
|
||||||
) -> Result<(), ErrorGuaranteed> {
|
|
||||||
// Destructors only work on local ADT types.
|
// Destructors only work on local ADT types.
|
||||||
match header.trait_ref.self_ty().kind() {
|
match header.trait_ref.self_ty().kind() {
|
||||||
ty::Adt(def, _) if def.did().is_local() => return Ok(()),
|
ty::Adt(def, _) if def.did().is_local() => return Ok(()),
|
||||||
|
@ -83,11 +80,10 @@ fn visit_implementation_of_drop<'tcx>(
|
||||||
Err(tcx.dcx().emit_err(errors::DropImplOnWrongItem { span: impl_.self_ty.span }))
|
Err(tcx.dcx().emit_err(errors::DropImplOnWrongItem { span: impl_.self_ty.span }))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_implementation_of_copy<'tcx>(
|
fn visit_implementation_of_copy(checker: &Checker<'_>) -> Result<(), ErrorGuaranteed> {
|
||||||
tcx: TyCtxt<'tcx>,
|
let tcx = checker.tcx;
|
||||||
impl_did: LocalDefId,
|
let impl_header = checker.impl_header;
|
||||||
impl_header: ty::ImplTraitHeader<'tcx>,
|
let impl_did = checker.impl_def_id;
|
||||||
) -> Result<(), ErrorGuaranteed> {
|
|
||||||
debug!("visit_implementation_of_copy: impl_did={:?}", impl_did);
|
debug!("visit_implementation_of_copy: impl_did={:?}", impl_did);
|
||||||
|
|
||||||
let self_type = impl_header.trait_ref.self_ty();
|
let self_type = impl_header.trait_ref.self_ty();
|
||||||
|
@ -120,11 +116,10 @@ fn visit_implementation_of_copy<'tcx>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_implementation_of_const_param_ty<'tcx>(
|
fn visit_implementation_of_const_param_ty(checker: &Checker<'_>) -> Result<(), ErrorGuaranteed> {
|
||||||
tcx: TyCtxt<'tcx>,
|
let tcx = checker.tcx;
|
||||||
impl_did: LocalDefId,
|
let header = checker.impl_header;
|
||||||
header: ty::ImplTraitHeader<'tcx>,
|
let impl_did = checker.impl_def_id;
|
||||||
) -> Result<(), ErrorGuaranteed> {
|
|
||||||
let self_type = header.trait_ref.self_ty();
|
let self_type = header.trait_ref.self_ty();
|
||||||
assert!(!self_type.has_escaping_bound_vars());
|
assert!(!self_type.has_escaping_bound_vars());
|
||||||
|
|
||||||
|
@ -148,10 +143,9 @@ fn visit_implementation_of_const_param_ty<'tcx>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_implementation_of_coerce_unsized(
|
fn visit_implementation_of_coerce_unsized(checker: &Checker<'_>) -> Result<(), ErrorGuaranteed> {
|
||||||
tcx: TyCtxt<'_>,
|
let tcx = checker.tcx;
|
||||||
impl_did: LocalDefId,
|
let impl_did = checker.impl_def_id;
|
||||||
) -> Result<(), ErrorGuaranteed> {
|
|
||||||
debug!("visit_implementation_of_coerce_unsized: impl_did={:?}", impl_did);
|
debug!("visit_implementation_of_coerce_unsized: impl_did={:?}", impl_did);
|
||||||
|
|
||||||
// Just compute this for the side-effects, in particular reporting
|
// Just compute this for the side-effects, in particular reporting
|
||||||
|
@ -161,11 +155,11 @@ fn visit_implementation_of_coerce_unsized(
|
||||||
tcx.at(span).ensure().coerce_unsized_info(impl_did)
|
tcx.at(span).ensure().coerce_unsized_info(impl_did)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_implementation_of_dispatch_from_dyn<'tcx>(
|
fn visit_implementation_of_dispatch_from_dyn(checker: &Checker<'_>) -> Result<(), ErrorGuaranteed> {
|
||||||
tcx: TyCtxt<'tcx>,
|
let tcx = checker.tcx;
|
||||||
impl_did: LocalDefId,
|
let header = checker.impl_header;
|
||||||
trait_ref: ty::TraitRef<'tcx>,
|
let impl_did = checker.impl_def_id;
|
||||||
) -> Result<(), ErrorGuaranteed> {
|
let trait_ref = header.trait_ref;
|
||||||
debug!("visit_implementation_of_dispatch_from_dyn: impl_did={:?}", impl_did);
|
debug!("visit_implementation_of_dispatch_from_dyn: impl_did={:?}", impl_did);
|
||||||
|
|
||||||
let span = tcx.def_span(impl_did);
|
let span = tcx.def_span(impl_did);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue