Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract function doesn't preserve unsafety #5814

Closed
Tracked by #2183
panstromek opened this issue Jul 27, 2020 · 0 comments · Fixed by #5819
Closed
Tracked by #2183

Extract function doesn't preserve unsafety #5814

panstromek opened this issue Jul 27, 2020 · 0 comments · Fixed by #5819
Labels
bug help wanted subsystem::refactoring Issues related to refactorings

Comments

@panstromek
Copy link
Contributor

panstromek commented Jul 27, 2020

Problem description

Extracting block of unsafe code from unsafe function doesn't preserve its unsafety (ie. the code is not wrapped in unsafe block and the extracted function is also not unsafe.

Steps to reproduce

Before:

unsafe fn this_is_unsafe (ptr : *const u32) -> u32 {
    <span>*ptr<span>
}

After

// this code doesn't compile anymore 
unsafe fn this_is_unsafe (ptr : *const u32) -> u32 {
    extracted(ptr)
}

fn extracted(ptr: *const u32) -> u32 {
    *ptr
}
@panstromek panstromek changed the title Extract function doesn Extract function doesn't preserve unsafety Jul 27, 2020
@Undin Undin added bug subsystem::refactoring Issues related to refactorings help wanted labels Jul 27, 2020
@Undin Undin mentioned this issue Jul 27, 2020
20 tasks
bors bot added a commit that referenced this issue Jul 28, 2020
5660: COMP: offer only struct fields in struct pat r=mchernyavsky a=Kobzol

This PR filters out unnecessary completions offered in struct pats.
It also adds `..` to completion, but I'm not sure if that's the right way to do it, so it's in a separate commit.

Fixes third part of #4448

5766: INSP: attach module without a parent to a parent module in AttachFileToModuleFix r=mchernyavsky a=Kobzol

#5490 added a quick fix to attach a file to a nearby module. However, for `mod.rs` files it offered only crate root files (`lib.rs`, `main.rs`) and not parent modules. So in this case:

```rust
//- foo/mod.rs
/* nothing to see here */
//- foo/bar/mod.rs
/* caret*/
```
The quick fix wasn't offered at `/*caret*/`.

After this PR, the quick fix is offered and the example code is transformed into this:

```rust
//- foo/mod.rs
mod bar;
//- foo/bar/mod.rs
```

5811: INSP: add support for trait refs in RsWrongTypeArgumentsNumberInspection r=undin a=Kobzol

`RsWrongTypeArgumentsNumberInspection` previously did not work for trait refs, for example `dyn Trait` or `impl Trait`. This PR adds support for these cases.

TODO:
- [x] run `RsRealProjectAnalysisTest`

5816: Refactoring of auto-import related code r=mchernyavsky a=Undin

These changes extract auto-import related code from `AutoImportFix` into `org.rust.ide.utils.import` package since this code widely used in different IDE features.
Also, this code is split into several separate files

As a result, a lot of code doesn't depend on `AutoImportFix`


5819: REF: add unsafe modifier to functions extracted from unsafe functions r=mchernyavsky a=Kobzol

This PR adds `unsafe` to functions extracted from `unsafe` functions. Currently the `unsafe` is added unconditionally, should I improve that?

The extracted statements would have to be scanned for unsafe operations that are not inside an `unsafe` block. Since pretty much the same code is already in `RsUnsafeExpressionAnnotator`, it should be refactored somehow to share the logic.

Fixes: #5814

Co-authored-by: Jakub Beránek <berykubik@gmail.com>
Co-authored-by: Arseniy Pendryak <a.pendryak@yandex.ru>
bors bot added a commit that referenced this issue Jul 29, 2020
5811: INSP: add support for trait refs in RsWrongTypeArgumentsNumberInspection r=undin a=Kobzol

`RsWrongTypeArgumentsNumberInspection` previously did not work for trait refs, for example `dyn Trait` or `impl Trait`. This PR adds support for these cases.

TODO:
- [x] run `RsRealProjectAnalysisTest`

5816: Refactoring of auto-import related code r=mchernyavsky a=Undin

These changes extract auto-import related code from `AutoImportFix` into `org.rust.ide.utils.import` package since this code widely used in different IDE features.
Also, this code is split into several separate files

As a result, a lot of code doesn't depend on `AutoImportFix`


5819: REF: add unsafe modifier to functions extracted from unsafe functions r=mchernyavsky a=Kobzol

This PR adds `unsafe` to functions extracted from `unsafe` functions. Currently the `unsafe` is added unconditionally, should I improve that?

The extracted statements would have to be scanned for unsafe operations that are not inside an `unsafe` block. Since pretty much the same code is already in `RsUnsafeExpressionAnnotator`, it should be refactored somehow to share the logic.

Fixes: #5814

Co-authored-by: Jakub Beránek <berykubik@gmail.com>
Co-authored-by: Arseniy Pendryak <a.pendryak@yandex.ru>
@bors bors bot closed this as completed in 2aad6ac Jul 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug help wanted subsystem::refactoring Issues related to refactorings
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants