Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions tests/ui/inference/ambiguous-cast-suggestion-issue-41261.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//@ edition: 2021

// Regression test for issue #41261.
// The diagnostic should point at the ambiguous cast, not at the later method call.

struct S {
v: Vec<(u32, Vec<u32>)>,
}

impl S {
pub fn remove(&mut self, i: u32) -> Option<std::vec::Drain<'_, u32>> {
self.v.get_mut(i as _).map(|&mut (_, ref mut v2)| {
//~^ ERROR type annotations needed
v2.drain(..)
})
}
}

fn main() {}
17 changes: 17 additions & 0 deletions tests/ui/inference/ambiguous-cast-suggestion-issue-41261.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error[E0282]: type annotations needed for `&mut (_, _)`
--> $DIR/ambiguous-cast-suggestion-issue-41261.rs:12:37
|
LL | self.v.get_mut(i as _).map(|&mut (_, ref mut v2)| {
| ^^^^^^^^^^^^^^^^^^^^
LL |
LL | v2.drain(..)
| -- type must be known at this point
|
help: consider giving this closure parameter an explicit type, where the placeholders `_` are specified
|
LL | self.v.get_mut(i as _).map(|&mut (_, ref mut v2): &mut (_, _)| {
| +++++++++++++

error: aborting due to 1 previous error

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