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

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
@@ -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

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: 4 additions & 5 deletions
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

Lines changed: 4 additions & 3 deletions
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

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)