1
Fork 0

Split note, fix const/static impl trait error

This commit is contained in:
Michael Goulet 2024-01-07 17:11:48 +00:00
parent 0f3957487b
commit 7e38b70cc0
39 changed files with 257 additions and 129 deletions

View file

@ -106,7 +106,8 @@ ast_lowering_misplaced_double_dot =
.note = only allowed in tuple, tuple struct, and slice patterns .note = only allowed in tuple, tuple struct, and slice patterns
ast_lowering_misplaced_impl_trait = ast_lowering_misplaced_impl_trait =
`impl Trait` only allowed in function and inherent method argument and return types, not in {$position} `impl Trait` is not allowed in {$position}
.note = `impl Trait` is only allowed in arguments and return types of functions and methods
ast_lowering_misplaced_relax_trait_bound = ast_lowering_misplaced_relax_trait_bound =
`?Trait` bounds are only permitted at the point where a type parameter is declared `?Trait` bounds are only permitted at the point where a type parameter is declared

View file

@ -90,6 +90,7 @@ pub enum AssocTyParenthesesSub {
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(ast_lowering_misplaced_impl_trait, code = "E0562")] #[diag(ast_lowering_misplaced_impl_trait, code = "E0562")]
#[note]
pub struct MisplacedImplTrait<'a> { pub struct MisplacedImplTrait<'a> {
#[primary_span] #[primary_span]
pub span: Span, pub span: Span,

View file

@ -182,7 +182,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
self.lower_use_tree(use_tree, &prefix, id, vis_span, ident, attrs) self.lower_use_tree(use_tree, &prefix, id, vis_span, ident, attrs)
} }
ItemKind::Static(box ast::StaticItem { ty: t, mutability: m, expr: e }) => { ItemKind::Static(box ast::StaticItem { ty: t, mutability: m, expr: e }) => {
let (ty, body_id) = self.lower_const_item(t, span, e.as_deref()); let (ty, body_id) =
self.lower_const_item(t, span, e.as_deref(), ImplTraitPosition::StaticTy);
hir::ItemKind::Static(ty, *m, body_id) hir::ItemKind::Static(ty, *m, body_id)
} }
ItemKind::Const(box ast::ConstItem { generics, ty, expr, .. }) => { ItemKind::Const(box ast::ConstItem { generics, ty, expr, .. }) => {
@ -191,7 +192,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
Const::No, Const::No,
id, id,
&ImplTraitContext::Disallowed(ImplTraitPosition::Generic), &ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|this| this.lower_const_item(ty, span, expr.as_deref()), |this| {
this.lower_const_item(ty, span, expr.as_deref(), ImplTraitPosition::ConstTy)
},
); );
hir::ItemKind::Const(ty, generics, body_id) hir::ItemKind::Const(ty, generics, body_id)
} }
@ -448,8 +451,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
ty: &Ty, ty: &Ty,
span: Span, span: Span,
body: Option<&Expr>, body: Option<&Expr>,
impl_trait_position: ImplTraitPosition,
) -> (&'hir hir::Ty<'hir>, hir::BodyId) { ) -> (&'hir hir::Ty<'hir>, hir::BodyId) {
let ty = self.lower_ty(ty, &ImplTraitContext::Disallowed(ImplTraitPosition::ConstTy)); let ty = self.lower_ty(ty, &ImplTraitContext::Disallowed(impl_trait_position));
(ty, self.lower_const_body(span, body)) (ty, self.lower_const_body(span, body))
} }

View file

