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

Allow underscore-prefixed renamed dependency in manifest #3724

Merged
merged 4 commits into from
Jun 21, 2021

Conversation

Rustin170506
Copy link
Member

close #3532

@rust-highfive
Copy link

r? @carols10cents

(rust-highfive has picked a reviewer for you, use r? to override)

@Turbo87 Turbo87 added A-backend ⚙️ C-bug 🐞 Category: unintended, undesired behavior labels Jun 19, 2021
@Turbo87
Copy link
Member

Turbo87 commented Jun 20, 2021

👋 @hi-rustin

the issue here is slightly more complicated. crate name generally are not allowed to start with an underscore, so adjusting valid_ident() to allow it could create some problems for us when people suddenly start publishing crates with a leading underscore.

#1487 implemented support for "renamed dependencies", but it looks like we did not test for the "name has a leading underscore" case. I think the first step in fixing this issue is to create a new test, roughly similar to the existing new_with_renamed_dependency() test, but with a leading underscore for the name. That should hopefully reproduce the issue that @jmagnuson is seeing in #3532.

@Rustin170506
Copy link
Member Author

Rustin170506 commented Jun 20, 2021

I think the first step in fixing this issue is to create a new test, roughly similar to the existing new_with_renamed_dependency() test, but with a leading underscore for the name.

@Turbo87 Thanks for the review! Added.

@Rustin170506
Copy link
Member Author

Rustin170506 commented Jun 20, 2021

The test case will fail when there is no such underscore change.

failed to decode: Error("missing field `crate`", line: 1, column: 249)
thread 'krate::publish::new_with_underscore_name_dependency' panicked at 'failed to decode: Error("missing field `crate`", line: 1, column: 249)', src/tests/util/response.rs:111:19
stack backtrace:
   0: rust_begin_unwind
             at /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53/library/std/src/panicking.rs:493:5
   1: std::panicking::begin_panic_fmt
             at /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53/library/std/src/panicking.rs:435:5
   2: all::util::response::json
             at ./src/tests/util/response.rs:111:19
   3: all::util::response::Response<T>::good
             at ./src/tests/util/response.rs:26:9
   4: all::krate::publish::new_with_underscore_name_dependency
             at ./src/tests/krate/publish.rs:187:5
   5: all::krate::publish::new_with_underscore_name_dependency::{{closure}}
             at ./src/tests/krate/publish.rs:174:1
   6: core::ops::function::FnOnce::call_once
             at /Users/rustin/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:227:5
   7: core::ops::function::FnOnce::call_once
             at /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: test failed, to rerun pass '-p cargo-registry --test all'

Process finished with exit code 101

@Rustin170506 Rustin170506 force-pushed the rustin-patch-fix-underscore branch from b8814e4 to b5f0294 Compare June 20, 2021 14:07
@Rustin170506
Copy link
Member Author

I did some local debugging and integration testing to make sure the logic was being tested.

src/tests/krate/publish.rs Outdated Show resolved Hide resolved
@Rustin170506 Rustin170506 force-pushed the rustin-patch-fix-underscore branch 2 times, most recently from 6fcb4b5 to 6fb1ed4 Compare June 20, 2021 16:59
@Rustin170506 Rustin170506 requested a review from Turbo87 June 20, 2021 17:04
@Rustin170506 Rustin170506 force-pushed the rustin-patch-fix-underscore branch from 6fb1ed4 to 2d01423 Compare June 20, 2021 17:12
Copy link
Member

@Turbo87 Turbo87 left a comment

Choose a reason for hiding this comment

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

looks good to me now, but I would like to get a second pair of eyes on this before we merge it.

@pietroalbini @jtgeibel @JohnTitor

@Rustin170506 Rustin170506 changed the title Allow underscore-prefixed dependency in manifest Allow underscore-prefixed renamed dependency in manifest Jun 21, 2021
Copy link
Member

@pietroalbini pietroalbini left a comment

Choose a reason for hiding this comment

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

The code changes themselves look great, but I'd prefer for the internal API to be harder to misuse and misunderstand:

  • The boolean Crate::valid_name("foo", true) or Crate::valid_name("bar" false) is a bit confusing if one doesn't know about this PR. I'd prefer to keep Crate::valid_name the same as before and adding a Crate::valid_dependency_name.
  • EncodableExplicitName is also a bit confusing, it'd be better to call it EncodableDependencyName.

@Rustin170506 Rustin170506 force-pushed the rustin-patch-fix-underscore branch from 2d01423 to cb76a05 Compare June 21, 2021 09:52
@Rustin170506
Copy link
Member Author

Rustin170506 commented Jun 21, 2021

The code changes themselves look great, but I'd prefer for the internal API to be harder to misuse and misunderstand:

* The boolean `Crate::valid_name("foo", true)` or `Crate::valid_name("bar" false)` is a bit confusing if one doesn't know about this PR. I'd prefer to keep `Crate::valid_name` the same as before and adding a `Crate::valid_dependency_name`.

* `EncodableExplicitName` is also a bit confusing, it'd be better to call it `EncodableDependencyName`.

@pietroalbini Addressed! Thanks for your review.

@Rustin170506 Rustin170506 force-pushed the rustin-patch-fix-underscore branch from ee151b3 to 7dfc717 Compare June 21, 2021 09:55
Copy link
Member

@pietroalbini pietroalbini left a comment

Choose a reason for hiding this comment

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

Thanks!

@pietroalbini
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Jun 21, 2021

📌 Commit 7dfc717 has been approved by pietroalbini

@bors
Copy link
Contributor

bors commented Jun 21, 2021

⌛ Testing commit 7dfc717 with merge e5290b7...

@bors
Copy link
Contributor

bors commented Jun 21, 2021

☀️ Test successful - checks-actions
Approved by: pietroalbini
Pushing e5290b7 to master...

@bors bors merged commit e5290b7 into rust-lang:master Jun 21, 2021
@jmagnuson
Copy link

Thank you, @hi-rustin, and everyone who helped get this merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-backend ⚙️ C-bug 🐞 Category: unintended, undesired behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

crates.io denies underscore-prefixed dependency in manifest
7 participants