|
1 | 1 | use rustc_data_structures::fx::FxIndexMap; |
2 | 2 | use rustc_errors::ErrorGuaranteed; |
| 3 | +use rustc_hir::attrs::AttributeKind; |
3 | 4 | use rustc_hir::def_id::{DefId, DefIdMap}; |
| 5 | +use rustc_hir::find_attr; |
4 | 6 | use rustc_macros::{HashStable, TyDecodable, TyEncodable}; |
5 | | -use rustc_span::sym; |
6 | 7 |
|
7 | 8 | use crate::error::StrictCoherenceNeedsNegativeCoherence; |
8 | 9 | use crate::ty::fast_reject::SimplifiedType; |
@@ -61,23 +62,15 @@ pub enum OverlapMode { |
61 | 62 | impl OverlapMode { |
62 | 63 | pub fn get(tcx: TyCtxt<'_>, trait_id: DefId) -> OverlapMode { |
63 | 64 | let with_negative_coherence = tcx.features().with_negative_coherence(); |
64 | | - let strict_coherence = tcx.has_attr(trait_id, sym::rustc_strict_coherence); |
| 65 | + let strict_coherence = find_attr!(tcx.get_all_attrs(trait_id), AttributeKind::RustcStrictCoherence(span) => *span); |
65 | 66 |
|
66 | 67 | if with_negative_coherence { |
67 | | - if strict_coherence { OverlapMode::Strict } else { OverlapMode::WithNegative } |
| 68 | + if strict_coherence.is_some() { OverlapMode::Strict } else { OverlapMode::WithNegative } |
68 | 69 | } else { |
69 | | - if strict_coherence { |
70 | | - let attr_span = trait_id |
71 | | - .as_local() |
72 | | - .into_iter() |
73 | | - .flat_map(|local_def_id| { |
74 | | - tcx.hir_attrs(tcx.local_def_id_to_hir_id(local_def_id)) |
75 | | - }) |
76 | | - .find(|attr| attr.has_name(sym::rustc_strict_coherence)) |
77 | | - .map(|attr| attr.span()); |
| 70 | + if let Some(span) = strict_coherence { |
78 | 71 | tcx.dcx().emit_err(StrictCoherenceNeedsNegativeCoherence { |
79 | 72 | span: tcx.def_span(trait_id), |
80 | | - attr_span, |
| 73 | + attr_span: span, |
81 | 74 | }); |
82 | 75 | } |
83 | 76 | OverlapMode::Stable |
|
0 commit comments