Skip to content

Commit

Permalink
Apply EarlyBinder only to TraitRef in ImplTraitHeader
Browse files Browse the repository at this point in the history
  • Loading branch information
Y-Nak committed Mar 6, 2024
1 parent f543c8d commit 4063f14
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
20 changes: 5 additions & 15 deletions compiler/rustc_hir_analysis/src/coherence/builtin.rs
Expand Up @@ -32,7 +32,7 @@ pub(super) fn check_trait<'tcx>(
impl_header: ty::ImplTraitHeader<'tcx>,
) -> Result<(), ErrorGuaranteed> {
let lang_items = tcx.lang_items();
let checker = Checker::new(tcx, trait_def_id, impl_def_id, impl_header);
let checker = Checker { tcx, trait_def_id, impl_def_id, impl_header };
let mut res = checker.check(lang_items.drop_trait(), visit_implementation_of_drop);
res = res.and(checker.check(lang_items.copy_trait(), visit_implementation_of_copy));
res = res.and(
Expand All @@ -52,19 +52,9 @@ struct Checker<'tcx> {
trait_def_id: DefId,
impl_def_id: LocalDefId,
impl_header: ty::ImplTraitHeader<'tcx>,
trait_ref: ty::TraitRef<'tcx>,
}

impl<'tcx> Checker<'tcx> {
fn new(
tcx: TyCtxt<'tcx>,
trait_def_id: DefId,
impl_def_id: LocalDefId,
impl_header: ty::ImplTraitHeader<'tcx>,
) -> Self {
let trait_ref = impl_header.trait_ref.instantiate_identity();
Self { tcx, trait_def_id, impl_def_id, impl_header, trait_ref }
}
fn check(
&self,
trait_def_id: Option<DefId>,
Expand All @@ -78,7 +68,7 @@ fn visit_implementation_of_drop(checker: &Checker<'_>) -> Result<(), ErrorGuaran
let tcx = checker.tcx;
let impl_did = checker.impl_def_id;
// Destructors only work on local ADT types.
match checker.trait_ref.self_ty().kind() {
match checker.impl_header.trait_ref.instantiate_identity().self_ty().kind() {
ty::Adt(def, _) if def.did().is_local() => return Ok(()),
ty::Error(_) => return Ok(()),
_ => {}
Expand All @@ -95,7 +85,7 @@ fn visit_implementation_of_copy(checker: &Checker<'_>) -> Result<(), ErrorGuaran
let impl_did = checker.impl_def_id;
debug!("visit_implementation_of_copy: impl_did={:?}", impl_did);

let self_type = checker.trait_ref.self_ty();
let self_type = impl_header.trait_ref.instantiate_identity().self_ty();
debug!("visit_implementation_of_copy: self_type={:?} (bound)", self_type);

let param_env = tcx.param_env(impl_did);
Expand Down Expand Up @@ -129,7 +119,7 @@ fn visit_implementation_of_const_param_ty(checker: &Checker<'_>) -> Result<(), E
let tcx = checker.tcx;
let header = checker.impl_header;
let impl_did = checker.impl_def_id;
let self_type = checker.trait_ref.self_ty();
let self_type = header.trait_ref.instantiate_identity().self_ty();
assert!(!self_type.has_escaping_bound_vars());

let param_env = tcx.param_env(impl_did);
Expand Down Expand Up @@ -167,7 +157,7 @@ fn visit_implementation_of_coerce_unsized(checker: &Checker<'_>) -> Result<(), E
fn visit_implementation_of_dispatch_from_dyn(checker: &Checker<'_>) -> Result<(), ErrorGuaranteed> {
let tcx = checker.tcx;
let impl_did = checker.impl_def_id;
let trait_ref = checker.trait_ref;
let trait_ref = checker.impl_header.trait_ref.instantiate_identity();
debug!("visit_implementation_of_dispatch_from_dyn: impl_did={:?}", impl_did);

let span = tcx.def_span(impl_did);
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Expand Up @@ -1981,9 +1981,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {

if of_trait && let Some(header) = tcx.impl_trait_header(def_id) {
record!(self.tables.impl_trait_header[def_id] <- header);
let trait_ref = header.trait_ref;

let trait_ref = trait_ref.instantiate_identity();
let trait_ref = header.trait_ref.instantiate_identity();
let simplified_self_ty = fast_reject::simplify_type(
self.tcx,
trait_ref.self_ty(),
Expand Down

0 comments on commit 4063f14

Please sign in to comment.