mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
E0379: Make diagnostic more precise
This commit is contained in:
parent
8f546aa495
commit
ae8e401c9f
@ -233,8 +233,14 @@ ast_passes_tilde_const_disallowed = `~const` is not allowed here
|
||||
.item = this item cannot have `~const` trait bounds
|
||||
|
||||
ast_passes_trait_fn_const =
|
||||
functions in traits cannot be declared const
|
||||
.label = functions in traits cannot be const
|
||||
functions in {$in_impl ->
|
||||
[true] trait impls
|
||||
*[false] traits
|
||||
} cannot be declared const
|
||||
.label = functions in {$in_impl ->
|
||||
[true] trait impls
|
||||
*[false] traits
|
||||
} cannot be const
|
||||
|
||||
ast_passes_trait_object_single_bound = only a single explicit lifetime bound is permitted
|
||||
|
||||
|
@ -293,7 +293,7 @@ impl<'a> AstValidator<'a> {
|
||||
|
||||
fn check_trait_fn_not_const(&self, constness: Const) {
|
||||
if let Const::Yes(span) = constness {
|
||||
self.dcx().emit_err(errors::TraitFnConst { span });
|
||||
self.dcx().emit_err(errors::TraitFnConst { span, in_impl: self.in_trait_impl });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,6 +49,7 @@ pub struct TraitFnConst {
|
||||
#[primary_span]
|
||||
#[label]
|
||||
pub span: Span,
|
||||
pub in_impl: bool,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
|
@ -6,6 +6,10 @@ Erroneous code example:
|
||||
trait Foo {
|
||||
const fn bar() -> u32; // error!
|
||||
}
|
||||
|
||||
impl Foo for () {
|
||||
const fn bar() -> u32 { 0 } // error!
|
||||
}
|
||||
```
|
||||
|
||||
Trait methods cannot be declared `const` by design. For more information, see
|
||||
|
@ -9,7 +9,7 @@ trait Foo {
|
||||
|
||||
impl Foo for u32 {
|
||||
const fn f() -> u32 {
|
||||
//~^ ERROR functions in traits cannot be declared const
|
||||
//~^ ERROR functions in trait impls cannot be declared const
|
||||
22
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
error[E0379]: functions in traits cannot be declared const
|
||||
error[E0379]: functions in trait impls cannot be declared const
|
||||
--> $DIR/const-fn-mismatch.rs:11:5
|
||||
|
|
||||
LL | const fn f() -> u32 {
|
||||
| ^^^^^ functions in traits cannot be const
|
||||
| ^^^^^ functions in trait impls cannot be const
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
|
@ -8,7 +8,7 @@ trait Foo {
|
||||
}
|
||||
|
||||
impl Foo for u32 {
|
||||
const fn foo() -> u32 { 0 } //~ ERROR functions in traits cannot be declared const
|
||||
const fn foo() -> u32 { 0 } //~ ERROR functions in trait impls cannot be declared const
|
||||
}
|
||||
|
||||
trait Bar {}
|
||||
|
@ -10,11 +10,11 @@ error[E0379]: functions in traits cannot be declared const
|
||||
LL | const fn bar() -> u32 { 0 }
|
||||
| ^^^^^ functions in traits cannot be const
|
||||
|
||||
error[E0379]: functions in traits cannot be declared const
|
||||
error[E0379]: functions in trait impls cannot be declared const
|
||||
--> $DIR/feature-gate-min_const_fn.rs:11:5
|
||||
|
|
||||
LL | const fn foo() -> u32 { 0 }
|
||||
| ^^^^^ functions in traits cannot be const
|
||||
| ^^^^^ functions in trait impls cannot be const
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
@ -4,11 +4,11 @@ error[E0379]: functions in traits cannot be declared const
|
||||
LL | const fn g();
|
||||
| ^^^^^ functions in traits cannot be const
|
||||
|
||||
error[E0379]: functions in traits cannot be declared const
|
||||
error[E0379]: functions in trait impls cannot be declared const
|
||||
--> $DIR/const-fn-in-trait.rs:7:5
|
||||
|
|
||||
LL | const fn f() -> u32 { 22 }
|
||||
| ^^^^^ functions in traits cannot be const
|
||||
| ^^^^^ functions in trait impls cannot be const
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
@ -26,10 +26,10 @@ fn main() {
|
||||
impl X for Y {
|
||||
async fn ft1() {} // OK.
|
||||
unsafe fn ft2() {} // OK.
|
||||
const fn ft3() {} //~ ERROR functions in traits cannot be declared const
|
||||
const fn ft3() {} //~ ERROR functions in trait impls cannot be declared const
|
||||
extern "C" fn ft4() {}
|
||||
const async unsafe extern "C" fn ft5() {}
|
||||
//~^ ERROR functions in traits cannot be declared const
|
||||
//~^ ERROR functions in trait impls cannot be declared const
|
||||
//~| ERROR functions cannot be both `const` and `async`
|
||||
}
|
||||
|
||||
|
@ -28,17 +28,17 @@ LL | const async unsafe extern "C" fn ft5();
|
||||
| | `async` because of this
|
||||
| `const` because of this
|
||||
|
||||
error[E0379]: functions in traits cannot be declared const
|
||||
error[E0379]: functions in trait impls cannot be declared const
|
||||
--> $DIR/fn-header-semantic-fail.rs:29:9
|
||||
|
|
||||
LL | const fn ft3() {}
|
||||
| ^^^^^ functions in traits cannot be const
|
||||
| ^^^^^ functions in trait impls cannot be const
|
||||
|
||||
error[E0379]: functions in traits cannot be declared const
|
||||
error[E0379]: functions in trait impls cannot be declared const
|
||||
--> $DIR/fn-header-semantic-fail.rs:31:9
|
||||
|
|
||||
LL | const async unsafe extern "C" fn ft5() {}
|
||||
| ^^^^^ functions in traits cannot be const
|
||||
| ^^^^^ functions in trait impls cannot be const
|
||||
|
||||
error: functions cannot be both `const` and `async`
|
||||
--> $DIR/fn-header-semantic-fail.rs:31:9
|
||||
|
@ -7,7 +7,7 @@ trait Trait {
|
||||
}
|
||||
|
||||
impl const Trait for () {
|
||||
const fn fun() {} //~ ERROR functions in traits cannot be declared const
|
||||
const fn fun() {} //~ ERROR functions in trait impls cannot be declared const
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
@ -4,11 +4,11 @@ error[E0379]: functions in traits cannot be declared const
|
||||
LL | const fn fun();
|
||||
| ^^^^^ functions in traits cannot be const
|
||||
|
||||
error[E0379]: functions in traits cannot be declared const
|
||||
error[E0379]: functions in trait impls cannot be declared const
|
||||
--> $DIR/trait-fn-const.rs:10:5
|
||||
|
|
||||
LL | const fn fun() {}
|
||||
| ^^^^^ functions in traits cannot be const
|
||||
| ^^^^^ functions in trait impls cannot be const
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user