-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Taint the type of ill-formed (unsized) statics #144226
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
Changes from 5 commits
e70d213
6b4181f
8322078
ec81464
7c64961
8817572
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -17,6 +17,7 @@ impl<F: Future> Task<F> { | |||||
} | ||||||
|
||||||
pub type F = impl Future; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Needing an extra annotation for an opaque type in a static item seems fine to me |
||||||
|
||||||
#[define_opaque(F)] | ||||||
fn foo() | ||||||
where | ||||||
|
@@ -31,5 +32,7 @@ where | |||||
|
||||||
// Check that statics are inhabited computes they layout. | ||||||
static POOL: Task<F> = Task::new(); | ||||||
//~^ ERROR cycle detected when computing type of `POOL` | ||||||
//~| ERROR cycle detected when computing type of `POOL` | ||||||
|
||||||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,97 @@ | ||
error[E0425]: cannot find value `Foo` in this scope | ||
--> $DIR/layout-error.rs:26:17 | ||
--> $DIR/layout-error.rs:27:17 | ||
| | ||
LL | let a = Foo; | ||
| ^^^ not found in this scope | ||
|
||
error: aborting due to 1 previous error | ||
error[E0391]: cycle detected when computing type of `POOL` | ||
--> $DIR/layout-error.rs:34:14 | ||
| | ||
LL | static POOL: Task<F> = Task::new(); | ||
| ^^^^^^^ | ||
| | ||
= note: ...which requires evaluating trait selection obligation `Task<F>: core::marker::Sync`... | ||
note: ...which requires computing type of opaque `F::{opaque#0}`... | ||
--> $DIR/layout-error.rs:19:14 | ||
| | ||
LL | pub type F = impl Future; | ||
| ^^^^^^^^^^^ | ||
note: ...which requires borrow-checking `foo`... | ||
--> $DIR/layout-error.rs:22:1 | ||
| | ||
LL | / fn foo() | ||
LL | | where | ||
LL | | F:, | ||
| |_______^ | ||
note: ...which requires promoting constants in MIR for `foo`... | ||
--> $DIR/layout-error.rs:22:1 | ||
| | ||
LL | / fn foo() | ||
LL | | where | ||
LL | | F:, | ||
| |_______^ | ||
note: ...which requires checking if `foo` contains FFI-unwind calls... | ||
--> $DIR/layout-error.rs:22:1 | ||
| | ||
LL | / fn foo() | ||
LL | | where | ||
LL | | F:, | ||
| |_______^ | ||
note: ...which requires building MIR for `foo`... | ||
--> $DIR/layout-error.rs:22:1 | ||
| | ||
LL | / fn foo() | ||
LL | | where | ||
LL | | F:, | ||
| |_______^ | ||
note: ...which requires match-checking `foo`... | ||
--> $DIR/layout-error.rs:22:1 | ||
| | ||
LL | / fn foo() | ||
LL | | where | ||
LL | | F:, | ||
| |_______^ | ||
note: ...which requires type-checking `foo`... | ||
--> $DIR/layout-error.rs:22:1 | ||
| | ||
LL | / fn foo() | ||
LL | | where | ||
LL | | F:, | ||
| |_______^ | ||
= note: ...which again requires computing type of `POOL`, completing the cycle | ||
note: cycle used when checking that `POOL` is well-formed | ||
--> $DIR/layout-error.rs:34:1 | ||
| | ||
LL | static POOL: Task<F> = Task::new(); | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information | ||
|
||
error[E0391]: cycle detected when computing type of `POOL` | ||
--> $DIR/layout-error.rs:34:14 | ||
| | ||
LL | static POOL: Task<F> = Task::new(); | ||
| ^^^^^^^ | ||
| | ||
= note: ...which requires evaluating trait selection obligation `Task<F>: core::marker::Sync`... | ||
note: ...which requires computing type of opaque `F::{opaque#0}`... | ||
--> $DIR/layout-error.rs:19:14 | ||
| | ||
LL | pub type F = impl Future; | ||
| ^^^^^^^^^^^ | ||
note: ...which requires computing the opaque types defined by `POOL`... | ||
--> $DIR/layout-error.rs:34:1 | ||
| | ||
LL | static POOL: Task<F> = Task::new(); | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
= note: ...which again requires computing type of `POOL`, completing the cycle | ||
note: cycle used when checking that `POOL` is well-formed | ||
--> $DIR/layout-error.rs:34:1 | ||
| | ||
LL | static POOL: Task<F> = Task::new(); | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0425`. | ||
Some errors have detailed explanations: E0391, E0425. | ||
For more information about an error, try `rustc --explain E0391`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
// Regression test for #80998. | ||
// | ||
//@ aux-build:metadata-sufficient-for-layout.rs | ||
//@ check-pass | ||
|
||
#![feature(type_alias_impl_trait, rustc_attrs)] | ||
#![feature(coroutine_trait)] | ||
|
@@ -23,5 +22,6 @@ mod helper { | |
|
||
// Static queries the layout of the coroutine. | ||
static A: Option<helper::F> = None; | ||
//~^ ERROR cycle detected when computing type of `A` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly here. Open an issue that this cycle diagnostic should propose adding the bound to the opaque. We'll fix that for TAITs but that shouldn't stop your PR |
||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
error[E0391]: cycle detected when computing type of `A` | ||
--> $DIR/metadata-sufficient-for-layout.rs:24:11 | ||
| | ||
LL | static A: Option<helper::F> = None; | ||
| ^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: ...which requires evaluating trait selection obligation `core::option::Option<helper::F>: core::marker::Sync`... | ||
note: ...which requires computing type of opaque `helper::F::{opaque#0}`... | ||
--> $DIR/metadata-sufficient-for-layout.rs:15:18 | ||
| | ||
LL | pub type F = impl Coroutine<(), Yield = (), Return = ()>; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
note: ...which requires borrow-checking `helper::f`... | ||
--> $DIR/metadata-sufficient-for-layout.rs:18:5 | ||
| | ||
LL | fn f() -> F { | ||
| ^^^^^^^^^^^ | ||
note: ...which requires computing type of opaque `helper::F::{opaque#0}` via HIR typeck... | ||
--> $DIR/metadata-sufficient-for-layout.rs:15:18 | ||
| | ||
LL | pub type F = impl Coroutine<(), Yield = (), Return = ()>; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
note: ...which requires computing the opaque types defined by `A`... | ||
--> $DIR/metadata-sufficient-for-layout.rs:24:1 | ||
| | ||
LL | static A: Option<helper::F> = None; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
= note: ...which again requires computing type of `A`, completing the cycle | ||
note: cycle used when checking that `A` is well-formed | ||
--> $DIR/metadata-sufficient-for-layout.rs:24:1 | ||
| | ||
LL | static A: Option<helper::F> = None; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0391`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@oli-obk is it okay for this to cycle-error? Having the type of a static depend on its value does seem quite cursed.^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is a static's type meaningfully different from a function's return type? Because it's not about its evaluated value, but just how opaque types work.
I don't think this use case is particularly unusual and expect people will want to be using TAITs like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm... not really, the problem is just that the constraint on the type cannot be so easily expressed as a trait query. For return types it's
T: Sized
, but for static types it's...T: Pointee<Metadata = ()>
or so?