forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#128467 - estebank:unsized-args, r=cjgillot
Detect `*` operator on `!Sized` expression The suggestion is new: ``` error[E0277]: the size for values of type `str` cannot be known at compilation time --> $DIR/unsized-str-in-return-expr-arg-and-local.rs:15:9 | LL | let x = *""; | ^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `str` = note: all local variables must have a statically known size = help: unsized locals are gated as an unstable feature help: references to `!Sized` types like `&str` are `Sized`; consider not dereferencing the expression | LL - let x = *""; LL + let x = ""; | ``` Fix rust-lang#128199.
- Loading branch information
Showing
10 changed files
with
187 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
tests/ui/sized/unsized-str-in-return-expr-arg-and-local.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
fn foo() -> impl Sized { | ||
//~^ ERROR the size for values of type `str` cannot be known at compilation time | ||
//~| HELP the trait `Sized` is not implemented for `str` | ||
*"" //~ HELP consider not dereferencing the expression | ||
} | ||
fn bar(_: impl Sized) {} | ||
struct S; | ||
|
||
impl S { | ||
fn baz(&self, _: impl Sized) {} | ||
} | ||
|
||
fn main() { | ||
let _ = foo(); | ||
let x = *""; | ||
//~^ ERROR the size for values of type `str` cannot be known at compilation time | ||
//~| HELP consider not dereferencing the expression | ||
//~| HELP the trait `Sized` is not implemented for `str` | ||
//~| HELP unsized locals are gated as an unstable feature | ||
bar(x); | ||
S.baz(x); | ||
bar(*""); | ||
//~^ ERROR the size for values of type `str` cannot be known at compilation time | ||
//~| HELP consider not dereferencing the expression | ||
//~| HELP the trait `Sized` is not implemented for `str` | ||
S.baz(*""); | ||
//~^ ERROR the size for values of type `str` cannot be known at compilation time | ||
//~| HELP consider not dereferencing the expression | ||
//~| HELP the trait `Sized` is not implemented for `str` | ||
} |
74 changes: 74 additions & 0 deletions
74
tests/ui/sized/unsized-str-in-return-expr-arg-and-local.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
error[E0277]: the size for values of type `str` cannot be known at compilation time | ||
--> $DIR/unsized-str-in-return-expr-arg-and-local.rs:1:13 | ||
| | ||
LL | fn foo() -> impl Sized { | ||
| ^^^^^^^^^^ doesn't have a size known at compile-time | ||
... | ||
LL | *"" | ||
| --- return type was inferred to be `str` here | ||
| | ||
= help: the trait `Sized` is not implemented for `str` | ||
help: references are always `Sized`, even if they point to unsized data; consider not dereferencing the expression | ||
| | ||
LL - *"" | ||
LL + "" | ||
| | ||
|
||
error[E0277]: the size for values of type `str` cannot be known at compilation time | ||
--> $DIR/unsized-str-in-return-expr-arg-and-local.rs:15:9 | ||
| | ||
LL | let x = *""; | ||
| ^ doesn't have a size known at compile-time | ||
| | ||
= help: the trait `Sized` is not implemented for `str` | ||
= note: all local variables must have a statically known size | ||
= help: unsized locals are gated as an unstable feature | ||
help: references are always `Sized`, even if they point to unsized data; consider not dereferencing the expression | ||
| | ||
LL - let x = *""; | ||
LL + let x = ""; | ||
| | ||
|
||
error[E0277]: the size for values of type `str` cannot be known at compilation time | ||
--> $DIR/unsized-str-in-return-expr-arg-and-local.rs:22:9 | ||
| | ||
LL | bar(*""); | ||
| --- ^^^ doesn't have a size known at compile-time | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
= help: the trait `Sized` is not implemented for `str` | ||
note: required by a bound in `bar` | ||
--> $DIR/unsized-str-in-return-expr-arg-and-local.rs:6:16 | ||
| | ||
LL | fn bar(_: impl Sized) {} | ||
| ^^^^^ required by this bound in `bar` | ||
help: references are always `Sized`, even if they point to unsized data; consider not dereferencing the expression | ||
| | ||
LL - bar(*""); | ||
LL + bar(""); | ||
| | ||
|
||
error[E0277]: the size for values of type `str` cannot be known at compilation time | ||
--> $DIR/unsized-str-in-return-expr-arg-and-local.rs:26:11 | ||
| | ||
LL | S.baz(*""); | ||
| --- ^^^ doesn't have a size known at compile-time | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
= help: the trait `Sized` is not implemented for `str` | ||
note: required by a bound in `S::baz` | ||
--> $DIR/unsized-str-in-return-expr-arg-and-local.rs:10:27 | ||
| | ||
LL | fn baz(&self, _: impl Sized) {} | ||
| ^^^^^ required by this bound in `S::baz` | ||
help: references are always `Sized`, even if they point to unsized data; consider not dereferencing the expression | ||
| | ||
LL - S.baz(*""); | ||
LL + S.baz(""); | ||
| | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters