Skip to content

Commit 381b326

Browse files
committed
identity uses are ok, even if there are no defining uses
1 parent 45b9d13 commit 381b326

File tree

4 files changed

+71
-1
lines changed

4 files changed

+71
-1
lines changed

compiler/rustc_borrowck/src/region_infer/opaque_types/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,16 @@ pub(crate) fn apply_computed_concrete_opaque_types<'tcx>(
503503
let mut errors = Vec::new();
504504
for &(key, hidden_type) in opaque_types {
505505
let Some(expected) = get_concrete_opaque_type(concrete_opaque_types, key.def_id) else {
506-
assert!(tcx.use_typing_mode_borrowck(), "non-defining use in defining scope");
506+
if !tcx.use_typing_mode_borrowck() {
507+
if let ty::Alias(ty::Opaque, alias_ty) = hidden_type.ty.kind()
508+
&& alias_ty.def_id == key.def_id.to_def_id()
509+
&& alias_ty.args == key.args
510+
{
511+
continue;
512+
} else {
513+
unreachable!("non-defining use in defining scope");
514+
}
515+
}
507516
errors.push(DeferredOpaqueTypeError::NonDefiningUseInDefiningScope {
508517
span: hidden_type.span,
509518
opaque_type_key: key,
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
error[E0277]: the trait bound `(): ReturnsSend` is not satisfied
2+
--> $DIR/ice-issue-146191.rs:6:52
3+
|
4+
LL | fn create_complex_future() -> impl Future<Output = impl ReturnsSend> {
5+
| ^^^^^^^^^^^^^^^^ the trait `ReturnsSend` is not implemented for `()`
6+
|
7+
help: this trait has no implementations, consider adding one
8+
--> $DIR/ice-issue-146191.rs:14:1
9+
|
10+
LL | trait ReturnsSend {}
11+
| ^^^^^^^^^^^^^^^^^
12+
note: required by a bound in an opaque type
13+
--> $DIR/ice-issue-146191.rs:6:57
14+
|
15+
LL | fn create_complex_future() -> impl Future<Output = impl ReturnsSend> {
16+
| ^^^^^^^^^^^
17+
18+
error[E0733]: recursion in an async block requires boxing
19+
--> $DIR/ice-issue-146191.rs:8:5
20+
|
21+
LL | async { create_complex_future().await }
22+
| ^^^^^ ----------------------------- recursive call here
23+
|
24+
= note: a recursive `async fn` call must introduce indirection such as `Box::pin` to avoid an infinitely sized future
25+
26+
error: aborting due to 2 previous errors
27+
28+
Some errors have detailed explanations: E0277, E0733.
29+
For more information about an error, try `rustc --explain E0277`.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/ice-issue-146191.rs:8:5
3+
|
4+
LL | async { create_complex_future().await }
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type
6+
7+
error[E0282]: type annotations needed
8+
--> $DIR/ice-issue-146191.rs:8:5
9+
|
10+
LL | async { create_complex_future().await }
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type
12+
|
13+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
14+
15+
error: aborting due to 2 previous errors
16+
17+
For more information about this error, try `rustc --explain E0282`.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//@ edition: 2024
2+
//@ revisions: current next
3+
//@[next] compile-flags: -Znext-solver
4+
//@ ignore-compare-mode-next-solver (explicit revisions)
5+
6+
fn create_complex_future() -> impl Future<Output = impl ReturnsSend> {
7+
//[current]~^ ERROR the trait bound `(): ReturnsSend` is not satisfied
8+
async { create_complex_future().await }
9+
//[current]~^ ERROR recursion in an async block requires
10+
//[next]~^^ ERROR type annotations needed
11+
//[next]~| ERROR type annotations needed
12+
}
13+
14+
trait ReturnsSend {}
15+
fn main() {}

0 commit comments

Comments
 (0)