You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Calling .into() on argument that expects Into<Type> gives confusing error #71252
When calling (x: Type)::into() in a fn that expects Into<Type> we currently emit:
error[E0283]: type annotations needed
--> src/librustc_resolve/late/diagnostics.rs:1143:21
|
1143 | err.span_note(spans.into(), "these named lifetimes are available to use");
| ^^^^^^^^^ ------------ this method call resolves to `T`
| |
| cannot infer type for type parameter `S` declared on the method `span_note`
|
= note: cannot resolve `_: std::convert::Into<rustc_span::MultiSpan>`
We should check whether T == MultiSpan and suggest the removal of the into() call.
@Duddino feel free to reach out either on this ticket or on a PR, but be warned that this has the potential to be quite involved. It is a great introduction to how some parts of rustc fit together though.
I've been looking into this for a while now, and my idea was to: Check if there a .into() call, check if the type of self was T and finally check if the argument of the function was Into. However I cannot figure how to get the type of Self. As far as my understanding goes, rustc hasn't yet inferred the type.
You can query the in-progress type table with the HirId for the expression. You're gonna have an Expr with a kind: ExprKind::MethodCall(method_name, [args including self]). From the first argument in that variant you can take the first element and get the expression for foo in foo.into(). Then you can use the HirId for that expression to do
let tables = tcx.typeck_tables_of(tcx.hir().local_def_id(hir_id));let opt_ty = tables.node_type_opt(expr.hir_id));
I do not know if we will have populated expr's type by then, but if we have, then that will give you the type of Self. Then, if you're in an FnCtxt you can use can_coerce to see if the inferred type for expr can be coerced to MultiSpan in the original example. I know this is a bit vague, but for this is inherently exploratory work :)
Activity
Duddino commentedon Apr 18, 2020
@rustbot claim
estebank commentedon Apr 18, 2020
@Duddino feel free to reach out either on this ticket or on a PR, but be warned that this has the potential to be quite involved. It is a great introduction to how some parts of
rustcfit together though.Duddino commentedon Apr 21, 2020
I've been looking into this for a while now, and my idea was to: Check if there a .into() call, check if the type of self was T and finally check if the argument of the function was Into. However I cannot figure how to get the type of Self. As far as my understanding goes, rustc hasn't yet inferred the type.
estebank commentedon Apr 21, 2020
You can query the in-progress type table with the
HirIdfor the expression. You're gonna have anExprwith akind: ExprKind::MethodCall(method_name, [args including self]). From the first argument in that variant you can take the first element and get the expression forfooinfoo.into(). Then you can use theHirIdfor that expression to doI do not know if we will have populated
expr's type by then, but if we have, then that will give you the type ofSelf. Then, if you're in anFnCtxtyou can usecan_coerceto see if the inferred type forexprcan be coerced toMultiSpanin the original example. I know this is a bit vague, but for this is inherently exploratory work :)Alexendoo commentedon Aug 5, 2020
Hi, are you still working on this issue @Duddino?
Duddino commentedon Aug 5, 2020
Alexendoo commentedon Aug 5, 2020
@rustbot release-assignment
Detect when method call on argument could be removed to fulfill faile…
Detect when method call on argument could be removed to fulfill faile…
Detect when method call on argument could be removed to fulfill faile…
Detect when method call on argument could be removed to fulfill faile…
Rollup merge of rust-lang#121100 - estebank:issue-71252, r=compiler-e…
Rollup merge of rust-lang#121100 - estebank:issue-71252, r=compiler-e…
Rollup merge of rust-lang#121100 - estebank:issue-71252, r=compiler-e…
Rollup merge of rust-lang#121100 - estebank:issue-71252, r=compiler-e…
Unrolled build for rust-lang#121100