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

Recursive static with impl Trait errors out early #59631

Closed
oli-obk opened this issue Apr 2, 2019 · 2 comments
Closed

Recursive static with impl Trait errors out early #59631

oli-obk opened this issue Apr 2, 2019 · 2 comments

Comments

@oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Apr 2, 2019

The following code should probably work. (cc @Aaron1011)

#![feature(impl_trait_in_bindings)]
static FOO: impl Copy = &FOO;

fn main() {
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error: non-defining existential type use in defining scope
 --> src/main.rs:2:25
  |
2 | static FOO: impl Copy = &FOO;
  |                         ^^^^ lifetime `'<empty>` is part of concrete type but not used in parameter list of existential type

error: aborting due to previous error

error: Could not compile `playground`.

To learn more, run the command again with --verbose.

@oli-obk oli-obk changed the title Recursive struct with impl Trait errors out early Recursive static with impl Trait errors out early Apr 2, 2019
@jyn514
Copy link
Member

@jyn514 jyn514 commented Jul 7, 2021

Triage: the current error for this is

error[E0391]: cycle detected when computing type of `FOO::{opaque#0}`
 --> src/main.rs:2:13
  |
2 | static FOO: impl Copy = &FOO;
  |             ^^^^^^^^^
  |
note: ...which requires borrow-checking `FOO`...
 --> src/main.rs:2:1
  |
2 | static FOO: impl Copy = &FOO;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires processing `FOO`...
 --> src/main.rs:2:1
  |
2 | static FOO: impl Copy = &FOO;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which requires const checking `FOO`...
 --> src/main.rs:2:1
  |
2 | static FOO: impl Copy = &FOO;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = note: ...which requires computing whether `impl std::marker::Copy` is freeze...
  = note: ...which requires evaluating trait selection obligation `impl std::marker::Copy: std::marker::Freeze`...
  = note: ...which again requires computing type of `FOO::{opaque#0}`, completing the cycle
  = note: cycle used when normalizing `impl std::marker::Copy`

@oli-obk why do you say this should compile? It seems strange that you could have a completely unconstrainted type, FOO has no defining use.

@oli-obk
Copy link
Contributor Author

@oli-obk oli-obk commented Jul 8, 2021

I just assumed that considering that

static FOO: &dyn Sync = &FOO;

compiles, that the impl trait version should compile, too. But we can just make a decision and declare this kind of cyclic static to be irrelevant and thus we can just ignore it. It's in the defining use scope, so it gets revealed, which would cause an infinitely deep reference (&&&&&&&&&&...), so it's not really useful or even well defined.

@oli-obk oli-obk closed this Jul 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants