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

Idea: Unintentional borrowing with &str return. #305

Open
bluss opened this issue Sep 6, 2015 · 3 comments · May be fixed by #13395
Open

Idea: Unintentional borrowing with &str return. #305

bluss opened this issue Sep 6, 2015 · 3 comments · May be fixed by #13395
Assignees
Labels
A-lint Area: New lints E-medium Call for participation: Medium difficulty level problem and requires some initial experience. T-middle Type: Probably requires verifiying types

Comments

@bluss
Copy link
Member

bluss commented Sep 6, 2015

This can happen, where the user uses string literals but unintentionally borrows self.

fn foo(&self) -> Result<(), &str> { Err("error") }

The lint should suggest &'static str in the return type to avoid false borrowing, if the function body uses &'static str. I guess Error::description(&self) -> &str is an exception, the borrowing is mandated by the trait.

@Manishearth Manishearth added E-medium Call for participation: Medium difficulty level problem and requires some initial experience. T-middle Type: Probably requires verifiying types A-lint Area: New lints labels Sep 6, 2015
@Manishearth
Copy link
Member

This might be nontrivial to catch, it involves walking the AST for returns, and then ensuring that all returned strings originate from static strings.

@llogiq
Copy link
Contributor

llogiq commented Sep 15, 2015

This could be a by-product of the Cow lint I'm currently writing.

@GnomedDev
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-lint Area: New lints E-medium Call for participation: Medium difficulty level problem and requires some initial experience. T-middle Type: Probably requires verifiying types
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants