Commit Graph

22662 Commits

Author SHA1 Message Date
bors
e2eaa99ca1 Auto merge of #12788 - hasali19:extract-var-mut, r=jonas-schievink
Fix extract variable assist for subexpression in mutable borrow

This checks if the expression is in a mutable borrow and if so makes the extracted variable `mut`.

Closes #12786
2022-07-18 12:42:05 +00:00
Milo Mirate
be30c4daf4 chore: change str_ref_to_string to str_ref_to_owned
ToString is implemented by many different types than &str, and
represents a serialization into string data. The fact that said data is
returned as owned, is an implementation detail.

If merely copying borrowed string data to owned string data is all that
is desired, ToOwned is a much better choice, because if the user later
refactors the code such that the input is no longer an `&str`, then they
will get a compiler error instead of a mysterious change-in-behavior.
2022-07-18 08:38:14 -04:00
bors
ee2d5fed30 Auto merge of #12795 - jonas-schievink:proc-macro-abi-1.64, r=jonas-schievink
feat: Support the 1.64 nightly proc macro ABI

Should resolve https://github.com/rust-lang/rust-analyzer/issues/12600

Not sure why I thought the Rust version was the same as on beta, that's never the case (but future nightly changes can break the ABI again).
2022-07-18 12:32:46 +00:00
Jonas Schievink
6cb0746f82 Support the 1.64 nightly proc macro ABI 2022-07-18 14:31:21 +02:00
bors
8e379cec62 Auto merge of #12286 - harpsword:fix_generate_constant, r=Veykril
fix: “Generate constant” ignores the path prefix of the identifier

fix #12022

add abilities to generate constant with prefix path, even these mods in path are not exist.

## some examples

https://user-images.githubusercontent.com/10148927/168710096-59d5c594-0e4a-4ba7-bfb3-21c4b99409ea.mov

https://user-images.githubusercontent.com/10148927/168710111-cd6d3df4-58eb-4358-ae9e-791bfc408efa.mov

https://user-images.githubusercontent.com/10148927/168710115-601923b7-2164-4b9a-85a9-fbb4b29796a1.mov

https://user-images.githubusercontent.com/10148927/168710118-3d4bc9c1-758b-4e6f-9709-568fa920937d.mov
2022-07-18 10:24:53 +00:00
harpsword
b5aa3b389e fix: “Generate constant” ignores the path prefix of the identifier 2022-07-18 08:36:10 +08:00
Hasan Ali
ea19e70304 Fix extract variable assist for subexpression in mutable borrow 2022-07-17 22:42:03 +01:00
bors
897a7ec4b8 Auto merge of #12785 - Logarithmus:feature/fix-negative-const-generics, r=Veykril
fix: un-inline `ConstScalarOrPath::from_expr_opt`

Sorry, but I missed these from #12778 `@flodiebold`
2022-07-17 17:53:02 +00:00
Artur Sinila
d9336a496c
fix: un-inline ConstScalarOrPath::from_expr_opt 2022-07-17 20:35:34 +03:00
bors
db6a85d358 Auto merge of #12778 - Logarithmus:feature/fix-negative-const-generics, r=flodiebold
Support negative, `char` & `bool` const generics

