Skip to content

Rip out rustc_layout_scalar_valid_range_* attribute support#155433

Open
oli-obk wants to merge 6 commits intorust-lang:mainfrom
oli-obk:bye-bye-long-attribute
Open

Rip out rustc_layout_scalar_valid_range_* attribute support#155433
oli-obk wants to merge 6 commits intorust-lang:mainfrom
oli-obk:bye-bye-long-attribute

Conversation

@oli-obk
Copy link
Copy Markdown
Contributor

@oli-obk oli-obk commented Apr 17, 2026

And either removes tests for it or replaces the uses with pattern types.

primarily fixes #135996

fixes #147761
fixes #133652

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 17, 2026

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

Some changes occurred to the CTFE machinery

cc @RalfJung, @lcnr

The Miri subtree was changed

cc @rust-lang/miri

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

rust-analyzer is developed in its own repository. If possible, consider making this change to rust-lang/rust-analyzer instead.

cc @rust-lang/rust-analyzer

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann, @JonathanBrouwer

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

Some changes occurred in compiler/rustc_hir/src/attrs

cc @jdonszelmann, @JonathanBrouwer

This PR changes a file inside tests/crashes. If a crash was fixed, please move into the corresponding ui subdir and add 'Fixes #' to the PR description to autoclose the issue upon merge.

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. labels Apr 17, 2026
@rustbot rustbot added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rust-analyzer Relevant to the rust-analyzer team, which will review and decide on the PR/issue. labels Apr 17, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 17, 2026

r? @chenyukang

rustbot has assigned @chenyukang.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 72 candidates
  • Random selection from 18 candidates

@JonathanBrouwer
Copy link
Copy Markdown
Contributor

Happy to review this
Love the branch name 🤣

r? me

Copy link
Copy Markdown
Contributor

@ChayimFriedman2 ChayimFriedman2 left a comment

Choose a reason for hiding this comment

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

Please revert the rust-analyzer changes. r-a needs to support old compilers, and also it doesn't even properly support pattern types yet.

View changes since this review

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 17, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 17, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Apr 17, 2026
@rust-log-analyzer

This comment has been minimized.

@oli-obk oli-obk force-pushed the bye-bye-long-attribute branch from c6053aa to cc13e2c Compare April 17, 2026 19:20
@mejrs
Copy link
Copy Markdown
Contributor

mejrs commented Apr 17, 2026

There is some prose in the dev guide that will no longer apply.

The other complicated safety check is for writes to fields of layout constrained structs (such as NonNull). These are found by looking for the borrow or assignment expression and then visiting the subexpression being borrowed or assigned with a separate visitor.

https://rustc-dev-guide.rust-lang.org/unsafety-checking.html?other-checks-involving-unsafe

@rust-log-analyzer
Copy link
Copy Markdown
Collaborator

The job x86_64-gnu-miri failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
tests/fail/tree_borrows/wildcard/strongly_protected_wildcard.rs ... ok
tests/fail/tree_borrows/wildcard/subtree_internal_relatedness_wildcard.rs ... ok

FAILED TEST: tests/fail/validity/nonzero.rs
command: MIRI_ENV_VAR_TEST="0" MIRI_TEMP="/tmp/miri-uitest-s3k8au" RUST_BACKTRACE="1" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/miri" "--error-format=json" "--sysroot=/checkout/obj/build/x86_64-unknown-linux-gnu/miri-sysroot" "-Dwarnings" "-Dunused" "-Ainternal_features" "-Zui-testing" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/tmp/miri_ui/0/tests/fail/validity" "tests/fail/validity/nonzero.rs" "--edition" "2021"

error: actual output differed from expected
Execute `./miri test --bless` to update `tests/fail/validity/nonzero.stderr` to the actual output
--- tests/fail/validity/nonzero.stderr
+++ <stderr output>
-error: Undefined Behavior: constructing invalid value of type NonZero<i32>: encountered 0, but expected something greater or equal to 1
+error[E0658]: cannot call conditionally-const method `<u32 as core::pat::RangePattern>::sub_one` in constants
   --> tests/fail/validity/nonzero.rs:LL:CC
    |
