Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't use generator witness for implied bounds #115173

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions compiler/rustc_trait_selection/src/traits/wf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,8 +608,6 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
| ty::Float(..)
| ty::Error(_)
| ty::Str
| ty::GeneratorWitness(..)
| ty::GeneratorWitnessMIR(..)
| ty::Never
| ty::Param(_)
| ty::Bound(..)
Expand Down Expand Up @@ -681,6 +679,12 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
}
}

ty::GeneratorWitness(..) | ty::GeneratorWitnessMIR(..) => {
// Unspecified in RFC 1214.
// They are always WF when the gnereator passes typeck/borrowck.
walker.skip_current_subtree();
}

ty::Generator(did, args, ..) => {
// Walk ALL the types in the generator: this will
// include the upvar types as well as the yield
Expand Down
17 changes: 17 additions & 0 deletions tests/ui/async-await/generator-wf-check.output_wf.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error[E0310]: the parameter type `T` may not live long enough
--> $DIR/generator-wf-check.rs:24:5
|
LL | / wf(async {
LL | |
LL | | None::<Static<T>>
LL | | });
| |______^ ...so that the type `T` will meet its required lifetime bounds
|
help: consider adding an explicit lifetime bound...
|
LL | fn test_output_wf<T: 'static>() {
| +++++++++

error: aborting due to previous error

For more information about this error, try `rustc --explain E0310`.
52 changes: 52 additions & 0 deletions tests/ui/async-await/generator-wf-check.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//! Tests if we draw implied bounds from the generator output or witness types,
//! and if so, whether we check these types are WF when checking the generator.

// edition: 2021
// revisions: output output_wf witness witness_wf
//[output] check-pass
//[output_wf] check-fail
//[witness] check-fail
//[witness_wf] check-fail

struct Static<T: 'static>(T);

fn wf<T>(_: T) {}

#[cfg(output)]
fn test_output<T>() {
async {
None::<Static<T>>
};
}

#[cfg(output_wf)]
fn test_output_wf<T>() {
wf(async {
//[output_wf]~^ ERROR `T` may not live long enough
None::<Static<T>>
});
}

#[cfg(witness)]
fn test_witness<T>() {
async {
let witness: Option<Static<T>> = None;
//[witness]~^ ERROR `T` may not live long enough
async {}.await;
drop(witness);
//[witness]~^ ERROR `T` may not live long enough
};
}

#[cfg(witness_wf)]
fn test_witness_wf<T>() {
wf(async {
let witness: Option<Static<T>> = None;
//[witness_wf]~^ ERROR `T` may not live long enough
async {}.await;
drop(witness);
//[witness_wf]~^ ERROR `T` may not live long enough
});
}

fn main() {}
25 changes: 25 additions & 0 deletions tests/ui/async-await/generator-wf-check.witness.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
error[E0310]: the parameter type `T` may not live long enough
--> $DIR/generator-wf-check.rs:33:22
|
LL | let witness: Option<Static<T>> = None;
| ^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds
|
help: consider adding an explicit lifetime bound...
|
LL | fn test_witness<T: 'static>() {
| +++++++++

error[E0310]: the parameter type `T` may not live long enough
--> $DIR/generator-wf-check.rs:36:9
|
LL | drop(witness);
| ^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds
|
help: consider adding an explicit lifetime bound...
|
LL | fn test_witness<T: 'static>() {
| +++++++++

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0310`.
25 changes: 25 additions & 0 deletions tests/ui/async-await/generator-wf-check.witness_wf.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
error[E0310]: the parameter type `T` may not live long enough
--> $DIR/generator-wf-check.rs:44:22
|
LL | let witness: Option<Static<T>> = None;
| ^^^^^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds
|
help: consider adding an explicit lifetime bound...
|
LL | fn test_witness_wf<T: 'static>() {
| +++++++++

error[E0310]: the parameter type `T` may not live long enough
--> $DIR/generator-wf-check.rs:47:9
|
LL | drop(witness);
| ^^^^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds
|
help: consider adding an explicit lifetime bound...
|
LL | fn test_witness_wf<T: 'static>() {
| +++++++++

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0310`.
Loading