Skip to content

Commit 251c33c

Browse files
committed
Remove an impl_polarity call where the information is already available in the header
1 parent 75de6cf commit 251c33c

File tree

1 file changed

+23
-16
lines changed
  • compiler/rustc_hir_analysis/src/coherence

1 file changed

+23
-16
lines changed

compiler/rustc_hir_analysis/src/coherence/builtin.rs

+23-16
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,15 @@ pub fn check_trait<'tcx>(
3333
) -> Result<(), ErrorGuaranteed> {
3434
let lang_items = tcx.lang_items();
3535
let checker = Checker { tcx, trait_def_id, impl_def_id };
36-
let mut res = checker.check(lang_items.drop_trait(), visit_implementation_of_drop);
37-
res = res.and(checker.check(lang_items.copy_trait(), visit_implementation_of_copy));
38-
res = res.and(
39-
checker.check(lang_items.const_param_ty_trait(), visit_implementation_of_const_param_ty),
40-
);
36+
let mut res = checker.check(lang_items.drop_trait(), |tcx, id| {
37+
visit_implementation_of_drop(tcx, id, impl_header)
38+
});
39+
res = res.and(checker.check(lang_items.copy_trait(), |tcx, id| {
40+
visit_implementation_of_copy(tcx, id, impl_header)
41+
}));
42+
res = res.and(checker.check(lang_items.const_param_ty_trait(), |tcx, id| {
43+
visit_implementation_of_const_param_ty(tcx, id, impl_header)
44+
}));
4145
res = res.and(
4246
checker.check(lang_items.coerce_unsized_trait(), visit_implementation_of_coerce_unsized),
4347
);
@@ -62,12 +66,13 @@ impl<'tcx> Checker<'tcx> {
6266
}
6367
}
6468

65-
fn visit_implementation_of_drop(
66-
tcx: TyCtxt<'_>,
69+
fn visit_implementation_of_drop<'tcx>(
70+
tcx: TyCtxt<'tcx>,
6771
impl_did: LocalDefId,
72+
header: ty::ImplTraitHeader<'tcx>,
6873
) -> Result<(), ErrorGuaranteed> {
6974
// Destructors only work on local ADT types.
70-
match tcx.type_of(impl_did).instantiate_identity().kind() {
75+
match header.trait_ref.self_ty().kind() {
7176
ty::Adt(def, _) if def.did().is_local() => return Ok(()),
7277
ty::Error(_) => return Ok(()),
7378
_ => {}
@@ -78,21 +83,22 @@ fn visit_implementation_of_drop(
7883
Err(tcx.dcx().emit_err(errors::DropImplOnWrongItem { span: impl_.self_ty.span }))
7984
}
8085

81-
fn visit_implementation_of_copy(
82-
tcx: TyCtxt<'_>,
86+
fn visit_implementation_of_copy<'tcx>(
87+
tcx: TyCtxt<'tcx>,
8388
impl_did: LocalDefId,
89+
impl_header: ty::ImplTraitHeader<'tcx>,
8490
) -> Result<(), ErrorGuaranteed> {
8591
debug!("visit_implementation_of_copy: impl_did={:?}", impl_did);
8692

87-
let self_type = tcx.type_of(impl_did).instantiate_identity();
93+
let self_type = impl_header.trait_ref.self_ty();
8894
debug!("visit_implementation_of_copy: self_type={:?} (bound)", self_type);
8995

9096
let param_env = tcx.param_env(impl_did);
9197
assert!(!self_type.has_escaping_bound_vars());
9298

9399
debug!("visit_implementation_of_copy: self_type={:?} (free)", self_type);
94100

95-
if let ty::ImplPolarity::Negative = tcx.impl_polarity(impl_did) {
101+
if let ty::ImplPolarity::Negative = impl_header.polarity {
96102
return Ok(());
97103
}
98104

@@ -114,16 +120,17 @@ fn visit_implementation_of_copy(
114120
}
115121
}
116122

117-
fn visit_implementation_of_const_param_ty(
118-
tcx: TyCtxt<'_>,
123+
fn visit_implementation_of_const_param_ty<'tcx>(
124+
tcx: TyCtxt<'tcx>,
119125
impl_did: LocalDefId,
126+
header: ty::ImplTraitHeader<'tcx>,
120127
) -> Result<(), ErrorGuaranteed> {
121-
let self_type = tcx.type_of(impl_did).instantiate_identity();
128+
let self_type = header.trait_ref.self_ty();
122129
assert!(!self_type.has_escaping_bound_vars());
123130

124131
let param_env = tcx.param_env(impl_did);
125132

126-
if let ty::ImplPolarity::Negative = tcx.impl_polarity(impl_did) {
133+
if let ty::ImplPolarity::Negative = header.polarity {
127134
return Ok(());
128135
}
129136

0 commit comments

Comments
 (0)