@ -322,7 +322,7 @@ impl std::fmt::Display for ImplTraitPosition {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let name = match self { let name = match self {
ImplTraitPosition::Path => "paths", ImplTraitPosition::Path => "paths",
ImplTraitPosition::Variable => "variable bindings", ImplTraitPosition::Variable => "the type of variable bindings",
ImplTraitPosition::Trait => "traits", ImplTraitPosition::Trait => "traits",
ImplTraitPosition::AsyncBlock => "async blocks", ImplTraitPosition::AsyncBlock => "async blocks",
ImplTraitPosition::Bound => "bounds", ImplTraitPosition::Bound => "bounds",
@ -334,7 +334,7 @@ impl std::fmt::Display for ImplTraitPosition {
ImplTraitPosition::ExternFnReturn => "`extern fn` return types", ImplTraitPosition::ExternFnReturn => "`extern fn` return types",
ImplTraitPosition::ClosureReturn => "closure return types", ImplTraitPosition::ClosureReturn => "closure return types",
ImplTraitPosition::PointerReturn => "`fn` pointer return types", ImplTraitPosition::PointerReturn => "`fn` pointer return types",
ImplTraitPosition::FnTraitReturn => "the return types of `Fn` trait bounds", ImplTraitPosition::FnTraitReturn => "the return type of `Fn` trait bounds",
ImplTraitPosition::GenericDefault => "generic parameter defaults", ImplTraitPosition::GenericDefault => "generic parameter defaults",
ImplTraitPosition::ConstTy => "const types", ImplTraitPosition::ConstTy => "const types",
ImplTraitPosition::StaticTy => "static types", ImplTraitPosition::StaticTy => "static types",

View file

@ -33,11 +33,13 @@ LL | fn main<A: TraitWAssocConst<A=32>>() {
= note: see issue #92827 <https://github.com/rust-lang/rust/issues/92827> for more information = note: see issue #92827 <https://github.com/rust-lang/rust/issues/92827> for more information
= help: add `#![feature(associated_const_equality)]` to the crate attributes to enable = help: add `#![feature(associated_const_equality)]` to the crate attributes to enable
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in impl headers error[E0562]: `impl Trait` is not allowed in impl headers
--> $DIR/issue-105330.rs:6:27 --> $DIR/issue-105330.rs:6:27
| |
LL | impl TraitWAssocConst for impl Demo { LL | impl TraitWAssocConst for impl Demo {
| ^^^^^^^^^ | ^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0131]: `main` function is not allowed to have generic parameters error[E0131]: `main` function is not allowed to have generic parameters
--> $DIR/issue-105330.rs:15:8 --> $DIR/issue-105330.rs:15:8

View file

@ -54,20 +54,20 @@ fn _rpit_dyn() -> Box<dyn Tr1<As1: Copy>> { Box::new(S1) }
const _cdef: impl Tr1<As1: Copy> = S1; const _cdef: impl Tr1<As1: Copy> = S1;
//~^ ERROR associated type bounds are unstable //~^ ERROR associated type bounds are unstable
//~| ERROR `impl Trait` only allowed in function and inherent method argument and return types //~| ERROR `impl Trait` is not allowed in const types
// FIXME: uncomment when `impl_trait_in_bindings` feature is fixed. // FIXME: uncomment when `impl_trait_in_bindings` feature is fixed.
// const _cdef_dyn: &dyn Tr1<As1: Copy> = &S1; // const _cdef_dyn: &dyn Tr1<As1: Copy> = &S1;
static _sdef: impl Tr1<As1: Copy> = S1; static _sdef: impl Tr1<As1: Copy> = S1;
//~^ ERROR associated type bounds are unstable //~^ ERROR associated type bounds are unstable
//~| ERROR `impl Trait` only allowed in function and inherent method argument and return types //~| ERROR `impl Trait` is not allowed in static types
// FIXME: uncomment when `impl_trait_in_bindings` feature is fixed. // FIXME: uncomment when `impl_trait_in_bindings` feature is fixed.
// static _sdef_dyn: &dyn Tr1<As1: Copy> = &S1; // static _sdef_dyn: &dyn Tr1<As1: Copy> = &S1;
fn main() { fn main() {
let _: impl Tr1<As1: Copy> = S1; let _: impl Tr1<As1: Copy> = S1;
//~^ ERROR associated type bounds are unstable //~^ ERROR associated type bounds are unstable
//~| ERROR `impl Trait` only allowed in function and inherent method argument and return types //~| ERROR `impl Trait` is not allowed in the type of variable bindings
// FIXME: uncomment when `impl_trait_in_bindings` feature is fixed. // FIXME: uncomment when `impl_trait_in_bindings` feature is fixed.
// let _: &dyn Tr1<As1: Copy> = &S1; // let _: &dyn Tr1<As1: Copy> = &S1;
} }

View file

@ -115,23 +115,29 @@ LL | let _: impl Tr1<As1: Copy> = S1;
= note: see issue #52662 <https://github.com/rust-lang/rust/issues/52662> for more information = note: see issue #52662 <https://github.com/rust-lang/rust/issues/52662> for more information
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable = help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in const types error[E0562]: `impl Trait` is not allowed in const types
--> $DIR/feature-gate-associated_type_bounds.rs:55:14 --> $DIR/feature-gate-associated_type_bounds.rs:55:14
| |
LL | const _cdef: impl Tr1<As1: Copy> = S1; LL | const _cdef: impl Tr1<As1: Copy> = S1;
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in const types error[E0562]: `impl Trait` is not allowed in static types
--> $DIR/feature-gate-associated_type_bounds.rs:61:15 --> $DIR/feature-gate-associated_type_bounds.rs:61:15
| |
LL | static _sdef: impl Tr1<As1: Copy> = S1; LL | static _sdef: impl Tr1<As1: Copy> = S1;
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in variable bindings error[E0562]: `impl Trait` is not allowed in the type of variable bindings
--> $DIR/feature-gate-associated_type_bounds.rs:68:12 --> $DIR/feature-gate-associated_type_bounds.rs:68:12
| |
LL | let _: impl Tr1<As1: Copy> = S1; LL | let _: impl Tr1<As1: Copy> = S1;
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0277]: the trait bound `<<Self as _Tr3>::A as Iterator>::Item: Copy` is not satisfied error[E0277]: the trait bound `<<Self as _Tr3>::A as Iterator>::Item: Copy` is not satisfied
--> $DIR/feature-gate-associated_type_bounds.rs:12:28 --> $DIR/feature-gate-associated_type_bounds.rs:12:28

View file

@ -1,6 +1,6 @@
fn f() -> impl Fn() -> impl Sized { || () } fn f() -> impl Fn() -> impl Sized { || () }
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types, not in the return types of `Fn` trait bounds //~^ ERROR `impl Trait` is not allowed in the return type of `Fn` trait bounds
fn g() -> &'static dyn Fn() -> impl Sized { &|| () } fn g() -> &'static dyn Fn() -> impl Sized { &|| () }
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types, not in the return types of `Fn` trait bounds //~^ ERROR `impl Trait` is not allowed in the return type of `Fn` trait bounds
fn main() {} fn main() {}

View file

@ -1,18 +1,20 @@
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in the return types of `Fn` trait bounds error[E0562]: `impl Trait` is not allowed in the return type of `Fn` trait bounds
--> $DIR/feature-gate-impl_trait_in_fn_trait_return.rs:1:24 --> $DIR/feature-gate-impl_trait_in_fn_trait_return.rs:1:24
| |
LL | fn f() -> impl Fn() -> impl Sized { || () } LL | fn f() -> impl Fn() -> impl Sized { || () }
| ^^^^^^^^^^ | ^^^^^^^^^^
| |
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
= note: see issue #99697 <https://github.com/rust-lang/rust/issues/99697> for more information = note: see issue #99697 <https://github.com/rust-lang/rust/issues/99697> for more information
= help: add `#![feature(impl_trait_in_fn_trait_return)]` to the crate attributes to enable = help: add `#![feature(impl_trait_in_fn_trait_return)]` to the crate attributes to enable
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in the return types of `Fn` trait bounds error[E0562]: `impl Trait` is not allowed in the return type of `Fn` trait bounds
--> $DIR/feature-gate-impl_trait_in_fn_trait_return.rs:3:32 --> $DIR/feature-gate-impl_trait_in_fn_trait_return.rs:3:32
| |
LL | fn g() -> &'static dyn Fn() -> impl Sized { &|| () } LL | fn g() -> &'static dyn Fn() -> impl Sized { &|| () }
| ^^^^^^^^^^ | ^^^^^^^^^^
| |
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
= note: see issue #99697 <https://github.com/rust-lang/rust/issues/99697> for more information = note: see issue #99697 <https://github.com/rust-lang/rust/issues/99697> for more information
= help: add `#![feature(impl_trait_in_fn_trait_return)]` to the crate attributes to enable = help: add `#![feature(impl_trait_in_fn_trait_return)]` to the crate attributes to enable

View file

@ -2,6 +2,6 @@ use std::fmt::Debug;
fn main() { fn main() {
let x: Option<impl Debug> = Some(44_u32); let x: Option<impl Debug> = Some(44_u32);
//~^ `impl Trait` only allowed in function and inherent method argument and return types //~^ `impl Trait` is not allowed in the type of variable bindings
println!("{:?}", x); println!("{:?}", x);
} }

View file

@ -1,8 +1,10 @@
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in variable bindings error[E0562]: `impl Trait` is not allowed in the type of variable bindings
--> $DIR/issue-54600.rs:4:19 --> $DIR/issue-54600.rs:4:19
| |
LL | let x: Option<impl Debug> = Some(44_u32); LL | let x: Option<impl Debug> = Some(44_u32);
| ^^^^^^^^^^ | ^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error: aborting due to 1 previous error error: aborting due to 1 previous error

View file

@ -3,5 +3,5 @@ use std::ops::Add;
fn main() { fn main() {
let i: i32 = 0; let i: i32 = 0;
let j: &impl Add = &i; let j: &impl Add = &i;
//~^ `impl Trait` only allowed in function and inherent method argument and return types //~^ `impl Trait` is not allowed in the type of variable bindings
} }

View file

@ -1,8 +1,10 @@
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in variable bindings error[E0562]: `impl Trait` is not allowed in the type of variable bindings
--> $DIR/issue-54840.rs:5:13 --> $DIR/issue-54840.rs:5:13
| |
LL | let j: &impl Add = &i; LL | let j: &impl Add = &i;
| ^^^^^^^^ | ^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error: aborting due to 1 previous error error: aborting due to 1 previous error

View file

@ -8,5 +8,5 @@ fn mk_gen() -> impl Coroutine<Return=!, Yield=()> {
fn main() { fn main() {
let gens: [impl Coroutine<Return=!, Yield=()>;2] = [ mk_gen(), mk_gen() ]; let gens: [impl Coroutine<Return=!, Yield=()>;2] = [ mk_gen(), mk_gen() ];
//~^ `impl Trait` only allowed in function and inherent method argument and return types //~^ `impl Trait` is not allowed in the type of variable bindings
} }

View file

@ -1,8 +1,10 @@
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in variable bindings error[E0562]: `impl Trait` is not allowed in the type of variable bindings
--> $DIR/issue-58504.rs:10:16 --> $DIR/issue-58504.rs:10:16
| |
LL | let gens: [impl Coroutine<Return=!, Yield=()>;2] = [ mk_gen(), mk_gen() ]; LL | let gens: [impl Coroutine<Return=!, Yield=()>;2] = [ mk_gen(), mk_gen() ];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error: aborting due to 1 previous error error: aborting due to 1 previous error

View file

@ -5,9 +5,9 @@ impl Lam for B {}
pub struct Wrap<T>(T); pub struct Wrap<T>(T);
const _A: impl Lam = { const _A: impl Lam = {
//~^ `impl Trait` only allowed in function and inherent method argument and return types //~^ `impl Trait` is not allowed in const types
let x: Wrap<impl Lam> = Wrap(B); let x: Wrap<impl Lam> = Wrap(B);
//~^ `impl Trait` only allowed in function and inherent method argument and return types //~^ `impl Trait` is not allowed in the type of variable bindings
x.0 x.0
}; };

View file

@ -1,14 +1,18 @@
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in const types error[E0562]: `impl Trait` is not allowed in const types
--> $DIR/issue-58956.rs:7:11 --> $DIR/issue-58956.rs:7:11
| |
LL | const _A: impl Lam = { LL | const _A: impl Lam = {
| ^^^^^^^^ | ^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in variable bindings error[E0562]: `impl Trait` is not allowed in the type of variable bindings
--> $DIR/issue-58956.rs:9:17 --> $DIR/issue-58956.rs:9:17
| |
LL | let x: Wrap<impl Lam> = Wrap(B); LL | let x: Wrap<impl Lam> = Wrap(B);
| ^^^^^^^^ | ^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error: aborting due to 2 previous errors error: aborting due to 2 previous errors

View file

@ -1,4 +1,4 @@
fn main() { fn main() {
let x : (impl Copy,) = (true,); let x : (impl Copy,) = (true,);
//~^ `impl Trait` only allowed in function and inherent method argument and return types //~^ `impl Trait` is not allowed in the type of variable bindings
} }

View file

@ -1,8 +1,10 @@
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in variable bindings error[E0562]: `impl Trait` is not allowed in the type of variable bindings
--> $DIR/issue-70971.rs:2:14 --> $DIR/issue-70971.rs:2:14
| |
LL | let x : (impl Copy,) = (true,); LL | let x : (impl Copy,) = (true,);
| ^^^^^^^^^ | ^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error: aborting due to 1 previous error error: aborting due to 1 previous error

View file

@ -1,7 +1,7 @@
struct Bug { struct Bug {
V1: [(); { V1: [(); {
let f: impl core::future::Future<Output = u8> = async { 1 }; let f: impl core::future::Future<Output = u8> = async { 1 };
//~^ `impl Trait` only allowed in function and inherent method argument and return types //~^ `impl Trait` is not allowed in the type of variable bindings
//~| expected identifier //~| expected identifier
1 1
}], }],

View file

@ -9,11 +9,13 @@ LL | let f: impl core::future::Future<Output = u8> = async { 1 };
= help: pass `--edition 2021` to `rustc` = help: pass `--edition 2021` to `rustc`
= note: for more on editions, read https://doc.rust-lang.org/edition-guide = note: for more on editions, read https://doc.rust-lang.org/edition-guide
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in variable bindings error[E0562]: `impl Trait` is not allowed in the type of variable bindings
--> $DIR/issue-79099.rs:3:16 --> $DIR/issue-79099.rs:3:16
| |
LL | let f: impl core::future::Future<Output = u8> = async { 1 }; LL | let f: impl core::future::Future<Output = u8> = async { 1 };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error: aborting due to 2 previous errors error: aborting due to 2 previous errors

View file

@ -1,8 +1,8 @@
struct Foo<T = impl Copy>(T); struct Foo<T = impl Copy>(T);
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in generic parameter defaults
type Result<T, E = impl std::error::Error> = std::result::Result<T, E>; type Result<T, E = impl std::error::Error> = std::result::Result<T, E>;
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in generic parameter defaults
// should not cause ICE // should not cause ICE
fn x() -> Foo { fn x() -> Foo {

View file

@ -1,14 +1,18 @@
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in generic parameter defaults error[E0562]: `impl Trait` is not allowed in generic parameter defaults
--> $DIR/issue-83929-impl-trait-in-generic-default.rs:1:16 --> $DIR/issue-83929-impl-trait-in-generic-default.rs:1:16
| |
LL | struct Foo<T = impl Copy>(T); LL | struct Foo<T = impl Copy>(T);
| ^^^^^^^^^ | ^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in generic parameter defaults error[E0562]: `impl Trait` is not allowed in generic parameter defaults
--> $DIR/issue-83929-impl-trait-in-generic-default.rs:4:20 --> $DIR/issue-83929-impl-trait-in-generic-default.rs:4:20
| |
LL | type Result<T, E = impl std::error::Error> = std::result::Result<T, E>; LL | type Result<T, E = impl std::error::Error> = std::result::Result<T, E>;
| ^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error: aborting due to 2 previous errors error: aborting due to 2 previous errors

View file

@ -3,7 +3,7 @@ impl Trait for () {}
fn foo<'a: 'a>() { fn foo<'a: 'a>() {
let _x: impl Trait = (); let _x: impl Trait = ();
//~^ `impl Trait` only allowed in function and inherent method argument and return types //~^ `impl Trait` is not allowed in the type of variable bindings
} }
fn main() {} fn main() {}

View file

@ -1,8 +1,10 @@
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in variable bindings error[E0562]: `impl Trait` is not allowed in the type of variable bindings
--> $DIR/issue-84919.rs:5:13 --> $DIR/issue-84919.rs:5:13
| |
LL | let _x: impl Trait = (); LL | let _x: impl Trait = ();
| ^^^^^^^^^^ | ^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error: aborting due to 1 previous error error: aborting due to 1 previous error

View file

@ -1,5 +1,5 @@
static x: impl Fn(&str) -> Result<&str, ()> = move |source| { static x: impl Fn(&str) -> Result<&str, ()> = move |source| {
//~^ `impl Trait` only allowed in function and inherent method argument and return types //~^ `impl Trait` is not allowed in static types
let res = (move |source| Ok(source))(source); let res = (move |source| Ok(source))(source);
let res = res.or((move |source| Ok(source))(source)); let res = res.or((move |source| Ok(source))(source));
res res

View file

@ -1,8 +1,10 @@
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in const types error[E0562]: `impl Trait` is not allowed in static types
--> $DIR/issue-86642.rs:1:11 --> $DIR/issue-86642.rs:1:11
| |
LL | static x: impl Fn(&str) -> Result<&str, ()> = move |source| { LL | static x: impl Fn(&str) -> Result<&str, ()> = move |source| {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error: aborting due to 1 previous error error: aborting due to 1 previous error

View file

@ -14,5 +14,5 @@ impl<F> Struct<F> {
fn main() { fn main() {
let _do_not_waste: Struct<impl Trait<Output = i32>> = Struct::new(()); let _do_not_waste: Struct<impl Trait<Output = i32>> = Struct::new(());
//~^ `impl Trait` only allowed in function and inherent method argument and return types //~^ `impl Trait` is not allowed in the type of variable bindings
} }

View file

@ -1,8 +1,10 @@
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in variable bindings error[E0562]: `impl Trait` is not allowed in the type of variable bindings
--> $DIR/issue-87295.rs:16:31 --> $DIR/issue-87295.rs:16:31
| |
LL | let _do_not_waste: Struct<impl Trait<Output = i32>> = Struct::new(()); LL | let _do_not_waste: Struct<impl Trait<Output = i32>> = Struct::new(());
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error: aborting due to 1 previous error error: aborting due to 1 previous error

View file

@ -9,7 +9,7 @@ fn bad_in_ret_position(x: impl Into<u32>) -> impl Into<impl Debug> { x }
fn bad_in_fn_syntax(x: fn() -> impl Into<impl Debug>) {} fn bad_in_fn_syntax(x: fn() -> impl Into<impl Debug>) {}
//~^ ERROR nested `impl Trait` is not allowed //~^ ERROR nested `impl Trait` is not allowed
//~| `impl Trait` only allowed in function and inherent method argument and return types //~| `impl Trait` is not allowed in `fn` pointer
fn bad_in_arg_position(_: impl Into<impl Debug>) { } fn bad_in_arg_position(_: impl Into<impl Debug>) { }
//~^ ERROR nested `impl Trait` is not allowed //~^ ERROR nested `impl Trait` is not allowed

View file

@ -34,11 +34,13 @@ LL | fn bad(x: impl Into<u32>) -> impl Into<impl Debug> { x }
| | nested `impl Trait` here | | nested `impl Trait` here
| outer `impl Trait` | outer `impl Trait`
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `fn` pointer return types error[E0562]: `impl Trait` is not allowed in `fn` pointer return types
--> $DIR/nested_impl_trait.rs:10:32 --> $DIR/nested_impl_trait.rs:10:32
| |
LL | fn bad_in_fn_syntax(x: fn() -> impl Into<impl Debug>) {} LL | fn bad_in_fn_syntax(x: fn() -> impl Into<impl Debug>) {}
| ^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0277]: the trait bound `impl Debug: From<impl Into<u32>>` is not satisfied error[E0277]: the trait bound `impl Debug: From<impl Into<u32>>` is not satisfied
--> $DIR/nested_impl_trait.rs:6:46 --> $DIR/nested_impl_trait.rs:6:46

View file

@ -16,47 +16,47 @@ fn in_adt_in_parameters(_: Vec<impl Debug>) { panic!() }
// Disallowed // Disallowed
fn in_fn_parameter_in_parameters(_: fn(impl Debug)) { panic!() } fn in_fn_parameter_in_parameters(_: fn(impl Debug)) { panic!() }
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in `fn` pointer
// Disallowed // Disallowed
fn in_fn_return_in_parameters(_: fn() -> impl Debug) { panic!() } fn in_fn_return_in_parameters(_: fn() -> impl Debug) { panic!() }
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in `fn` pointer
// Disallowed // Disallowed
fn in_fn_parameter_in_return() -> fn(impl Debug) { panic!() } fn in_fn_parameter_in_return() -> fn(impl Debug) { panic!() }
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in `fn` pointer
// Disallowed // Disallowed
fn in_fn_return_in_return() -> fn() -> impl Debug { panic!() } fn in_fn_return_in_return() -> fn() -> impl Debug { panic!() }
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in `fn` pointer
// Disallowed // Disallowed
fn in_dyn_Fn_parameter_in_parameters(_: &dyn Fn(impl Debug)) { panic!() } fn in_dyn_Fn_parameter_in_parameters(_: &dyn Fn(impl Debug)) { panic!() }
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in the parameters of `Fn` trait bounds
// Disallowed // Disallowed
fn in_dyn_Fn_return_in_parameters(_: &dyn Fn() -> impl Debug) { panic!() } fn in_dyn_Fn_return_in_parameters(_: &dyn Fn() -> impl Debug) { panic!() }
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in the return type of `Fn` trait bounds
// Disallowed // Disallowed
fn in_dyn_Fn_parameter_in_return() -> &'static dyn Fn(impl Debug) { panic!() } fn in_dyn_Fn_parameter_in_return() -> &'static dyn Fn(impl Debug) { panic!() }
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in the parameters of `Fn` trait bounds
// Allowed // Allowed
fn in_dyn_Fn_return_in_return() -> &'static dyn Fn() -> impl Debug { panic!() } fn in_dyn_Fn_return_in_return() -> &'static dyn Fn() -> impl Debug { panic!() }
// Disallowed // Disallowed
fn in_impl_Fn_parameter_in_parameters(_: &impl Fn(impl Debug)) { panic!() } fn in_impl_Fn_parameter_in_parameters(_: &impl Fn(impl Debug)) { panic!() }
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in the parameters of `Fn` trait bounds
//~^^ ERROR nested `impl Trait` is not allowed //~^^ ERROR nested `impl Trait` is not allowed
// Disallowed // Disallowed
fn in_impl_Fn_return_in_parameters(_: &impl Fn() -> impl Debug) { panic!() } fn in_impl_Fn_return_in_parameters(_: &impl Fn() -> impl Debug) { panic!() }
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in the return type of `Fn` trait bounds
// Disallowed // Disallowed
fn in_impl_Fn_parameter_in_return() -> &'static impl Fn(impl Debug) { panic!() } fn in_impl_Fn_parameter_in_return() -> &'static impl Fn(impl Debug) { panic!() }
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in the parameters of `Fn` trait bounds
//~| ERROR nested `impl Trait` is not allowed //~| ERROR nested `impl Trait` is not allowed
// Allowed // Allowed
@ -64,11 +64,11 @@ fn in_impl_Fn_return_in_return() -> &'static impl Fn() -> impl Debug { panic!()
// Disallowed // Disallowed
fn in_Fn_parameter_in_generics<F: Fn(impl Debug)> (_: F) { panic!() } fn in_Fn_parameter_in_generics<F: Fn(impl Debug)> (_: F) { panic!() }
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in the parameters of `Fn` trait bounds
// Disallowed // Disallowed
fn in_Fn_return_in_generics<F: Fn() -> impl Debug> (_: F) { panic!() } fn in_Fn_return_in_generics<F: Fn() -> impl Debug> (_: F) { panic!() }
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in the return type of `Fn` trait bounds
// Allowed // Allowed
@ -81,22 +81,22 @@ fn in_impl_Trait_in_return() -> impl IntoIterator<Item = impl IntoIterator> {
// Disallowed // Disallowed
struct InBraceStructField { x: impl Debug } struct InBraceStructField { x: impl Debug }
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in field types
// Disallowed // Disallowed
struct InAdtInBraceStructField { x: Vec<impl Debug> } struct InAdtInBraceStructField { x: Vec<impl Debug> }
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in field types
// Disallowed // Disallowed
struct InTupleStructField(impl Debug); struct InTupleStructField(impl Debug);
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in field types
// Disallowed // Disallowed
enum InEnum { enum InEnum {
InBraceVariant { x: impl Debug }, InBraceVariant { x: impl Debug },
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in field types
InTupleVariant(impl Debug), InTupleVariant(impl Debug),
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in field types
} }
// Allowed // Allowed
@ -136,10 +136,10 @@ impl DummyType {
// Disallowed // Disallowed
extern "C" { extern "C" {
fn in_foreign_parameters(_: impl Debug); fn in_foreign_parameters(_: impl Debug);
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in `extern fn`
fn in_foreign_return() -> impl Debug; fn in_foreign_return() -> impl Debug;
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in `extern fn`
} }
// Allowed // Allowed
@ -155,97 +155,97 @@ type InTypeAlias<R> = impl Debug;
//~^ ERROR `impl Trait` in type aliases is unstable //~^ ERROR `impl Trait` in type aliases is unstable
type InReturnInTypeAlias<R> = fn() -> impl Debug; type InReturnInTypeAlias<R> = fn() -> impl Debug;
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in `fn` pointer
//~| ERROR `impl Trait` in type aliases is unstable //~| ERROR `impl Trait` in type aliases is unstable
// Disallowed in impl headers // Disallowed in impl headers
impl PartialEq<impl Debug> for () { impl PartialEq<impl Debug> for () {
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in traits
} }
// Disallowed in impl headers // Disallowed in impl headers
impl PartialEq<()> for impl Debug { impl PartialEq<()> for impl Debug {
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in impl headers
} }
// Disallowed in inherent impls // Disallowed in inherent impls
impl impl Debug { impl impl Debug {
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in impl headers
} }
// Disallowed in inherent impls // Disallowed in inherent impls
struct InInherentImplAdt<T> { t: T } struct InInherentImplAdt<T> { t: T }
impl InInherentImplAdt<impl Debug> { impl InInherentImplAdt<impl Debug> {
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in impl headers
} }
// Disallowed in where clauses // Disallowed in where clauses
fn in_fn_where_clause() fn in_fn_where_clause()
where impl Debug: Debug where impl Debug: Debug
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in bounds
{ {
} }
// Disallowed in where clauses // Disallowed in where clauses
fn in_adt_in_fn_where_clause() fn in_adt_in_fn_where_clause()
where Vec<impl Debug>: Debug where Vec<impl Debug>: Debug
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in bounds
{ {
} }
// Disallowed // Disallowed
fn in_trait_parameter_in_fn_where_clause<T>() fn in_trait_parameter_in_fn_where_clause<T>()
where T: PartialEq<impl Debug> where T: PartialEq<impl Debug>
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in bounds
{ {
} }
// Disallowed // Disallowed
fn in_Fn_parameter_in_fn_where_clause<T>() fn in_Fn_parameter_in_fn_where_clause<T>()
where T: Fn(impl Debug) where T: Fn(impl Debug)
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in the parameters of `Fn` trait bounds
{ {
} }
// Disallowed // Disallowed
fn in_Fn_return_in_fn_where_clause<T>() fn in_Fn_return_in_fn_where_clause<T>()
where T: Fn() -> impl Debug where T: Fn() -> impl Debug
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in the return type of `Fn` trait bounds
{ {
} }
// Disallowed // Disallowed
struct InStructGenericParamDefault<T = impl Debug>(T); struct InStructGenericParamDefault<T = impl Debug>(T);
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in generic parameter defaults
// Disallowed // Disallowed
enum InEnumGenericParamDefault<T = impl Debug> { Variant(T) } enum InEnumGenericParamDefault<T = impl Debug> { Variant(T) }
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in generic parameter defaults
// Disallowed // Disallowed
trait InTraitGenericParamDefault<T = impl Debug> {} trait InTraitGenericParamDefault<T = impl Debug> {}
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in generic parameter defaults
// Disallowed // Disallowed
type InTypeAliasGenericParamDefault<T = impl Debug> = T; type InTypeAliasGenericParamDefault<T = impl Debug> = T;
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in generic parameter defaults
// Disallowed // Disallowed
impl <T = impl Debug> T {} impl <T = impl Debug> T {}
//~^ ERROR defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions //~^ ERROR defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
//~| WARNING this was previously accepted by the compiler but is being phased out //~| WARNING this was previously accepted by the compiler but is being phased out
//~| ERROR `impl Trait` only allowed in function and inherent method argument and return types //~| ERROR `impl Trait` is not allowed in generic parameter defaults
//~| ERROR no nominal type found //~| ERROR no nominal type found
// Disallowed // Disallowed
fn in_method_generic_param_default<T = impl Debug>(_: T) {} fn in_method_generic_param_default<T = impl Debug>(_: T) {}
//~^ ERROR defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions //~^ ERROR defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
//~| WARNING this was previously accepted by the compiler but is being phased out //~| WARNING this was previously accepted by the compiler but is being phased out
//~| ERROR `impl Trait` only allowed in function and inherent method argument and return types //~| ERROR `impl Trait` is not allowed in generic parameter defaults
fn main() { fn main() {
let _in_local_variable: impl Fn() = || {}; let _in_local_variable: impl Fn() = || {};
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in the type of variable bindings
let _in_return_in_local_variable = || -> impl Fn() { || {} }; let _in_return_in_local_variable = || -> impl Fn() { || {} };
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in closure return types
} }

View file

@ -43,227 +43,301 @@ LL | type InReturnInTypeAlias<R> = fn() -> impl Debug;
= note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information = note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
= help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `fn` pointer parameters error[E0562]: `impl Trait` is not allowed in `fn` pointer parameters
--> $DIR/where-allowed.rs:18:40 --> $DIR/where-allowed.rs:18:40
| |
LL | fn in_fn_parameter_in_parameters(_: fn(impl Debug)) { panic!() } LL | fn in_fn_parameter_in_parameters(_: fn(impl Debug)) { panic!() }
| ^^^^^^^^^^ | ^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `fn` pointer return types error[E0562]: `impl Trait` is not allowed in `fn` pointer return types
--> $DIR/where-allowed.rs:22:42 --> $DIR/where-allowed.rs:22:42
| |
LL | fn in_fn_return_in_parameters(_: fn() -> impl Debug) { panic!() } LL | fn in_fn_return_in_parameters(_: fn() -> impl Debug) { panic!() }
| ^^^^^^^^^^ | ^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `fn` pointer parameters error[E0562]: `impl Trait` is not allowed in `fn` pointer parameters
--> $DIR/where-allowed.rs:26:38 --> $DIR/where-allowed.rs:26:38
| |
LL | fn in_fn_parameter_in_return() -> fn(impl Debug) { panic!() } LL | fn in_fn_parameter_in_return() -> fn(impl Debug) { panic!() }
| ^^^^^^^^^^ | ^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `fn` pointer return types error[E0562]: `impl Trait` is not allowed in `fn` pointer return types
--> $DIR/where-allowed.rs:30:40 --> $DIR/where-allowed.rs:30:40
| |
LL | fn in_fn_return_in_return() -> fn() -> impl Debug { panic!() } LL | fn in_fn_return_in_return() -> fn() -> impl Debug { panic!() }
| ^^^^^^^^^^ | ^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in the parameters of `Fn` trait bounds error[E0562]: `impl Trait` is not allowed in the parameters of `Fn` trait bounds
--> $DIR/where-allowed.rs:34:49 --> $DIR/where-allowed.rs:34:49
| |
LL | fn in_dyn_Fn_parameter_in_parameters(_: &dyn Fn(impl Debug)) { panic!() } LL | fn in_dyn_Fn_parameter_in_parameters(_: &dyn Fn(impl Debug)) { panic!() }
| ^^^^^^^^^^ | ^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in the return types of `Fn` trait bounds error[E0562]: `impl Trait` is not allowed in the return type of `Fn` trait bounds
--> $DIR/where-allowed.rs:38:51 --> $DIR/where-allowed.rs:38:51
| |
LL | fn in_dyn_Fn_return_in_parameters(_: &dyn Fn() -> impl Debug) { panic!() } LL | fn in_dyn_Fn_return_in_parameters(_: &dyn Fn() -> impl Debug) { panic!() }
| ^^^^^^^^^^ | ^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in the parameters of `Fn` trait bounds error[E0562]: `impl Trait` is not allowed in the parameters of `Fn` trait bounds
--> $DIR/where-allowed.rs:42:55 --> $DIR/where-allowed.rs:42:55
| |
LL | fn in_dyn_Fn_parameter_in_return() -> &'static dyn Fn(impl Debug) { panic!() } LL | fn in_dyn_Fn_parameter_in_return() -> &'static dyn Fn(impl Debug) { panic!() }
| ^^^^^^^^^^ | ^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in the parameters of `Fn` trait bounds error[E0562]: `impl Trait` is not allowed in the parameters of `Fn` trait bounds
--> $DIR/where-allowed.rs:49:51 --> $DIR/where-allowed.rs:49:51
| |
LL | fn in_impl_Fn_parameter_in_parameters(_: &impl Fn(impl Debug)) { panic!() } LL | fn in_impl_Fn_parameter_in_parameters(_: &impl Fn(impl Debug)) { panic!() }
| ^^^^^^^^^^ | ^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in the return types of `Fn` trait bounds error[E0562]: `impl Trait` is not allowed in the return type of `Fn` trait bounds
--> $DIR/where-allowed.rs:54:53 --> $DIR/where-allowed.rs:54:53
| |
LL | fn in_impl_Fn_return_in_parameters(_: &impl Fn() -> impl Debug) { panic!() } LL | fn in_impl_Fn_return_in_parameters(_: &impl Fn() -> impl Debug) { panic!() }
| ^^^^^^^^^^ | ^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in the parameters of `Fn` trait bounds error[E0562]: `impl Trait` is not allowed in the parameters of `Fn` trait bounds
--> $DIR/where-allowed.rs:58:57 --> $DIR/where-allowed.rs:58:57
| |
LL | fn in_impl_Fn_parameter_in_return() -> &'static impl Fn(impl Debug) { panic!() } LL | fn in_impl_Fn_parameter_in_return() -> &'static impl Fn(impl Debug) { panic!() }
| ^^^^^^^^^^ | ^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in the parameters of `Fn` trait bounds error[E0562]: `impl Trait` is not allowed in the parameters of `Fn` trait bounds
--> $DIR/where-allowed.rs:66:38 --> $DIR/where-allowed.rs:66:38
| |
LL | fn in_Fn_parameter_in_generics<F: Fn(impl Debug)> (_: F) { panic!() } LL | fn in_Fn_parameter_in_generics<F: Fn(impl Debug)> (_: F) { panic!() }
| ^^^^^^^^^^ | ^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in the return types of `Fn` trait bounds error[E0562]: `impl Trait` is not allowed in the return type of `Fn` trait bounds
--> $DIR/where-allowed.rs:70:40 --> $DIR/where-allowed.rs:70:40
| |
LL | fn in_Fn_return_in_generics<F: Fn() -> impl Debug> (_: F) { panic!() } LL | fn in_Fn_return_in_generics<F: Fn() -> impl Debug> (_: F) { panic!() }
| ^^^^^^^^^^ | ^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in field types error[E0562]: `impl Trait` is not allowed in field types
--> $DIR/where-allowed.rs:83:32 --> $DIR/where-allowed.rs:83:32
| |
LL | struct InBraceStructField { x: impl Debug } LL | struct InBraceStructField { x: impl Debug }
| ^^^^^^^^^^ | ^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in field types error[E0562]: `impl Trait` is not allowed in field types
--> $DIR/where-allowed.rs:87:41 --> $DIR/where-allowed.rs:87:41
| |
LL | struct InAdtInBraceStructField { x: Vec<impl Debug> } LL | struct InAdtInBraceStructField { x: Vec<impl Debug> }
| ^^^^^^^^^^ | ^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in field types error[E0562]: `impl Trait` is not allowed in field types
--> $DIR/where-allowed.rs:91:27 --> $DIR/where-allowed.rs:91:27
| |
LL | struct InTupleStructField(impl Debug); LL | struct InTupleStructField(impl Debug);
| ^^^^^^^^^^ | ^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in field types error[E0562]: `impl Trait` is not allowed in field types
--> $DIR/where-allowed.rs:96:25 --> $DIR/where-allowed.rs:96:25
| |
LL | InBraceVariant { x: impl Debug }, LL | InBraceVariant { x: impl Debug },
| ^^^^^^^^^^ | ^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in field types error[E0562]: `impl Trait` is not allowed in field types
--> $DIR/where-allowed.rs:98:20 --> $DIR/where-allowed.rs:98:20
| |
LL | InTupleVariant(impl Debug), LL | InTupleVariant(impl Debug),
| ^^^^^^^^^^ | ^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `extern fn` parameters error[E0562]: `impl Trait` is not allowed in `extern fn` parameters
--> $DIR/where-allowed.rs:138:33 --> $DIR/where-allowed.rs:138:33
| |
LL | fn in_foreign_parameters(_: impl Debug); LL | fn in_foreign_parameters(_: impl Debug);
| ^^^^^^^^^^ | ^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `extern fn` return types error[E0562]: `impl Trait` is not allowed in `extern fn` return types
--> $DIR/where-allowed.rs:141:31 --> $DIR/where-allowed.rs:141:31
| |
LL | fn in_foreign_return() -> impl Debug; LL | fn in_foreign_return() -> impl Debug;
| ^^^^^^^^^^ | ^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `fn` pointer return types error[E0562]: `impl Trait` is not allowed in `fn` pointer return types
--> $DIR/where-allowed.rs:157:39 --> $DIR/where-allowed.rs:157:39
| |
LL | type InReturnInTypeAlias<R> = fn() -> impl Debug; LL | type InReturnInTypeAlias<R> = fn() -> impl Debug;
| ^^^^^^^^^^ | ^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in traits error[E0562]: `impl Trait` is not allowed in traits
--> $DIR/where-allowed.rs:162:16 --> $DIR/where-allowed.rs:162:16
| |
LL | impl PartialEq<impl Debug> for () { LL | impl PartialEq<impl Debug> for () {
| ^^^^^^^^^^ | ^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in impl headers error[E0562]: `impl Trait` is not allowed in impl headers
--> $DIR/where-allowed.rs:167:24 --> $DIR/where-allowed.rs:167:24
| |
LL | impl PartialEq<()> for impl Debug { LL | impl PartialEq<()> for impl Debug {
| ^^^^^^^^^^ | ^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in impl headers error[E0562]: `impl Trait` is not allowed in impl headers
--> $DIR/where-allowed.rs:172:6 --> $DIR/where-allowed.rs:172:6
| |
LL | impl impl Debug { LL | impl impl Debug {
| ^^^^^^^^^^ | ^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in impl headers error[E0562]: `impl Trait` is not allowed in impl headers
--> $DIR/where-allowed.rs:178:24 --> $DIR/where-allowed.rs:178:24
| |
LL | impl InInherentImplAdt<impl Debug> { LL | impl InInherentImplAdt<impl Debug> {
| ^^^^^^^^^^ | ^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in bounds error[E0562]: `impl Trait` is not allowed in bounds
--> $DIR/where-allowed.rs:184:11 --> $DIR/where-allowed.rs:184:11
| |
LL | where impl Debug: Debug LL | where impl Debug: Debug
| ^^^^^^^^^^ | ^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in bounds error[E0562]: `impl Trait` is not allowed in bounds
--> $DIR/where-allowed.rs:191:15 --> $DIR/where-allowed.rs:191:15
| |
LL | where Vec<impl Debug>: Debug LL | where Vec<impl Debug>: Debug
| ^^^^^^^^^^ | ^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in bounds error[E0562]: `impl Trait` is not allowed in bounds
--> $DIR/where-allowed.rs:198:24 --> $DIR/where-allowed.rs:198:24
| |
LL | where T: PartialEq<impl Debug> LL | where T: PartialEq<impl Debug>
| ^^^^^^^^^^ | ^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in the parameters of `Fn` trait bounds error[E0562]: `impl Trait` is not allowed in the parameters of `Fn` trait bounds
--> $DIR/where-allowed.rs:205:17 --> $DIR/where-allowed.rs:205:17
| |
LL | where T: Fn(impl Debug) LL | where T: Fn(impl Debug)
| ^^^^^^^^^^ | ^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in the return types of `Fn` trait bounds error[E0562]: `impl Trait` is not allowed in the return type of `Fn` trait bounds
--> $DIR/where-allowed.rs:212:22 --> $DIR/where-allowed.rs:212:22
| |
LL | where T: Fn() -> impl Debug LL | where T: Fn() -> impl Debug
| ^^^^^^^^^^ | ^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in generic parameter defaults error[E0562]: `impl Trait` is not allowed in generic parameter defaults
--> $DIR/where-allowed.rs:218:40 --> $DIR/where-allowed.rs:218:40
| |
LL | struct InStructGenericParamDefault<T = impl Debug>(T); LL | struct InStructGenericParamDefault<T = impl Debug>(T);
| ^^^^^^^^^^ | ^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in generic parameter defaults error[E0562]: `impl Trait` is not allowed in generic parameter defaults
--> $DIR/where-allowed.rs:222:36 --> $DIR/where-allowed.rs:222:36
| |
LL | enum InEnumGenericParamDefault<T = impl Debug> { Variant(T) } LL | enum InEnumGenericParamDefault<T = impl Debug> { Variant(T) }
| ^^^^^^^^^^ | ^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in generic parameter defaults error[E0562]: `impl Trait` is not allowed in generic parameter defaults
--> $DIR/where-allowed.rs:226:38 --> $DIR/where-allowed.rs:226:38
| |
LL | trait InTraitGenericParamDefault<T = impl Debug> {} LL | trait InTraitGenericParamDefault<T = impl Debug> {}
| ^^^^^^^^^^ | ^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in generic parameter defaults error[E0562]: `impl Trait` is not allowed in generic parameter defaults
--> $DIR/where-allowed.rs:230:41 --> $DIR/where-allowed.rs:230:41
| |
LL | type InTypeAliasGenericParamDefault<T = impl Debug> = T; LL | type InTypeAliasGenericParamDefault<T = impl Debug> = T;
| ^^^^^^^^^^ | ^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in generic parameter defaults error[E0562]: `impl Trait` is not allowed in generic parameter defaults
--> $DIR/where-allowed.rs:234:11 --> $DIR/where-allowed.rs:234:11
| |
LL | impl <T = impl Debug> T {} LL | impl <T = impl Debug> T {}
| ^^^^^^^^^^ | ^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in generic parameter defaults error[E0562]: `impl Trait` is not allowed in generic parameter defaults
--> $DIR/where-allowed.rs:241:40 --> $DIR/where-allowed.rs:241:40
| |
LL | fn in_method_generic_param_default<T = impl Debug>(_: T) {} LL | fn in_method_generic_param_default<T = impl Debug>(_: T) {}
| ^^^^^^^^^^ | ^^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in variable bindings error[E0562]: `impl Trait` is not allowed in the type of variable bindings
--> $DIR/where-allowed.rs:247:29 --> $DIR/where-allowed.rs:247:29
| |
LL | let _in_local_variable: impl Fn() = || {}; LL | let _in_local_variable: impl Fn() = || {};
| ^^^^^^^^^ | ^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in closure return types error[E0562]: `impl Trait` is not allowed in closure return types
--> $DIR/where-allowed.rs:249:46 --> $DIR/where-allowed.rs:249:46
| |
LL | let _in_return_in_local_variable = || -> impl Fn() { || {} }; LL | let _in_return_in_local_variable = || -> impl Fn() { || {} };
| ^^^^^^^^^ | ^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
--> $DIR/where-allowed.rs:234:7 --> $DIR/where-allowed.rs:234:7

View file

@ -7,22 +7,22 @@ trait Iterable {
} }
struct Container<T: Iterable<Item = impl Foo>> { struct Container<T: Iterable<Item = impl Foo>> {
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in generics
field: T field: T
} }
enum Enum<T: Iterable<Item = impl Foo>> { enum Enum<T: Iterable<Item = impl Foo>> {
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in generics
A(T), A(T),
} }
union Union<T: Iterable<Item = impl Foo> + Copy> { union Union<T: Iterable<Item = impl Foo> + Copy> {
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in generics
x: T, x: T,
} }
type Type<T: Iterable<Item = impl Foo>> = T; type Type<T: Iterable<Item = impl Foo>> = T;
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in generics
fn main() { fn main() {
} }

View file

@ -1,26 +1,34 @@
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in generics error[E0562]: `impl Trait` is not allowed in generics
--> $DIR/issue-47715.rs:9:37 --> $DIR/issue-47715.rs:9:37
| |
LL | struct Container<T: Iterable<Item = impl Foo>> { LL | struct Container<T: Iterable<Item = impl Foo>> {
| ^^^^^^^^ | ^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in generics error[E0562]: `impl Trait` is not allowed in generics
--> $DIR/issue-47715.rs:14:30 --> $DIR/issue-47715.rs:14:30
| |
LL | enum Enum<T: Iterable<Item = impl Foo>> { LL | enum Enum<T: Iterable<Item = impl Foo>> {
| ^^^^^^^^ | ^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in generics error[E0562]: `impl Trait` is not allowed in generics
--> $DIR/issue-47715.rs:19:32 --> $DIR/issue-47715.rs:19:32
| |
LL | union Union<T: Iterable<Item = impl Foo> + Copy> { LL | union Union<T: Iterable<Item = impl Foo> + Copy> {
| ^^^^^^^^ | ^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in generics error[E0562]: `impl Trait` is not allowed in generics
--> $DIR/issue-47715.rs:24:30 --> $DIR/issue-47715.rs:24:30
| |
LL | type Type<T: Iterable<Item = impl Foo>> = T; LL | type Type<T: Iterable<Item = impl Foo>> = T;
| ^^^^^^^^ | ^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error: aborting due to 4 previous errors error: aborting due to 4 previous errors

View file

@ -4,7 +4,7 @@
// FIXME: this is ruled out for now but should work // FIXME: this is ruled out for now but should work
type Foo = fn() -> impl Send; type Foo = fn() -> impl Send;
//~^ ERROR: `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR: `impl Trait` is not allowed in `fn` pointer return types
fn make_foo() -> Foo { fn make_foo() -> Foo {
|| 15 || 15

View file

@ -1,8 +1,10 @@
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in `fn` pointer return types error[E0562]: `impl Trait` is not allowed in `fn` pointer return types
--> $DIR/type-alias-impl-trait-fn-type.rs:6:20 --> $DIR/type-alias-impl-trait-fn-type.rs:6:20
| |
LL | type Foo = fn() -> impl Send; LL | type Foo = fn() -> impl Send;
| ^^^^^^^^^ | ^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error: aborting due to 1 previous error error: aborting due to 1 previous error

View file

@ -1,6 +1,6 @@
struct S; struct S;
fn f() { fn f() {
let _: S<impl Oops> = S; //~ ERROR cannot find trait `Oops` in this scope let _: S<impl Oops> = S; //~ ERROR cannot find trait `Oops` in this scope
//~^ ERROR `impl Trait` only allowed in function and inherent method argument and return types //~^ ERROR `impl Trait` is not allowed in the type of variable bindings
} }
fn main() {} fn main() {}

View file

@ -4,11 +4,13 @@ error[E0405]: cannot find trait `Oops` in this scope
LL | let _: S<impl Oops> = S; LL | let _: S<impl Oops> = S;
| ^^^^ not found in this scope | ^^^^ not found in this scope
error[E0562]: `impl Trait` only allowed in function and inherent method argument and return types, not in variable bindings error[E0562]: `impl Trait` is not allowed in the type of variable bindings
--> $DIR/issue-104513-ice.rs:3:14 --> $DIR/issue-104513-ice.rs:3:14
| |
LL | let _: S<impl Oops> = S; LL | let _: S<impl Oops> = S;
| ^^^^^^^^^ | ^^^^^^^^^
|
= note: `impl Trait` is only allowed in arguments and return types of functions and methods
error: aborting due to 2 previous errors error: aborting due to 2 previous errors