Skip to content

Commit eec25d6

Browse files
aliemjaycuviper
authored andcommitted
(cherry picked from commit a1e274f)
1 parent dfe9af5 commit eec25d6

11 files changed

+128
-103
lines changed

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+13-20
Original file line numberDiff line numberDiff line change
@@ -328,26 +328,19 @@ fn check_opaque_type_well_formed<'tcx>(
328328

329329
// Require that the hidden type actually fulfills all the bounds of the opaque type, even without
330330
// the bounds that the function supplies.
331-
let mut obligations = vec![];
332-
infcx
333-
.insert_hidden_type(
334-
OpaqueTypeKey { def_id, args: identity_args },
335-
&ObligationCause::misc(definition_span, def_id),
336-
param_env,
337-
definition_ty,
338-
true,
339-
&mut obligations,
340-
)
341-
.unwrap();
342-
infcx.add_item_bounds_for_hidden_type(
343-
def_id.to_def_id(),
344-
identity_args,
345-
ObligationCause::misc(definition_span, def_id),
346-
param_env,
347-
definition_ty,
348-
&mut obligations,
349-
);
350-
ocx.register_obligations(obligations);
331+
let opaque_ty = Ty::new_opaque(tcx, def_id.to_def_id(), identity_args);
332+
ocx.eq(&ObligationCause::misc(definition_span, def_id), param_env, opaque_ty, definition_ty)
333+
.map_err(|err| {
334+
infcx
335+
.err_ctxt()
336+
.report_mismatched_types(
337+
&ObligationCause::misc(definition_span, def_id),
338+
opaque_ty,
339+
definition_ty,
340+
err,
341+
)
342+
.emit()
343+
})?;
351344

352345
// Require the hidden type to be well-formed with only the generics of the opaque type.
353346
// Defining use functions may have more bounds than the opaque type, which is ok, as long as the

compiler/rustc_infer/src/infer/opaque_types.rs

