Skip to content

Commit 0189eeb

Browse files
committed
Resolve to a concrete impl instead of using fuzzy search
1 parent 8e0b68e commit 0189eeb

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -831,18 +831,21 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
831831
);
832832
let mut diag = struct_span_code_err!(self.dcx(), span, E0277, "{}", err_msg);
833833
*diag.long_ty_path() = file;
834-
if !self.predicate_may_hold(&Obligation::new(
834+
let obligation = Obligation::new(
835835
self.tcx,
836836
ObligationCause::dummy(),
837837
param_env,
838838
trait_ref,
839-
)) {
839+
);
840+
if !self.predicate_may_hold(&obligation) {
840841
diag.downgrade_to_delayed_bug();
841842
}
842-
for candidate in self.find_similar_impl_candidates(trait_ref) {
843-
let CandidateSimilarity::Exact { .. } = candidate.similarity else { continue };
844-
let impl_did = candidate.impl_def_id;
845-
let trait_did = candidate.trait_ref.def_id;
843+
844+
if let Ok(Some(ImplSource::UserDefined(impl_data))) =
845+
SelectionContext::new(self).select(&obligation.with(self.tcx, trait_ref.skip_binder()))
846+
{
847+
let impl_did = impl_data.impl_def_id;
848+
let trait_did = trait_ref.def_id();
846849
let impl_span = self.tcx.def_span(impl_did);
847850
let trait_name = self.tcx.item_name(trait_did);
848851

tests/ui/consts/issue-94675.stderr

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,27 @@ error[E0277]: the trait bound `Vec<usize>: [const] Index<_>` is not satisfied
33
|
44
LL | self.bar[0] = baz.len();
55
| ^^^^^^^^^^^
6+
|
7+
note: trait `Index` is implemented but not `const`
8+
--> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
69

710
error[E0277]: the trait bound `Vec<usize>: [const] IndexMut<usize>` is not satisfied
811
--> $DIR/issue-94675.rs:11:9
912
|
1013
LL | self.bar[0] = baz.len();
1114
| ^^^^^^^^^^^
15+
|
16+
note: trait `IndexMut` is implemented but not `const`
17+
--> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
1218

1319
error[E0277]: the trait bound `Vec<usize>: [const] Index<usize>` is not satisfied
1420
--> $DIR/issue-94675.rs:11:9
1521
|
1622
LL | self.bar[0] = baz.len();
1723
| ^^^^^^^^^^^
1824
|
25+
note: trait `Index` is implemented but not `const`
26+
--> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
1927
note: required by a bound in `std::ops::IndexMut::index_mut`
2028
--> $SRC_DIR/core/src/ops/index.rs:LL:COL
2129

tests/ui/traits/const-traits/call-generic-method-fail.stderr

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ error[E0277]: the trait bound `T: [const] PartialEq` is not satisfied
33
|
44
LL | *t == *t
55
| ^^^^^^^^
6-
|
7-
note: trait `PartialEq` is implemented but not `const`
8-
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
9-
note: trait `PartialEq` is implemented but not `const`
10-
--> $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL
116

127
error: aborting due to 1 previous error
138

0 commit comments

Comments
 (0)