rust-lang / rust-lang/rust

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

Open
#119,140 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-suggestion-diagnostics C-bug D-invalid-suggestion
Dominant language
Rust
Stars
119k
Forks
16.2k
PR merge metrics
PR metrics pending

Description

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<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`.
error: could not compile `yew-tuto` (bin "yew-tuto") due to previous error
user@perso-dev:yew-tuto (yew-autoprops)$ 

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reported src/main.rs reproducer and run cargo build --target=wasm32-unknown-unknown using the versions listed in the issue. Trace the E0277 diagnostic that suggests borrowing Vec<Video> and identify where that suggestion is generated. Done means the diagnostic recommends valid reference syntax for this case and the reproducer’s diagnostic test passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.