Skip to content
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

do not emit overlap errors for impls failing the orphan check #89550

Merged
merged 2 commits 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
13 changes: 8 additions & 5 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,14 @@ rustc_queries! {
desc { "check for overlap between inherent impls defined in this crate" }
}

/// Checks whether all impls in the crate pass the overlap check, returning
/// which impls fail it. If all impls are correct, the returned slice is empty.
query orphan_check_crate(_: ()) -> &'tcx [LocalDefId] {
desc {
"checking whether the immpl in the this crate follow the orphan rules",
}
}

/// Check whether the function has any recursion that could cause the inliner to trigger
/// a cycle. Returns the call stack causing the cycle. The call stack does not contain the
/// current function, just all intermediate functions.
Expand Down Expand Up @@ -1056,11 +1064,6 @@ rustc_queries! {
}

/// Return all `impl` blocks in the current crate.
///
/// To allow caching this between crates, you must pass in [`LOCAL_CRATE`] as the crate number.
/// Passing in any other crate will cause an ICE.
///
/// [`LOCAL_CRATE`]: rustc_hir::def_id::LOCAL_CRATE
query all_local_trait_impls(_: ()) -> &'tcx BTreeMap<DefId, Vec<LocalDefId>> {
desc { "local trait impls" }
}
Expand Down
13 changes: 11 additions & 2 deletions compiler/rustc_trait_selection/src/traits/specialize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,11 @@ pub(super) fn specialization_graph_provider(
sg
}

// This function is only used when
// encountering errors and inlining
// it negatively impacts perf.
#[cold]
#[inline(never)]
fn report_overlap_conflict(
tcx: TyCtxt<'_>,
overlap: OverlapError,
Expand Down Expand Up @@ -443,8 +448,12 @@ fn report_conflicting_impls(
match used_to_be_allowed {
None => {
sg.has_errored = true;
let err = struct_span_err!(tcx.sess, impl_span, E0119, "");
decorate(LintDiagnosticBuilder::new(err));
if overlap.with_impl.is_local() || !tcx.orphan_check_crate(()).contains(&impl_def_id) {
oli-obk marked this conversation as resolved.
Show resolved Hide resolved
let err = struct_span_err!(tcx.sess, impl_span, E0119, "");
decorate(LintDiagnosticBuilder::new(err));
} else {
tcx.sess.delay_span_bug(impl_span, "impl should have failed the orphan check");
}
}
Some(kind) => {
let lint = match kind {
Expand Down
8 changes: 5 additions & 3 deletions compiler/rustc_typeck/src/coherence/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,15 @@ pub fn provide(providers: &mut Providers) {
use self::builtin::coerce_unsized_info;
use self::inherent_impls::{crate_inherent_impls, inherent_impls};
use self::inherent_impls_overlap::crate_inherent_impls_overlap_check;
use self::orphan::orphan_check_crate;

*providers = Providers {
coherent_trait,
crate_inherent_impls,
inherent_impls,
crate_inherent_impls_overlap_check,
coerce_unsized_info,
orphan_check_crate,
..*providers
};
}
Expand All @@ -195,13 +197,13 @@ fn coherent_trait(tcx: TyCtxt<'_>, def_id: DefId) {
}

pub fn check_coherence(tcx: TyCtxt<'_>) {
tcx.sess.time("unsafety_checking", || unsafety::check(tcx));
tcx.ensure().orphan_check_crate(());

for &trait_def_id in tcx.all_local_trait_impls(()).keys() {
tcx.ensure().coherent_trait(trait_def_id);
}

tcx.sess.time("unsafety_checking", || unsafety::check(tcx));
tcx.sess.time("orphan_checking", || orphan::check(tcx));

// these queries are executed for side-effects (error reporting):
tcx.ensure().crate_inherent_impls(());
tcx.ensure().crate_inherent_impls_overlap_check(());
Expand Down
Loading