Skip to content

fix: offer 'type_mismatch' some fixes inside macro#21952

Open
A4-Tacks wants to merge 1 commit intorust-lang:masterfrom
A4-Tacks:macro-call-ty-mismatch-fixes
Open

fix: offer 'type_mismatch' some fixes inside macro#21952
A4-Tacks wants to merge 1 commit intorust-lang:masterfrom
A4-Tacks:macro-call-ty-mismatch-fixes

Conversation

@A4-Tacks
Copy link
Copy Markdown
Member

@A4-Tacks A4-Tacks commented Apr 4, 2026

  • Supports macro for add_missing_ok_or_some and str_ref_to_owned

Example

macro_rules! identity { ($($t:tt)*) => ($($t)*) }
identity! {
    fn test() -> String {
        "a"$0
    }
}

Before this PR

Invalid trigger range and edit range

After this PR

macro_rules! identity { ($($t:tt)*) => ($($t)*) }
identity! {
    fn test() -> String {
        "a".to_owned()
    }
}

macro_rules! identity { ($($t:tt)*) => ($($t)*) }
identity! {
    fn div(x: i32, y: i32) -> Result<i32, ()> {
        if y == 0 { return Err(()); }
        x / y$0
    }
}

Before this PR

Invalid trigger range and edit range

After this PR

macro_rules! identity { ($($t:tt)*) => ($($t)*) }
identity! {
    fn div(x: i32, y: i32) -> Result<i32, ()> {
        if y == 0 { return Err(()); }
        Ok(x / y)
    }
}

- Supports macro for `add_missing_ok_or_some` and `str_ref_to_owned`

Example
---
```rust
macro_rules! identity { ($($t:tt)*) => ($($t)*) }
identity! {
    fn test() -> String {
        "a"$0
    }
}
```

**Before this PR**

Invalid trigger range and edit range

**After this PR**

```rust
macro_rules! identity { ($($t:tt)*) => ($($t)*) }
identity! {
    fn test() -> String {
        "a".to_owned()
    }
}
```

---

```rust
macro_rules! identity { ($($t:tt)*) => ($($t)*) }
identity! {
    fn div(x: i32, y: i32) -> Result<i32, ()> {
        if y == 0 { return Err(()); }
        x / y$0
    }
}
```

**Before this PR**

Invalid trigger range and edit range

**After this PR**

```rust
macro_rules! identity { ($($t:tt)*) => ($($t)*) }
identity! {
    fn div(x: i32, y: i32) -> Result<i32, ()> {
        if y == 0 { return Err(()); }
        Ok(x / y)
    }
}
```
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants