mirror of https://github.com/rust-lang/rust.git
Rollup merge of #122100 - compiler-errors:better-capture, r=oli-obk
Better comment for implicit captures in RPITIT Improve the error message for implicit captures. Also always set E0657. r? oli-obk
This commit is contained in:
commit
e76bd6214f
|
@ -1,57 +1,26 @@
|
||||||
A lifetime bound on a trait implementation was captured at an incorrect place.
|
An `impl Trait` captured a higher-ranked lifetime, which is not supported.
|
||||||
|
|
||||||
|
Currently, `impl Trait` types are only allowed to capture lifetimes from
|
||||||
|
their parent items, and not from any `for<'a>` binders in scope.
|
||||||
|
|
||||||
Erroneous code example:
|
Erroneous code example:
|
||||||
|
|
||||||
```compile_fail,E0657
|
```compile_fail,E0657
|
||||||
trait Id<T> {}
|
trait BorrowInto<'a> {
|
||||||
trait Lt<'a> {}
|
type Target;
|
||||||
|
|
||||||
impl<'a> Lt<'a> for () {}
|
fn borrow_into(&'a self) -> Self::Target;
|
||||||
impl<T> Id<T> for T {}
|
|
||||||
|
|
||||||
fn free_fn_capture_hrtb_in_impl_trait()
|
|
||||||
-> Box<for<'a> Id<impl Lt<'a>>> // error!
|
|
||||||
{
|
|
||||||
Box::new(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Foo;
|
impl<'a> BorrowInto<'a> for () {
|
||||||
impl Foo {
|
type Target = &'a ();
|
||||||
fn impl_fn_capture_hrtb_in_impl_trait()
|
|
||||||
-> Box<for<'a> Id<impl Lt<'a>>> // error!
|
fn borrow_into(&'a self) -> Self::Target {
|
||||||
{
|
self
|
||||||
Box::new(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
|
||||||
|
|
||||||
Here, you have used the inappropriate lifetime in the `impl Trait`,
|
fn opaque() -> impl for<'a> BorrowInto<'a, Target = impl Sized + 'a> {
|
||||||
The `impl Trait` can only capture lifetimes bound at the fn or impl
|
()
|
||||||
level.
|
|
||||||
|
|
||||||
To fix this we have to define the lifetime at the function or impl
|
|
||||||
level and use that lifetime in the `impl Trait`. For example you can
|
|
||||||
define the lifetime at the function:
|
|
||||||
|
|
||||||
```
|
|
||||||
trait Id<T> {}
|
|
||||||
trait Lt<'a> {}
|
|
||||||
|
|
||||||
impl<'a> Lt<'a> for () {}
|
|
||||||
impl<T> Id<T> for T {}
|
|
||||||
|
|
||||||
fn free_fn_capture_hrtb_in_impl_trait<'b>()
|
|
||||||
-> Box<for<'a> Id<impl Lt<'b>>> // ok!
|
|
||||||
{
|
|
||||||
Box::new(())
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Foo;
|
|
||||||
impl Foo {
|
|
||||||
fn impl_fn_capture_hrtb_in_impl_trait<'b>()
|
|
||||||
-> Box<for<'a> Id<impl Lt<'b>>> // ok!
|
|
||||||
{
|
|
||||||
Box::new(())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
|
@ -312,6 +312,10 @@ hir_analysis_only_current_traits_primitive = only traits defined in the current
|
||||||
|
|
||||||
hir_analysis_only_current_traits_ty = `{$ty}` is not defined in the current crate
|
hir_analysis_only_current_traits_ty = `{$ty}` is not defined in the current crate
|
||||||
|
|
||||||
|
hir_analysis_opaque_captures_higher_ranked_lifetime = `impl Trait` cannot capture {$bad_place}
|
||||||
|
.label = `impl Trait` implicitly captures all lifetimes in scope
|
||||||
|
.note = lifetime declared here
|
||||||
|
|
||||||
hir_analysis_paren_sugar_attribute = the `#[rustc_paren_sugar]` attribute is a temporary means of controlling which traits can use parenthetical notation
|
hir_analysis_paren_sugar_attribute = the `#[rustc_paren_sugar]` attribute is a temporary means of controlling which traits can use parenthetical notation
|
||||||
.help = add `#![feature(unboxed_closures)]` to the crate attributes to use it
|
.help = add `#![feature(unboxed_closures)]` to the crate attributes to use it
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
use core::ops::ControlFlow;
|
use core::ops::ControlFlow;
|
||||||
use rustc_ast::visit::walk_list;
|
use rustc_ast::visit::walk_list;
|
||||||
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
|
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
|
||||||
use rustc_errors::{codes::*, struct_span_code_err};
|
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::{DefKind, Res};
|
use rustc_hir::def::{DefKind, Res};
|
||||||
use rustc_hir::def_id::LocalDefId;
|
use rustc_hir::def_id::LocalDefId;
|
||||||
|
@ -669,34 +668,47 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
|
||||||
// and ban them. Type variables instantiated inside binders aren't
|
// and ban them. Type variables instantiated inside binders aren't
|
||||||
// well-supported at the moment, so this doesn't work.
|
// well-supported at the moment, so this doesn't work.
|
||||||
// In the future, this should be fixed and this error should be removed.
|
// In the future, this should be fixed and this error should be removed.
|
||||||
let def = self.map.defs.get(&lifetime.hir_id).cloned();
|
let def = self.map.defs.get(&lifetime.hir_id).copied();
|
||||||
let Some(ResolvedArg::LateBound(_, _, def_id)) = def else { continue };
|
let Some(ResolvedArg::LateBound(_, _, lifetime_def_id)) = def else { continue };
|
||||||
let Some(def_id) = def_id.as_local() else { continue };
|
let Some(lifetime_def_id) = lifetime_def_id.as_local() else { continue };
|
||||||
let hir_id = self.tcx.local_def_id_to_hir_id(def_id);
|
let lifetime_hir_id = self.tcx.local_def_id_to_hir_id(lifetime_def_id);
|
||||||
// Ensure that the parent of the def is an item, not HRTB
|
|
||||||
let parent_id = self.tcx.parent_hir_id(hir_id);
|
let bad_place = match self.tcx.hir_node(self.tcx.parent_hir_id(lifetime_hir_id))
|
||||||
if !parent_id.is_owner() {
|
|
||||||
struct_span_code_err!(
|
|
||||||
self.tcx.dcx(),
|
|
||||||
lifetime.ident.span,
|
|
||||||
E0657,
|
|
||||||
"`impl Trait` can only capture lifetimes bound at the fn or impl level"
|
|
||||||
)
|
|
||||||
.emit();
|
|
||||||
self.uninsert_lifetime_on_error(lifetime, def.unwrap());
|
|
||||||
}
|
|
||||||
if let hir::Node::Item(hir::Item {
|
|
||||||
kind: hir::ItemKind::OpaqueTy { .. }, ..
|
|
||||||
}) = self.tcx.hir_node(parent_id)
|
|
||||||
{
|
{
|
||||||
self.tcx.dcx().struct_span_err(
|
// Opaques do not declare their own lifetimes, so if a lifetime comes from an opaque
|
||||||
lifetime.ident.span,
|
// it must be a reified late-bound lifetime from a trait goal.
|
||||||
"higher kinded lifetime bounds on nested opaque types are not supported yet",
|
hir::Node::Item(hir::Item {
|
||||||
)
|
kind: hir::ItemKind::OpaqueTy { .. }, ..
|
||||||
.with_span_note(self.tcx.def_span(def_id), "lifetime declared here")
|
}) => "higher-ranked lifetime from outer `impl Trait`",
|
||||||
.emit();
|
// Other items are fine.
|
||||||
self.uninsert_lifetime_on_error(lifetime, def.unwrap());
|
hir::Node::Item(_) | hir::Node::TraitItem(_) | hir::Node::ImplItem(_) => {
|
||||||
}
|
continue;
|
||||||
|
}
|
||||||
|
hir::Node::Ty(hir::Ty { kind: hir::TyKind::BareFn(_), .. }) => {
|
||||||
|
"higher-ranked lifetime from function pointer"
|
||||||
|
}
|
||||||
|
hir::Node::Ty(hir::Ty { kind: hir::TyKind::TraitObject(..), .. }) => {
|
||||||
|
"higher-ranked lifetime from `dyn` type"
|
||||||
|
}
|
||||||
|
_ => "higher-ranked lifetime",
|
||||||
|
};
|
||||||
|
|
||||||
|
let (span, label) = if lifetime.ident.span == self.tcx.def_span(lifetime_def_id)
|
||||||
|
{
|
||||||
|
let opaque_span = self.tcx.def_span(item_id.owner_id);
|
||||||
|
(opaque_span, Some(opaque_span))
|
||||||
|
} else {
|
||||||
|
(lifetime.ident.span, None)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Ensure that the parent of the def is an item, not HRTB
|
||||||
|
self.tcx.dcx().emit_err(errors::OpaqueCapturesHigherRankedLifetime {
|
||||||
|
span,
|
||||||
|
label,
|
||||||
|
decl_span: self.tcx.def_span(lifetime_def_id),
|
||||||
|
bad_place,
|
||||||
|
});
|
||||||
|
self.uninsert_lifetime_on_error(lifetime, def.unwrap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => intravisit::walk_ty(self, ty),
|
_ => intravisit::walk_ty(self, ty),
|
||||||
|
|
|
@ -1607,3 +1607,15 @@ pub struct UnnamedFieldsReprFieldDefined {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(hir_analysis_opaque_captures_higher_ranked_lifetime, code = E0657)]
|
||||||
|
pub struct OpaqueCapturesHigherRankedLifetime {
|
||||||
|
#[primary_span]
|
||||||
|
pub span: Span,
|
||||||
|
#[label]
|
||||||
|
pub label: Option<Span>,
|
||||||
|
#[note]
|
||||||
|
pub decl_span: Span,
|
||||||
|
pub bad_place: &'static str,
|
||||||
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ impl<T> Id<T> for T {}
|
||||||
|
|
||||||
fn free_fn_capture_hrtb_in_impl_trait()
|
fn free_fn_capture_hrtb_in_impl_trait()
|
||||||
-> Box<for<'a> Id<impl Lt<'a>>>
|
-> Box<for<'a> Id<impl Lt<'a>>>
|
||||||
//~^ ERROR `impl Trait` can only capture lifetimes bound at the fn or impl level [E0657]
|
//~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from `dyn` type
|
||||||
{
|
{
|
||||||
Box::new(())
|
Box::new(())
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ struct Foo;
|
||||||
impl Foo {
|
impl Foo {
|
||||||
fn impl_fn_capture_hrtb_in_impl_trait()
|
fn impl_fn_capture_hrtb_in_impl_trait()
|
||||||
-> Box<for<'a> Id<impl Lt<'a>>>
|
-> Box<for<'a> Id<impl Lt<'a>>>
|
||||||
//~^ ERROR `impl Trait` can only capture lifetimes bound at the fn or impl level
|
//~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from `dyn` type
|
||||||
{
|
{
|
||||||
Box::new(())
|
Box::new(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,26 @@
|
||||||
error[E0657]: `impl Trait` can only capture lifetimes bound at the fn or impl level
|
error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from `dyn` type
|
||||||
--> $DIR/E0657.rs:10:31
|
--> $DIR/E0657.rs:10:31
|
||||||
|
|
|
|
||||||
LL | -> Box<for<'a> Id<impl Lt<'a>>>
|
LL | -> Box<for<'a> Id<impl Lt<'a>>>
|
||||||
| ^^
|
| ^^
|
||||||
|
|
|
||||||
|
note: lifetime declared here
|
||||||
|
--> $DIR/E0657.rs:10:16
|
||||||
|
|
|
||||||
|
LL | -> Box<for<'a> Id<impl Lt<'a>>>
|
||||||
|
| ^^
|
||||||
|
|
||||||
error[E0657]: `impl Trait` can only capture lifetimes bound at the fn or impl level
|
error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from `dyn` type
|
||||||
--> $DIR/E0657.rs:19:35
|
--> $DIR/E0657.rs:19:35
|
||||||
|
|
|
|
||||||
LL | -> Box<for<'a> Id<impl Lt<'a>>>
|
LL | -> Box<for<'a> Id<impl Lt<'a>>>
|
||||||
| ^^
|
| ^^
|
||||||
|
|
|
||||||
|
note: lifetime declared here
|
||||||
|
--> $DIR/E0657.rs:19:20
|
||||||
|
|
|
||||||
|
LL | -> Box<for<'a> Id<impl Lt<'a>>>
|
||||||
|
| ^^
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
|
|
@ -2,19 +2,19 @@
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
|
||||||
fn a() -> impl Fn(&u8) -> (impl Debug + '_) {
|
fn a() -> impl Fn(&u8) -> (impl Debug + '_) {
|
||||||
//~^ ERROR higher kinded lifetime bounds on nested opaque types are not supported yet
|
//~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
|
||||||
|x| x
|
|x| x
|
||||||
//~^ ERROR lifetime may not live long enough
|
//~^ ERROR lifetime may not live long enough
|
||||||
}
|
}
|
||||||
|
|
||||||
fn b() -> impl for<'a> Fn(&'a u8) -> (impl Debug + 'a) {
|
fn b() -> impl for<'a> Fn(&'a u8) -> (impl Debug + 'a) {
|
||||||
//~^ ERROR higher kinded lifetime bounds on nested opaque types are not supported yet
|
//~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
|
||||||
|x| x
|
|x| x
|
||||||
//~^ ERROR lifetime may not live long enough
|
//~^ ERROR lifetime may not live long enough
|
||||||
}
|
}
|
||||||
|
|
||||||
fn c() -> impl for<'a> Fn(&'a u8) -> (impl Debug + '_) {
|
fn c() -> impl for<'a> Fn(&'a u8) -> (impl Debug + '_) {
|
||||||
//~^ ERROR higher kinded lifetime bounds on nested opaque types are not supported yet
|
//~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
|
||||||
|x| x
|
|x| x
|
||||||
//~^ ERROR lifetime may not live long enough
|
//~^ ERROR lifetime may not live long enough
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ help: consider using the `'static` lifetime, but this is uncommon unless you're
|
||||||
LL | fn d() -> impl Fn() -> (impl Debug + 'static) {
|
LL | fn d() -> impl Fn() -> (impl Debug + 'static) {
|
||||||
| ~~~~~~~
|
| ~~~~~~~
|
||||||
|
|
||||||
error: higher kinded lifetime bounds on nested opaque types are not supported yet
|
error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
|
||||||
--> $DIR/impl-fn-hrtb-bounds.rs:4:41
|
--> $DIR/impl-fn-hrtb-bounds.rs:4:41
|
||||||
|
|
|
|
||||||
LL | fn a() -> impl Fn(&u8) -> (impl Debug + '_) {
|
LL | fn a() -> impl Fn(&u8) -> (impl Debug + '_) {
|
||||||
|
@ -31,7 +31,7 @@ LL | |x| x
|
||||||
| |return type of closure is impl Debug + '2
|
| |return type of closure is impl Debug + '2
|
||||||
| has type `&'1 u8`
|
| has type `&'1 u8`
|
||||||
|
|
||||||
error: higher kinded lifetime bounds on nested opaque types are not supported yet
|
error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
|
||||||
--> $DIR/impl-fn-hrtb-bounds.rs:10:52
|
--> $DIR/impl-fn-hrtb-bounds.rs:10:52
|
||||||
|
|
|
|
||||||
LL | fn b() -> impl for<'a> Fn(&'a u8) -> (impl Debug + 'a) {
|
LL | fn b() -> impl for<'a> Fn(&'a u8) -> (impl Debug + 'a) {
|
||||||
|
@ -52,7 +52,7 @@ LL | |x| x
|
||||||
| |return type of closure is impl Debug + '2
|
| |return type of closure is impl Debug + '2
|
||||||
| has type `&'1 u8`
|
| has type `&'1 u8`
|
||||||
|
|
||||||
error: higher kinded lifetime bounds on nested opaque types are not supported yet
|
error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
|
||||||
--> $DIR/impl-fn-hrtb-bounds.rs:16:52
|
--> $DIR/impl-fn-hrtb-bounds.rs:16:52
|
||||||
|
|
|
|
||||||
LL | fn c() -> impl for<'a> Fn(&'a u8) -> (impl Debug + '_) {
|
LL | fn c() -> impl for<'a> Fn(&'a u8) -> (impl Debug + '_) {
|
||||||
|
@ -75,4 +75,5 @@ LL | |x| x
|
||||||
|
|
||||||
error: aborting due to 7 previous errors
|
error: aborting due to 7 previous errors
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0106`.
|
Some errors have detailed explanations: E0106, E0657.
|
||||||
|
For more information about an error, try `rustc --explain E0106`.
|
||||||
|
|
|
@ -3,7 +3,7 @@ use std::fmt::Debug;
|
||||||
|
|
||||||
fn a() -> impl Fn(&u8) -> impl Debug + '_ {
|
fn a() -> impl Fn(&u8) -> impl Debug + '_ {
|
||||||
//~^ ERROR ambiguous `+` in a type
|
//~^ ERROR ambiguous `+` in a type
|
||||||
//~| ERROR higher kinded lifetime bounds on nested opaque types are not supported yet
|
//~| ERROR cannot capture higher-ranked lifetime from outer `impl Trait`
|
||||||
|x| x
|
|x| x
|
||||||
//~^ ERROR lifetime may not live long enough
|
//~^ ERROR lifetime may not live long enough
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ error: ambiguous `+` in a type
|
||||||
LL | fn b() -> impl Fn() -> impl Debug + Send {
|
LL | fn b() -> impl Fn() -> impl Debug + Send {
|
||||||
| ^^^^^^^^^^^^^^^^^ help: use parentheses to disambiguate: `(impl Debug + Send)`
|
| ^^^^^^^^^^^^^^^^^ help: use parentheses to disambiguate: `(impl Debug + Send)`
|
||||||
|
|
||||||
error: higher kinded lifetime bounds on nested opaque types are not supported yet
|
error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
|
||||||
--> $DIR/impl-fn-parsing-ambiguities.rs:4:40
|
--> $DIR/impl-fn-parsing-ambiguities.rs:4:40
|
||||||
|
|
|
|
||||||
LL | fn a() -> impl Fn(&u8) -> impl Debug + '_ {
|
LL | fn a() -> impl Fn(&u8) -> impl Debug + '_ {
|
||||||
|
@ -33,3 +33,4 @@ LL | |x| x
|
||||||
|
|
||||||
error: aborting due to 4 previous errors
|
error: aborting due to 4 previous errors
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0657`.
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
error[E0657]: `impl Trait` can only capture lifetimes bound at the fn or impl level
|
error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from `dyn` type
|
||||||
|
--> $DIR/implicit-capture-late.rs:10:55
|
||||||
|
|
|
||||||
|
LL | fn foo(x: Vec<i32>) -> Box<dyn for<'a> Deref<Target = impl ?Sized>> {
|
||||||
|
| ^^^^^^^^^^^ `impl Trait` implicitly captures all lifetimes in scope
|
||||||
|
|
|
||||||
|
note: lifetime declared here
|
||||||
--> $DIR/implicit-capture-late.rs:10:36
|
--> $DIR/implicit-capture-late.rs:10:36
|
||||||
|
|
|
|
||||||
LL | fn foo(x: Vec<i32>) -> Box<dyn for<'a> Deref<Target = impl ?Sized>> {
|
LL | fn foo(x: Vec<i32>) -> Box<dyn for<'a> Deref<Target = impl ?Sized>> {
|
||||||
|
|
|
@ -13,7 +13,7 @@ impl<'a> Trait<'a> for X {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn f() -> impl for<'a> Trait<'a, Out = impl Sized + 'a> {
|
fn f() -> impl for<'a> Trait<'a, Out = impl Sized + 'a> {
|
||||||
//~^ ERROR higher kinded lifetime bounds on nested opaque types are not supported yet
|
//~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
|
||||||
X(())
|
X(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
error: higher kinded lifetime bounds on nested opaque types are not supported yet
|
error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
|
||||||
--> $DIR/issue-54895.rs:15:53
|
--> $DIR/issue-54895.rs:15:53
|
||||||
|
|
|
|
||||||
LL | fn f() -> impl for<'a> Trait<'a, Out = impl Sized + 'a> {
|
LL | fn f() -> impl for<'a> Trait<'a, Out = impl Sized + 'a> {
|
||||||
|
@ -12,3 +12,4 @@ LL | fn f() -> impl for<'a> Trait<'a, Out = impl Sized + 'a> {
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0657`.
|
||||||
|
|
|
@ -19,7 +19,7 @@ where
|
||||||
|
|
||||||
struct A;
|
struct A;
|
||||||
fn test() -> impl for<'a> MyFn<&'a A, Output=impl Iterator + 'a> {
|
fn test() -> impl for<'a> MyFn<&'a A, Output=impl Iterator + 'a> {
|
||||||
//~^ ERROR higher kinded lifetime bounds on nested opaque types are not supported yet
|
//~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
|
||||||
Wrap(|a| Some(a).into_iter())
|
Wrap(|a| Some(a).into_iter())
|
||||||
//~^ ERROR implementation of `FnOnce` is not general enough
|
//~^ ERROR implementation of `FnOnce` is not general enough
|
||||||
//~| ERROR implementation of `FnOnce` is not general enough
|
//~| ERROR implementation of `FnOnce` is not general enough
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
error: higher kinded lifetime bounds on nested opaque types are not supported yet
|
error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
|
||||||
--> $DIR/issue-67830.rs:21:62
|
--> $DIR/issue-67830.rs:21:62
|
||||||
|
|
|
|
||||||
LL | fn test() -> impl for<'a> MyFn<&'a A, Output=impl Iterator + 'a> {
|
LL | fn test() -> impl for<'a> MyFn<&'a A, Output=impl Iterator + 'a> {
|
||||||
|
@ -31,3 +31,4 @@ LL | Wrap(|a| Some(a).into_iter())
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0657`.
|
||||||
|
|
|
@ -13,17 +13,17 @@ impl<'a> Hrtb<'a> for &'a () {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_impl() -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> {}
|
fn make_impl() -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> {}
|
||||||
//~^ ERROR higher kinded lifetime bounds on nested opaque types are not supported yet
|
//~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
|
||||||
|
|
||||||
fn make_weird_impl<'b>(x: &'b ()) -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> {
|
fn make_weird_impl<'b>(x: &'b ()) -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> {
|
||||||
//~^ ERROR higher kinded lifetime bounds on nested opaque types are not supported yet
|
//~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
|
||||||
&()
|
&()
|
||||||
//~^ ERROR implementation of `Hrtb` is not general enough
|
//~^ ERROR implementation of `Hrtb` is not general enough
|
||||||
//~| ERROR implementation of `Hrtb` is not general enough
|
//~| ERROR implementation of `Hrtb` is not general enough
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_bad_impl<'b>(x: &'b ()) -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> {
|
fn make_bad_impl<'b>(x: &'b ()) -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> {
|
||||||
//~^ ERROR higher kinded lifetime bounds on nested opaque types are not supported yet
|
//~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
|
||||||
x
|
x
|
||||||
//~^ ERROR implementation of `Hrtb` is not general enough
|
//~^ ERROR implementation of `Hrtb` is not general enough
|
||||||
//~| ERROR implementation of `Hrtb` is not general enough
|
//~| ERROR implementation of `Hrtb` is not general enough
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
error: higher kinded lifetime bounds on nested opaque types are not supported yet
|
error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
|
||||||
--> $DIR/issue-88236-2.rs:15:61
|
--> $DIR/issue-88236-2.rs:15:61
|
||||||
|
|
|
|
||||||
LL | fn make_impl() -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> {}
|
LL | fn make_impl() -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> {}
|
||||||
|
@ -10,7 +10,7 @@ note: lifetime declared here
|
||||||
LL | fn make_impl() -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> {}
|
LL | fn make_impl() -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> {}
|
||||||
| ^^
|
| ^^
|
||||||
|
|
||||||
error: higher kinded lifetime bounds on nested opaque types are not supported yet
|
error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
|
||||||
--> $DIR/issue-88236-2.rs:18:80
|
--> $DIR/issue-88236-2.rs:18:80
|
||||||
|
|
|
|
||||||
LL | fn make_weird_impl<'b>(x: &'b ()) -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> {
|
LL | fn make_weird_impl<'b>(x: &'b ()) -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> {
|
||||||
|
@ -40,7 +40,7 @@ LL | &()
|
||||||
= note: `Hrtb<'a>` would have to be implemented for the type `&()`
|
= note: `Hrtb<'a>` would have to be implemented for the type `&()`
|
||||||
= note: ...but `Hrtb<'0>` is actually implemented for the type `&'0 ()`, for some specific lifetime `'0`
|
= note: ...but `Hrtb<'0>` is actually implemented for the type `&'0 ()`, for some specific lifetime `'0`
|
||||||
|
|
||||||
error: higher kinded lifetime bounds on nested opaque types are not supported yet
|
error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
|
||||||
--> $DIR/issue-88236-2.rs:25:78
|
--> $DIR/issue-88236-2.rs:25:78
|
||||||
|
|
|
|
||||||
LL | fn make_bad_impl<'b>(x: &'b ()) -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> {
|
LL | fn make_bad_impl<'b>(x: &'b ()) -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> {
|
||||||
|
@ -90,3 +90,4 @@ LL | x
|
||||||
|
|
||||||
error: aborting due to 8 previous errors
|
error: aborting due to 8 previous errors
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0657`.
|
||||||
|
|
|
@ -13,6 +13,6 @@ impl<'a> Hrtb<'a> for &'a () {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_impl() -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> {}
|
fn make_impl() -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> {}
|
||||||
//~^ ERROR higher kinded lifetime bounds on nested opaque types are not supported yet
|
//~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
error: higher kinded lifetime bounds on nested opaque types are not supported yet
|
error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
|
||||||
--> $DIR/issue-88236.rs:15:61
|
--> $DIR/issue-88236.rs:15:61
|
||||||
|
|
|
|
||||||
LL | fn make_impl() -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> {}
|
LL | fn make_impl() -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> {}
|
||||||
|
@ -12,3 +12,4 @@ LL | fn make_impl() -> impl for<'a> Hrtb<'a, Assoc = impl Send + 'a> {}
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0657`.
|
||||||
|
|
|
@ -23,18 +23,18 @@ impl Qux<'_> for () {}
|
||||||
|
|
||||||
// This is not supported.
|
// This is not supported.
|
||||||
fn one_hrtb_outlives() -> impl for<'a> Foo<'a, Assoc = impl Sized + 'a> {}
|
fn one_hrtb_outlives() -> impl for<'a> Foo<'a, Assoc = impl Sized + 'a> {}
|
||||||
//~^ ERROR higher kinded lifetime bounds on nested opaque types are not supported yet
|
//~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
|
||||||
|
|
||||||
// This is not supported.
|
// This is not supported.
|
||||||
fn one_hrtb_trait_param() -> impl for<'a> Foo<'a, Assoc = impl Qux<'a>> {}
|
fn one_hrtb_trait_param() -> impl for<'a> Foo<'a, Assoc = impl Qux<'a>> {}
|
||||||
//~^ ERROR higher kinded lifetime bounds on nested opaque types are not supported yet
|
//~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
|
||||||
|
|
||||||
fn one_hrtb_outlives_uses() -> impl for<'a> Bar<'a, Assoc = impl Sized + 'a> {}
|
fn one_hrtb_outlives_uses() -> impl for<'a> Bar<'a, Assoc = impl Sized + 'a> {}
|
||||||
//~^ ERROR higher kinded lifetime bounds on nested opaque types are not supported yet
|
//~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
|
||||||
//~| ERROR implementation of `Bar` is not general enough
|
//~| ERROR implementation of `Bar` is not general enough
|
||||||
|
|
||||||
fn one_hrtb_trait_param_uses() -> impl for<'a> Bar<'a, Assoc = impl Qux<'a>> {}
|
fn one_hrtb_trait_param_uses() -> impl for<'a> Bar<'a, Assoc = impl Qux<'a>> {}
|
||||||
//~^ ERROR higher kinded lifetime bounds on nested opaque types are not supported yet
|
//~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
|
||||||
//~| ERROR: the trait bound `for<'a> &'a (): Qux<'_>` is not satisfied
|
//~| ERROR: the trait bound `for<'a> &'a (): Qux<'_>` is not satisfied
|
||||||
|
|
||||||
// This should resolve.
|
// This should resolve.
|
||||||
|
|
|
@ -29,7 +29,7 @@ help: consider introducing lifetime `'b` here
|
||||||
LL | fn two_htrb_outlives_uses<'b>() -> impl for<'a> Bar<'a, Assoc = impl for<'b> Sized + 'b> {}
|
LL | fn two_htrb_outlives_uses<'b>() -> impl for<'a> Bar<'a, Assoc = impl for<'b> Sized + 'b> {}
|
||||||
| ++++
|
| ++++
|
||||||
|
|
||||||
error: higher kinded lifetime bounds on nested opaque types are not supported yet
|
error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
|
||||||
--> $DIR/nested-rpit-hrtb.rs:25:69
|
--> $DIR/nested-rpit-hrtb.rs:25:69
|
||||||
|
|
|
|
||||||
LL | fn one_hrtb_outlives() -> impl for<'a> Foo<'a, Assoc = impl Sized + 'a> {}
|
LL | fn one_hrtb_outlives() -> impl for<'a> Foo<'a, Assoc = impl Sized + 'a> {}
|
||||||
|
@ -41,7 +41,7 @@ note: lifetime declared here
|
||||||
LL | fn one_hrtb_outlives() -> impl for<'a> Foo<'a, Assoc = impl Sized + 'a> {}
|
LL | fn one_hrtb_outlives() -> impl for<'a> Foo<'a, Assoc = impl Sized + 'a> {}
|
||||||
| ^^
|
| ^^
|
||||||
|
|
||||||
error: higher kinded lifetime bounds on nested opaque types are not supported yet
|
error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
|
||||||
--> $DIR/nested-rpit-hrtb.rs:29:68
|
--> $DIR/nested-rpit-hrtb.rs:29:68
|
||||||
|
|
|
|
||||||
LL | fn one_hrtb_trait_param() -> impl for<'a> Foo<'a, Assoc = impl Qux<'a>> {}
|
LL | fn one_hrtb_trait_param() -> impl for<'a> Foo<'a, Assoc = impl Qux<'a>> {}
|
||||||
|
@ -53,7 +53,7 @@ note: lifetime declared here
|
||||||
LL | fn one_hrtb_trait_param() -> impl for<'a> Foo<'a, Assoc = impl Qux<'a>> {}
|
LL | fn one_hrtb_trait_param() -> impl for<'a> Foo<'a, Assoc = impl Qux<'a>> {}
|
||||||
| ^^
|
| ^^
|
||||||
|
|
||||||
error: higher kinded lifetime bounds on nested opaque types are not supported yet
|
error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
|
||||||
--> $DIR/nested-rpit-hrtb.rs:32:74
|
--> $DIR/nested-rpit-hrtb.rs:32:74
|
||||||
|
|
|
|
||||||
LL | fn one_hrtb_outlives_uses() -> impl for<'a> Bar<'a, Assoc = impl Sized + 'a> {}
|
LL | fn one_hrtb_outlives_uses() -> impl for<'a> Bar<'a, Assoc = impl Sized + 'a> {}
|
||||||
|
@ -74,7 +74,7 @@ LL | fn one_hrtb_outlives_uses() -> impl for<'a> Bar<'a, Assoc = impl Sized + 'a
|
||||||
= note: `()` must implement `Bar<'a>`
|
= note: `()` must implement `Bar<'a>`
|
||||||
= note: ...but it actually implements `Bar<'0>`, for some specific lifetime `'0`
|
= note: ...but it actually implements `Bar<'0>`, for some specific lifetime `'0`
|
||||||
|
|
||||||
error: higher kinded lifetime bounds on nested opaque types are not supported yet
|
error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
|
||||||
--> $DIR/nested-rpit-hrtb.rs:36:73
|
--> $DIR/nested-rpit-hrtb.rs:36:73
|
||||||
|
|
|
|
||||||
LL | fn one_hrtb_trait_param_uses() -> impl for<'a> Bar<'a, Assoc = impl Qux<'a>> {}
|
LL | fn one_hrtb_trait_param_uses() -> impl for<'a> Bar<'a, Assoc = impl Qux<'a>> {}
|
||||||
|
@ -133,5 +133,5 @@ LL | fn two_htrb_outlives_uses() -> impl for<'a> Bar<'a, Assoc = impl for<'b> Si
|
||||||
|
|
||||||
error: aborting due to 12 previous errors
|
error: aborting due to 12 previous errors
|
||||||
|
|
||||||
Some errors have detailed explanations: E0261, E0277.
|
Some errors have detailed explanations: E0261, E0277, E0657.
|
||||||
For more information about an error, try `rustc --explain E0261`.
|
For more information about an error, try `rustc --explain E0261`.
|
||||||
|
|
|
@ -7,7 +7,7 @@ pub trait Trait<'a> {
|
||||||
trait Test<'a> {}
|
trait Test<'a> {}
|
||||||
|
|
||||||
pub type Foo = impl for<'a> Trait<'a, Assoc = impl Test<'a>>;
|
pub type Foo = impl for<'a> Trait<'a, Assoc = impl Test<'a>>;
|
||||||
//~^ ERROR higher kinded lifetime bounds on nested opaque types are not supported yet
|
//~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
|
||||||
|
|
||||||
impl Trait<'_> for () {
|
impl Trait<'_> for () {
|
||||||
type Assoc = ();
|
type Assoc = ();
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
error: higher kinded lifetime bounds on nested opaque types are not supported yet
|
error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from outer `impl Trait`
|
||||||
--> $DIR/escaping-bound-var.rs:9:25
|
--> $DIR/escaping-bound-var.rs:9:47
|
||||||
|
|
|
|
||||||
LL | pub type Foo = impl for<'a> Trait<'a, Assoc = impl Test<'a>>;
|
LL | pub type Foo = impl for<'a> Trait<'a, Assoc = impl Test<'a>>;
|
||||||
| ^^
|
| ^^^^^^^^^^^^^ `impl Trait` implicitly captures all lifetimes in scope
|
||||||
|
|
|
|
||||||
note: lifetime declared here
|
note: lifetime declared here
|
||||||
--> $DIR/escaping-bound-var.rs:9:25
|
--> $DIR/escaping-bound-var.rs:9:25
|
||||||
|
@ -12,3 +12,4 @@ LL | pub type Foo = impl for<'a> Trait<'a, Assoc = impl Test<'a>>;
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0657`.
|
||||||
|
|
|
@ -12,11 +12,11 @@ type CapturedEarly<'a> = impl Sized + Captures<'a>; //~ [*, o]
|
||||||
//~^ ERROR: unconstrained opaque type
|
//~^ ERROR: unconstrained opaque type
|
||||||
|
|
||||||
type NotCapturedLate<'a> = dyn for<'b> Iterator<Item = impl Sized>; //~ [*, o, o]
|
type NotCapturedLate<'a> = dyn for<'b> Iterator<Item = impl Sized>; //~ [*, o, o]
|
||||||
//~^ ERROR `impl Trait` can only capture lifetimes bound at the fn or impl level
|
//~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from `dyn` type
|
||||||
//~| ERROR: unconstrained opaque type
|
//~| ERROR: unconstrained opaque type
|
||||||
|
|
||||||
type Captured<'a> = dyn for<'b> Iterator<Item = impl Sized + Captures<'a>>; //~ [*, o, o]
|
type Captured<'a> = dyn for<'b> Iterator<Item = impl Sized + Captures<'a>>; //~ [*, o, o]
|
||||||
//~^ ERROR `impl Trait` can only capture lifetimes bound at the fn or impl level
|
//~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from `dyn` type
|
||||||
//~| ERROR: unconstrained opaque type
|
//~| ERROR: unconstrained opaque type
|
||||||
|
|
||||||
type Bar<'a, 'b: 'b, T> = impl Sized; //~ ERROR [*, *, o, o, o]
|
type Bar<'a, 'b: 'b, T> = impl Sized; //~ ERROR [*, *, o, o, o]
|
||||||
|
|
|
@ -1,10 +1,22 @@
|
||||||
error[E0657]: `impl Trait` can only capture lifetimes bound at the fn or impl level
|
error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from `dyn` type
|
||||||
|
--> $DIR/variance.rs:14:56
|
||||||
|
|
|
||||||
|
LL | type NotCapturedLate<'a> = dyn for<'b> Iterator<Item = impl Sized>;
|
||||||
|
| ^^^^^^^^^^ `impl Trait` implicitly captures all lifetimes in scope
|
||||||
|
|
|
||||||
|
note: lifetime declared here
|
||||||
--> $DIR/variance.rs:14:36
|
--> $DIR/variance.rs:14:36
|
||||||
|
|
|
|
||||||
LL | type NotCapturedLate<'a> = dyn for<'b> Iterator<Item = impl Sized>;
|
LL | type NotCapturedLate<'a> = dyn for<'b> Iterator<Item = impl Sized>;
|
||||||
| ^^
|
| ^^
|
||||||
|
|
||||||
error[E0657]: `impl Trait` can only capture lifetimes bound at the fn or impl level
|
error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from `dyn` type
|
||||||
|
--> $DIR/variance.rs:18:49
|
||||||
|
|
|
||||||
|
LL | type Captured<'a> = dyn for<'b> Iterator<Item = impl Sized + Captures<'a>>;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^ `impl Trait` implicitly captures all lifetimes in scope
|
||||||
|
|
|
||||||
|
note: lifetime declared here
|
||||||
--> $DIR/variance.rs:18:29
|
--> $DIR/variance.rs:18:29
|
||||||
|
|
|
|
||||||
LL | type Captured<'a> = dyn for<'b> Iterator<Item = impl Sized + Captures<'a>>;
|
LL | type Captured<'a> = dyn for<'b> Iterator<Item = impl Sized + Captures<'a>>;
|
||||||
|
|
Loading…
Reference in New Issue