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

Feature Request: Diagnostic to replace trailing return <val>; with just <val> #10970

Closed
izik1 opened this issue Dec 9, 2021 · 4 comments · Fixed by #16460
Closed

Feature Request: Diagnostic to replace trailing return <val>; with just <val> #10970

izik1 opened this issue Dec 9, 2021 · 4 comments · Fixed by #16460
Assignees
Labels
A-diagnostics diagnostics / error reporting C-feature Category: feature request E-has-instructions Issue has some instructions and pointers to code to get started S-actionable Someone could pick this issue up and work on it right now

Comments

@izik1
Copy link
Contributor

izik1 commented Dec 9, 2021

Example:

#[derive(Copy, Clone, Eq, PartialEq)]
pub struct Id(pub i32);

pub fn path(next: &[Id], width: usize, u: Id, v: Id) -> Vec<Id> {
    let mut u = u;
    let mut path = vec![];
    while u != v {
        u = next[u.0 as usize * width + v.0 as usize];
        path.push(u);
    }
    return<|> path;
}

->

#[derive(Copy, Clone, Eq, PartialEq)]
pub struct Id(pub i32);

pub fn path(next: &[Id], width: usize, u: Id, v: Id) -> Vec<Id> {
    let mut u = u;
    let mut path = vec![];
    while u != v {
        u = next[u.0 as usize * width + v.0 as usize];
        path.push(u);
    }
    <|>path
}

(not actually too sure where to put the cursor)

If this does get picked up at some point: edge-case warning: the trailing semi might not exist.

I'd honestly be interested in doing this myself

@Veykril Veykril added the A-diagnostics diagnostics / error reporting label Dec 9, 2021
@Veykril
Copy link
Member

Veykril commented Dec 9, 2021

Instead of an assist this should just be a diagnostic with a fixit.

Relevant code parts to follow are https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_diagnostics/src/lib.rs and https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir/src/diagnostics.rs.

Most similar ones to this would probably be the RemoveThisSemicolon and/or ReplaceFilterMapNextWithFindMap diagnostics, so following how those work should give you insight on how to do this.

@Veykril Veykril added the E-has-instructions Issue has some instructions and pointers to code to get started label Dec 9, 2021
@lnicola lnicola added C-feature Category: feature request S-actionable Someone could pick this issue up and work on it right now labels Dec 9, 2021
@gowrizrh
Copy link
Contributor

i'd like to pick this up and work through it

@izik1
Copy link
Contributor Author

izik1 commented Dec 15, 2021

So, I have gotten started with this and am still working on it (see: https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/implementing.2010970.20.28diagnostic.20for.20trailing.20.60return.3B.60.29/near/264587951), umm, honestly, I'd like to get this done tonight or tomorrow night, life did what life is oh so good at and distracted me for a while

@Veykril Veykril changed the title Feature Request: Assist to replace trailing return <val>; with just <val> Feature Request: Diagnostic to replace trailing return <val>; with just <val> Feb 1, 2022
@davidsemakula
Copy link
Contributor

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics diagnostics / error reporting C-feature Category: feature request E-has-instructions Issue has some instructions and pointers to code to get started S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
5 participants