Skip to content

Commit 69e4f21

Browse files
authored
Rollup merge of #99290 - compiler-errors:revert-98794, r=lcnr
Revert "Highlight conflicting param-env candidates" This reverts #98794, commit 0813525. Seems to have caused an incremental compilation bug. The root cause of the incr comp bug is somewhat unrelated but is triggered by this PR, so I don't feel comfortable with having this PR in the codebase until it can be investigated further. Fixes #99233.
2 parents 02b9701 + 1c8f87e commit 69e4f21

File tree

8 files changed

+19
-114
lines changed

8 files changed

+19
-114
lines changed

Diff for: compiler/rustc_middle/src/traits/mod.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -542,17 +542,9 @@ pub enum SelectionError<'tcx> {
542542
ErrorReporting,
543543
/// Multiple applicable `impl`s where found. The `DefId`s correspond to
544544
/// all the `impl`s' Items.
545-
Ambiguous(Vec<AmbiguousSelection>),
545+
Ambiguous(Vec<DefId>),
546546
}
547547

548-
#[derive(Copy, Clone, Debug)]
549-
pub enum AmbiguousSelection {
550-
Impl(DefId),
551-
ParamEnv(Span),
552-
}
553-
554-
TrivialTypeTraversalAndLiftImpls! { AmbiguousSelection, }
555-
556548
/// When performing resolution, it is typically the case that there
557549
/// can be one of three outcomes:
558550
///

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

+11-30
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use rustc_hir::GenericParam;
2323
use rustc_hir::Item;
2424
use rustc_hir::Node;
2525
use rustc_infer::infer::error_reporting::same_type_modulo_infer;
26-
use rustc_infer::traits::{AmbiguousSelection, TraitEngine};
26+
use rustc_infer::traits::TraitEngine;
2727
use rustc_middle::traits::select::OverflowError;
2828
use rustc_middle::ty::abstract_const::NotConstEvaluatable;
2929
use rustc_middle::ty::error::ExpectedFound;
@@ -1403,7 +1403,7 @@ trait InferCtxtPrivExt<'hir, 'tcx> {
14031403
fn annotate_source_of_ambiguity(
14041404
&self,
14051405
err: &mut Diagnostic,
1406-
impls: &[AmbiguousSelection],
1406+
impls: &[DefId],
14071407
predicate: ty::Predicate<'tcx>,
14081408
);
14091409

@@ -2036,14 +2036,6 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
20362036
);
20372037
match selcx.select_from_obligation(&obligation) {
20382038
Err(SelectionError::Ambiguous(impls)) if impls.len() > 1 => {
2039-
if self.is_tainted_by_errors() && subst.is_none() {
2040-
// If `subst.is_none()`, then this is probably two param-env
2041-
// candidates or impl candidates that are equal modulo lifetimes.
2042-
// Therefore, if we've already emitted an error, just skip this
2043-
// one, since it's not particularly actionable.
2044-
err.cancel();
2045-
return;
2046-
}
20472039
self.annotate_source_of_ambiguity(&mut err, &impls, predicate);
20482040
}
20492041
_ => {
@@ -2224,35 +2216,24 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
22242216
fn annotate_source_of_ambiguity(
22252217
&self,
22262218
err: &mut Diagnostic,
2227-
impls: &[AmbiguousSelection],
2219+
impls: &[DefId],
22282220
predicate: ty::Predicate<'tcx>,
22292221
) {
22302222
let mut spans = vec![];
22312223
let mut crates = vec![];
22322224
let mut post = vec![];
2233-
let mut or_where_clause = false;
2234-
for ambig in impls {
2235-
match ambig {
2236-
AmbiguousSelection::Impl(def_id) => match self.tcx.span_of_impl(*def_id) {
2237-
Ok(span) => spans.push(span),
2238-
Err(name) => {
2239-
crates.push(name);
2240-
if let Some(header) = to_pretty_impl_header(self.tcx, *def_id) {
2241-
post.push(header);
2242-
}
2225+
for def_id in impls {
2226+
match self.tcx.span_of_impl(*def_id) {
2227+
Ok(span) => spans.push(span),
2228+
Err(name) => {
2229+
crates.push(name);
2230+
if let Some(header) = to_pretty_impl_header(self.tcx, *def_id) {
2231+
post.push(header);
22432232
}
2244-
},
2245-
AmbiguousSelection::ParamEnv(span) => {
2246-
or_where_clause = true;
2247-
spans.push(*span);
22482233
}
22492234
}
22502235
}
2251-
let msg = format!(
2252-
"multiple `impl`s{} satisfying `{}` found",
2253-
if or_where_clause { " or `where` clauses" } else { "" },
2254-
predicate
2255-
);
2236+
let msg = format!("multiple `impl`s satisfying `{}` found", predicate);
22562237
let mut crate_names: Vec<_> = crates.iter().map(|n| format!("`{}`", n)).collect();
22572238
crate_names.sort();
22582239
crate_names.dedup();

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

+2-41
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
//!
77
//! [rustc dev guide]:https://rustc-dev-guide.rust-lang.org/traits/resolution.html#candidate-assembly
88
use hir::LangItem;
9-
use rustc_data_structures::fx::FxHashMap;
109
use rustc_hir as hir;
1110
use rustc_hir::def_id::DefId;
12-
use rustc_infer::traits::util::elaborate_predicates_with_span;
13-
use rustc_infer::traits::{AmbiguousSelection, TraitEngine};
11+
use rustc_infer::traits::TraitEngine;
1412
use rustc_infer::traits::{Obligation, SelectionError, TraitObligation};
1513
use rustc_lint_defs::builtin::DEREF_INTO_DYN_SUPERTRAIT;
1614
use rustc_middle::ty::print::with_no_trimmed_paths;
@@ -201,48 +199,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
201199
// and report ambiguity.
202200
if i > 1 {
203201
debug!("multiple matches, ambig");
204-
205-
// Collect a list of (probable) spans that point to a param-env candidate
206-
let tcx = self.infcx.tcx;
207-
let owner = stack.obligation.cause.body_id.owner.to_def_id();
208-
let predicates = tcx.predicates_of(owner).instantiate_identity(tcx);
209-
let param_env_spans: FxHashMap<_, _> = elaborate_predicates_with_span(
210-
tcx,
211-
std::iter::zip(predicates.predicates, predicates.spans),
212-
)
213-
.filter_map(|obligation| {
214-
let kind = obligation.predicate.kind();
215-
if let ty::PredicateKind::Trait(trait_pred) = kind.skip_binder() {
216-
if trait_pred.trait_ref
217-
== ty::TraitRef::identity(tcx, trait_pred.def_id())
218-
.skip_binder()
219-
{
220-
// HACK: Remap the `Self: Trait` predicate that every trait has to a more useful span
221-
Some((
222-
kind.rebind(trait_pred),
223-
tcx.def_span(trait_pred.def_id()),
224-
))
225-
} else {
226-
Some((kind.rebind(trait_pred), obligation.cause.span))
227-
}
228-
} else {
229-
None
230-
}
231-
})
232-
.collect();
233-
234202
return Err(Ambiguous(
235203
candidates
236204
.into_iter()
237205
.filter_map(|c| match c.candidate {
238-
SelectionCandidate::ImplCandidate(def_id) => {
239-
Some(AmbiguousSelection::Impl(def_id))
240-
}
241-
SelectionCandidate::ParamCandidate(predicate) => {
242-
Some(AmbiguousSelection::ParamEnv(
243-
*param_env_spans.get(&predicate)?,
244-
))
245-
}
206+
SelectionCandidate::ImplCandidate(def_id) => Some(def_id),
246207
_ => None,
247208
})
248209
.collect(),

Diff for: src/test/ui/issues/issue-21974.stderr

+1-7
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,7 @@ error[E0283]: type annotations needed: cannot satisfy `&'a T: Foo`
44
LL | where &'a T : Foo,
55
| ^^^
66
|
7-
note: multiple `impl`s or `where` clauses satisfying `&'a T: Foo` found
8-
--> $DIR/issue-21974.rs:11:19
9-
|
10-
LL | where &'a T : Foo,
11-
| ^^^
12-
LL | &'b T : Foo
13-
| ^^^
7+
= note: cannot satisfy `&'a T: Foo`
148

159
error: aborting due to previous error
1610

Diff for: src/test/ui/issues/issue-24424.stderr

+1-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ error[E0283]: type annotations needed: cannot satisfy `T0: Trait0<'l0>`
44
LL | impl <'l0, 'l1, T0> Trait1<'l0, T0> for bool where T0 : Trait0<'l0>, T0 : Trait0<'l1> {}
55
| ^^^^^^^^^^^
66
|
7-
note: multiple `impl`s or `where` clauses satisfying `T0: Trait0<'l0>` found
8-
--> $DIR/issue-24424.rs:4:57
9-
|
10-
LL | impl <'l0, 'l1, T0> Trait1<'l0, T0> for bool where T0 : Trait0<'l0>, T0 : Trait0<'l1> {}
11-
| ^^^^^^^^^^^ ^^^^^^^^^^^
7+
= note: cannot satisfy `T0: Trait0<'l0>`
128

139
error: aborting due to previous error
1410

Diff for: src/test/ui/lifetimes/issue-34979.stderr

+1-7
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,7 @@ error[E0283]: type annotations needed: cannot satisfy `&'a (): Foo`
44
LL | &'a (): Foo,
55
| ^^^
66
|
7-
note: multiple `impl`s or `where` clauses satisfying `&'a (): Foo` found
8-
--> $DIR/issue-34979.rs:6:13
9-
|
10-
LL | &'a (): Foo,
11-
| ^^^
12-
LL | &'static (): Foo;
13-
| ^^^
7+
= note: cannot satisfy `&'a (): Foo`
148

159
error: aborting due to previous error
1610

Diff for: src/test/ui/traits/issue-85735.stderr

+1-8
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,7 @@ error[E0283]: type annotations needed: cannot satisfy `T: FnMut<(&'a (),)>`
44
LL | T: FnMut(&'a ()),
55
| ^^^^^^^^^^^^^
66
|
7-
note: multiple `impl`s or `where` clauses satisfying `T: FnMut<(&'a (),)>` found
8-
--> $DIR/issue-85735.rs:7:8
9-
|
10-
LL | T: FnMut(&'a ()),
11-
| ^^^^^^^^^^^^^
12-
LL |
13-
LL | T: FnMut(&'b ()),
14-
| ^^^^^^^^^^^^^
7+
= note: cannot satisfy `T: FnMut<(&'a (),)>`
158

169
error: aborting due to previous error
1710

Diff for: src/test/ui/type/type-check/issue-40294.stderr

+1-7
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,7 @@ error[E0283]: type annotations needed: cannot satisfy `&'a T: Foo`
44
LL | where &'a T : Foo,
55
| ^^^
66
|
7-
note: multiple `impl`s or `where` clauses satisfying `&'a T: Foo` found
8-
--> $DIR/issue-40294.rs:6:19
9-
|
10-
LL | where &'a T : Foo,
11-
| ^^^
12-
LL | &'b T : Foo
13-
| ^^^
7+
= note: cannot satisfy `&'a T: Foo`
148

159
error: aborting due to previous error
1610

0 commit comments

Comments
 (0)