Skip to content

Commit

Permalink
Fix ambiguous call to constraints.as_ref() (#22)
Browse files Browse the repository at this point in the history
If `fast-ssh` is built with an up-to-date version of `rustc`,
the compiler complains about `constraints.as_ref()` being ambiguous,
demanding the types involved in the `.constraints()` call be clarified
with a `::<&[Constraint]>` turbofish annotation:

```
Compiling fast-ssh v0.3.1 (/build/source)
error[E0283]: type annotations needed
  --> src/layout.rs:60:10
   |
60 |         .constraints(constraints.as_ref())
   |          ^^^^^^^^^^^             ------ type must be known at this point
   |          |
   |          cannot infer type of the type parameter `C` declared on the method `constraints`
   |
   = note: multiple `impl`s satisfying `Vec<Constraint>: AsRef<_>` found in the `alloc` crate:
           - impl<T, A> AsRef<Vec<T, A>> for Vec<T, A>
             where A: Allocator;
           - impl<T, A> AsRef<[T]> for Vec<T, A>
             where A: Allocator;
help: consider specifying the generic argument
   |
60 |         .constraints::<&T>(constraints.as_ref())
   |                     ++++++

For more information about this error, try `rustc --explain E0283`.
error: could not compile `fast-ssh` (bin "fast-ssh") due to previous error
```

Luckily, if we use `constraints.as_slice()` instead, the types
involved are still apparent to the compiler, and the resulting
code still remains about as readable as before.
  • Loading branch information
mfrischknecht authored Apr 27, 2024
1 parent de145d7 commit 0d81887
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub fn create_layout(app: &App, frame: &mut Frame<CrosstermBackend<Stdout>>) ->
.direction(Direction::Horizontal)
.margin(1)
.horizontal_margin(0)
.constraints(constraints.as_ref())
.constraints(constraints.as_slice())
.split(base_chunk[1]);

AppLayout {
Expand Down

0 comments on commit 0d81887

Please sign in to comment.