diff options
| author | Yuki Okushi <jtitor@2k36.org> | 2022-05-11 13:16:34 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-11 13:16:34 +0900 |
| commit | 17a735b69a3e9c59f7755d43a0e4b26867e72852 (patch) | |
| tree | 83e032bc5e9e4367121c622eb4ad4adcbc017d76 | |
| parent | 95b2d37a392d50a7a42b7b4936386cbf926a27d7 (diff) | |
| parent | d63f82e1efbfbe2344ffa3a47602faaee6429d04 (diff) | |
| download | rust-17a735b69a3e9c59f7755d43a0e4b26867e72852.tar.gz rust-17a735b69a3e9c59f7755d43a0e4b26867e72852.zip | |
Rollup merge of #96903 - oli-obk:opaque_type_lifetime_constraints, r=compiler-errors
Use lifetimes on type-alias-impl-trait used in function signatures to infer output type lifetimes
fixes https://github.com/rust-lang/rust/issues/96564
TLDR:
```rust
fn execute(ty: Ty<'_>) -> &str { todo!() }
```
(`Ty` being a type alias impl trait) used to produce the following error before this PR
```
error[E0581]: return type references an anonymous lifetime, which is not constrained by the fn input types
--> src/lib.rs:4:27
|
4 | fn execute(ty: Ty<'_>) -> &str { todo!() }
| ^^^^
|
= note: lifetimes appearing in an associated type are not considered constrained
```
| -rw-r--r-- | compiler/rustc_middle/src/ty/fold.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/type-alias-impl-trait/constrain_inputs.rs | 17 |
2 files changed, 18 insertions, 1 deletions
diff --git a/compiler/rustc_middle/src/ty/fold.rs b/compiler/rustc_middle/src/ty/fold.rs index 896a8280551..a2a450d76f1 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 00000000000..c32174288ee --- /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() {} |
