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

Make str::from_utf8 const fn #84643

Closed
wants to merge 1 commit into from
Closed

Make str::from_utf8 const fn #84643

wants to merge 1 commit into from

Conversation

lf-
Copy link
Contributor

@lf- lf- commented Apr 28, 2021

However: I am not at all confident in the soundness of this
implementation. I am getting around the lack of const align_offset by
writing the alignment myself by casting to usize. However, this is marked
unsafe. After searching the rustc source for why, I found this:

// casting pointers to ints is unsafe in const fn because the const evaluator cannot
// possibly know what the result of various operations like `address / 2` would be
// pointers during const evaluation have no integral address, only an abstract one

And I don't know if an "abstract" address can have binary & applied to it, so I'd like some help with that.

However: I am not at all confident in the soundness of this
implementation. Everything done here is defined but:

```
// casting pointers to ints is unsafe in const fn because the const evaluator cannot
// possibly know what the result of various operations like `address / 2` would be
// pointers during const evaluation have no integral address, only an abstract one
```

And I don't know if an "abstract" address can be &'d.
@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @dtolnay (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 28, 2021
@leonardo-m
Copy link

Perhaps it's better to make align_offset const first (or at the same time).

@lf-
Copy link
Contributor Author

lf- commented Apr 28, 2021

I need to go understand the const evaluator a lot more I think, because the spooky comment is supposedly right after I talked to someone more familiar with that side: there are not integral pointers in the constant evaluator. So this feature might require some kind of compiler support or making it so that align_offset returns usize::MAX for all inputs in constant evaluation mode. I'm not entirely sure what to do given this.

@lf-
Copy link
Contributor Author

lf- commented Apr 28, 2021

It looks like I've wandered straight into a proverbial patch of brambles: #62420 (comment)

@lf- lf- closed this May 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants