@@ -18,17 +18,7 @@ use rustc_stable_hash::{FromStableHash, SipHasher128Hash, StableSipHasher128};
1818use serde:: Deserialize ;
1919
2020/// Trait for mdtest configuration types.
21- ///
22- /// This allows the parser to be generic over different configuration types
23- /// (e.g. ty's `MarkdownTestConfig` vs ruff's `Options`) while still being
24- /// able to enforce constraints during parsing.
25- pub trait MdtestConfig : Clone + Default + for < ' de > Deserialize < ' de > {
26- /// Whether this configuration specifies external dependencies.
27- ///
28- /// Used by the parser to enforce that at most one section per file
29- /// specifies dependencies.
30- fn has_dependencies ( & self ) -> bool ;
31- }
21+ pub trait MdtestConfig : Clone + Default + for < ' de > Deserialize < ' de > { }
3222
3323/// Parse the Markdown `source` as a test suite with given `title`.
3424pub fn parse < ' s , C : MdtestConfig > (
@@ -517,10 +507,6 @@ struct Parser<'s, C> {
517507
518508 /// Whether or not the current section has a config block.
519509 current_section_has_config : bool ,
520-
521- /// Whether or not any section in the file has external dependencies.
522- /// Only one section per file is allowed to have dependencies (for lockfile support).
523- file_has_dependencies : bool ,
524510}
525511
526512impl < ' s , C : MdtestConfig > Parser < ' s , C > {
@@ -543,7 +529,6 @@ impl<'s, C: MdtestConfig> Parser<'s, C> {
543529 stack : SectionStack :: new ( root_section_id) ,
544530 current_section_files : IndexMap :: default ( ) ,
545531 current_section_has_config : false ,
546- file_has_dependencies : false ,
547532 }
548533 }
549534
@@ -927,16 +912,6 @@ impl<'s, C: MdtestConfig> Parser<'s, C> {
927912
928913 let config: C = toml:: from_str ( code) . context ( "Error while parsing Markdown TOML config" ) ?;
929914
930- if config. has_dependencies ( ) {
931- if self . file_has_dependencies {
932- bail ! (
933- "Multiple sections with `[project]` dependencies in the same file are not allowed. \
934- External dependencies must be specified in a single top-level configuration block."
935- ) ;
936- }
937- self . file_has_dependencies = true ;
938- }
939-
940915 let current_section = & mut self . sections [ self . stack . top ( ) ] ;
941916 current_section. config = config;
942917
@@ -1105,14 +1080,18 @@ mod tests {
11051080 /// ```
11061081 #[ derive( Clone , Debug , Default , Deserialize ) ]
11071082 #[ serde( rename_all = "kebab-case" , deny_unknown_fields) ]
1083+ #[ expect(
1084+ unused,
1085+ reason = "These fields are only used for testing deserialization and never read"
1086+ ) ]
11081087 struct TestConfig {
11091088 project : Option < Project > ,
1110- #[ expect( unused) ]
11111089 environment : Option < Environment > ,
11121090 }
11131091
11141092 #[ derive( Clone , Debug , Default , Deserialize ) ]
11151093 struct Project {
1094+ #[ expect( unused) ]
11161095 dependencies : Option < Vec < String > > ,
11171096 }
11181097
@@ -1122,13 +1101,7 @@ mod tests {
11221101 typeshed : Option < String > ,
11231102 }
11241103
1125- impl super :: MdtestConfig for TestConfig {
1126- fn has_dependencies ( & self ) -> bool {
1127- self . project
1128- . as_ref ( )
1129- . is_some_and ( |project| project. dependencies . is_some ( ) )
1130- }
1131- }
1104+ impl super :: MdtestConfig for TestConfig { }
11321105
11331106 fn parse < ' s > (
11341107 title : & ' s str ,
@@ -2257,39 +2230,4 @@ mod tests {
22572230 let parse_result = parse ( "file.md" , & source) ;
22582231 assert ! ( parse_result. is_ok( ) , "{parse_result:?}" ) ;
22592232 }
2260-
2261- #[ test]
2262- fn multiple_sections_with_dependencies_not_allowed ( ) {
2263- let source = dedent (
2264- r#"
2265- # First section
2266-
2267- ```toml
2268- [project]
2269- dependencies = ["pydantic==2.12.2"]
2270- ```
2271-
2272- ```py
2273- x = 1
2274- ```
2275-
2276- # Second section
2277-
2278- ```toml
2279- [project]
2280- dependencies = ["numpy==2.0.0"]
2281- ```
2282-
2283- ```py
2284- y = 2
2285- ```
2286- "# ,
2287- ) ;
2288- let err = parse ( "file.md" , & source) . expect_err ( "Should fail to parse" ) ;
2289- assert_eq ! (
2290- err. to_string( ) ,
2291- "Multiple sections with `[project]` dependencies in the same file are not allowed. \
2292- External dependencies must be specified in a single top-level configuration block."
2293- ) ;
2294- }
22952233}
0 commit comments