Remove an impl_polarity
call where the information is already available in the header
This commit is contained in:
parent
75de6cf9a3
commit
251c33ce2a
1 changed files with 23 additions and 16 deletions
|
@ -33,11 +33,15 @@ pub fn check_trait<'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 };
|
||||||
let mut res = checker.check(lang_items.drop_trait(), visit_implementation_of_drop);
|
let mut res = checker.check(lang_items.drop_trait(), |tcx, id| {
|
||||||
res = res.and(checker.check(lang_items.copy_trait(), visit_implementation_of_copy));
|
visit_implementation_of_drop(tcx, id, impl_header)
|
||||||
res = res.and(
|
});
|
||||||
checker.check(lang_items.const_param_ty_trait(), visit_implementation_of_const_param_ty),
|
res = res.and(checker.check(lang_items.copy_trait(), |tcx, id| {
|
||||||
);
|
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),
|
||||||
);
|
);
|
||||||
|
@ -62,12 +66,13 @@ impl<'tcx> Checker<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_implementation_of_drop(
|
fn visit_implementation_of_drop<'tcx>(
|
||||||
tcx: TyCtxt<'_>,
|
tcx: TyCtxt<'tcx>,
|
||||||
impl_did: LocalDefId,
|
impl_did: LocalDefId,
|
||||||
|
header: ty::ImplTraitHeader<'tcx>,
|
||||||
) -> Result<(), ErrorGuaranteed> {
|
) -> Result<(), ErrorGuaranteed> {
|
||||||
// Destructors only work on local ADT types.
|
// Destructors only work on local ADT types.
|
||||||
match tcx.type_of(impl_did).instantiate_identity().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(()),
|
||||||
ty::Error(_) => return Ok(()),
|
ty::Error(_) => return Ok(()),
|
||||||
_ => {}
|
_ => {}
|
||||||
|
@ -78,13 +83,14 @@ fn visit_implementation_of_drop(
|
||||||
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(
|
fn visit_implementation_of_copy<'tcx>(
|
||||||
tcx: TyCtxt<'_>,
|
tcx: TyCtxt<'tcx>,
|
||||||
impl_did: LocalDefId,
|
impl_did: LocalDefId,
|
||||||
|
impl_header: ty::ImplTraitHeader<'tcx>,
|
||||||
) -> Result<(), ErrorGuaranteed> {
|
) -> Result<(), ErrorGuaranteed> {
|
||||||
debug!("visit_implementation_of_copy: impl_did={:?}", impl_did);
|
debug!("visit_implementation_of_copy: impl_did={:?}", impl_did);
|
||||||
|
|
||||||
let self_type = tcx.type_of(impl_did).instantiate_identity();
|
let self_type = impl_header.trait_ref.self_ty();
|
||||||
debug!("visit_implementation_of_copy: self_type={:?} (bound)", self_type);
|
debug!("visit_implementation_of_copy: self_type={:?} (bound)", self_type);
|
||||||
|
|
||||||
let param_env = tcx.param_env(impl_did);
|
let param_env = tcx.param_env(impl_did);
|
||||||
|
@ -92,7 +98,7 @@ fn visit_implementation_of_copy(
|
||||||
|
|
||||||
debug!("visit_implementation_of_copy: self_type={:?} (free)", self_type);
|
debug!("visit_implementation_of_copy: self_type={:?} (free)", self_type);
|
||||||
|
|
||||||
if let ty::ImplPolarity::Negative = tcx.impl_polarity(impl_did) {
|
if let ty::ImplPolarity::Negative = impl_header.polarity {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,16 +120,17 @@ fn visit_implementation_of_copy(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_implementation_of_const_param_ty(
|
fn visit_implementation_of_const_param_ty<'tcx>(
|
||||||
tcx: TyCtxt<'_>,
|
tcx: TyCtxt<'tcx>,
|
||||||
impl_did: LocalDefId,
|
impl_did: LocalDefId,
|
||||||
|
header: ty::ImplTraitHeader<'tcx>,
|
||||||
) -> Result<(), ErrorGuaranteed> {
|
) -> Result<(), ErrorGuaranteed> {
|
||||||
let self_type = tcx.type_of(impl_did).instantiate_identity();
|
let self_type = header.trait_ref.self_ty();
|
||||||
assert!(!self_type.has_escaping_bound_vars());
|
assert!(!self_type.has_escaping_bound_vars());
|
||||||
|
|
||||||
let param_env = tcx.param_env(impl_did);
|
let param_env = tcx.param_env(impl_did);
|
||||||
|
|
||||||
if let ty::ImplPolarity::Negative = tcx.impl_polarity(impl_did) {
|
if let ty::ImplPolarity::Negative = header.polarity {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue