mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 00:34:06 +00:00
generic_arg_contains_target
: ignore closures
This commit is contained in:
parent
69d575e58d
commit
681736a6b2
@ -700,8 +700,14 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
|
||||
match inner.unpack() {
|
||||
GenericArgKind::Lifetime(_) => {}
|
||||
GenericArgKind::Type(ty) => {
|
||||
if matches!(ty.kind(), ty::Opaque(..)) {
|
||||
// Opaque types can't be named by the user right now
|
||||
if matches!(ty.kind(), ty::Opaque(..) | ty::Closure(..) | ty::Generator(..)) {
|
||||
// Opaque types can't be named by the user right now.
|
||||
//
|
||||
// Both the generic arguments of closures and generators can
|
||||
// also not be named. We may want to only look into the closure
|
||||
// signature in case it has no captures, as that can be represented
|
||||
// using `fn(T) -> R`.
|
||||
|
||||
// FIXME(type_alias_impl_trait): These opaque types
|
||||
// can actually be named, so it would make sense to
|
||||
// adjust this case and add a test for it.
|
||||
|
@ -4,10 +4,10 @@ fn main() {
|
||||
// error handles this gracefully, and in particular doesn't generate an extra
|
||||
// note about the `?` operator in the closure body, which isn't relevant to
|
||||
// the inference.
|
||||
let x = |r| { //~ ERROR type annotations needed for `Result<(), E>`
|
||||
let x = |r| {
|
||||
let v = r?;
|
||||
Ok(v)
|
||||
};
|
||||
|
||||
let _ = x(x(Ok(())));
|
||||
let _ = x(x(Ok(()))); //~ ERROR type annotations needed for `Result<(), E>`
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
error[E0282]: type annotations needed for `Result<(), E>`
|
||||
--> $DIR/cannot-infer-closure-circular.rs:7:14
|
||||
--> $DIR/cannot-infer-closure-circular.rs:12:9
|
||||
|
|
||||
LL | let x = |r| {
|
||||
| ^
|
||||
LL | let _ = x(x(Ok(())));
|
||||
| ^
|
||||
|
|
||||
help: consider giving this closure parameter an explicit type, where the type for type parameter `E` is specified
|
||||
help: consider giving this pattern a type, where the type for type parameter `E` is specified
|
||||
|
|
||||
LL | let x = |r: Result<(), E>| {
|
||||
| +++++++++++++++
|
||||
LL | let _: Result<(), E> = x(x(Ok(())));
|
||||
| +++++++++++++++
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
@ -1,13 +1,8 @@
|
||||
error[E0282]: type annotations needed for the closure `fn(Vec<_>)`
|
||||
--> $DIR/unknown_type_for_closure.rs:2:9
|
||||
error[E0282]: type annotations needed
|
||||
--> $DIR/unknown_type_for_closure.rs:2:13
|
||||
|
|
||||
LL | let x = |b: Vec<_>| {};
|
||||
| ^
|
||||
|
|
||||
help: consider giving `x` an explicit type, where the type for struct `Vec<_>` is specified
|
||||
|
|
||||
LL | let x: [closure@$DIR/unknown_type_for_closure.rs:2:13: 2:27] = |b: Vec<_>| {};
|
||||
| +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
| ^^^^^^^^^^^^^^ cannot infer type for struct `Vec<_>`
|
||||
|
||||
error[E0282]: type annotations needed
|
||||
--> $DIR/unknown_type_for_closure.rs:6:14
|
||||
@ -20,16 +15,11 @@ help: consider giving this closure parameter an explicit type
|
||||
LL | let x = |_: _| {};
|
||||
| +++
|
||||
|
||||
error[E0282]: type annotations needed for the closure `fn(_)`
|
||||
--> $DIR/unknown_type_for_closure.rs:10:9
|
||||
error[E0282]: type annotations needed
|
||||
--> $DIR/unknown_type_for_closure.rs:10:14
|
||||
|
|
||||
LL | let x = |k: _| {};
|
||||
| ^
|
||||
|
|
||||
help: consider giving `x` an explicit type, where the placeholders `_` are specified
|
||||
|
|
||||
LL | let x: [closure@$DIR/unknown_type_for_closure.rs:10:13: 10:22] = |k: _| {};
|
||||
| +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
| ^ cannot infer type
|
||||
|
||||
error[E0282]: type annotations needed
|
||||
--> $DIR/unknown_type_for_closure.rs:14:28
|
||||
|
Loading…
Reference in New Issue
Block a user