mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-13 12:36:47 +00:00
Point at appropriate type parameter in more trait bound errors
This commit is contained in:
parent
ac89e1615d
commit
120c24dab5
@ -67,6 +67,37 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
})
|
||||
};
|
||||
|
||||
// Account for enum variant constructors, where the type param corresponds to the enum
|
||||
// itself.
|
||||
let enum_def_id = if let hir::def::DefKind::Ctor(hir::def::CtorOf::Variant, _) =
|
||||
self.tcx.def_kind(def_id)
|
||||
{
|
||||
// `def_id` corresponds to a constructor, and its parent is the variant, and we want
|
||||
// the enum.
|
||||
Some(self.tcx.parent(self.tcx.parent(def_id)))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let variant_param_to_point_at = find_param_matching(&|param_term| {
|
||||
// FIXME: It would be nice to make this not use string manipulation,
|
||||
// but it's pretty hard to do this, since `ty::ParamTy` is missing
|
||||
// sufficient info to determine if it is synthetic, and we don't
|
||||
// always have a convenient way of getting `ty::Generics` at the call
|
||||
// sites we invoke `IsSuggestable::is_suggestable`.
|
||||
let include = match param_term {
|
||||
ty::ParamTerm::Ty(param_ty) => !param_ty.name.as_str().starts_with("impl "),
|
||||
_ => true,
|
||||
};
|
||||
// Account for enum variant constructors, where the type param corresponds to the enum
|
||||
// itself.
|
||||
let def_id = if let Some(def_id) = enum_def_id {
|
||||
def_id
|
||||
} else {
|
||||
def_id
|
||||
};
|
||||
self.tcx.parent(generics.param_at(param_term.index(), self.tcx).def_id) == def_id
|
||||
&& include
|
||||
});
|
||||
// Prefer generics that are local to the fn item, since these are likely
|
||||
// to be the cause of the unsatisfied predicate.
|
||||
let mut param_to_point_at = find_param_matching(&|param_term| {
|
||||
@ -102,6 +133,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
|
||||
match &expr.kind {
|
||||
hir::ExprKind::Path(qpath) => {
|
||||
let def_id = if let Some(def_id) = enum_def_id {
|
||||
def_id
|
||||
} else {
|
||||
def_id
|
||||
};
|
||||
if let hir::ExprKind::Path(hir::QPath::Resolved(None, path)) = expr.kind {
|
||||
for segment in path.segments {
|
||||
if let Some(param) = variant_param_to_point_at
|
||||
&& self.point_at_generic_if_possible(error, def_id, param, segment)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if let hir::Node::Expr(hir::Expr {
|
||||
kind: hir::ExprKind::Call(callee, args),
|
||||
hir_id: call_hir_id,
|
||||
|
@ -1,13 +1,11 @@
|
||||
error[E0271]: type mismatch resolving `<Adapter<I> as Iterator>::Item == Option<T>`
|
||||
--> $DIR/associated-types-issue-20346.rs:34:36
|
||||
--> $DIR/associated-types-issue-20346.rs:34:33
|
||||
|
|
||||
LL | fn test_adapter<T, I: Iterator<Item=Option<T>>>(it: I) {
|
||||
| - this type parameter
|
||||
...
|
||||
LL | is_iterator_of::<Option<T>, _>(&adapter);
|
||||
| ------------------------------ ^^^^^^^^ type mismatch resolving `<Adapter<I> as Iterator>::Item == Option<T>`
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
| ^ type mismatch resolving `<Adapter<I> as Iterator>::Item == Option<T>`
|
||||
|
|
||||
note: expected this to be `Option<T>`
|
||||
--> $DIR/associated-types-issue-20346.rs:23:17
|
||||
|
@ -1,10 +1,8 @@
|
||||
error[E0277]: the size for values of type `str` cannot be known at compilation time
|
||||
--> $DIR/unsized-ret.rs:10:27
|
||||
--> $DIR/unsized-ret.rs:10:11
|
||||
|
|
||||
LL | foo::<fn() -> str, _>(None, ());
|
||||
| --------------------- ^^^^ doesn't have a size known at compile-time
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
| ^^^^^^^^^^^ doesn't have a size known at compile-time
|
||||
|
|
||||
= help: within `fn() -> str`, the trait `Sized` is not implemented for `str`
|
||||
= note: required because it appears within the type `fn() -> str`
|
||||
@ -15,12 +13,10 @@ LL | fn foo<F: Fn<T>, T:std::marker::Tuple>(f: Option<F>, t: T) {
|
||||
| ^^^^^ required by this bound in `foo`
|
||||
|
||||
error[E0277]: the size for values of type `(dyn std::fmt::Display + 'a)` cannot be known at compilation time
|
||||
--> $DIR/unsized-ret.rs:13:66
|
||||
--> $DIR/unsized-ret.rs:13:11
|
||||
|
|
||||
LL | foo::<for<'a> fn(&'a ()) -> (dyn std::fmt::Display + 'a), _>(None, (&(),));
|
||||
| ------------------------------------------------------------ ^^^^ doesn't have a size known at compile-time
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
||||
|
|
||||
= help: within `for<'a> fn(&'a ()) -> (dyn std::fmt::Display + 'a)`, the trait `for<'a> Sized` is not implemented for `(dyn std::fmt::Display + 'a)`
|
||||
= note: required because it appears within the type `fn(&()) -> dyn Display`
|
||||
|
@ -17,12 +17,10 @@ LL | fn ret() -> impl Iterator<Item = ()> + ?Send { std::iter::empty() }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0277]: the size for values of type `[i32]` cannot be known at compilation time
|
||||
--> $DIR/issue-87199.rs:18:22
|
||||
--> $DIR/issue-87199.rs:18:15
|
||||
|
|
||||
LL | ref_arg::<[i32]>(&[5]);
|
||||
| ---------------- ^^^^ doesn't have a size known at compile-time
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
| ^^^^^ doesn't have a size known at compile-time
|
||||
|
|
||||
= help: the trait `Sized` is not implemented for `[i32]`
|
||||
note: required by a bound in `ref_arg`
|
||||
|
@ -1,10 +1,8 @@
|
||||
error[E0277]: the trait bound `for<'b> &'b S: Trait` is not satisfied
|
||||
--> $DIR/imm-ref-trait-object-literal-bound-regions.rs:17:14
|
||||
--> $DIR/imm-ref-trait-object-literal-bound-regions.rs:17:11
|
||||
|
|
||||
LL | foo::<S>(s);
|
||||
| -------- ^ the trait `for<'b> Trait` is not implemented for `&'b S`
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
| ^ the trait `for<'b> Trait` is not implemented for `&'b S`
|
||||
|
|
||||
= help: the trait `Trait` is implemented for `&'a mut S`
|
||||
= note: `for<'b> Trait` is implemented for `&'b mut S`, but not for `&'b S`
|
||||
|
@ -1,10 +1,8 @@
|
||||
error[E0277]: expected a `Fn<_>` closure, found `fn() -> str`
|
||||
--> $DIR/builtin-fn-must-return-sized.rs:15:27
|
||||
--> $DIR/builtin-fn-must-return-sized.rs:15:11
|
||||
|
|
||||
LL | foo::<fn() -> str, _>(None, ());
|
||||
| --------------------- ^^^^ expected an `Fn<_>` closure, found `fn() -> str`
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
| ^^^^^^^^^^^ expected an `Fn<_>` closure, found `fn() -> str`
|
||||
|
|
||||
= help: the trait `Fn<_>` is not implemented for `fn() -> str`
|
||||
note: required by a bound in `foo`
|
||||
|
@ -5,10 +5,10 @@ LL | impls::<W<_>>();
|
||||
| ^^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `impls`
|
||||
|
||||
error[E0275]: overflow evaluating the requirement `W<_>: Trait`
|
||||
--> $DIR/fixpoint-exponential-growth.rs:29:5
|
||||
--> $DIR/fixpoint-exponential-growth.rs:29:13
|
||||
|
|
||||
LL | impls::<W<_>>();
|
||||
| ^^^^^^^^^^^^^
|
||||
| ^^^^
|
||||
|
|
||||
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`fixpoint_exponential_growth`)
|
||||
note: required by a bound in `impls`
|
||||
|
@ -1,8 +1,8 @@
|
||||
error[E0275]: overflow evaluating the requirement `(): Trait`
|
||||
--> $DIR/double-cycle-inductive-coinductive.rs:32:5
|
||||
--> $DIR/double-cycle-inductive-coinductive.rs:32:19
|
||||
|
|
||||
LL | impls_trait::<()>();
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
| ^^
|
||||
|
|
||||
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`double_cycle_inductive_coinductive`)
|
||||
note: required by a bound in `impls_trait`
|
||||
@ -12,10 +12,10 @@ LL | fn impls_trait<T: Trait>() {}
|
||||
| ^^^^^ required by this bound in `impls_trait`
|
||||
|
||||
error[E0275]: overflow evaluating the requirement `(): TraitRev`
|
||||
--> $DIR/double-cycle-inductive-coinductive.rs:35:5
|
||||
--> $DIR/double-cycle-inductive-coinductive.rs:35:23
|
||||
|
|
||||
LL | impls_trait_rev::<()>();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^
|
||||
|
|
||||
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`double_cycle_inductive_coinductive`)
|
||||
note: required by a bound in `impls_trait_rev`
|
||||
|
@ -1,8 +1,8 @@
|
||||
error[E0275]: overflow evaluating the requirement `(): AR`
|
||||
--> $DIR/inductive-not-on-stack.rs:44:5
|
||||
--> $DIR/inductive-not-on-stack.rs:44:16
|
||||
|
|
||||
LL | impls_ar::<()>();
|
||||
| ^^^^^^^^^^^^^^
|
||||
| ^^
|
||||
|
|
||||
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`inductive_not_on_stack`)
|
||||
note: required by a bound in `impls_ar`
|
||||
|
@ -1,8 +1,8 @@
|
||||
error[E0283]: type annotations needed: cannot satisfy `Foo: Send`
|
||||
--> $DIR/dont-type_of-tait-in-defining-scope.rs:16:5
|
||||
--> $DIR/dont-type_of-tait-in-defining-scope.rs:16:18
|
||||
|
|
||||
LL | needs_send::<Foo>();
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
| ^^^
|
||||
|
|
||||
= note: cannot satisfy `Foo: Send`
|
||||
note: required by a bound in `needs_send`
|
||||
|
@ -5,10 +5,10 @@ LL | impls::<W<_>>();
|
||||
| ^^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `impls`
|
||||
|
||||
error[E0275]: overflow evaluating the requirement `W<_>: Trait`
|
||||
--> $DIR/exponential-trait-goals.rs:17:5
|
||||
--> $DIR/exponential-trait-goals.rs:17:13
|
||||
|
|
||||
LL | impls::<W<_>>();
|
||||
| ^^^^^^^^^^^^^
|
||||
| ^^^^
|
||||
|
|
||||
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`exponential_trait_goals`)
|
||||
note: required by a bound in `impls`
|
||||
|
@ -1,8 +1,8 @@
|
||||
error[E0275]: overflow evaluating the requirement `Inc<Inc<Inc<Inc<Inc<Inc<Inc<...>>>>>>>: Trait`
|
||||
--> $DIR/global-cache.rs:21:5
|
||||
--> $DIR/global-cache.rs:21:19
|
||||
|
|
||||
LL | impls_trait::<Four<Four<Four<Four<()>>>>>();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "18"]` attribute to your crate (`global_cache`)
|
||||
note: required by a bound in `impls_trait`
|
||||
|
@ -1,8 +1,8 @@
|
||||
error[E0275]: overflow evaluating the requirement `<T as Foo1>::Assoc1: Bar`
|
||||
--> $DIR/recursive-self-normalization-2.rs:16:5
|
||||
--> $DIR/recursive-self-normalization-2.rs:16:17
|
||||
|
|
||||
LL | needs_bar::<T::Assoc1>();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`recursive_self_normalization_2`)
|
||||
note: required by a bound in `needs_bar`
|
||||
|
@ -1,8 +1,8 @@
|
||||
error[E0275]: overflow evaluating the requirement `<T as Foo>::Assoc: Bar`
|
||||
--> $DIR/recursive-self-normalization.rs:12:5
|
||||
--> $DIR/recursive-self-normalization.rs:12:17
|
||||
|
|
||||
LL | needs_bar::<T::Assoc>();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^
|
||||
|
|
||||
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "256"]` attribute to your crate (`recursive_self_normalization`)
|
||||
note: required by a bound in `needs_bar`
|
||||
|
@ -15,10 +15,10 @@ LL | default type Id = T;
|
||||
| ^ cannot infer type for associated type `<T as Default>::Id`
|
||||
|
||||
error[E0284]: type annotations needed: cannot satisfy `<u32 as Default>::Id == ()`
|
||||
--> $DIR/specialization-unconstrained.rs:20:5
|
||||
--> $DIR/specialization-unconstrained.rs:20:12
|
||||
|
|
||||
LL | test::<u32, ()>();
|
||||
| ^^^^^^^^^^^^^^^ cannot satisfy `<u32 as Default>::Id == ()`
|
||||
| ^^^ cannot satisfy `<u32 as Default>::Id == ()`
|
||||
|
|
||||
note: required by a bound in `test`
|
||||
--> $DIR/specialization-unconstrained.rs:17:20
|
||||
|
@ -1,8 +1,8 @@
|
||||
error[E0283]: type annotations needed: cannot satisfy `T: Bar`
|
||||
--> $DIR/two-projection-param-candidates-are-ambiguous.rs:26:5
|
||||
--> $DIR/two-projection-param-candidates-are-ambiguous.rs:26:17
|
||||
|
|
||||
LL | needs_bar::<T>();
|
||||
| ^^^^^^^^^^^^^^
|
||||
| ^
|
||||
|
|
||||
= note: cannot satisfy `T: Bar`
|
||||
= help: the trait `Bar` is implemented for `T`
|
||||
|
@ -1,10 +1,8 @@
|
||||
error[E0277]: the trait bound `(): Marker<u32>` is not satisfied
|
||||
--> $DIR/issue-90804-incorrect-reference-suggestion.rs:10:17
|
||||
--> $DIR/issue-90804-incorrect-reference-suggestion.rs:10:13
|
||||
|
|
||||
LL | check::<()>(());
|
||||
| ----------- ^^ the trait `Marker<u32>` is not implemented for `()`
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
| ^^ the trait `Marker<u32>` is not implemented for `()`
|
||||
|
|
||||
note: required by a bound in `check`
|
||||
--> $DIR/issue-90804-incorrect-reference-suggestion.rs:7:17
|
||||
|
@ -1,12 +1,10 @@
|
||||
error[E0277]: the size for values of type `X` cannot be known at compilation time
|
||||
--> $DIR/unsized3.rs:7:13
|
||||
--> $DIR/unsized3.rs:7:10
|
||||
|
|
||||
LL | fn f1<X: ?Sized>(x: &X) {
|
||||
| - this type parameter needs to be `Sized`
|
||||
LL | f2::<X>(x);
|
||||
| ------- ^ doesn't have a size known at compile-time
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
| ^ doesn't have a size known at compile-time
|
||||
|
|
||||
note: required by a bound in `f2`
|
||||
--> $DIR/unsized3.rs:10:7
|
||||
@ -24,14 +22,12 @@ LL | fn f2<X: ?Sized>(x: &X) {
|
||||
| ++++++++
|
||||
|
||||
error[E0277]: the size for values of type `X` cannot be known at compilation time
|
||||
--> $DIR/unsized3.rs:18:13
|
||||
--> $DIR/unsized3.rs:18:10
|
||||
|
|
||||
LL | fn f3<X: ?Sized + T>(x: &X) {
|
||||
| - this type parameter needs to be `Sized`
|
||||
LL | f4::<X>(x);
|
||||
| ------- ^ doesn't have a size known at compile-time
|
||||
| |
|
||||
| required by a bound introduced by this call
|
||||
| ^ doesn't have a size known at compile-time
|
||||
|
|
||||
note: required by a bound in `f4`
|
||||
--> $DIR/unsized3.rs:21:7
|
||||
|
Loading…
Reference in New Issue
Block a user