Skip to content

Commit 760673e

Browse files
Remove logic in one_bound in astconv that prefers non-const bounds
1 parent e44b11f commit 760673e

File tree

3 files changed

+13
-45
lines changed

3 files changed

+13
-45
lines changed

compiler/rustc_hir_analysis/src/astconv/mod.rs

+2-33
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
10321032
self.trait_defines_associated_item_named(r.def_id(), assoc_kind, assoc_name)
10331033
});
10341034

1035-
let Some(mut bound) = matching_candidates.next() else {
1035+
let Some(bound) = matching_candidates.next() else {
10361036
let reported = self.complain_about_assoc_item_not_found(
10371037
all_candidates,
10381038
&ty_param_name.to_string(),
@@ -1046,38 +1046,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
10461046
};
10471047
debug!(?bound);
10481048

1049-
// look for a candidate that is not the same as our first bound, disregarding
1050-
// whether the bound is const.
1051-
let mut next_cand = matching_candidates.next();
1052-
while let Some(mut bound2) = next_cand {
1053-
debug!(?bound2);
1054-
if bound2.bound_vars() != bound.bound_vars() {
1055-
break;
1056-
}
1057-
1058-
let generics = tcx.generics_of(bound.def_id());
1059-
let Some(host_index) = generics.host_effect_index else { break };
1060-
1061-
// always return the bound that contains the host param.
1062-
if let ty::ConstKind::Param(_) = bound2.skip_binder().args.const_at(host_index).kind() {
1063-
(bound, bound2) = (bound2, bound);
1064-
}
1065-
1066-
let unconsted_args = bound
1067-
.skip_binder()
1068-
.args
1069-
.iter()
1070-
.enumerate()
1071-
.map(|(n, arg)| if host_index == n { tcx.consts.true_.into() } else { arg });
1072-
1073-
if unconsted_args.eq(bound2.skip_binder().args.iter()) {
1074-
next_cand = matching_candidates.next();
1075-
} else {
1076-
break;
1077-
}
1078-
}
1079-
1080-
if let Some(bound2) = next_cand {
1049+
if let Some(bound2) = matching_candidates.next() {
10811050
debug!(?bound2);
10821051

10831052
let assoc_kind_str = assoc_kind_str(assoc_kind);

tests/ui/rfcs/rfc-2632-const-trait-impl/const-impl-trait.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// known-bug: #110395
2+
// Broken until we have `&T: const Deref` impl in stdlib
3+
24
#![allow(incomplete_features)]
35
#![feature(
46
associated_type_bounds,
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0277]: can't compare `()` with `()`
2-
--> $DIR/const-impl-trait.rs:35:17
2+
--> $DIR/const-impl-trait.rs:37:17
33
|
44
LL | assert!(cmp(&()));
55
| --- ^^^ no implementation for `() == ()`
@@ -9,23 +9,20 @@ LL | assert!(cmp(&()));
99
= help: the trait `const PartialEq` is not implemented for `()`
1010
= help: the trait `PartialEq` is implemented for `()`
1111
note: required by a bound in `cmp`
12-
--> $DIR/const-impl-trait.rs:12:23
12+
--> $DIR/const-impl-trait.rs:14:23
1313
|
1414
LL | const fn cmp(a: &impl ~const PartialEq) -> bool {
1515
| ^^^^^^^^^^^^^^^^ required by this bound in `cmp`
1616

17-
error[E0277]: can't compare `&impl ~const PartialEq` with `&impl ~const PartialEq`
18-
--> $DIR/const-impl-trait.rs:13:7
17+
error[E0369]: binary operation `==` cannot be applied to type `&impl ~const PartialEq`
18+
--> $DIR/const-impl-trait.rs:15:7
1919
|
2020
LL | a == a
21-
| ^^ no implementation for `&impl ~const PartialEq == &impl ~const PartialEq`
22-
|
23-
= help: the trait `~const PartialEq<&impl ~const PartialEq>` is not implemented for `&impl ~const PartialEq`
24-
help: consider dereferencing both sides of the expression
25-
|
26-
LL | *a == *a
27-
| + +
21+
| - ^^ - &impl ~const PartialEq
22+
| |
23+
| &impl ~const PartialEq
2824

2925
error: aborting due to 2 previous errors
3026

31-
For more information about this error, try `rustc --explain E0277`.
27+
Some errors have detailed explanations: E0277, E0369.
28+
For more information about an error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)