Skip to content

Commit 207fb5f

Browse files
fix impl trait message, bless tests
1 parent f04f732 commit 207fb5f

31 files changed

+129
-256
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ impl std::fmt::Display for ImplTraitPosition {
297297
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
298298
let name = match self {
299299
ImplTraitPosition::Path => "path",
300-
ImplTraitPosition::Variable => "variable",
300+
ImplTraitPosition::Variable => "variable binding",
301301
ImplTraitPosition::Type => "type",
302302
ImplTraitPosition::Trait => "trait",
303303
ImplTraitPosition::AsyncBlock => "async block",
@@ -1419,10 +1419,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
14191419
self.sess,
14201420
t.span,
14211421
E0562,
1422-
"`impl Trait` not allowed outside of \
1423-
function and inherent method return types",
1422+
"`impl Trait` only allowed in function and inherent method return types, not in {}",
1423+
position
14241424
);
1425-
err.note(&format!("found `impl Trait` in {}", position));
14261425
err.emit();
14271426
hir::TyKind::Err
14281427
}

src/test/ui/feature-gates/feature-gate-associated_type_bounds.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,20 @@ fn _rpit_dyn() -> Box<dyn Tr1<As1: Copy>> { Box::new(S1) }
5757

5858
const _cdef: impl Tr1<As1: Copy> = S1;
5959
//~^ ERROR associated type bounds are unstable
60-
//~| ERROR `impl Trait` not allowed outside of function and inherent method return types [E0562]
60+
//~| ERROR `impl Trait` only allowed in function and inherent method return types
6161
// FIXME: uncomment when `impl_trait_in_bindings` feature is fixed.
6262
// const _cdef_dyn: &dyn Tr1<As1: Copy> = &S1;
6363

6464
static _sdef: impl Tr1<As1: Copy> = S1;
6565
//~^ ERROR associated type bounds are unstable
66-
//~| ERROR `impl Trait` not allowed outside of function and inherent method return types [E0562]
66+
//~| ERROR `impl Trait` only allowed in function and inherent method return types
6767
// FIXME: uncomment when `impl_trait_in_bindings` feature is fixed.
6868
// static _sdef_dyn: &dyn Tr1<As1: Copy> = &S1;
6969

7070
fn main() {
7171
let _: impl Tr1<As1: Copy> = S1;
7272
//~^ ERROR associated type bounds are unstable
73-
//~| ERROR `impl Trait` not allowed outside of function and inherent method return types [E0562]
73+
//~| ERROR `impl Trait` only allowed in function and inherent method return types
7474
// FIXME: uncomment when `impl_trait_in_bindings` feature is fixed.
7575
// let _: &dyn Tr1<As1: Copy> = &S1;
7676
}

src/test/ui/feature-gates/feature-gate-associated_type_bounds.stderr

+3-9
Original file line numberDiff line numberDiff line change
@@ -115,29 +115,23 @@ LL | let _: impl Tr1<As1: Copy> = S1;
115115
= note: see issue #52662 <https://github.com/rust-lang/rust/issues/52662> for more information
116116
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
117117

118-
error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
118+
error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in type
119119
--> $DIR/feature-gate-associated_type_bounds.rs:58:14
120120
|
121121
LL | const _cdef: impl Tr1<As1: Copy> = S1;
122122
| ^^^^^^^^^^^^^^^^^^^
123-
|
124-
= note: found `impl Trait` in type
125123

126-
error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
124+
error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in type
127125
--> $DIR/feature-gate-associated_type_bounds.rs:64:15
128126
|
129127
LL | static _sdef: impl Tr1<As1: Copy> = S1;
130128
| ^^^^^^^^^^^^^^^^^^^
131-
|
132-
= note: found `impl Trait` in type
133129

134-
error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
130+
error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in variable binding
135131
--> $DIR/feature-gate-associated_type_bounds.rs:71:12
136132
|
137133
LL | let _: impl Tr1<As1: Copy> = S1;
138134
| ^^^^^^^^^^^^^^^^^^^
139-
|
140-
= note: found `impl Trait` in variable
141135

142136
error[E0277]: the trait bound `<<Self as _Tr3>::A as Iterator>::Item: Copy` is not satisfied
143137
--> $DIR/feature-gate-associated_type_bounds.rs:15:28

src/test/ui/impl-trait/issues/issue-54600.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ use std::fmt::Debug;
22

33
fn main() {
44
let x: Option<impl Debug> = Some(44_u32);
5-
//~^ `impl Trait` not allowed outside of function and inherent method return types
5+
//~^ `impl Trait` only allowed in function and inherent method return types
66
println!("{:?}", x);
77
}

src/test/ui/impl-trait/issues/issue-54600.stderr

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
1+
error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in variable binding
22
--> $DIR/issue-54600.rs:4:19
33
|
44
LL | let x: Option<impl Debug> = Some(44_u32);
55
| ^^^^^^^^^^
6-
|
7-
= note: found `impl Trait` in variable
86

97
error: aborting due to previous error
108

src/test/ui/impl-trait/issues/issue-54840.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ use std::ops::Add;
33
fn main() {
44
let i: i32 = 0;
55
let j: &impl Add = &i;
6-
//~^ `impl Trait` not allowed outside of function and inherent method return types
6+
//~^ `impl Trait` only allowed in function and inherent method return types
77
}

src/test/ui/impl-trait/issues/issue-54840.stderr

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
1+
error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in variable binding
22
--> $DIR/issue-54840.rs:5:13
33
|
44
LL | let j: &impl Add = &i;
55
| ^^^^^^^^
6-
|
7-
= note: found `impl Trait` in variable
86

97
error: aborting due to previous error
108

src/test/ui/impl-trait/issues/issue-58504.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ fn mk_gen() -> impl Generator<Return=!, Yield=()> {
88

99
fn main() {
1010
let gens: [impl Generator<Return=!, Yield=()>;2] = [ mk_gen(), mk_gen() ];
11-
//~^ `impl Trait` not allowed outside of function and inherent method return types
11+
//~^ `impl Trait` only allowed in function and inherent method return types
1212
}

src/test/ui/impl-trait/issues/issue-58504.stderr

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
1+
error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in variable binding
22
--> $DIR/issue-58504.rs:10:16
33
|
44
LL | let gens: [impl Generator<Return=!, Yield=()>;2] = [ mk_gen(), mk_gen() ];
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6-
|
7-
= note: found `impl Trait` in variable
86

97
error: aborting due to previous error
108

src/test/ui/impl-trait/issues/issue-58956.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ impl Lam for B {}
55
pub struct Wrap<T>(T);
66

77
const _A: impl Lam = {
8-
//~^ `impl Trait` not allowed outside of function and inherent method return types
8+
//~^ `impl Trait` only allowed in function and inherent method return types
99
let x: Wrap<impl Lam> = Wrap(B);
10-
//~^ `impl Trait` not allowed outside of function and inherent method return types
10+
//~^ `impl Trait` only allowed in function and inherent method return types
1111
x.0
1212
};
1313

src/test/ui/impl-trait/issues/issue-58956.stderr

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
1+
error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in type
22
--> $DIR/issue-58956.rs:7:11
33
|
44
LL | const _A: impl Lam = {
55
| ^^^^^^^^
6-
|
7-
= note: found `impl Trait` in type
86

9-
error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
7+
error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in variable binding
108
--> $DIR/issue-58956.rs:9:17
119
|
1210
LL | let x: Wrap<impl Lam> = Wrap(B);
1311
| ^^^^^^^^
14-
|
15-
= note: found `impl Trait` in variable
1612

1713
error: aborting due to 2 previous errors
1814

Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
fn main() {
22
let x : (impl Copy,) = (true,);
3-
//~^ `impl Trait` not allowed outside of function and inherent method return types
3+
//~^ `impl Trait` only allowed in function and inherent method return types
44
}

src/test/ui/impl-trait/issues/issue-70971.stderr

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
1+
error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in variable binding
22
--> $DIR/issue-70971.rs:2:14
33
|
44
LL | let x : (impl Copy,) = (true,);
55
| ^^^^^^^^^
6-
|
7-
= note: found `impl Trait` in variable
86

97
error: aborting due to previous error
108

src/test/ui/impl-trait/issues/issue-79099.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
struct Bug {
22
V1: [(); {
33
let f: impl core::future::Future<Output = u8> = async { 1 };
4-
//~^ `impl Trait` not allowed outside of function and inherent method return types
4+
//~^ `impl Trait` only allowed in function and inherent method return types
55
//~| expected identifier
66
1
77
}],

src/test/ui/impl-trait/issues/issue-79099.stderr

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@ LL | let f: impl core::future::Future<Output = u8> = async { 1 };
99
= help: set `edition = "2021"` in `Cargo.toml`
1010
= note: for more on editions, read https://doc.rust-lang.org/edition-guide
1111

12-
error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
12+
error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in variable binding
1313
--> $DIR/issue-79099.rs:3:16
1414
|
1515
LL | let f: impl core::future::Future<Output = u8> = async { 1 };
1616
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17-
|
18-
= note: found `impl Trait` in variable
1917

2018
error: aborting due to 2 previous errors
2119

src/test/ui/impl-trait/issues/issue-83929-impl-trait-in-generic-default.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
struct Foo<T = impl Copy>(T);
2-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
2+
//~^ ERROR `impl Trait` only allowed in function and inherent method return types
33

44
type Result<T, E = impl std::error::Error> = std::result::Result<T, E>;
5-
//~^ ERROR `impl Trait` not allowed outside of function and inherent method return types
5+
//~^ ERROR `impl Trait` only allowed in function and inherent method return types
66

77
// should not cause ICE
88
fn x() -> Foo {

src/test/ui/impl-trait/issues/issue-83929-impl-trait-in-generic-default.stderr

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
1+
error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in type
22
--> $DIR/issue-83929-impl-trait-in-generic-default.rs:1:16
33
|
44
LL | struct Foo<T = impl Copy>(T);
55
| ^^^^^^^^^
6-
|
7-
= note: found `impl Trait` in type
86

9-
error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
7+
error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in type
108
--> $DIR/issue-83929-impl-trait-in-generic-default.rs:4:20
119
|
1210
LL | type Result<T, E = impl std::error::Error> = std::result::Result<T, E>;
1311
| ^^^^^^^^^^^^^^^^^^^^^^
14-
|
15-
= note: found `impl Trait` in type
1612

1713
error: aborting due to 2 previous errors
1814

src/test/ui/impl-trait/issues/issue-84919.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ impl Trait for () {}
33

44
fn foo<'a: 'a>() {
55
let _x: impl Trait = ();
6-
//~^ `impl Trait` not allowed outside of function and inherent method return types
6+
//~^ `impl Trait` only allowed in function and inherent method return types
77
}
88

99
fn main() {}

src/test/ui/impl-trait/issues/issue-84919.stderr

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
1+
error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in variable binding
22
--> $DIR/issue-84919.rs:5:13
33
|
44
LL | let _x: impl Trait = ();
55
| ^^^^^^^^^^
6-
|
7-
= note: found `impl Trait` in variable
86

97
error: aborting due to previous error
108

src/test/ui/impl-trait/issues/issue-86642.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
static x: impl Fn(&str) -> Result<&str, ()> = move |source| {
2-
//~^ `impl Trait` not allowed outside of function and inherent method return types
2+
//~^ `impl Trait` only allowed in function and inherent method return types
33
let res = (move |source| Ok(source))(source);
44
let res = res.or((move |source| Ok(source))(source));
55
res

src/test/ui/impl-trait/issues/issue-86642.stderr

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
1+
error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in type
22
--> $DIR/issue-86642.rs:1:11
33
|
44
LL | static x: impl Fn(&str) -> Result<&str, ()> = move |source| {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6-
|
7-
= note: found `impl Trait` in type
86

97
error: aborting due to previous error
108

src/test/ui/impl-trait/issues/issue-87295.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ impl<F> Struct<F> {
1414

1515
fn main() {
1616
let _do_not_waste: Struct<impl Trait<Output = i32>> = Struct::new(());
17-
//~^ `impl Trait` not allowed outside of function and inherent method return types
17+
//~^ `impl Trait` only allowed in function and inherent method return types
1818
}

src/test/ui/impl-trait/issues/issue-87295.stderr

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
1+
error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in variable binding
22
--> $DIR/issue-87295.rs:16:31
33
|
44
LL | let _do_not_waste: Struct<impl Trait<Output = i32>> = Struct::new(());
55
| ^^^^^^^^^^^^^^^^^^^^^^^^
6-
|
7-
= note: found `impl Trait` in variable
86

97
error: aborting due to previous error
108

src/test/ui/impl-trait/nested_impl_trait.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn bad_in_ret_position(x: impl Into<u32>) -> impl Into<impl Debug> { x }
77

88
fn bad_in_fn_syntax(x: fn() -> impl Into<impl Debug>) {}
99
//~^ ERROR nested `impl Trait` is not allowed
10-
//~^^ `impl Trait` not allowed
10+
//~| `impl Trait` only allowed in function and inherent method return types
1111

1212
fn bad_in_arg_position(_: impl Into<impl Debug>) { }
1313
//~^ ERROR nested `impl Trait` is not allowed
@@ -23,7 +23,7 @@ fn allowed_in_assoc_type() -> impl Iterator<Item=impl Fn()> {
2323
}
2424

2525
fn allowed_in_ret_type() -> impl Fn() -> impl Into<u32> {
26-
//~^ `impl Trait` not allowed
26+
//~^ `impl Trait` only allowed in function and inherent method return types
2727
|| 5
2828
}
2929

src/test/ui/impl-trait/nested_impl_trait.stderr

+2-6
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,17 @@ LL | fn bad(x: impl Into<u32>) -> impl Into<impl Debug> { x }
3434
| | nested `impl Trait` here
3535
| outer `impl Trait`
3636

37-
error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
37+
error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in `fn` pointer return
3838
--> $DIR/nested_impl_trait.rs:8:32
3939
|
4040
LL | fn bad_in_fn_syntax(x: fn() -> impl Into<impl Debug>) {}
4141
| ^^^^^^^^^^^^^^^^^^^^^
42-
|
43-
= note: found `impl Trait` in `fn` pointer return
4442

45-
error[E0562]: `impl Trait` not allowed outside of function and inherent method return types
43+
error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in `Fn` trait return
4644
--> $DIR/nested_impl_trait.rs:25:42
4745
|
4846
LL | fn allowed_in_ret_type() -> impl Fn() -> impl Into<u32> {
4947
| ^^^^^^^^^^^^^^
50-
|
51-
= note: found `impl Trait` in `Fn` trait return
5248

5349
error: aborting due to 6 previous errors
5450

0 commit comments

Comments
 (0)