Skip to content

Commit 3d29b68

Browse files
committed
Auto merge of rust-lang#90648 - matthewjasper:assoc-item-cleanup, r=cjgillot
Assoc item cleanup This removes some fields from ObligationCauseCode Split out of rust-lang#90639
2 parents d71ba74 + 9734c03 commit 3d29b68

File tree

9 files changed

+29
-62
lines changed

9 files changed

+29
-62
lines changed

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

-2
Original file line numberDiff line numberDiff line change
@@ -2190,14 +2190,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
21902190

21912191
if let Some(SubregionOrigin::CompareImplMethodObligation {
21922192
span,
2193-
item_name,
21942193
impl_item_def_id,
21952194
trait_item_def_id,
21962195
}) = origin
21972196
{
21982197
return self.report_extra_impl_obligation(
21992198
span,
2200-
item_name,
22012199
impl_item_def_id,
22022200
trait_item_def_id,
22032201
&format!("`{}: {}`", bound_kind, sub),

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,16 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
5454
{
5555
if let SubregionOrigin::CompareImplTypeObligation {
5656
span,
57-
item_name,
5857
impl_item_def_id,
5958
trait_item_def_id,
6059
} = origin
6160
{
62-
self.emit_associated_type_err(span, item_name, impl_item_def_id, trait_item_def_id);
61+
self.emit_associated_type_err(
62+
span,
63+
self.infcx.tcx.item_name(impl_item_def_id),
64+
impl_item_def_id,
65+
trait_item_def_id,
66+
);
6367
return Some(ErrorReported);
6468
}
6569
}

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

+15-24
Original file line numberDiff line numberDiff line change
@@ -330,30 +330,21 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
330330
);
331331
err
332332
}
333-
infer::CompareImplMethodObligation {
334-
span,
335-
item_name,
336-
impl_item_def_id,
337-
trait_item_def_id,
338-
} => self.report_extra_impl_obligation(
339-
span,
340-
item_name,
341-
impl_item_def_id,
342-
trait_item_def_id,
343-
&format!("`{}: {}`", sup, sub),
344-
),
345-
infer::CompareImplTypeObligation {
346-
span,
347-
item_name,
348-
impl_item_def_id,
349-
trait_item_def_id,
350-
} => self.report_extra_impl_obligation(
351-
span,
352-
item_name,
353-
impl_item_def_id,
354-
trait_item_def_id,
355-
&format!("`{}: {}`", sup, sub),
356-
),
333+
infer::CompareImplMethodObligation { span, impl_item_def_id, trait_item_def_id } => {
334+
self.report_extra_impl_obligation(
335+
span,
336+
impl_item_def_id,
337+
trait_item_def_id,
338+
&format!("`{}: {}`", sup, sub),
339+
)
340+
}
341+
infer::CompareImplTypeObligation { span, impl_item_def_id, trait_item_def_id } => self
342+
.report_extra_impl_obligation(
343+
span,
344+
impl_item_def_id,
345+
trait_item_def_id,
346+
&format!("`{}: {}`", sup, sub),
347+
),
357348
}
358349
}
359350

compiler/rustc_infer/src/infer/mod.rs

+2-16
Original file line numberDiff line numberDiff line change
@@ -419,21 +419,11 @@ pub enum SubregionOrigin<'tcx> {
419419

420420
/// Comparing the signature and requirements of an impl method against
421421
/// the containing trait.
422-
CompareImplMethodObligation {
423-
span: Span,
424-
item_name: Symbol,
425-
impl_item_def_id: DefId,
426-
trait_item_def_id: DefId,
427-
},
422+
CompareImplMethodObligation { span: Span, impl_item_def_id: DefId, trait_item_def_id: DefId },
428423

429424
/// Comparing the signature and requirements of an impl associated type
430425
/// against the containing trait
431-
CompareImplTypeObligation {
432-
span: Span,
433-
item_name: Symbol,
434-
impl_item_def_id: DefId,
435-
trait_item_def_id: DefId,
436-
},
426+
CompareImplTypeObligation { span: Span, impl_item_def_id: DefId, trait_item_def_id: DefId },
437427
}
438428

439429
// `SubregionOrigin` is used a lot. Make sure it doesn't unintentionally get bigger.
@@ -1830,23 +1820,19 @@ impl<'tcx> SubregionOrigin<'tcx> {
18301820
}
18311821

18321822
traits::ObligationCauseCode::CompareImplMethodObligation {
1833-
item_name,
18341823
impl_item_def_id,
18351824
trait_item_def_id,
18361825
} => SubregionOrigin::CompareImplMethodObligation {
18371826
span: cause.span,
1838-
item_name,
18391827
impl_item_def_id,
18401828
trait_item_def_id,
18411829
},
18421830

