-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Suppress suggestions in derive macro #120272
Suppress suggestions in derive macro #120272
Conversation
r? @oli-obk (rustbot has picked a reviewer for you, use r? to override) |
LGTM (please don't take my word for it, I've only messed with this section of the compiler twice :D ). I am qualified enough to ask for a squash though. |
2dedac8
to
8ac80a9
Compare
@Teapot4195 Thank you for comment. I squashed my commits. |
I think we could check this directly in Adding a test for this is rather involved I'd presume, so manually testing it seems ok to me. But if you wanna try adding a test, we do have tests like /home/ubuntu/rustc/rust10/tests/ui/proc-macro/derive-b.rs so you can probably just copy one of these tests and their derive and create a derive that will always emit your diagnostic. |
@oli-obk |
This comment has been minimized.
This comment has been minimized.
Looks like rustc has tests 😆 try running |
@oli-obk --- a/tests/ui/pattern/usefulness/issue-119778-type-error-ice.stderr
+++ b/tests/ui/pattern/usefulness/issue-119778-type-error-ice.stderr
@@ -14,11 +14,6 @@ error[E0425]: cannot find value `S` in this scope
|
LL | struct Foo([u8; S]);
| ^ not found in this scope
- |
-help: you might be missing a const parameter
- |
-LL | struct Foo<const S: /* Type */>([u8; S]);
- | +++++++++++++++++++++
error[E0658]: `impl Trait` in type aliases is unstable I think the reason of test failure is that the checks in |
I think it's ok to lose this suggestion if it is still reported in another error in the same test. If that is not the case, then we need to figure out why this code is marked as expanded by a derive. |
This comment has been minimized.
This comment has been minimized.
some tests are still failing |
@oli-obk I have one assumption of this. For example, the suggestion in --- a/tests/ui/associated-types/issue-38821.stderr
+++ b/tests/ui/associated-types/issue-38821.stderr
@@ -12,10 +12,6 @@ LL | impl<T: NotNull> IntoNullable for T {
| |
| unsatisfied trait bound introduced here
= note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)
-help: consider further restricting the associated type
- |
-LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>, <Col as Expression>::SqlType: NotNull,
- | +++++++++++++++++++++++++++++++++++++++
error: aborting due to 1 previous error This suggestion is came from
Also I checked the result of expansion by // ...
//~^ ERROR the trait bound `<Col as Expression>::SqlType: NotNull` is not satisfied
pub enum ColumnInsertValue<Col, Expr> where Col: Column,
Expr: Expression<SqlType = <Col::SqlType as IntoNullable>::Nullable> {
Expression(Col, Expr),
Default(Col),
}
// ...
#[automatically_derived]
impl<Col: ::core::marker::Copy, Expr: ::core::marker::Copy>
::core::marker::Copy for ColumnInsertValue<Col, Expr> where Col: Column,
Expr: Expression<SqlType = <Col::SqlType as IntoNullable>::Nullable> /* here? */ {
}
// ... I am guessing that the suggestion is in the Could you tell me how to explain this or is there better explanation? Thank you. |
Ah yea, that makes sense :/ Not sure what the best way forward is. I guess ideally we'd make the expansion somehow signal that it is referring to code copied from non-expanded code (in contrast to fully generated code, which is what the original issue was about). That would require modifying our derives, and would not help for proc macro derives, for which I don't know how we can address it at this point. |
@oli-obk I think the essence of this problem is that it is necessary to determine whether a suggestion is grammatically correct or not. It would be impossible to determine that using only As a different approach, I have an idea to check if the code to which the suggestion is applied is grammatically correct, and suppress it if it is not. I would like to implement a PoC if I can afford it. |
that sound scary. I don't think we should go down that route (if I understand correctly what you're trying to do)
that sounds doable. we store information about the derive's span in the expansion info. So we could check if it overlaps with that. |
@oli-obk
I don't (can't) take care about proc-macro now. |
That sounds good to me. We can figure out proc macros later, doesn't have to be in this PR |
Thank you! I will implement by this method. |
b4d2e2f
to
8cc5084
Compare
This comment has been minimized.
This comment has been minimized.
Thank you for your review. I added a test for the issue and fix to use for-loop. |
Great! Let's land this then @bors r+ rollup |
@bors r- I've been told about a possible perf impact that previous attempts have had |
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
…-in-derive-macro, r=<try> Suppress suggestions in derive macro close rust-lang#118809 I suppress warnings inside derive macros. For example, the compiler emits following error by a program described in rust-lang#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 ```
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (7ad2516): comparison URL. Overall result: no relevant changes - no action neededBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. @bors rollup=never Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 667.259s -> 666.873s (-0.06%) |
@bors r+ rollup |
…iaskrgr Rollup of 9 pull requests Successful merges: - rust-lang#119213 (simd intrinsics: add simd_shuffle_generic and other missing intrinsics) - rust-lang#120272 (Suppress suggestions in derive macro) - rust-lang#120773 (large_assignments: Allow moves into functions) - rust-lang#120874 (Take empty `where` bounds into account when suggesting predicates) - rust-lang#120882 (interpret/write_discriminant: when encoding niched variant, ensure the stored value matches) - rust-lang#120883 (interpret: rename ReadExternStatic → ExternStatic) - rust-lang#120890 (Adapt `llvm-has-rust-patches` validation to take `llvm-config` into account.) - rust-lang#120895 (don't skip coercions for types with errors) - rust-lang#120896 (Print kind of coroutine closure) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 9 pull requests Successful merges: - rust-lang#119213 (simd intrinsics: add simd_shuffle_generic and other missing intrinsics) - rust-lang#120272 (Suppress suggestions in derive macro) - rust-lang#120773 (large_assignments: Allow moves into functions) - rust-lang#120874 (Take empty `where` bounds into account when suggesting predicates) - rust-lang#120882 (interpret/write_discriminant: when encoding niched variant, ensure the stored value matches) - rust-lang#120883 (interpret: rename ReadExternStatic → ExternStatic) - rust-lang#120890 (Adapt `llvm-has-rust-patches` validation to take `llvm-config` into account.) - rust-lang#120895 (don't skip coercions for types with errors) - rust-lang#120896 (Print kind of coroutine closure) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 9 pull requests Successful merges: - rust-lang#119213 (simd intrinsics: add simd_shuffle_generic and other missing intrinsics) - rust-lang#120272 (Suppress suggestions in derive macro) - rust-lang#120773 (large_assignments: Allow moves into functions) - rust-lang#120874 (Take empty `where` bounds into account when suggesting predicates) - rust-lang#120882 (interpret/write_discriminant: when encoding niched variant, ensure the stored value matches) - rust-lang#120883 (interpret: rename ReadExternStatic → ExternStatic) - rust-lang#120890 (Adapt `llvm-has-rust-patches` validation to take `llvm-config` into account.) - rust-lang#120895 (don't skip coercions for types with errors) - rust-lang#120896 (Print kind of coroutine closure) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 9 pull requests Successful merges: - rust-lang#119213 (simd intrinsics: add simd_shuffle_generic and other missing intrinsics) - rust-lang#120272 (Suppress suggestions in derive macro) - rust-lang#120773 (large_assignments: Allow moves into functions) - rust-lang#120874 (Take empty `where` bounds into account when suggesting predicates) - rust-lang#120882 (interpret/write_discriminant: when encoding niched variant, ensure the stored value matches) - rust-lang#120883 (interpret: rename ReadExternStatic → ExternStatic) - rust-lang#120890 (Adapt `llvm-has-rust-patches` validation to take `llvm-config` into account.) - rust-lang#120895 (don't skip coercions for types with errors) - rust-lang#120896 (Print kind of coroutine closure) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#120272 - long-long-float:suppress-suggestions-in-derive-macro, r=oli-obk Suppress suggestions in derive macro close rust-lang#118809 I suppress warnings inside derive macros. For example, the compiler emits following error by a program described in rust-lang#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 ```
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.
In this PR, suggestions to cast are suppressed.