Skip to content

Commit 7a77fce

Browse files
committed
test: Add rustc tests for annotation sorting
1 parent b6a8199 commit 7a77fce

File tree

1 file changed

+212
-0
lines changed

1 file changed

+212
-0
lines changed

tests/rustc_tests.rs

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2466,3 +2466,215 @@ LL | ----cargo
24662466
let renderer = Renderer::plain().anonymized_line_numbers(true);
24672467
assert_data_eq!(renderer.render(input), expected);
24682468
}
2469+
2470+
#[test]
2471+
fn pat_tuple_field_count_cross() {
2472+
// tests/ui/pattern/pat-tuple-field-count-cross.stderr
2473+
2474+
let source = r#"//@ aux-build:declarations-for-tuple-field-count-errors.rs
2475+
2476+
extern crate declarations_for_tuple_field_count_errors;
2477+
2478+
use declarations_for_tuple_field_count_errors::*;
2479+
2480+
fn main() {
2481+
match Z0 {
2482+
Z0() => {} //~ ERROR expected tuple struct or tuple variant, found unit struct `Z0`
2483+
Z0(x) => {} //~ ERROR expected tuple struct or tuple variant, found unit struct `Z0`
2484+
}
2485+
match Z1() {
2486+
Z1 => {} //~ ERROR match bindings cannot shadow tuple structs
2487+
Z1(x) => {} //~ ERROR this pattern has 1 field, but the corresponding tuple struct has 0 fields
2488+
}
2489+
2490+
match S(1, 2, 3) {
2491+
S() => {} //~ ERROR this pattern has 0 fields, but the corresponding tuple struct has 3 fields
2492+
S(1) => {} //~ ERROR this pattern has 1 field, but the corresponding tuple struct has 3 fields
2493+
S(xyz, abc) => {} //~ ERROR this pattern has 2 fields, but the corresponding tuple struct has 3 fields
2494+
S(1, 2, 3, 4) => {} //~ ERROR this pattern has 4 fields, but the corresponding tuple struct has 3 fields
2495+
}
2496+
match M(1, 2, 3) {
2497+
M() => {} //~ ERROR this pattern has 0 fields, but the corresponding tuple struct has 3 fields
2498+
M(1) => {} //~ ERROR this pattern has 1 field, but the corresponding tuple struct has 3 fields
2499+
M(xyz, abc) => {} //~ ERROR this pattern has 2 fields, but the corresponding tuple struct has 3 fields
2500+
M(1, 2, 3, 4) => {} //~ ERROR this pattern has 4 fields, but the corresponding tuple struct has 3 fields
2501+
}
2502+
2503+
match E1::Z0 {
2504+
E1::Z0() => {} //~ ERROR expected tuple struct or tuple variant, found unit variant `E1::Z0`
2505+
E1::Z0(x) => {} //~ ERROR expected tuple struct or tuple variant, found unit variant `E1::Z0`
2506+
}
2507+
match E1::Z1() {
2508+
E1::Z1 => {} //~ ERROR expected unit struct, unit variant or constant, found tuple variant `E1::Z1`
2509+
E1::Z1(x) => {} //~ ERROR this pattern has 1 field, but the corresponding tuple variant has 0 fields
2510+
}
2511+
match E1::S(1, 2, 3) {
2512+
E1::S() => {} //~ ERROR this pattern has 0 fields, but the corresponding tuple variant has 3 fields
2513+
E1::S(1) => {} //~ ERROR this pattern has 1 field, but the corresponding tuple variant has 3 fields
2514+
E1::S(xyz, abc) => {} //~ ERROR this pattern has 2 fields, but the corresponding tuple variant has 3 fields
2515+
E1::S(1, 2, 3, 4) => {} //~ ERROR this pattern has 4 fields, but the corresponding tuple variant has 3 fields
2516+
}
2517+
2518+
match E2::S(1, 2, 3) {
2519+
E2::S() => {} //~ ERROR this pattern has 0 fields, but the corresponding tuple variant has 3 fields
2520+
E2::S(1) => {} //~ ERROR this pattern has 1 field, but the corresponding tuple variant has 3 fields
2521+
E2::S(xyz, abc) => {} //~ ERROR this pattern has 2 fields, but the corresponding tuple variant has 3 fields
2522+
E2::S(1, 2, 3, 4) => {} //~ ERROR this pattern has 4 fields, but the corresponding tuple variant has 3 fields
2523+
}
2524+
match E2::M(1, 2, 3) {
2525+
E2::M() => {} //~ ERROR this pattern has 0 fields, but the corresponding tuple variant has 3 fields
2526+
E2::M(1) => {} //~ ERROR this pattern has 1 field, but the corresponding tuple variant has 3 fields
2527+
E2::M(xyz, abc) => {} //~ ERROR this pattern has 2 fields, but the corresponding tuple variant has 3 fields
2528+
E2::M(1, 2, 3, 4) => {} //~ ERROR this pattern has 4 fields, but the corresponding tuple variant has 3 fields
2529+
}
2530+
}
2531+
"#;
2532+
let source1 = r#"pub struct Z0;
2533+
pub struct Z1();
2534+
2535+
pub struct S(pub u8, pub u8, pub u8);
2536+
pub struct M(
2537+
pub u8,
2538+
pub u8,
2539+
pub u8,
2540+
);
2541+
2542+
pub enum E1 { Z0, Z1(), S(u8, u8, u8) }
2543+
2544+
pub enum E2 {
2545+
S(u8, u8, u8),
2546+
M(
2547+
u8,
2548+
u8,
2549+
u8,
2550+
),
2551+
}
2552+
"#;
2553+
2554+
let input = Level::ERROR
2555+
.header("expected unit struct, unit variant or constant, found tuple variant `E1::Z1`")
2556+
.id(r#"E0532"#)
2557+
.group(
2558+
Group::new()
2559+
.element(
2560+
Snippet::source(source)
2561+
.origin("$DIR/pat-tuple-field-count-cross.rs")
2562+
.fold(true)
2563+
.annotation(AnnotationKind::Primary.span(1760..1766)),
2564+
)
2565+
.element(
2566+
Snippet::source(source1)
2567+
.origin("$DIR/auxiliary/declarations-for-tuple-field-count-errors.rs")
2568+
.fold(true)
2569+
.annotation(
2570+
AnnotationKind::Context
2571+
.span(143..145)
2572+
.label("`E1::Z1` defined here"),
2573+
)
2574+
.annotation(
2575+
AnnotationKind::Context
2576+
.span(139..141)
2577+
.label("similarly named unit variant `Z0` defined here"),
2578+
),
2579+
),
2580+
)
2581+
.group(
2582+
Group::new()
2583+
.element(Level::HELP.title("use the tuple variant pattern syntax instead"))
2584+
.element(
2585+
Snippet::source(source)
2586+
.origin("$DIR/pat-tuple-field-count-cross.rs")
2587+
.fold(true)
2588+
.patch(Patch::new(1760..1766, r#"E1::Z1()"#)),
2589+
),
2590+
)
2591+
.group(
2592+
Group::new()
2593+
.element(Level::HELP.title("a unit variant with a similar name exists"))
2594+
.element(
2595+
Snippet::source(source)
2596+
.origin("$DIR/pat-tuple-field-count-cross.rs")
2597+
.fold(true)
2598+
.patch(Patch::new(1764..1766, r#"Z0"#)),
2599+
),
2600+
);
2601+
let expected = str![[r#"
2602+
error[E0532]: expected unit struct, unit variant or constant, found tuple variant `E1::Z1`
2603+
--> $DIR/pat-tuple-field-count-cross.rs:35:9
2604+
|
2605+
LL | E1::Z1 => {} //~ ERROR expected unit struct, unit variant or constant, found tuple variant `E1::Z1`
2606+
| ^^^^^^
2607+
|
2608+
::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:11:15
2609+
|
2610+
LL | pub enum E1 { Z0, Z1(), S(u8, u8, u8) }
2611+
| -- -- `E1::Z1` defined here
2612+
| |
2613+
| similarly named unit variant `Z0` defined here
2614+
|
2615+
help: use the tuple variant pattern syntax instead
2616+
|
2617+
LL | E1::Z1() => {} //~ ERROR expected unit struct, unit variant or constant, found tuple variant `E1::Z1`
2618+
| ++
2619+
help: a unit variant with a similar name exists
2620+
|
2621+
LL - E1::Z1 => {} //~ ERROR expected unit struct, unit variant or constant, found tuple variant `E1::Z1`
2622+
LL + E1::Z0 => {} //~ ERROR expected unit struct, unit variant or constant, found tuple variant `E1::Z1`
2623+
|
2624+
"#]];
2625+
let renderer = Renderer::plain().anonymized_line_numbers(true);
2626+
assert_data_eq!(renderer.render(input), expected);
2627+
}
2628+
2629+
#[test]
2630+
fn unterminated_nested_comment() {
2631+
// tests/ui/lexer/unterminated-nested-comment.rs
2632+
2633+
let source = r#"/* //~ ERROR E0758
2634+
/* */
2635+
/*
2636+
*/
2637+
"#;
2638+
2639+
let input = Level::ERROR.header("unterminated block comment").id("E0758").group(
2640+
Group::new().element(
2641+
Snippet::source(source)
2642+
.origin("$DIR/unterminated-nested-comment.rs")
2643+
.fold(true)
2644+
.annotation(
2645+
AnnotationKind::Context
2646+
.span(0..2)
2647+
.label("unterminated block comment"),
2648+
)
2649+
.annotation(AnnotationKind::Context.span(25..27).label(
2650+
"...as last nested comment starts here, maybe you want to close this instead?",
2651+
))
2652+
.annotation(
2653+
AnnotationKind::Context
2654+
.span(28..30)
2655+
.label("...and last nested comment terminates here."),
2656+
)
2657+
.annotation(AnnotationKind::Primary.span(0..31)),
2658+
),
2659+
);
2660+
2661+
let expected = str![[r#"
2662+
error[E0758]: unterminated block comment
2663+
--> $DIR/unterminated-nested-comment.rs:1:1
2664+
|
2665+
LL | /* //~ ERROR E0758
2666+
| ^-
2667+
| |
2668+
| _unterminated block comment
2669+
| |
2670+
LL | | /* */
2671+
LL | | /*
2672+
| | -- ...as last nested comment starts here, maybe you want to close this instead?
2673+
LL | | */
2674+
| |_--^
2675+
| |
2676+
| ...and last nested comment terminates here.
2677+
"#]];
2678+
let renderer = Renderer::plain().anonymized_line_numbers(true);
2679+
assert_data_eq!(renderer.render(input), expected);
2680+
}

0 commit comments

Comments
 (0)