+1-19
Original file line numberDiff line numberDiff line change
@@ -145,25 +145,7 @@ impl<'tcx> InferCtxt<'tcx> {
145145
return None;
146146
}
147147
}
148-
DefiningAnchor::Bubble => {
149-
if let ty::Alias(ty::Opaque, _) = b.kind() {
150-
// In bubble mode we don't know which of the two opaque types is supposed to have the other
151-
// as a hidden type (both, none or either one of them could be in its defining scope).
152-
let predicate = ty::PredicateKind::AliasRelate(
153-
a.into(),
154-
b.into(),
155-
ty::AliasRelationDirection::Equate,
156-
);
157-
let obligation = traits::Obligation::new(
158-
self.tcx,
159-
cause.clone(),
160-
param_env,
161-
predicate,
162-
);
163-
let obligations = vec![obligation];
164-
return Some(Ok(InferOk { value: (), obligations }));
165-
}
166-
}
148+
DefiningAnchor::Bubble => {}
167149
DefiningAnchor::Error => return None,
168150
};
169151
if let ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, .. }) = *b.kind() {

compiler/rustc_trait_selection/src/traits/fulfill.rs

+2-21
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use rustc_infer::infer::DefineOpaqueTypes;
66
use rustc_infer::traits::ProjectionCacheKey;
77
use rustc_infer::traits::{PolyTraitObligation, SelectionError, TraitEngine};
88
use rustc_middle::mir::interpret::ErrorHandled;
9-
use rustc_middle::traits::DefiningAnchor;
109
use rustc_middle::ty::abstract_const::NotConstEvaluatable;
1110
use rustc_middle::ty::error::{ExpectedFound, TypeError};
1211
use rustc_middle::ty::GenericArgsRef;
@@ -626,27 +625,9 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
626625
}
627626
}
628627
ty::PredicateKind::Ambiguous => ProcessResult::Unchanged,
629-
ty::PredicateKind::AliasRelate(..)
630-
if matches!(self.selcx.infcx.defining_use_anchor, DefiningAnchor::Bubble) =>
631-
{
632-
ProcessResult::Unchanged
628+
ty::PredicateKind::AliasRelate(..) => {
629+
bug!("AliasRelate is only used for new solver")
633630
}
634-
ty::PredicateKind::AliasRelate(a, b, relate) => match relate {
635-
ty::AliasRelationDirection::Equate => match self
636-
.selcx
637-
.infcx
638-
.at(&obligation.cause, obligation.param_env)
639-
.eq(DefineOpaqueTypes::Yes, a, b)
640-
{
641-
Ok(inf_ok) => ProcessResult::Changed(mk_pending(inf_ok.into_obligations())),
642-
Err(_) => ProcessResult::Error(FulfillmentErrorCode::CodeSelectionError(
643-
SelectionError::Unimplemented,
644-
)),
645-
},
646-
ty::AliasRelationDirection::Subtype => {
647-
bug!("AliasRelate with subtyping is only used for new solver")
648-
}
649-
},
650631
ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, ty)) => {
651632
match self.selcx.infcx.at(&obligation.cause, obligation.param_env).eq(
652633
DefineOpaqueTypes::No,

compiler/rustc_trait_selection/src/traits/select/mod.rs

+2-21
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ use rustc_infer::traits::TraitObligation;
3838
use rustc_middle::dep_graph::dep_kinds;
3939
use rustc_middle::dep_graph::DepNodeIndex;
4040
use rustc_middle::mir::interpret::ErrorHandled;
41-
use rustc_middle::traits::DefiningAnchor;
4241
use rustc_middle::ty::abstract_const::NotConstEvaluatable;
4342
use rustc_middle::ty::fold::BottomUpFolder;
4443
use rustc_middle::ty::relate::TypeRelation;
@@ -1003,27 +1002,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
10031002
}
10041003
}
10051004
}
1006-
ty::PredicateKind::AliasRelate(..)
1007-
if matches!(self.infcx.defining_use_anchor, DefiningAnchor::Bubble) =>
1008-
{
1009-
Ok(EvaluatedToAmbig)
1005+
ty::PredicateKind::AliasRelate(..) => {
1006+
bug!("AliasRelate is only used for new solver")
10101007
}
1011-
ty::PredicateKind::AliasRelate(a, b, relate) => match relate {
1012-
ty::AliasRelationDirection::Equate => match self
1013-
.infcx
1014-
.at(&obligation.cause, obligation.param_env)
1015-
.eq(DefineOpaqueTypes::Yes, a, b)
1016-
{
1017-
Ok(inf_ok) => self.evaluate_predicates_recursively(
1018-
previous_stack,
1019-
inf_ok.into_obligations(),
1020-
),
1021-
Err(_) => Ok(EvaluatedToErr),
1022-
},
1023-
ty::AliasRelationDirection::Subtype => {
1024-
bug!("AliasRelate subtyping is only used for new solver")
1025-
}
1026-
},
10271008
ty::PredicateKind::Ambiguous => Ok(EvaluatedToAmbig),
10281009
ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, ty)) => {
10291010
match self.infcx.at(&obligation.cause, obligation.param_env).eq(

tests/ui/impl-trait/async_scope_creep.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#![feature(type_alias_impl_trait)]
22
// edition:2021
3-
//[rpit] check-pass
4-
// revisions: tait rpit
3+
// check-pass
54

65
struct Pending {}
76

@@ -13,23 +12,15 @@ impl AsyncRead for i32 {}
1312

1413
type PendingReader<'a> = impl AsyncRead + 'a;
1514

16-
#[cfg(tait)]
17-
type OpeningReadFuture<'a> = impl std::future::Future<Output = Result<PendingReader<'a>, CantOpen>>;
15+
type OpeningReadFuture<'a> =
16+
impl std::future::Future<Output = Result<PendingReader<'a>, CantOpen>>;
1817

1918
impl Pending {
2019
async fn read(&mut self) -> Result<impl AsyncRead + '_, CantOpen> {
2120
Ok(42)
2221
}
2322

24-
#[cfg(tait)]
2523
fn read_fut(&mut self) -> OpeningReadFuture<'_> {
26-
self.read() //[tait]~ ERROR: cannot satisfy `impl AsyncRead + 'a == PendingReader<'a>`
27-
}
28-
29-
#[cfg(rpit)]
30-
fn read_fut(
31-
&mut self,
32-
) -> impl std::future::Future<Output = Result<PendingReader<'_>, CantOpen>> {
3324
self.read()
3425
}
3526
}

tests/ui/impl-trait/async_scope_creep.tait.stderr

-9
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
error: internal compiler error: no errors encountered even though `delay_span_bug` issued
2+
3+
error: internal compiler error: {OpaqueTypeKey { def_id: DefId(rpit::{opaque#0}), args: [] }: OpaqueTypeDecl { hidden_type: OpaqueHiddenType { span: no-location (#0), ty: Alias(Opaque, AliasTy { args: [], def_id: DefId(foo::{opaque#0}) }) } }}
4+
|
5+
=
6+
7+
8+
error: internal compiler error: error performing ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: UserFacing }, value: ProvePredicate { predicate: Binder { value: ProjectionPredicate(AliasTy { args: [FnDef(DefId(rpit), []), ()], def_id: DefId(ops::function::FnOnce::Output) }, Term::Ty(Alias(Opaque, AliasTy { args: [], def_id: DefId(foo::{opaque#0}) }))), bound_vars: [] } } }
9+
--> $DIR/equality-in-canonical-query.rs:19:5
10+
|
11+
LL | same_output(foo, rpit);
12+
| ^^^^^^^^^^^^^^^^^^^^^^
13+
|
14+
15+
--> $DIR/equality-in-canonical-query.rs:19:5
16+
|
17+
LL | same_output(foo, rpit);
18+
| ^^^^^^^^^^^^^^^^^^^^^^
19+
20+
21+
22+
23+
24+
25+
26+
query stack during panic:
27+
end of query stack
28+
error: aborting due to 3 previous errors
29+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// issue: #116877
2+
// revisions: sized clone
3+
//[sized] check-pass
4+
5+
//[clone] known-bug: #108498
6+
//[clone] failure-status: 101
7+
//[clone] normalize-stderr-test: "DefId\(.*?\]::" -> "DefId("
8+
//[clone] normalize-stderr-test: "(?m)note: .*$" -> ""
9+
//[clone] normalize-stderr-test: "(?m)^ *\d+: .*\n" -> ""
10+
//[clone] normalize-stderr-test: "(?m)^ *at .*\n" -> ""
11+
12+
#[cfg(sized)] fn rpit() -> impl Sized {}
13+
#[cfg(clone)] fn rpit() -> impl Clone {}
14+
15+
fn same_output<Out>(_: impl Fn() -> Out, _: impl Fn() -> Out) {}
16+
17+
pub fn foo() -> impl Sized {
18+
same_output(rpit, foo);
19+
same_output(foo, rpit);
20+
rpit()
21+
}
22+
23+
fn main () {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
error: internal compiler error: no errors encountered even though `delay_span_bug` issued
2+
3+
error: internal compiler error: {OpaqueTypeKey { def_id: DefId(get_rpit::{opaque#0}), args: [] }: OpaqueTypeDecl { hidden_type: OpaqueHiddenType { span: no-location (#0), ty: Alias(Opaque, AliasTy { args: [], def_id: DefId(Opaque::{opaque#0}) }) } }}
4+
|
5+
=
6+
7+
8+
error: internal compiler error: error performing ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: UserFacing }, value: ProvePredicate { predicate: Binder { value: ProjectionPredicate(AliasTy { args: [FnDef(DefId(get_rpit), []), ()], def_id: DefId(ops::function::FnOnce::Output) }, Term::Ty(Alias(Opaque, AliasTy { args: [], def_id: DefId(Opaque::{opaque#0}) }))), bound_vars: [] } } }
9+
--> $DIR/rpit_tait_equality_in_canonical_query.rs:28:5
10+
|
11+
LL | query(get_rpit);
12+
| ^^^^^^^^^^^^^^^
13+
|
14+
15+
--> $DIR/rpit_tait_equality_in_canonical_query.rs:28:5
16+
|
17+
LL | query(get_rpit);
18+
| ^^^^^^^^^^^^^^^
19+
20+
21+
22+
23+
24+
25+
26+
query stack during panic:
27+
end of query stack
28+
error: aborting due to 3 previous errors
29+

tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@
77
88
// revisions: current next
99
//[next] compile-flags: -Ztrait-solver=next
10-
// check-pass
10+
//[next] check-pass
11+
12+
//[current] known-bug: #108498
13+
//[current] failure-status: 101
14+
//[current] normalize-stderr-test: "DefId\(.*?\]::" -> "DefId("
15+
//[current] normalize-stderr-test: "(?m)note: .*$" -> ""
16+
//[current] normalize-stderr-test: "(?m)^ *\d+: .*\n" -> ""
17+
//[current] normalize-stderr-test: "(?m)^ *at .*\n" -> ""
1118

1219
#![feature(type_alias_impl_trait)]
1320

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// The canonical query `Projection(<get_rpit as FnOnce>::Output = Opaque)`
2+
// is the *only* site that defines `Opaque` in MIR typeck.
3+
//
4+
// check-pass
5+
6+
#![feature(type_alias_impl_trait)]
7+
8+
type Opaque = impl Sized;
9+
10+
fn get_rpit() -> impl Sized {}
11+
12+
fn query(_: impl FnOnce() -> Opaque) {}
13+
14+
fn test(_: Opaque) {
15+
query(get_rpit);
16+
}
17+
18+
fn main() {}

0 commit comments

Comments
 (0)