Skip to content

Commit 5b355ce

Browse files
committed
test: Multiple line removals
1 parent e4c7105 commit 5b355ce

File tree

1 file changed

+216
-0
lines changed

1 file changed

+216
-0
lines changed

tests/rustc_tests.rs

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5679,3 +5679,219 @@ help: Unicode character ' ' (No-Break Space) looks like ' ' (Space), but it is
56795679
let renderer_unicode = renderer_ascii.decor_style(DecorStyle::Unicode);
56805680
assert_data_eq!(renderer_unicode.render(report), expected_unicode);
56815681
}
5682+
5683+
#[test]
5684+
fn issue_109854() {
5685+
// tests/ui/suggestions/issue-109854.rs
5686+
let source_0 = r##" String::with_capacity(
5687+
//~^ ERROR this function takes 1 argument but 3 arguments were supplied
5688+
generate_setter,
5689+
r#"
5690+
pub(crate) struct Person<T: Clone> {}
5691+
"#,
5692+
r#""#,
5693+
"##;
5694+
let source_1 = r#" generate_setter,
5695+
"#;
5696+
let title_0 = "expected type `usize`
5697+
found fn item `fn() {generate_setter}`";
5698+
let source_2 = r##" generate_setter,
5699+
r#"
5700+
pub(crate) struct Person<T: Clone> {}
5701+
"#,
5702+
r#""#,
5703+
"##;
5704+
5705+
let report = &[
5706+
Level::ERROR
5707+
.primary_title("this function takes 1 argument but 3 arguments were supplied")
5708+
.id("E0061")
5709+
.element(
5710+
Snippet::source(source_0)
5711+
.path("$DIR/issue-109854.rs")
5712+
.line_start(2)
5713+
.annotation(AnnotationKind::Primary.span(4..25))
5714+
.annotation(
5715+
AnnotationKind::Context
5716+
.span(128..172)
5717+
.label("unexpected argument #2 of type `&'static str`"),
5718+
)
5719+
.annotation(
5720+
AnnotationKind::Context
5721+
.span(179..184)
5722+
.label("unexpected argument #3 of type `&'static str`"),
5723+
),
5724+
),
5725+
Level::NOTE
5726+
.secondary_title("expected `usize`, found fn item")
5727+
.element(
5728+
Snippet::source(source_1)
5729+
.path("$DIR/issue-109854.rs")
5730+
.line_start(4)
5731+
.annotation(AnnotationKind::Primary.span(4..19)),
5732+
)
5733+
.element(Level::NOTE.message(title_0)),
5734+
Level::NOTE
5735+
.secondary_title("associated function defined here")
5736+
.element(
5737+
Origin::path("$SRC_DIR/alloc/src/string.rs")
5738+
.line(480)
5739+
.char_column(11),
5740+
),
5741+
Level::HELP
5742+
.secondary_title("remove the extra arguments")
5743+
.element(
5744+
Snippet::source(source_2)
5745+
.path("$DIR/issue-109854.rs")
5746+
.line_start(4)
5747+
.patch(Patch::new(4..19, "/* usize */"))
5748+
.patch(Patch::new(19..69, ""))
5749+
.patch(Patch::new(69..81, "")),
5750+
),
5751+
];
5752+
let expected_ascii = str![[r##"
5753+
error[E0061]: this function takes 1 argument but 3 arguments were supplied
5754+
--> $DIR/issue-109854.rs:2:5
5755+
|
5756+
2 | String::with_capacity(
5757+
| ^^^^^^^^^^^^^^^^^^^^^
5758+
...
5759+
5 | / r#"
5760+
6 | | pub(crate) struct Person<T: Clone> {}
5761+
7 | | "#,
5762+
| |__- unexpected argument #2 of type `&'static str`
5763+
8 | r#""#,
5764+
| ----- unexpected argument #3 of type `&'static str`
5765+
|
5766+
note: expected `usize`, found fn item
5767+
--> $DIR/issue-109854.rs:4:5
5768+
|
5769+
4 | generate_setter,
5770+
| ^^^^^^^^^^^^^^^
5771+
= note: expected type `usize`
5772+
found fn item `fn() {generate_setter}`
5773+
note: associated function defined here
5774+
--> $SRC_DIR/alloc/src/string.rs:480:11
5775+
help: remove the extra arguments
5776+
|
5777+
4 - generate_setter,
5778+
4 + /* usize */,
5779+
|
5780+
"##]];
5781+
let renderer_ascii = Renderer::plain();
5782+
assert_data_eq!(renderer_ascii.render(report), expected_ascii);
5783+
5784+
let expected_unicode = str![[r##"
5785+
error[E0061]: this function takes 1 argument but 3 arguments were supplied
5786+
╭▸ $DIR/issue-109854.rs:2:5
5787+
5788+
2 │ String::with_capacity(
5789+
│ ━━━━━━━━━━━━━━━━━━━━━
5790+
5791+
5 │ ┌ r#"
5792+
6 │ │ pub(crate) struct Person<T: Clone> {}
5793+
7 │ │ "#,
5794+
│ └──┘ unexpected argument #2 of type `&'static str`
5795+
8 │ r#""#,
5796+
│ ───── unexpected argument #3 of type `&'static str`
5797+
╰╴
5798+
note: expected `usize`, found fn item
5799+
╭▸ $DIR/issue-109854.rs:4:5
5800+
5801+
4 │ generate_setter,
5802+
│ ━━━━━━━━━━━━━━━
5803+
╰ note: expected type `usize`
5804+
found fn item `fn() {generate_setter}`
5805+
note: associated function defined here
5806+
─▸ $SRC_DIR/alloc/src/string.rs:480:11
5807+
help: remove the extra arguments
5808+
╭╴
5809+
4 - generate_setter,
5810+
4 + /* usize */,
5811+
╰╴
5812+
"##]];
5813+
let renderer_unicode = renderer_ascii.decor_style(DecorStyle::Unicode);
5814+
assert_data_eq!(renderer_unicode.render(report), expected_unicode);
5815+
}
5816+
5817+
#[test]
5818+
fn match_same_arms() {
5819+
// src/tools/clippy/tests/ui/match_same_arms.rs
5820+
let source = r#" 2 => 'b',
5821+
3 => 'b',
5822+
_ => 'b',
5823+
"#;
5824+
5825+
let report = &[
5826+
Level::ERROR
5827+
.primary_title("these match arms have identical bodies")
5828+
.element(
5829+
Snippet::source(source)
5830+
.path("tests/ui/match_same_arms.rs")
5831+
.line_start(20)
5832+
.annotation(AnnotationKind::Primary.span(8..16))
5833+
.annotation(AnnotationKind::Primary.span(26..34))
5834+
.annotation(
5835+
AnnotationKind::Primary
5836+
.span(44..52)
5837+
.label("the wildcard arm"),
5838+
),
5839+
)
5840+
.element(
5841+
Level::HELP
5842+
.message("if this is unintentional make the arms return different values"),
5843+
),
5844+
Level::HELP
5845+
.secondary_title("otherwise remove the non-wildcard arms")
5846+
.element(
5847+
Snippet::source(source)
5848+
.path("tests/ui/match_same_arms.rs")
5849+
.line_start(20)
5850+
.patch(Patch::new(8..26, ""))
5851+
.patch(Patch::new(26..44, "")),
5852+
),
5853+
];
5854+
let expected_ascii = str![[r#"
5855+
error: these match arms have identical bodies
5856+
--> tests/ui/match_same_arms.rs:20:9
5857+
|
5858+
20 | 2 => 'b',
5859+
| ^^^^^^^^
5860+
21 | 3 => 'b',
5861+
| ^^^^^^^^
5862+
22 | _ => 'b',
5863+
| ^^^^^^^^ the wildcard arm
5864+
|
5865+
= help: if this is unintentional make the arms return different values
5866+
help: otherwise remove the non-wildcard arms
5867+
|
5868+
20 - 2 => 'b',
5869+
21 - 3 => 'b',
5870+
20 + _ => 'b',
5871+
|
5872+
"#]];
5873+
let renderer_ascii = Renderer::plain();
5874+
assert_data_eq!(renderer_ascii.render(report), expected_ascii);
5875+
5876+
let expected_unicode = str![[r#"
5877+
error: these match arms have identical bodies
5878+
╭▸ tests/ui/match_same_arms.rs:20:9
5879+
5880+
20 │ 2 => 'b',
5881+
│ ━━━━━━━━
5882+
21 │ 3 => 'b',
5883+
│ ━━━━━━━━
5884+
22 │ _ => 'b',
5885+
│ ━━━━━━━━ the wildcard arm
5886+
5887+
╰ help: if this is unintentional make the arms return different values
5888+
help: otherwise remove the non-wildcard arms
5889+
╭╴
5890+
20 - 2 => 'b',
5891+
21 - 3 => 'b',
5892+
20 + _ => 'b',
5893+
╰╴
5894+
"#]];
5895+
let renderer_unicode = renderer_ascii.decor_style(DecorStyle::Unicode);
5896+
assert_data_eq!(renderer_unicode.render(report), expected_unicode);
5897+
}

0 commit comments

Comments
 (0)