-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
Merged
bors
merged 2 commits into
rust-lang:master
from
chenyukang:yukang/fix-107113-wrong-sugg-in-macro
Aug 3, 2023
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,13 @@ | ||
// run-rustfix | ||
// edition:2018 | ||
fn _consume_reference<T: ?Sized>(_: &T) {} | ||
|
||
async fn _foo() { | ||
_consume_reference::<i32>(&Box::new(7_i32)); | ||
_consume_reference::<i32>(&*async { Box::new(7_i32) }.await); | ||
//~^ ERROR mismatched types | ||
_consume_reference::<[i32]>(&vec![7_i32]); | ||
_consume_reference::<[i32]>(&async { vec![7_i32] }.await); | ||
} | ||
|
||
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// check-fail | ||
// run-rustfix | ||
// edition:2018 | ||
fn _consume_reference<T: ?Sized>(_: &T) {} | ||
|
||
|
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,13 @@ | ||
// force-host | ||
// no-prefer-dynamic | ||
|
||
#![crate_type = "proc-macro"] | ||
|
||
extern crate proc_macro; | ||
|
||
use proc_macro::TokenStream; | ||
|
||
#[proc_macro_attribute] | ||
pub fn main(_: TokenStream, item: TokenStream) -> TokenStream { | ||
"fn main() -> std::io::Result<()> { () } ".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,8 @@ | ||
// edition:2021 | ||
// aux-build:issue-107113.rs | ||
|
||
#[macro_use] | ||
extern crate issue_107113; | ||
|
||
#[issue_107113::main] //~ ERROR mismatched types [E0308] | ||
async fn main() -> std::io::Result<()> {} |
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,16 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/issue-107113-wrap.rs:7:1 | ||
| | ||
LL | #[issue_107113::main] | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| expected `Result<(), Error>`, found `()` | ||
| expected `Result<(), std::io::Error>` because of return type | ||
| | ||
= note: expected enum `Result<(), std::io::Error>` | ||
found unit type `()` | ||
= note: this error originates in the attribute macro `issue_107113::main` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
This is because
in_external_macro
is not right, missingDesugaringKind::Await
, so I added it and with extraDesugaringKind::Async
.So the new suggestion comes out:
It seems right, so I keep it.
By the way, I think our current
in_external_macro
still missing some DesugaringKind, and thein_external_macro
is not a proper name right now considering it actually not just checkingMacro
, a suitable function name should be something likeproper_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
We need some cleanup for these functions here?