11867: create generate is, as, try_into group r=Veykril a=jakevossen5
Fixes #11636
In `generate_enum_projection_method.rs`, the changes to the function are from `cargo fmt`, I made the same change as I did in `generate_enum_is_method.rs`.
Felix Maurer [Thu, 31 Mar 2022 21:00:48 +0000 (23:00 +0200)]
Prevent underflow when converting line numbers
Previously, when line numbers of Rust spans were converted to LSP
ranges, they could underflow resulting in very large line numbers. As
an underflow is always wrong, prevent it and use 0 instead.
Jonas Bushart [Thu, 31 Mar 2022 18:15:01 +0000 (18:15 +0000)]
Fix: Select correct insert position for disabled group import
The logic for importing with and without `group_imports` differed
significantly when no previous group existed. This lead to the problem
of using the wrong position when importing inside a module (#11585) or
when inner attributes are involved.
The existing code for grouped imports is better and takes these things
into account.
This PR changes the flow to use the pre-existing code for adding a new
import group even for the non-grouped import settings.
Some coverage markers are updated and the `group` is removed, since they
are now invoked in both cases (grouping and no grouping).
Tests are updated and two tests (empty module and inner attribute) are
added.
I saw a file sync bug the other day but didn't know how to further debug it. This command might give a clue as to what's wrong and help debug issues like https://github.com/rust-analyzer/rust-analyzer/issues/4829.
bors r+
Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
bors[bot] [Wed, 30 Mar 2022 13:48:50 +0000 (13:48 +0000)]
Merge #11852
11852: Type mismatch when last expression is noreturn asm r=lnicola a=weirdsmiley
When last expression in a function body is noreturn asm, then analyzer
complains about the type mismatch by highlighting entire body. This
fixes it by introducing loop {} in the expanded code.
Manas [Wed, 30 Mar 2022 13:32:27 +0000 (19:02 +0530)]
Type mismatch when last expression is noreturn asm
When last expression in a function body is noreturn asm, then analyzer
complains about the type mismatch by highlighting entire body. This
fixes it by introducing loop {} in the expanded code.
6b38c2d75 docs(auto_import): change by_self -> self and by_crate -> crate
Keep things consistent with the package.json , which uses `self` and
`crate` instead of `by_self` and `by_crate`. Both names are in fact
allowed as aliases, but we should be consistent so that people reading
the docs and using a schema do not see red squiggles.
docs(auto_import): change by_self -> self and by_crate -> crate
Keep things consistent with the package.json , which uses `self` and
`crate` instead of `by_self` and `by_crate`. Both names are in fact
allowed as aliases, but we should be consistent so that people reading
the docs and using a schema do not see red squiggles.
bors[bot] [Tue, 29 Mar 2022 16:10:20 +0000 (16:10 +0000)]
Merge #11842
11842: Fix duplicate type mismatches with blocks r=flodiebold a=flodiebold
E.g. when there's a type mismatch on the return value of a function. To fix this, we have to return the expected type as the type of the block when there's a mismatch. That meant some IDE code that expected otherwise had to be adapted, in particular the "add return type" assist. For the "wrap in Ok/Some" quickfix, this sadly means it usually can't be applied in all branches of an if expression at the same time anymore, because there's a type mismatch for each branch that has the wrong type.
Florian Diebold [Tue, 29 Mar 2022 15:51:11 +0000 (17:51 +0200)]
Fix duplicate type mismatches with blocks
E.g. when there's a type mismatch on the return value of a function. To
fix this, we have to return the expected type as the type of the block
when there's a mismatch. That meant some IDE code that expected
otherwise had to be adapted, in particular the "add return type" assist.
For the "wrap in Ok/Some" quickfix, this sadly means it usually can't be applied
in all branches of an if expression at the same time anymore, because
there's a type mismatch for each branch that has the wrong type.
bors[bot] [Tue, 29 Mar 2022 10:55:17 +0000 (10:55 +0000)]
Merge #11840
11840: Fix another const generic panic r=flodiebold a=HKalbasi
fix #11835
If I change `dyn` to `impl` in the test, it will infer the type as `IntoIterator::Item<impl Iterator<Item = [Ar<u8, 7>; 9]> + ?Sized>` instead of `[Ar<u8, 7>; 9]`. Maybe it needs some action?
bors[bot] [Fri, 25 Mar 2022 15:11:56 +0000 (15:11 +0000)]
Merge #11809
11809: feat: disable experimental diagnostics by default r=jonas-schievink a=jonas-schievink
Now that we diagnose type mismatches, we have another diagnostic that can potentially produce false positives, so let's disable experimental diagnostics by default.
Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
bors[bot] [Thu, 24 Mar 2022 09:42:09 +0000 (09:42 +0000)]
Merge #11772
11772: Support constants in const eval r=HKalbasi a=HKalbasi
This PR enables evaluating things like this:
```rust
const X: usize = 2;
const Y: usize = 3 + X; // = 5
```
My target was nalgebra's `U5`, `U22`, ... which are defined as `type U5 = Const<{ SomeType5::SOME_ASSOC_CONST }>` but I didn't find out how to find the `ConstId` of the implementation of the trait, not the trait itself (possibly related to #4558 ? We can find associated type alias, so maybe this is doable already) So it doesn't help for nalgebra currently, but it is useful anyway.
bors[bot] [Wed, 23 Mar 2022 22:45:44 +0000 (22:45 +0000)]
Merge #11806
11806: fix: Fix async block type inference using containing function return type r=Veykril a=Veykril
Fixes https://github.com/rust-analyzer/rust-analyzer/issues/11804
Should fix https://github.com/rust-analyzer/rust-analyzer/issues/11798#issuecomment-1076880521
bors[bot] [Wed, 23 Mar 2022 14:11:42 +0000 (14:11 +0000)]
Merge #11801
11801: fix: avoid returning `None` from `Span::join` to fix some proc macros r=jonas-schievink a=jonas-schievink
Some proc macros, notably rocket, `.unwrap()` the result of `Span::join` (and correctly so, it should never be `None`). We don't have a proper implementation of that API, so we always returned `None`. This changes our stub impl to return the first span instead.
Does not fully fix rocket's macros, they need other stuff to work too.
bors r+
Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
https://github.com/rust-analyzer/rust-analyzer/pull/11663 introduced a regression tracked in https://github.com/rust-analyzer/rust-analyzer/issues/11781, this fixes it.
bors[bot] [Tue, 22 Mar 2022 15:31:45 +0000 (15:31 +0000)]
Merge #11789
11789: fix: Fix lifetime elision hint configuration key r=Veykril a=Veykril
This is inconsistent with the other configuration keys unfortunately, but this is an issue of how we structured them here in general.
I feel like we'll have to do a proper pass over all the configs, check them for consistency and then write down some documentation of how our configs should be laid out, then apply fixes to the inconsistencies all at once which will entail breaking some user configurations unfortunately since we won't be able to do proper fallback handling for some of these.
bors[bot] [Tue, 22 Mar 2022 10:40:23 +0000 (10:40 +0000)]
Merge #11780
11780: feat: Add type mismatch diagnostic r=flodiebold a=flodiebold
This adds a proper diagnostic for type mismatches, turning "Add reference here", "Missing Ok or Some" and "Remove this semicolon" into quickfixes for this single diagnostic.
The diagnostic is marked as experimental when it does not have one of these quickfixes, so it can be turned off with `rust-analyzer.diagnostics.enableExperimental` (or specifically with `rust-analyzer.diagnostics.disabled` of course, the ID is `type-mismatch`).
There will still be some false positives, but I think there shouldn't be too many especially when the Chalk fix lands, and it's still experimental anyway :slightly_smiling_face:
This also fixes type checking for `rustc_legacy_const_generics` just to avoid some errors in tests.