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