E0379: Make diagnostic more precise
This commit is contained in:
parent
8f546aa495
commit
ae8e401c9f
13 changed files with 31 additions and 20 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue