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

Provide appropriate types in turbofish suggestions #76043

Closed
wants to merge 17 commits into from

Conversation

estebank
Copy link
Contributor

When encountering an expression that is missing type information, provide a structured suggestion to use a turbofish or local binding type with an appropriate type.

@rust-highfive
Copy link
Collaborator

r? @matthewjasper

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 28, 2020
Comment on lines 369 to 370
// FIXME: ideally we would use `can_coerce` here instead, but `typeck`
// comes *after* in the dependency graph.
Copy link
Member

Choose a reason for hiding this comment

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

You could make it a query (using canonicalization to allow inference variables to pass through). In fact, we've been meaning to make coercions more integrated into the trait system for many years now, cc @nikomatsakis

@estebank

This comment has been minimized.

@bors

This comment has been minimized.

@estebank estebank force-pushed the needs_type_info_sugg branch 2 times, most recently from 5155ff4 to bbb7114 Compare August 30, 2020 21:30
@bors

This comment has been minimized.

@jyn514 jyn514 added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 15, 2020
@bors

This comment has been minimized.

@camelid

This comment has been minimized.

@camelid camelid 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 Oct 7, 2020
@estebank estebank 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 Oct 11, 2020
Comment on lines 337 to 377
self.tcx.for_each_relevant_impl(data.trait_ref.def_id, self_ty, |impl_def_id| {
self.probe(|_| {
let trait_args = InternalSubsts::identity_for_item(self.tcx, data.trait_ref.def_id);
let impl_args = traits::specialize::fulfill_implication(
self,
obligation.param_env,
data.trait_ref,
impl_def_id,
);
let substs = match impl_args {
Ok(impl_args) => trait_args.rebase_onto(self.tcx, impl_def_id, impl_args),
_ => return,
};
let trait_ref = self.tcx.impl_trait_ref(impl_def_id).unwrap();

let cause = traits::ObligationCause::dummy();
let mut selcx = SelectionContext::new(&self);
let param_env = obligation.param_env.clone();
let (target_trait_ref, obligations) = traits::util::impl_trait_ref_and_oblig(
&mut selcx,
param_env,
impl_def_id,
substs,
);
self.resolve_vars_if_possible(&target_trait_ref);
if let Ok(eval_result) = selcx.evaluate_predicates(
Some(Obligation::new(
cause.clone(),
param_env,
target_trait_ref.without_const().to_predicate(self.tcx),
))
.into_iter()
.chain(obligations),
) {
debug!("get_turbofish_suggestions result {:?}", eval_result);
if eval_result.must_apply_modulo_regions()
&& !matches!(trait_ref.self_ty().kind(), ty::Infer(_))
{
turbofish_suggestions.insert(trait_ref.self_ty());
}
};
})
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@eddyb @nikomatsakis could you take a look at this to see if it makes sense?

@estebank estebank force-pushed the needs_type_info_sugg branch 3 times, most recently from 948a06c to c6171be Compare October 14, 2020 05:42
When encountering a situation where extra type annotations are needed,
we sometimes suggest using turbofish. When we do so, previously we used
either the `fn`'s type parameter names or `_` as placeholders. Now, we
probe for all types that implement the traits the type parameter is
bounded by and provide a structured suggestion for them.
Specifically avoid non-sense suggestion when calling `panic!` with
something `!Send`.
@bors
Copy link
Contributor

bors commented Oct 24, 2020

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

Note that reviewers usually do not review pull requests until merge conflicts are resolved! Once you resolve the conflicts, you should change the labels applied by bors to indicate that your PR is ready for review. Post this as a comment to change the labels:

@rustbot modify labels: +S-waiting-on-review -S-waiting-on-author

@JohnCSimon JohnCSimon 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 9, 2020
@crlf0710 crlf0710 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 28, 2020
@camelid camelid 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 18, 2020
@Dylan-DPC-zz
Copy link

closing this due to inactivity

@Dylan-DPC-zz Dylan-DPC-zz 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 Dec 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints 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.

10 participants