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

Add const generic disambiguation #1325

Merged
merged 2 commits into from Jun 24, 2022

Conversation

CohenArthur
Copy link
Member

@CohenArthur CohenArthur commented Jun 20, 2022

Closes #1321

@CohenArthur CohenArthur force-pushed the add-const-generic-disambiguation branch from 8ee8fa1 to 8de8490 Compare June 20, 2022 12:39
@CohenArthur CohenArthur marked this pull request as ready for review June 20, 2022 12:39
At the AST level, we might encounter situations where const generic
arguments are ambiguous: They could be resolved to either a type or a
const expression, as shown in this example:

```rust
let a: Foo<N>; // what is N? A type? A const? The parser doesn't know
```

However, when parsing default expressions for const generic parameters,
we need to be able to disambiguate to const expressions early:

```rust
struct Foo<const N: usize = { M }> {
    /* ... */
}
```

In that code, `M` could be considered ambiguous: Is it a type? a const?
A random non-const variable? What matters is that we disambiguate it to
a const generic argument, so that it errors out appropriately in later
phases of the compiler.

In that case, we need to go from a `ConstArg::Ambiguous("M")` to a
`ConstArg::Clear(IdentifierExpr("M"))`.

In later passes of the compiler, we will also need to disambiguate to
types. But that will be done at the HIR/Resolving level.
@CohenArthur CohenArthur force-pushed the add-const-generic-disambiguation branch from 8de8490 to 7f5ea92 Compare June 24, 2022 13:13
@CohenArthur
Copy link
Member Author

bors r+

@bors
Copy link
Contributor

bors bot commented Jun 24, 2022

Build succeeded:

@bors bors bot merged commit fa57ab9 into Rust-GCC:master Jun 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add way to disambiguate AST::ConstGenericArg early
2 participants