@@ -197,6 +197,7 @@ fn make_test_crate_attrs() {
197
197
assert_eq!(2+2, 4);" ;
198
198
let expected = "#![allow(unused)]
199
199
#![feature(sick_rad)]
200
+
200
201
fn main() {
201
202
assert_eq!(2+2, 4);
202
203
}"
@@ -228,8 +229,8 @@ fn make_test_fake_main() {
228
229
let input = "//Ceci n'est pas une `fn main`
229
230
assert_eq!(2+2, 4);" ;
230
231
let expected = "#![allow(unused)]
231
- //Ceci n'est pas une `fn main`
232
232
fn main() {
233
+ //Ceci n'est pas une `fn main`
233
234
assert_eq!(2+2, 4);
234
235
}"
235
236
. to_string ( ) ;
@@ -259,8 +260,8 @@ fn make_test_issues_21299() {
259
260
assert_eq!(2+2, 4);" ;
260
261
261
262
let expected = "#![allow(unused)]
262
- // fn main
263
263
fn main() {
264
+ // fn main
264
265
assert_eq!(2+2, 4);
265
266
}"
266
267
. to_string ( ) ;
@@ -401,3 +402,76 @@ fn check_split_args() {
401
402
compare ( "a\n \t \r b" , & [ "a" , "b" ] ) ;
402
403
compare ( "a\n \t 1 \r b" , & [ "a" , "1" , "b" ] ) ;
403
404
}
405
+
406
+ #[ test]
407
+ fn comment_in_attrs ( ) {
408
+ // If there is an inline code comment after attributes, we need to ensure that
409
+ // a backline will be added to prevent generating code "inside" it (and thus generating)
410
+ // invalid code.
411
+ let opts = default_global_opts ( "" ) ;
412
+ let input = "\
413
+ #![feature(rustdoc_internals)]
414
+ #![allow(internal_features)]
415
+ #![doc(rust_logo)]
416
+ //! This crate has the Rust(tm) branding on it." ;
417
+ let expected = "\
418
+ #![allow(unused)]
419
+ #![feature(rustdoc_internals)]
420
+ #![allow(internal_features)]
421
+ #![doc(rust_logo)]
422
+ //! This crate has the Rust(tm) branding on it.
423
+ fn main() {
424
+
425
+ }"
426
+ . to_string ( ) ;
427
+ let ( output, len) = make_test ( input, None , false , & opts, None ) ;
428
+ assert_eq ! ( ( output, len) , ( expected, 2 ) ) ;
429
+
430
+ // And same, if there is a `main` function provided by the user, we ensure that it's
431
+ // correctly separated.
432
+ let input = "\
433
+ #![feature(rustdoc_internals)]
434
+ #![allow(internal_features)]
435
+ #![doc(rust_logo)]
436
+ //! This crate has the Rust(tm) branding on it.
437
+ fn main() {}" ;
438
+ let expected = "\
439
+ #![allow(unused)]
440
+ #![feature(rustdoc_internals)]
441
+ #![allow(internal_features)]
442
+ #![doc(rust_logo)]
443
+ //! This crate has the Rust(tm) branding on it.
444
+
445
+ fn main() {}"
446
+ . to_string ( ) ;
447
+ let ( output, len) = make_test ( input, None , false , & opts, None ) ;
448
+ assert_eq ! ( ( output, len) , ( expected, 1 ) ) ;
449
+ }
450
+
451
+ // This test ensures that the only attributes taken into account when we switch between
452
+ // "crate level" content and the rest doesn't include inner attributes span, as it would
453
+ // include part of the item and generate broken code.
454
+ #[ test]
455
+ fn inner_attributes ( ) {
456
+ let opts = default_global_opts ( "" ) ;
457
+ let input = r#"
458
+ //! A doc comment that applies to the implicit anonymous module of this crate
459
+
460
+ pub mod outer_module {
461
+ //!! - Still an inner line doc (but with a bang at the beginning)
462
+ }
463
+ "# ;
464
+ let expected = "#![allow(unused)]
465
+
466
+ //! A doc comment that applies to the implicit anonymous module of this crate
467
+
468
+
469
+ fn main() {
470
+ pub mod outer_module {
471
+ //!! - Still an inner line doc (but with a bang at the beginning)
472
+ }
473
+ }"
474
+ . to_string ( ) ;
475
+ let ( output, len) = make_test ( input, None , false , & opts, None ) ;
476
+ assert_eq ! ( ( output, len) , ( expected, 2 ) ) ;
477
+ }
0 commit comments