rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
96.64k stars 12.49k forks source link

E0277 suggestion for changing parameter type to a reference suggests a syntax error #119140

Open ydirson opened 8 months ago

ydirson commented 8 months ago

On the yew tutorial, starting from this working state I tried this change:

 -#[derive(Properties, PartialEq)]
-struct VideosListProps {
-    videos: Vec<Video>,
-    on_click: Callback<Video>,
-}
-
+#[autoprops]
 #[function_component(VideosList)]
-fn videos_list(VideosListProps { videos, on_click }: &VideosListProps) -> Html {
+fn videos_list(videos: Vec<Video>, on_click: Callback<Video>) -> Html {
     let on_click = on_click.clone();
     videos.iter().map(|video| {
         let on_video_select = {

This resulted in this build error:

   Compiling yew-tuto v0.1.0 (/home/user/soft/rustweb/yew-tuto)
error[E0277]: the trait bound `Vec<Video>: ImplicitClone` is not satisfied
  --> src/main.rs:16:16
   |
14 | #[autoprops]
   | ------------ required by a bound introduced by this call
15 | #[function_component(VideosList)]
16 | fn videos_list(videos: Vec<Video>, on_click: Callback<Video>) -> Html {
   |                ^^^^^^ the trait `ImplicitClone` is not implemented for `Vec<Video>`
   |
help: consider borrowing here
   |
16 | fn videos_list(&videos: Vec<Video>, on_click: Callback<Video>) -> Html {
   |                +

For more information about this error, try `rustc --explain E0277`.

This produces a syntax error, a more correct suggestion would be videos: &Vec<Video>.

Meta

rustc 1.74.0 (79e9716c9 2023-11-13)
binary: rustc
commit-hash: 79e9716c980570bfd1f666e3b16ac583f0168962
commit-date: 2023-11-13
host: x86_64-unknown-linux-gnu
release: 1.74.0
LLVM version: 17.0.4
rustc 1.76.0-nightly (3f28fe133 2023-12-18)
binary: rustc
commit-hash: 3f28fe133475ec5faf3413b556bf3cfb0d51336c
commit-date: 2023-12-18
host: x86_64-unknown-linux-gnu
release: 1.76.0-nightly
LLVM version: 17.0.6
Backtrace

no backtrace: ``` user@perso-dev:yew-tuto (yew-autoprops)$ RUST_BACKTRACE=1 cargo build --target=wasm32-unknown-unknown Compiling yew-tuto v0.1.0 (/home/user/soft/rustweb/yew-tuto) error[E0277]: the trait bound `Vec

veera-sivarajan commented 8 months ago

@rustbot claim

veera-sivarajan commented 7 months ago

@rustbot release-assignment