@@ -2587,3 +2587,115 @@ LL | let s: &str = include_bytes!("file.txt"); //~ ERROR mismatched types
2587
2587
let renderer = Renderer :: plain ( ) . anonymized_line_numbers ( true ) ;
2588
2588
assert_data_eq ! ( renderer. render( input) , expected) ;
2589
2589
}
2590
+
2591
+ #[ test]
2592
+ fn id_on_title ( ) {
2593
+ let source = r#"// Regression test for issue #114529
2594
+ // Tests that we do not ICE during const eval for a
2595
+ // break-with-value in contexts where it is illegal
2596
+
2597
+ #[allow(while_true)]
2598
+ fn main() {
2599
+ [(); {
2600
+ while true {
2601
+ break 9; //~ ERROR `break` with value from a `while` loop
2602
+ };
2603
+ 51
2604
+ }];
2605
+
2606
+ [(); {
2607
+ while let Some(v) = Some(9) {
2608
+ break v; //~ ERROR `break` with value from a `while` loop
2609
+ };
2610
+ 51
2611
+ }];
2612
+
2613
+ while true {
2614
+ break (|| { //~ ERROR `break` with value from a `while` loop
2615
+ let local = 9;
2616
+ });
2617
+ }
2618
+ }
2619
+ "# ;
2620
+ let input = Level :: ERROR
2621
+ . header ( "`break` with value from a `while` loop" )
2622
+ . id ( "E0571" )
2623
+ . group (
2624
+ Group :: new ( ) . element (
2625
+ Snippet :: source ( source)
2626
+ . line_start ( 1 )
2627
+ . path ( "$DIR/issue-114529-illegal-break-with-value.rs" )
2628
+ . fold ( true )
2629
+ . annotation (
2630
+ AnnotationKind :: Primary
2631
+ . span ( 483 ..581 )
2632
+ . label ( "can only break with a value inside `loop` or breakable block" ) ,
2633
+ )
2634
+ . annotation (
2635
+ AnnotationKind :: Context
2636
+ . span ( 462 ..472 )
2637
+ . label ( "you can't `break` with a value in a `while` loop" ) ,
2638
+ ) ,
2639
+ ) ,
2640
+ )
2641
+ . group (
2642
+ Group :: new ( )
2643
+ . element (
2644
+ Level :: HELP
2645
+ . text ( Some ( "suggestion[S0123]" ) )
2646
+ . title ( "use `break` on its own without a value inside this `while` loop" ) ,
2647
+ )
2648
+ . element (
2649
+ Snippet :: source ( source)
2650
+ . line_start ( 1 )
2651
+ . path ( "$DIR/issue-114529-illegal-break-with-value.rs" )
2652
+ . fold ( true )
2653
+ . patch ( Patch :: new ( 483 ..581 , "break" ) ) ,
2654
+ ) ,
2655
+ ) ;
2656
+
2657
+ let expected_ascii = str![ [ r#"
2658
+ error[E0571]: `break` with value from a `while` loop
2659
+ --> $DIR/issue-114529-illegal-break-with-value.rs:22:9
2660
+ |
2661
+ LL | while true {
2662
+ | ---------- you can't `break` with a value in a `while` loop
2663
+ LL | / break (|| { //~ ERROR `break` with value from a `while` loop
2664
+ LL | | let local = 9;
2665
+ LL | | });
2666
+ | |__________^ can only break with a value inside `loop` or breakable block
2667
+ |
2668
+ suggestion[S0123]: use `break` on its own without a value inside this `while` loop
2669
+ |
2670
+ LL - break (|| { //~ ERROR `break` with value from a `while` loop
2671
+ LL - let local = 9;
2672
+ LL - });
2673
+ LL + break;
2674
+ |
2675
+ "# ] ] ;
2676
+
2677
+ let renderer_ascii = Renderer :: plain ( ) . anonymized_line_numbers ( true ) ;
2678
+ assert_data_eq ! ( renderer_ascii. render( input. clone( ) ) , expected_ascii) ;
2679
+
2680
+ let expected_unicode = str![ [ r#"
2681
+ error[E0571]: `break` with value from a `while` loop
2682
+ ╭▸ $DIR/issue-114529-illegal-break-with-value.rs:22:9
2683
+ │
2684
+ LL │ while true {
2685
+ │ ────────── you can't `break` with a value in a `while` loop
2686
+ LL │ ┏ break (|| { //~ ERROR `break` with value from a `while` loop
2687
+ LL │ ┃ let local = 9;
2688
+ LL │ ┃ });
2689
+ │ ┗━━━━━━━━━━┛ can only break with a value inside `loop` or breakable block
2690
+ ╰╴
2691
+ suggestion[S0123]: use `break` on its own without a value inside this `while` loop
2692
+ ╭╴
2693
+ LL - break (|| { //~ ERROR `break` with value from a `while` loop
2694
+ LL - let local = 9;
2695
+ LL - });
2696
+ LL + break;
2697
+ ╰╴
2698
+ "# ] ] ;
2699
+ let renderer_unicode = renderer_ascii. theme ( OutputTheme :: Unicode ) ;
2700
+ assert_data_eq ! ( renderer_unicode. render( input) , expected_unicode) ;
2701
+ }
0 commit comments