intellij-rust: Quick fixes on type mismatch
A very basic type checking just merged #1727
Now it’s possible to attach quick fixes to a type mismatch
annotations (on this line). I can imagine the following quick fixes (we assume that A
is actual type, B
is expected type and so a
is a var of type A
. e.g. let a: A = ...; let _: B = a;
):
Coercions:
- If both types are numerics, we can suggest to add a cast
a as B
. - We can have a set of special cases like
str.to_string()
/String.as_str()
- We can try to find
impl From<A> for B
, and if it is exists, suggestB::from(a)
-
From
is not the one type conversion trait. We can also deal withToOwned
/AsRef
/AsMut
/Borrow
/BorrowMut
or evenTryFrom
/FromStr
- We can try to deref
*a
to match required type - We can also get more references
&a
/&mut a
- And any combinations of these, like
&*a
- Or even
&S::from(*a)
Refactorings:
- Suggest to change type of local variable/function/struct field etc. https://github.com/intellij-rust/intellij-rust/pull/5647
- Suggest to change (or add) return type in current function signature #1772
You can find examples of quick fixes in the org.rust.ide.annotator.fixes
package.
You can find more info about how to start contributing to Intellij-Rust in CONTRIBUTING.md, and some info about our architecure in ARCHITECTURE.md. If you have any questions about this issue, you can ask them right here or in our gitter. If you decided to grab this issue, please leave a comment here and put yourself in the worklist.
About this issue
- Original URL
- State: open
- Created 7 years ago
- Reactions: 1
- Comments: 16 (16 by maintainers)
Commits related to this issue
- ANN: add quick fix on numeric type mismatch This commit adds quick-fix for the numeric types mismatch, which fulfills the first bullet-point of the issue: https://github.com/intellij-rust/intellij-ru... — committed to oleg-semenov/intellij-rust by oleg-semenov 7 years ago
- ANN: add quick fix on numeric type mismatch This commit adds quick-fix for the numeric types mismatch, which fulfills the first bullet-point of the issue: https://github.com/intellij-rust/intellij-ru... — committed to oleg-semenov/intellij-rust by oleg-semenov 7 years ago
- Merge #2130 2130: ANN: add quick fix on numeric type mismatch r=vlad20012 a=oleg-semenov This commit adds quick-fix for the numeric types mismatch, which fulfills the first bullet-point of the issu... — committed to intellij-rust/intellij-rust by bors[bot] 7 years ago
- ANN: add quick fix for type mismatch when impl From<A> for B exists This commit adds quick-fix for the types mismatch when impl From<A> for B exists for actual type A and expected type B, which fulfi... — committed to oleg-semenov/intellij-rust by oleg-semenov 7 years ago
- ANN: add quick fix for type mismatch when impl From<A> for B exists This commit adds quick-fix for the types mismatch when impl From<A> for B exists for actual type A and expected type B, which fulfi... — committed to oleg-semenov/intellij-rust by oleg-semenov 7 years ago
- ANN: add quick fix for type mismatch when impl From<A> for B exists This commit adds quick-fix for the types mismatch when impl From<A> for B exists for actual type A and expected type B, which fulfi... — committed to oleg-semenov/intellij-rust by oleg-semenov 7 years ago
- Merge #2154 2154: ANN: add quick fix for type mismatch when impl From<A> for B exists r=Undin a=oleg-semenov This commit adds quick-fix for the types mismatch when impl From<A> for B exists for act... — committed to intellij-rust/intellij-rust by bors[bot] 6 years ago
- This commit adds quick-fix for the types mismatch when impl `ToOwned` for A exists and B is `Owned` type of A where A is actual type and B is expected type, which fulfills part of the forth bullet-poi... — committed to oleg-semenov/intellij-rust by oleg-semenov 6 years ago
- This commit adds quick-fix for the types mismatch when impl `ToOwned` for A exists and B is `Owned` type of A where A is actual type and B is expected type, which fulfills part of the forth bullet-poi... — committed to oleg-semenov/intellij-rust by oleg-semenov 6 years ago
- Merge #2196 2196: ANN: add quick fix for type mismatch when impl ToOwned for A exists and B is Owned type of A r=vlad20012 a=oleg-semenov This commit adds quick-fix for the types mismatch when impl... — committed to intellij-rust/intellij-rust by bors[bot] 6 years ago
- Merge #2210 2210: INSP: enable typecheck for reference types r=vlad20012 a=vlad20012 Note: typecheck is a disabled by default inspection, and this PR **do not** enables it by default =) Most of b... — committed to intellij-rust/intellij-rust by bors[bot] 6 years ago
- This commit adds quick-fix for the types mismatch when String is expected type and impl `ToString` for actual type exists. This fulfills part of the 2nd bullet-point of the issue: https://github.com/i... — committed to oleg-semenov/intellij-rust by oleg-semenov 6 years ago
- ANN: add quick fix on String type mismatch This commit adds quick-fix for the types mismatch when String is expected type and impl `ToString` for actual type exists. This fulfills part of the 2nd bul... — committed to oleg-semenov/intellij-rust by oleg-semenov 6 years ago
- ANN: add quick fix on String type mismatch This commit adds quick-fix for the types mismatch when String is expected type and impl `ToString` for actual type exists. This fulfills part of the 2nd bul... — committed to oleg-semenov/intellij-rust by oleg-semenov 6 years ago
- Merge #2305 2305: ANN: add quick fix on String type mismatch r=vlad20012 a=oleg-semenov This commit adds quick-fix for the types mismatch when String is expected type and impl `ToString` for actual... — committed to intellij-rust/intellij-rust by bors[bot] 6 years ago
- ANN: add quick fix on str/String type mismatch This commit adds quick-fix for the types mismatch when `&str` or `&mut str` is expected type and `String` is actual type. This fulfills part of the 2nd ... — committed to oleg-semenov/intellij-rust by oleg-semenov 6 years ago
- ANN: add quick fix on str/String type mismatch This commit adds quick-fix for the types mismatch when `&str` or `&mut str` is expected type and `String` is actual type. This fulfills part of the 2nd ... — committed to oleg-semenov/intellij-rust by oleg-semenov 6 years ago
- Merge #2309 2309: ANN: add quick fix on str/String type mismatch r=vlad20012 a=oleg-semenov This commit adds quick-fix for the types mismatch when `&str` or `&mut str` is expected type and `String`... — committed to intellij-rust/intellij-rust by bors[bot] 6 years ago
- ANN: add type mismatch quick fix using Borrow/BorrowMut and AsRef/Mut This commit adds series of quick-fix for the types mismatch when impl `Borrow<B>`/`BorrowMut<B>/AsRef<B>/AsMut<B>` for A exists w... — committed to oleg-semenov/intellij-rust by oleg-semenov 6 years ago
- ANN: add type mismatch quick fix using Borrow/BorrowMut and AsRef/Mut This commit adds series of quick-fix for the types mismatch when impl `Borrow<B>`/`BorrowMut<B>/AsRef<B>/AsMut<B>` for A exists w... — committed to oleg-semenov/intellij-rust by oleg-semenov 6 years ago
Thanks @vlad20012, no prob, hope you feel better now. Cool, I’ll add the simple cases first.