Skip to content

Never type impls - #6451

Draft
Person-93 wants to merge 7 commits into
PyO3:mainfrom
Person-93:never_type_impls
Draft

Person-93 wants to merge 7 commits into
PyO3:mainfrom
Person-93:never_type_impls

Conversation

@Person-93

Copy link
Copy Markdown
Contributor

With the never type stabilized in rust 1.100 we can add trait impls for it and use the never-say-never trick to make it work in older rust versions.

Comment thread src/conversion.rs Outdated
@Person-93

Copy link
Copy Markdown
Contributor Author

@davidhewitt do you know what might be causing the compiler errors about conflicting implementations from the pyclass macro? https://github.com/PyO3/pyo3/actions/runs/35962300436/job/107513513485?pr=6451#step:14:261

@Person-93
Person-93 marked this pull request as draft September 24, 2026 06:12
@mejrs

mejrs commented Sep 24, 2026

Copy link
Copy Markdown
Member

We already have impls for Infallible, which is an alias for !.

@Tpt

Tpt commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

+1 to @mejrs. In 1.100 Infallible is an alias for ! so I guess we can just implement traits for Infallible and get something that works for ! in 1.100+

@mejrs

mejrs commented Sep 24, 2026

Copy link
Copy Markdown
Member

The major difference is that Infallible doesn't spontaneously coerce into anything (prior to it being aliased with rust 1.100) because empty enums do not have the same coercion behavior as !. This means you (and users) might have to insert a bunch of match never {} blocks here and there.

I think I would prefer that over the conditional compilation and the never say never hack

@Person-93

Copy link
Copy Markdown
Contributor Author

I think I would prefer that over the conditional compilation and the never say never hack

Prior to never type stabilization I'd have agreed with you. It relied on a compiler bug which might be fixed in future versions. But with the conditional compilation, we are not relying on it in future versions.

@davidhewitt davidhewitt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It certainly seems like the current implementation has issues on MSRV; perhaps let's just implement only for 1.100+ once that releases?

Comment thread src/err/mod.rs Outdated

This branch has not been deployed

No deployments
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.

4 participants