Skip to content

Commit 220bb61

Browse files
committed
Fix diagnostics with errors
1 parent 9b5574f commit 220bb61

File tree

8 files changed

+35
-36
lines changed

8 files changed

+35
-36
lines changed

compiler/rustc_fluent_macro/src/fluent.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -271,17 +271,15 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok
271271
);
272272
});
273273
}
274-
#[cfg(debug_assertions)]
275-
{
276-
// Record variables referenced by these messages so we can produce
277-
// tests in the derive diagnostics to validate them.
278-
let ident = quote::format_ident!("{snake_name}_refs");
279-
let vrefs = variable_references(msg);
280-
constants.extend(quote! {
281-
#[cfg(test)]
282-
pub const #ident: &[&str] = &[#(#vrefs),*];
283-
})
284-
}
274+
275+
// Record variables referenced by these messages so we can produce
276+
// tests in the derive diagnostics to validate them.
277+
let ident = quote::format_ident!("{snake_name}_refs");
278+
let vrefs = variable_references(msg);
279+
constants.extend(quote! {
280+
#[cfg(test)]
281+
pub const #ident: &[&str] = &[#(#vrefs),*];
282+
})
285283
}
286284
}
287285

@@ -348,7 +346,6 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok
348346
.into()
349347
}
350348

