From c5870680dbc7f217709836a67de6535d5202aa1c Mon Sep 17 00:00:00 2001 From: Adam Harvey Date: Fri, 29 Nov 2024 08:49:22 -0800 Subject: [PATCH] components: don't infer MSRV based on edition In #9996, we started showing the MSRV based on the edition for crate versions that declare an edition but not a `rust-version` in their manifest. This isn't strictly correct: a crate may require features added later in an edition than in the first Rust version that defined that edition, and showing this as an MSRV implies a level of support that the crate author may not have intended. So, we shouldn't show an MSRV if one isn't declared, but we _can_ show the edition if one of those is defined. Let's do that. Fixes #10103. --- app/components/crate-sidebar.hbs | 18 +++++++----------- app/components/crate-sidebar.module.css | 8 +++----- app/components/edition.hbs | 14 ++++++++++++++ app/components/edition.module.css | 3 +++ app/components/msrv.hbs | 10 ++++++++++ app/components/msrv.module.css | 3 +++ app/components/version-list/row.hbs | 16 +++++++--------- app/components/version-list/row.module.css | 6 ++---- app/models/version.js | 16 ++++++++++------ tests/models/version-test.js | 20 ++++++++++++++++++++ 10 files changed, 79 insertions(+), 35 deletions(-) create mode 100644 app/components/edition.hbs create mode 100644 app/components/edition.module.css create mode 100644 app/components/msrv.hbs create mode 100644 app/components/msrv.module.css diff --git a/app/components/crate-sidebar.hbs b/app/components/crate-sidebar.hbs index d078b5f6790..c588da07336 100644 --- a/app/components/crate-sidebar.hbs +++ b/app/components/crate-sidebar.hbs @@ -17,19 +17,15 @@ - {{#if @version.msrv}} + {{#if @version.rust_version}}
{{svg-jar "rust"}} - - v{{@version.msrv}} - - - "Minimum Supported Rust Version" - {{#if @version.edition}} -
requires Rust Edition {{@version.edition}}
- {{/if}} -
-
+ +
+ {{else if @version.edition}} +
+ {{svg-jar "rust"}} +
{{/if}} diff --git a/app/components/crate-sidebar.module.css b/app/components/crate-sidebar.module.css index c66bdc2f1d6..b432e5f7aa9 100644 --- a/app/components/crate-sidebar.module.css +++ b/app/components/crate-sidebar.module.css @@ -20,6 +20,7 @@ .date, .msrv, +.edition, .license, .bytes { display: flex; @@ -34,16 +35,13 @@ } .date, -.msrv { +.msrv, +.edition { [title], :global(.ember-tooltip-target) { cursor: help; } } -.edition { - margin-top: var(--space-2xs); -} - .license { a { color: var(--main-color); diff --git a/app/components/edition.hbs b/app/components/edition.hbs new file mode 100644 index 00000000000..2ca77a12fce --- /dev/null +++ b/app/components/edition.hbs @@ -0,0 +1,14 @@ + + {{@version.edition}} edition + + + This crate version does not declare a Minimum Supported Rust Version, but + does require the {{@version.edition}} Rust Edition. + +
+ {{@version.editionMsrv}} was the first version of Rust in this edition, + but this crate may require features that were added in later versions of + Rust. +
+
+
\ No newline at end of file diff --git a/app/components/edition.module.css b/app/components/edition.module.css new file mode 100644 index 00000000000..68ea5ee4dbe --- /dev/null +++ b/app/components/edition.module.css @@ -0,0 +1,3 @@ +.edition-msrv { + margin-top: var(--space-2xs); +} diff --git a/app/components/msrv.hbs b/app/components/msrv.hbs new file mode 100644 index 00000000000..35536b9f676 --- /dev/null +++ b/app/components/msrv.hbs @@ -0,0 +1,10 @@ + + v{{@version.msrv}} + + + "Minimum Supported Rust Version" + {{#if @version.edition}} +
requires Rust Edition {{@version.edition}}
+ {{/if}} +
+
\ No newline at end of file diff --git a/app/components/msrv.module.css b/app/components/msrv.module.css new file mode 100644 index 00000000000..c5aae0e7c7d --- /dev/null +++ b/app/components/msrv.module.css @@ -0,0 +1,3 @@ +.edition { + margin-top: var(--space-2xs); +} diff --git a/app/components/version-list/row.hbs b/app/components/version-list/row.hbs index 137a72adc0d..2e77ba1e557 100644 --- a/app/components/version-list/row.hbs +++ b/app/components/version-list/row.hbs @@ -67,17 +67,15 @@ {{#if (or @version.crate_size @version.license @version.featureList)}}
- {{#if @version.msrv}} + {{#if @version.rust_version}} {{svg-jar "rust"}} - v{{@version.msrv}} - - - "Minimum Supported Rust Version" - {{#if @version.edition}} -
requires Rust Edition {{@version.edition}}
- {{/if}} -
+ +
+ {{else if @version.edition}} + + {{svg-jar "rust"}} + {{/if}} diff --git a/app/components/version-list/row.module.css b/app/components/version-list/row.module.css index 63722b01f09..b26ad533c57 100644 --- a/app/components/version-list/row.module.css +++ b/app/components/version-list/row.module.css @@ -205,17 +205,15 @@ .msrv { text-transform: initial; +} +.msrv, .edition { svg { /* this makes the text look a little more aligned with the icon... 🤷 */ margin-bottom: -0.15em; } } -.edition { - margin-top: var(--space-2xs); -} - .bytes { font-variant-numeric: tabular-nums; text-transform: none; diff --git a/app/models/version.js b/app/models/version.js index 1c5e4682ffb..ccac88619d9 100644 --- a/app/models/version.js +++ b/app/models/version.js @@ -50,12 +50,8 @@ export default class Version extends Model { return this.belongsTo('crate').id(); } - get msrv() { - let rustVersion = this.rust_version; - if (rustVersion) { - // add `.0` suffix if the `rust-version` field only has two version components - return /^[^.]+\.[^.]+$/.test(rustVersion) ? `${rustVersion}.0` : rustVersion; - } else if (this.edition === '2018') { + get editionMsrv() { + if (this.edition === '2018') { return '1.31.0'; } else if (this.edition === '2021') { return '1.56.0'; @@ -64,6 +60,14 @@ export default class Version extends Model { } } + get msrv() { + let rustVersion = this.rust_version; + if (rustVersion) { + // add `.0` suffix if the `rust-version` field only has two version components + return /^[^.]+\.[^.]+$/.test(rustVersion) ? `${rustVersion}.0` : rustVersion; + } + } + get isNew() { return Date.now() - this.created_at.getTime() < EIGHT_DAYS; } diff --git a/tests/models/version-test.js b/tests/models/version-test.js index 34601ed9757..3cac01fcc68 100644 --- a/tests/models/version-test.js +++ b/tests/models/version-test.js @@ -32,6 +32,26 @@ module('Model | Version', function (hooks) { assert.false(versions[0].isNew); }); + test('editionMsrv', async function (assert) { + let version = await this.store.createRecord('version'); + assert.strictEqual(version.editionMsrv, undefined); + + version.edition = '2015'; + assert.strictEqual(version.editionMsrv, undefined); + + version.edition = '2018'; + assert.strictEqual(version.editionMsrv, '1.31.0'); + + version.edition = '2021'; + assert.strictEqual(version.editionMsrv, '1.56.0'); + + version.edition = '2024'; + assert.strictEqual(version.editionMsrv, '1.85.0'); + + version.edition = '2027'; + assert.strictEqual(version.editionMsrv, undefined); + }); + test('msrv', async function (assert) { let version = await this.store.createRecord('version'); assert.strictEqual(version.msrv, undefined);