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.

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.
@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.

@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
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-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

6 participants