Before:
![Before](https://user-images.githubusercontent.com/29541480/179379832-0c3b2a74-fef6-427e-b89f-7e31d9c37b3d.png)

After:
![After](https://user-images.githubusercontent.com/29541480/179379863-b62475dd-e7bf-41f2-b437-08dfe55951af.png)

I tried to implement stuff like `Const<{NUM1 + 3 + NUM2}>` by using already existing constant evaluation mechanism for ordinary constants, but turned out to be harder than I thought, maybe because I've never ever tinkered with compilers before
2022-07-17 17:17:39 +00:00
Artur Sinila
83177a7cfe
fix: address suggestions 2022-07-17 18:22:11 +03:00
Artur Sinila
15f73008f8
refactor: inline some variables 2022-07-17 14:55:21 +03:00
bors
667fd25164 Auto merge of #12781 - iDawer:hir_display.stack_overflow, r=lnicola
fix: Stack overflows and wrong type inference of associated type shorthands

This fixes `generic_predicates_for_param_query` comparing local IDs that belong to different definitions.

As the query is used in multiple places this fix affects various r-a features when an associated type shorthand and `impl Trait` involved. Notably inference, goto, completion, hover.

Fixes #12484
2022-07-17 11:01:15 +00:00
iDawer
a0fd58bbbe Check for local IDs belong to same definition 2022-07-17 11:43:08 +05:00
Artur Sinila
a96f0aa7cd
feat: support negative const generic parameters
* feat: support `bool` & `char` const generics
2022-07-17 04:18:53 +03:00
Artur Sinila
b9b42e8670
tests: add hover tests for const generics 2022-07-17 02:13:09 +03:00
bors
766c5f0861 Auto merge of #12689 - Veykril:macro-rec, r=Veykril
internal: Record all macro definitions in ItemScope

Fixes https://github.com/rust-lang/rust-analyzer/issues/12100

Doesn't resolve the shadowing issues though, fixing those is gonna be really tricky I believe unless we can come up with a nice scheme to "order" item tree items (using syntax ranges and file ids would be a pain and also a bad idea since that'll require us to potentially reparse files in collection).
2022-07-16 16:45:26 +00:00
bors
01d251789f Auto merge of #12539 - soruh:instanciate_empty_structs, r=Veykril
Automatically instaciate trivially instaciable structs in "Generate new" and "Fill struct fields"

As proposed in #12535 this PR changes the "Generate new" and "Fill struct fields" assist/diagnostic to instanciate structs with no fields and enums with a single empty variant.

For example:
```rust
pub enum Bar {
    Bar {},
}
struct Foo<T> {
    a: usize,
    bar: Bar,
    _phantom: std::marker::PhantomData<T>,
}
impl<T> Foo<T> {
    /* generate new */

    fn random() -> Self {
        Self { /* Fill struct fields */ }
    }
}
```

was previously:
```rust
impl<T> Foo<T> {
    fn new(a: usize, bar: Bar, _phantom: std::marker::PhantomData<T>) -> Self {
        Self { a, bar, _phantom }
    }

    fn random() -> Self {
        Self {
            a: todo!(),
            bar: todo!(),
            _phantom: todo!(),
        }
    }
}
```

and is now:
```rust
impl<T> Foo<T> {
  fn new(a: usize) -> Self {
      Self {
          a,
          bar: Bar::Bar {},
          _phantom: std::marker::PhantomData
      }
  }

  fn random() -> Self {
      Self {
          a: todo!(),
          bar: Bar::Bar {},
          _phantom: std::marker::PhantomData,
      }
  }
}
```

I'd be happy about any suggestions.

## TODO
   - [x]  deduplicate `use_trivial_constructor` (unclear how to do as it's used in two separate crates)
   - [x]  write tests

Closes #12535
2022-07-16 16:36:57 +00:00
bors
ac526e029a Auto merge of #12712 - harpsword:fix-rename-crate-root, r=Veykril
fix: ignore renames for crate root

close #12684 . I just ignore renames for crate root in `rename_mod` func.
2022-07-16 16:28:41 +00:00
bors
3d7da510f9 Auto merge of #12775 - flodiebold:syntax-fixup-if, r=flodiebold
fix: Improve syntax fixup a bit, handle incomplete `if`

- allow appending tokens after a token, not just a node
- allow inserting delimiters (and remove them again)
- fix up `if {}` and `if` without anything following
2022-07-16 11:05:19 +00:00
Florian Diebold
0a4065d12d Improve syntax fixup a bit, handle incomplete if
- allow appending tokens after a token, not just a node
- allow inserting delimiters (and remove them again)
- fix up `if {}` and `if` without anything following
2022-07-16 13:03:32 +02:00
bors
f2c2c36efe Auto merge of #12776 - matklad:nosu, r=matklad
try fixing spurious CI failures on windows

It seems like it may be related to self-update? Anyways, I think we
should be disabling self-update on CI
2022-07-16 10:45:34 +00:00
Aleksey Kladov
c205c629ef try fixing spurious CI failures on windows
It seems like it may be related to self-update? Anyways, I think we
should be disabling self-update on CI
2022-07-16 11:42:28 +01:00
bors
96481b7786 Auto merge of #12773 - Veykril:self-compl, r=Veykril
fix: Improve self param completion applicability

Fixes https://github.com/rust-lang/rust-analyzer/issues/9522
2022-07-16 10:28:52 +00:00
Lukas Wirth
b96f8f18b0 fix: Improve self param completion applicability 2022-07-16 12:28:41 +02:00
bors
d3796adeaa Auto merge of #12772 - Veykril:nameres, r=Veykril
internal: Remove allocation in DefCollector::reseed_with_unresolved_attribute
2022-07-16 09:50:22 +00:00
bors
2e9d5b59a6 Auto merge of #12766 - Veykril:completion-vis, r=Veykril
fix: Don't show qualified path completions for private items

Fixes https://github.com/rust-lang/rust-analyzer/issues/12703
2022-07-16 09:29:20 +00:00
Lukas Wirth
25090f0e6d internal: Remove allocation in DefCollector::reseed_with_unresolved_attribute 2022-07-16 11:17:15 +02:00
bors
4ad9185778 Auto merge of #12764 - matklad:rustupaction, r=lnicola
Remove deprecate action

https://old.reddit.com/r/rust/comments/vyx4oj/actionsrs_organization_became_unmaintained/

Looking at this holistically, I don't fully understand *why* we need an
action here? Seems like we can just use rustup? nowadays github runners
come with rustup pre-installed.
2022-07-16 05:28:32 +00:00
Aleksey Kladov
b49f2a2b43 Remove deprecate action
https://old.reddit.com/r/rust/comments/vyx4oj/actionsrs_organization_became_unmaintained/

Looking at this holistically, I don't fully understand *why* we need an
action here? Seems like we can just use rustup? nowadays github runners
come with rustup pre-installed.
2022-07-15 23:04:09 +01:00
Aleksey Kladov
248fa55fc7 Update .github/workflows/release.yaml
Co-authored-by: Laurențiu Nicola <lnicola@users.noreply.github.com>
2022-07-15 23:04:09 +01:00
Aleksey Kladov
f4fe2ea227 Remove deprecate action
https://old.reddit.com/r/rust/comments/vyx4oj/actionsrs_organization_became_unmaintained/

Looking at this holistically, I don't fully understand *why* we need an
action here? Seems like we can just use rustup? nowadays github runners
come with rustup pre-installed.
2022-07-15 23:04:09 +01:00
Lukas Wirth
7ff6c36716 fix: Don't show qualified path completions for private items 2022-07-15 13:30:43 +02:00
bors
029184d977 Auto merge of #12765 - Veykril:import-insert-fix, r=Veykril
fix: Fix imports being inserted before doc comments in inline modules

Fixes https://github.com/rust-lang/rust-analyzer/issues/12758
2022-07-14 20:57:22 +00:00
Lukas Wirth
6b823b0234 fix: Fix imports being inserted before doc comments in inline modules 2022-07-14 22:56:56 +02:00
bors
073b3253c1 Auto merge of #12556 - DorianListens:dscheidt/generic-extract, r=Veykril
fix: Support generics in extract_function assist

This change attempts to resolve issue #7636: Extract into Function does not
create a generic function with constraints when extracting generic code.

In `FunctionBody::analyze_container`, we now traverse the `ancestors` in search
of `AnyHasGenericParams`, and attach any `GenericParamList`s and `WhereClause`s
we find to the `ContainerInfo`.

Later, in `format_function`, we collect all the `GenericParam`s and
`WherePred`s from the container, and filter them to keep only types matching
`TypeParam`s used within the newly extracted function body or param list. We
can then include the new `GenericParamList` and `WhereClause` in the new
function definition.

This change only impacts `TypeParam`s. `LifetimeParam`s and `ConstParam`s are
out of scope for this change.

I've never contributed to this project before, but I did try to follow the style guide. I believe that this change represents an improvement over the status quo, but I think it's also fair to argue that it doesn't fully "fix" the linked issue. I'm totally open to merging this as is, or going further to try to make a more complete solution. Also: if there are other unit or integration tests I should add, please let me know where to look!
2022-07-14 14:29:37 +00:00
bors
fbba1d7acb Auto merge of #12691 - Veykril:proc-macro-diag, r=Veykril
fix: Fix unresolved proc macro diagnostics pointing to macro expansions

Fixes https://github.com/rust-lang/rust-analyzer/issues/12657
2022-07-14 14:21:16 +00:00
bors
5af3ef527c Auto merge of #12735 - feniljain:fix-completions, r=feniljain
fix(completion): `super::` completion at crate root and module depth aware

- should close #12439
- Suggest super according to the depth in tree
2022-07-14 11:53:29 +00:00
feniljain
4cbde4ed8f fix(completion): super:: completion at crate root and module depth
aware
2022-07-14 17:07:43 +05:30
Dorian Scheidt
796641b5d8 Make search for applicable generics more precise 2022-07-13 14:54:17 -05:00
Dorian Scheidt
075ab03851 fix: Support generics in extract_function assist
This change attempts to resolve issue #7636: Extract into Function does not
create a generic function with constraints when extracting generic code.

In `FunctionBody::analyze_container`, we now traverse the `ancestors` in search
of `AnyHasGenericParams`, and attach any `GenericParamList`s and `WhereClause`s
we find to the `ContainerInfo`.

Later, in `format_function`, we collect all the `GenericParam`s and
`WherePred`s from the container, and filter them to keep only types matching
`TypeParam`s used within the newly extracted function body or param list. We
can then include the new `GenericParamList` and `WhereClause` in the new
function definition.

This change only impacts `TypeParam`s. `LifetimeParam`s and `ConstParam`s are
out of scope for this change.
2022-07-13 14:54:10 -05:00
soruh
a5ad4de111 add tests 2022-07-13 16:16:48 +02:00
bors
794ecd58a3 Auto merge of #12755 - Veykril:server-version, r=lnicola
fix: Set server binary version when distributing
2022-07-13 12:00:16 +00:00
Lukas Wirth
ec51dcbbc7 fix: Set server binary version when distributing 2022-07-13 13:34:04 +02:00
bors
90b509702e Auto merge of #12754 - Veykril:vscode-status, r=Veykril
fix: Fix VSCode status bar tooltip not showing the error messages
2022-07-13 11:29:12 +00:00
Lukas Wirth
def89af1ef fix: Fix VSCode status bar tooltip not showing the error messages 2022-07-13 13:26:23 +02:00
bors
fc47ce53c8 Auto merge of #12696 - hi-rustin:rustin-patch-fix, r=Veykril
Add str_ref_to_string fix

close https://github.com/rust-lang/rust-analyzer/issues/11383
When type mismatch is `&str` -> `String` try to fix it.
2022-07-13 09:57:51 +00:00
bors
84a6bc99ad Auto merge of #12742 - TonalidadeHidrica:fix-obsolete-config-keys, r=Veykril
Fix obsolete config keys

The config keys were drastically reorganized by #12010, but the docs don't reflect the updates, causing inconsistency and confusion.  I checked for such obsolete configuration keys and updated to the new one.  For reproducibility, I attach a small shell script that I used to examine the old keys.  Now the script only detects `cargoExtraArgs` and `overrideCargo`, which originates from other type definition in the code but not from the configuration.

<details><summary>script</summary>

```bash
echo "allowMergingIntoGlobImports
exprFillDefault
importEnforceGranularity
importGranularity
importMergeBehavior
importMergeBehaviour
importGroup
importPrefix
warmup
loadOutDirsFromCheck
runBuildScripts
runBuildScriptsCommand
useRustcWrapperForBuildScripts
enableExperimental
procAttrMacros
breakPoints
exitPoints
yieldPoints
linksInHover
linksInHover
gotoTypeDef
chainingHints
closureReturnTypeHints
hideNamedConstructorHints
parameterHints
reborrowHints
typeHints
lruCapacity
cargoExtraArgs
overrideCargo
rustcSource
enableRangeFormatting
assist\.allowMergingIntoGlobImports
assist\.exprFillDefault
assist\.importEnforceGranularity
assist\.importGranularity
assist\.importMergeBehavior
assist\.importMergeBehaviour
assist\.importGroup
assist\.importPrefix
primeCaches\.enable
cache\.warmup
cargo\.loadOutDirsFromCheck
cargo\.runBuildScripts
cargo\.runBuildScriptsCommand
cargo\.useRustcWrapperForBuildScripts
completion\.snippets
diagnostics\.enableExperimental
experimental\.procAttrMacros
highlighting\.strings
highlightRelated\.breakPoints
highlightRelated\.exitPoints
highlightRelated\.yieldPoints
highlightRelated\.references
hover\.documentation
hover\.linksInHover
hoverActions\.linksInHover
hoverActions\.debug
hoverActions\.enable
hoverActions\.gotoTypeDef
hoverActions\.implementations
hoverActions\.references
hoverActions\.run
inlayHints\.chainingHints
inlayHints\.closureReturnTypeHints
inlayHints\.hideNamedConstructorHints
inlayHints\.parameterHints
inlayHints\.reborrowHints
inlayHints\.typeHints
lruCapacity
runnables\.cargoExtraArgs
runnables\.overrideCargo
rustcSource
rustfmt\.enableRangeFormatting
allFeatures
addCallArgumentSnippets
addCallParenthesis
callInfo\.full
cargo\.allFeatures
checkOnSave\.allFeatures
completion\.addCallArgumentSnippets
completion\.addCallParenthesis" | while read -r pattern
do
  rg '\b'$pattern'\b([^.]|$)' . -g "!crates/rust-analyzer/src/config/patch_old_style.rs" -g "!editors/code/src/config.ts" -g "!a.sh" --no-heading --color=always --line-number
done

exit

excluded
# debug
# enable
# run
# implementations
# references
# documentation
# references
# snippets
# strings
# full
```

</details>
2022-07-13 09:46:26 +00:00
bors
4cbf23c192 Auto merge of #12747 - jonas-schievink:proc-macro-abi-1.63, r=jonas-schievink
fix: Update 1.63 proc macro ABI to match rustc

This updates us to the ABI used by rustc 1.63.0-beta.5, which will likely be the ABI of the next stable Rust release. It should also work on nightly (for now, but future changes won't be supported until the rustc version is bumped).

cc https://github.com/rust-lang/rust-analyzer/issues/12600
2022-07-12 13:29:25 +00:00
Jonas Schievink
ebfbb314c0 Update 1.63 proc macro ABI to match rustc 2022-07-12 15:19:31 +02:00