Skip to content

Commit fb17d88

Browse files
committed
Use a struct instead of a tuple
1 parent 1c666b7 commit fb17d88

File tree

8 files changed

+19
-10
lines changed

8 files changed

+19
-10
lines changed

compiler/rustc_hir_analysis/src/collect.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1329,7 +1329,7 @@ fn suggest_impl_trait<'tcx>(
13291329
fn impl_trait_header(
13301330
tcx: TyCtxt<'_>,
13311331
def_id: LocalDefId,
1332-
) -> Option<(ty::EarlyBinder<ty::TraitRef<'_>>, ty::ImplPolarity)> {
1332+
) -> Option<ty::EarlyBinder<ty::ImplTraitHeader<'_>>> {
13331333
let icx = ItemCtxt::new(tcx, def_id);
13341334
let item = tcx.hir().expect_item(def_id);
13351335
let impl_ = item.expect_impl();
@@ -1339,7 +1339,7 @@ fn impl_trait_header(
13391339
.map(|ast_trait_ref| {
13401340
let selfty = tcx.type_of(def_id).instantiate_identity();
13411341

1342-
let impl_trait_ref = if let Some(ErrorGuaranteed { .. }) = check_impl_constness(
1342+
let trait_ref = if let Some(ErrorGuaranteed { .. }) = check_impl_constness(
13431343
tcx,
13441344
tcx.is_const_trait_impl_raw(def_id.to_def_id()),
13451345
ast_trait_ref,
@@ -1365,7 +1365,10 @@ fn impl_trait_header(
13651365
} else {
13661366
icx.astconv().instantiate_mono_trait_ref(ast_trait_ref, selfty)
13671367
};
1368-
(ty::EarlyBinder::bind(impl_trait_ref), polarity_of_impl_item(tcx, def_id, impl_, item.span))
1368+
ty::EarlyBinder::bind(ty::ImplTraitHeader {
1369+
trait_ref,
1370+
polarity: polarity_of_impl_item(tcx, def_id, impl_, item.span)
1371+
})
13691372
})
13701373
}
13711374

compiler/rustc_metadata/src/rmeta/encoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1966,7 +1966,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
19661966

19671967
if of_trait && let Some(header) = tcx.impl_trait_header(def_id) {
19681968
record!(self.tables.impl_trait_header[def_id] <- header);
1969-
let (trait_ref, _polarity) = header;
1969+
let trait_ref = header.map_bound(|h| h.trait_ref);
19701970

19711971
let trait_ref = trait_ref.instantiate_identity();
19721972
let simplified_self_ty = fast_reject::simplify_type(

compiler/rustc_metadata/src/rmeta/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ define_tables! {
423423
variances_of: Table<DefIndex, LazyArray<ty::Variance>>,
424424
fn_sig: Table<DefIndex, LazyValue<ty::EarlyBinder<ty::PolyFnSig<'static>>>>,
425425
codegen_fn_attrs: Table<DefIndex, LazyValue<CodegenFnAttrs>>,
426-
impl_trait_header: Table<DefIndex, LazyValue<(ty::EarlyBinder<ty::TraitRef<'static>>, ty::ImplPolarity)>>,
426+
impl_trait_header: Table<DefIndex, LazyValue<ty::EarlyBinder<ty::ImplTraitHeader<'static>>>>,
427427
const_param_default: Table<DefIndex, LazyValue<ty::EarlyBinder<rustc_middle::ty::Const<'static>>>>,
428428
object_lifetime_default: Table<DefIndex, LazyValue<ObjectLifetimeDefault>>,
429429
optimized_mir: Table<DefIndex, LazyValue<mir::Body<'static>>>,

compiler/rustc_middle/src/query/erase.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,8 @@ impl EraseType for Option<mir::DestructuredConstant<'_>> {
177177
type Result = [u8; size_of::<Option<mir::DestructuredConstant<'static>>>()];
178178
}
179179

180-
impl EraseType for Option<(ty::EarlyBinder<ty::TraitRef<'_>>, ty::ImplPolarity)> {
181-
type Result =
182-
[u8; size_of::<Option<(ty::EarlyBinder<ty::TraitRef<'static>>, ty::ImplPolarity)>>()];
180+
impl EraseType for Option<ty::EarlyBinder<ty::ImplTraitHeader<'_>>> {
181+
type Result = [u8; size_of::<Option<ty::EarlyBinder<ty::ImplTraitHeader<'static>>>>()];
183182
}
184183

185184
impl EraseType for Option<ty::EarlyBinder<Ty<'_>>> {

compiler/rustc_middle/src/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ rustc_queries! {
848848

849849
/// Given an `impl_id`, return the trait it implements along with some header information.
850850
/// Return `None` if this is an inherent impl.
851-
query impl_trait_header(impl_id: DefId) -> Option<(ty::EarlyBinder<ty::TraitRef<'tcx>>, ty::ImplPolarity)> {
851+
query impl_trait_header(impl_id: DefId) -> Option<ty::EarlyBinder<ty::ImplTraitHeader<'tcx>>> {
852852
desc { |tcx| "computing trait implemented by `{}`", tcx.def_path_str(impl_id) }
853853
cache_on_disk_if { impl_id.is_local() }
854854
separate_provide_extern

compiler/rustc_middle/src/ty/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2315,7 +2315,7 @@ impl<'tcx> TyCtxt<'tcx> {
23152315
self,
23162316
def_id: impl IntoQueryParam<DefId>,
23172317
) -> Option<ty::EarlyBinder<ty::TraitRef<'tcx>>> {
2318-
Some(self.impl_trait_header(def_id)?.0)
2318+
Some(self.impl_trait_header(def_id)?.map_bound(|h| h.trait_ref))
23192319
}
23202320
}
23212321

compiler/rustc_middle/src/ty/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,12 @@ pub struct ImplHeader<'tcx> {
248248
pub predicates: Vec<Predicate<'tcx>>,
249249
}
250250

251+
#[derive(Copy, Clone, Debug, TypeFoldable, TypeVisitable, TyEncodable, TyDecodable, HashStable)]
252+
pub struct ImplTraitHeader<'tcx> {
253+
pub trait_ref: ty::TraitRef<'tcx>,
254+
pub polarity: ImplPolarity,
255+
}
256+
251257
#[derive(Copy, Clone, PartialEq, Eq, Debug, TypeFoldable, TypeVisitable)]
252258
pub enum ImplSubject<'tcx> {
253259
Trait(TraitRef<'tcx>),

compiler/rustc_middle/src/ty/parameterized.rs

+1
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,5 @@ parameterized_over_tcx! {
134134
ty::Predicate,
135135
ty::Clause,
136136
ty::ClauseKind,
137+
ty::ImplTraitHeader
137138
}

0 commit comments

Comments
 (0)