Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't drop Unsize candidate in intercrate mode #125792

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
param_env: ty::ParamEnv<'tcx>,
cause: &ObligationCause<'tcx>,
) -> Option<ty::PolyExistentialTraitRef<'tcx>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

this function can likely cause a hang. it uses infcx.predicate_may_hold inside of the solver ✨

// Don't drop any candidates in intercrate mode, as it's incomplete.
// (Not that it matters, since `Unsize` is not a stable trait.)
if self.infcx.intercrate {
return None;
}

let tcx = self.tcx();
if tcx.features().trait_upcasting {
return None;
Expand Down
13 changes: 13 additions & 0 deletions tests/ui/specialization/dont-drop-upcast-candidate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#![feature(unsize)]

use std::marker::Unsize;
use std::ops::Deref;

trait Foo: Bar {}
trait Bar {}

impl<T> Bar for T where dyn Foo: Unsize<dyn Bar> {}
impl Bar for () {}
//~^ ERROR conflicting implementations of trait `Bar` for type `()`

fn main() {}
11 changes: 11 additions & 0 deletions tests/ui/specialization/dont-drop-upcast-candidate.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0119]: conflicting implementations of trait `Bar` for type `()`
--> $DIR/dont-drop-upcast-candidate.rs:10:1
|
LL | impl<T> Bar for T where dyn Foo: Unsize<dyn Bar> {}
| ------------------------------------------------ first implementation here
LL | impl Bar for () {}
| ^^^^^^^^^^^^^^^ conflicting implementation for `()`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0119`.
Loading