Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 74cef6d

Browse files
committed
Auto merge of rust-lang#16450 - Urhengulas:edition-aware-parser, r=Veykril
internal: Prepare parser interface for editions
2 parents f3c7bd0 + 83370fe commit 74cef6d

File tree

24 files changed

+140
-102
lines changed

24 files changed

+140
-102
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/hir-def/src/macro_expansion_tests/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,11 @@ impl ProcMacroExpander for IdentityWhenValidProcMacroExpander {
316316
_: Span,
317317
_: Span,
318318
) -> Result<Subtree, ProcMacroExpansionError> {
319-
let (parse, _) =
320-
::mbe::token_tree_to_syntax_node(subtree, ::mbe::TopEntryPoint::MacroItems);
319+
let (parse, _) = ::mbe::token_tree_to_syntax_node(
320+
subtree,
321+
::mbe::TopEntryPoint::MacroItems,
322+
span::Edition::CURRENT,
323+
);
321324
if parse.errors().is_empty() {
322325
Ok(subtree.clone())
323326
} else {

crates/hir-def/src/nameres/collector.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,7 @@ impl DefCollector<'_> {
534534
Edition::Edition2015 => name![rust_2015],
535535
Edition::Edition2018 => name![rust_2018],
536536
Edition::Edition2021 => name![rust_2021],
537-
// FIXME: update this when rust_2024 exists
538-
Edition::Edition2024 => name![rust_2021],
537+
Edition::Edition2024 => name![rust_2024],
539538
};
540539

541540
let path_kind = match self.def_map.data.edition {

crates/hir-expand/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ tt.workspace = true
3232
mbe.workspace = true
3333
limit.workspace = true
3434
span.workspace = true
35+
parser.workspace = true
3536

3637
[dev-dependencies]
3738
expect-test = "1.4.0"

crates/hir-expand/src/builtin_derive_macro.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,11 @@ struct BasicAdtInfo {
204204
}
205205

206206
fn parse_adt(tt: &tt::Subtree, call_site: Span) -> Result<BasicAdtInfo, ExpandError> {
207-
let (parsed, tm) = &mbe::token_tree_to_syntax_node(tt, mbe::TopEntryPoint::MacroItems);
207+
let (parsed, tm) = &mbe::token_tree_to_syntax_node(
208+
tt,
209+
mbe::TopEntryPoint::MacroItems,
210+
parser::Edition::CURRENT,
211+
);
208212
let macro_items = ast::MacroItems::cast(parsed.syntax_node())
209213
.ok_or_else(|| ExpandError::other("invalid item definition"))?;
210214
let item = macro_items.items().next().ok_or_else(|| ExpandError::other("no item found"))?;

crates/hir-expand/src/db.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ fn token_tree_to_syntax_node(
676676
ExpandTo::Type => mbe::TopEntryPoint::Type,
677677
ExpandTo::Expr => mbe::TopEntryPoint::Expr,
678678
};
679-
mbe::token_tree_to_syntax_node(tt, entry_point)
679+
mbe::token_tree_to_syntax_node(tt, entry_point, parser::Edition::CURRENT)
680680
}
681681

682682
fn check_tt_count(tt: &tt::Subtree) -> Result<(), ExpandResult<()>> {

crates/hir-expand/src/fixup.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,11 @@ mod tests {
417417
expect.assert_eq(&actual);
418418

419419
// the fixed-up tree should be syntactically valid
420-
let (parse, _) = mbe::token_tree_to_syntax_node(&tt, ::mbe::TopEntryPoint::MacroItems);
420+
let (parse, _) = mbe::token_tree_to_syntax_node(
421+
&tt,
422+
::mbe::TopEntryPoint::MacroItems,
423+
parser::Edition::CURRENT,
424+
);
421425
assert!(
422426
parse.errors().is_empty(),
423427
"parse has syntax errors. parse tree:\n{:#?}",

crates/hir-expand/src/name.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ pub mod known {
303303
rust_2015,
304304
rust_2018,
305305
rust_2021,
306+
rust_2024,
306307
v1,
307308
new_display,
308309
new_debug,

crates/hir-ty/src/method_resolution.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,7 @@ fn iterate_trait_method_candidates(
11571157
{
11581158
// FIXME: this should really be using the edition of the method name's span, in case it
11591159
// comes from a macro
1160-
if db.crate_graph()[krate].edition < Edition::Edition2021 {
1160+
if db.crate_graph()[krate].edition < Edition::CURRENT {
11611161
continue;
11621162
}
11631163
}

crates/mbe/src/expander/matcher.rs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -743,9 +743,11 @@ fn match_meta_var(
743743
) -> ExpandResult<Option<Fragment>> {
744744
let fragment = match kind {
745745
MetaVarKind::Path => {
746-
return input.expect_fragment(parser::PrefixEntryPoint::Path).map(|it| {
747-
it.map(|it| tt::TokenTree::subtree_or_wrap(it, delim_span)).map(Fragment::Path)
748-
});
746+
return input
747+
.expect_fragment(parser::PrefixEntryPoint::Path, parser::Edition::CURRENT)
748+
.map(|it| {
749+
it.map(|it| tt::TokenTree::subtree_or_wrap(it, delim_span)).map(Fragment::Path)
750+
});
749751
}
750752
MetaVarKind::Ty => parser::PrefixEntryPoint::Ty,
751753
MetaVarKind::Pat => parser::PrefixEntryPoint::PatTop,
@@ -770,21 +772,23 @@ fn match_meta_var(
770772
}
771773
_ => {}
772774
};
773-
return input.expect_fragment(parser::PrefixEntryPoint::Expr).map(|tt| {
774-
tt.map(|tt| match tt {
775-
tt::TokenTree::Leaf(leaf) => tt::Subtree {
776-
delimiter: tt::Delimiter::invisible_spanned(*leaf.span()),
777-
token_trees: Box::new([leaf.into()]),
778-
},
779-
tt::TokenTree::Subtree(mut s) => {
780-
if s.delimiter.kind == tt::DelimiterKind::Invisible {
781-
s.delimiter.kind = tt::DelimiterKind::Parenthesis;
775+
return input
776+
.expect_fragment(parser::PrefixEntryPoint::Expr, parser::Edition::CURRENT)
777+
.map(|tt| {
778+
tt.map(|tt| match tt {
779+
tt::TokenTree::Leaf(leaf) => tt::Subtree {
780+
delimiter: tt::Delimiter::invisible_spanned(*leaf.span()),
781+
token_trees: Box::new([leaf.into()]),
782+
},
783+
tt::TokenTree::Subtree(mut s) => {
784+
if s.delimiter.kind == tt::DelimiterKind::Invisible {
785+
s.delimiter.kind = tt::DelimiterKind::Parenthesis;
786+
}
787+
s
782788
}
783-
s
784-
}
785-
})
786-
.map(Fragment::Expr)
787-
});
789+
})
790+
.map(Fragment::Expr)
791+
});
788792
}
789793
MetaVarKind::Ident | MetaVarKind::Tt | MetaVarKind::Lifetime | MetaVarKind::Literal => {
790794
let tt_result = match kind {
@@ -819,7 +823,7 @@ fn match_meta_var(
819823
return tt_result.map(|it| Some(Fragment::Tokens(it))).into();
820824
}
821825
};
822-
input.expect_fragment(fragment).map(|it| it.map(Fragment::Tokens))
826+
input.expect_fragment(fragment, parser::Edition::CURRENT).map(|it| it.map(Fragment::Tokens))
823827
}
824828

825829
fn collect_vars(collector_fun: &mut impl FnMut(SmolStr), pattern: &MetaTemplate) {

0 commit comments

Comments
 (0)