-LL |     let _x = Some(unsafe { NonZero(0) });
+LL | struct NonZero(std::pat::pattern_type!(u32 is 1..u32::MAX));
-   |                            ^^^^^^^^^^ Undefined Behavior occurred here
+   |                                                  ^^^^^^^^
    |
-   = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
-   = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
+   = note: calls in constants are limited to constant functions, tuple structs and tuple variants
+   = note: see issue #143874 <https://github.com/rust-lang/rust/issues/143874> for more information
+   = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
+   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
 
-note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
+error: `core::pat::RangePattern` is not yet stable as a const trait
+  --> tests/fail/validity/nonzero.rs:LL:CC
+   |
+LL | struct NonZero(std::pat::pattern_type!(u32 is 1..u32::MAX));
+   |                                                  ^^^^^^^^
+   |
+help: add `#![feature(pattern_type_range_trait)]` to the crate attributes to enable
+   |
+LL + #![feature(pattern_type_range_trait)]
+   |
 
-error: aborting due to 1 previous error
+error: aborting due to 2 previous errors
 
+For more information about this error, try `rustc --explain E0658`.

Full unnormalized output:
error[E0658]: cannot call conditionally-const method `<u32 as core::pat::RangePattern>::sub_one` in constants
##[error]  --> tests/fail/validity/nonzero.rs:5:50
   |
LL | struct NonZero(std::pat::pattern_type!(u32 is 1..u32::MAX));
   |                                                  ^^^^^^^^
   |
   = note: calls in constants are limited to constant functions, tuple structs and tuple variants
   = note: see issue #143874 <https://github.com/rust-lang/rust/issues/143874> for more information
   = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error: `core::pat::RangePattern` is not yet stable as a const trait
##[error]  --> tests/fail/validity/nonzero.rs:5:50
   |
LL | struct NonZero(std::pat::pattern_type!(u32 is 1..u32::MAX));
   |                                                  ^^^^^^^^
   |
help: add `#![feature(pattern_type_range_trait)]` to the crate attributes to enable
   |
LL + #![feature(pattern_type_range_trait)]
---

error: `encountered 0, but expected something greater or equal to 1` not found in diagnostics on line 9
##[error] --> tests/fail/validity/nonzero.rs:9:54
  |
9 |     let _x = Some(unsafe { NonZero(0) }); //~ ERROR: encountered 0, but expected something greater or equal to 1
  |                                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected because of this pattern
  |

error: there were 2 unmatched diagnostics
##[error] --> tests/fail/validity/nonzero.rs:5:50
  |
5 | struct NonZero(std::pat::pattern_type!(u32 is 1..u32::MAX));
  |                                                  ^^^^^^^^
  |                                                  |
  |                                                  Error[E0658]: cannot call conditionally-const method `<u32 as core::pat::RangePattern>::sub_one` in constants
  |                                                  Error: `core::pat::RangePattern` is not yet stable as a const trait
  |

full stderr:
error[E0658]: cannot call conditionally-const method `<u32 as core::pat::RangePattern>::sub_one` in constants
##[error]  --> tests/fail/validity/nonzero.rs:5:50
   |
LL | struct NonZero(std::pat::pattern_type!(u32 is 1..u32::MAX));
   |                                                  ^^^^^^^^
   |
   = note: calls in constants are limited to constant functions, tuple structs and tuple variants
   = note: see issue #143874 <https://github.com/rust-lang/rust/issues/143874> for more information
   = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
   = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error: `core::pat::RangePattern` is not yet stable as a const trait
##[error]  --> tests/fail/validity/nonzero.rs:5:50
   |
LL | struct NonZero(std::pat::pattern_type!(u32 is 1..u32::MAX));
   |                                                  ^^^^^^^^
   |
