Code change:
use super::*; <ins> use rustc_span::source_map::DUMMY_SP; fn create_doc_fragment(s: &str) -> Vec<DocFragment> { vec![DocFragment { line: 0, span: DUMMY_SP, parent_module: None, doc: s.to_string(), kind: DocFragmentKind::SugaredDoc, }] } #[track_caller] fn run_test(input: &str, expected: &str) { let mut s = create_doc_fragment(input); unindent_fragments(&mut s); assert_eq!(s[0].doc, expected); } </ins> #[test] fn should_unindent() { <del> let s = "    line1n    line2".to_string(); let r = unindent(&s); assert_eq!(r, "line1nline2"); </del> <ins> run_test("    line1n    line2", "line1nline2"); </ins> } #[test] fn should_unindent_multiple_paragraphs() { <del> let s = "    line1nn    line2".to_string(); let r = unindent(&s); assert_eq!(r, "line1nnline2"); </del> <ins> run_test("    line1nn    line2", "line1nnline2"); </ins> } #[test] fn should_leave_multiple_indent_levels() { // Line 2 is indented another level beyond the // base indentation and should be preserved <del> let s = "    line1nn        line2".to_string(); let r = unindent(&s); assert_eq!(r, "line1nn    line2"); </del> <ins> run_test("    line1nn        line2", "line1nn    line2"); </ins> } #[test] fn should_ignore_first_line_indent() { <del> // The first line of the first paragraph may not be indented as // far due to the way the doc string was written: // // #[doc = "Start way over here //          and continue here"] let s = "line1n    line2".to_string(); let r = unindent(&s); assert_eq!(r, "line1nline2"); </del> <ins> run_test("line1n    line2", "line1n    line2"); </ins> } #[test] fn should_not_ignore_first_line_indent_in_a_single_line_para() { <del> let s = "line1nn    line2".to_string(); let r = unindent(&s); assert_eq!(r, "line1nn    line2"); </del> <ins> run_test("line1nn    line2", "line1nn    line2"); </ins> } #[test] fn should_unindent_tabs() { <del> let s = "tline1ntline2".to_string(); let r = unindent(&s); assert_eq!(r, "line1nline2"); </del> <ins> run_test("tline1ntline2", "line1nline2"); </ins> } #[test] fn should_trim_mixed_indentation() { <del> let s = "t    line1nt    line2".to_string(); let r = unindent(&s); assert_eq!(r, "line1nline2"); let s = "    tline1n    tline2".to_string(); let r = unindent(&s); assert_eq!(r, "line1nline2"); </del> <ins> run_test("t    line1nt    line2", "line1nline2"); run_test("    tline1n    tline2", "line1nline2"); </ins> } #[test] fn should_not_trim() { <del> let s = "t    line1  nt    line2".to_string(); let r = unindent(&s); assert_eq!(r, "line1  nline2"); let s = "    tline1  n    tline2".to_string(); let r = unindent(&s); assert_eq!(r, "line1  nline2"); </del> <ins> run_test("t    line1  nt    line2", "line1  nline2"); run_test("    tline1  n    tline2", "line1  nline2"); </ins> }

Related discussion:
text: There are two relevant passes: runs second and removes leading columns of whitespace from the docs. This runs on a single "doc fragment" at a time, because of merging that normally means the entire documentation string, but since sugared and raw docs aren't merged they remain as separate fragments and use their own widths of leading whitespace to strip.
That also matches up with first released in 1.24 which introduced this distinction between doc kinds in order to fix , which IMO was user error in not matching the indent depth.