Skip to content

Commit f410552

Browse files
committed
test: Add rustc test with empty source
1 parent 24573e2 commit f410552

File tree

1 file changed

+114
-0
lines changed

1 file changed

+114
-0
lines changed

tests/rustc_tests.rs

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2680,3 +2680,117 @@ LL | | */
26802680
let renderer = Renderer::plain().anonymized_line_numbers(true);
26812681
assert_data_eq!(renderer.render(input), expected);
26822682
}
2683+
2684+
#[test]
2685+
#[should_panic(expected = "called `Option::unwrap()` on a `None` value")]
2686+
fn mismatched_types1() {
2687+
// tests/ui/include-macros/mismatched-types.rs
2688+
2689+
let file_txt_source = r#""#;
2690+
2691+
let rust_source = r#"fn main() {
2692+
let b: &[u8] = include_str!("file.txt"); //~ ERROR mismatched types
2693+
let s: &str = include_bytes!("file.txt"); //~ ERROR mismatched types
2694+
}"#;
2695+
2696+
let input = Level::ERROR.header("mismatched types").id("E0308").group(
2697+
Group::new()
2698+
.element(
2699+
Snippet::source(file_txt_source)
2700+
.fold(true)
2701+
.line_start(3)
2702+
.origin("$DIR/file.txt")
2703+
.annotation(
2704+
AnnotationKind::Primary
2705+
.span(0..0)
2706+
.label("expected `&[u8]`, found `&str`"),
2707+
),
2708+
)
2709+
.element(
2710+
Snippet::source(rust_source)
2711+
.origin("$DIR/mismatched-types.rs")
2712+
.fold(true)
2713+
.annotation(
2714+
AnnotationKind::Context
2715+
.span(23..28)
2716+
.label("expected due to this"),
2717+
)
2718+
.annotation(
2719+
AnnotationKind::Context
2720+
.span(31..55)
2721+
.label("in this macro invocation"),
2722+
),
2723+
)
2724+
.element(
2725+
Level::NOTE.title("expected reference `&[u8]`\n found reference `&'static str`"),
2726+
),
2727+
);
2728+
2729+
let expected = str![[r#"
2730+
error[E0308]: mismatched types
2731+
--> $DIR/file.txt:3:1
2732+
|
2733+
LL |
2734+
| ^ expected `&[u8]`, found `&str`
2735+
|
2736+
::: $DIR/mismatched-types.rs:2:12
2737+
|
2738+
LL | let b: &[u8] = include_str!("file.txt"); //~ ERROR mismatched types
2739+
| ----- ------------------------ in this macro invocation
2740+
| |
2741+
| expected due to this
2742+
|
2743+
= note: expected reference `&[u8]`
2744+
found reference `&'static str`
2745+
"#]];
2746+
let renderer = Renderer::plain().anonymized_line_numbers(true);
2747+
assert_data_eq!(renderer.render(input), expected);
2748+
}
2749+
2750+
#[test]
2751+
fn mismatched_types2() {
2752+
// tests/ui/include-macros/mismatched-types.rs
2753+
2754+
let source = r#"fn main() {
2755+
let b: &[u8] = include_str!("file.txt"); //~ ERROR mismatched types
2756+
let s: &str = include_bytes!("file.txt"); //~ ERROR mismatched types
2757+
}"#;
2758+
2759+
let input = Level::ERROR.header("mismatched types").id("E0308").group(
2760+
Group::new()
2761+
.element(
2762+
Snippet::source(source)
2763+
.origin("$DIR/mismatched-types.rs")
2764+
.fold(true)
2765+
.annotation(
2766+
AnnotationKind::Primary
2767+
.span(105..131)
2768+
.label("expected `&str`, found `&[u8; 0]`"),
2769+
)
2770+
.annotation(
2771+
AnnotationKind::Context
2772+
.span(98..102)
2773+
.label("expected due to this"),
2774+
),
2775+
)
2776+
.element(
2777+
Level::NOTE
2778+
.title("expected reference `&str`\n found reference `&'static [u8; 0]`"),
2779+
),
2780+
);
2781+
2782+
let expected = str![[r#"
2783+
error[E0308]: mismatched types
2784+
--> $DIR/mismatched-types.rs:3:19
2785+
|
2786+
LL | let s: &str = include_bytes!("file.txt"); //~ ERROR mismatched types
2787+
| ---- ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&str`, found `&[u8; 0]`
2788+
| |
2789+
| expected due to this
2790+
|
2791+
= note: expected reference `&str`
2792+
found reference `&'static [u8; 0]`
2793+
"#]];
2794+
let renderer = Renderer::plain().anonymized_line_numbers(true);
2795+
assert_data_eq!(renderer.render(input), expected);
2796+
}

0 commit comments

Comments
 (0)