Skip to content

Support constants with arbitrary types#588

Closed
petrochenkov wants to merge 1 commit intomozilla:masterfrom
petrochenkov:consty
Closed

Support constants with arbitrary types#588
petrochenkov wants to merge 1 commit intomozilla:masterfrom
petrochenkov:consty

Conversation

@petrochenkov
Copy link
Copy Markdown
Contributor

When converting const items migrate from whitelist to blacklist approach to the constant's type.
As long as we can convert the right hand side with Literal::load we assume that we can convert the left hand side as well, perhaps using user-defined types defined in the crate.

The one exception is str type.
Despite being able to convert string literals with Literal::load, we cannot convert str.
We can't even introduce an opaque type for it because it's unsized and pointers to it are fat.

Closes #583

@petrochenkov
Copy link
Copy Markdown
Contributor Author

Alternatively, we could just reject string literals on the right side.

That would perhaps be even more robust in the face of cases like

pub type A = &'static str;
pub const C: A = "my string";

@petrochenkov
Copy link
Copy Markdown
Contributor Author

Alternatively, we could just reject string literals on the right side.

That approach is simpler as well.
It's implemented in #589, closing this PR in favor of that.

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.

"Unhandled const definition" on a constant with a type alias (typedef) type

1 participant