From d63f82e1efbfbe2344ffa3a47602faaee6429d04 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 10 May 2022 14:50:31 +0000 Subject: [PATCH] Use lifetimes on type-alias-impl-trait used in function signatures to infer output type lifetimes --- compiler/rustc_middle/src/ty/fold.rs | 2 +- .../type-alias-impl-trait/constrain_inputs.rs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/type-alias-impl-trait/constrain_inputs.rs diff --git a/compiler/rustc_middle/src/ty/fold.rs b/compiler/rustc_middle/src/ty/fold.rs index 896a8280551d2..a2a450d76f18a 100644 --- a/compiler/rustc_middle/src/ty/fold.rs +++ b/compiler/rustc_middle/src/ty/fold.rs @@ -1349,7 +1349,7 @@ impl<'tcx> TypeVisitor<'tcx> for LateBoundRegionsCollector { // ignore the inputs to a projection, as they may not appear // in the normalized form if self.just_constrained { - if let ty::Projection(..) | ty::Opaque(..) = t.kind() { + if let ty::Projection(..) = t.kind() { return ControlFlow::CONTINUE; } } diff --git a/src/test/ui/type-alias-impl-trait/constrain_inputs.rs b/src/test/ui/type-alias-impl-trait/constrain_inputs.rs new file mode 100644 index 0000000000000..c32174288ee68 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/constrain_inputs.rs @@ -0,0 +1,17 @@ +// check-pass + +#![feature(type_alias_impl_trait)] + +mod foo { + type Ty<'a> = impl Sized; + fn defining(s: &str) -> Ty<'_> { s } + fn execute(ty: Ty<'_>) -> &str { todo!() } +} + +mod bar { + type Ty<'a> = impl FnOnce() -> &'a str; + fn defining(s: &str) -> Ty<'_> { move || s } + fn execute(ty: Ty<'_>) -> &str { ty() } +} + +fn main() {}