Auto merge of #119879 - matthiaskrgr:rollup-y710der, r=matthiaskrgr

Rollup of 4 pull requests

Successful merges:

 - #119781 (fix typo)
 - #119865 (Set `c_str_literals` stabilization version back to `CURRENT_RUSTC_VERSION`)
 - #119866 (Convert `effects` description to doc comment)
 - #119868 (Register even erroneous impls)

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2024-01-12 09:11:57 +00:00
commit bfd799f1a5
12 changed files with 190 additions and 54 deletions

View file

@ -26,7 +26,7 @@ use rustc_middle::ty::{self, ImplSubject, Ty, TyCtxt, TypeVisitableExt};
use rustc_middle::ty::{GenericArgs, GenericArgsRef};
use rustc_session::lint::builtin::COHERENCE_LEAK_CHECK;
use rustc_session::lint::builtin::ORDER_DEPENDENT_TRAIT_OBJECTS;
use rustc_span::{Span, DUMMY_SP};
use rustc_span::{ErrorGuaranteed, Span, DUMMY_SP};
use super::util;
use super::SelectionContext;
@ -258,7 +258,7 @@ fn fulfill_implication<'tcx>(
pub(super) fn specialization_graph_provider(
tcx: TyCtxt<'_>,
trait_id: DefId,
) -> specialization_graph::Graph {
) -> Result<&'_ specialization_graph::Graph, ErrorGuaranteed> {
let mut sg = specialization_graph::Graph::new();
let overlap_mode = specialization_graph::OverlapMode::get(tcx, trait_id);
@ -271,6 +271,8 @@ pub(super) fn specialization_graph_provider(
trait_impls
.sort_unstable_by_key(|def_id| (-(def_id.krate.as_u32() as i64), def_id.index.index()));
let mut errored = Ok(());
for impl_def_id in trait_impls {
if let Some(impl_def_id) = impl_def_id.as_local() {
// This is where impl overlap checking happens:
@ -283,15 +285,21 @@ pub(super) fn specialization_graph_provider(
};
if let Some(overlap) = overlap {
report_overlap_conflict(tcx, overlap, impl_def_id, used_to_be_allowed, &mut sg);
errored = errored.and(report_overlap_conflict(
tcx,
overlap,
impl_def_id,
used_to_be_allowed,
));
}
} else {
let parent = tcx.impl_parent(impl_def_id).unwrap_or(trait_id);
sg.record_impl_from_cstore(tcx, parent, impl_def_id)
}
}
errored?;
sg
Ok(tcx.arena.alloc(sg))
}
// This function is only used when
@ -304,36 +312,31 @@ fn report_overlap_conflict<'tcx>(
overlap: OverlapError<'tcx>,
impl_def_id: LocalDefId,
used_to_be_allowed: Option<FutureCompatOverlapErrorKind>,
sg: &mut specialization_graph::Graph,
) {
) -> Result<(), ErrorGuaranteed> {
let impl_polarity = tcx.impl_polarity(impl_def_id.to_def_id());
let other_polarity = tcx.impl_polarity(overlap.with_impl);
match (impl_polarity, other_polarity) {
(ty::ImplPolarity::Negative, ty::ImplPolarity::Positive) => {
report_negative_positive_conflict(
Err(report_negative_positive_conflict(
tcx,
&overlap,
impl_def_id,
impl_def_id.to_def_id(),
overlap.with_impl,
sg,
);
))
}
(ty::ImplPolarity::Positive, ty::ImplPolarity::Negative) => {
report_negative_positive_conflict(
Err(report_negative_positive_conflict(
tcx,
&overlap,
impl_def_id,
overlap.with_impl,
impl_def_id.to_def_id(),
sg,
);
))
}
_ => {
report_conflicting_impls(tcx, overlap, impl_def_id, used_to_be_allowed, sg);
}
_ => report_conflicting_impls(tcx, overlap, impl_def_id, used_to_be_allowed),
}
}
@ -343,16 +346,16 @@ fn report_negative_positive_conflict<'tcx>(
local_impl_def_id: LocalDefId,
negative_impl_def_id: DefId,
positive_impl_def_id: DefId,
sg: &mut specialization_graph::Graph,
) {
let err = tcx.dcx().create_err(NegativePositiveConflict {
impl_span: tcx.def_span(local_impl_def_id),
trait_desc: overlap.trait_ref,
self_ty: overlap.self_ty,
negative_impl_span: tcx.span_of_impl(negative_impl_def_id),
positive_impl_span: tcx.span_of_impl(positive_impl_def_id),
});
sg.has_errored = Some(err.emit());
) -> ErrorGuaranteed {
tcx.dcx()
.create_err(NegativePositiveConflict {
impl_span: tcx.def_span(local_impl_def_id),
trait_desc: overlap.trait_ref,
self_ty: overlap.self_ty,
negative_impl_span: tcx.span_of_impl(negative_impl_def_id),
positive_impl_span: tcx.span_of_impl(positive_impl_def_id),
})
.emit()
}
fn report_conflicting_impls<'tcx>(
@ -360,8 +363,7 @@ fn report_conflicting_impls<'tcx>(
overlap: OverlapError<'tcx>,
impl_def_id: LocalDefId,
used_to_be_allowed: Option<FutureCompatOverlapErrorKind>,
sg: &mut specialization_graph::Graph,
) {
) -> Result<(), ErrorGuaranteed> {
let impl_span = tcx.def_span(impl_def_id);
// Work to be done after we've built the DiagnosticBuilder. We have to define it
@ -429,14 +431,11 @@ fn report_conflicting_impls<'tcx>(
let mut err = tcx.dcx().struct_span_err(impl_span, msg);
err.code(error_code!(E0119));
decorate(tcx, &overlap, impl_span, &mut err);
Some(err.emit())
err.emit()
} else {
Some(
tcx.dcx()
.span_delayed_bug(impl_span, "impl should have failed the orphan check"),
)
tcx.dcx().span_delayed_bug(impl_span, "impl should have failed the orphan check")
};
sg.has_errored = reported;
Err(reported)
}
Some(kind) => {
let lint = match kind {
@ -452,8 +451,9 @@ fn report_conflicting_impls<'tcx>(
decorate(tcx, &overlap, impl_span, err);
},
);
Ok(())
}
};
}
}
/// Recovers the "impl X for Y" signature from `impl_def_id` and returns it as a