Skip to content

Commit 74cddcc

Browse files
authored
components: don't infer MSRV based on edition (#10108)
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.
1 parent dd50738 commit 74cddcc

File tree

10 files changed

+79
-35
lines changed

10 files changed

+79
-35
lines changed

app/components/crate-sidebar.hbs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,15 @@
1717
</span>
1818
</time>
1919

20-
{{#if @version.msrv}}
20+
{{#if @version.rust_version}}
2121
<div local-class="msrv" data-test-msrv>
2222
{{svg-jar "rust"}}
23-
<span>
24-
v{{@version.msrv}}
25-
26-
<EmberTooltip>
27-
&quot;Minimum Supported Rust Version&quot;
28-
{{#if @version.edition}}
29-
<div local-class="edition">requires Rust Edition {{@version.edition}}</div>
30-
{{/if}}
31-
</EmberTooltip>
32-
</span>
23+
<Msrv @version={{@version}} />
24+
</div>
25+
{{else if @version.edition}}
26+
<div local-class="edition" data-test-edition>
27+
{{svg-jar "rust"}}
28+
<Edition @version={{@version}} />
3329
</div>
3430
{{/if}}
3531

app/components/crate-sidebar.module.css

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
.date,
2222
.msrv,
23+
.edition,
2324
.license,
2425
.bytes {
2526
display: flex;
@@ -34,16 +35,13 @@
3435
}
3536

3637
.date,
37-
.msrv {
38+
.msrv,
39+
.edition {
3840
[title], :global(.ember-tooltip-target) {
3941
cursor: help;
4042
}
4143
}
4244

43-
.edition {
44-
margin-top: var(--space-2xs);
45-
}
46-
4745
.license {
4846
a {
4947
color: var(--main-color);

app/components/edition.hbs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<span>
2+
{{@version.edition}} edition
3+
4+
<EmberTooltip>
5+
This crate version does not declare a Minimum Supported Rust Version, but
6+
does require the {{@version.edition}} Rust Edition.
7+
8+
<div local-class="edition-msrv">
9+
{{@version.editionMsrv}} was the first version of Rust in this edition,
10+
but this crate may require features that were added in later versions of
11+
Rust.
12+
</div>
13+
</EmberTooltip>
14+
</span>

app/components/edition.module.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.edition-msrv {
2+
margin-top: var(--space-2xs);
3+
}

app/components/msrv.hbs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<span>
2+
v{{@version.msrv}}
3+
4+
<EmberTooltip>
5+
&quot;Minimum Supported Rust Version&quot;
6+
{{#if @version.edition}}
7+
<div local-class="edition">requires Rust Edition {{@version.edition}}</div>
8+
{{/if}}
9+
</EmberTooltip>
10+
</span>

app/components/msrv.module.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.edition {
2+
margin-top: var(--space-2xs);
3+
}

app/components/version-list/row.hbs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,15 @@
6767

6868
{{#if (or @version.crate_size @version.license @version.featureList)}}
6969
<div local-class="metadata-row">
70-
{{#if @version.msrv}}
70+
{{#if @version.rust_version}}
7171
<span local-class="msrv">
7272
{{svg-jar "rust"}}
73-
v{{@version.msrv}}
74-
75-
<EmberTooltip>
76-
&quot;Minimum Supported Rust Version&quot;
77-
{{#if @version.edition}}
78-
<div local-class="edition">requires Rust Edition {{@version.edition}}</div>
79-
{{/if}}
80-
</EmberTooltip>
73+
<Msrv @version={{@version}} />
74+
</span>
75+
{{else if @version.edition}}
76+
<span local-class="edition">
77+
{{svg-jar "rust"}}
78+
<Edition @version={{@version}} />
8179
</span>
8280
{{/if}}
8381

app/components/version-list/row.module.css

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,17 +205,15 @@
205205

206206
.msrv {
207207
text-transform: initial;
208+
}
208209

210+
.msrv, .edition {
209211
svg {
210212
/* this makes the text look a little more aligned with the icon... 🤷 */
211213
margin-bottom: -0.15em;
212214
}
213215
}
214216

215-
.edition {
216-
margin-top: var(--space-2xs);
217-
}
218-
219217
.bytes {
220218
font-variant-numeric: tabular-nums;
221219
text-transform: none;

app/models/version.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,8 @@ export default class Version extends Model {
5050
return this.belongsTo('crate').id();
5151
}
5252

53-
get msrv() {
54-
let rustVersion = this.rust_version;
55-
if (rustVersion) {
56-
// add `.0` suffix if the `rust-version` field only has two version components
57-
return /^[^.]+\.[^.]+$/.test(rustVersion) ? `${rustVersion}.0` : rustVersion;
58-
} else if (this.edition === '2018') {
53+
get editionMsrv() {
54+
if (this.edition === '2018') {
5955
return '1.31.0';
6056
} else if (this.edition === '2021') {
6157
return '1.56.0';
@@ -64,6 +60,14 @@ export default class Version extends Model {
6460
}
6561
}
6662

63+
get msrv() {
64+
let rustVersion = this.rust_version;
65+
if (rustVersion) {
66+
// add `.0` suffix if the `rust-version` field only has two version components
67+
return /^[^.]+\.[^.]+$/.test(rustVersion) ? `${rustVersion}.0` : rustVersion;
68+
}
69+
}
70+
6771
get isNew() {
6872
return Date.now() - this.created_at.getTime() < EIGHT_DAYS;
6973
}

tests/models/version-test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,26 @@ module('Model | Version', function (hooks) {
3232
assert.false(versions[0].isNew);
3333
});
3434

35+
test('editionMsrv', async function (assert) {
36+
let version = await this.store.createRecord('version');
37+
assert.strictEqual(version.editionMsrv, undefined);
38+
39+
version.edition = '2015';
40+
assert.strictEqual(version.editionMsrv, undefined);
41+
42+
version.edition = '2018';
43+
assert.strictEqual(version.editionMsrv, '1.31.0');
44+
45+
version.edition = '2021';
46+
assert.strictEqual(version.editionMsrv, '1.56.0');
47+
48+
version.edition = '2024';
49+
assert.strictEqual(version.editionMsrv, '1.85.0');
50+
51+
version.edition = '2027';
52+
assert.strictEqual(version.editionMsrv, undefined);
53+
});
54+
3555
test('msrv', async function (assert) {
3656
let version = await this.store.createRecord('version');
3757
assert.strictEqual(version.msrv, undefined);

0 commit comments

Comments
 (0)