-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Avoid complex diagnostics in snippets which contain newlines #75020
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c269525
Avoid complex diagnostics in snippets which contain newlines
JohnTitor ad978e5
Separate complex multispan into some notes
JohnTitor 66226ca
Address some code reviews
JohnTitor 2da86a1
Add "this has type `{}` which {}" note
JohnTitor 54d9ffc
Only separate notes if span is multiline
JohnTitor 8d65101
Fix format
JohnTitor 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 hidden or 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 hidden or 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,25 @@ | ||
// edition:2018 | ||
// #70935: Check if we do not emit snippet | ||
// with newlines which lead complex diagnostics. | ||
|
||
use std::future::Future; | ||
|
||
async fn baz<T>(_c: impl FnMut() -> T) where T: Future<Output=()> { | ||
} | ||
|
||
fn foo(tx: std::sync::mpsc::Sender<i32>) -> impl Future + Send { | ||
//~^ ERROR: future cannot be sent between threads safely | ||
async move { | ||
baz(|| async{ | ||
foo(tx.clone()); | ||
}).await; | ||
} | ||
} | ||
|
||
fn bar(_s: impl Future + Send) { | ||
} | ||
|
||
fn main() { | ||
let (tx, _rx) = std::sync::mpsc::channel(); | ||
bar(foo(tx)); | ||
} |
This file contains hidden or 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,30 @@ | ||
error: future cannot be sent between threads safely | ||
--> $DIR/issue-70935-complex-spans.rs:10:45 | ||
| | ||
LL | fn foo(tx: std::sync::mpsc::Sender<i32>) -> impl Future + Send { | ||
| ^^^^^^^^^^^^^^^^^^ future created by async block is not `Send` | ||
| | ||
= help: the trait `Sync` is not implemented for `Sender<i32>` | ||
note: future is not `Send` as this value is used across an await | ||
--> $DIR/issue-70935-complex-spans.rs:13:9 | ||
| | ||
LL | / baz(|| async{ | ||
LL | | foo(tx.clone()); | ||
LL | | }).await; | ||
| |________________^ first, await occurs here, with the value maybe used later... | ||
note: the value is later dropped here | ||
--> $DIR/issue-70935-complex-spans.rs:15:17 | ||
| | ||
LL | }).await; | ||
| ^ | ||
note: this has type `[closure@$DIR/issue-70935-complex-spans.rs:13:13: 15:10]` which is not `Send` | ||
--> $DIR/issue-70935-complex-spans.rs:13:13 | ||
| | ||
LL | baz(|| async{ | ||
| _____________^ | ||
LL | | foo(tx.clone()); | ||
LL | | }).await; | ||
| |_________^ | ||
|
||
error: aborting due to previous error | ||
|
This file contains hidden or 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
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.
Added this note separately, since this span has some lines and loses readability when we do as @estebank suggested (#75020 (comment)). I feel it's redundant a bit.
@tmandry Does this make sense for you?
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.
@JohnTitor something I've done in other errors i check whether
Span
s are exactly the same, if one encloses the other, or if one of them is multiline to provide different output depending on what looks best. In this case just checking whether the "inner" span is multiline to decide between span_labels and span_notes should be easy to do and reasonable as a solution. What do you two think?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.
r=me with or without the proposed changes.
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.
Sounds good! Addressed via 54d9ffc.