351-
#[cfg(debug_assertions)]
352349
fn variable_references<'a>(msg: &Message<&'a str>) -> Vec<&'a str> {
353350
let mut refs = vec![];
354351
if let Some(Pattern { elements }) = &msg.value {

compiler/rustc_hir_analysis/messages.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ hir_analysis_missing_trait_item_suggestion = implement the missing item: `{$snip
137137
138138
hir_analysis_missing_trait_item_unstable = not all trait items implemented, missing: `{$missing_item_name}`
139139
.note = default implementation of `{$missing_item_name}` is unstable
140-
.some_note = use of unstable library feature '{$feature}': {$r}
140+
.some_note = use of unstable library feature '{$feature}': {$reason}
141141
.none_note = use of unstable library feature '{$feature}'
142142
143143
hir_analysis_missing_type_params =

compiler/rustc_macros/src/diagnostics/diagnostic.rs

+6-13
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl<'a> DiagnosticDerive<'a> {
7777
});
7878

7979
let DiagnosticDeriveKind::Diagnostic { handler } = &builder.kind else { unreachable!() };
80-
#[allow(unused_mut)]
80+
8181
let mut imp = structure.gen_impl(quote! {
8282
gen impl<'__diagnostic_handler_sess, G>
8383
rustc_errors::IntoDiagnostic<'__diagnostic_handler_sess, G>
@@ -95,11 +95,8 @@ impl<'a> DiagnosticDerive<'a> {
9595
}
9696
}
9797
});
98-
#[cfg(debug_assertions)]
99-
{
100-
for test in slugs.borrow().iter().map(|s| generate_test(s, &structure)) {
101-
imp.extend(test);
102-
}
98+
for test in slugs.borrow().iter().map(|s| generate_test(s, &structure)) {
99+
imp.extend(test);
103100
}
104101
imp
105102
}
@@ -170,7 +167,6 @@ impl<'a> LintDiagnosticDerive<'a> {
170167
});
171168

172169
let diag = &builder.diag;
173-
#[allow(unused_mut)]
174170
let mut imp = structure.gen_impl(quote! {
175171
gen impl<'__a> rustc_errors::DecorateLint<'__a, ()> for @Self {
176172
#[track_caller]
@@ -187,12 +183,10 @@ impl<'a> LintDiagnosticDerive<'a> {
187183
}
188184
}
189185
});
190-
#[cfg(debug_assertions)]
191-
{
192-
for test in slugs.borrow().iter().map(|s| generate_test(s, &structure)) {
193-
imp.extend(test);
194-
}
186+
for test in slugs.borrow().iter().map(|s| generate_test(s, &structure)) {
187+
imp.extend(test);
195188
}
189+
196190
imp
197191
}
198192
}
@@ -223,7 +217,6 @@ impl Mismatch {
223217

224218
/// Generates a `#[test]` that verifies that all referenced variables
225219
/// exist on this structure.
226-
#[cfg(debug_assertions)]
227220
fn generate_test(slug: &syn::Path, structure: &Structure<'_>) -> TokenStream {
228221
// FIXME: We can't identify variables in a subdiagnostic
229222
for field in structure.variants().iter().flat_map(|v| v.ast().fields.iter()) {

compiler/rustc_passes/src/errors.rs

-8
Original file line numberDiff line numberDiff line change
@@ -1153,14 +1153,6 @@ pub struct UnixSigpipeValues {
11531153
pub span: Span,
11541154
}
11551155

1156-
#[derive(Diagnostic)]
1157-
#[diag(passes_no_main_function, code = "E0601")]
1158-
pub struct NoMainFunction {
1159-
#[primary_span]
1160-
pub span: Span,
1161-
pub crate_name: String,
1162-
}
1163-
11641156
pub struct NoMainErr {
11651157
pub sp: Span,
11661158
pub crate_name: Symbol,

tests/ui/stability-attribute/auxiliary/default_body.rs

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ pub trait JustTrait {
1111
#[rustc_default_body_unstable(feature = "fun_default_body", issue = "none")]
1212
#[stable(feature = "stable_feature", since = "1.0.0")]
1313
fn fun() {}
14+
15+
#[rustc_default_body_unstable(feature = "fun_default_body", issue = "none", reason = "reason")]
16+
#[stable(feature = "stable_feature", since = "1.0.0")]
17+
fn fun2() {}
1418
}
1519

1620
#[rustc_must_implement_one_of(eq, neq)]

tests/ui/stability-attribute/default-body-stability-err.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ struct Type;
1010
impl JustTrait for Type {}
1111
//~^ ERROR not all trait items implemented, missing: `CONSTANT` [E0046]
1212
//~| ERROR not all trait items implemented, missing: `fun` [E0046]
13+
//~| ERROR not all trait items implemented, missing: `fun2` [E0046]
1314

1415
impl Equal for Type {
1516
//~^ ERROR not all trait items implemented, missing: `eq` [E0046]

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

+12-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,18 @@ LL | impl JustTrait for Type {}
1818
= note: use of unstable library feature 'fun_default_body'
1919
= help: add `#![feature(fun_default_body)]` to the crate attributes to enable
2020

21+
error[E0046]: not all trait items implemented, missing: `fun2`
22+
--> $DIR/default-body-stability-err.rs:10:1
23+
|
24+
LL | impl JustTrait for Type {}
25+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
26+
|
27+
= note: default implementation of `fun2` is unstable
28+
= note: use of unstable library feature 'fun_default_body': reason
29+
= help: add `#![feature(fun_default_body)]` to the crate attributes to enable
30+
2131
error[E0046]: not all trait items implemented, missing: `eq`
22-
--> $DIR/default-body-stability-err.rs:14:1
32+
--> $DIR/default-body-stability-err.rs:15:1
2333
|
2434
LL | / impl Equal for Type {
2535
LL | |
@@ -33,6 +43,6 @@ LL | | }
3343
= note: use of unstable library feature 'eq_default_body'
3444
= help: add `#![feature(eq_default_body)]` to the crate attributes to enable
3545

36-
error: aborting due to 3 previous errors
46+
error: aborting due to 4 previous errors
3747

3848
For more information about this error, try `rustc --explain E0046`.

tests/ui/stability-attribute/default-body-stability-ok-impls.rs

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ impl JustTrait for Type {
1212
const CONSTANT: usize = 1;
1313

1414
fn fun() {}
15+
16+
fn fun2() {}
1517
}
1618

1719
impl Equal for Type {

0 commit comments

Comments
 (0)