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

Lines changed: 3 additions & 4 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 3 additions & 9 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 2 additions & 2 deletions
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

0 commit comments

Comments
 (0)