-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
src/test/ui/suggestions/appropriate-type-param-turbofish.stderr
Outdated
Show resolved
Hide resolved
// FIXME: ideally we would use `can_coerce` here instead, but `typeck` | ||
// comes *after* in the dependency graph. |
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.
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
src/librustc_trait_selection/traits/error_reporting/suggestions.rs
Outdated
Show resolved
Hide resolved
src/librustc_trait_selection/traits/error_reporting/suggestions.rs
Outdated
Show resolved
Hide resolved
src/librustc_trait_selection/traits/error_reporting/suggestions.rs
Outdated
Show resolved
Hide resolved
src/test/ui/inference/cannot-infer-async-enabled-impl-trait-bindings.stderr
Outdated
Show resolved
Hide resolved
src/librustc_trait_selection/traits/error_reporting/suggestions.rs
Outdated
Show resolved
Hide resolved
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
5155ff4
to
bbb7114
Compare
This comment has been minimized.
This comment has been minimized.
bbb7114
to
dc910f9
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
dc910f9
to
4df705e
Compare
4df705e
to
b888626
Compare
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()); | ||
} | ||
}; | ||
}) | ||
}); |
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.
@eddyb @nikomatsakis could you take a look at this to see if it makes sense?
948a06c
to
c6171be
Compare
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`.
3cde317
to
eedaf5d
Compare
eedaf5d
to
654a412
Compare
☔ 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:
|
closing this due to inactivity |
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.