Skip to content
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

On type mismatch involving fn/method call, point at definition #119340

Closed
wants to merge 3 commits into from

Conversation

sjwang05
Copy link
Contributor

Closes #61066

@rustbot
Copy link
Collaborator

rustbot commented Dec 27, 2023

r? @cjgillot

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 27, 2023
@@ -21,6 +21,8 @@ LL | fn f(x: &mut dyn Iterator<Item: Iterator<Item = &'_ ()>>) -> Option<&'_ ()>
|
= note: expected enum `Option<&()>`
found enum `Option<impl Iterator<Item = &'_ ()>>`
note: the method next is defined here
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what's up with cases like this one--FWIW the span gets printed correctly when I run locally.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

compiler/rustc_hir_typeck/src/demand.rs Outdated Show resolved Hide resolved
})
| hir::Node::Item(hir::Item { kind: hir::ItemKind::Fn(sig, ..), .. }) = node
&& let ret_span = sig.decl.output.span()
&& !ret_span.from_expansion()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not from expansions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mainly to avoid giving weird suggestions in desugaring like async fn, though if you think we should still give suggestions in macros, we could check for desugaring_kind().is_none() instead.

if let Some(local_did) = def_id.as_local()
&& let Some(node) = self.tcx.opt_hir_node(self.tcx.local_def_id_to_hir_id(local_did))
&& let hir::Node::ImplItem(hir::ImplItem {
kind: hir::ImplItemKind::Fn(sig, ..), ..
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we check we aren't suggesting a change in a trait impl?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't match on hir::TraitItem--I made the check a bit clearer when addressing #119340 (comment)

compiler/rustc_hir_typeck/src/demand.rs Outdated Show resolved Hide resolved
compiler/rustc_hir_typeck/src/demand.rs Outdated Show resolved Hide resolved
@cjgillot cjgillot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 29, 2023
@sjwang05
Copy link
Contributor Author

sjwang05 commented Jan 3, 2024

Thanks for all the suggestions.

@rustbot review

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 3, 2024
Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for any unintended harshness, but I am really not in favor of this change 😅

I believe it inverts the normal "source of truth" we use (the signature) when suggesting to change a function signature that may have other call-sites, and I am skeptical that adding this information on every mismatch is worthwhile. Does it account for the other call-sites of the function that may break when this signature is changed?

As for the technical impl, I believe it needs to avoid labeling spans that don't actually map to lines in the source map, and needs to use backticks on item names.

Also, does this handle polymorphic functions correctly? How does it map a type mismatch back to the generic parameters of the function, for example?

Finally, why do we need to provide a structured suggestion -- seems to break run-rustfix tests for a very heuristic suggestion?

@compiler-errors compiler-errors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 5, 2024
@bors
Copy link
Contributor

bors commented Feb 10, 2024

☔ The latest upstream changes (presumably #120877) made this pull request unmergeable. Please resolve the merge conflicts.

@Dylan-DPC
Copy link
Member

@sjwang05 any updates on this?

@Dylan-DPC
Copy link
Member

Closing this as inactive. Feel free to reöpen this pr or create a new pr if you get the time to work on this. Thanks

@Dylan-DPC Dylan-DPC closed this Apr 21, 2024
@Dylan-DPC Dylan-DPC added S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

On type mismatch involving fn call, point at fn definition
7 participants