Skip to content

Commit e061ae9

Browse files
authored
Rollup merge of #111612 - ChayimFriedman2:collect-into-slice-ref, r=petrochenkov
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.
2 parents 248666b + d1c226e commit e061ae9

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

core/src/iter/traits/collect.rs

+10
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@
9494
/// ```
9595
#[stable(feature = "rust1", since = "1.0.0")]
9696
#[rustc_on_unimplemented(
97+
on(
98+
_Self = "&[{A}]",
99+
message = "a slice of type `{Self}` cannot be built since we need to store the elements somewhere",
100+
label = "try explicitly collecting into a `Vec<{A}>`",
101+
),
102+
on(
103+
all(A = "{integer}", any(_Self = "&[{integral}]",)),
104+
message = "a slice of type `{Self}` cannot be built since we need to store the elements somewhere",
105+
label = "try explicitly collecting into a `Vec<{A}>`",
106+
),
97107
on(
98108
_Self = "[{A}]",
99109
message = "a slice of type `{Self}` cannot be built since `{Self}` has no definite size",

0 commit comments

Comments
 (0)