Skip to content

Commit

Permalink
Rollup merge of #111612 - ChayimFriedman2:collect-into-slice-ref, r=p…
Browse files Browse the repository at this point in the history
…etrochenkov

Give better error when collecting into `&[T]`

The detection of slice reference of `{integral}` in `rustc_on_unimplemented` is hacky, but a proper solution requires changing `FmtPrinter` to add a parameter to print integers as `{integral}` and I didn't want to change it just for `rustc_on_unimplemented`. I can do that if requested, though.

I'm open to better wording; this is the best I could come up with.
  • Loading branch information
Dylan-DPC authored May 22, 2023
2 parents 248666b + d1c226e commit e061ae9
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions core/src/iter/traits/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_on_unimplemented(
on(
_Self = "&[{A}]",
message = "a slice of type `{Self}` cannot be built since we need to store the elements somewhere",
label = "try explicitly collecting into a `Vec<{A}>`",
),
on(
all(A = "{integer}", any(_Self = "&[{integral}]",)),
message = "a slice of type `{Self}` cannot be built since we need to store the elements somewhere",
label = "try explicitly collecting into a `Vec<{A}>`",
),
on(
_Self = "[{A}]",
message = "a slice of type `{Self}` cannot be built since `{Self}` has no definite size",
Expand Down

0 comments on commit e061ae9

Please sign in to comment.