Skip to content

Commit 3341c94

Browse files
committed
ast_validation: tweak diagnostic output
1 parent 79d139a commit 3341c94

20 files changed

+96
-81
lines changed

src/librustc_ast_passes/ast_validation.rs

+23-12
Original file line numberDiff line numberDiff line change
@@ -223,21 +223,29 @@ impl<'a> AstValidator<'a> {
223223

224224
fn check_trait_fn_not_async(&self, fn_span: Span, asyncness: Async) {
225225
if let Async::Yes { span, .. } = asyncness {
226-
struct_span_err!(self.session, fn_span, E0706, "trait fns cannot be declared `async`")
227-
.span_label(span, "`async` because of this")
228-
.note("`async` trait functions are not currently supported")
229-
.note(
230-
"consider using the `async-trait` crate: https://crates.io/crates/async-trait",
231-
)
232-
.emit();
226+
struct_span_err!(
227+
self.session,
228+
fn_span,
229+
E0706,
230+
"functions in traits cannot be declared `async`"
231+
)
232+
.span_label(span, "`async` because of this")
233+
.note("`async` trait functions are not currently supported")
234+
.note("consider using the `async-trait` crate: https://crates.io/crates/async-trait")
235+
.emit();
233236
}
234237
}
235238

236239
fn check_trait_fn_not_const(&self, constness: Const) {
237240
if let Const::Yes(span) = constness {
238-
struct_span_err!(self.session, span, E0379, "trait fns cannot be declared const")
239-
.span_label(span, "trait fns cannot be const")
240-
.emit();
241+
struct_span_err!(
242+
self.session,
243+
span,
244+
E0379,
245+
"functions in traits cannot be declared const"
246+
)
247+
.span_label(span, "functions in traits cannot be const")
248+
.emit();
241249
}
242250
}
243251

@@ -513,8 +521,11 @@ impl<'a> AstValidator<'a> {
513521
for param in &generics.params {
514522
if let GenericParamKind::Const { .. } = param.kind {
515523
self.err_handler()
516-
.struct_span_err(span, "const parameters are not permitted in `const fn`")
517-
.span_label(const_span, "`const fn` because of this")
524+
.struct_span_err(
525+
span,
526+
"const parameters are not permitted in const functions",
527+
)
528+
.span_label(const_span, "`const` because of this")
518529
.emit();
519530
}
520531
}
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// edition:2018
22
trait T {
3-
async fn foo() {} //~ ERROR trait fns cannot be declared `async`
4-
async fn bar(&self) {} //~ ERROR trait fns cannot be declared `async`
3+
async fn foo() {} //~ ERROR functions in traits cannot be declared `async`
4+
async fn bar(&self) {} //~ ERROR functions in traits cannot be declared `async`
55
}
66

77
fn main() {}

src/test/ui/async-await/async-trait-fn.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0706]: trait fns cannot be declared `async`
1+
error[E0706]: functions in traits cannot be declared `async`
22
--> $DIR/async-trait-fn.rs:3:5
33
|
44
LL | async fn foo() {}
@@ -9,7 +9,7 @@ LL | async fn foo() {}
99
= note: `async` trait functions are not currently supported
1010
= note: consider using the `async-trait` crate: https://crates.io/crates/async-trait
1111

12-
error[E0706]: trait fns cannot be declared `async`
12+
error[E0706]: functions in traits cannot be declared `async`
1313
--> $DIR/async-trait-fn.rs:4:5
1414
|
1515
LL | async fn bar(&self) {}

src/test/ui/async-await/edition-deny-async-fns-2015.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl Foo {
1616

1717
trait Bar {
1818
async fn foo() {} //~ ERROR `async fn` is not permitted in the 2015 edition
19-
//~^ ERROR trait fns cannot be declared `async`
19+
//~^ ERROR functions in traits cannot be declared `async`
2020
}
2121

2222
fn main() {

src/test/ui/async-await/edition-deny-async-fns-2015.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ LL | async fn bar() {}
8888
= help: set `edition = "2018"` in `Cargo.toml`
8989
= note: for more on editions, read https://doc.rust-lang.org/edition-guide
9090

91-
error[E0706]: trait fns cannot be declared `async`
91+
error[E0706]: functions in traits cannot be declared `async`
9292
--> $DIR/edition-deny-async-fns-2015.rs:18:5
9393
|
9494
LL | async fn foo() {}

src/test/ui/const-generics/const-fn-with-const-param.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
33

44
const fn const_u32_identity<const X: u32>() -> u32 {
5-
//~^ ERROR const parameters are not permitted in `const fn`
5+
//~^ ERROR const parameters are not permitted in const functions
66
X
77
}
88

src/test/ui/const-generics/const-fn-with-const-param.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error: const parameters are not permitted in `const fn`
1+
error: const parameters are not permitted in const functions
22
--> $DIR/const-fn-with-const-param.rs:4:1
33
|
44
LL | const fn const_u32_identity<const X: u32>() -> u32 {
55
| ^----
66
| |
7-
| _`const fn` because of this
7+
| _`const` because of this
88
| |
99
LL | |
1010
LL | | X

src/test/ui/consts/const-fn-mismatch.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ trait Foo {
1010
}
1111

1212
impl Foo for u32 {
13-
const fn f() -> u32 { 22 }
14-
//~^ ERROR trait fns cannot be declared const
13+
const fn f() -> u32 {
14+
//~^ ERROR functions in traits cannot be declared const
15+
22
16+
}
1517
}
1618

17-
fn main() { }
19+
fn main() {}

src/test/ui/consts/const-fn-mismatch.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0379]: trait fns cannot be declared const
1+
error[E0379]: functions in traits cannot be declared const
22
--> $DIR/const-fn-mismatch.rs:13:5
33
|
4-
LL | const fn f() -> u32 { 22 }
5-
| ^^^^^ trait fns cannot be const
4+
LL | const fn f() -> u32 {
5+
| ^^^^^ functions in traits cannot be const
66

77
error: aborting due to previous error
88

src/test/ui/consts/const-fn-not-in-trait.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55

66
trait Foo {
77
const fn f() -> u32;
8-
//~^ ERROR trait fns cannot be declared const
9-
const fn g() -> u32 { 0 }
10-
//~^ ERROR trait fns cannot be declared const
8+
//~^ ERROR functions in traits cannot be declared const
9+
const fn g() -> u32 {
10+
//~^ ERROR functions in traits cannot be declared const
11+
0
12+
}
1113
}
1214

13-
fn main() { }
15+
fn main() {}

src/test/ui/consts/const-fn-not-in-trait.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
error[E0379]: trait fns cannot be declared const
1+
error[E0379]: functions in traits cannot be declared const
22
--> $DIR/const-fn-not-in-trait.rs:7:5
33
|
44
LL | const fn f() -> u32;
5-
| ^^^^^ trait fns cannot be const
5+
| ^^^^^ functions in traits cannot be const
66

7-
error[E0379]: trait fns cannot be declared const
7+
error[E0379]: functions in traits cannot be declared const
88
--> $DIR/const-fn-not-in-trait.rs:9:5
99
|
10-
LL | const fn g() -> u32 { 0 }
11-
| ^^^^^ trait fns cannot be const
10+
LL | const fn g() -> u32 {
11+
| ^^^^^ functions in traits cannot be const
1212

1313
error: aborting due to 2 previous errors
1414

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ const fn foo() -> usize { 0 } // ok
44

55
trait Foo {
66
const fn foo() -> u32; //~ ERROR const fn is unstable
7-
//~| ERROR trait fns cannot be declared const
7+
//~| ERROR functions in traits cannot be declared const
88
const fn bar() -> u32 { 0 } //~ ERROR const fn is unstable
9-
//~| ERROR trait fns cannot be declared const
9+
//~| ERROR functions in traits cannot be declared const
1010
}
1111

1212
impl Foo for u32 {
13-
const fn foo() -> u32 { 0 } //~ ERROR trait fns cannot be declared const
13+
const fn foo() -> u32 { 0 } //~ ERROR functions in traits cannot be declared const
1414
}
1515

1616
trait Bar {}

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
error[E0379]: trait fns cannot be declared const
1+
error[E0379]: functions in traits cannot be declared const
22
--> $DIR/feature-gate-const_fn.rs:6:5
33
|
44
LL | const fn foo() -> u32;
5-
| ^^^^^ trait fns cannot be const
5+
| ^^^^^ functions in traits cannot be const
66

7-
error[E0379]: trait fns cannot be declared const
7+
error[E0379]: functions in traits cannot be declared const
88
--> $DIR/feature-gate-const_fn.rs:8:5
99
|
1010
LL | const fn bar() -> u32 { 0 }
11-
| ^^^^^ trait fns cannot be const
11+
| ^^^^^ functions in traits cannot be const
1212

13-
error[E0379]: trait fns cannot be declared const
13+
error[E0379]: functions in traits cannot be declared const
1414
--> $DIR/feature-gate-const_fn.rs:13:5
1515
|
1616
LL | const fn foo() -> u32 { 0 }
17-
| ^^^^^ trait fns cannot be const
17+
| ^^^^^ functions in traits cannot be const
1818

1919
error[E0658]: const fn is unstable
2020
--> $DIR/feature-gate-const_fn.rs:6:5

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ const fn foo() -> usize { 0 } // stabilized
44

55
trait Foo {
66
const fn foo() -> u32; //~ ERROR const fn is unstable
7-
//~| ERROR trait fns cannot be declared const
7+
//~| ERROR functions in traits cannot be declared const
88
const fn bar() -> u32 { 0 } //~ ERROR const fn is unstable
9-
//~| ERROR trait fns cannot be declared const
9+
//~| ERROR functions in traits cannot be declared const
1010
}
1111

1212
impl Foo for u32 {
13-
const fn foo() -> u32 { 0 } //~ ERROR trait fns cannot be declared const
13+
const fn foo() -> u32 { 0 } //~ ERROR functions in traits cannot be declared const
1414
}
1515

1616
trait Bar {}

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
error[E0379]: trait fns cannot be declared const
1+
error[E0379]: functions in traits cannot be declared const
22
--> $DIR/feature-gate-min_const_fn.rs:6:5
33
|
44
LL | const fn foo() -> u32;
5-
| ^^^^^ trait fns cannot be const
5+
| ^^^^^ functions in traits cannot be const
66

7-
error[E0379]: trait fns cannot be declared const
7+
error[E0379]: functions in traits cannot be declared const
88
--> $DIR/feature-gate-min_const_fn.rs:8:5
99
|
1010
LL | const fn bar() -> u32 { 0 }
11-
| ^^^^^ trait fns cannot be const
11+
| ^^^^^ functions in traits cannot be const
1212

13-
error[E0379]: trait fns cannot be declared const
13+
error[E0379]: functions in traits cannot be declared const
1414
--> $DIR/feature-gate-min_const_fn.rs:13:5
1515
|
1616
LL | const fn foo() -> u32 { 0 }
17-
| ^^^^^ trait fns cannot be const
17+
| ^^^^^ functions in traits cannot be const
1818

1919
error[E0658]: const fn is unstable
2020
--> $DIR/feature-gate-min_const_fn.rs:6:5

src/test/ui/issues/issue-54954.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const ARR_LEN: usize = Tt::const_val::<[i8; 123]>();
55

66
trait Tt {
77
const fn const_val<T: Sized>() -> usize {
8-
//~^ ERROR trait fns cannot be declared const
8+
//~^ ERROR functions in traits cannot be declared const
99
core::mem::size_of::<T>()
1010
}
1111
}

src/test/ui/issues/issue-54954.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0379]: trait fns cannot be declared const
1+
error[E0379]: functions in traits cannot be declared const
22
--> $DIR/issue-54954.rs:7:5
33
|
44
LL | const fn const_val<T: Sized>() -> usize {
5-
| ^^^^^ trait fns cannot be const
5+
| ^^^^^ functions in traits cannot be const
66

77
error[E0283]: type annotations needed
88
--> $DIR/issue-54954.rs:3:24

src/test/ui/mismatched_types/const-fn-in-trait.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
error[E0379]: trait fns cannot be declared const
1+
error[E0379]: functions in traits cannot be declared const
22
--> $DIR/const-fn-in-trait.rs:7:5
33
|
44
LL | const fn g();
5-
| ^^^^^ trait fns cannot be const
5+
| ^^^^^ functions in traits cannot be const
66

7-
error[E0379]: trait fns cannot be declared const
7+
error[E0379]: functions in traits cannot be declared const
88
--> $DIR/const-fn-in-trait.rs:11:5
99
|
1010
LL | const fn f() -> u32 { 22 }
11-
| ^^^^^ trait fns cannot be const
11+
| ^^^^^ functions in traits cannot be const
1212

1313
error: aborting due to 2 previous errors
1414

src/test/ui/parser/fn-header-semantic-fail.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,26 @@ fn main() {
1414
//~^ ERROR functions cannot be both `const` and `async`
1515

1616
trait X {
17-
async fn ft1(); //~ ERROR trait fns cannot be declared `async`
17+
async fn ft1(); //~ ERROR functions in traits cannot be declared `async`
1818
unsafe fn ft2(); // OK.
19-
const fn ft3(); //~ ERROR trait fns cannot be declared const
19+
const fn ft3(); //~ ERROR functions in traits cannot be declared const
2020
extern "C" fn ft4(); // OK.
2121
const async unsafe extern "C" fn ft5();
22-
//~^ ERROR trait fns cannot be declared `async`
23-
//~| ERROR trait fns cannot be declared const
22+
//~^ ERROR functions in traits cannot be declared `async`
23+
//~| ERROR functions in traits cannot be declared const
2424
//~| ERROR functions cannot be both `const` and `async`
2525
}
2626

2727
struct Y;
2828
impl X for Y {
29-
async fn ft1() {} //~ ERROR trait fns cannot be declared `async`
29+
async fn ft1() {} //~ ERROR functions in traits cannot be declared `async`
3030
//~^ ERROR method `ft1` has an incompatible type for trait
3131
unsafe fn ft2() {} // OK.
32-
const fn ft3() {} //~ ERROR trait fns cannot be declared const
32+
const fn ft3() {} //~ ERROR functions in traits cannot be declared const
3333
extern "C" fn ft4() {}
3434
const async unsafe extern "C" fn ft5() {}
35-
//~^ ERROR trait fns cannot be declared `async`
36-
//~| ERROR trait fns cannot be declared const
35+
//~^ ERROR functions in traits cannot be declared `async`
36+
//~| ERROR functions in traits cannot be declared const
3737
//~| ERROR method `ft5` has an incompatible type for trait
3838
//~| ERROR functions cannot be both `const` and `async`
3939
}

0 commit comments

Comments
 (0)