Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable span properly to fix build failure with span feature disabled #120

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

lo48576
Copy link

@lo48576 lo48576 commented Feb 21, 2025

Summary

  • Fix build error when span feature is disabled (due to --no-default-features (cargo CLI) or default-features = false (Cargo.toml)).
  • Set error span correctly even when span feature is disabled.
    • This fixes v2_parser::failure_tests::bad_child_test failure with span feature disabled.

How to reproduce

  1. Check out kdl-rs repository
    • main branch or the latest release (v6.3.3)
    • Older versions may also be affected, but I didn't check.
  2. Run cargo check --no-default-features
  3. You'll see build error.
$ cargo check --no-default-features
    Checking kdl v6.3.3 (/tmp/kdl2/kdl-rs)
error[E0308]: `if` and `else` have incompatible types
   --> src/v2_parser.rs:558:12
    |
543 |         let entry = if let Some(after_key) = after_key {
    |  ___________________-
544 | |           let (after_eq, value) = (
545 | |               node_space0.take(),
546 | |               cut_err(value.context(cx().lbl("property value"))),
...   |
549 | | /         value.map(|mut value| {
550 | | |             value.name = maybe_ident;
551 | | |             if let Some(fmt) = value.format_mut() {
552 | | |                 fmt.after_key = after_key.into();
...   | |
556 | | |             value
557 | | |         })
    | | |__________- expected because of this
558 | |       } else if let Some(ident) = maybe_ident {
    | |  ____________^
559 | | |         // It was ambiguous, but this ident is actually a value.
560 | | |         Some(KdlEntry {
561 | | |             format: Some(KdlEntryFormat {
...   | |
574 | | |             .flatten()
575 | | |     };
    | | |     ^
    | |_|_____|
    |   |_____`if` and `else` have incompatible types
    |         expected `Option<()>`, found `Option<KdlEntry>`
    |
    = note: expected enum `Option<()>`
               found enum `Option<entry::KdlEntry>`

warning: variable does not need to be mutable
   --> src/v2_parser.rs:751:34
    |
751 |                     ErrMode::Cut(mut pe) => {
    |                                  ----^^
    |                                  |
    |                                  help: remove this `mut`
    |
    = note: `#[warn(unused_mut)]` on by default

For more information about this error, try `rustc --explain E0308`.
warning: `kdl` (lib) generated 1 warning
error: could not compile `kdl` (lib) due to 1 previous error; 1 warning emitted
$

@lo48576 lo48576 changed the title Enable span properly to fix build failure with --no-default-features Enable span properly to fix build failure with span feature disabled Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant