Rollup merge of #107068 - mejrs:use_derive, r=estebank
autoderive Subdiagnostic for AddtoExternBlockSuggestion
This commit is contained in:
commit
c44c60caba
@ -1100,16 +1100,17 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
|||||||
replace_span: self.ending_semi_or_hi(item.span),
|
replace_span: self.ending_semi_or_hi(item.span),
|
||||||
extern_block_suggestion: match sig.header.ext {
|
extern_block_suggestion: match sig.header.ext {
|
||||||
Extern::None => None,
|
Extern::None => None,
|
||||||
Extern::Implicit(start_span) => Some(ExternBlockSuggestion {
|
Extern::Implicit(start_span) => Some(ExternBlockSuggestion::Implicit {
|
||||||
start_span,
|
start_span,
|
||||||
end_span: item.span.shrink_to_hi(),
|
end_span: item.span.shrink_to_hi(),
|
||||||
abi: None,
|
|
||||||
}),
|
|
||||||
Extern::Explicit(abi, start_span) => Some(ExternBlockSuggestion {
|
|
||||||
start_span,
|
|
||||||
end_span: item.span.shrink_to_hi(),
|
|
||||||
abi: Some(abi.symbol_unescaped),
|
|
||||||
}),
|
}),
|
||||||
|
Extern::Explicit(abi, start_span) => {
|
||||||
|
Some(ExternBlockSuggestion::Explicit {
|
||||||
|
start_span,
|
||||||
|
end_span: item.span.shrink_to_hi(),
|
||||||
|
abi: abi.symbol_unescaped,
|
||||||
|
})
|
||||||
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
//! Errors emitted by ast_passes.
|
//! Errors emitted by ast_passes.
|
||||||
|
|
||||||
use rustc_errors::{fluent, AddToDiagnostic, Applicability, Diagnostic, SubdiagnosticMessage};
|
|
||||||
use rustc_macros::{Diagnostic, Subdiagnostic};
|
use rustc_macros::{Diagnostic, Subdiagnostic};
|
||||||
use rustc_span::{Span, Symbol};
|
use rustc_span::{Span, Symbol};
|
||||||
|
|
||||||
@ -207,28 +206,21 @@ pub struct FnWithoutBody {
|
|||||||
pub extern_block_suggestion: Option<ExternBlockSuggestion>,
|
pub extern_block_suggestion: Option<ExternBlockSuggestion>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct ExternBlockSuggestion {
|
#[derive(Subdiagnostic)]
|
||||||
pub start_span: Span,
|
pub enum ExternBlockSuggestion {
|
||||||
pub end_span: Span,
|
#[multipart_suggestion(ast_passes_extern_block_suggestion, applicability = "maybe-incorrect")]
|
||||||
pub abi: Option<Symbol>,
|
Implicit {
|
||||||
}
|
#[suggestion_part(code = "extern {{")]
|
||||||
|
start_span: Span,
|
||||||
impl AddToDiagnostic for ExternBlockSuggestion {
|
#[suggestion_part(code = " }}")]
|
||||||
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
|
end_span: Span,
|
||||||
where
|
},
|
||||||
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
|
#[multipart_suggestion(ast_passes_extern_block_suggestion, applicability = "maybe-incorrect")]
|
||||||
{
|
Explicit {
|
||||||
let start_suggestion = if let Some(abi) = self.abi {
|
#[suggestion_part(code = "extern \"{abi}\" {{")]
|
||||||
format!("extern \"{}\" {{", abi)
|
start_span: Span,
|
||||||
} else {
|
#[suggestion_part(code = " }}")]
|
||||||
"extern {".to_owned()
|
end_span: Span,
|
||||||
};
|
abi: Symbol,
|
||||||
let end_suggestion = " }".to_owned();
|
},
|
||||||
|
|
||||||
diag.multipart_suggestion(
|
|
||||||
fluent::extern_block_suggestion,
|
|
||||||
vec![(self.start_span, start_suggestion), (self.end_span, end_suggestion)],
|
|
||||||
Applicability::MaybeIncorrect,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -88,4 +88,5 @@ ast_passes_ty_alias_without_body =
|
|||||||
ast_passes_fn_without_body =
|
ast_passes_fn_without_body =
|
||||||
free function without a body
|
free function without a body
|
||||||
.suggestion = provide a definition for the function
|
.suggestion = provide a definition for the function
|
||||||
.extern_block_suggestion = if you meant to declare an externally defined function, use an `extern` block
|
|
||||||
|
ast_passes_extern_block_suggestion = if you meant to declare an externally defined function, use an `extern` block
|
||||||
|
Loading…
x
Reference in New Issue
Block a user