Skip to content

Commit 199ee40

Browse files
committed
Move errors
1 parent 48f89e7 commit 199ee40

File tree

3 files changed

+89
-77
lines changed

3 files changed

+89
-77
lines changed

compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ pub mod ambiguity;
22
pub mod call_kind;
33
mod fulfillment_errors;
44
pub mod on_unimplemented;
5+
pub mod on_unimplemented_format;
56
mod overflow;
67
pub mod suggestions;
78

compiler/rustc_trait_selection/src/error_reporting/traits/on_unimplemented.rs

Lines changed: 2 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ use rustc_errors::codes::*;
77
use rustc_errors::{ErrorGuaranteed, struct_span_code_err};
88
use rustc_hir::def_id::{DefId, LocalDefId};
99
use rustc_hir::{AttrArgs, Attribute};
10-
use rustc_macros::LintDiagnostic;
1110
use rustc_middle::bug;
1211
use rustc_middle::ty::print::PrintTraitRefExt as _;
1312
use rustc_middle::ty::{self, GenericArgsRef, GenericParamDefKind, TyCtxt};
1413
use rustc_parse_format::{ParseMode, Parser, Piece, Position};
1514
use rustc_session::lint::builtin::UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES;
16-
use rustc_span::{Ident, Span, Symbol, kw, sym};
15+
use rustc_span::{Span, Symbol, kw, sym};
1716
use tracing::{debug, info};
1817
use {rustc_attr_parsing as attr, rustc_hir as hir};
1918

2019
use super::{ObligationCauseCode, PredicateObligation};
2120
use crate::error_reporting::TypeErrCtxt;
21+
use crate::error_reporting::traits::on_unimplemented_format::errors::*;
2222
use crate::errors::{
2323
EmptyOnClauseInOnUnimplemented, InvalidOnClauseInOnUnimplemented, NoValueInOnUnimplemented,
2424
};
@@ -320,81 +320,6 @@ pub enum AppendConstMessage {
320320
Custom(Symbol, Span),
321321
}
322322

323-
#[derive(LintDiagnostic)]
324-
#[diag(trait_selection_malformed_on_unimplemented_attr)]
325-
#[help]
326-
pub struct MalformedOnUnimplementedAttrLint {
327-
#[label]
328-
pub span: Span,
329-
}
330-
331-
impl MalformedOnUnimplementedAttrLint {
332-
fn new(span: Span) -> Self {
333-
Self { span }
334-
}
335-
}
336-
337-
#[derive(LintDiagnostic)]
338-
#[diag(trait_selection_missing_options_for_on_unimplemented_attr)]
339-
#[help]
340-
pub struct MissingOptionsForOnUnimplementedAttr;
341-
342-
#[derive(LintDiagnostic)]
343-
#[diag(trait_selection_ignored_diagnostic_option)]
344-
pub struct IgnoredDiagnosticOption {
345-
pub option_name: &'static str,
346-
#[label]
347-
pub span: Span,
348-
#[label(trait_selection_other_label)]
349-
pub prev_span: Span,
350-
}
351-
352-
impl IgnoredDiagnosticOption {
353-
fn maybe_emit_warning<'tcx>(
354-
tcx: TyCtxt<'tcx>,
355-
item_def_id: DefId,
356-
new: Option<Span>,
357-
old: Option<Span>,
358-
option_name: &'static str,
359-
) {
360-
if let (Some(new_item), Some(old_item)) = (new, old) {
361-
if let Some(item_def_id) = item_def_id.as_local() {
362-
tcx.emit_node_span_lint(
363-
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
364-
tcx.local_def_id_to_hir_id(item_def_id),
365-
new_item,
366-
IgnoredDiagnosticOption { span: new_item, prev_span: old_item, option_name },
367-
);
368-
}
369-
}
370-
}
371-
}
372-
373-
#[derive(LintDiagnostic)]
374-
#[diag(trait_selection_unknown_format_parameter_for_on_unimplemented_attr)]
375-
#[help]
376-
pub struct UnknownFormatParameterForOnUnimplementedAttr {
377-
argument_name: Symbol,
378-
trait_name: Ident,
379-
}
380-
381-
#[derive(LintDiagnostic)]
382-
#[diag(trait_selection_disallowed_positional_argument)]
383-
#[help]
384-
pub struct DisallowedPositionalArgument;
385-
386-
#[derive(LintDiagnostic)]
387-
#[diag(trait_selection_invalid_format_specifier)]
388-
#[help]
389-
pub struct InvalidFormatSpecifier;
390-
391-
#[derive(LintDiagnostic)]
392-
#[diag(trait_selection_wrapped_parser_error)]
393-
pub struct WrappedParserError {
394-
description: String,
395-
label: String,
396-
}
397-
398323
impl<'tcx> OnUnimplementedDirective {
399324
fn parse(
400325
tcx: TyCtxt<'tcx>,
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
pub mod errors {
2+
use rustc_macros::LintDiagnostic;
3+
use rustc_middle::ty::TyCtxt;
4+
use rustc_session::lint::builtin::UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES;
5+
use rustc_span::Ident;
6+
7+
use super::*;
8+
9+
#[derive(LintDiagnostic)]
10+
#[diag(trait_selection_unknown_format_parameter_for_on_unimplemented_attr)]
11+
#[help]
12+
pub struct UnknownFormatParameterForOnUnimplementedAttr {
13+
pub argument_name: Symbol,
14+
pub trait_name: Ident,
15+
}
16+
17+
#[derive(LintDiagnostic)]
18+
#[diag(trait_selection_disallowed_positional_argument)]
19+
#[help]
20+
pub struct DisallowedPositionalArgument;
21+
22+
#[derive(LintDiagnostic)]
23+
#[diag(trait_selection_invalid_format_specifier)]
24+
#[help]
25+
pub struct InvalidFormatSpecifier;
26+
27+
#[derive(LintDiagnostic)]
28+
#[diag(trait_selection_wrapped_parser_error)]
29+
pub struct WrappedParserError {
30+
pub description: String,
31+
pub label: String,
32+
}
33+
#[derive(LintDiagnostic)]
34+
#[diag(trait_selection_malformed_on_unimplemented_attr)]
35+
#[help]
36+
pub struct MalformedOnUnimplementedAttrLint {
37+
#[label]
38+
pub span: Span,
39+
}
40+
41+
impl MalformedOnUnimplementedAttrLint {
42+
pub fn new(span: Span) -> Self {
43+
Self { span }
44+
}
45+
}
46+
47+
#[derive(LintDiagnostic)]
48+
#[diag(trait_selection_missing_options_for_on_unimplemented_attr)]
49+
#[help]
50+
pub struct MissingOptionsForOnUnimplementedAttr;
51+
52+
#[derive(LintDiagnostic)]
53+
#[diag(trait_selection_ignored_diagnostic_option)]
54+
pub struct IgnoredDiagnosticOption {
55+
pub option_name: &'static str,
56+
#[label]
57+
pub span: Span,
58+
#[label(trait_selection_other_label)]
59+
pub prev_span: Span,
60+
}
61+
62+
impl IgnoredDiagnosticOption {
63+
pub fn maybe_emit_warning<'tcx>(
64+
tcx: TyCtxt<'tcx>,
65+
item_def_id: DefId,
66+
new: Option<Span>,
67+
old: Option<Span>,
68+
option_name: &'static str,
69+
) {
70+
if let (Some(new_item), Some(old_item)) = (new, old) {
71+
if let Some(item_def_id) = item_def_id.as_local() {
72+
tcx.emit_node_span_lint(
73+
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
74+
tcx.local_def_id_to_hir_id(item_def_id),
75+
new_item,
76+
IgnoredDiagnosticOption {
77+
span: new_item,
78+
prev_span: old_item,
79+
option_name,
80+
},
81+
);
82+
}
83+
}
84+
}
85+
}
86+
}

0 commit comments

Comments
 (0)