-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #120272 - long-long-float:suppress-suggestions-in-der…
…ive-macro, r=oli-obk Suppress suggestions in derive macro close #118809 I suppress warnings inside derive macros. For example, the compiler emits following error by a program described in #118809 (comment) with a suggestion that indicates invalid syntax. ``` error[E0308]: `?` operator has incompatible types --> src/main.rs:3:17 | 3 | #[derive(Debug, Deserialize)] | ^^^^^^^^^^^ expected `u32`, found `u64` | = note: `?` operator cannot convert from `u64` to `u32` = note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info) help: you can convert a `u64` to a `u32` and panic if the converted value doesn't fit | 3 | #[derive(Debug, Deserialize.try_into().unwrap())] | ++++++++++++++++++++ For more information about this error, try `rustc --explain E0308`. error: could not compile `serde_test` (bin "serde_test") due to 2 previous errors ``` In this PR, suggestions to cast are suppressed. ``` error[E0308]: `?` operator has incompatible types --> src/main.rs:3:17 | 3 | #[derive(Debug, Deserialize)] | ^^^^^^^^^^^ expected `u32`, found `u64` | = note: `?` operator cannot convert from `u64` to `u32` = note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info) For more information about this error, try `rustc --explain E0308`. error: could not compile `serde_test` (bin "serde_test") due to 2 previous errors ```
- Loading branch information
Showing
5 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// force-host | ||
// no-prefer-dynamic | ||
|
||
#![crate_type = "proc-macro"] | ||
|
||
extern crate proc_macro; | ||
use proc_macro::TokenStream; | ||
|
||
#[proc_macro_derive(Deserialize)] | ||
pub fn deserialize_derive(input: TokenStream) -> TokenStream { | ||
"impl Build { | ||
fn deserialize() -> Option<u64> { | ||
let x: Option<u32> = Some(0); | ||
Some(x? + 1) | ||
} | ||
} | ||
" | ||
.parse() | ||
.unwrap() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// aux-build: issue-118809.rs | ||
|
||
#[macro_use] | ||
extern crate issue_118809; | ||
|
||
#[derive(Deserialize)] //~ ERROR mismatched types [E0308] | ||
pub struct Build { | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/issue-118809.rs:6:10 | ||
| | ||
LL | #[derive(Deserialize)] | ||
| ^^^^^^^^^^^ | ||
| | | ||
| expected `u64`, found `u32` | ||
| arguments to this enum variant are incorrect | ||
| | ||
help: the type constructed contains `u32` due to the type of the argument passed | ||
--> $DIR/issue-118809.rs:6:10 | ||
| | ||
LL | #[derive(Deserialize)] | ||
| ^^^^^^^^^^^ this argument influences the type of `Some` | ||
note: tuple variant defined here | ||
--> $SRC_DIR/core/src/option.rs:LL:COL | ||
= note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |