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

Higher kinded checks are deferred to the time of use #106426

Closed
HKalbasi opened this issue Jan 3, 2023 · 3 comments
Closed

Higher kinded checks are deferred to the time of use #106426

HKalbasi opened this issue Jan 3, 2023 · 3 comments
Labels
T-lang Relevant to the language team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@HKalbasi
Copy link
Member

HKalbasi commented Jan 3, 2023

In this code I will get a compiler error:

struct F where i32: Iterator;
error[[E0277]](https://doc.rust-lang.org/stable/error-index.html#E0277): `i32` is not an iterator
 --> src/main.rs:2:20
  |
2 |     struct F where i32: Iterator;
  |                    ^^^^^^^^^^^^^ `i32` is not an iterator
  |
  = help: the trait `Iterator` is not implemented for `i32`
  = note: if you want to iterate between `start` until a value `end`, use the exclusive range syntax `start..end` or the inclusive range syntax `start..=end`
  = help: see issue #48214

But in this code there is no compiler error:

struct F where for<'a> &'a i32: 'static;

But if I use F, I will get a compiler error:

struct F where for<'a> &'a i32: 'static;
let _x = F;
error: higher-ranked lifetime error
 --> src/main.rs:4:14
  |
4 |     let _x = F;
  |              ^
  |
  = note: could not prove `for<'a> &'a i32: 'static`

error: could not compile `playground` due to previous error

Which is inconsistent behavior. I think either both of them should compile, or both of them should not.

@inquisitivecrystal inquisitivecrystal added T-lang Relevant to the language team, which will review and decide on the PR/issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 4, 2023
@compiler-errors
Copy link
Member

This comment perhaps sheds some light on this inconsistency being (somewhat) intentional: #100090 (comment)

@compiler-errors compiler-errors added T-types Relevant to the types team, which will review and decide on the PR/issue. and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 4, 2023
@HKalbasi
Copy link
Member Author

HKalbasi commented Jan 4, 2023

So after feature trivial_bounds it will become a warning for both cases?

@QuineDot
Copy link

QuineDot commented Feb 6, 2023

With trivial_bounds, the Iterator case would behave similar to the higher-ranked case (able to compile the definition but not to call it due to unsatisfiable bounds). And I believe the idea is both would warn about the unsatisfiable definition, yes.

@HKalbasi HKalbasi closed this as completed Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-lang Relevant to the language team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants