Skip to content

Commit 1c82fac

Browse files
authored
Rollup merge of #95560 - lcnr:obligation-cause, r=oli-obk
convert more `DefId`s to `LocalDefId`
2 parents 1e43cf4 + 8eacf60 commit 1c82fac

File tree

11 files changed

+51
-45
lines changed

11 files changed

+51
-45
lines changed

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

+2-2
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

+3-3
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

+2-2
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

+7-3
Original file line numberDiff line numberDiff line change
@@ -423,16 +423,20 @@ pub enum SubregionOrigin<'tcx> {
423423

424424
/// Comparing the signature and requirements of an impl method against
425425
/// the containing trait.
426-
CompareImplMethodObligation { span: Span, impl_item_def_id: DefId, trait_item_def_id: DefId },
426+
CompareImplMethodObligation {
427+
span: Span,
428+
impl_item_def_id: LocalDefId,
429+
trait_item_def_id: DefId,
430+
},
427431

428432
/// Comparing the signature and requirements of an impl associated type
429433
/// against the containing trait
430-
CompareImplTypeObligation { span: Span, impl_item_def_id: DefId, trait_item_def_id: DefId },
434+
CompareImplTypeObligation { span: Span, impl_item_def_id: LocalDefId, trait_item_def_id: DefId },
431435

432436
/// Checking that the bounds of a trait's associated type hold for a given impl
433437
CheckAssociatedTypeBounds {
434438
parent: Box<SubregionOrigin<'tcx>>,
435-
impl_item_def_id: DefId,
439+
impl_item_def_id: LocalDefId,
436440
trait_item_def_id: DefId,
437441
},
438442
}

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

+3-3
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

+4-5
Original file line numberDiff line numberDiff line change
@@ -276,24 +276,23 @@ 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

295-
/// Checking that this expression can be assigned where it needs to be
296-
// FIXME(eddyb) #11161 is the original Expr required?
295+
/// Checking that this expression can be assigned to its target.
297296
ExprAssignable,
298297

299298
/// Computing common supertype in the arms of a match expression

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -1913,15 +1913,15 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
19131913
self.suggest_fully_qualified_path(&mut err, def_id, span, trait_ref.def_id());
19141914
} else if let (
19151915
Ok(ref snippet),
1916-
ObligationCauseCode::BindingObligation(ref def_id, _),
1916+
&ObligationCauseCode::BindingObligation(def_id, _),
19171917
) =
19181918
(self.tcx.sess.source_map().span_to_snippet(span), obligation.cause.code())
19191919
{
1920-
let generics = self.tcx.generics_of(*def_id);
1920+
let generics = self.tcx.generics_of(def_id);
19211921
if generics.params.iter().any(|p| p.name != kw::SelfUpper)
19221922
&& !snippet.ends_with('>')
19231923
&& !generics.has_impl_trait()
1924-
&& !self.tcx.fn_trait_kind_from_lang_item(*def_id).is_some()
1924+
&& !self.tcx.fn_trait_kind_from_lang_item(def_id).is_some()
19251925
{
19261926
// FIXME: To avoid spurious suggestions in functions where type arguments
19271927
// where already supplied, we check the snippet to make sure it doesn't
@@ -2223,6 +2223,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
22232223
"suggest_unsized_bound_if_applicable: pred={:?} item_def_id={:?} span={:?}",
22242224
pred, item_def_id, span
22252225
);
2226+
22262227
let (Some(node), true) = (
22272228
self.tcx.hir().get_if_local(item_def_id),
22282229
Some(pred.def_id()) == self.tcx.lang_items().sized_trait(),

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

+4-4
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

+4-5
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

+2-2
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};

compiler/rustc_typeck/src/check/wfcheck.rs

+16-13
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ fn check_associated_item(
940940
item.ident(fcx.tcx).span,
941941
sig,
942942
hir_sig.decl,
943-
item.def_id,
943+
item.def_id.expect_local(),
944944
&mut implied_bounds,
945945
);
946946
check_method_receiver(fcx, hir_sig, item, self_ty);
@@ -1068,7 +1068,7 @@ fn check_type_defn<'tcx, F>(
10681068
}
10691069
}
10701070

1071-
check_where_clauses(fcx, item.span, item.def_id.to_def_id(), None);
1071+
check_where_clauses(fcx, item.span, item.def_id, None);
10721072

10731073
// No implied bounds in a struct definition.
10741074
FxHashSet::default()
@@ -1096,7 +1096,7 @@ fn check_trait(tcx: TyCtxt<'_>, item: &hir::Item<'_>) {
10961096

10971097
// FIXME: this shouldn't use an `FnCtxt` at all.
10981098
for_item(tcx, item).with_fcx(|fcx| {
1099-
check_where_clauses(fcx, item.span, item.def_id.to_def_id(), None);
1099+
check_where_clauses(fcx, item.span, item.def_id, None);
11001100

11011101
FxHashSet::default()
11021102
});
@@ -1144,7 +1144,7 @@ fn check_item_fn(
11441144
for_id(tcx, def_id, span).with_fcx(|fcx| {
11451145
let sig = tcx.fn_sig(def_id);
11461146
let mut implied_bounds = FxHashSet::default();
1147-
check_fn_or_method(fcx, ident.span, sig, decl, def_id.to_def_id(), &mut implied_bounds);
1147+
check_fn_or_method(fcx, ident.span, sig, decl, def_id, &mut implied_bounds);
11481148
implied_bounds
11491149
})
11501150
}
@@ -1238,7 +1238,7 @@ fn check_impl<'tcx>(
12381238
}
12391239
}
12401240

1241-
check_where_clauses(fcx, item.span, item.def_id.to_def_id(), None);
1241+
check_where_clauses(fcx, item.span, item.def_id, None);
12421242

12431243
fcx.impl_implied_bounds(item.def_id.to_def_id(), item.span)
12441244
});
@@ -1249,7 +1249,7 @@ fn check_impl<'tcx>(
12491249
fn check_where_clauses<'tcx, 'fcx>(
12501250
fcx: &FnCtxt<'fcx, 'tcx>,
12511251
span: Span,
1252-
def_id: DefId,
1252+
def_id: LocalDefId,
12531253
return_ty: Option<(Ty<'tcx>, Span)>,
12541254
) {
12551255
let tcx = fcx.tcx;
@@ -1317,7 +1317,7 @@ fn check_where_clauses<'tcx, 'fcx>(
13171317
// For more examples see tests `defaults-well-formedness.rs` and `type-check-defaults.rs`.
13181318
//
13191319
// First we build the defaulted substitution.
1320-
let substs = InternalSubsts::for_item(tcx, def_id, |param, _| {
1320+
let substs = InternalSubsts::for_item(tcx, def_id.to_def_id(), |param, _| {
13211321
match param.kind {
13221322
GenericParamDefKind::Lifetime => {
13231323
// All regions are identity.
@@ -1411,8 +1411,11 @@ fn check_where_clauses<'tcx, 'fcx>(
14111411
// below: there, we are not trying to prove those predicates
14121412
// to be *true* but merely *well-formed*.
14131413
let pred = fcx.normalize_associated_types_in(sp, pred);
1414-
let cause =
1415-
traits::ObligationCause::new(sp, fcx.body_id, traits::ItemObligation(def_id));
1414+
let cause = traits::ObligationCause::new(
1415+
sp,
1416+
fcx.body_id,
1417+
traits::ItemObligation(def_id.to_def_id()),
1418+
);
14161419
traits::Obligation::new(cause, fcx.param_env, pred)
14171420
});
14181421

@@ -1445,10 +1448,10 @@ fn check_fn_or_method<'fcx, 'tcx>(
14451448
span: Span,
14461449
sig: ty::PolyFnSig<'tcx>,
14471450
hir_decl: &hir::FnDecl<'_>,
1448-
def_id: DefId,
1451+
def_id: LocalDefId,
14491452
implied_bounds: &mut FxHashSet<Ty<'tcx>>,
14501453
) {
1451-
let sig = fcx.tcx.liberate_late_bound_regions(def_id, sig);
1454+
let sig = fcx.tcx.liberate_late_bound_regions(def_id.to_def_id(), sig);
14521455

14531456
// Normalize the input and output types one at a time, using a different
14541457
// `WellFormedLoc` for each. We cannot call `normalize_associated_types`
@@ -1462,7 +1465,7 @@ fn check_fn_or_method<'fcx, 'tcx>(
14621465
span,
14631466
ty,
14641467
WellFormedLoc::Param {
1465-
function: def_id.expect_local(),
1468+
function: def_id,
14661469
// Note that the `param_idx` of the output type is
14671470
// one greater than the index of the last input type.
14681471
param_idx: i.try_into().unwrap(),
@@ -1485,7 +1488,7 @@ fn check_fn_or_method<'fcx, 'tcx>(
14851488
input_ty.into(),
14861489
ty.span,
14871490
ObligationCauseCode::WellFormed(Some(WellFormedLoc::Param {
1488-
function: def_id.expect_local(),
1491+
function: def_id,
14891492
param_idx: i.try_into().unwrap(),
14901493
})),
14911494
);

0 commit comments

Comments
 (0)