Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 234ba91

Browse files
committedApr 17, 2025·
Add const effect syntax to the parser for all function headers
1 parent b991728 commit 234ba91

File tree

130 files changed

+919
-366
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+919
-366
lines changed
 

‎compiler/rustc_ast/src/ast.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3021,7 +3021,7 @@ impl BoundPolarity {
30213021
}
30223022
}
30233023

3024-
/// The constness of a trait bound.
3024+
/// The constness of a trait bound or function.
30253025
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, Hash)]
30263026
#[derive(HashStable_Generic)]
30273027
pub enum BoundConstness {
@@ -3473,7 +3473,7 @@ pub struct FnHeader {
34733473
/// Whether this is `async`, `gen`, or nothing.
34743474
pub coroutine_kind: Option<CoroutineKind>,
34753475
/// The `const` keyword, if any
3476-
pub constness: Const,
3476+
pub constness: BoundConstness,
34773477
/// The `extern` keyword and corresponding ABI string, if any.
34783478
pub ext: Extern,
34793479
}
@@ -3484,7 +3484,7 @@ impl FnHeader {
34843484
let Self { safety, coroutine_kind, constness, ext } = self;
34853485
matches!(safety, Safety::Unsafe(_))
34863486
|| coroutine_kind.is_some()
3487-
|| matches!(constness, Const::Yes(_))
3487+
|| !matches!(constness, BoundConstness::Never)
34883488
|| !matches!(ext, Extern::None)
34893489
}
34903490
}
@@ -3494,7 +3494,7 @@ impl Default for FnHeader {
34943494
FnHeader {
34953495
safety: Safety::Default,
34963496
coroutine_kind: None,
3497-
constness: Const::No,
3497+
constness: BoundConstness::Never,
34983498
ext: Extern::None,
34993499
}
35003500
}

‎compiler/rustc_ast/src/mut_visit.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,14 @@ fn visit_constness<T: MutVisitor>(vis: &mut T, constness: &mut Const) {
902902
}
903903
}
904904

905+
// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
906+
fn walk_bound_constness<T: MutVisitor>(vis: &mut T, constness: &mut BoundConstness) {
907+
match constness {
908+
BoundConstness::Never => {}
909+
BoundConstness::Always(span) | BoundConstness::Maybe(span) => vis.visit_span(span),
910+
}
911+
}
912+
905913
fn walk_closure_binder<T: MutVisitor>(vis: &mut T, binder: &mut ClosureBinder) {
906914
match binder {
907915
ClosureBinder::NotPresent => {}
@@ -1131,10 +1139,7 @@ fn walk_poly_trait_ref<T: MutVisitor>(vis: &mut T, p: &mut PolyTraitRef) {
11311139

11321140
fn walk_modifiers<V: MutVisitor>(vis: &mut V, m: &mut TraitBoundModifiers) {
11331141
let TraitBoundModifiers { constness, asyncness, polarity } = m;
1134-
match constness {
1135-
BoundConstness::Never => {}
1136-
BoundConstness::Always(span) | BoundConstness::Maybe(span) => vis.visit_span(span),
1137-
}
1142+
walk_bound_constness(vis, constness);
11381143
match asyncness {
11391144
BoundAsyncness::Normal => {}
11401145
BoundAsyncness::Async(span) => vis.visit_span(span),
@@ -1443,7 +1448,7 @@ fn walk_const_item<T: MutVisitor>(vis: &mut T, item: &mut ConstItem) {
14431448

14441449
fn walk_fn_header<T: MutVisitor>(vis: &mut T, header: &mut FnHeader) {
14451450
let FnHeader { safety, coroutine_kind, constness, ext: _ } = header;
1446-
visit_constness(vis, constness);
1451+
walk_bound_constness(vis, constness);
14471452
coroutine_kind.as_mut().map(|coroutine_kind| vis.visit_coroutine_kind(coroutine_kind));
14481453
visit_safety(vis, safety);
14491454
}

0 commit comments

Comments
 (0)
Please sign in to comment.