Skip to content

Commit de23c4e

Browse files
committed
Port trait_selection diagnostics
1 parent 1c8544b commit de23c4e

File tree

5 files changed

+62
-50
lines changed

5 files changed

+62
-50
lines changed
Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
dump_vtable_entries = vtable entries for `{$trait_ref}`: {$entries}
22
3-
unable_to_construct_constant_value_unevaluated_constant = unable to construct a constant value for the unevaluated constant {$unevaluated}
3+
unable_to_construct_constant_value = unable to construct a constant value for the unevaluated constant {$unevaluated}
44
5-
reached_recursion_limit_auto_deref = reached the recursion limit while auto-dereferencing `{$ty}`
6-
deref_recursion_limit_reached = deref recursion limit reached
7-
deref_recursion_limit_reached_help = consider increasing the recursion limit by adding a `#![recursion_limit = "{$suggested_limit}"]` attribute to your crate (`{$crate_name}`)
5+
auto_deref_reached_recursion_limit = reached the recursion limit while auto-dereferencing `{$ty}`
6+
auto_deref_reached_recursion_limit_label = deref recursion limit reached
7+
auto_deref_reached_recursion_limit_help = consider increasing the recursion limit by adding a `#![recursion_limit = "{$suggested_limit}"]` attribute to your crate (`{$crate_name}`)
8+
9+
empty_on_clause_in_rustc_on_unimplemented = empty `on`-clause in `#[rustc_on_unimplemented]`
10+
empty_on_clause_in_rustc_on_unimplemented_label = empty on-clause here
11+
12+
invalid_on_clause_in_rustc_on_unimplemented = invalid `on`-clause in `#[rustc_on_unimplemented]`
13+
invalid_on_clause_in_rustc_on_unimplemented_label = invalid on-clause here
14+
15+
no_value_in_rustc_on_unimplemented = this attribute must have a valid value
16+
no_value_in_rustc_on_unimplemented_label = expected value here
17+
no_value_in_rustc_on_unimplemented_note = "eg `#[rustc_on_unimplemented(message="foo")]`"

