Skip to content

Commit 97c11ff

Browse files
Strongly prefer alias and param-env bounds
1 parent a2d806d commit 97c11ff

8 files changed

+78
-32
lines changed

compiler/rustc_trait_selection/src/solve/assembly/mod.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
33
use super::search_graph::OverflowHandler;
44
use super::{EvalCtxt, SolverMode};
5-
use crate::solve::CanonicalResponseExt;
65
use crate::traits::coherence;
76
use rustc_data_structures::fx::FxIndexSet;
87
use rustc_hir::def_id::DefId;
@@ -744,13 +743,18 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
744743
SolverMode::Normal => {
745744
let param_env_responses = candidates
746745
.iter()
747-
.filter(|c| matches!(c.source, CandidateSource::ParamEnv(_)))
746+
.filter(|c| {
747+
matches!(
748+
c.source,
749+
CandidateSource::ParamEnv(_) | CandidateSource::AliasBound
750+
)
751+
})
748752
.map(|c| c.result)
749753
.collect::<Vec<_>>();
750754
if let Some(result) = self.try_merge_responses(&param_env_responses) {
751-
if result.has_only_region_constraints() {
752-
return Ok(result);
753-
}
755+
// We strongly prefer alias and param-env bounds here, even if they affect inference.
756+
// See https://github.com/rust-lang/trait-system-refactor-initiative/issues/11.
757+
return Ok(result);
754758
}
755759
}
756760
}

tests/ui/dyn-star/param-env-infer.current.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ LL | #![feature(dyn_star, pointer_like_trait)]
88
= note: `#[warn(incomplete_features)]` on by default
99

1010
error[E0282]: type annotations needed
11-
--> $DIR/param-env-infer.rs:12:10
11+
--> $DIR/param-env-infer.rs:13:10
1212
|
1313
LL | t as _
1414
| ^ cannot infer type

tests/ui/dyn-star/param-env-infer.next.stderr

+60-5
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,67 @@ LL | #![feature(dyn_star, pointer_like_trait)]
77
= note: see issue #102425 <https://github.com/rust-lang/rust/issues/102425> for more information
88
= note: `#[warn(incomplete_features)]` on by default
99

10-
error[E0282]: type annotations needed
11-
--> $DIR/param-env-infer.rs:12:10
10+
error[E0391]: cycle detected when computing type of `make_dyn_star::{opaque#0}`
11+
--> $DIR/param-env-infer.rs:11:60
1212
|
13-
LL | t as _
14-
| ^ cannot infer type
13+
LL | fn make_dyn_star<'a, T: PointerLike + Debug + 'a>(t: T) -> impl PointerLike + Debug + 'a {
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15+
|
16+
note: ...which requires borrow-checking `make_dyn_star`...
17+
--> $DIR/param-env-infer.rs:11:1
18+
|
19+
LL | fn make_dyn_star<'a, T: PointerLike + Debug + 'a>(t: T) -> impl PointerLike + Debug + 'a {
20+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21+
note: ...which requires promoting constants in MIR for `make_dyn_star`...
22+
--> $DIR/param-env-infer.rs:11:1
23+
|
24+
LL | fn make_dyn_star<'a, T: PointerLike + Debug + 'a>(t: T) -> impl PointerLike + Debug + 'a {
25+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26+
note: ...which requires preparing `make_dyn_star` for borrow checking...
27+
--> $DIR/param-env-infer.rs:11:1
28+
|
29+
LL | fn make_dyn_star<'a, T: PointerLike + Debug + 'a>(t: T) -> impl PointerLike + Debug + 'a {
30+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
31+
note: ...which requires unsafety-checking `make_dyn_star`...
32+
--> $DIR/param-env-infer.rs:11:1
33+
|
34+
LL | fn make_dyn_star<'a, T: PointerLike + Debug + 'a>(t: T) -> impl PointerLike + Debug + 'a {
35+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
36+
note: ...which requires building MIR for `make_dyn_star`...
37+
--> $DIR/param-env-infer.rs:11:1
38+
|
39+
LL | fn make_dyn_star<'a, T: PointerLike + Debug + 'a>(t: T) -> impl PointerLike + Debug + 'a {
40+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
41+
note: ...which requires match-checking `make_dyn_star`...
42+
--> $DIR/param-env-infer.rs:11:1
43+
|
44+
LL | fn make_dyn_star<'a, T: PointerLike + Debug + 'a>(t: T) -> impl PointerLike + Debug + 'a {
45+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
46+
note: ...which requires building THIR for `make_dyn_star`...
47+
--> $DIR/param-env-infer.rs:11:1
48+
|
49+
LL | fn make_dyn_star<'a, T: PointerLike + Debug + 'a>(t: T) -> impl PointerLike + Debug + 'a {
50+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
51+
note: ...which requires type-checking `make_dyn_star`...
52+
--> $DIR/param-env-infer.rs:11:1
53+
|
54+
LL | fn make_dyn_star<'a, T: PointerLike + Debug + 'a>(t: T) -> impl PointerLike + Debug + 'a {
55+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
56+
= note: ...which requires computing layout of `make_dyn_star::{opaque#0}`...
57+
= note: ...which requires normalizing `make_dyn_star::{opaque#0}`...
58+
= note: ...which again requires computing type of `make_dyn_star::{opaque#0}`, completing the cycle
59+
note: cycle used when checking item types in top-level module
60+
--> $DIR/param-env-infer.rs:5:1
61+
|
62+
LL | / #![feature(dyn_star, pointer_like_trait)]
63+
LL | |
64+
LL | |
65+
LL | | use std::fmt::Debug;
66+
... |
67+
LL | |
68+
LL | | fn main() {}
69+
| |____________^
1570

1671
error: aborting due to previous error; 1 warning emitted
1772

18-
For more information about this error, try `rustc --explain E0282`.
73+
For more information about this error, try `rustc --explain E0391`.

tests/ui/dyn-star/param-env-infer.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ use std::fmt::Debug;
99
use std::marker::PointerLike;
1010

1111
fn make_dyn_star<'a, T: PointerLike + Debug + 'a>(t: T) -> impl PointerLike + Debug + 'a {
12+
//[next]~^ ERROR cycle detected when computing type of `make_dyn_star::{opaque#0}`
1213
t as _
13-
//~^ ERROR type annotations needed
14+
//[current]~^ ERROR type annotations needed
1415
}
1516

1617
fn main() {}

tests/ui/traits/new-solver/alias_eq_dont_use_normalizes_to_if_substs_eq.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// compile-flags: -Ztrait-solver=next
22

3+
// check-pass
4+
// (should not pass, should be turned into a coherence-only test)
5+
36
// check that when computing `alias-eq(<() as Foo<u16, T>>::Assoc, <() as Foo<?0, T>>::Assoc)`
47
// we do not infer `?0 = u8` via the `for<STOP> (): Foo<u8, STOP>` impl or `?0 = u16` by
58
// relating substs as either could be a valid solution.
@@ -36,7 +39,6 @@ where
3639
{
3740
// `<() as Foo<u16, STOP>>::Assoc == <() as Foo<_, STOP>>::Assoc`
3841
let _: <() as Foo<u16, T>>::Assoc = output::<_, T>();
39-
//~^ error: type annotations needed
4042

4143
// let _: <() as Foo<u16, T>>::Assoc = output::<u8, T>(); // OK
4244
// let _: <() as Foo<u16, T>>::Assoc = output::<u16, T>(); // OK

tests/ui/traits/new-solver/alias_eq_dont_use_normalizes_to_if_substs_eq.stderr

-9
This file was deleted.

tests/ui/traits/new-solver/alias_eq_substs_eq_not_intercrate.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// compile-flags: -Ztrait-solver=next
22

3+
// check-pass
4+
// (should not pass, should be turned into a coherence-only test)
5+
36
// check that a `alias-eq(<?0 as TraitB>::Assoc, <T as TraitB>::Assoc)` goal fails.
47

58
// FIXME(deferred_projection_equality): add a test that this is true during coherence
@@ -14,7 +17,6 @@ fn needs_a<T: TraitB>() -> T::Assoc {
1417

1518
fn bar<T: TraitB>() {
1619
let _: <_ as TraitB>::Assoc = needs_a::<T>();
17-
//~^ error: type annotations needed
1820
}
1921

2022
fn main() {}

tests/ui/traits/new-solver/alias_eq_substs_eq_not_intercrate.stderr

-9
This file was deleted.

0 commit comments

Comments
 (0)