help: add `#![feature(pattern_type_range_trait)]` to the crate attributes to enable
   |
LL + #![feature(pattern_type_range_trait)]
---
Location:
   /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ui_test-0.30.3/src/lib.rs:365

  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ BACKTRACE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
   1: <color_eyre[8a73bc537fa7a2a9]::config::EyreHook>::into_eyre_hook::{closure#0}<unknown>
      at <unknown source file>:<unknown line>
   2: <eyre[e1e165e5419e5e79]::Report>::from_adhoc::<&str><unknown>
      at <unknown source file>:<unknown line>
   3: ui_test[3909027f1e3571c1]::run_tests_generic::<ui_test[3909027f1e3571c1]::default_file_filter, ui[12286ef3bb2f46cb]::run_tests::{closure#1}, alloc[5e7a068fcf27e3f1]::boxed::Box<dyn ui_test[3909027f1e3571c1]::status_emitter::StatusEmitter>><unknown>
      at <unknown source file>:<unknown line>
   4: ui[12286ef3bb2f46cb]::ui<unknown>
      at <unknown source file>:<unknown line>
   5: ui[12286ef3bb2f46cb]::main<unknown>
      at <unknown source file>:<unknown line>
   6: std[1c1fa987ec45fd20]::sys::backtrace::__rust_begin_short_backtrace::<fn() -> core[f59f0f8a5b0f8bce]::result::Result<(), eyre[e1e165e5419e5e79]::Report>, core[f59f0f8a5b0f8bce]::result::Result<(), eyre[e1e165e5419e5e79]::Report>><unknown>
      at <unknown source file>:<unknown line>
   7: std[1c1fa987ec45fd20]::rt::lang_start::<core[f59f0f8a5b0f8bce]::result::Result<(), eyre[e1e165e5419e5e79]::Report>>::{closure#0}<unknown>
      at <unknown source file>:<unknown line>
   8: std[1c1fa987ec45fd20]::rt::lang_start_internal<unknown>
      at <unknown source file>:<unknown line>
   9: main<unknown>
      at <unknown source file>:<unknown line>
  10: __libc_start_main<unknown>
      at <unknown source file>:<unknown line>
  11: _start<unknown>
      at <unknown source file>:<unknown line>

Run with COLORBT_SHOW_HIDDEN=1 environment variable to disable frame filtering.
Run with RUST_BACKTRACE=full to include source snippets.
error: test failed, to rerun pass `--test ui`

Caused by:
  process didn't exit successfully: `/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/ui-68e75f7c489cb44a` (exit status: 1)
Bootstrap failed while executing `test --stage 2 src/tools/miri src/tools/miri/cargo-miri`
Command `/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo test -Zwarnings --target x86_64-unknown-linux-gnu -Zbinary-dep-depinfo -j 4 -Zroot-dir=/checkout --locked --color=always --profile=release --manifest-path /checkout/src/tools/miri/Cargo.toml -- [workdir=/checkout]` failed with exit code 1
Created at: src/bootstrap/src/core/build_steps/tool.rs:191:21
Executed at: src/bootstrap/src/core/build_steps/test.rs:740:19

--- BACKTRACE vvv
   0: <bootstrap::utils::exec::DeferredCommand>::finish_process
             at /checkout/src/bootstrap/src/utils/exec.rs:939:17
   1: <bootstrap::utils::exec::DeferredCommand>::wait_for_output::<&bootstrap::utils::exec::ExecutionContext>
             at /checkout/src/bootstrap/src/utils/exec.rs:831:21
   2: <bootstrap::utils::exec::ExecutionContext>::run
             at /checkout/src/bootstrap/src/utils/exec.rs:741:45
   3: <bootstrap::utils::exec::BootstrapCommand>::run::<&bootstrap::core::builder::Builder>
             at /checkout/src/bootstrap/src/utils/exec.rs:339:27
   4: <bootstrap::core::build_steps::test::Miri as bootstrap::core::builder::Step>::run
             at /checkout/src/bootstrap/src/core/build_steps/test.rs:740:19
   5: <bootstrap::core::builder::Builder>::ensure::<bootstrap::core::build_steps::test::Miri>
             at /checkout/src/bootstrap/src/core/builder/mod.rs:1579:36
   6: <bootstrap::core::build_steps::test::Miri as bootstrap::core::builder::Step>::make_run
             at /checkout/src/bootstrap/src/core/build_steps/test.rs:666:21
   7: <bootstrap::core::builder::StepDescription>::maybe_run
             at /checkout/src/bootstrap/src/core/builder/mod.rs:476:13
   8: bootstrap::core::builder::cli_paths::match_paths_to_steps_and_run
             at /checkout/src/bootstrap/src/core/builder/cli_paths.rs:232:18
   9: <bootstrap::core::builder::Builder>::run_step_descriptions
             at /checkout/src/bootstrap/src/core/builder/mod.rs:1122:9
  10: <bootstrap::core::builder::Builder>::execute_cli
             at /checkout/src/bootstrap/src/core/builder/mod.rs:1101:14
  11: <bootstrap::Build>::build
             at /checkout/src/bootstrap/src/lib.rs:799:25
  12: bootstrap::main
             at /checkout/src/bootstrap/src/bin/main.rs:130:11
  13: <fn() as core::ops::function::FnOnce<()>>::call_once
             at /rustc/ef0fb8a2563200e322fa4419f09f65a63742038c/library/core/src/ops/function.rs:250:5
  14: std::sys::backtrace::__rust_begin_short_backtrace::<fn(), ()>
             at /rustc/ef0fb8a2563200e322fa4419f09f65a63742038c/library/std/src/sys/backtrace.rs:166:18
  15: std::rt::lang_start::<()>::{closure#0}
             at /rustc/ef0fb8a2563200e322fa4419f09f65a63742038c/library/std/src/rt.rs:206:18
  16: <&dyn core::ops::function::Fn<(), Output = i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe as core::ops::function::FnOnce<()>>::call_once
             at /rustc/ef0fb8a2563200e322fa4419f09f65a63742038c/library/core/src/ops/function.rs:287:21
  17: std::panicking::catch_unwind::do_call::<&dyn core::ops::function::Fn<(), Output = i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe, i32>
             at /rustc/ef0fb8a2563200e322fa4419f09f65a63742038c/library/std/src/panicking.rs:581:40
  18: std::panicking::catch_unwind::<i32, &dyn core::ops::function::Fn<(), Output = i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe>
             at /rustc/ef0fb8a2563200e322fa4419f09f65a63742038c/library/std/src/panicking.rs:544:19
  19: std::panic::catch_unwind::<&dyn core::ops::function::Fn<(), Output = i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe, i32>
             at /rustc/ef0fb8a2563200e322fa4419f09f65a63742038c/library/std/src/panic.rs:359:14
  20: std::rt::lang_start_internal::{closure#0}
             at /rustc/ef0fb8a2563200e322fa4419f09f65a63742038c/library/std/src/rt.rs:175:24
  21: std::panicking::catch_unwind::do_call::<std::rt::lang_start_internal::{closure#0}, isize>
             at /rustc/ef0fb8a2563200e322fa4419f09f65a63742038c/library/std/src/panicking.rs:581:40
---
  28: __libc_start_main
  29: _start


Command has failed. Rerun with -v to see more details.
Build completed unsuccessfully in 0:48:38
  local time: Fri Apr 17 20:11:58 UTC 2026
  network time: Fri, 17 Apr 2026 20:11:58 GMT
##[error]Process completed with exit code 1.
##[group]Run echo "disk usage:"

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Apr 18, 2026

☔ The latest upstream changes (presumably #142531) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rust-analyzer Relevant to the rust-analyzer team, which will review and decide on the PR/issue.

Projects

None yet

7 participants