Skip to content

Commit 1c8f87e

Browse files
Revert "Highlight conflicting param-env candidates"
This reverts commit 0813525.
1 parent 0fe5390 commit 1c8f87e

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
@@ -541,17 +541,9 @@ pub enum SelectionError<'tcx> {
541541
ErrorReporting,
542542
/// Multiple applicable `impl`s where found. The `DefId`s correspond to
543543
/// all the `impl`s' Items.
544-
Ambiguous(Vec<AmbiguousSelection>),
544+
Ambiguous(Vec<DefId>),
545545
}
546546

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

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;
@@ -1402,7 +1402,7 @@ trait InferCtxtPrivExt<'hir, 'tcx> {
14021402
fn annotate_source_of_ambiguity(
14031403
&self,
14041404
err: &mut Diagnostic,
1405-
impls: &[AmbiguousSelection],
1405+
impls: &[DefId],
14061406
predicate: ty::Predicate<'tcx>,
14071407
);
14081408

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