Skip to content

Commit 200019c

Browse files
authoredMar 2, 2024
Rollup merge of rust-lang#121731 - oli-obk:eager_opaque_checks, r=compiler-errors
Now that inlining, mir validation and const eval all use reveal-all, we won't be constraining hidden types here anymore r? `@compiler-errors` one bubble down, two more to go the test is unrelated, just something I noticed would be good to test in both the old solver and the new.
2 parents 30976fb + 0bb2a6b commit 200019c

File tree

4 files changed

+38
-24
lines changed

4 files changed

+38
-24
lines changed
 

‎compiler/rustc_const_eval/src/util/compare_types.rs

+3-22
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! other areas of the compiler as well.
55
66
use rustc_infer::infer::TyCtxtInferExt;
7-
use rustc_middle::traits::{DefiningAnchor, ObligationCause};
7+
use rustc_middle::traits::ObligationCause;
88
use rustc_middle::ty::{ParamEnv, Ty, TyCtxt, Variance};
99
use rustc_trait_selection::traits::ObligationCtxt;
1010

@@ -33,9 +33,6 @@ pub fn is_equal_up_to_subtyping<'tcx>(
3333
/// When validating assignments, the variance should be `Covariant`. When checking
3434
/// during `MirPhase` >= `MirPhase::Runtime(RuntimePhase::Initial)` variance should be `Invariant`
3535
/// because we want to check for type equality.
36-
///
37-
/// This mostly ignores opaque types as it can be used in constraining contexts
38-
/// while still computing the final underlying type.
3936
pub fn relate_types<'tcx>(
4037
tcx: TyCtxt<'tcx>,
4138
param_env: ParamEnv<'tcx>,
@@ -47,8 +44,7 @@ pub fn relate_types<'tcx>(
4744
return true;
4845
}
4946

50-
let mut builder =
51-
tcx.infer_ctxt().ignoring_regions().with_opaque_type_inference(DefiningAnchor::Bubble);
47+
let mut builder = tcx.infer_ctxt().ignoring_regions();
5248
let infcx = builder.build();
5349
let ocx = ObligationCtxt::new(&infcx);
5450
let cause = ObligationCause::dummy();
@@ -58,20 +54,5 @@ pub fn relate_types<'tcx>(
5854
Ok(()) => {}
5955
Err(_) => return false,
6056
};
61-
let errors = ocx.select_all_or_error();
62-
// With `Reveal::All`, opaque types get normalized away, with `Reveal::UserFacing`
63-
// we would get unification errors because we're unable to look into opaque types,
64-
// even if they're constrained in our current function.
65-
for (key, ty) in infcx.take_opaque_types() {
66-
let hidden_ty = tcx.type_of(key.def_id).instantiate(tcx, key.args);
67-
if hidden_ty != ty.hidden_type.ty {
68-
span_bug!(
69-
ty.hidden_type.span,
70-
"{}, {}",
71-
tcx.type_of(key.def_id).instantiate(tcx, key.args),
72-
ty.hidden_type.ty
73-
);
74-
}
75-
}
76-
errors.is_empty()
57+
ocx.select_all_or_error().is_empty()
7758
}

‎tests/ui/impl-trait/hidden-type-is-opaque-2.stderr ‎tests/ui/impl-trait/hidden-type-is-opaque-2.default.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0282]: type annotations needed
2-
--> $DIR/hidden-type-is-opaque-2.rs:8:17
2+
--> $DIR/hidden-type-is-opaque-2.rs:10:17
33
|
44
LL | Thunk::new(|mut cont| {
55
| ^^^^^^^^
@@ -13,7 +13,7 @@ LL | Thunk::new(|mut cont: /* Type */| {
1313
| ++++++++++++
1414

1515
error[E0282]: type annotations needed
16-
--> $DIR/hidden-type-is-opaque-2.rs:18:17
16+
--> $DIR/hidden-type-is-opaque-2.rs:20:17
1717
|
1818
LL | Thunk::new(|mut cont| {
1919
| ^^^^^^^^
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/hidden-type-is-opaque-2.rs:10:17
3+
|
4+
LL | Thunk::new(|mut cont| {
5+
| ^^^^^^^^
6+
LL |
7+
LL | cont.reify_as();
8+
| ---- type must be known at this point
9+
|
10+
help: consider giving this closure parameter an explicit type
11+
|
12+
LL | Thunk::new(|mut cont: /* Type */| {
13+
| ++++++++++++
14+
15+
error[E0282]: type annotations needed
16+
--> $DIR/hidden-type-is-opaque-2.rs:20:17
17+
|
18+
LL | Thunk::new(|mut cont| {
19+
| ^^^^^^^^
20+
LL |
21+
LL | cont.reify_as();
22+
| ---- type must be known at this point
23+
|
24+
help: consider giving this closure parameter an explicit type
25+
|
26+
LL | Thunk::new(|mut cont: /* Type */| {
27+
| ++++++++++++
28+
29+
error: aborting due to 2 previous errors
30+
31+
For more information about this error, try `rustc --explain E0282`.

‎tests/ui/impl-trait/hidden-type-is-opaque-2.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// This doesn't work, because we don't flow information from opaque types
22
// into function arguments via the function's generic parameters
33
// FIXME(oli-obk): make `expected_inputs_for_expected_output` support this
4+
//@ revisions: default next
5+
//@[next] compile-flags: -Znext-solver
46

57
#![feature(type_alias_impl_trait)]
68

0 commit comments

Comments
 (0)
Please sign in to comment.