2022-08-17 23:51:01 +09:00
|
|
|
//! Errors emitted by ast_passes.
|
|
|
|
|
|
2022-10-03 14:09:05 +01:00
|
|
|
use rustc_errors::{fluent, AddToDiagnostic, Applicability, Diagnostic, SubdiagnosticMessage};
|
2022-09-18 11:45:41 -04:00
|
|
|
use rustc_macros::{Diagnostic, Subdiagnostic};
|
2022-08-18 04:36:57 +09:00
|
|
|
use rustc_span::{Span, Symbol};
|
2022-08-17 23:51:01 +09:00
|
|
|
|
|
|
|
|
use crate::ast_validation::ForbiddenLetReason;
|
|
|
|
|
|
2022-09-18 11:45:41 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(ast_passes_forbidden_let)]
|
2022-08-17 23:51:01 +09:00
|
|
|
#[note]
|
|
|
|
|
pub struct ForbiddenLet {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
#[subdiagnostic]
|
|
|
|
|
pub(crate) reason: ForbiddenLetReason,
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:45:41 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(ast_passes_forbidden_let_stable)]
|
2022-08-29 19:49:30 +02:00
|
|
|
#[note]
|
|
|
|
|
pub struct ForbiddenLetStable {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:45:41 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(ast_passes_forbidden_assoc_constraint)]
|
2022-08-18 04:36:57 +09:00
|
|
|
pub struct ForbiddenAssocConstraint {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:45:41 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(ast_passes_keyword_lifetime)]
|
2022-08-18 04:36:57 +09:00
|
|
|
pub struct KeywordLifetime {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:45:41 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(ast_passes_invalid_label)]
|
2022-08-18 04:36:57 +09:00
|
|
|
pub struct InvalidLabel {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
pub name: Symbol,
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:45:41 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(ast_passes_invalid_visibility, code = "E0449")]
|
2022-08-18 04:36:57 +09:00
|
|
|
pub struct InvalidVisibility {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
2022-10-22 11:07:54 +02:00
|
|
|
#[label(implied)]
|
2022-08-18 04:36:57 +09:00
|
|
|
pub implied: Option<Span>,
|
|
|
|
|
#[subdiagnostic]
|
|
|
|
|
pub note: Option<InvalidVisibilityNote>,
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:47:31 -04:00
|
|
|
#[derive(Subdiagnostic)]
|
2022-08-18 04:36:57 +09:00
|
|
|
pub enum InvalidVisibilityNote {
|
2022-10-22 11:07:54 +02:00
|
|
|
#[note(individual_impl_items)]
|
2022-08-18 04:36:57 +09:00
|
|
|
IndividualImplItems,
|
2022-10-22 11:07:54 +02:00
|
|
|
#[note(individual_foreign_items)]
|
2022-08-18 04:36:57 +09:00
|
|
|
IndividualForeignItems,
|
|
|
|
|
}
|
2022-08-18 16:49:52 +09:00
|
|
|
|
2022-09-18 11:45:41 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(ast_passes_trait_fn_const, code = "E0379")]
|
2022-08-18 16:57:25 +09:00
|
|
|
pub struct TraitFnConst {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
#[label]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
}
|
2022-08-18 17:38:11 +09:00
|
|
|
|
2022-09-18 11:45:41 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(ast_passes_forbidden_lifetime_bound)]
|
2022-08-18 17:38:11 +09:00
|
|
|
pub struct ForbiddenLifetimeBound {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub spans: Vec<Span>,
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:45:41 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(ast_passes_forbidden_non_lifetime_param)]
|
2022-08-18 17:38:11 +09:00
|
|
|
pub struct ForbiddenNonLifetimeParam {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub spans: Vec<Span>,
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:45:41 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(ast_passes_fn_param_too_many)]
|
2022-08-18 18:20:14 +09:00
|
|
|
pub struct FnParamTooMany {
|
2022-08-18 17:38:11 +09:00
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
pub max_num_args: usize,
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:45:41 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(ast_passes_fn_param_c_var_args_only)]
|
2022-08-18 18:20:14 +09:00
|
|
|
pub struct FnParamCVarArgsOnly {
|
2022-08-18 17:38:11 +09:00
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:45:41 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(ast_passes_fn_param_c_var_args_not_last)]
|
2022-08-18 18:20:14 +09:00
|
|
|
pub struct FnParamCVarArgsNotLast {
|
2022-08-18 17:38:11 +09:00
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
}
|
2022-08-18 17:46:01 +09:00
|
|
|
|
2022-09-18 11:45:41 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(ast_passes_fn_param_doc_comment)]
|
2022-08-18 18:20:14 +09:00
|
|
|
pub struct FnParamDocComment {
|
2022-08-18 17:46:01 +09:00
|
|
|
#[primary_span]
|
|
|
|
|
#[label]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:45:41 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(ast_passes_fn_param_forbidden_attr)]
|
2022-08-18 18:20:14 +09:00
|
|
|
pub struct FnParamForbiddenAttr {
|
2022-08-18 17:46:01 +09:00
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
}
|
2022-08-18 18:20:14 +09:00
|
|
|
|
2022-09-18 11:45:41 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(ast_passes_fn_param_forbidden_self)]
|
2022-08-18 18:20:14 +09:00
|
|
|
#[note]
|
|
|
|
|
pub struct FnParamForbiddenSelf {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
#[label]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
}
|
2022-08-19 02:43:01 +09:00
|
|
|
|
2022-09-18 11:45:41 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(ast_passes_forbidden_default)]
|
2022-08-19 02:43:01 +09:00
|
|
|
pub struct ForbiddenDefault {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
#[label]
|
|
|
|
|
pub def_span: Span,
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:45:41 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(ast_passes_assoc_const_without_body)]
|
2022-08-19 02:43:01 +09:00
|
|
|
pub struct AssocConstWithoutBody {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
#[suggestion(code = " = <expr>;", applicability = "has-placeholders")]
|
|
|
|
|
pub replace_span: Span,
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:45:41 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(ast_passes_assoc_fn_without_body)]
|
2022-08-19 02:43:01 +09:00
|
|
|
pub struct AssocFnWithoutBody {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
#[suggestion(code = " {{ <body> }}", applicability = "has-placeholders")]
|
|
|
|
|
pub replace_span: Span,
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:45:41 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(ast_passes_assoc_type_without_body)]
|
2022-08-19 02:43:01 +09:00
|
|
|
pub struct AssocTypeWithoutBody {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
#[suggestion(code = " = <type>;", applicability = "has-placeholders")]
|
|
|
|
|
pub replace_span: Span,
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:45:41 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(ast_passes_const_without_body)]
|
2022-08-19 02:43:01 +09:00
|
|
|
pub struct ConstWithoutBody {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
#[suggestion(code = " = <expr>;", applicability = "has-placeholders")]
|
|
|
|
|
pub replace_span: Span,
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:45:41 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(ast_passes_static_without_body)]
|
2022-08-19 02:43:01 +09:00
|
|
|
pub struct StaticWithoutBody {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
#[suggestion(code = " = <expr>;", applicability = "has-placeholders")]
|
|
|
|
|
pub replace_span: Span,
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:45:41 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(ast_passes_ty_alias_without_body)]
|
2022-08-19 02:43:01 +09:00
|
|
|
pub struct TyAliasWithoutBody {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
#[suggestion(code = " = <type>;", applicability = "has-placeholders")]
|
|
|
|
|
pub replace_span: Span,
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:45:41 -04:00
|
|
|
#[derive(Diagnostic)]
|
2022-10-22 11:07:54 +02:00
|
|
|
#[diag(ast_passes_fn_without_body)]
|
2022-08-19 02:43:01 +09:00
|
|
|
pub struct FnWithoutBody {
|
|
|
|
|
#[primary_span]
|
|
|
|
|
pub span: Span,
|
|
|
|
|
#[suggestion(code = " {{ <body> }}", applicability = "has-placeholders")]
|
|
|
|
|
pub replace_span: Span,
|
|
|
|
|
#[subdiagnostic]
|
|
|
|
|
pub extern_block_suggestion: Option<ExternBlockSuggestion>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub struct ExternBlockSuggestion {
|
|
|
|
|
pub start_span: Span,
|
|
|
|
|
pub end_span: Span,
|
|
|
|
|
pub abi: Option<Symbol>,
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-18 11:45:41 -04:00
|
|
|
impl AddToDiagnostic for ExternBlockSuggestion {
|
2022-10-03 14:09:05 +01:00
|
|
|
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
|
|
|
|
|
where
|
|
|
|
|
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
|
|
|
|
|
{
|
2022-08-19 02:43:01 +09:00
|
|
|
let start_suggestion = if let Some(abi) = self.abi {
|
|
|
|
|
format!("extern \"{}\" {{", abi)
|
|
|
|
|
} else {
|
|
|
|
|
"extern {".to_owned()
|
|
|
|
|
};
|
|
|
|
|
let end_suggestion = " }".to_owned();
|
|
|
|
|
|
|
|
|
|
diag.multipart_suggestion(
|
2022-10-22 11:07:54 +02:00
|
|
|
fluent::extern_block_suggestion,
|
2022-08-19 02:43:01 +09:00
|
|
|
vec![(self.start_span, start_suggestion), (self.end_span, end_suggestion)],
|
|
|
|
|
Applicability::MaybeIncorrect,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|