Skip to content

Conversation

@Enselic
Copy link
Member

@Enselic Enselic commented Dec 20, 2025

Start small. If it works well we can increase usage bit by bit as time passes.

My main motivation for doing this is to get rid of the + 1 I otherwise have to add in #150201 on this line:

                crate::directives::line::line_directive(file, zero_based_line_no + 1, &line)

But I think this is a nice general improvement by itself.

Note that we keep using "0" to represent "no specific line" because changing to Option<LineNumber> everywhere is a very noisy and significant change. That can be changed later if wanted, but let's not do it now.

@rustbot
Copy link
Collaborator

rustbot commented Dec 20, 2025

Some changes occurred in src/tools/compiletest

cc @jieyouxu

@rustbot rustbot added A-compiletest Area: The compiletest test runner A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Dec 20, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 20, 2025

r? @jieyouxu

rustbot has assigned @jieyouxu.
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

@Enselic Enselic marked this pull request as draft December 20, 2025 18:21
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 20, 2025
@rust-log-analyzer

This comment has been minimized.

@Enselic Enselic force-pushed the line-no branch 2 times, most recently from 5a015a9 to 334900c Compare December 22, 2025 07:58
@Enselic Enselic changed the title compiletest: Add LineNo newtype to avoid +1 magic here and there compiletest: Add LineNumber newtype to avoid +1 magic here and there Dec 22, 2025
@rust-log-analyzer

This comment has been minimized.

@Enselic
Copy link
Member Author

Enselic commented Dec 22, 2025

I've done some additional verification and code cleanup and am happy with how this works and looks. Ready for review!

@Enselic Enselic marked this pull request as ready for review December 22, 2025 15:34
@rustbot

This comment was marked as off-topic.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 22, 2025
Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

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

Seems good, thanks

View changes since this review

@jieyouxu
Copy link
Member

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Dec 23, 2025

📌 Commit 4dcb9d0 has been approved by jieyouxu

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 23, 2025
Comment on lines 8 to 19
/// Create a LineNumber from a zero-based line index. I.e. if `zero_based`
/// is `0` it means "the first line".
pub(crate) fn from_zero_based(zero_based: usize) -> Self {
// Ensure to panic on overflow.
LineNumber(zero_based.strict_add(1))
}

pub(crate) fn from_one_based(one_based: usize) -> LineNumber {
// You can't pass zero here. Use .none() for "no specific line".
assert!(one_based > 0);
LineNumber(one_based)
}
Copy link
Member

Choose a reason for hiding this comment

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

These constructors seem overly complicated and unnecessary to me.

From what I can tell, every call site would be made much simpler by just calling a single LineNumber::enumerate(..) method that always starts from 1.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep that's a lot nicer, thanks. Done.

@jieyouxu
Copy link
Member

Good point re. the constructors.
@bors r- (since not in a rollup yet).

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Dec 23, 2025
@jieyouxu
Copy link
Member

r? @Zalathar (off review for a few days)

@rustbot rustbot assigned Zalathar and unassigned jieyouxu Dec 23, 2025
@rust-log-analyzer

This comment has been minimized.

Start small. If it works well we can increase usage bit by bit as time
passes.

Note that we keep using "0" to represent "no specific line" because
changing to `Option<LineNumber>` everywhere is much bigger and noisier
change. That can be done later if wanted.
@Zalathar
Copy link
Member

Thanks for the adjustments.

@bors r=Zalathar,jieyouxu

@bors
Copy link
Collaborator

bors commented Dec 23, 2025

📌 Commit ffbb9a5 has been approved by Zalathar,jieyouxu

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 23, 2025
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Dec 23, 2025
compiletest: Add `LineNumber` newtype to avoid `+1` magic here and there

Start small. If it works well we can increase usage bit by bit as time passes.

My main motivation for doing this is to get rid of the `+ 1` I otherwise have to add in rust-lang#150201 on this line:
```rs
                crate::directives::line::line_directive(file, zero_based_line_no + 1, &line)
```
But I think this is a nice general improvement by itself.

Note that we keep using "0" to represent "no specific line" because changing to `Option<LineNumber>` everywhere is a very noisy and significant change. That _can_ be changed later if wanted, but let's not do it now.
bors added a commit that referenced this pull request Dec 23, 2025
…uwer

Rollup of 3 pull requests

Successful merges:

 - #150205 (compiletest: Add `LineNumber` newtype to avoid `+1` magic here and there)
 - #150295 (Fix compilation error in hermit-abi time.rs)
 - #150301 (std: remove unsupported pipe module from VEXos pal)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Dec 23, 2025
…uwer

Rollup of 6 pull requests

Successful merges:

 - #150130 (Support syntax for one-line trait reuse)
 - #150205 (compiletest: Add `LineNumber` newtype to avoid `+1` magic here and there)
 - #150282 (move a ui test to coretests unit test)
 - #150295 (Fix compilation error in hermit-abi time.rs)
 - #150301 (std: remove unsupported pipe module from VEXos pal)
 - #150303 (`target_features::Stability`: tweak docs of `requires_nightly()`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit c0337ca into rust-lang:main Dec 23, 2025
11 checks passed
@rustbot rustbot added this to the 1.94.0 milestone Dec 23, 2025
rust-timer added a commit that referenced this pull request Dec 23, 2025
Rollup merge of #150205 - Enselic:line-no, r=Zalathar,jieyouxu

compiletest: Add `LineNumber` newtype to avoid `+1` magic here and there

Start small. If it works well we can increase usage bit by bit as time passes.

My main motivation for doing this is to get rid of the `+ 1` I otherwise have to add in #150201 on this line:
```rs
                crate::directives::line::line_directive(file, zero_based_line_no + 1, &line)
```
But I think this is a nice general improvement by itself.

Note that we keep using "0" to represent "no specific line" because changing to `Option<LineNumber>` everywhere is a very noisy and significant change. That _can_ be changed later if wanted, but let's not do it now.

impl LineNumber {
/// This represents "no specific line" (used e.g. for implied directives).
pub(crate) const ZERO: Self = Self(0);
Copy link
Contributor

@euclio euclio Dec 23, 2025

Choose a reason for hiding this comment

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

Nit: could call this ANY or similar to better communicate intent. ZERO seems more like an implementation detail

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

Labels

A-compiletest Area: The compiletest test runner A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants