diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-02-11 08:19:21 +0100 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-02-13 10:40:17 +0100 |
| commit | 3341c940068d60ade54ea343301a810c0bb51153 (patch) | |
| tree | ede7d803f3bb3be1ccb66878238c605d8f1f9594 /src | |
| parent | 79d139ac7056d0102db605715f354689b0214705 (diff) | |
| download | rust-3341c940068d60ade54ea343301a810c0bb51153.tar.gz rust-3341c940068d60ade54ea343301a810c0bb51153.zip | |
ast_validation: tweak diagnostic output
Diffstat (limited to 'src')
20 files changed, 96 insertions, 81 deletions
diff --git a/src/librustc_ast_passes/ast_validation.rs b/src/librustc_ast_passes/ast_validation.rs index 0bc6179dabf..2f0495b8b5a 100644 --- a/src/librustc_ast_passes/ast_validation.rs +++ b/src/librustc_ast_passes/ast_validation.rs @@ -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(); } } diff --git a/src/test/ui/async-await/async-trait-fn.rs b/src/test/ui/async-await/async-trait-fn.rs index 786100e916d..f0403b76620 100644 --- a/src/test/ui/async-await/async-trait-fn.rs +++ b/src/test/ui/async-await/async-trait-fn.rs @@ -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() {} diff --git a/src/test/ui/async-await/async-trait-fn.stderr b/src/test/ui/async-await/async-trait-fn.stderr index 04f72fb645e..6080b2815ee 100644 --- a/src/test/ui/async-await/async-trait-fn.stderr +++ b/src/test/ui/async-await/async-trait-fn.stderr @@ -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) {} diff --git a/src/test/ui/async-await/edition-deny-async-fns-2015.rs b/src/test/ui/async-await/edition-deny-async-fns-2015.rs index c85896150c2..5d2d186137e 100644 --- a/src/test/ui/async-await/edition-deny-async-fns-2015.rs +++ b/src/test/ui/async-await/edition-deny-async-fns-2015.rs @@ -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() { diff --git a/src/test/ui/async-await/edition-deny-async-fns-2015.stderr b/src/test/ui/async-await/edition-deny-async-fns-2015.stderr index 4afb0430a72..f3d982801bb 100644 --- a/src/test/ui/async-await/edition-deny-async-fns-2015.stderr +++ b/src/test/ui/async-await/edition-deny-async-fns-2015.stderr @@ -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() {} diff --git a/src/test/ui/const-generics/const-fn-with-const-param.rs b/src/test/ui/const-generics/const-fn-with-const-param.rs index f36bf3875c3..e9e236be556 100644 --- a/src/test/ui/const-generics/const-fn-with-const-param.rs +++ b/src/test/ui/const-generics/const-fn-with-const-param.rs @@ -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 } diff --git a/src/test/ui/const-generics/const-fn-with-const-param.stderr b/src/test/ui/const-generics/const-fn-with-const-param.stderr index 68670963f8e..ca31d695361 100644 --- a/src/test/ui/const-generics/const-fn-with-const-param.stderr +++ b/src/test/ui/const-generics/const-fn-with-const-param.stderr @@ -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 diff --git a/src/test/ui/consts/const-fn-mismatch.rs b/src/test/ui/consts/const-fn-mismatch.rs index 5bd274fe66b..d4cfba6460c 100644 --- a/src/test/ui/consts/const-fn-mismatch.rs +++ b/src/test/ui/consts/const-fn-mismatch.rs @@ -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() {} diff --git a/src/test/ui/consts/const-fn-mismatch.stderr b/src/test/ui/consts/const-fn-mismatch.stderr index 03bb7c6e8d6..0f4ce010fee 100644 --- a/src/test/ui/consts/const-fn-mismatch.stderr +++ b/src/test/ui/consts/const-fn-mismatch.stderr @@ -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 diff --git a/src/test/ui/consts/const-fn-not-in-trait.rs b/src/test/ui/consts/const-fn-not-in-trait.rs index 3975c22c56e..1006d854688 100644 --- a/src/test/ui/consts/const-fn-not-in-trait.rs +++ b/src/test/ui/consts/const-fn-not-in-trait.rs @@ -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() {} diff --git a/src/test/ui/consts/const-fn-not-in-trait.stderr b/src/test/ui/consts/const-fn-not-in-trait.stderr index 6821a6c2bc6..12ce3066037 100644 --- a/src/test/ui/consts/const-fn-not-in-trait.stderr +++ b/src/test/ui/consts/const-fn-not-in-trait.stderr @@ -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 diff --git a/src/test/ui/feature-gates/feature-gate-const_fn.rs b/src/test/ui/feature-gates/feature-gate-const_fn.rs index f46d1dc13d3..691c367aeb8 100644 --- a/src/test/ui/feature-gates/feature-gate-const_fn.rs +++ b/src/test/ui/feature-gates/feature-gate-const_fn.rs @@ -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 {} diff --git a/src/test/ui/feature-gates/feature-gate-const_fn.stderr b/src/test/ui/feature-gates/feature-gate-const_fn.stderr index 6a44f079bfb..843e5630137 100644 --- a/src/test/ui/feature-gates/feature-gate-const_fn.stderr +++ b/src/test/ui/feature-gates/feature-gate-const_fn.stderr @@ -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 diff --git a/src/test/ui/feature-gates/feature-gate-min_const_fn.rs b/src/test/ui/feature-gates/feature-gate-min_const_fn.rs index 669631df2ad..5a01e053ed0 100644 --- a/src/test/ui/feature-gates/feature-gate-min_const_fn.rs +++ b/src/test/ui/feature-gates/feature-gate-min_const_fn.rs @@ -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 {} diff --git a/src/test/ui/feature-gates/feature-gate-min_const_fn.stderr b/src/test/ui/feature-gates/feature-gate-min_const_fn.stderr index 7ab9d748b31..56a882e30fc 100644 --- a/src/test/ui/feature-gates/feature-gate-min_const_fn.stderr +++ b/src/test/ui/feature-gates/feature-gate-min_const_fn.stderr @@ -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 diff --git a/src/test/ui/issues/issue-54954.rs b/src/test/ui/issues/issue-54954.rs index 9e9f92ed9ac..3d6355f5c59 100644 --- a/src/test/ui/issues/issue-54954.rs +++ b/src/test/ui/issues/issue-54954.rs @@ -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>() } } diff --git a/src/test/ui/issues/issue-54954.stderr b/src/test/ui/issues/issue-54954.stderr index d99a5772e8a..4967b82216e 100644 --- a/src/test/ui/issues/issue-54954.stderr +++ b/src/test/ui/issues/issue-54954.stderr @@ -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 diff --git a/src/test/ui/mismatched_types/const-fn-in-trait.stderr b/src/test/ui/mismatched_types/const-fn-in-trait.stderr index ec1f36bf087..817582df27d 100644 --- a/src/test/ui/mismatched_types/const-fn-in-trait.stderr +++ b/src/test/ui/mismatched_types/const-fn-in-trait.stderr @@ -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 diff --git a/src/test/ui/parser/fn-header-semantic-fail.rs b/src/test/ui/parser/fn-header-semantic-fail.rs index a05ea277eec..c327667f4cd 100644 --- a/src/test/ui/parser/fn-header-semantic-fail.rs +++ b/src/test/ui/parser/fn-header-semantic-fail.rs @@ -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` } diff --git a/src/test/ui/parser/fn-header-semantic-fail.stderr b/src/test/ui/parser/fn-header-semantic-fail.stderr index a9e4a183347..1142cee9851 100644 --- a/src/test/ui/parser/fn-header-semantic-fail.stderr +++ b/src/test/ui/parser/fn-header-semantic-fail.stderr @@ -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() {} |