compiler/rustc_trait_selection/src/autoderef.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use crate::errors::AutoDerefReachedRecursionLimit;
12
use crate::traits::query::evaluate_obligation::InferCtxtExt;
23
use crate::traits::{self, TraitEngine};
3-
use crate::errors::ReachedRecursionLimitDeref;
44
use rustc_hir as hir;
55
use rustc_infer::infer::InferCtxt;
66
use rustc_middle::ty::{self, TraitRef, Ty, TyCtxt};
@@ -222,7 +222,7 @@ pub fn report_autoderef_recursion_limit_error<'tcx>(tcx: TyCtxt<'tcx>, span: Spa
222222
Limit(0) => Limit(2),
223223
limit => limit * 2,
224224
};
225-
tcx.sess.emit_err(ReachedRecursionLimitDeref {
225+
tcx.sess.emit_err(AutoDerefReachedRecursionLimit {
226226
span,
227227
ty: format!("{:?}", ty),
228228
suggested_limit: suggested_limit.to_string(),
Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use rustc_span::Span;
21
use rustc_macros::SessionDiagnostic;
2+
use rustc_span::Span;
33

44
#[derive(SessionDiagnostic)]
55
#[error(trait_selection::dump_vtable_entries)]
@@ -11,21 +11,46 @@ pub struct DumpVTableEntries {
1111
}
1212

1313
#[derive(SessionDiagnostic)]
14-
#[error(trait_selection::unable_to_construct_constant_value_unevaluated_constant)]
15-
pub struct UnableToConstructConstantValueUnevaluatedConstant {
14+
#[error(trait_selection::unable_to_construct_constant_value)]
15+
pub struct UnableToConstructConstantValue {
1616
#[primary_span]
1717
pub span: Span,
1818
pub unevaluated: String,
1919
}
2020

2121
#[derive(SessionDiagnostic)]
22-
#[help(trait_selection::deref_recursion_limit_reached_help)]
23-
#[error(trait_selection::reached_recursion_limit_auto_deref, code = "E0055")]
24-
pub struct ReachedRecursionLimitDeref {
22+
#[help(trait_selection::auto_deref_reached_recursion_limit_help)]
23+
#[error(trait_selection::auto_deref_reached_recursion_limit, code = "E0055")]
24+
pub struct AutoDerefReachedRecursionLimit {
2525
#[primary_span]
26-
#[label(trait_selection::deref_recursion_limit_reached)]
26+
#[label(trait_selection::auto_deref_reached_recursion_limit_label)]
2727
pub span: Span,
2828
pub ty: String,
2929
pub suggested_limit: String,
3030
pub crate_name: String,
3131
}
32+
33+
#[derive(SessionDiagnostic)]
34+
#[error(trait_selection::empty_on_clause_in_rustc_on_unimplemented, code = "E0232")]
35+
pub struct EmptyOnClauseInOnUnimplemented {
36+
#[primary_span]
37+
#[label(trait_selection::empty_on_clause_in_rustc_on_unimplemented_label)]
38+
pub span: Span
39+
}
40+
41+
#[derive(SessionDiagnostic)]
42+
#[error(trait_selection::invalid_on_clause_in_rustc_on_unimplemented, code = "E0232")]
43+
pub struct InvalidOnClauseInOnUnimplemented {
44+
#[primary_span]
45+
#[label(trait_selection::invalid_on_clause_in_rustc_on_unimplemented_label)]
46+
pub span: Span
47+
}
48+
49+
#[derive(SessionDiagnostic)]
50+
#[error(trait_selection::no_value_in_rustc_on_unimplemented, code = "E0232")]
51+
pub struct NoValueInOnUnimplemented {
52+
#[primary_span]
53+
#[label(trait_selection::no_value_in_rustc_on_unimplemented_label)]
54+
#[note(trait_selection::no_value_in_rustc_on_unimplemented_note)]
55+
pub span: Span
56+
}

compiler/rustc_trait_selection/src/traits/auto_trait.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
use super::*;
55

6-
use crate::errors::UnableToConstructConstantValueUnevaluatedConstant;
6+
use crate::errors::UnableToConstructConstantValue;
77
use crate::infer::region_constraints::{Constraint, RegionConstraintData};
88
use crate::infer::InferCtxt;
99
use crate::traits::project::ProjectAndUnifyResult;
@@ -832,7 +832,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
832832
let tcx = self.tcx;
833833
let def_id = unevaluated.def.did;
834834
let reported = tcx.sess.emit_err(
835-
UnableToConstructConstantValueUnevaluatedConstant {
835+
UnableToConstructConstantValue {
836836
span: tcx.def_span(def_id),
837837
unevaluated: format!("{:?}", unevaluated),
838838
},

compiler/rustc_trait_selection/src/traits/on_unimplemented.rs

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use rustc_parse_format::{ParseMode, Parser, Piece, Position};
88
use rustc_span::symbol::{kw, sym, Symbol};
99
use rustc_span::{Span, DUMMY_SP};
1010

11+
use crate::errors::{EmptyOnClauseInOnUnimplemented, InvalidOnClauseInOnUnimplemented, NoValueInOnUnimplemented};
12+
1113
#[derive(Clone, Debug)]
1214
pub struct OnUnimplementedFormatString(Symbol);
1315

@@ -35,21 +37,6 @@ pub struct OnUnimplementedNote {
3537
pub append_const_msg: Option<Option<Symbol>>,
3638
}
3739

38-
fn parse_error(
39-
tcx: TyCtxt<'_>,
40-
span: Span,
41-
message: &str,
42-
label: &str,
43-
note: Option<&str>,
44-
) -> ErrorGuaranteed {
45-
let mut diag = struct_span_err!(tcx.sess, span, E0232, "{}", message);
46-
diag.span_label(span, label);
47-
if let Some(note) = note {
48-
diag.note(note);
49-
}
50-
diag.emit()
51-
}
52-
5340
impl<'tcx> OnUnimplementedDirective {
5441
fn parse(
5542
tcx: TyCtxt<'tcx>,
@@ -71,23 +58,15 @@ impl<'tcx> OnUnimplementedDirective {
7158
let cond = item_iter
7259
.next()
7360
.ok_or_else(|| {
74-
parse_error(
75-
tcx,
76-
span,
77-
"empty `on`-clause in `#[rustc_on_unimplemented]`",
78-
"empty on-clause here",
79-
None,
80-
)
61+
tcx.sess.emit_err(EmptyOnClauseInOnUnimplemented {
62+
span
63+
})
8164
})?
8265
.meta_item()
8366
.ok_or_else(|| {
84-
parse_error(
85-
tcx,
86-
span,
87-
"invalid `on`-clause in `#[rustc_on_unimplemented]`",
88-
"invalid on-clause here",
89-
None,
90-
)
67+
tcx.sess.emit_err(InvalidOnClauseInOnUnimplemented {
68+
span
69+
})
9170
})?;
9271
attr::eval_condition(cond, &tcx.sess.parse_sess, Some(tcx.features()), &mut |cfg| {
9372
if let Some(value) = cfg.value && let Err(guar) = parse_value(value) {
@@ -150,12 +129,10 @@ impl<'tcx> OnUnimplementedDirective {
150129
}
151130

152131
// nothing found
153-
parse_error(
154-
tcx,
155-
item.span(),
156-
"this attribute must have a valid value",
157-
"expected value here",
158-
Some(r#"eg `#[rustc_on_unimplemented(message="foo")]`"#),
132+
tcx.sess.emit_err(
133+
NoValueInOnUnimplemented {
134+
span: item.span(),
135+
}
159136
);
160137
}
161138

0 commit comments

Comments
 (0)