Skip to content

Commit 790ab94

Browse files
committed
Move ImplHeader out of rustc_middle.
It's not used in `rustc_middle`, and `rustc_trait_selection` is a better place for it.
1 parent e83c8cb commit 790ab94

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -250,18 +250,6 @@ impl MainDefinition {
250250
}
251251
}
252252

253-
/// The "header" of an impl is everything outside the body: a Self type, a trait
254-
/// ref (in the case of a trait impl), and a set of predicates (from the
255-
/// bounds / where-clauses).
256-
#[derive(Clone, Debug, TypeFoldable, TypeVisitable)]
257-
pub struct ImplHeader<'tcx> {
258-
pub impl_def_id: DefId,
259-
pub impl_args: ty::GenericArgsRef<'tcx>,
260-
pub self_ty: Ty<'tcx>,
261-
pub trait_ref: Option<TraitRef<'tcx>>,
262-
pub predicates: Vec<Predicate<'tcx>>,
263-
}
264-
265253
#[derive(Copy, Clone, Debug, TyEncodable, TyDecodable, HashStable)]
266254
pub struct ImplTraitHeader<'tcx> {
267255
pub trait_ref: ty::EarlyBinder<'tcx, ty::TraitRef<'tcx>>,

compiler/rustc_trait_selection/src/traits/coherence.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use rustc_hir::def::DefKind;
1212
use rustc_hir::def_id::{CRATE_DEF_ID, DefId};
1313
use rustc_infer::infer::{DefineOpaqueTypes, InferCtxt, TyCtxtInferExt};
1414
use rustc_infer::traits::PredicateObligations;
15+
use rustc_macros::{TypeFoldable, TypeVisitable};
1516
use rustc_middle::bug;
1617
use rustc_middle::traits::query::NoSolution;
1718
use rustc_middle::traits::solve::{CandidateSource, Certainty, Goal};
@@ -37,8 +38,20 @@ use crate::traits::{
3738
SelectionContext, SkipLeakCheck, util,
3839
};
3940

41+
/// The "header" of an impl is everything outside the body: a Self type, a trait
42+
/// ref (in the case of a trait impl), and a set of predicates (from the
43+
/// bounds / where-clauses).
44+
#[derive(Clone, Debug, TypeFoldable, TypeVisitable)]
45+
pub struct ImplHeader<'tcx> {
46+
pub impl_def_id: DefId,
47+
pub impl_args: ty::GenericArgsRef<'tcx>,
48+
pub self_ty: Ty<'tcx>,
49+
pub trait_ref: Option<ty::TraitRef<'tcx>>,
50+
pub predicates: Vec<ty::Predicate<'tcx>>,
51+
}
52+
4053
pub struct OverlapResult<'tcx> {
41-
pub impl_header: ty::ImplHeader<'tcx>,
54+
pub impl_header: ImplHeader<'tcx>,
4255
pub intercrate_ambiguity_causes: FxIndexSet<IntercrateAmbiguityCause<'tcx>>,
4356

4457
/// `true` if the overlap might've been permitted before the shift
@@ -151,11 +164,11 @@ pub fn overlapping_impls(
151164
}
152165
}
153166

154-
fn fresh_impl_header<'tcx>(infcx: &InferCtxt<'tcx>, impl_def_id: DefId) -> ty::ImplHeader<'tcx> {
167+
fn fresh_impl_header<'tcx>(infcx: &InferCtxt<'tcx>, impl_def_id: DefId) -> ImplHeader<'tcx> {
155168
let tcx = infcx.tcx;
156169
let impl_args = infcx.fresh_args_for_item(DUMMY_SP, impl_def_id);
157170

158-
ty::ImplHeader {
171+
ImplHeader {
159172
impl_def_id,
160173
impl_args,
161174
self_ty: tcx.type_of(impl_def_id).instantiate(tcx, impl_args),
@@ -173,7 +186,7 @@ fn fresh_impl_header_normalized<'tcx>(
173186
infcx: &InferCtxt<'tcx>,
174187
param_env: ty::ParamEnv<'tcx>,
175188
impl_def_id: DefId,
176-
) -> ty::ImplHeader<'tcx> {
189+
) -> ImplHeader<'tcx> {
177190
let header = fresh_impl_header(infcx, impl_def_id);
178191

179192
let InferOk { value: mut header, obligations } =
@@ -287,8 +300,8 @@ fn overlap<'tcx>(
287300
fn equate_impl_headers<'tcx>(
288301
infcx: &InferCtxt<'tcx>,
289302
param_env: ty::ParamEnv<'tcx>,
290-
impl1: &ty::ImplHeader<'tcx>,
291-
impl2: &ty::ImplHeader<'tcx>,
303+
impl1: &ImplHeader<'tcx>,
304+
impl2: &ImplHeader<'tcx>,
292305
) -> Option<PredicateObligations<'tcx>> {
293306
let result =
294307
match (impl1.trait_ref, impl2.trait_ref) {

0 commit comments

Comments
 (0)