Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion compiler/rustc_trait_selection/src/traits/select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,17 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
) => false,

(ParamCandidate(other), ParamCandidate(victim)) => {
if other.value == victim.value && victim.constness == Constness::NotConst {
let value_same_except_bound_vars = other.value.skip_binder()
== victim.value.skip_binder()
&& !other.value.skip_binder().has_escaping_bound_vars();
if value_same_except_bound_vars {
// See issue #84398. In short, we can generate multiple ParamCandidates which are
// the same except for unused bound vars. Just pick the current one (the should
// both evaluate to the same answer). This is probably best characterized as a
// "hack", since we might prefer to just do our best to *not* create essentially
// duplicate candidates in the first place.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we want to pick the one with fewer bound vars? it'd be nice to be more deterministic here

true
} else if other.value == victim.value && victim.constness == Constness::NotConst {
// Drop otherwise equivalent non-const candidates in favor of const candidates.
true
} else {
Expand Down
20 changes: 20 additions & 0 deletions src/test/ui/lifetimes/issue-84398.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// check-pass

pub trait Deserialize<'de>: Sized {}
pub trait DeserializeOwned: for<'de> Deserialize<'de> {}

pub trait Extensible {
type Config;
}

// The `C` here generates a `C: Sized` candidate
pub trait Installer<C> {
fn init<B: Extensible<Config = C>>(&mut self) -> ()
where
// This clause generates a `for<'de> C: Sized` candidate
B::Config: DeserializeOwned,
{
}
}

fn main() {}