It's usually a good idea to post the full compiler error. It contains useful information that makes it easier for us to understand the problem:
error[E0369]: binary operation `>` cannot be applied to type `&T`
--> src/lib.rs:6:17
|
6 | if item > largest {
| ---- ^ ------- &T
| |
| &T
|
help: consider restricting type parameter `T`
|
1 | fn largest_func<T: std::cmp::PartialOrd> (list: &[T]) -> &T { // error compiler
| ^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
(Playground)
As @LingMan notes, the error comes from the comparison on line 6, because you haven't required that T
supports that operation. Often, the compiler also has a suggestion about how you might correct the problem; that's the section that starts help:
. If you rewrite line 1 to look like the compiler has printed it, this particular error will be taken care of.
It's important to note that this will sometimes uncover additional errors, and the resulting code still won't compile for some other reason. This doesn't mean that the suggestion was wrong, only incomplete.