Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c1a79d8

Browse files
committed
Suppress redundant listing of unstable library features used on nightly
On nightly, there's a suggestion/help containing the `#![feature(..)]` attribute required to enable any required unstable features, so the note listing the features is unnecessary. This only applies to const-unstable and default-body-unstable errors. Normal "use of unstable library feature" errors list the features in the error message, so it doesn't feel redundant.
1 parent 5a2346a commit c1a79d8

File tree

15 files changed

+49
-29
lines changed

15 files changed

+49
-29
lines changed

‎compiler/rustc_const_eval/src/check_consts/ops.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,8 @@ impl<'tcx> NonConstOp<'tcx> for FnCallUnstable {
329329
ccx.dcx().create_err(errors::UnstableConstFn {
330330
span,
331331
def_path: ccx.tcx.def_path_str(self.def_id),
332-
features: stability::unstable_message(&self.features, self.reason.to_opt_reason()),
332+
features: stability::unstable_message(&self.features, self.reason.to_opt_reason())
333+
.hide_features_on_nightly(&ccx.tcx.sess),
333334
issues: stability::unstable_issues(&self.features),
334335
nightly_subdiags: stability::unstable_nightly_subdiags(
335336
&ccx.tcx.sess,
@@ -380,7 +381,8 @@ impl<'tcx> NonConstOp<'tcx> for IntrinsicUnstable {
380381
ccx.dcx().create_err(errors::UnstableIntrinsic {
381382
span,
382383
name: self.name,
383-
features: stability::unstable_message(&self.features, self.reason.to_opt_reason()),
384+
features: stability::unstable_message(&self.features, self.reason.to_opt_reason())
385+
.hide_features_on_nightly(&ccx.tcx.sess),
384386
issues: stability::unstable_issues(&self.features),
385387
nightly_subdiags: stability::unstable_nightly_subdiags(
386388
&ccx.tcx.sess,

‎compiler/rustc_const_eval/src/errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ pub(crate) struct UnstableConstFn {
120120
pub span: Span,
121121
pub def_path: String,
122122
#[subdiagnostic]
123-
pub features: rustc_middle::error::UnstableLibraryFeatureNote,
123+
pub features: Option<rustc_middle::error::UnstableLibraryFeatureNote>,
124124
#[subdiagnostic]
125125
pub issues: Vec<rustc_middle::error::UnstableLibraryFeatureIssue>,
126126
#[subdiagnostic]
@@ -134,7 +134,7 @@ pub(crate) struct UnstableIntrinsic {
134134
pub span: Span,
135135
pub name: Symbol,
136136
#[subdiagnostic]
137-
pub features: rustc_middle::error::UnstableLibraryFeatureNote,
137+
pub features: Option<rustc_middle::error::UnstableLibraryFeatureNote>,
138138
#[subdiagnostic]
139139
pub issues: Vec<rustc_middle::error::UnstableLibraryFeatureIssue>,
140140
#[subdiagnostic]

‎compiler/rustc_hir_analysis/src/check/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,10 @@ fn default_body_is_unstable(
301301
let inject_span = item_did
302302
.as_local()
303303
.and_then(|id| tcx.crate_level_attribute_injection_span(tcx.local_def_id_to_hir_id(id)));
304-
305304
tcx.dcx().emit_err(errors::MissingTraitItemUnstable {
306305
span: impl_span,
307306
missing_item_name,
308-
features: stability::unstable_message(denials, reason),
307+
features: stability::unstable_message(denials, reason).hide_features_on_nightly(&tcx.sess),
309308
issues: stability::unstable_issues(denials),
310309
nightly_subdiags: stability::unstable_nightly_subdiags(&tcx.sess, denials, inject_span),
311310
});

‎compiler/rustc_hir_analysis/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ pub(crate) struct MissingTraitItemUnstable {
979979
pub span: Span,
980980
pub missing_item_name: Symbol,
981981
#[subdiagnostic]
982-
pub features: rustc_middle::error::UnstableLibraryFeatureNote,
982+
pub features: Option<rustc_middle::error::UnstableLibraryFeatureNote>,
983983
#[subdiagnostic]
984984
pub issues: Vec<rustc_middle::error::UnstableLibraryFeatureIssue>,
985985
#[subdiagnostic]

‎compiler/rustc_middle/messages.ftl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,19 @@ middle_unstable_library_feature_issue =
117117
*[false] {""}
118118
}
119119
120+
middle_unstable_library_feature_note =
121+
{$only_show_reason ->
122+
[true] reason for unstability: {$reason}
123+
*[false] -> use of unstable library {$count ->
124+
[one] feature
125+
*[other] features
126+
} {$features}{STREQ($reason, "") ->
127+
[true] {""}
128+
*[false] : {$reason}
129+
}
130+
}
131+
132+
120133
middle_unstable_library_feature_suggestion_for_allocator_api =
121134
consider wrapping the inner types in tuple
122135

‎compiler/rustc_middle/src/error.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,28 @@ pub struct SoftUnstableLibraryFeature {
199199

200200
/// A note for other diagnostics which report unstable library features
201201
#[derive(Subdiagnostic)]
202-
#[note(middle_unstable_library_feature)]
202+
#[note(middle_unstable_library_feature_note)]
203203
pub struct UnstableLibraryFeatureNote {
204204
pub features: DiagSymbolList,
205205
pub count: usize,
206206
pub reason: String,
207+
pub only_show_reason: bool,
208+
}
209+
210+
impl UnstableLibraryFeatureNote {
211+
/// On nightly, in errors for const-unstable and default-body-unstable items, suppress the
212+
/// feature list, since it's redundant with the `#![feature(...)]` suggestion.
213+
pub fn hide_features_on_nightly(self, sess: &rustc_session::Session) -> Option<Self> {
214+
if sess.is_nightly_build() {
215+
if self.reason.is_empty() {
216+
None
217+
} else {
218+
Some(UnstableLibraryFeatureNote { only_show_reason: true, ..self })
219+
}
220+
} else {
221+
Some(self)
222+
}
223+
}
207224
}
208225

209226
#[derive(Subdiagnostic)]

‎compiler/rustc_middle/src/middle/stability.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ pub fn unstable_message(
118118
features: denials.iter().map(|d| d.feature).collect(),
119119
count: denials.len(),
120120
reason: reason.map(|r| r.to_string()).unwrap_or_default(),
121+
only_show_reason: false,
121122
}
122123
}
123124

@@ -164,7 +165,8 @@ pub fn report_unstable(
164165
suggestions: Vec<UnstableLibraryFeatureSugg>,
165166
span: Span,
166167
) {
167-
let UnstableLibraryFeatureNote { features, count, reason } = unstable_message(denials, reason);
168+
let UnstableLibraryFeatureNote { features, count, reason, .. } =
169+
unstable_message(denials, reason);
168170
let issues = unstable_issues(denials);
169171
let nightly_subdiags = unstable_nightly_subdiags(sess, denials, None);
170172

@@ -186,7 +188,8 @@ pub fn soft_unstable(
186188
reason: Option<Symbol>,
187189
suggestions: Vec<UnstableLibraryFeatureSugg>,
188190
) -> SoftUnstableLibraryFeature {
189-
let UnstableLibraryFeatureNote { features, count, reason } = unstable_message(denials, reason);
191+
let UnstableLibraryFeatureNote { features, count, reason, .. } =
192+
unstable_message(denials, reason);
190193
let mut issues = unstable_issues(denials);
191194
let nightly_subdiags = unstable_nightly_subdiags(sess, denials, None);
192195

‎tests/ui/consts/const-unstable-intrinsic.stderr

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ error: `min_align_of_val` is not yet stable as a const intrinsic
5050
LL | unstable_intrinsic::old_way::min_align_of_val(&x);
5151
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5252
|
53-
= note: use of unstable library feature `unstable`
5453
= note: see issue #42 <https://github.com/rust-lang/rust/issues/42> for more information
5554
= help: add `#![feature(unstable)]` to the crate attributes to enable
5655
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
@@ -69,7 +68,6 @@ error: `min_align_of_val` is not yet stable as a const intrinsic
6968
LL | unstable_intrinsic::new_way::min_align_of_val(&x);
7069
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7170
|
72-
= note: use of unstable library feature `unstable`
7371
= note: see issue #42 <https://github.com/rust-lang/rust/issues/42> for more information
7472
= help: add `#![feature(unstable)]` to the crate attributes to enable
7573
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

‎tests/ui/stability-attribute/const-stability-attribute-implies-no-feature.stderr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ error: `foobar` is not yet stable as a const fn
44
LL | foobar();
55
| ^^^^^^^^
66
|
7-
= note: use of unstable library feature `const_foobar`
87
= note: see issue #1 <https://github.com/rust-lang/rust/issues/1> for more information
98
= help: add `#![feature(const_foobar)]` to the crate attributes to enable
109
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

‎tests/ui/stability-attribute/default-body-stability-err.stderr

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ LL | impl JustTrait for Type {}
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: default implementation of `CONSTANT` is unstable
8-
= note: use of unstable library feature `constant_default_body`
98
= help: add `#![feature(constant_default_body)]` to the crate attributes to enable
109
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
1110

@@ -16,7 +15,6 @@ LL | impl JustTrait for Type {}
1615
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
1716
|
1817
= note: default implementation of `fun` is unstable
19-
= note: use of unstable library feature `fun_default_body`
2018
= help: add `#![feature(fun_default_body)]` to the crate attributes to enable
2119
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
2220

@@ -27,7 +25,7 @@ LL | impl JustTrait for Type {}
2725
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
2826
|
2927
= note: default implementation of `fun2` is unstable
30-
= note: use of unstable library feature `fun_default_body`: reason
28+
= note: reason for unstability: reason
3129
= help: add `#![feature(fun_default_body)]` to the crate attributes to enable
3230
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
3331

@@ -43,7 +41,6 @@ LL | | }
4341
| |_^
4442
|
4543
= note: default implementation of `eq` is unstable
46-
= note: use of unstable library feature `eq_default_body`
4744
= help: add `#![feature(eq_default_body)]` to the crate attributes to enable
4845
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
4946

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /