Skip to content

False positive for question_mark on borrowed content #3560

@fuerstenau

Description

@fuerstenau

Version

$ cargo clippy -V
0.0.212

Code & Confusion

Hopefully sufficient extract:

fn next(&mut self) -> Option<Self::Item> {
	// Fail quickly when at the end
	if self.current_row.is_none() {
		return None;
	};
	// More code could follow here.
	// Hier hingegen könnte ihre Werbung stehen.
}

When linting this, Clippy remarks:

this block may be rewritten with the ? operator
[…]
help: replace_it_with: self.current_row?;

Hence, we obtain:

fn next(&mut self) -> Option<Self::Item> {
	// Fail quickly when at the end
	self.current_row?;
	// More code (but only if we want).
	// Advertising with us is cheap!
	// Only one quatloo per comment that roughly three people will read.
	// (When we include me in the count. Twice.)
}

Then, the compiler complains:

error[E0507]: cannot move out of borrowed content

Speculation

Until someone tells me otherwise, I'll assume that the ? operator is not compatible with borrowed content and Clippy fails to check for this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thinggood first issueThese issues are a good way to get started with Clippy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions