mirror of https://github.com/rust-lang/rust.git
ast_validation: tweak diagnostic output
This commit is contained in:
parent
79d139ac70
commit
3341c94006
|
@ -223,21 +223,29 @@ impl<'a> AstValidator<'a> {
|
|||
|
||||
fn check_trait_fn_not_async(&self, fn_span: Span, asyncness: Async) {
|
||||
if let Async::Yes { span, .. } = asyncness {
|
||||
struct_span_err!(self.session, fn_span, E0706, "trait fns cannot be declared `async`")
|
||||
.span_label(span, "`async` because of this")
|
||||
.note("`async` trait functions are not currently supported")
|
||||
.note(
|
||||
"consider using the `async-trait` crate: https://crates.io/crates/async-trait",
|
||||
)
|
||||
.emit();
|
||||
struct_span_err!(
|
||||
self.session,
|
||||
fn_span,
|
||||
E0706,
|
||||
"functions in traits cannot be declared `async`"
|
||||
)
|
||||
.span_label(span, "`async` because of this")
|
||||
.note("`async` trait functions are not currently supported")
|
||||
.note("consider using the `async-trait` crate: https://crates.io/crates/async-trait")
|
||||
.emit();
|
||||
}
|
||||
}
|
||||
|
||||
fn check_trait_fn_not_const(&self, constness: Const) {
|
||||
if let Const::Yes(span) = constness {
|
||||
struct_span_err!(self.session, span, E0379, "trait fns cannot be declared const")
|
||||
.span_label(span, "trait fns cannot be const")
|
||||
.emit();
|
||||
struct_span_err!(
|
||||
self.session,
|
||||
span,
|
||||
E0379,
|
||||
"functions in traits cannot be declared const"
|
||||
)
|
||||
.span_label(span, "functions in traits cannot be const")
|
||||
.emit();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -513,8 +521,11 @@ impl<'a> AstValidator<'a> {
|
|||
for param in &generics.params {
|
||||
if let GenericParamKind::Const { .. } = param.kind {
|
||||
self.err_handler()
|
||||
.struct_span_err(span, "const parameters are not permitted in `const fn`")
|
||||
.span_label(const_span, "`const fn` because of this")
|
||||
.struct_span_err(
|
||||
span,
|
||||
"const parameters are not permitted in const functions",
|
||||
)
|
||||
.span_label(const_span, "`const` because of this")
|
||||
.emit();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// edition:2018
|
||||
trait T {
|
||||
async fn foo() {} //~ ERROR trait fns cannot be declared `async`
|
||||
async fn bar(&self) {} //~ ERROR trait fns cannot be declared `async`
|
||||
async fn foo() {} //~ ERROR functions in traits cannot be declared `async`
|
||||
async fn bar(&self) {} //~ ERROR functions in traits cannot be declared `async`
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
error[E0706]: trait fns cannot be declared `async`
|
||||
error[E0706]: functions in traits cannot be declared `async`
|
||||
--> $DIR/async-trait-fn.rs:3:5
|
||||
|
|
||||
LL | async fn foo() {}
|
||||
|
@ -9,7 +9,7 @@ LL | async fn foo() {}
|
|||
= note: `async` trait functions are not currently supported
|
||||
= note: consider using the `async-trait` crate: https://crates.io/crates/async-trait
|
||||
|
||||
error[E0706]: trait fns cannot be declared `async`
|
||||
error[E0706]: functions in traits cannot be declared `async`
|
||||
--> $DIR/async-trait-fn.rs:4:5
|
||||
|
|
||||
LL | async fn bar(&self) {}
|
||||
|
|
|
@ -16,7 +16,7 @@ impl Foo {
|
|||
|
||||
trait Bar {
|
||||
async fn foo() {} //~ ERROR `async fn` is not permitted in the 2015 edition
|
||||
//~^ ERROR trait fns cannot be declared `async`
|
||||
//~^ ERROR functions in traits cannot be declared `async`
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -88,7 +88,7 @@ LL | async fn bar() {}
|
|||
= help: set `edition = "2018"` in `Cargo.toml`
|
||||
= note: for more on editions, read https://doc.rust-lang.org/edition-guide
|
||||
|
||||
error[E0706]: trait fns cannot be declared `async`
|
||||
error[E0706]: functions in traits cannot be declared `async`
|
||||
--> $DIR/edition-deny-async-fns-2015.rs:18:5
|
||||
|
|
||||
LL | async fn foo() {}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
|
||||
|
||||
const fn const_u32_identity<const X: u32>() -> u32 {
|
||||
//~^ ERROR const parameters are not permitted in `const fn`
|
||||
//~^ ERROR const parameters are not permitted in const functions
|
||||
X
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
error: const parameters are not permitted in `const fn`
|
||||
error: const parameters are not permitted in const functions
|
||||
--> $DIR/const-fn-with-const-param.rs:4:1
|
||||
|
|
||||
LL | const fn const_u32_identity<const X: u32>() -> u32 {
|
||||
| ^----
|
||||
| |
|
||||
| _`const fn` because of this
|
||||
| _`const` because of this
|
||||
| |
|
||||
LL | |
|
||||
LL | | X
|
||||
|
|
|
@ -10,8 +10,10 @@ trait Foo {
|
|||
}
|
||||
|
||||
impl Foo for u32 {
|
||||
const fn f() -> u32 { 22 }
|
||||
//~^ ERROR trait fns cannot be declared const
|
||||
const fn f() -> u32 {
|
||||
//~^ ERROR functions in traits cannot be declared const
|
||||
22
|
||||
}
|
||||
}
|
||||
|
||||
fn main() { }
|
||||
fn main() {}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
error[E0379]: trait fns cannot be declared const
|
||||
error[E0379]: functions in traits cannot be declared const
|
||||
--> $DIR/const-fn-mismatch.rs:13:5
|
||||
|
|
||||
LL | const fn f() -> u32 { 22 }
|
||||
| ^^^^^ trait fns cannot be const
|
||||
LL | const fn f() -> u32 {
|
||||
| ^^^^^ functions in traits cannot be const
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
@ -5,9 +5,11 @@
|
|||
|
||||
trait Foo {
|
||||
const fn f() -> u32;
|
||||
//~^ ERROR trait fns cannot be declared const
|
||||
const fn g() -> u32 { 0 }
|
||||
//~^ ERROR trait fns cannot be declared const
|
||||
//~^ ERROR functions in traits cannot be declared const
|
||||
const fn g() -> u32 {
|
||||
//~^ ERROR functions in traits cannot be declared const
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
fn main() { }
|
||||
fn main() {}
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
error[E0379]: trait fns cannot be declared const
|
||||
error[E0379]: functions in traits cannot be declared const
|
||||
--> $DIR/const-fn-not-in-trait.rs:7:5
|
||||
|
|
||||
LL | const fn f() -> u32;
|
||||
| ^^^^^ trait fns cannot be const
|
||||
| ^^^^^ functions in traits cannot be const
|
||||
|
||||
error[E0379]: trait fns cannot be declared const
|
||||
error[E0379]: functions in traits cannot be declared const
|
||||
--> $DIR/const-fn-not-in-trait.rs:9:5
|
||||
|
|
||||
LL | const fn g() -> u32 { 0 }
|
||||
| ^^^^^ trait fns cannot be const
|
||||
LL | const fn g() -> u32 {
|
||||
| ^^^^^ functions in traits cannot be const
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
@ -4,13 +4,13 @@ const fn foo() -> usize { 0 } // ok
|
|||
|
||||
trait Foo {
|
||||
const fn foo() -> u32; //~ ERROR const fn is unstable
|
||||
//~| ERROR trait fns cannot be declared const
|
||||
//~| ERROR functions in traits cannot be declared const
|
||||
const fn bar() -> u32 { 0 } //~ ERROR const fn is unstable
|
||||
//~| ERROR trait fns cannot be declared const
|
||||
//~| ERROR functions in traits cannot be declared const
|
||||
}
|
||||
|
||||
impl Foo for u32 {
|
||||
const fn foo() -> u32 { 0 } //~ ERROR trait fns cannot be declared const
|
||||
const fn foo() -> u32 { 0 } //~ ERROR functions in traits cannot be declared const
|
||||
}
|
||||
|
||||
trait Bar {}
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
error[E0379]: trait fns cannot be declared const
|
||||
error[E0379]: functions in traits cannot be declared const
|
||||
--> $DIR/feature-gate-const_fn.rs:6:5
|
||||
|
|
||||
LL | const fn foo() -> u32;
|
||||
| ^^^^^ trait fns cannot be const
|
||||
| ^^^^^ functions in traits cannot be const
|
||||
|
||||
error[E0379]: trait fns cannot be declared const
|
||||
error[E0379]: functions in traits cannot be declared const
|
||||
--> $DIR/feature-gate-const_fn.rs:8:5
|
||||
|
|
||||
LL | const fn bar() -> u32 { 0 }
|
||||
| ^^^^^ trait fns cannot be const
|
||||
| ^^^^^ functions in traits cannot be const
|
||||
|
||||
error[E0379]: trait fns cannot be declared const
|
||||
error[E0379]: functions in traits cannot be declared const
|
||||
--> $DIR/feature-gate-const_fn.rs:13:5
|
||||
|
|
||||
LL | const fn foo() -> u32 { 0 }
|
||||
| ^^^^^ trait fns cannot be const
|
||||
| ^^^^^ functions in traits cannot be const
|
||||
|
||||
error[E0658]: const fn is unstable
|
||||
--> $DIR/feature-gate-const_fn.rs:6:5
|
||||
|
|
|
@ -4,13 +4,13 @@ const fn foo() -> usize { 0 } // stabilized
|
|||
|
||||
trait Foo {
|
||||
const fn foo() -> u32; //~ ERROR const fn is unstable
|
||||
//~| ERROR trait fns cannot be declared const
|
||||
//~| ERROR functions in traits cannot be declared const
|
||||
const fn bar() -> u32 { 0 } //~ ERROR const fn is unstable
|
||||
//~| ERROR trait fns cannot be declared const
|
||||
//~| ERROR functions in traits cannot be declared const
|
||||
}
|
||||
|
||||
impl Foo for u32 {
|
||||
const fn foo() -> u32 { 0 } //~ ERROR trait fns cannot be declared const
|
||||
const fn foo() -> u32 { 0 } //~ ERROR functions in traits cannot be declared const
|
||||
}
|
||||
|
||||
trait Bar {}
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
error[E0379]: trait fns cannot be declared const
|
||||
error[E0379]: functions in traits cannot be declared const
|
||||
--> $DIR/feature-gate-min_const_fn.rs:6:5
|
||||
|
|
||||
LL | const fn foo() -> u32;
|
||||
| ^^^^^ trait fns cannot be const
|
||||
| ^^^^^ functions in traits cannot be const
|
||||
|
||||
error[E0379]: trait fns cannot be declared const
|
||||
error[E0379]: functions in traits cannot be declared const
|
||||
--> $DIR/feature-gate-min_const_fn.rs:8:5
|
||||
|
|
||||
LL | const fn bar() -> u32 { 0 }
|
||||
| ^^^^^ trait fns cannot be const
|
||||
| ^^^^^ functions in traits cannot be const
|
||||
|
||||
error[E0379]: trait fns cannot be declared const
|
||||
error[E0379]: functions in traits cannot be declared const
|
||||
--> $DIR/feature-gate-min_const_fn.rs:13:5
|
||||
|
|
||||
LL | const fn foo() -> u32 { 0 }
|
||||
| ^^^^^ trait fns cannot be const
|
||||
| ^^^^^ functions in traits cannot be const
|
||||
|
||||
error[E0658]: const fn is unstable
|
||||
--> $DIR/feature-gate-min_const_fn.rs:6:5
|
||||
|
|
|
@ -5,7 +5,7 @@ const ARR_LEN: usize = Tt::const_val::<[i8; 123]>();
|
|||
|
||||
trait Tt {
|
||||
const fn const_val<T: Sized>() -> usize {
|
||||
//~^ ERROR trait fns cannot be declared const
|
||||
//~^ ERROR functions in traits cannot be declared const
|
||||
core::mem::size_of::<T>()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
error[E0379]: trait fns cannot be declared const
|
||||
error[E0379]: functions in traits cannot be declared const
|
||||
--> $DIR/issue-54954.rs:7:5
|
||||
|
|
||||
LL | const fn const_val<T: Sized>() -> usize {
|
||||
| ^^^^^ trait fns cannot be const
|
||||
| ^^^^^ functions in traits cannot be const
|
||||
|
||||
error[E0283]: type annotations needed
|
||||
--> $DIR/issue-54954.rs:3:24
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
error[E0379]: trait fns cannot be declared const
|
||||
error[E0379]: functions in traits cannot be declared const
|
||||
--> $DIR/const-fn-in-trait.rs:7:5
|
||||
|
|
||||
LL | const fn g();
|
||||
| ^^^^^ trait fns cannot be const
|
||||
| ^^^^^ functions in traits cannot be const
|
||||
|
||||
error[E0379]: trait fns cannot be declared const
|
||||
error[E0379]: functions in traits cannot be declared const
|
||||
--> $DIR/const-fn-in-trait.rs:11:5
|
||||
|
|
||||
LL | const fn f() -> u32 { 22 }
|
||||
| ^^^^^ trait fns cannot be const
|
||||
| ^^^^^ functions in traits cannot be const
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
@ -14,26 +14,26 @@ fn main() {
|
|||
//~^ ERROR functions cannot be both `const` and `async`
|
||||
|
||||
trait X {
|
||||
async fn ft1(); //~ ERROR trait fns cannot be declared `async`
|
||||
async fn ft1(); //~ ERROR functions in traits cannot be declared `async`
|
||||
unsafe fn ft2(); // OK.
|
||||
const fn ft3(); //~ ERROR trait fns cannot be declared const
|
||||
const fn ft3(); //~ ERROR functions in traits cannot be declared const
|
||||
extern "C" fn ft4(); // OK.
|
||||
const async unsafe extern "C" fn ft5();
|
||||
//~^ ERROR trait fns cannot be declared `async`
|
||||
//~| ERROR trait fns cannot be declared const
|
||||
//~^ ERROR functions in traits cannot be declared `async`
|
||||
//~| ERROR functions in traits cannot be declared const
|
||||
//~| ERROR functions cannot be both `const` and `async`
|
||||
}
|
||||
|
||||
struct Y;
|
||||
impl X for Y {
|
||||
async fn ft1() {} //~ ERROR trait fns cannot be declared `async`
|
||||
async fn ft1() {} //~ ERROR functions in traits cannot be declared `async`
|
||||
//~^ ERROR method `ft1` has an incompatible type for trait
|
||||
unsafe fn ft2() {} // OK.
|
||||
const fn ft3() {} //~ ERROR trait fns cannot be declared const
|
||||
const fn ft3() {} //~ ERROR functions in traits cannot be declared const
|
||||
extern "C" fn ft4() {}
|
||||
const async unsafe extern "C" fn ft5() {}
|
||||
//~^ ERROR trait fns cannot be declared `async`
|
||||
//~| ERROR trait fns cannot be declared const
|
||||
//~^ ERROR functions in traits cannot be declared `async`
|
||||
//~| ERROR functions in traits cannot be declared const
|
||||
//~| ERROR method `ft5` has an incompatible type for trait
|
||||
//~| ERROR functions cannot be both `const` and `async`
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ LL | const async unsafe extern "C" fn ff5() {} // OK.
|
|||
| | `async` because of this
|
||||
| `const` because of this
|
||||
|
||||
error[E0706]: trait fns cannot be declared `async`
|
||||
error[E0706]: functions in traits cannot be declared `async`
|
||||
--> $DIR/fn-header-semantic-fail.rs:17:9
|
||||
|
|
||||
LL | async fn ft1();
|
||||
|
@ -18,19 +18,19 @@ LL | async fn ft1();
|
|||
= note: `async` trait functions are not currently supported
|
||||
= note: consider using the `async-trait` crate: https://crates.io/crates/async-trait
|
||||
|
||||
error[E0379]: trait fns cannot be declared const
|
||||
error[E0379]: functions in traits cannot be declared const
|
||||
--> $DIR/fn-header-semantic-fail.rs:19:9
|
||||
|
|
||||
LL | const fn ft3();
|
||||
| ^^^^^ trait fns cannot be const
|
||||
| ^^^^^ functions in traits cannot be const
|
||||
|
||||
error[E0379]: trait fns cannot be declared const
|
||||
error[E0379]: functions in traits cannot be declared const
|
||||
--> $DIR/fn-header-semantic-fail.rs:21:9
|
||||
|
|
||||
LL | const async unsafe extern "C" fn ft5();
|
||||
| ^^^^^ trait fns cannot be const
|
||||
| ^^^^^ functions in traits cannot be const
|
||||
|
||||
error[E0706]: trait fns cannot be declared `async`
|
||||
error[E0706]: functions in traits cannot be declared `async`
|
||||
--> $DIR/fn-header-semantic-fail.rs:21:9
|
||||
|
|
||||
LL | const async unsafe extern "C" fn ft5();
|
||||
|
@ -50,7 +50,7 @@ LL | const async unsafe extern "C" fn ft5();
|
|||
| | `async` because of this
|
||||
| `const` because of this
|
||||
|
||||
error[E0706]: trait fns cannot be declared `async`
|
||||
error[E0706]: functions in traits cannot be declared `async`
|
||||
--> $DIR/fn-header-semantic-fail.rs:29:9
|
||||
|
|
||||
LL | async fn ft1() {}
|
||||
|
@ -61,19 +61,19 @@ LL | async fn ft1() {}
|
|||
= note: `async` trait functions are not currently supported
|
||||
= note: consider using the `async-trait` crate: https://crates.io/crates/async-trait
|
||||
|
||||
error[E0379]: trait fns cannot be declared const
|
||||
error[E0379]: functions in traits cannot be declared const
|
||||
--> $DIR/fn-header-semantic-fail.rs:32:9
|
||||
|
|
||||
LL | const fn ft3() {}
|
||||
| ^^^^^ trait fns cannot be const
|
||||
| ^^^^^ functions in traits cannot be const
|
||||
|
||||
error[E0379]: trait fns cannot be declared const
|
||||
error[E0379]: functions in traits cannot be declared const
|
||||
--> $DIR/fn-header-semantic-fail.rs:34:9
|
||||
|
|
||||
LL | const async unsafe extern "C" fn ft5() {}
|
||||
| ^^^^^ trait fns cannot be const
|
||||
| ^^^^^ functions in traits cannot be const
|
||||
|
||||
error[E0706]: trait fns cannot be declared `async`
|
||||
error[E0706]: functions in traits cannot be declared `async`
|
||||
--> $DIR/fn-header-semantic-fail.rs:34:9
|
||||
|
|
||||
LL | const async unsafe extern "C" fn ft5() {}
|
||||
|
|
Loading…
Reference in New Issue