Skip to content

Commit 5890265

Browse files
committed
WIP 75 - Silence compiler warning, move compat test suite file
Silence compiler warning: macro-expanded `macro_export` macros from the current crate cannot be referred to by absolute paths rust-lang/rust#52234 By adding this to lib.rs: This is a warning for a future error in the compiler. It does not allow $crate to be used by this macro as_str_slice_test_case! if the macro is used inside the crate, and by other crates. One solution is just to require anyone who uses this macro to import the appropriate symbols, kind of like what you have to do with use `std::fmt::Write as _` before calling write! Also, move the compat test suite file to the top level parser_ng folder instead of being located in the sub-folder "as_str_slice_core". And rename "core.rs" to "as_str_slice_core.rs" since "core" is used else where in the code base to refer to the top-level "core" module.
1 parent 55d5d9e commit 5890265

File tree

6 files changed

+43
-12
lines changed

6 files changed

+43
-12
lines changed

todo.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,15 +245,15 @@
245245
- [x] update `md_parser_syn_hi_impl.rs` to use this. provide a new `bool` flag that allows the new
246246
`_ng` parser active instead of the old one (keep them all in the code for now). there is 1
247247
function that is shared between the two, so move that to `_ng` for smart code block tests.
248-
- [ ] add a new test case in `parse_heading_ng()` test cases, and use the markdown constant from the
248+
- [x] add a new test case in `parse_heading_ng()` test cases, and use the markdown constant from the
249249
demo examples for the editor, which currently shows up in 2 places (consolidate them into
250250
one):
251251
- `get_real_world_content()` in
252252
`tui/src/tui/md_parser_ng/as_str_slice/compatibility_test_suite.rs`
253253
- `get_default_content()` in `tui/examples/tui_apps/ex_editor/state.rs`
254-
- [ ] make quality and compatibility improvments to `md_parse_ng` now that it is attached to the
255-
test examples. there is an extra new line at the bottom of the editor for some reason that
256-
does not show up with the legacy parser.
254+
- [x] make quality and compatibility improvments to `md_parse_ng` now that it is attached to the
255+
test examples. verify that extra line at the bottom of editor example shows up both for legacy
256+
and NG parser
257257
- [ ] use `cargo bench` in `compatibility_test_suite.rs` to compare the relative performance of both
258258
legacy and NG parsers
259259
- [ ] would it be possible to cache the AST returned by `parse_markdown_ng()`? is this a tree

tui/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,8 @@
10101010
#![warn(clippy::unwrap_in_result)]
10111011
#![warn(rust_2018_idioms)]
10121012
#![allow(clippy::literal_string_with_formatting_args)]
1013+
// Disable the following to allow as_str_slice_test_case! to continue working.
1014+
#![allow(macro_expanded_macro_exports_accessed_by_absolute_paths)]
10131015

10141016
// Attach.
10151017
pub mod core;

tui/src/tui/md_parser_ng/as_str_slice/core.rs renamed to tui/src/tui/md_parser_ng/as_str_slice/as_str_slice_core.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,21 @@ where
337337
/// as_str_slice_test_case!(slice, "", "foo", "");
338338
/// assert_eq!(slice.to_inline_string(), "\nfoo\n\n");
339339
/// ```
340+
///
341+
/// # Compiler warning about `macro_export` macros from the current crate cannot be referred to by absolute paths
342+
///
343+
/// This is a warning for a future error in the compiler. It does not allow
344+
/// `$crate` to be used by this macro `as_str_slice_test_case!` if the macro is
345+
/// used inside the crate, and by other crates.
346+
///
347+
/// - More info: <https://github.com/rust-lang/rust/pull/52234>
348+
/// - Workaround for now: It is currently suppressed by adding this to `lib.rs`:
349+
/// `#![allow(macro_expanded_macro_exports_accessed_by_absolute_paths)]`
350+
///
351+
/// One solution is just to require anyone who uses this macro to import the appropriate
352+
/// symbols, kind of like what you have to do with use `std::fmt::Write as _` before
353+
/// calling `write!`. Also, `::r3bl_tui` can't be used, and neither is `r3bl_tui::` to
354+
/// import the `GCString` and `AsStrSlice` structs.
340355
#[macro_export]
341356
macro_rules! as_str_slice_test_case {
342357
($var_name:ident, $($string_expr:expr),+ $(,)?) => {
@@ -353,7 +368,7 @@ macro_rules! as_str_slice_test_case {
353368

354369
#[cfg(test)]
355370
mod tests_as_str_slice_test_case {
356-
use crate::{as_str_slice_test_case, assert_eq2};
371+
use crate::assert_eq2;
357372

358373
#[test]
359374
fn test_as_str_slice_creation() {
@@ -481,9 +496,10 @@ impl CharLengthExt for &str {
481496
/// Unit tests for the [crate::AsStrSlice] struct and its methods.
482497
#[cfg(test)]
483498
mod tests_as_str_slice_basic_functionality {
499+
use as_str_slice_test_case;
484500
use nom::Input;
485501

486-
use crate::{as_str_slice_test_case, assert_eq2, idx, len, AsStrSlice};
502+
use crate::{assert_eq2, idx, len, AsStrSlice};
487503

488504
#[test]
489505
fn test_gc_string_slice_basic_functionality() {

tui/src/tui/md_parser_ng/as_str_slice/mod.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,29 @@
8989
//! documentation on the [`AsStrSlice`] struct.**
9090
9191
// Attach.
92+
#[rustfmt::skip]
9293
pub mod compatibility;
93-
#[cfg(test)]
94-
pub mod compatibility_test_suite;
95-
pub mod core;
94+
#[rustfmt::skip]
95+
pub mod as_str_slice_core;
96+
#[rustfmt::skip]
9697
pub mod iterators;
98+
#[rustfmt::skip]
9799
pub mod operations;
100+
#[rustfmt::skip]
98101
pub mod position;
102+
#[rustfmt::skip]
99103
pub mod traits;
100104

101105
// Re-export.
102-
pub use core::*;
103-
106+
#[rustfmt::skip]
107+
pub use as_str_slice_core::*;
108+
#[rustfmt::skip]
104109
pub use compatibility::*;
110+
#[rustfmt::skip]
105111
pub use iterators::*;
112+
#[rustfmt::skip]
106113
pub use operations::*;
114+
#[rustfmt::skip]
107115
pub use position::*;
116+
#[rustfmt::skip]
108117
pub use traits::*;

tui/src/tui/md_parser_ng/as_str_slice/compatibility_test_suite.rs renamed to tui/src/tui/md_parser_ng/compatibility_test_suite.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,4 +514,4 @@ mod tests_parse_markdown_compatibility {
514514
// Test with H1 to see if it's specific to H2
515515
test_compatibility_helper("emoji_h1_with_list", "# Heading 😀\n\n1. List item");
516516
}
517-
}
517+
}

tui/src/tui/md_parser_ng/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ pub use fragment_ng::*;
102102
pub use parse_markdown_ng::*;
103103
pub use standard_ng::*;
104104

105+
// Attach test sources.
106+
#[cfg(test)]
107+
pub mod compatibility_test_suite;
108+
105109
// Export for tests and examples.
106110
/// Returns the real-world markdown content from the ex_editor example.
107111
/// This content includes emojis in headings, nested lists, code blocks, metadata,

0 commit comments

Comments
 (0)