Skip to content

Conversation

@danakj
Copy link
Contributor

@danakj danakj commented Oct 28, 2025

They don't get stored anywhere yet, but this type checks the declarations and diagnoses errors in their form, such as not placing a facet type after impls or a type before it.

@danakj danakj requested a review from a team as a code owner October 28, 2025 15:44
@danakj danakj requested review from dwblaikie and zygoloid and removed request for a team and dwblaikie October 28, 2025 15:44
// CHECK:STDERR: ^~~~~~~
interface Z(T:! type) {
// Self can not appear in a requirement. It can appear in the self-type or in
// an interface parameter.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a rule? I don't recall this one. Do you know why this is disallowed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is #6285, which needs some discussion. There is a TODO in the code where the diagnostic is generated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed this restriction and diagnostic.

// CHECK:STDERR: require T impls Z(Self);
// CHECK:STDERR: ^~~~~~~
// CHECK:STDERR:
require T impls Z(Self);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess eventually the error we want here is that Z is not identified (if I remember correctly). Maybe worth a TODO?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Josh says IIUC we want to be able to require itself, and it should just mean it uses all the require statements that were written above. When there's none then that doesn't work though.

context.decl_introducer_state_stack().Push<Lex::TokenKind::Require>();

auto scope_id = context.scope_stack().PeekNameScopeId();
auto scope_inst_id = context.name_scopes().Get(scope_id).inst_id();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this inst id always valid (eg, in a scope nested within a function scope)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe so, yes.

In this:

interface Y {}

fn F() {
  interface Z {
    require impls Y;
  }
}

The scope inst is the Z decl.

If you meant:

fn F() {
  require impls Y;
}

Then that's a parse error.

}
for (auto self_impls : facet_type_info.self_impls_constraints) {
type_iter.Add(self_impls);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be checking all of these interfaces mention Self, not just that any of them do? Eg require i32 impls X(Self) & Y should probably be invalid.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks

@danakj danakj requested a review from zygoloid October 29, 2025 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants