Skip to content

Commit c1a9cf4

Browse files
committed
make query take (LocalDefId, DefId)
1 parent 831f440 commit c1a9cf4

File tree

5 files changed

+28
-31
lines changed

5 files changed

+28
-31
lines changed

compiler/rustc_hir_analysis/src/check/check.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1046,9 +1046,8 @@ fn check_impl_items_against_trait<'tcx>(
10461046
hir::ImplItemKind::Const(..) => {
10471047
// Find associated const definition.
10481048
let _ = tcx.compare_assoc_const_impl_item_with_trait_item((
1049-
&ty_impl_item,
1050-
&ty_trait_item,
1051-
impl_trait_ref,
1049+
impl_item.id.def_id.def_id,
1050+
ty_impl_item.trait_item_def_id.unwrap(),
10521051
));
10531052
}
10541053
hir::ImplItemKind::Fn(..) => {

compiler/rustc_hir_analysis/src/check/compare_method.rs

+20-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::potentially_plural_count;
22
use crate::errors::LifetimesOrBoundsMismatchOnTrait;
3-
use hir::def_id::DefId;
3+
use hir::def_id::{DefId, LocalDefId};
44
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
55
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticId, ErrorGuaranteed};
66
use rustc_hir as hir;
@@ -1303,14 +1303,17 @@ fn compare_generic_param_kinds<'tcx>(
13031303
/// Use `tcx.compare_assoc_const_impl_item_with_trait_item` instead
13041304
pub(crate) fn raw_compare_const_impl<'tcx>(
13051305
tcx: TyCtxt<'tcx>,
1306-
(impl_c, trait_c, impl_trait_ref): (&ty::AssocItem, &ty::AssocItem, ty::TraitRef<'tcx>),
1306+
(impl_const_item_def, trait_const_item_def): (LocalDefId, DefId),
13071307
) -> Result<(), ErrorGuaranteed> {
1308+
let impl_const_item = tcx.associated_item(impl_const_item_def);
1309+
let trait_const_item = tcx.associated_item(trait_const_item_def);
1310+
let impl_trait_ref = tcx.impl_trait_ref(impl_const_item.container_id(tcx)).unwrap();
13081311
debug!("compare_const_impl(impl_trait_ref={:?})", impl_trait_ref);
13091312

1310-
let impl_c_span = tcx.def_span(impl_c.def_id);
1313+
let impl_c_span = tcx.def_span(impl_const_item_def.to_def_id());
13111314

13121315
tcx.infer_ctxt().enter(|infcx| {
1313-
let param_env = tcx.param_env(impl_c.def_id);
1316+
let param_env = tcx.param_env(impl_const_item_def.to_def_id());
13141317
let ocx = ObligationCtxt::new(&infcx);
13151318

13161319
// The below is for the most part highly similar to the procedure
@@ -1322,18 +1325,18 @@ pub(crate) fn raw_compare_const_impl<'tcx>(
13221325

13231326
// Create a parameter environment that represents the implementation's
13241327
// method.
1325-
let impl_c_hir_id = tcx.hir().local_def_id_to_hir_id(impl_c.def_id.expect_local());
1328+
let impl_c_hir_id = tcx.hir().local_def_id_to_hir_id(impl_const_item_def);
13261329

13271330
// Compute placeholder form of impl and trait const tys.
1328-
let impl_ty = tcx.type_of(impl_c.def_id);
1329-
let trait_ty = tcx.bound_type_of(trait_c.def_id).subst(tcx, trait_to_impl_substs);
1331+
let impl_ty = tcx.type_of(impl_const_item_def.to_def_id());
1332+
let trait_ty = tcx.bound_type_of(trait_const_item_def).subst(tcx, trait_to_impl_substs);
13301333
let mut cause = ObligationCause::new(
13311334
impl_c_span,
13321335
impl_c_hir_id,
13331336
ObligationCauseCode::CompareImplItemObligation {
1334-
impl_item_def_id: impl_c.def_id.expect_local(),
1335-
trait_item_def_id: trait_c.def_id,
1336-
kind: impl_c.kind,
1337+
impl_item_def_id: impl_const_item_def,
1338+
trait_item_def_id: trait_const_item_def,
1339+
kind: impl_const_item.kind,
13371340
},
13381341
);
13391342

@@ -1357,24 +1360,24 @@ pub(crate) fn raw_compare_const_impl<'tcx>(
13571360
);
13581361

13591362
// Locate the Span containing just the type of the offending impl
1360-
match tcx.hir().expect_impl_item(impl_c.def_id.expect_local()).kind {
1363+
match tcx.hir().expect_impl_item(impl_const_item_def).kind {
13611364
ImplItemKind::Const(ref ty, _) => cause.span = ty.span,
1362-
_ => bug!("{:?} is not a impl const", impl_c),
1365+
_ => bug!("{:?} is not a impl const", impl_const_item),
13631366
}
13641367

13651368
let mut diag = struct_span_err!(
13661369
tcx.sess,
13671370
cause.span,
13681371
E0326,
13691372
"implemented const `{}` has an incompatible type for trait",
1370-
trait_c.name
1373+
trait_const_item.name
13711374
);
13721375

1373-
let trait_c_span = trait_c.def_id.as_local().map(|trait_c_def_id| {
1376+
let trait_c_span = trait_const_item_def.as_local().map(|trait_c_def_id| {
13741377
// Add a label to the Span containing just the type of the const
13751378
match tcx.hir().expect_trait_item(trait_c_def_id).kind {
13761379
TraitItemKind::Const(ref ty, _) => ty.span,
1377-
_ => bug!("{:?} is not a trait const", trait_c),
1380+
_ => bug!("{:?} is not a trait const", trait_const_item),
13781381
}
13791382
});
13801383

@@ -1402,10 +1405,8 @@ pub(crate) fn raw_compare_const_impl<'tcx>(
14021405

14031406
// FIXME return `ErrorReported` if region obligations error?
14041407
let outlives_environment = OutlivesEnvironment::new(param_env);
1405-
infcx.check_region_obligations_and_report_errors(
1406-
impl_c.def_id.expect_local(),
1407-
&outlives_environment,
1408-
);
1408+
infcx
1409+
.check_region_obligations_and_report_errors(impl_const_item_def, &outlives_environment);
14091410
maybe_error_reported
14101411
})
14111412
}

compiler/rustc_middle/src/query/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2102,8 +2102,8 @@ rustc_queries! {
21022102
}
21032103

21042104
query compare_assoc_const_impl_item_with_trait_item(
2105-
key: (&'tcx ty::AssocItem, &'tcx ty::AssocItem, ty::TraitRef<'tcx>)
2105+
key: (LocalDefId, DefId)
21062106
) -> Result<(), ErrorGuaranteed> {
2107-
desc { |tcx| "checking assoc const `{}` has the same type as trait item", tcx.def_path_str(key.0.def_id) }
2107+
desc { |tcx| "checking assoc const `{}` has the same type as trait item", tcx.def_path_str(key.0.to_def_id()) }
21082108
}
21092109
}

compiler/rustc_ty_utils/src/instance.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,11 @@ fn resolve_associated_item<'tcx>(
184184
// error has already been/will be emitted elsewhere).
185185
if leaf_def.item.kind == ty::AssocKind::Const
186186
&& trait_item_id != leaf_def.item.def_id
187-
&& leaf_def.item.def_id.is_local()
187+
&& let Some(leaf_def_item) = leaf_def.item.def_id.as_local()
188188
{
189-
let impl_item = tcx.associated_item(leaf_def.item.def_id);
190-
let trait_item = tcx.associated_item(trait_item_id);
191-
let impl_trait_ref = tcx.impl_trait_ref(impl_item.container_id(tcx)).unwrap();
192189
tcx.compare_assoc_const_impl_item_with_trait_item((
193-
impl_item,
194-
trait_item,
195-
impl_trait_ref,
190+
leaf_def_item,
191+
trait_item_id,
196192
))?;
197193
}
198194

compiler/rustc_ty_utils/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
//! This API is completely unstable and subject to change.
66
77
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
8+
#![feature(let_chains)]
89
#![feature(control_flow_enum)]
910
#![feature(never_type)]
1011
#![feature(box_patterns)]

0 commit comments

Comments
 (0)