Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ jobs:
- name: Install Rust Problem Matcher
run: echo "::add-matcher::.github/rust.json"

- name: Check without building tests
run: cargo check --features in-rust-tree -p proc-macro-srv-cli

- name: Test
run: cargo test --features in-rust-tree -p proc-macro-srv -p proc-macro-srv-cli -p proc-macro-api -- --quiet

Expand Down
13 changes: 8 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions crates/cfg/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn assert_parse_result(input: &str, expected: CfgExpr) {
pred_ast.syntax(),
DummyTestSpanMap,
DUMMY,
DocCommentDesugarMode::ProcMacro,
DocCommentDesugarMode::Keep,
);
let cfg = CfgExpr::parse(&tt);
assert_eq!(cfg, expected);
Expand All @@ -39,7 +39,7 @@ fn check_dnf(input: &str, expect: Expect) {
pred_ast.syntax(),
DummyTestSpanMap,
DUMMY,
DocCommentDesugarMode::ProcMacro,
DocCommentDesugarMode::Keep,
);
let cfg = CfgExpr::parse(&tt);
let actual = format!("#![cfg({})]", DnfExpr::new(&cfg));
Expand All @@ -57,7 +57,7 @@ fn check_why_inactive(input: &str, opts: &CfgOptions, expect: Expect) {
pred_ast.syntax(),
DummyTestSpanMap,
DUMMY,
DocCommentDesugarMode::ProcMacro,
DocCommentDesugarMode::Keep,
);
let cfg = CfgExpr::parse(&tt);
let dnf = DnfExpr::new(&cfg);
Expand All @@ -77,7 +77,7 @@ fn check_enable_hints(input: &str, opts: &CfgOptions, expected_hints: &[&str]) {
pred_ast.syntax(),
DummyTestSpanMap,
DUMMY,
DocCommentDesugarMode::ProcMacro,
DocCommentDesugarMode::Keep,
);
let cfg = CfgExpr::parse(&tt);
let dnf = DnfExpr::new(&cfg);
Expand Down
3 changes: 3 additions & 0 deletions crates/hir-def/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,6 @@ in-rust-tree = ["hir-expand/in-rust-tree"]

[lints]
workspace = true

