-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add diagnostics for rustc_metadata #34970
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
178f8a8
4cbbe51
eead207
3476aad
2a0136c
5f9aa81
9a4a81f
055a228
3f6b5e6
cdda2c3
083b536
0608f31
fd9ebcf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,6 +91,197 @@ You need to link your code to the relevant crate in order to be able to use it | |
well, and you link to them the same way. | ||
"##, | ||
|
||
E0466: r##" | ||
Invalid macro import declarations. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're supposed to be a little more exhaustive on the error, not just repeat the error message. |
||
|
||
This is a syntax error at the level of attribute declarations. | ||
|
||
Causes of this error: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be "Erroneous code example". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the language that critical? Just looking at handful random error numbers, it looks like E0050, E0053, E0054, and E0055 don't say "Erroneous code example". If we stick that strictly to the RFC it looks like some old errors need to be rewritten. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They've been written way before the RFC. They'll be updated later. |
||
|
||
```ignore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't be |
||
#[macro_use(a_macro(another_macro))] // error: invalid import declaration | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just one whitespace is enough before "// error: ...". |
||
extern crate some_crate; | ||
|
||
#[macro_use(i_want = "some_macros")] // error: invalid import declaration | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just one whitespace is enough before "// error: ...". |
||
extern crate another_crate; | ||
``` | ||
|
||
Macro imports are properly declared as: | ||
|
||
```ignore | ||
#[macro_use(get_tacos, bring_beer)] // imports macros get_tacos and | ||
extern crate some_crate; // bring_beer from some_crate | ||
``` | ||
|
||
Declaring `macro_use` with no arguments will import all available macros from | ||
the given crate. | ||
|
||
Exported macros must be declared as such with `macro_export`. In the above | ||
example, some_crate would contain: | ||
|
||
```ignore | ||
#[macro_export] | ||
macro_rules! get_tacos { | ||
... | ||
} | ||
|
||
#[macro_export] | ||
macro_rules! bring_beer { | ||
... | ||
} | ||
``` | ||
|
||
"##, | ||
|
||
E0467: r##" | ||
Invalid or no macros listed for reexport. | ||
|
||
This is a syntax error at the level of attribute declarations. | ||
|
||
Causes of this error: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same. |
||
|
||
```ignore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't be |
||
#[macro_reexport] // error: no macros listed for export | ||
extern crate macros_for_good; | ||
``` | ||
```ignore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same. |
||
#[macro_reexport(fun_macro = "foo")] // error: not a macro identifier | ||
extern crate macros_for_good; | ||
``` | ||
|
||
Currently, `macro_reexport` requires at least one macro name to be listed. | ||
Unlike `macro_use`, listing no names does not reexport all macros from the | ||
given crate. | ||
|
||
Decide which macros you would like to export and list them properly. | ||
"##, | ||
|
||
E0468: r##" | ||
A non-root module attempts to import macros from another crate. | ||
|
||
```ignore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same. |
||
mod foo { | ||
#[macro_use(helpful_macro)] // error: must be at crate root to import | ||
extern crate some_crate; // macros from another crate | ||
helpful_macro!(...) | ||
} | ||
|
||
fn main() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why adding the |
||
// ... | ||
} | ||
``` | ||
|
||
Only `extern crate` imports at the crate root level (i.e., in lib.rs) are | ||
allowed to import macros. | ||
|
||
Either move the macro import to crate root or do without the foreign macros. | ||
|
||
This will work: | ||
|
||
```ignore | ||
#[macro_use(helpful_macro)] | ||
extern crate some_crate; | ||
mod foo { | ||
helpful_macro!(...) | ||
} | ||
|
||
fn main() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why adding the |
||
//... | ||
} | ||
``` | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extra empty line. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure I understand? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line shouldn't exist. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still extra empty line. |
||
"##, | ||
|
||
E0469: r##" | ||
A macro listed for import was not found. | ||
|
||
Either the listed macro is not contained in the imported crate, or it is not | ||
exported from the given crate. | ||
|
||
```ignore | ||
/// // crate some_crate contains: | ||
/// #[macro_export] | ||
/// macro_rules! eat { | ||
/// ... | ||
/// } | ||
/// macro_rules! drink { | ||
/// ... | ||
/// } | ||
|
||
// error: drink is a private macro of some_crate | ||
// error: be_merry does not exist in some_crate | ||
#[macro_use(drink, be_merry)] | ||
extern crate some_crate; | ||
``` | ||
|
||
This could be caused by a typo. Did you misspell the macro's name? | ||
|
||
Double-check the names of the macros listed for import, and that the crate | ||
in question exports them. | ||
|
||
A working version of the above: | ||
|
||
```ignore | ||
/// // crate some_crate contains: | ||
/// #[macro_export] | ||
/// macro_rules! eat { | ||
/// ... | ||
/// } | ||
/// #[macro_export] | ||
/// macro_rules! drink { | ||
/// ... | ||
/// } | ||
|
||
#[macro_use(eat, drink)] | ||
extern crate some_crate; | ||
``` | ||
"##, | ||
|
||
E0470: r##" | ||
A macro listed for reexport was not found. | ||
|
||
Either the listed macro is not contained in the imported crate, or it is not | ||
exported from the given crate. | ||
|
||
```ignore | ||
/// // crate some_crate contains: | ||
/// #[macro_export] | ||
/// macro_rules! eat { | ||
/// ... | ||
/// } | ||
/// macro_rules! drink { | ||
/// ... | ||
/// } | ||
|
||
// error: drink is a private macro of some_crate | ||
// error: be_merry does not exist in some_crate | ||
#[macro_reexport(drink, be_merry)] | ||
extern crate some_crate; | ||
``` | ||
|
||
This could be caused by a typo. Did you misspell the macro's name? | ||
|
||
Double-check the names of the macros listed for reexport, and that the crate | ||
in question exports them. | ||
|
||
A working version of the above: | ||
|
||
```ignore | ||
/// // crate some_crate contains: | ||
/// #[macro_export] | ||
/// macro_rules! eat { | ||
/// ... | ||
/// } | ||
/// #[macro_export] | ||
/// macro_rules! drink { | ||
/// ... | ||
/// } | ||
|
||
#[macro_reexport(eat, drink)] | ||
extern crate some_crate; | ||
``` | ||
"##, | ||
|
||
} | ||
|
||
register_diagnostics! { | ||
|
@@ -102,11 +293,6 @@ register_diagnostics! { | |
E0462, // found staticlib `..` instead of rlib or dylib | ||
E0464, // multiple matching crates for `..` | ||
E0465, // multiple .. candidates for `..` found | ||
E0466, // bad macro import | ||
E0467, // bad macro reexport | ||
E0468, // an `extern crate` loading macros must be at the crate root | ||
E0469, // imported macro not found | ||
E0470, // reexported macro not found | ||
E0519, // local crate and dependency have same (crate-name, disambiguator) | ||
E0523, // two dependencies have same (crate-name, disambiguator) but different SVH | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,3 +62,5 @@ pub mod index; | |
pub mod loader; | ||
pub mod macro_import; | ||
pub mod tls_context; | ||
|
||
__build_diagnostic_array! { librustc_metadata, DIAGNOSTICS } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why adding this line? (I'm still curious haha) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mentioned this in a comment in the #32777 thread - The diagnostics in The line in With these changes, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't know about |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why adding this? (I'm curious)