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: (x, "n bar();n"); //!
They are not supposed to be applied to a doc comment I do not think that. Your example would make sense for which I also consider to be wrong, but I am talking about which should insert the attribute conditionally but that is not the point. It might help to illustrate my thought process; We have some kind of documented item: rust /// let example = Example::new() /// .first() /// .build(); /// and each of those is turned into a doc attribute rust"] #[doc = "let example = Example::new()"] #[doc = " .first()"] #[doc = " .build();"] #[doc = " In a later step those attributes would then be concatenated and parsed as markdown or whatever. I want to use this behavior to document items conditionally, depending on which features the crate user has enabled. One way to do this would be to do rust let example = Example::new() .first() .build(); rust let example = Example::new() .first() .second() .build(); but that would blow up the source code with many duplicate lines, where only some minor things were changed. So I thought that it might make more sense to conditionally include a doc comment like this: rust /// let example = Example::new() /// .first() #[cfgattr(feature = "one", doc = " .second()")] /// .build(); /// which would turn into rust"] #[doc = "let example = Example::new()"] #[doc = " .first()"] #[doc = " .second()"] #[doc = " .build();"] #[doc = " or rust"] #[doc = "let example = Example::new()"] #[doc = " .first()"] #[doc = " .build();"] #[doc = " depending on whether the feature is enabled. So the attribute should not be inserted and not applied to the following doc comment. The weird thing is that the manually expanded version is working as expected. rust"] #[doc = "let example = Example::new()"] #[doc = " .first()"] #[cfg_attr(feature = "one", doc = " .second()")] #[doc = " .build();"] #[doc = " but this is very unhandy to work with :/
I was randomly looking at passes for another reason and noticed what is likely the source of this issue.