diff options
| author | Yuki Okushi <huyuumi.dev+love@gmail.com> | 2022-11-01 12:03:42 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-01 12:03:42 +0900 |
| commit | 5bf9d617cb28ac857b9495fdc0df7031ad906eaf (patch) | |
| tree | 0796df05dce717b189913f40a541b678006a46b8 /compiler/rustc_middle/src | |
| parent | 2a6a8f4d307864fcb1d88e6a9c71d481de0f1e6d (diff) | |
| parent | 953727f57474e540315ef16f11ad7dfafdfd9db9 (diff) | |
| download | rust-5bf9d617cb28ac857b9495fdc0df7031ad906eaf.tar.gz rust-5bf9d617cb28ac857b9495fdc0df7031ad906eaf.zip | |
Rollup merge of #103772 - compiler-errors:better-strict-coherence-err, r=davidtwco
better error for `rustc_strict_coherence` misuse Fixes #103753
Diffstat (limited to 'compiler/rustc_middle/src')
| -rw-r--r-- | compiler/rustc_middle/src/error.rs | 9 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/traits/specialization_graph.rs | 17 |
2 files changed, 24 insertions, 2 deletions
diff --git a/compiler/rustc_middle/src/error.rs b/compiler/rustc_middle/src/error.rs index a7a7ac0599d..43903e6739f 100644 --- a/compiler/rustc_middle/src/error.rs +++ b/compiler/rustc_middle/src/error.rs @@ -55,3 +55,12 @@ pub struct ConstEvalNonIntError { #[primary_span] pub span: Span, } + +#[derive(Diagnostic)] +#[diag(middle_strict_coherence_needs_negative_coherence)] +pub(crate) struct StrictCoherenceNeedsNegativeCoherence { + #[primary_span] + pub span: Span, + #[label] + pub attr_span: Option<Span>, +} diff --git a/compiler/rustc_middle/src/traits/specialization_graph.rs b/compiler/rustc_middle/src/traits/specialization_graph.rs index 0a2819feecf..f1c21588261 100644 --- a/compiler/rustc_middle/src/traits/specialization_graph.rs +++ b/compiler/rustc_middle/src/traits/specialization_graph.rs @@ -1,3 +1,4 @@ +use crate::error::StrictCoherenceNeedsNegativeCoherence; use crate::ty::fast_reject::SimplifiedType; use crate::ty::visit::TypeVisitable; use crate::ty::{self, TyCtxt}; @@ -65,9 +66,21 @@ impl OverlapMode { if with_negative_coherence { if strict_coherence { OverlapMode::Strict } else { OverlapMode::WithNegative } - } else if strict_coherence { - bug!("To use strict_coherence you need to set with_negative_coherence feature flag"); } else { + if strict_coherence { + let attr_span = trait_id + .as_local() + .into_iter() + .flat_map(|local_def_id| { + tcx.hir().attrs(tcx.hir().local_def_id_to_hir_id(local_def_id)) + }) + .find(|attr| attr.has_name(sym::rustc_strict_coherence)) + .map(|attr| attr.span); + tcx.sess.emit_err(StrictCoherenceNeedsNegativeCoherence { + span: tcx.def_span(trait_id), + attr_span, + }); + } OverlapMode::Stable } } |