18431831
traits::ObligationCauseCode::CompareImplTypeObligation {
1844-
item_name,
18451832
impl_item_def_id,
18461833
trait_item_def_id,
18471834
} => SubregionOrigin::CompareImplTypeObligation {
18481835
span: cause.span,
1849-
item_name,
18501836
impl_item_def_id,
18511837
trait_item_def_id,
18521838
},

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use rustc_errors::{struct_span_err, DiagnosticBuilder};
66
use rustc_hir as hir;
77
use rustc_hir::def_id::DefId;
88
use rustc_middle::ty::TyCtxt;
9-
use rustc_span::symbol::Symbol;
109
use rustc_span::{MultiSpan, Span};
1110
use std::fmt;
1211
use std::iter;
@@ -15,8 +14,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1514
pub fn report_extra_impl_obligation(
1615
&self,
1716
error_span: Span,
18-
item_name: Symbol,
19-
_impl_item_def_id: DefId,
17+
impl_item_def_id: DefId,
2018
trait_item_def_id: DefId,
2119
requirement: &dyn fmt::Display,
2220
) -> DiagnosticBuilder<'tcx> {
@@ -27,6 +25,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
2725

2826
if let Some(trait_item_span) = self.tcx.hir().span_if_local(trait_item_def_id) {
2927
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);
3029
err.span_label(span, format!("definition of `{}` from trait", item_name));
3130
}
3231

compiler/rustc_middle/src/traits/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,12 @@ pub enum ObligationCauseCode<'tcx> {
267267

268268
/// Error derived when matching traits/impls; see ObligationCause for more details
269269
CompareImplMethodObligation {
270-
item_name: Symbol,
271270
impl_item_def_id: DefId,
272271
trait_item_def_id: DefId,
273272
},
274273

275274
/// Error derived when matching traits/impls; see ObligationCause for more details
276275
CompareImplTypeObligation {
277-
item_name: Symbol,
278276
impl_item_def_id: DefId,
279277
trait_item_def_id: DefId,
280278
},

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

-3
Original file line numberDiff line numberDiff line change
@@ -266,19 +266,16 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
266266
}
267267
}
268268
if let ObligationCauseCode::CompareImplMethodObligation {
269-
item_name,
270269
impl_item_def_id,
271270
trait_item_def_id,
272271
}
273272
| ObligationCauseCode::CompareImplTypeObligation {
274-
item_name,
275273
impl_item_def_id,
276274
trait_item_def_id,
277275
} = obligation.cause.code
278276
{
279277
self.report_extra_impl_obligation(
280278
span,
281-
item_name,
282279
impl_item_def_id,
283280
trait_item_def_id,
284281
&format!("`{}`", obligation.predicate),

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

+4-8
Original file line numberDiff line numberDiff line change
@@ -2354,11 +2354,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
23542354
)
23552355
});
23562356
}
2357-
ObligationCauseCode::CompareImplMethodObligation {
2358-
item_name,
2359-
trait_item_def_id,
2360-
..
2361-
} => {
2357+
ObligationCauseCode::CompareImplMethodObligation { trait_item_def_id, .. } => {
2358+
let item_name = self.tcx.item_name(trait_item_def_id);
23622359
let msg = format!(
23632360
"the requirement `{}` appears on the impl method `{}` but not on the \
23642361
corresponding trait method",
@@ -2383,9 +2380,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
23832380
}
23842381
err.span_note(assoc_span, &msg);
23852382
}
2386-
ObligationCauseCode::CompareImplTypeObligation {
2387-
item_name, trait_item_def_id, ..
2388-
} => {
2383+
ObligationCauseCode::CompareImplTypeObligation { trait_item_def_id, .. } => {
2384+
let item_name = self.tcx.item_name(trait_item_def_id);
23892385
let msg = format!(
23902386
"the requirement `{}` appears on the associated impl type `{}` but not on the \
23912387
corresponding associated trait type",

compiler/rustc_typeck/src/check/compare_method.rs

-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ fn compare_predicate_entailment<'tcx>(
9292
impl_m_span,
9393
impl_m_hir_id,
9494
ObligationCauseCode::CompareImplMethodObligation {
95-
item_name: impl_m.ident.name,
9695
impl_item_def_id: impl_m.def_id,
9796
trait_item_def_id: trait_m.def_id,
9897
},
@@ -1167,7 +1166,6 @@ fn compare_type_predicate_entailment<'tcx>(
11671166
impl_ty_span,
11681167
impl_ty_hir_id,
11691168
ObligationCauseCode::CompareImplTypeObligation {
1170-
item_name: impl_ty.ident.name,
11711169
impl_item_def_id: impl_ty.def_id,
11721170
trait_item_def_id: trait_ty.def_id,
11731171
},

0 commit comments

Comments
 (0)