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 feature names to begin with numbers #1331

Merged
merged 2 commits into from
Apr 9, 2018

Conversation

sgrif
Copy link
Contributor

@sgrif sgrif commented Apr 7, 2018

Diesel 1.2 had planned on renaming our large-tables and huge-tables
features to 32-column-tables and 64-column-tables respectively,
while also introducing the 128-column-tables feature. This change was
made several months ago in Diesel. Cargo will happily accept those
as feature names, and resolve them properly from other crates.

However while publishing Diesel 1.2, I ran into a snag mid-release when
I realized that Cargo is incorrectly assuming that a feature name must
be the same as a crate name. I suspect this is an artifact of the fact
that feature names often are crate names (and perhaps in the past that
was the only form of feature?).

However, now they are an entirely separate thing, and we should allow
the same set of feature names that Cargo does. (As an aside, do we want
to apply the same 64 character limit that we apply to crate names to
feature names?)

Fixes #1329.

Diesel 1.2 had planned on renaming our `large-tables` and `huge-tables`
features to `32-column-tables` and `64-column-tables` respectively,
while also introducing the `128-column-tables` feature. This change was
made several months ago in Diesel. Cargo will happily accept those
as feature names, and resolve them properly from other crates.

However while publishing Diesel 1.2, I ran into a snag mid-release when
I realized that Cargo is incorrectly assuming that a feature name must
be the same as a crate name. I suspect this is an artifact of the fact
that feature names often are crate names (and perhaps in the past that
was the only form of feature?).

However, now they are an entirely separate thing, and we should allow
the same set of feature names that Cargo does. (As an aside, do we want
to apply the same 64 character limit that we apply to crate names to
feature names?)

Fixes rust-lang#1329.
@sgrif sgrif force-pushed the sg-allow-features-with-numbers branch from 711f849 to 4bf9efa Compare April 7, 2018 20:33
@sgrif
Copy link
Contributor Author

sgrif commented Apr 7, 2018

The workaround we had to do (putting an x in front of all the feature names) is super ugly, so if we are able to land this somewhat quickly I'd really appreciate it.

@carols10cents
Copy link
Member

Before merging this, I'd like to make sure we're not removing an important restriction... but this restriction is from before my time.

@alexcrichton do you recall why feature names have to be valid crate names (and have the restriction that they not start with a number)?

It looks like valid_feature_name was added with these restrictions in 2014: d64528f in response to this bug: rust-lang/cargo#963

@carols10cents
Copy link
Member

Cargo is incorrectly assuming that a feature name must be the same as a crate name.

To be clear, I don't think the current code is checking that the feature name is that of an existing crate, I think the code is checking that a valid feature name has the same restrictions as valid crate names.

@alexcrichton
Copy link
Member

Crate names needed to not start with a number in the sense that they're Rust identifiers, and IIRC it was just easy to use the same validation for feature names. AFAIK feature names are always specified as strings or not interpreted in an identifier context so it should be fine to allow things like numbers out in front.

@carols10cents
Copy link
Member

Thanks @alexcrichton! I'm good with this then. Will comment again when I've got this deployed to prod.

bors: r+

bors-voyager bot added a commit that referenced this pull request Apr 9, 2018
1331: Allow feature names to begin with numbers r=carols10cents

Diesel 1.2 had planned on renaming our `large-tables` and `huge-tables`
features to `32-column-tables` and `64-column-tables` respectively,
while also introducing the `128-column-tables` feature. This change was
made several months ago in Diesel. Cargo will happily accept those
as feature names, and resolve them properly from other crates.

However while publishing Diesel 1.2, I ran into a snag mid-release when
I realized that Cargo is incorrectly assuming that a feature name must
be the same as a crate name. I suspect this is an artifact of the fact
that feature names often are crate names (and perhaps in the past that
was the only form of feature?).

However, now they are an entirely separate thing, and we should allow
the same set of feature names that Cargo does. (As an aside, do we want
to apply the same 64 character limit that we apply to crate names to
feature names?)

Fixes #1329.
@bors-voyager
Copy link
Contributor

bors-voyager bot commented Apr 9, 2018

Build succeeded

@bors-voyager bors-voyager bot merged commit cd8be67 into rust-lang:master Apr 9, 2018
@carols10cents
Copy link
Member

Deployed, and I was able to publish a crate with a feature that starts with a number!

@sgrif sgrif deleted the sg-allow-features-with-numbers branch April 13, 2018 15:16
bors added a commit that referenced this pull request May 15, 2020
Permit '+' in feature name, as in "c++20"

Up front: I am familiar with the several discussions linked by rust-lang/crates-io-cargo-teams#41 (comment), and the conversation beginning at #1331 (comment). This PR is not motivated by attempting to match whatever behavior Cargo currently has. Instead, it's a small thing I think we can decide now whether to allow. But it's necessary to say no corresponding Cargo change is required to accommodate this crates.io change.

This PR updates feature validation during publish to accept e.g. "c++20" and "dependency/c++20". We continue to not accept "c++20/feature" as the prefix before the slash would normally refer to a crate name of a dependency and a '+' would not be allowed in those.

I am interested in using such feature names in https://github.com/dtolnay/cxx.

In a Cargo.toml plusses appear as:

```toml
[features]
default = ["c++20"]
"c++20" = ["my-dependency/c++20"]
```

To give some slight further justification for why this particular ascii character above other possible characters we might allow: `+` is pretty common in OS package names in a way that no other currently disallowed character is. Some examples pulled arbitrarily from `apt-cache pkgnames | rg '\+'`:

- https://packages.debian.org/buster/dvd+rw-tools
- https://packages.debian.org/buster/elpa-ghub+
- https://packages.debian.org/buster/libarpack++2-dev
- https://packages.debian.org/buster/libdwarf++0
- https://packages.debian.org/buster/libelf++0
- https://packages.debian.org/buster/magics++
- https://packages.debian.org/buster/memtest86+
- https://packages.debian.org/buster/minisat+
- https://packages.debian.org/buster/paw++
- https://packages.debian.org/buster/swish++
- https://packages.debian.org/buster/vera++
- https://packages.debian.org/buster/voro++

The actual names of the projects contain `+`; various ones in the descriptions in the above links are styled as ARPACK++, Memtest86+, Magics++, Paw++, MinSat+, SWISH++, Vera++, Voro++. When binding to something like this behind a feature, using `+` in the feature name is the most intuitive.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

crates.io is incorrectly disallowing feature names that start with numbers
3 participants