-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Fix wrong report on closure args mismatch when a ref is expected but not found #42270
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
use std::ops::{FnOnce, Fn}; | ||
|
||
pub fn main() { | ||
let a = [(1u32,2u32)]; | ||
let b = a.iter().map(|x: (u32, u32)| 45); | ||
let d1 = a.iter().map(|x: &(u16,u16)| 45); | ||
let d2 = a.iter().map(|x: (u16,u16)| 45); | ||
foo(|y: isize| ()); | ||
} | ||
|
||
fn foo<F>(m: F) where F: Fn(usize) {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
error[E0622]: type mismatch in closure arguments | ||
--> $DIR/closure-arg-type-mismatch.rs:15:26 | ||
| | ||
15 | let b = a.iter().map(|x: (u32, u32)| 45); | ||
| ^^^ ------------------ takes a `std::ops::FnMut<((u32, u32),)>` | ||
| | | ||
| expected closure that takes a `std::ops::FnMut<(&(u32, u32),)>` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm thinking about implementing a hint telling the user to add a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, I couldn't find a way (except for "parsing") to convert |
||
|
||
error[E0622]: type mismatch in closure arguments | ||
--> $DIR/closure-arg-type-mismatch.rs:16:27 | ||
| | ||
16 | let d1 = a.iter().map(|x: &(u16,u16)| 45); | ||
| ^^^ ------------------ takes a `for<'r> std::ops::FnMut<(&'r (u16, u16),)>` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this binder/lifetime be displayed? |
||
| | | ||
| expected closure that takes a `std::ops::FnMut<(&(u32, u32),)>` | ||
|
||
error[E0622]: type mismatch in closure arguments | ||
--> $DIR/closure-arg-type-mismatch.rs:17:27 | ||
| | ||
17 | let d2 = a.iter().map(|x: (u16,u16)| 45); | ||
| ^^^ ----------------- takes a `std::ops::FnMut<((u16, u16),)>` | ||
| | | ||
| expected closure that takes a `std::ops::FnMut<(&(u32, u32),)>` | ||
|
||
error[E0622]: type mismatch in closure arguments | ||
--> $DIR/closure-arg-type-mismatch.rs:18:9 | ||
| | ||
18 | foo(|y: isize| ()); | ||
| ^^^ ------------- takes a `std::ops::Fn<(isize,)>` | ||
| | | ||
| expected closure that takes a `std::ops::Fn<(usize,)>` | ||
| | ||
= note: required by `foo` | ||
|
||
error: aborting due to 4 previous errors | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should be able to extract the types of the arguments by examining the substs of the
expected_ref
andfound
trait-refs. Something like:But it might need to be
type_at(0)
. That will give you aBinder<Ty<'tcx>>
, which you should be able to use with{}
I think.