Skip to content

Conversation

scottmcm
Copy link
Member

@scottmcm scottmcm commented Jan 8, 2025

This greatly reduces the number of places that actually use the rustc_layout_scalar_valid_range_* attributes down to just 3:

library/core\src\ptr\non_null.rs
68:#[rustc_layout_scalar_valid_range_start(1)]

library/core\src\num\niche_types.rs
19:        #[rustc_layout_scalar_valid_range_start($low)]
20:        #[rustc_layout_scalar_valid_range_end($high)]

Everything else -- PAL Nanoseconds, alloc's Cap, niched FDs, etc -- all just wrap those niche_types types.

r? ghost

@rustbot rustbot added O-solid Operating System: SOLID O-unix Operating system: Unix-like O-windows Operating system: Windows S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jan 8, 2025
@rust-log-analyzer

This comment has been minimized.

@scottmcm scottmcm force-pushed the more-mcp807-library-updates branch from 9afba99 to 32606ca Compare January 8, 2025 08:17
@rust-log-analyzer

This comment has been minimized.

@scottmcm scottmcm force-pushed the more-mcp807-library-updates branch from 32606ca to 91c7fde Compare January 8, 2025 08:28
@rust-log-analyzer

This comment has been minimized.

@scottmcm scottmcm force-pushed the more-mcp807-library-updates branch from 91c7fde to 1df19d1 Compare January 9, 2025 02:33
@rust-log-analyzer

This comment has been minimized.

#[derive(Clone, Copy)]
#[repr(transparent)]
#[rustc_layout_scalar_valid_range_start(1)]
#[rustc_nonnull_optimization_guaranteed]
Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't see this attribute in the new code for the non zero integers

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch! Thank you.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, actually, I think it's fine. The inner ones don't need it because they're not exactly the guaranteed ones, rather the NonZero wrapper struct has it:

#[stable(feature = "generic_nonzero", since = "1.79.0")]
#[repr(transparent)]
#[rustc_nonnull_optimization_guaranteed]
#[rustc_diagnostic_item = "NonZero"]
pub struct NonZero<T: ZeroablePrimitive>(T::NonZeroInner);

@scottmcm scottmcm force-pushed the more-mcp807-library-updates branch from 1df19d1 to 6eb893e Compare January 9, 2025 17:49
@rust-log-analyzer

This comment has been minimized.

@scottmcm scottmcm force-pushed the more-mcp807-library-updates branch from 6eb893e to f10ae9d Compare January 10, 2025 06:13
@rust-log-analyzer

This comment has been minimized.

This greatly reduces the number of places that actually use the `rustc_layout_scalar_valid_range_*` attributes down to just 3:
```
library/core\src\ptr\non_null.rs
68:#[rustc_layout_scalar_valid_range_start(1)]

library/core\src\num\niche_types.rs
19:        #[rustc_layout_scalar_valid_range_start($low)]
20:        #[rustc_layout_scalar_valid_range_end($high)]
```

Everything else -- PAL Nanoseconds, alloc's `Cap`, niched FDs, etc -- all just wrap those `niche_types` types.
@scottmcm scottmcm force-pushed the more-mcp807-library-updates branch from f10ae9d to 6f2a783 Compare January 10, 2025 07:47
@scottmcm
Copy link
Member Author

Yay, finally got through CI 🎉

Hmm, since PAL changes, how about
r? @ChrisDenton

@rustbot ready

@scottmcm scottmcm marked this pull request as ready for review January 10, 2025 19:36
Copy link
Member

@ChrisDenton ChrisDenton left a comment

Choose a reason for hiding this comment

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

This looks great! And thanks to juntyr for reviewing too.

Comment on lines +54 to +56
/// 100% perma-unstable
#[doc(hidden)]
pub mod niche_types;
Copy link
Member

Choose a reason for hiding this comment

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

It's a shame there isn't a way to say "this is pub only for alloc/std". But I guess having it be unstable is good enough.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, there's a bunch of issue = "none" stuff so that alloc and core can both use it :/

impl $name {
#[inline]
pub const unsafe fn new_unchecked(val: $int) -> Self {
// SAFETY: same precondition
Copy link
Member

@ChrisDenton ChrisDenton Jan 10, 2025

Choose a reason for hiding this comment

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

It's kinda weird to write "same precondition" here as it isn't entirely clear what "same" is referring to. In any case, I think a bit of repetition here would be fine. Especially if things get moved around in the future.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, especially now that it's used cross-crates. (An earlier version of this it was pub(super) and I didn't care as much.) Put proper /// docs and SAFETY on it.

@ChrisDenton
Copy link
Member

Thanks!

@bors r+

@bors
Copy link
Collaborator

bors commented Jan 11, 2025

📌 Commit ebd6d3f has been approved by ChrisDenton

It is now in the queue for this repository.

@bors bors removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 11, 2025
@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jan 11, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 11, 2025
Rollup of 6 pull requests

Successful merges:

 - rust-lang#134074 (bootstrap: `std::io::ErrorKind::CrossesDevices` is finally stable)
 - rust-lang#135236 (Update a bunch of library types for MCP807)
 - rust-lang#135301 (re-add a warning for old master branch, but with much simpler logic)
 - rust-lang#135324 (Initial fs module for uefi)
 - rust-lang#135326 (support target specific `optimized-compiler-builtins`)
 - rust-lang#135347 (Use `NonNull::without_provenance` within the standard library)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 351e618 into rust-lang:master Jan 11, 2025
6 checks passed
@rustbot rustbot added this to the 1.86.0 milestone Jan 11, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jan 11, 2025
Rollup merge of rust-lang#135236 - scottmcm:more-mcp807-library-updates, r=ChrisDenton

Update a bunch of library types for MCP807

This greatly reduces the number of places that actually use the `rustc_layout_scalar_valid_range_*` attributes down to just 3:
```
library/core\src\ptr\non_null.rs
68:#[rustc_layout_scalar_valid_range_start(1)]

library/core\src\num\niche_types.rs
19:        #[rustc_layout_scalar_valid_range_start($low)]
20:        #[rustc_layout_scalar_valid_range_end($high)]
```

Everything else -- PAL Nanoseconds, alloc's `Cap`, niched FDs, etc -- all just wrap those `niche_types` types.

r? ghost
@scottmcm scottmcm deleted the more-mcp807-library-updates branch January 12, 2025 00:08
@scottmcm scottmcm mentioned this pull request Jul 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-solid Operating System: SOLID O-unix Operating system: Unix-like O-windows Operating system: Windows S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants