Skip to content

Commit 7ae1c06

Browse files
authored
Unrolled build for rust-lang#116802
Rollup merge of rust-lang#116802 - compiler-errors:anchor-opaque-wf, r=oli-obk Remove `DefiningAnchor::Bubble` from opaque wf check Set the defining anchor to `DefiningAnchor::Bind(parent_def_id)` where `parent_def_id` is the first parent def-id that isn't an opaque. This "fixes" some of the nested-return-type wf tests. If we *do* want these to be hard-errors for TAITs, we should probably make those error separately from this check (i.e. via some check like the code in the `OPAQUE_HIDDEN_INFERRED_BOUND` lint). The fact that some of these tests fail but not all of them seems kinda coincidental. r? oli-obk
2 parents 4af886f + 743e6d1 commit 7ae1c06

7 files changed

+37
-48
lines changed

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
22
use rustc_errors::ErrorGuaranteed;
3+
use rustc_hir::def::DefKind;
34
use rustc_hir::def_id::LocalDefId;
45
use rustc_hir::OpaqueTyOrigin;
56
use rustc_infer::infer::InferCtxt;
@@ -308,20 +309,19 @@ fn check_opaque_type_well_formed<'tcx>(
308309
return Ok(definition_ty);
309310
};
310311
let param_env = tcx.param_env(def_id);
311-
// HACK This bubble is required for this tests to pass:
312-
// nested-return-type2-tait2.rs
313-
// nested-return-type2-tait3.rs
312+
313+
let mut parent_def_id = def_id;
314+
while tcx.def_kind(parent_def_id) == DefKind::OpaqueTy {
315+
parent_def_id = tcx.local_parent(parent_def_id);
316+
}
317+
314318
// FIXME(-Ztrait-solver=next): We probably should use `DefiningAnchor::Error`
315319
// and prepopulate this `InferCtxt` with known opaque values, rather than
316320
// using the `Bind` anchor here. For now it's fine.
317321
let infcx = tcx
318322
.infer_ctxt()
319323
.with_next_trait_solver(next_trait_solver)
320-
.with_opaque_type_inference(if next_trait_solver {
321-
DefiningAnchor::Bind(def_id)
322-
} else {
323-
DefiningAnchor::Bubble
324-
})
324+
.with_opaque_type_inference(DefiningAnchor::Bind(parent_def_id))
325325
.build();
326326
let ocx = ObligationCtxt::new(&infcx);
327327
let identity_args = GenericArgs::identity_for_item(tcx, def_id);

tests/ui/impl-trait/async_scope_creep.rs

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

66
struct Pending {}
@@ -23,7 +23,7 @@ impl Pending {
2323

2424
#[cfg(tait)]
2525
fn read_fut(&mut self) -> OpeningReadFuture<'_> {
26-
self.read() //[tait]~ ERROR: cannot satisfy `impl AsyncRead + 'a == PendingReader<'a>`
26+
self.read()
2727
}
2828

2929
#[cfg(rpit)]

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

-9
This file was deleted.

tests/ui/impl-trait/nested-return-type2-tait2.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// check-pass
2+
13
#![feature(type_alias_impl_trait)]
24

35
trait Duh {}
@@ -17,6 +19,7 @@ impl<R: Duh, F: FnMut() -> R> Trait for F {
1719

1820
type Sendable = impl Send;
1921
type Traitable = impl Trait<Assoc = Sendable>;
22+
//~^ WARN opaque type `Traitable` does not satisfy its associated type bounds
2023

2124
// The `impl Send` here is then later compared against the inference var
2225
// created, causing the inference var to be set to `impl Send` instead of
@@ -25,7 +28,6 @@ type Traitable = impl Trait<Assoc = Sendable>;
2528
// type does not implement `Duh`, even if its hidden type does. So we error out.
2629
fn foo() -> Traitable {
2730
|| 42
28-
//~^ ERROR `Sendable: Duh` is not satisfied
2931
}
3032

3133
fn main() {
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
1-
error[E0277]: the trait bound `Sendable: Duh` is not satisfied
2-
--> $DIR/nested-return-type2-tait2.rs:27:5
1+
warning: opaque type `Traitable` does not satisfy its associated type bounds
2+
--> $DIR/nested-return-type2-tait2.rs:21:29
33
|
4-
LL | || 42
5-
| ^^^^^ the trait `Duh` is not implemented for `Sendable`
4+
LL | type Assoc: Duh;
5+
| --- this associated type bound is unsatisfied for `Sendable`
6+
...
7+
LL | type Traitable = impl Trait<Assoc = Sendable>;
8+
| ^^^^^^^^^^^^^^^^
69
|
7-
= help: the trait `Duh` is implemented for `i32`
8-
note: required for `{closure@$DIR/nested-return-type2-tait2.rs:27:5: 27:7}` to implement `Trait`
9-
--> $DIR/nested-return-type2-tait2.rs:14:31
10-
|
11-
LL | impl<R: Duh, F: FnMut() -> R> Trait for F {
12-
| --- ^^^^^ ^
13-
| |
14-
| unsatisfied trait bound introduced here
10+
= note: `#[warn(opaque_hidden_inferred_bound)]` on by default
1511

16-
error: aborting due to previous error
12+
warning: 1 warning emitted
1713

18-
For more information about this error, try `rustc --explain E0277`.

tests/ui/impl-trait/nested-return-type2-tait3.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// check-pass
2+
13
#![feature(type_alias_impl_trait)]
24

35
trait Duh {}
@@ -16,6 +18,7 @@ impl<R: Duh, F: FnMut() -> R> Trait for F {
1618
}
1719

1820
type Traitable = impl Trait<Assoc = impl Send>;
21+
//~^ WARN opaque type `Traitable` does not satisfy its associated type bounds
1922

2023
// The `impl Send` here is then later compared against the inference var
2124
// created, causing the inference var to be set to `impl Send` instead of
@@ -24,7 +27,6 @@ type Traitable = impl Trait<Assoc = impl Send>;
2427
// type does not implement `Duh`, even if its hidden type does. So we error out.
2528
fn foo() -> Traitable {
2629
|| 42
27-
//~^ ERROR `impl Send: Duh` is not satisfied
2830
}
2931

3032
fn main() {
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
error[E0277]: the trait bound `impl Send: Duh` is not satisfied
2-
--> $DIR/nested-return-type2-tait3.rs:26:5
1+
warning: opaque type `Traitable` does not satisfy its associated type bounds
2+
--> $DIR/nested-return-type2-tait3.rs:20:29
33
|
4-
LL | || 42
5-
| ^^^^^ the trait `Duh` is not implemented for `impl Send`
4+
LL | type Assoc: Duh;
5+
| --- this associated type bound is unsatisfied for `impl Send`
6+
...
7+
LL | type Traitable = impl Trait<Assoc = impl Send>;
8+
| ^^^^^^^^^^^^^^^^^
69
|
7-
= help: the trait `Duh` is implemented for `i32`
8-
note: required for `{closure@$DIR/nested-return-type2-tait3.rs:26:5: 26:7}` to implement `Trait`
9-
--> $DIR/nested-return-type2-tait3.rs:14:31
10+
= note: `#[warn(opaque_hidden_inferred_bound)]` on by default
11+
help: add this bound
1012
|
11-
LL | impl<R: Duh, F: FnMut() -> R> Trait for F {
12-
| --- ^^^^^ ^
13-
| |
14-
| unsatisfied trait bound introduced here
13+
LL | type Traitable = impl Trait<Assoc = impl Send + Duh>;
14+
| +++++
1515

16-
error: aborting due to previous error
16+
warning: 1 warning emitted
1717

18-
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)