mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
Don't synthesize host effect params for trait assoc fns marked const
This commit is contained in:
parent
88d69b72b4
commit
ba860344e1
@ -1254,11 +1254,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||
coroutine_kind: Option<CoroutineKind>,
|
||||
) -> (&'hir hir::Generics<'hir>, hir::FnSig<'hir>) {
|
||||
let header = self.lower_fn_header(sig.header);
|
||||
// Don't pass along the user-provided constness of trait associated functions; we don't want to
|
||||
// synthesize a host effect param for them. We reject `const` on them during AST validation.
|
||||
let constness = if kind == FnDeclKind::Inherent { sig.header.constness } else { Const::No };
|
||||
let itctx = ImplTraitContext::Universal;
|
||||
let (generics, decl) =
|
||||
self.lower_generics(generics, sig.header.constness, id, &itctx, |this| {
|
||||
this.lower_fn_decl(&sig.decl, id, sig.span, kind, coroutine_kind)
|
||||
});
|
||||
let (generics, decl) = self.lower_generics(generics, constness, id, &itctx, |this| {
|
||||
this.lower_fn_decl(&sig.decl, id, sig.span, kind, coroutine_kind)
|
||||
});
|
||||
(generics, hir::FnSig { header, decl, span: self.lower_span(sig.span) })
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,13 @@
|
||||
// Regression test for issue #113378.
|
||||
#![feature(const_trait_impl, effects)]
|
||||
|
||||
#[const_trait]
|
||||
trait Trait {
|
||||
const fn fun(); //~ ERROR functions in traits cannot be declared const
|
||||
}
|
||||
|
||||
impl const Trait for () {
|
||||
const fn fun() {} //~ ERROR functions in traits cannot be declared const
|
||||
}
|
||||
|
||||
fn main() {}
|
@ -0,0 +1,15 @@
|
||||
error[E0379]: functions in traits cannot be declared const
|
||||
--> $DIR/trait-fn-const.rs:6:5
|
||||
|
|
||||
LL | const fn fun();
|
||||
| ^^^^^ functions in traits cannot be const
|
||||
|
||||
error[E0379]: functions in traits cannot be declared const
|
||||
--> $DIR/trait-fn-const.rs:10:5
|
||||
|
|
||||
LL | const fn fun() {}
|
||||
| ^^^^^ functions in traits cannot be const
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0379`.
|
Loading…
Reference in New Issue
Block a user