Skip to content

Commit a7500e5

Browse files
committed
Add test for suggestion to borrow unsized function parameters
This is a regression test for rust-lang#82820. This test case is included in more general tests, but I think the error regressed because there were a bunch of other diagnostic changes in the test that obscured this regression. Hopefully, having a test specific to the suggestion, and running rustfix for the test, will prevent this error from regressing in the future.
1 parent 18587b1 commit a7500e5

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// run-rustfix
2+
3+
#![allow(dead_code, unused_variables)]
4+
5+
fn foo1(bar: &str) {}
6+
//~^ ERROR the size for values of type `str` cannot be known at compilation time
7+
//~| HELP the trait `Sized` is not implemented for `str`
8+
//~| HELP unsized fn params are gated as an unstable feature
9+
//~| HELP function arguments must have a statically known size, borrowed types always have a known size
10+
11+
fn foo2(_bar: &str) {}
12+
//~^ ERROR the size for values of type `str` cannot be known at compilation time
13+
//~| HELP the trait `Sized` is not implemented for `str`
14+
//~| HELP unsized fn params are gated as an unstable feature
15+
//~| HELP function arguments must have a statically known size, borrowed types always have a known size
16+
17+
fn foo3(_: &str) {}
18+
//~^ ERROR the size for values of type `str` cannot be known at compilation time
19+
//~| HELP the trait `Sized` is not implemented for `str`
20+
//~| HELP unsized fn params are gated as an unstable feature
21+
//~| HELP function arguments must have a statically known size, borrowed types always have a known size
22+
23+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// run-rustfix
2+
3+
#![allow(dead_code, unused_variables)]
4+
5+
fn foo1(bar: str) {}
6+
//~^ ERROR the size for values of type `str` cannot be known at compilation time
7+
//~| HELP the trait `Sized` is not implemented for `str`
8+
//~| HELP unsized fn params are gated as an unstable feature
9+
//~| HELP function arguments must have a statically known size, borrowed types always have a known size
10+
11+
fn foo2(_bar: str) {}
12+
//~^ ERROR the size for values of type `str` cannot be known at compilation time
13+
//~| HELP the trait `Sized` is not implemented for `str`
14+
//~| HELP unsized fn params are gated as an unstable feature
15+
//~| HELP function arguments must have a statically known size, borrowed types always have a known size
16+
17+
fn foo3(_: str) {}
18+
//~^ ERROR the size for values of type `str` cannot be known at compilation time
19+
//~| HELP the trait `Sized` is not implemented for `str`
20+
//~| HELP unsized fn params are gated as an unstable feature
21+
//~| HELP function arguments must have a statically known size, borrowed types always have a known size
22+
23+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
error[E0277]: the size for values of type `str` cannot be known at compilation time
2+
--> $DIR/unsized-function-parameter.rs:5:9
3+
|
4+
LL | fn foo1(bar: str) {}
5+
| ^^^ doesn't have a size known at compile-time
6+
|
7+
= help: the trait `Sized` is not implemented for `str`
8+
= help: unsized fn params are gated as an unstable feature
9+
help: function arguments must have a statically known size, borrowed types always have a known size
10+
|
11+
LL | fn foo1(bar: &str) {}
12+
| ^
13+
14+
error[E0277]: the size for values of type `str` cannot be known at compilation time
15+
--> $DIR/unsized-function-parameter.rs:11:9
16+
|
17+
LL | fn foo2(_bar: str) {}
18+
| ^^^^ doesn't have a size known at compile-time
19+
|
20+
= help: the trait `Sized` is not implemented for `str`
21+
= help: unsized fn params are gated as an unstable feature
22+
help: function arguments must have a statically known size, borrowed types always have a known size
23+
|
24+
LL | fn foo2(_bar: &str) {}
25+
| ^
26+
27+
error[E0277]: the size for values of type `str` cannot be known at compilation time
28+
--> $DIR/unsized-function-parameter.rs:17:9
29+
|
30+
LL | fn foo3(_: str) {}
31+
| ^ doesn't have a size known at compile-time
32+
|
33+
= help: the trait `Sized` is not implemented for `str`
34+
= help: unsized fn params are gated as an unstable feature
35+
help: function arguments must have a statically known size, borrowed types always have a known size
36+
|
37+
LL | fn foo3(_: &str) {}
38+
| ^
39+
40+
error: aborting due to 3 previous errors
41+
42+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)