Repository: servo/servo
File: components/config/opts.rs (Rust)

Code before:
            flow_tree: false,
            stacking_context_tree: false,
            scroll_tree: false,
            display_list: false,
            relayout_event: false,
            profile_script_events: false,
            style_statistics: false,
            gc_profile: false,
        };

        for option in options_string.split(',') {
            let option = option.trim();
            match option {
                "help" => config.help = true,
                "display-list" => config.display_list = true,
                "stacking-context-tree" => config.stacking_context_tree = true,
                "flow-tree" => config.flow_tree = true,
                "rule-tree" => config.rule_tree = true,
                "style-tree" => config.style_tree = true,
                "style-stats" => config.style_statistics = true,
                "scroll-tree" => config.scroll_tree = true,
                "gc-profile" => config.gc_profile = true,
                "profile-script-events" => config.profile_script_events = true,
                "relayout-event" => config.relayout_event = true,
                "" => {},
                _ => return Err(format!("Unknown diagnostic option: {}", option)),
            };
        }

        Ok(config)
    }

    /// Print available diagnostic logging options and their descriptions.
    pub fn print_debug_options_usage(app: &str) {
        fn print_option(name: &str, description: &str) {
            println!("\t{:<35} {}", name, description);
        }

        println!(
            "Usage: {} debug option,[options,...]\n\twhere options include\n\nOptions:",
            app
        );
        print_option("help", "Show this help message");
        print_option("style-tree", "Log the style tree after each restyle");
        print_option("rule-tree", "Log the rule tree");
        print_option("flow-tree", "Log the fragment tree after each layout");
        print_option(
            "stacking-context-tree",
            "Log the stacking context tree after each layout",
        );
        print_option("scroll-tree", "Log the scroll tree after each layout");

Review comment (suggestion):
```suggestion
                _ => return Err(format!("Unknown diagnostic option: {option}")),
```

Code after:
        #[cfg(debug_assertions)]
        {
            if let Ok(diagnostics_var) = std::env::var("SERVO_DIAGNOSTICS") {
                if let Err(error) = config.extend_from_string(&diagnostics_var) {
                    eprintln!("Could not parse debug logging option: {error}");
                }
            }
        }

        config
    }

    /// Print available diagnostic logging options and their descriptions.
    fn print_debug_options_usage(app: &str) {
        fn print_option(name: &str, description: &str) {
            println!("\t{:<35} {}", name, description);
        }

        println!(
            "Usage: {} debug option,[options,...]\n\twhere options include\n\nOptions:",
            app
        );
        print_option("help", "Show this help message");
        print_option("style-tree", "Log the style tree after each restyle");
        print_option("rule-tree", "Log the rule tree");
        print_option("flow-tree", "Log the fragment tree after each layout");
        print_option(
            "stacking-context-tree",
            "Log the stacking context tree after each layout",
        );
        print_option("scroll-tree", "Log the scroll tree after each layout");
        print_option("display-list", "Log the display list after each layout");
        print_option("style-stats", "Log style sharing cache statistics");
        print_option("relayout-event", "Log when relayout occurs");
        print_option("profile-script-events", "Log script event processing time");
        print_option("gc-profile", "Log garbage collection statistics");
        println!();

        process::exit(0);
    }

    /// Extend the current configuration with additional options.
    ///
    /// Parses the string and merges any enabled options into the current configuration.
    pub fn extend_from_string(&mut self, option_string: &str) -> Result<(), String> {
        for option in option_string.split(',') {
            let option = option.trim();
            match option {
                "help" => Self::print_debug_options_usage("servo"),
                "display-list" => self.display_list = true,
                "stacking-context-tree" => self.stacking_context_tree = true,