[package.metadata.cargo-machete]
ignored = ["ra-ap-rustc_parse_format"]
13 changes: 8 additions & 5 deletions crates/hir-def/src/item_tree/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use hir_expand::{
use intern::{Interned, Symbol, sym};
use syntax::{AstNode, ast};
use syntax_bridge::DocCommentDesugarMode;
use tt::token_to_literal;
use tt::literal_from_str;

use crate::item_tree::lower::Ctx;

Expand Down Expand Up @@ -64,11 +64,13 @@ impl AttrsOrCfg {
ast::Meta::KeyValueMeta(meta) => {
let span = span_map.span_for(path_range);
let input = meta.expr().and_then(|value| {
if let ast::Expr::Literal(value) = value {
Some(Box::new(AttrInput::Literal(token_to_literal(
if let ast::Expr::Literal(value) = value
&& let Ok(lit) = literal_from_str(
value.token().text(),
span_map.span_for(value.syntax().text_range()),
))))
)
{
Some(Box::new(AttrInput::Literal(lit)))
} else {
None
}
Expand All @@ -84,7 +86,8 @@ impl AttrsOrCfg {
.unwrap_or_else(|| meta.syntax().clone()),
span_map,
span,
DocCommentDesugarMode::ProcMacro,
// FIXME: This won't be correct once we support args for macro_rules attributes.
DocCommentDesugarMode::Keep,
);
let input = Some(Box::new(AttrInput::TokenTree(tt)));
(span, input)
Expand Down
8 changes: 3 additions & 5 deletions crates/hir-def/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@

#![cfg_attr(feature = "in-rust-tree", feature(rustc_private))]

#[cfg(feature = "in-rust-tree")]
extern crate rustc_parse_format;

#[cfg(not(feature = "in-rust-tree"))]
extern crate ra_ap_rustc_parse_format as rustc_parse_format;
stdx::rustc_crates! {
extern crate rustc_parse_format or ra_ap_rustc_parse_format;
}

pub extern crate ra_ap_rustc_abi as layout;
pub extern crate ra_ap_rustc_abi as rustc_abi;
Expand Down
81 changes: 81 additions & 0 deletions crates/hir-def/src/macro_expansion_tests/mbe/matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,84 @@ macro_rules! m {
"#]],
);
}

#[test]
fn doc_comment_is_ignored() {
check(
r#"
macro_rules! m {
(
/// hello
) => {};
}

m!();
"#,
expect![[r#"
macro_rules! m {
(
/// hello
) => {};
}


"#]],
);
check(
r#"
macro_rules! m {
() => {
macro_rules! m2 {
(/** hello */) => {}
}
};
}

m!();
m2!();
"#,
expect![[r#"
macro_rules! m {
() => {
macro_rules! m2 {
(/** hello */) => {}
}
};
}

macro_rules !m2 {
(/** hello */
) = > {}
}

"#]],
);
check(
r#"
macro_rules! m {
($($t:tt)*) => {
macro_rules! m2 {
($($t)*) => {}
}
};
}

m!(/** hello */);
m2!();
"#,
expect![[r#"
macro_rules! m {
($($t:tt)*) => {
macro_rules! m2 {
($($t)*) => {}
}
};
}

macro_rules !m2 {
(#[doc = r" hello "]) = > {}
}
/* error: unexpected token in input */
"#]],
);
}
2 changes: 1 addition & 1 deletion crates/hir-def/src/macro_expansion_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ fn pretty_print_macro_expansion(
(T!['{'], T!['}']) => "",
(T![=], _) | (_, T![=]) => " ",
(_, T!['{']) => " ",
(T![;] | T!['{'] | T!['}'], _) => "\n",
(T![;] | T!['{'] | T!['}'] | T![inner_doc_comment] | T![outer_doc_comment], _) => "\n",
(_, T!['}']) => "\n",
_ if (prev_kind.is_any_identifier()
|| prev_kind == LIFETIME_IDENT
Expand Down
10 changes: 7 additions & 3 deletions crates/hir-def/src/macro_expansion_tests/proc_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ mod foo {

#[attr1]
#[attr2] struct S;
#[doc = " Foo"] mod foo {
/// Foo
mod foo {
# ![foo]
# ![doc = "123..."]
# ![attr2]
Expand Down Expand Up @@ -293,8 +294,11 @@ struct S;
#[doc = "doc attr"]
struct S;

#[doc = " doc string \\n with newline"]
#[doc = "\n MultiLines Doc\n MultiLines Doc\n"]
/// doc string \n with newline
/**
MultiLines Doc
MultiLines Doc
*/
#[doc = "doc attr"] struct S;"##]],
);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-expand/src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ impl AttrId {
tt.syntax(),
SpanMap::RealSpanMap(&span_map),
span_map.span_for_range(tt.syntax().text_range()),
DocCommentDesugarMode::ProcMacro,
DocCommentDesugarMode::Keep,
);
let Some((_, _, derive_tts)) =
parse_path_comma_token_tree(db, &tt).nth(derive_index as usize)
Expand Down
14 changes: 7 additions & 7 deletions crates/hir-expand/src/builtin/derive_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ fn parse_adt_from_syntax(
it.syntax(),
tm,
call_site,
DocCommentDesugarMode::ProcMacro,
DocCommentDesugarMode::Keep,
)
}
None => {
Expand All @@ -309,7 +309,7 @@ fn parse_adt_from_syntax(
it.syntax(),
tm,
call_site,
DocCommentDesugarMode::ProcMacro,
DocCommentDesugarMode::Keep,
)
}),
ast::TypeOrConstParam::Const(_) => None,
Expand All @@ -322,7 +322,7 @@ fn parse_adt_from_syntax(
ty.syntax(),
tm,
call_site,
DocCommentDesugarMode::ProcMacro,
DocCommentDesugarMode::Keep,
)
})
.unwrap_or_else(|| {
Expand All @@ -343,7 +343,7 @@ fn parse_adt_from_syntax(
it.syntax(),
tm,
call_site,
DocCommentDesugarMode::ProcMacro,
DocCommentDesugarMode::Keep,
)
})
.collect()
Expand Down Expand Up @@ -380,7 +380,7 @@ fn parse_adt_from_syntax(
it.syntax(),
tm,
call_site,
DocCommentDesugarMode::ProcMacro,
DocCommentDesugarMode::Keep,
)
})
.collect();
Expand Down Expand Up @@ -664,7 +664,7 @@ fn coerce_shared_target(
FxHashMap::default(),
remove,
span,
DocCommentDesugarMode::ProcMacro,
DocCommentDesugarMode::Keep,
|_, _| (true, Vec::new()),
);

Expand Down Expand Up @@ -1464,7 +1464,7 @@ fn coerce_pointee_expand(
self_for_traits.syntax(),
&span_map,
span,
DocCommentDesugarMode::ProcMacro,
DocCommentDesugarMode::Keep,
);
let info = match parse_adt_from_syntax(&adt, &span_map, span) {
Ok(it) => it,
Expand Down
2 changes: 1 addition & 1 deletion crates/hir-expand/src/builtin/fn_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ fn include_expand(
&editioned_file_id.parse(db).syntax_node(),
crate::HirFileId::from(editioned_file_id).span_map(db),
span,
syntax_bridge::DocCommentDesugarMode::ProcMacro,
syntax_bridge::DocCommentDesugarMode::Keep,
))
}

Expand Down
10 changes: 8 additions & 2 deletions crates/hir-expand/src/cfg_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,18 +297,24 @@ pub(crate) fn attr_macro_input_to_token_tree(
span_map: SpanMap<'_>,
span: Span,
is_derive: bool,
is_declarative: bool,
censor_item_tree_attr_ids: &[AttrId],
krate: Crate,
) -> (tt::TopSubtree, SyntaxFixupUndoInfo) {
let fixups = fixup::fixup_syntax(span_map, node, span, DocCommentDesugarMode::ProcMacro);
let doc_comment_mode = if is_declarative {
DocCommentDesugarMode::DesugarMbeInput
} else {
DocCommentDesugarMode::Keep
};
let fixups = fixup::fixup_syntax(span_map, node, span, doc_comment_mode);
(
syntax_bridge::syntax_node_to_token_tree_modified(
node,
span_map,
fixups.append,
fixups.remove,
span,
DocCommentDesugarMode::ProcMacro,
doc_comment_mode,
macro_input_callback(db, is_derive, censor_item_tree_attr_ids, krate, span, span_map),
),
fixups.undo_info,
Expand Down
Loading
Loading