Rewrite added diagnostics as translatable
Start messages with lowercase
This commit is contained in:
parent
5c5c3c9527
commit
18388c9f73
6 changed files with 61 additions and 14 deletions
|
@ -209,3 +209,13 @@ resolve_indeterminate =
|
||||||
|
|
||||||
resolve_module_only =
|
resolve_module_only =
|
||||||
visibility must resolve to a module
|
visibility must resolve to a module
|
||||||
|
|
||||||
|
resolve_macro_expected_found =
|
||||||
|
expected {$expected}, found {$found} `{$macro_path}`
|
||||||
|
|
||||||
|
resolve_remove_surrounding_derive =
|
||||||
|
remove from the surrounding `derive()`
|
||||||
|
|
||||||
|
resolve_add_as_non_derive =
|
||||||
|
add as non-Derive macro
|
||||||
|
`#[{$macro_path}]`
|
||||||
|
|
|
@ -472,3 +472,30 @@ pub(crate) struct Indeterminate(#[primary_span] pub(crate) Span);
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(resolve_module_only)]
|
#[diag(resolve_module_only)]
|
||||||
pub(crate) struct ModuleOnly(#[primary_span] pub(crate) Span);
|
pub(crate) struct ModuleOnly(#[primary_span] pub(crate) Span);
|
||||||
|
|
||||||
|
#[derive(Diagnostic, Default)]
|
||||||
|
#[diag(resolve_macro_expected_found)]
|
||||||
|
pub(crate) struct MacroExpectedFound<'a> {
|
||||||
|
#[primary_span]
|
||||||
|
pub(crate) span: Span,
|
||||||
|
pub(crate) found: &'a str,
|
||||||
|
pub(crate) expected: &'a str,
|
||||||
|
pub(crate) macro_path: &'a str,
|
||||||
|
#[subdiagnostic]
|
||||||
|
pub(crate) remove_surrounding_derive: Option<RemoveSurroundingDerive>,
|
||||||
|
#[subdiagnostic]
|
||||||
|
pub(crate) remove_surrounding_derive_help: Option<RemoveAddAsNonDerive<'a>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Subdiagnostic)]
|
||||||
|
#[help(resolve_remove_surrounding_derive)]
|
||||||
|
pub(crate) struct RemoveSurroundingDerive {
|
||||||
|
#[primary_span]
|
||||||
|
pub(crate) span: Span,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Subdiagnostic)]
|
||||||
|
#[help(resolve_add_as_non_derive)]
|
||||||
|
pub(crate) struct RemoveAddAsNonDerive<'a> {
|
||||||
|
pub(crate) macro_path: &'a str,
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
//! A bunch of methods and structures more or less related to resolving macros and
|
//! A bunch of methods and structures more or less related to resolving macros and
|
||||||
//! interface provided by `Resolver` to macro expander.
|
//! interface provided by `Resolver` to macro expander.
|
||||||
|
|
||||||
|
use crate::errors::{MacroExpectedFound, RemoveAddAsNonDerive, RemoveSurroundingDerive};
|
||||||
use crate::Namespace::*;
|
use crate::Namespace::*;
|
||||||
use crate::{BuiltinMacroState, Determinacy};
|
use crate::{BuiltinMacroState, Determinacy};
|
||||||
use crate::{DeriveData, Finalize, ParentScope, ResolutionError, Resolver, ScopeSet};
|
use crate::{DeriveData, Finalize, ParentScope, ResolutionError, Resolver, ScopeSet};
|
||||||
|
@ -543,21 +544,30 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
};
|
};
|
||||||
if let Some((article, expected)) = unexpected_res {
|
if let Some((article, expected)) = unexpected_res {
|
||||||
let path_str = pprust::path_to_string(path);
|
let path_str = pprust::path_to_string(path);
|
||||||
let msg = format!("expected {}, found {} `{}`", expected, res.descr(), path_str);
|
|
||||||
let mut err = self.tcx.sess.struct_span_err(path.span, &msg);
|
|
||||||
|
|
||||||
err.span_label(path.span, format!("not {} {}", article, expected));
|
let mut err = MacroExpectedFound {
|
||||||
|
span: path.span,
|
||||||
|
expected,
|
||||||
|
found: res.descr(),
|
||||||
|
macro_path: &path_str,
|
||||||
|
..Default::default() // Subdiagnostics default to None
|
||||||
|
};
|
||||||
|
|
||||||
// Suggest moving the macro out of the derive() as the macro isn't Derive
|
// Suggest moving the macro out of the derive() if the macro isn't Derive
|
||||||
if !path.span.from_expansion()
|
if !path.span.from_expansion()
|
||||||
&& kind == MacroKind::Derive
|
&& kind == MacroKind::Derive
|
||||||
&& ext.macro_kind() != MacroKind::Derive
|
&& ext.macro_kind() != MacroKind::Derive
|
||||||
{
|
{
|
||||||
err.span_help(path.span, "remove from the surrounding `derive()`");
|
err.remove_surrounding_derive = Some(RemoveSurroundingDerive { span: path.span });
|
||||||
err.help(format!("add as non-Derive macro\n`#[{}]`", path_str));
|
err.remove_surrounding_derive_help =
|
||||||
|
Some(RemoveAddAsNonDerive { macro_path: &path_str });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut err = self.tcx.sess.create_err(err);
|
||||||
|
err.span_label(path.span, format!("not {} {}", article, expected));
|
||||||
|
|
||||||
err.emit();
|
err.emit();
|
||||||
|
|
||||||
return Ok((self.dummy_ext(kind), Res::Err));
|
return Ok((self.dummy_ext(kind), Res::Err));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,12 +4,12 @@ error: expected derive macro, found built-in attribute `inline`
|
||||||
LL | #[derive(inline)]
|
LL | #[derive(inline)]
|
||||||
| ^^^^^^ not a derive macro
|
| ^^^^^^ not a derive macro
|
||||||
|
|
|
|
||||||
help: Remove from the surrounding `derive()`
|
help: remove from the surrounding `derive()`
|
||||||
--> $DIR/macro-path-prelude-fail-4.rs:1:10
|
--> $DIR/macro-path-prelude-fail-4.rs:1:10
|
||||||
|
|
|
|
||||||
LL | #[derive(inline)]
|
LL | #[derive(inline)]
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
= help: Add as non-Derive macro
|
= help: add as non-Derive macro
|
||||||
`#[inline]`
|
`#[inline]`
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
|
@ -58,12 +58,12 @@ error: expected derive macro, found attribute macro `my_macro_attr`
|
||||||
LL | #[derive(my_macro_attr)]
|
LL | #[derive(my_macro_attr)]
|
||||||
| ^^^^^^^^^^^^^ not a derive macro
|
| ^^^^^^^^^^^^^ not a derive macro
|
||||||
|
|
|
|
||||||
help: Remove from the surrounding `derive()`
|
help: remove from the surrounding `derive()`
|
||||||
--> $DIR/macro-namespace-reserved-2.rs:53:10
|
--> $DIR/macro-namespace-reserved-2.rs:53:10
|
||||||
|
|
|
|
||||||
LL | #[derive(my_macro_attr)]
|
LL | #[derive(my_macro_attr)]
|
||||||
| ^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^
|
||||||
= help: Add as non-Derive macro
|
= help: add as non-Derive macro
|
||||||
`#[my_macro_attr]`
|
`#[my_macro_attr]`
|
||||||
|
|
||||||
error: can't use a procedural macro from the same crate that defines it
|
error: can't use a procedural macro from the same crate that defines it
|
||||||
|
@ -96,12 +96,12 @@ error: expected derive macro, found macro `crate::my_macro`
|
||||||
LL | #[derive(crate::my_macro)]
|
LL | #[derive(crate::my_macro)]
|
||||||
| ^^^^^^^^^^^^^^^ not a derive macro
|
| ^^^^^^^^^^^^^^^ not a derive macro
|
||||||
|
|
|
|
||||||
help: Remove from the surrounding `derive()`
|
help: remove from the surrounding `derive()`
|
||||||
--> $DIR/macro-namespace-reserved-2.rs:50:10
|
--> $DIR/macro-namespace-reserved-2.rs:50:10
|
||||||
|
|
|
|
||||||
LL | #[derive(crate::my_macro)]
|
LL | #[derive(crate::my_macro)]
|
||||||
| ^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^
|
||||||
= help: Add as non-Derive macro
|
= help: add as non-Derive macro
|
||||||
`#[crate::my_macro]`
|
`#[crate::my_macro]`
|
||||||
|
|
||||||
error: cannot find macro `my_macro_attr` in this scope
|
error: cannot find macro `my_macro_attr` in this scope
|
||||||
|
|
|
@ -4,12 +4,12 @@ error: expected derive macro, found tool attribute `rustfmt::skip`
|
||||||
LL | #[derive(rustfmt::skip)]
|
LL | #[derive(rustfmt::skip)]
|
||||||
| ^^^^^^^^^^^^^ not a derive macro
|
| ^^^^^^^^^^^^^ not a derive macro
|
||||||
|
|
|
|
||||||
help: Remove from the surrounding `derive()`
|
help: remove from the surrounding `derive()`
|
||||||
--> $DIR/tool-attributes-misplaced-2.rs:1:10
|
--> $DIR/tool-attributes-misplaced-2.rs:1:10
|
||||||
|
|
|
|
||||||
LL | #[derive(rustfmt::skip)]
|
LL | #[derive(rustfmt::skip)]
|
||||||
| ^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^
|
||||||
= help: Add as non-Derive macro
|
= help: add as non-Derive macro
|
||||||
`#[rustfmt::skip]`
|
`#[rustfmt::skip]`
|
||||||
|
|
||||||
error: expected macro, found tool attribute `rustfmt::skip`
|
error: expected macro, found tool attribute `rustfmt::skip`
|
||||||
|
|
Loading…
Add table
Reference in a new issue