Skip to content

Commit 796b828

Browse files
committed
convert more DefIds to LocalDefId
1 parent 0677edc commit 796b828

File tree

11 files changed

+50
-43
lines changed

11 files changed

+50
-43
lines changed

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,15 +237,15 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
237237
ObligationCauseCode::MatchImpl(parent, ..) => parent.code(),
238238
_ => cause.code(),
239239
}
240-
&& let (ObligationCauseCode::ItemObligation(item_def_id), None) = (code, override_error_code)
240+
&& let (&ObligationCauseCode::ItemObligation(item_def_id), None) = (code, override_error_code)
241241
{
242242
// Same case of `impl Foo for dyn Bar { fn qux(&self) {} }` introducing a `'static`
243243
// lifetime as above, but called using a fully-qualified path to the method:
244244
// `Foo::qux(bar)`.
245245
let mut v = TraitObjectVisitor(FxHashSet::default());
246246
v.visit_ty(param.param_ty);
247247
if let Some((ident, self_ty)) =
248-
self.get_impl_ident_and_self_ty_from_trait(*item_def_id, &v.0)
248+
self.get_impl_ident_and_self_ty_from_trait(item_def_id, &v.0)
249249
&& self.suggest_constrain_dyn_trait_in_impl(&mut err, &v.0, ident, self_ty)
250250
{
251251
override_error_code = Some(ident.name);

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::traits::ObligationCauseCode::CompareImplMethodObligation;
77
use rustc_errors::ErrorGuaranteed;
88
use rustc_hir as hir;
99
use rustc_hir::def::Res;
10-
use rustc_hir::def_id::DefId;
10+
use rustc_hir::def_id::{DefId, LocalDefId};
1111
use rustc_hir::intravisit::Visitor;
1212
use rustc_middle::hir::nested_filter;
1313
use rustc_middle::ty::print::RegionHighlightMode;
@@ -51,7 +51,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
5151
{
5252
let guar = self.emit_associated_type_err(
5353
span,
54-
self.infcx.tcx.item_name(impl_item_def_id),
54+
self.infcx.tcx.item_name(impl_item_def_id.to_def_id()),
5555
impl_item_def_id,
5656
trait_item_def_id,
5757
);
@@ -155,7 +155,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
155155
&self,
156156
span: Span,
157157
item_name: Symbol,
158-
impl_item_def_id: DefId,
158+
impl_item_def_id: LocalDefId,
159159
trait_item_def_id: DefId,
160160
) -> ErrorGuaranteed {
161161
let impl_sp = self.tcx().def_span(impl_item_def_id);

compiler/rustc_infer/src/infer/error_reporting/note.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
348348
let mut err = self.report_concrete_failure(*parent, sub, sup);
349349

350350
let trait_item_span = self.tcx.def_span(trait_item_def_id);
351-
let item_name = self.tcx.item_name(impl_item_def_id);
351+
let item_name = self.tcx.item_name(impl_item_def_id.to_def_id());
352352
err.span_label(
353353
trait_item_span,
354354
format!("definition of `{}` from trait", item_name),
@@ -370,7 +370,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
370370
let where_clause_span = self
371371
.tcx
372372
.hir()
373-
.get_generics(impl_item_def_id.expect_local())
373+
.get_generics(impl_item_def_id)
374374
.unwrap()
375375
.where_clause
376376
.tail_span_for_suggestion();

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,16 +425,20 @@ pub enum SubregionOrigin<'tcx> {
425425

426426
/// Comparing the signature and requirements of an impl method against
427427
/// the containing trait.
428-
CompareImplMethodObligation { span: Span, impl_item_def_id: DefId, trait_item_def_id: DefId },
428+
CompareImplMethodObligation {
429+
span: Span,
430+
impl_item_def_id: LocalDefId,
431+
trait_item_def_id: DefId,
432+
},
429433

430434
/// Comparing the signature and requirements of an impl associated type
431435
/// against the containing trait
432-
CompareImplTypeObligation { span: Span, impl_item_def_id: DefId, trait_item_def_id: DefId },
436+
CompareImplTypeObligation { span: Span, impl_item_def_id: LocalDefId, trait_item_def_id: DefId },
433437

434438
/// Checking that the bounds of a trait's associated type hold for a given impl
435439
CheckAssociatedTypeBounds {
436440
parent: Box<SubregionOrigin<'tcx>>,
437-
impl_item_def_id: DefId,
441+
impl_item_def_id: LocalDefId,
438442
trait_item_def_id: DefId,
439443
},
440444
}

compiler/rustc_infer/src/traits/error_reporting/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::infer::InferCtxt;
44
use rustc_data_structures::fx::FxHashSet;
55
use rustc_errors::{struct_span_err, DiagnosticBuilder, ErrorGuaranteed};
66
use rustc_hir as hir;
7-
use rustc_hir::def_id::DefId;
7+
use rustc_hir::def_id::{DefId, LocalDefId};
88
use rustc_middle::ty::TyCtxt;
99
use rustc_span::{MultiSpan, Span};
1010
use std::fmt;
@@ -14,7 +14,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1414
pub fn report_extra_impl_obligation(
1515
&self,
1616
error_span: Span,
17-
impl_item_def_id: DefId,
17+
impl_item_def_id: LocalDefId,
1818
trait_item_def_id: DefId,
1919
requirement: &dyn fmt::Display,
2020
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
@@ -25,7 +25,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
2525

2626
if let Some(trait_item_span) = self.tcx.hir().span_if_local(trait_item_def_id) {
2727
let span = self.tcx.sess.source_map().guess_head_span(trait_item_span);
28-
let item_name = self.tcx.item_name(impl_item_def_id);
28+
let item_name = self.tcx.item_name(impl_item_def_id.to_def_id());
2929
err.span_label(span, format!("definition of `{}` from trait", item_name));
3030
}
3131

compiler/rustc_middle/src/traits/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,19 +276,19 @@ pub enum ObligationCauseCode<'tcx> {
276276

277277
/// Error derived when matching traits/impls; see ObligationCause for more details
278278
CompareImplMethodObligation {
279-
impl_item_def_id: DefId,
279+
impl_item_def_id: LocalDefId,
280280
trait_item_def_id: DefId,
281281
},
282282

283283
/// Error derived when matching traits/impls; see ObligationCause for more details
284284
CompareImplTypeObligation {
285-
impl_item_def_id: DefId,
285+
impl_item_def_id: LocalDefId,
286286
trait_item_def_id: DefId,
287287
},
288288

289289
/// Checking that the bounds of a trait's associated type hold for a given impl
290290
CheckAssociatedTypeBounds {
291-
impl_item_def_id: DefId,
291+
impl_item_def_id: LocalDefId,
292292
trait_item_def_id: DefId,
293293
},
294294

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,15 +1797,15 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
17971797
self.suggest_fully_qualified_path(&mut err, def_id, span, trait_ref.def_id());
17981798
} else if let (
17991799
Ok(ref snippet),
1800-
ObligationCauseCode::BindingObligation(ref def_id, _),
1800+
&ObligationCauseCode::BindingObligation(def_id, _),
18011801
) =
18021802
(self.tcx.sess.source_map().span_to_snippet(span), obligation.cause.code())
18031803
{
1804-
let generics = self.tcx.generics_of(*def_id);
1804+
let generics = self.tcx.generics_of(def_id);
18051805
if generics.params.iter().any(|p| p.name != kw::SelfUpper)
18061806
&& !snippet.ends_with('>')
18071807
&& !generics.has_impl_trait()
1808-
&& !self.tcx.fn_trait_kind_from_lang_item(*def_id).is_some()
1808+
&& !self.tcx.fn_trait_kind_from_lang_item(def_id).is_some()
18091809
{
18101810
// FIXME: To avoid spurious suggestions in functions where type arguments
18111811
// where already supplied, we check the snippet to make sure it doesn't
@@ -2107,6 +2107,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
21072107
"suggest_unsized_bound_if_applicable: pred={:?} item_def_id={:?} span={:?}",
21082108
pred, item_def_id, span
21092109
);
2110+
21102111
let (Some(node), true) = (
21112112
self.tcx.hir().get_if_local(item_def_id),
21122113
Some(pred.def_id()) == self.tcx.lang_items().sized_trait(),

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ pub trait InferCtxtExt<'tcx> {
128128
fn suggest_fully_qualified_path(
129129
&self,
130130
err: &mut Diagnostic,
131-
def_id: DefId,
131+
item_def_id: DefId,
132132
span: Span,
133133
trait_ref: DefId,
134134
);
@@ -1317,16 +1317,16 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
13171317
fn suggest_fully_qualified_path(
13181318
&self,
13191319
err: &mut Diagnostic,
1320-
def_id: DefId,
1320+
item_def_id: DefId,
13211321
span: Span,
13221322
trait_ref: DefId,
13231323
) {
1324-
if let Some(assoc_item) = self.tcx.opt_associated_item(def_id) {
1324+
if let Some(assoc_item) = self.tcx.opt_associated_item(item_def_id) {
13251325
if let ty::AssocKind::Const | ty::AssocKind::Type = assoc_item.kind {
13261326
err.note(&format!(
13271327
"{}s cannot be accessed directly on a `trait`, they can only be \
13281328
accessed through a specific `impl`",
1329-
assoc_item.kind.as_def_kind().descr(def_id)
1329+
assoc_item.kind.as_def_kind().descr(item_def_id)
13301330
));
13311331
err.span_suggestion(
13321332
span,

compiler/rustc_typeck/src/check/compare_method.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ use super::{potentially_plural_count, FnCtxt, Inherited};
2828
/// - `impl_m_span`: span to use for reporting errors
2929
/// - `trait_m`: the method in the trait
3030
/// - `impl_trait_ref`: the TraitRef corresponding to the trait implementation
31-
3231
crate fn compare_impl_method<'tcx>(
3332
tcx: TyCtxt<'tcx>,
3433
impl_m: &ty::AssocItem,
@@ -88,7 +87,7 @@ fn compare_predicate_entailment<'tcx>(
8887
impl_m_span,
8988
impl_m_hir_id,
9089
ObligationCauseCode::CompareImplMethodObligation {
91-
impl_item_def_id: impl_m.def_id,
90+
impl_item_def_id: impl_m.def_id.expect_local(),
9291
trait_item_def_id: trait_m.def_id,
9392
},
9493
);
@@ -231,7 +230,7 @@ fn compare_predicate_entailment<'tcx>(
231230
span,
232231
impl_m_hir_id,
233232
ObligationCauseCode::CompareImplMethodObligation {
234-
impl_item_def_id: impl_m.def_id,
233+
impl_item_def_id: impl_m.def_id.expect_local(),
235234
trait_item_def_id: trait_m.def_id,
236235
},
237236
);
@@ -1154,7 +1153,7 @@ fn compare_type_predicate_entailment<'tcx>(
11541153
impl_ty_span,
11551154
impl_ty_hir_id,
11561155
ObligationCauseCode::CompareImplTypeObligation {
1157-
impl_item_def_id: impl_ty.def_id,
1156+
impl_item_def_id: impl_ty.def_id.expect_local(),
11581157
trait_item_def_id: trait_ty.def_id,
11591158
},
11601159
);
@@ -1383,7 +1382,7 @@ pub fn check_type_bounds<'tcx>(
13831382
impl_ty_span,
13841383
impl_ty_hir_id,
13851384
ObligationCauseCode::CheckAssociatedTypeBounds {
1386-
impl_item_def_id: impl_ty.def_id,
1385+
impl_item_def_id: impl_ty.def_id.expect_local(),
13871386
trait_item_def_id: trait_ty.def_id,
13881387
},
13891388
);

compiler/rustc_typeck/src/check/method/confirm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use super::{probe, MethodCallee};
22

33
use crate::astconv::{AstConv, CreateSubstsForGenericArgsCtxt, IsMethodCall};
44
use crate::check::{callee, FnCtxt};
5-
use crate::hir::def_id::DefId;
6-
use crate::hir::GenericArg;
75
use rustc_hir as hir;
6+
use rustc_hir::def_id::DefId;
7+
use rustc_hir::GenericArg;
88
use rustc_infer::infer::{self, InferOk};
99
use rustc_middle::traits::{ObligationCauseCode, UnifyReceiverContext};
1010
use rustc_middle::ty::adjustment::{Adjust, Adjustment, PointerCast};

0 commit comments

Comments
 (0)