Skip to content

Assoc item cleanup #90648

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2190,14 +2190,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {

if let Some(SubregionOrigin::CompareImplMethodObligation {
span,
item_name,
impl_item_def_id,
trait_item_def_id,
}) = origin
{
return self.report_extra_impl_obligation(
span,
item_name,
impl_item_def_id,
trait_item_def_id,
&format!("`{}: {}`", bound_kind, sub),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,16 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
{
if let SubregionOrigin::CompareImplTypeObligation {
span,
item_name,
impl_item_def_id,
trait_item_def_id,
} = origin
{
self.emit_associated_type_err(span, item_name, impl_item_def_id, trait_item_def_id);
self.emit_associated_type_err(
span,
self.infcx.tcx.item_name(impl_item_def_id),
impl_item_def_id,
trait_item_def_id,
);
return Some(ErrorReported);
}
}
Expand Down
39 changes: 15 additions & 24 deletions compiler/rustc_infer/src/infer/error_reporting/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,30 +330,21 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
);
err
}
infer::CompareImplMethodObligation {
span,
item_name,
impl_item_def_id,
trait_item_def_id,
} => self.report_extra_impl_obligation(
span,
item_name,
impl_item_def_id,
trait_item_def_id,
&format!("`{}: {}`", sup, sub),
),
infer::CompareImplTypeObligation {
span,
item_name,
impl_item_def_id,
trait_item_def_id,
} => self.report_extra_impl_obligation(
span,
item_name,
impl_item_def_id,
trait_item_def_id,
&format!("`{}: {}`", sup, sub),
),
infer::CompareImplMethodObligation { span, impl_item_def_id, trait_item_def_id } => {
self.report_extra_impl_obligation(
span,
impl_item_def_id,
trait_item_def_id,
&format!("`{}: {}`", sup, sub),
)
}
infer::CompareImplTypeObligation { span, impl_item_def_id, trait_item_def_id } => self
.report_extra_impl_obligation(
span,
impl_item_def_id,
trait_item_def_id,
&format!("`{}: {}`", sup, sub),
),
}
}

Expand Down
18 changes: 2 additions & 16 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,21 +419,11 @@ pub enum SubregionOrigin<'tcx> {

/// Comparing the signature and requirements of an impl method against
/// the containing trait.
CompareImplMethodObligation {
span: Span,
item_name: Symbol,
impl_item_def_id: DefId,
trait_item_def_id: DefId,
},
CompareImplMethodObligation { span: Span, impl_item_def_id: DefId, trait_item_def_id: DefId },

/// Comparing the signature and requirements of an impl associated type
/// against the containing trait
CompareImplTypeObligation {
span: Span,
item_name: Symbol,
impl_item_def_id: DefId,
trait_item_def_id: DefId,
},
CompareImplTypeObligation { span: Span, impl_item_def_id: DefId, trait_item_def_id: DefId },
}

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

traits::ObligationCauseCode::CompareImplMethodObligation {
item_name,
impl_item_def_id,
trait_item_def_id,
} => SubregionOrigin::CompareImplMethodObligation {
span: cause.span,
item_name,
impl_item_def_id,
trait_item_def_id,
},

traits::ObligationCauseCode::CompareImplTypeObligation {
item_name,
impl_item_def_id,
trait_item_def_id,
} => SubregionOrigin::CompareImplTypeObligation {
span: cause.span,
item_name,
impl_item_def_id,
trait_item_def_id,
},
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_infer/src/traits/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use rustc_errors::{struct_span_err, DiagnosticBuilder};
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_middle::ty::TyCtxt;
use rustc_span::symbol::Symbol;
use rustc_span::{MultiSpan, Span};
use std::fmt;
use std::iter;
Expand All @@ -15,8 +14,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
pub fn report_extra_impl_obligation(
&self,
error_span: Span,
item_name: Symbol,
_impl_item_def_id: DefId,
impl_item_def_id: DefId,
trait_item_def_id: DefId,
requirement: &dyn fmt::Display,
) -> DiagnosticBuilder<'tcx> {
Expand All @@ -27,6 +25,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {

if let Some(trait_item_span) = self.tcx.hir().span_if_local(trait_item_def_id) {
let span = self.tcx.sess.source_map().guess_head_span(trait_item_span);
let item_name = self.tcx.item_name(impl_item_def_id);
err.span_label(span, format!("definition of `{}` from trait", item_name));
}

Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_middle/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,12 @@ pub enum ObligationCauseCode<'tcx> {

/// Error derived when matching traits/impls; see ObligationCause for more details
CompareImplMethodObligation {
item_name: Symbol,
impl_item_def_id: DefId,
trait_item_def_id: DefId,
},

/// Error derived when matching traits/impls; see ObligationCause for more details
CompareImplTypeObligation {
item_name: Symbol,
impl_item_def_id: DefId,
trait_item_def_id: DefId,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,19 +266,16 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
}
}
if let ObligationCauseCode::CompareImplMethodObligation {
item_name,
impl_item_def_id,
trait_item_def_id,
}
| ObligationCauseCode::CompareImplTypeObligation {
item_name,
impl_item_def_id,
trait_item_def_id,
} = obligation.cause.code
{
self.report_extra_impl_obligation(
span,
item_name,
impl_item_def_id,
trait_item_def_id,
&format!("`{}`", obligation.predicate),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2354,11 +2354,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
)
});
}
ObligationCauseCode::CompareImplMethodObligation {
item_name,
trait_item_def_id,
..
} => {
ObligationCauseCode::CompareImplMethodObligation { trait_item_def_id, .. } => {
let item_name = self.tcx.item_name(trait_item_def_id);
let msg = format!(
"the requirement `{}` appears on the impl method `{}` but not on the \
corresponding trait method",
Expand All @@ -2383,9 +2380,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
}
err.span_note(assoc_span, &msg);
}
ObligationCauseCode::CompareImplTypeObligation {
item_name, trait_item_def_id, ..
} => {
ObligationCauseCode::CompareImplTypeObligation { trait_item_def_id, .. } => {
let item_name = self.tcx.item_name(trait_item_def_id);
let msg = format!(
"the requirement `{}` appears on the associated impl type `{}` but not on the \
corresponding associated trait type",
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_typeck/src/check/compare_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ fn compare_predicate_entailment<'tcx>(
impl_m_span,
impl_m_hir_id,
ObligationCauseCode::CompareImplMethodObligation {
item_name: impl_m.ident.name,
impl_item_def_id: impl_m.def_id,
trait_item_def_id: trait_m.def_id,
},
Expand Down Expand Up @@ -1164,7 +1163,6 @@ fn compare_type_predicate_entailment<'tcx>(
impl_ty_span,
impl_ty_hir_id,
ObligationCauseCode::CompareImplTypeObligation {
item_name: impl_ty.ident.name,
impl_item_def_id: impl_ty.def_id,
trait_item_def_id: trait_ty.def_id,
},
Expand Down