Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

不加vec!的话会有以下报错。 #467

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

514366607
Copy link

error[E0277]: a value of type Vec<i32> cannot be built from an iterator over elements of type &{integer}
--> main.rs:26:44
|
26 | let v4: Vec = [0; 10].into_iter().collect();
| ^^^^^^^ value of type Vec<i32> cannot be built from std::iter::Iterator<Item=&{integer}>
|
= help: the trait FromIterator<&{integer}> is not implemented for Vec<i32>
= help: the trait FromIterator<T> is implemented for Vec<T>
note: the method call chain might not have had the expected associated types
--> main.rs:26:32
|
26 | let v4: Vec = [0; 10].into_iter().collect();
| ------- ^^^^^^^^^^^ Iterator::Item is &{integer} here
| |
| this expression has type [{integer}; 10]
note: required by a bound in collect
--> /Users/hible/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/iter/traits/iterator.rs:2049:19
|
2049 | fn collect<B: FromIteratorSelf::Item>(self) -> B
| ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in Iterator::collect

error: aborting due to previous error

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

@CAESIUS-TIM
Copy link

rust 2018 会有问题,但是 2021 以上就没有问题了。

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=6cdf7413bc6b5a593b5e18d865e302f9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants