`feature(new_range)` applies to macro expansions and breaks their assumptions
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
#![feature(new_range)] changes the meaning of .. syntax for the entire build, regardless of where the tokens came from. Therefore, it can break macros defined by crates not using new_range. I think it should instead be activated based on the span of the .. token, similar to how edition-specific behaviors are often implemented.
I encountered this while trying to test feature(new_range) in code that uses arcstr::literal_substr!.
Repro
Substitute crate name in the doctest as needed.
//! ```
//! #![feature(new_range, new_range_api)]
//! // should print 5
//! dbg!(playground::example!("hello"));
//! ```
#[macro_export]
macro_rules! example {
($s:literal) => {
$crate::takes_range(0..$s.len())
};
}
pub fn takes_range(range: core::ops::Range<usize>) -> usize {
range.end
}
I expected to see this happen: The use of a macro defined by another crate should successfully compile.
Instead, this happened:
error[E0308]: mismatched types
--> src/lib.rs:6:6
|
8 | dbg!(scratchpad::example!("hello"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| expected `std::ops::Range<usize>`, found `std::range::Range<usize>`
| arguments to this function are incorrect
|
= note: expected struct `std::ops::Range<usize>`
found struct `std::range::Range<usize>`
note: function defined here
--> src/lib.rs:14:8
|
14 | pub fn takes_range(range: core::ops::Range<usize>) -> usize {
| ^^^^^^^^^^^
= note: this error originates in the macro `scratchpad::example` (in Nightly builds, run with -Z macro-backtrace for more info)
help: call `Into::into` on this expression to convert `std::range::Range<usize>` into `std::ops::Range<usize>`
|
8 | dbg!(scratchpad::example!("hello").into());
| +++++++
Meta
rustc --version --verbose:
rustc 1.93.0-nightly (292be5c7c 2025-10-29)
binary: rustc
commit-hash: 292be5c7c05138d753bbd4b30db7a3f1a5c914f7
commit-date: 2025-10-29
host: aarch64-apple-darwin
release: 1.93.0-nightly
LLVM version: 21.1.3
@rustbot label +F-new_range
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the doctest with feature(new_range, new_range_api) and the exported example! macro calling takes_range(0..$s.len()). Trace how the new_range feature interprets the range token from the macro expansion. Done means the example compiles successfully without requiring .into(), while preserving the feature's behavior for local range syntax.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100