-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Avoid wrong code suggesting for attribute macro #107254
Avoid wrong code suggesting for attribute macro #107254
Conversation
It'd be nice if we can find a more general solution. I don't think there should ever be a suggestion using a call_site span of an attribute macro. |
it is right, there is a new .fixed file.
it seems strange, but it is valid code.
Michael Goulet ***@***.***> 于 2023年1月25日周三 01:58写道:
… ***@***.**** commented on this pull request.
------------------------------
In tests/ui/coercion/coerce-block-tail-83783.stderr
<#107254 (comment)>:
> @@ -6,6 +6,10 @@ LL | _consume_reference::<i32>(&async { Box::new(7_i32) }.await);
|
= note: expected type `i32`
found struct `Box<i32>`
+help: consider unboxing the value
+ |
+LL | _consume_reference::<i32>(&*async { Box::new(7_i32) }.await);
This is not right?
—
Reply to this email directly, view it on GitHub
<#107254 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABYJ5U6YYHI6FO4NFW6U5TWUAJ57ANCNFSM6AAAAAAUE7HPFI>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
@@ -706,6 +706,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |||
expected: Ty<'tcx>, | |||
expr_ty: Ty<'tcx>, | |||
) -> bool { | |||
if in_external_macro(self.tcx.sess, expr.span) { |
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.
@compiler-errors
My change at here makes this case failed:
rustc --edition 2021 tests/ui/async-await/proper-span-for-type-error.rs
error[E0308]: mismatched types
--> tests/ui/async-await/proper-span-for-type-error.rs:8:5
|
8 | a().await //~ ERROR mismatched types
| ^^^^^^^^^ expected enum `Result`, found `()`
|
= note: expected enum `Result<(), i32>`
found unit type `()`
help: try adding an expression at the end of the block
|
8 ~ a().await;
9 ~ Ok(()) //~ ERROR mismatched types
|
This is because in_external_macro
is not right, missing DesugaringKind::Await
, so I added it and with extra DesugaringKind::Async
.
So the new suggestion comes out:
_consume_reference::<i32>(&*async { Box::new(7_i32) }.await);
It seems right, so I keep it.
By the way, I think our current in_external_macro
still missing some DesugaringKind, and the in_external_macro
is not a proper name right now considering it actually not just checking Macro
, a suitable function name should be something like proper_for_suggesting
.
And we have a similar function in span
, but it definitely need some fix:
rust/compiler/rustc_span/src/lib.rs
Lines 600 to 607 in c048326
pub fn can_be_used_for_suggestions(self) -> bool { | |
!self.from_expansion() | |
// FIXME: If this span comes from a `derive` macro but it points at code the user wrote, | |
// the callsite span and the span will be pointing at different places. It also means that | |
// we can safely provide suggestions on this span. | |
|| (matches!(self.ctxt().outer_expn_data().kind, ExpnKind::Macro(MacroKind::Derive, _)) | |
&& self.parent_callsite().map(|p| (p.lo(), p.hi())) != Some((self.lo(), self.hi()))) | |
} |
We need some cleanup for these functions here?
Yes, we'd better find a centralized way to do this since it's relevant for pretty much all reported diagnostics. This is the second time I solve this kind of issue, I tried to add a rust/compiler/rustc_errors/src/diagnostic.rs Line 625 in c048326
and rust/compiler/rustc_errors/src/diagnostic.rs Line 707 in c048326
There are about 10+ testcases's result changed, I need to tweak the filter function. |
b3c6813
to
5bcb80c
Compare
@compiler-errors do you have more comments for this PR? |
@chenyukang I believe that a more general solution would be something along the lines of my attempt at #109082. The problem is that that PR causes a perf regression that I haven't yet been able to shake off. We could land this PR as is (and the change to in_external_macro is correct), but feels like adding yet another corner case check when we could nip this entire category of issues in the bud. Would you be interested in taking on the strategy shown in #109082 and see if we can do that without the perf impact? |
@estebank I will take a look at your PR, I guess the performance regression is introduced by the changes on some functions of |
☔ The latest upstream changes (presumably #113591) made this pull request unmergeable. Please resolve the merge conflicts. |
@chenyukang any updates on this? |
5bcb80c
to
75b9f53
Compare
I just resolved the conflicts, as @estebank said we may land this PR but #109082 is an more completed solution. #109082 has some perf issue right now. I may also take a look at it. |
This comment has been minimized.
This comment has been minimized.
851af7f
to
ac25636
Compare
Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
Fix the issue of So I added a another commit to fix it: ref here: rust/compiler/rustc_ast_lowering/src/item.rs Line 1052 in 7a5d2d0
|
@bors r+ |
⌛ Testing commit ac25636 with merge 07ac64019fac2eba26112cea9e1a27069103b010... |
💔 Test failed - checks-actions |
@bors retry |
☀️ Test successful - checks-actions |
Finished benchmarking commit (736ef39): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression 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.
CyclesResultsThis 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.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 647.939s -> 648.105s (0.03%) |
…ugg-in-macro, r=estebank Avoid wrong code suggesting for attribute macro Fixes rust-lang#107113 r? `@estebank`
Fixes #107113
r? @estebank