796be88062
When suggesting a type on inference error, do not use `{closure@..}`. Instead, replace with an appropriate `fn` ptr. On the error message, use `short_ty_string` and write long types to disk. ``` error[E0284]: type annotations needed for `Select<{closure@lib.rs:2782:13}, _, Expression<'_>, _>` --> crates/lang/src/parser.rs:41:13 | 41 | let lit = select! { | ^^^ 42 | Token::Int(i) = e => Expression::new(Expr::Lit(ast::Lit::Int(i.parse().unwrap())), e.span()), | ---- type must be known at this point | = note: the full type name has been written to '/home/gh-estebank/iowo/target/debug/deps/lang-e2d6e25819442273.long-type-4587393693885174369.txt' = note: cannot satisfy `<_ as chumsky::input::Input<'_>>::Span == SimpleSpan` help: consider giving `lit` an explicit type, where the type for type parameter `I` is specified | 41 | let lit: Select<for<'a, 'b> fn(tokens::Token<'_>, &'a mut MapExtra<'_, 'b, _, _>) -> Option<Expression<'_>>, _, Expression<'_>, _> = select! { | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ``` instead of ``` error[E0284]: type annotations needed for `Select<{closure@/home/gh-estebank/.cargo/registry/src/index.crates.io-6f17d22bba15001f/chumsky-1.0.0-alpha.6/src/lib.rs:2782:13: 2782:28}, _, Expression<'_>, _>` --> crates/lang/src/parser.rs:41:13 | 41 | let lit = select! { | ^^^ 42 | Token::Int(i) = e => Expression::new(Expr::Lit(ast::Lit::Int(i.parse().unwrap())), e.span()), | ---- type must be known at this point | = note: cannot satisfy `<_ as chumsky::input::Input<'_>>::Span == SimpleSpan` help: consider giving `lit` an explicit type, where the type for type parameter `I` is specified | 41 | let lit: Select<{closure@/home/gh-estebank/.cargo/registry/src/index.crates.io-6f17d22bba15001f/chumsky-1.0.0-alpha.6/src/lib.rs:2782:13: 2782:28}, _, Expression<'_>, _> = select! { | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ``` Fix #123630.
41 lines
1.0 KiB
Rust
41 lines
1.0 KiB
Rust
#![allow(dead_code)]
|
|
#![allow(dropping_copy_types)]
|
|
|
|
// "guessing" in trait selection can affect `copy_or_move`. Check that this
|
|
// is correctly handled. I am not sure what is the "correct" behaviour,
|
|
// but we should at least not ICE.
|
|
|
|
use std::mem;
|
|
|
|
struct U([u8; 1337]);
|
|
|
|
struct S<'a,T:'a>(&'a T);
|
|
impl<'a, T> Clone for S<'a, T> { fn clone(&self) -> Self { S(self.0) } }
|
|
/// This impl triggers inference "guessing" - S<_>: Copy => _ = U
|
|
impl<'a> Copy for S<'a, Option<U>> {}
|
|
|
|
fn assert_impls_fn<R,T: Fn()->R>(_: &T){}
|
|
|
|
fn main() {
|
|
let n = None;
|
|
//~^ ERROR type annotations needed for `Option<_>`
|
|
let e = S(&n);
|
|
let f = || {
|
|
// S being copy is critical for this to work
|
|
drop(e);
|
|
mem::size_of_val(e.0)
|
|
};
|
|
assert_impls_fn(&f);
|
|
assert_eq!(f(), 1337+1);
|
|
|
|
assert_eq!((|| {
|
|
// S being Copy is not critical here, but
|
|
// we check it anyway.
|
|
let n = None;
|
|
let e = S(&n);
|
|
let ret = mem::size_of_val(e.0);
|
|
drop(e);
|
|
ret
|
|
})(), 1337+1);
|
|
}
|