Skip to content

Commit

Permalink
Remove logic in one_bound in astconv that prefers non-const bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Jan 8, 2024
1 parent e44b11f commit 760673e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 45 deletions.
35 changes: 2 additions & 33 deletions compiler/rustc_hir_analysis/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
self.trait_defines_associated_item_named(r.def_id(), assoc_kind, assoc_name)
});

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

// look for a candidate that is not the same as our first bound, disregarding
// whether the bound is const.
let mut next_cand = matching_candidates.next();
while let Some(mut bound2) = next_cand {
debug!(?bound2);
if bound2.bound_vars() != bound.bound_vars() {
break;
}

let generics = tcx.generics_of(bound.def_id());
let Some(host_index) = generics.host_effect_index else { break };

// always return the bound that contains the host param.
if let ty::ConstKind::Param(_) = bound2.skip_binder().args.const_at(host_index).kind() {
(bound, bound2) = (bound2, bound);
}

let unconsted_args = bound
.skip_binder()
.args
.iter()
.enumerate()
.map(|(n, arg)| if host_index == n { tcx.consts.true_.into() } else { arg });

if unconsted_args.eq(bound2.skip_binder().args.iter()) {
next_cand = matching_candidates.next();
} else {
break;
}
}

if let Some(bound2) = next_cand {
if let Some(bound2) = matching_candidates.next() {
debug!(?bound2);

let assoc_kind_str = assoc_kind_str(assoc_kind);
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/rfcs/rfc-2632-const-trait-impl/const-impl-trait.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// known-bug: #110395
// Broken until we have `&T: const Deref` impl in stdlib

#![allow(incomplete_features)]
#![feature(
associated_type_bounds,
Expand Down
21 changes: 9 additions & 12 deletions tests/ui/rfcs/rfc-2632-const-trait-impl/const-impl-trait.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0277]: can't compare `()` with `()`
--> $DIR/const-impl-trait.rs:35:17
--> $DIR/const-impl-trait.rs:37:17
|
LL | assert!(cmp(&()));
| --- ^^^ no implementation for `() == ()`
Expand All @@ -9,23 +9,20 @@ LL | assert!(cmp(&()));
= help: the trait `const PartialEq` is not implemented for `()`
= help: the trait `PartialEq` is implemented for `()`
note: required by a bound in `cmp`
--> $DIR/const-impl-trait.rs:12:23
--> $DIR/const-impl-trait.rs:14:23
|
LL | const fn cmp(a: &impl ~const PartialEq) -> bool {
| ^^^^^^^^^^^^^^^^ required by this bound in `cmp`

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

error: aborting due to 2 previous errors

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

0 comments on commit 760673e

Please sign in to comment.