ast_lowering: use derive more
Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
parent
feeeb11d89
commit
2a4b587a68
1 changed files with 18 additions and 41 deletions
|
@ -1,7 +1,4 @@
|
||||||
use rustc_errors::{
|
use rustc_errors::DiagnosticArgFromDisplay;
|
||||||
fluent, AddToDiagnostic, Applicability, Diagnostic, DiagnosticArgFromDisplay,
|
|
||||||
SubdiagnosticMessage,
|
|
||||||
};
|
|
||||||
use rustc_macros::{Diagnostic, Subdiagnostic};
|
use rustc_macros::{Diagnostic, Subdiagnostic};
|
||||||
use rustc_span::{symbol::Ident, Span, Symbol};
|
use rustc_span::{symbol::Ident, Span, Symbol};
|
||||||
|
|
||||||
|
@ -15,25 +12,15 @@ pub struct GenericTypeWithParentheses {
|
||||||
pub sub: Option<UseAngleBrackets>,
|
pub sub: Option<UseAngleBrackets>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy, Subdiagnostic)]
|
||||||
|
#[multipart_suggestion(ast_lowering::use_angle_brackets, applicability = "maybe-incorrect")]
|
||||||
pub struct UseAngleBrackets {
|
pub struct UseAngleBrackets {
|
||||||
|
#[suggestion_part(code = "<")]
|
||||||
pub open_param: Span,
|
pub open_param: Span,
|
||||||
|
#[suggestion_part(code = ">")]
|
||||||
pub close_param: Span,
|
pub close_param: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AddToDiagnostic for UseAngleBrackets {
|
|
||||||
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
|
|
||||||
where
|
|
||||||
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
|
|
||||||
{
|
|
||||||
diag.multipart_suggestion(
|
|
||||||
fluent::ast_lowering::use_angle_brackets,
|
|
||||||
vec![(self.open_param, String::from("<")), (self.close_param, String::from(">"))],
|
|
||||||
Applicability::MaybeIncorrect,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(ast_lowering::invalid_abi, code = "E0703")]
|
#[diag(ast_lowering::invalid_abi, code = "E0703")]
|
||||||
#[note]
|
#[note]
|
||||||
|
@ -68,30 +55,20 @@ pub struct AssocTyParentheses {
|
||||||
pub sub: AssocTyParenthesesSub,
|
pub sub: AssocTyParenthesesSub,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy, Subdiagnostic)]
|
||||||
pub enum AssocTyParenthesesSub {
|
pub enum AssocTyParenthesesSub {
|
||||||
Empty { parentheses_span: Span },
|
#[multipart_suggestion(ast_lowering::remove_parentheses)]
|
||||||
NotEmpty { open_param: Span, close_param: Span },
|
Empty {
|
||||||
}
|
#[suggestion_part(code = "")]
|
||||||
|
parentheses_span: Span,
|
||||||
impl AddToDiagnostic for AssocTyParenthesesSub {
|
},
|
||||||
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
|
#[multipart_suggestion(ast_lowering::use_angle_brackets)]
|
||||||
where
|
NotEmpty {
|
||||||
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
|
#[suggestion_part(code = "<")]
|
||||||
{
|
open_param: Span,
|
||||||
match self {
|
#[suggestion_part(code = ">")]
|
||||||
Self::Empty { parentheses_span } => diag.multipart_suggestion(
|
close_param: Span,
|
||||||
fluent::ast_lowering::remove_parentheses,
|
},
|
||||||
vec![(parentheses_span, String::new())],
|
|
||||||
Applicability::MaybeIncorrect,
|
|
||||||
),
|
|
||||||
Self::NotEmpty { open_param, close_param } => diag.multipart_suggestion(
|
|
||||||
fluent::ast_lowering::use_angle_brackets,
|
|
||||||
vec![(open_param, String::from("<")), (close_param, String::from(">"))],
|
|
||||||
Applicability::MaybeIncorrect,
|
|
||||||
),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue