Skip to content

Commit 16d0d0b

Browse files
authored
Rollup merge of #99095 - rhysd:issue-99092, r=compiler-errors
Remove duplicate notes from error on inter-crate ambiguous impl of traits Fixes #99092
2 parents 342b666 + d5aed20 commit 16d0d0b

File tree

7 files changed

+45
-13
lines changed

7 files changed

+45
-13
lines changed

Diff for: compiler/rustc_trait_selection/src/traits/coherence.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::traits::{
1313
self, FulfillmentContext, Normalized, Obligation, ObligationCause, PredicateObligation,
1414
PredicateObligations, SelectionContext,
1515
};
16-
//use rustc_data_structures::fx::FxHashMap;
16+
use rustc_data_structures::fx::FxIndexSet;
1717
use rustc_errors::Diagnostic;
1818
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
1919
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
@@ -44,7 +44,7 @@ pub enum Conflict {
4444

4545
pub struct OverlapResult<'tcx> {
4646
pub impl_header: ty::ImplHeader<'tcx>,
47-
pub intercrate_ambiguity_causes: Vec<IntercrateAmbiguityCause>,
47+
pub intercrate_ambiguity_causes: FxIndexSet<IntercrateAmbiguityCause>,
4848

4949
/// `true` if the overlap might've been permitted before the shift
5050
/// to universes.

Diff for: compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
110110
IntercrateAmbiguityCause::DownstreamCrate { trait_desc, self_desc }
111111
};
112112
debug!(?cause, "evaluate_stack: pushing cause");
113-
self.intercrate_ambiguity_causes.as_mut().unwrap().push(cause);
113+
self.intercrate_ambiguity_causes.as_mut().unwrap().insert(cause);
114114
}
115115
}
116116
}

Diff for: compiler/rustc_trait_selection/src/traits/select/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::traits::error_reporting::InferCtxtExt;
2424
use crate::traits::project::ProjectAndUnifyResult;
2525
use crate::traits::project::ProjectionCacheKeyExt;
2626
use crate::traits::ProjectionCacheKey;
27-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
27+
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
2828
use rustc_data_structures::stack::ensure_sufficient_stack;
2929
use rustc_errors::{Diagnostic, ErrorGuaranteed};
3030
use rustc_hir as hir;
@@ -52,7 +52,7 @@ pub use rustc_middle::traits::select::*;
5252
mod candidate_assembly;
5353
mod confirmation;
5454

55-
#[derive(Clone, Debug)]
55+
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
5656
pub enum IntercrateAmbiguityCause {
5757
DownstreamCrate { trait_desc: String, self_desc: Option<String> },
5858
UpstreamCrateUpdate { trait_desc: String, self_desc: Option<String> },
@@ -128,7 +128,7 @@ pub struct SelectionContext<'cx, 'tcx> {
128128
/// We don't do his until we detect a coherence error because it can
129129
/// lead to false overflow results (#47139) and because always
130130
/// computing it may negatively impact performance.
131-
intercrate_ambiguity_causes: Option<Vec<IntercrateAmbiguityCause>>,
131+
intercrate_ambiguity_causes: Option<FxIndexSet<IntercrateAmbiguityCause>>,
132132

133133
/// The mode that trait queries run in, which informs our error handling
134134
/// policy. In essence, canonicalized queries need their errors propagated
@@ -254,14 +254,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
254254
pub fn enable_tracking_intercrate_ambiguity_causes(&mut self) {
255255
assert!(self.intercrate);
256256
assert!(self.intercrate_ambiguity_causes.is_none());
257-
self.intercrate_ambiguity_causes = Some(vec![]);
257+
self.intercrate_ambiguity_causes = Some(FxIndexSet::default());
258258
debug!("selcx: enable_tracking_intercrate_ambiguity_causes");
259259
}
260260

261261
/// Gets the intercrate ambiguity causes collected since tracking
262262
/// was enabled and disables tracking at the same time. If
263263
/// tracking is not enabled, just returns an empty vector.
264-
pub fn take_intercrate_ambiguity_causes(&mut self) -> Vec<IntercrateAmbiguityCause> {
264+
pub fn take_intercrate_ambiguity_causes(&mut self) -> FxIndexSet<IntercrateAmbiguityCause> {
265265
assert!(self.intercrate);
266266
self.intercrate_ambiguity_causes.take().unwrap_or_default()
267267
}
@@ -960,7 +960,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
960960
});
961961

962962
debug!(?cause, "evaluate_stack: pushing cause");
963-
self.intercrate_ambiguity_causes.as_mut().unwrap().push(cause);
963+
self.intercrate_ambiguity_causes.as_mut().unwrap().insert(cause);
964964
}
965965
}
966966
}
@@ -1252,7 +1252,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
12521252
reservation impl ambiguity on {:?}",
12531253
def_id
12541254
);
1255-
intercrate_ambiguity_clauses.push(
1255+
intercrate_ambiguity_clauses.insert(
12561256
IntercrateAmbiguityCause::ReservationImpl {
12571257
message: value.to_string(),
12581258
},

Diff for: compiler/rustc_trait_selection/src/traits/specialize/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use specialization_graph::GraphExt;
1515
use crate::infer::{InferCtxt, InferOk, TyCtxtInferExt};
1616
use crate::traits::select::IntercrateAmbiguityCause;
1717
use crate::traits::{self, coherence, FutureCompatOverlapErrorKind, ObligationCause, TraitEngine};
18-
use rustc_data_structures::fx::FxHashSet;
18+
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
1919
use rustc_errors::{struct_span_err, EmissionGuarantee, LintDiagnosticBuilder};
2020
use rustc_hir::def_id::{DefId, LocalDefId};
2121
use rustc_middle::ty::subst::{InternalSubsts, Subst, SubstsRef};
@@ -33,7 +33,7 @@ pub struct OverlapError {
3333
pub with_impl: DefId,
3434
pub trait_desc: String,
3535
pub self_desc: Option<String>,
36-
pub intercrate_ambiguity_causes: Vec<IntercrateAmbiguityCause>,
36+
pub intercrate_ambiguity_causes: FxIndexSet<IntercrateAmbiguityCause>,
3737
pub involves_placeholder: bool,
3838
}
3939

Diff for: src/test/ui/coherence/coherence-projection-conflict-orphan.stderr

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ LL | impl<A:Iterator> Foo<A::Item> for A { }
88
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `i32`
99
|
1010
= note: upstream crates may add a new impl of trait `std::iter::Iterator` for type `i32` in future versions
11-
= note: upstream crates may add a new impl of trait `std::iter::Iterator` for type `i32` in future versions
1211

1312
error: aborting due to previous error
1413

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
struct S;
2+
3+
impl From<()> for S {
4+
fn from(x: ()) -> Self {
5+
S
6+
}
7+
}
8+
9+
impl<I> From<I> for S
10+
//~^ ERROR conflicting implementations of trait
11+
where
12+
I: Iterator<Item = ()>,
13+
{
14+
fn from(x: I) -> Self {
15+
S
16+
}
17+
}
18+
19+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0119]: conflicting implementations of trait `std::convert::From<()>` for type `S`
2+
--> $DIR/inter-crate-ambiguity-causes-notes.rs:9:1
3+
|
4+
LL | impl From<()> for S {
5+
| ------------------- first implementation here
6+
...
7+
LL | impl<I> From<I> for S
8+
| ^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `S`
9+
|
10+
= note: upstream crates may add a new impl of trait `std::iter::Iterator` for type `()` in future versions
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0119`.

0 commit comments

Comments
 (0)