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

Simplify SimpleType::from_nir for UnionType #213

Closed
wants to merge 2 commits into from
Closed

Simplify SimpleType::from_nir for UnionType #213

wants to merge 2 commits into from

Conversation

scottmcm
Copy link

@scottmcm scottmcm commented Mar 7, 2021

Spotted in crater using a prototype of a has-breaking-changes version of rust-lang/rfcs#3058

TBD whether this change will ever be required, but I think it's a good change even if not.

@scottmcm
Copy link
Author

scottmcm commented Mar 7, 2021

Looks like everything's green except for a clippy failure that's not related to this change.

@steffahn
Copy link

steffahn commented Mar 8, 2021

How about using flat_map instead?

How about using and_then instead?

@Nadrieril
Copy link
Owner

Interesting! Is this because the new Try won't allow conversion from Option to Result<_, NoneType>?
I don't think this is a correct transformation however. If from_nir returns None I want to abort because there was a type error. I realize I should have used an actual error type for that. I'll try that now.

@Nadrieril
Copy link
Owner

The fact that tests passed anyways is because serde_dhall is nowhere near as well-tested as dhall, since it's mostly a facade. Not great though

@Nadrieril
Copy link
Owner

Should be fixed in 846c14f . This should no longer cause a break with the new Try trait

@steffahn
Copy link

steffahn commented Mar 9, 2021

FYI, this is not about the new Try trait actually introducing any breaking changes. Some limited ways to convert option into result with ? were accidentally introduced and there are measures in place that it stays this way with the new try_trait version. The mentioned crater run was done with a version not including these measures and doesn't represent any actual problems arising from the code that's being “fixed” by this PR in the future. Nonetheless, conversion of option into result with ? is using an accidentally stabilized feature, so it could count as being quite unidiomatic.

@scottmcm
Copy link
Author

👍 to the change to use an error type.

The main thing here was this:

.map(|v| Ok(Self::from_nir(v)?))

This isn't the only codebase where we've seen that, but it's a subtle mixing of ?-on-Option-in-a-Result-method that wasn't ever supposed to be stabilized, and only works because of inference being cleverer than was realized in the previous Try RFC.

So we're looking to see if we can just remove it (perhaps over an edition). So far it's looking promising, since the error messages would be better and the cases I've found so far have been clearer without the mixing -- either using Result like here, or using Option all the way through like in https://github.com/rust-analyzer/rust-analyzer/pull/7735/files

@scottmcm scottmcm closed this Mar 10, 2021
@scottmcm scottmcm deleted the avoid-mixing-option-and-result branch March 10, 2021 00:24
@Nadrieril
Copy link
Owner

Thanks for spotting that, that was indeed a confusing mix

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.

3 participants