Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustc_metadata: minor tidying #131743

Merged
merged 4 commits into from
Oct 18, 2024
Merged

Conversation

tamird
Copy link
Contributor

@tamird tamird commented Oct 15, 2024

Cleaned up some code while investigating #131720.

See individual commits.

This was added in cc3c8bb when it was
closer to the `extract_one` call. Move it back near that call.
@rustbot
Copy link
Collaborator

rustbot commented Oct 15, 2024

r? @lcnr

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

@rustbot rustbot added 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. labels Oct 15, 2024
|| file.starts_with(self.target.dll_prefix.as_ref())
&& file.ends_with(self.target.dll_suffix.as_ref())
{
match file.starts_with("lib").then_some(()).and_then(|()| {
Copy link
Member

Choose a reason for hiding this comment

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

? isn't this just .then

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, because the closure still needs to return Option<T> rather than T.

But this can be .then(...).flatten(). Making that change causes rustfmt to increase indentation, so I've left it as is.

Copy link
Member

@jieyouxu jieyouxu Oct 16, 2024

Choose a reason for hiding this comment

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

To be honest I find this .then_some(()).and_then(|()| { confusing. It looks like this is trying to use the scrutinee closure to select an FxIndexMap to insert the entry into. I find this very convoluted. Can't we just do something straightforward, like jieyouxu@6eba971?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion. I was trying to avoid repeating conditions (your code repeats file_name.starts_with("lib") twice).

I replaced this with a more imperative closure which should be easier to understand. Can you take a look?

Copy link
Member

@jieyouxu jieyouxu Oct 16, 2024

Choose a reason for hiding this comment

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

Frankly, I don't think it's worth avoiding the trivial repetitions if that is what's required, I still find this hard to follow than just doing the simple thing. I let other compiler reviewers decide what they find more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would you mind removing the waiting-on-author label?

Copy link
Member

@jieyouxu jieyouxu Oct 16, 2024

Choose a reason for hiding this comment

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

Would you mind removing the waiting-on-author label?

You can write @rustbot ready to indicate that. cf. https://rustc-dev-guide.rust-lang.org/contributing.html#waiting-for-reviews

@jieyouxu
Copy link
Member

@rustbot author

@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 Oct 16, 2024
@tamird tamird force-pushed the find_commandline_library-tidy branch from dd7b38f to 7bacfb2 Compare October 16, 2024 12:42
@jieyouxu
Copy link
Member

@rustbot ready

@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 Oct 16, 2024
Comment on lines 729 to 758
// FnMut cannot return reference to captured value, so references
// must be taken outside the closure.
let rlibs = &mut rlibs;
let rmetas = &mut rmetas;
let dylibs = &mut dylibs;
match (|| {
if file.starts_with("lib") {
if file.ends_with(".rlib") {
return Some(rlibs);
}
if file.ends_with(".rmeta") {
return Some(rmetas);
}
}
let dll_prefix = self.target.dll_prefix.as_ref();
let dll_suffix = self.target.dll_suffix.as_ref();
if file.starts_with(dll_prefix) && file.ends_with(dll_suffix) {
return Some(dylibs);
}
None
})() {
Some(dst) => {
dst.insert(loc_canon.clone(), PathKind::ExternFlag);
}
None => {
self.crate_rejections
.via_filename
.push(CrateMismatch { path: loc_orig.clone(), got: String::new() });
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I am personally not a fan of matching on a closure, maybe something like this?

            'accept_crate: {
                if file.starts_with("lib") {
                    if file.ends_with(".rlib") {
                        rlibs.insert(loc_canon.clone(), PathKind::ExternFlag);
                        break 'accept_crate;
                    }
                    if file.ends_with(".rmeta") {
                        rmetas.insert(loc_canon.clone(), PathKind::ExternFlag);
                        break 'accept_crate;
                    }
                }
                let dll_prefix = self.target.dll_prefix.as_ref();
                let dll_suffix = self.target.dll_suffix.as_ref();
                if file.starts_with(dll_prefix) && file.ends_with(dll_suffix) {
                     dylibs.insert(loc_canon.clone(), PathKind::ExternFlag);
                     break 'accept_crate;
                }
                
                self.crate_rejections
                        .via_filename
                        .push(CrateMismatch { path: loc_orig.clone(), got: String::new() });
           };

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's fragile because removing any break would produce incorrect logic. I've assigned the result to a local variable, do you like that better?

@tamird tamird force-pushed the find_commandline_library-tidy branch from 7bacfb2 to 94a2be9 Compare October 17, 2024 15:13
@lcnr
Copy link
Contributor

lcnr commented Oct 17, 2024

good enough 😁

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Oct 17, 2024

📌 Commit 94a2be9 has been approved by lcnr

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 Oct 17, 2024
jhpratt added a commit to jhpratt/rust that referenced this pull request Oct 18, 2024
…dy, r=lcnr

rustc_metadata: minor tidying

Cleaned up some code while investigating rust-lang#131720.

See individual commits.
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 18, 2024
Rollup of 5 pull requests

Successful merges:

 - rust-lang#130136 (Partially stabilize const_pin)
 - rust-lang#131654 (Various fixes for Xous)
 - rust-lang#131743 (rustc_metadata: minor tidying)
 - rust-lang#131823 (Bump libc to 0.2.161)
 - rust-lang#131850 (Missing parenthesis)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 18, 2024
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#131654 (Various fixes for Xous)
 - rust-lang#131743 (rustc_metadata: minor tidying)
 - rust-lang#131823 (Bump libc to 0.2.161)
 - rust-lang#131850 (Missing parenthesis)
 - rust-lang#131857 (Allow dropping dyn principal)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 02cc3a6 into rust-lang:master Oct 18, 2024
6 checks passed
@rustbot rustbot added this to the 1.84.0 milestone Oct 18, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Oct 18, 2024
Rollup merge of rust-lang#131743 - tamird:find_commandline_library-tidy, r=lcnr

rustc_metadata: minor tidying

Cleaned up some code while investigating rust-lang#131720.

See individual commits.
@tamird tamird deleted the find_commandline_library-tidy branch October 18, 2024 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants