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

more refined suggestions for functions that return a reference #17310

Closed
antonilol opened this issue May 29, 2024 · 6 comments · Fixed by #19226
Closed

more refined suggestions for functions that return a reference #17310

antonilol opened this issue May 29, 2024 · 6 comments · Fixed by #19226
Assignees
Labels
A-completion autocompletion C-bug Category: bug E-easy

Comments

@antonilol
Copy link

antonilol commented May 29, 2024

when typing CustomByteSlice:: (see screenshot below), the first suggestion is to also borrow the result, this is fine normally, but in this case from_bytes already returns a reference (note that the result is not wrong, but does raise a clippy warning)

image

a special case for these unsized newtype wrappers is that they can't be constructed with &StructName(something), so this suggestion (see screenshot below) should not be here (unless this will be supported by rust some time in the future, but then still it is not supported now so should not be suggested as it results in code that has compile errors)

image

@antonilol antonilol added the C-feature Category: feature request label May 29, 2024
@Veykril Veykril added E-easy A-completion autocompletion C-bug Category: bug and removed C-feature Category: feature request labels May 29, 2024
@divyaranjan1905
Copy link

@rustbot claim

@divyaranjan1905
Copy link

@Veykril I'd like to take this as my first contribution to rust-analyzer. Do you have a clue about where I might look in the source code for this bug?

@Veykril
Copy link
Member

Veykril commented Aug 7, 2024

The relevant bits are here

fn path_ref_match(
completion: &CompletionContext<'_>,
path_ctx: &PathCompletionCtx,
ty: &hir::Type,
item: &mut Builder,
) {
if let Some(original_path) = &path_ctx.original_path {
// At least one char was typed by the user already, in that case look for the original path
if let Some(original_path) = completion.sema.original_ast_node(original_path.clone()) {
if let Some(ref_match) = compute_ref_match(completion, ty) {
item.ref_match(ref_match, original_path.syntax().text_range().start());
}
}
} else {
// completion requested on an empty identifier, there is no path here yet.
// FIXME: This might create inconsistent completions where we show a ref match in macro inputs
// as long as nothing was typed yet
if let Some(ref_match) = compute_ref_match(completion, ty) {
item.ref_match(ref_match, completion.position.offset);
}
}
}

@Shourya742
Copy link
Contributor

Hey @Veykril , is this still up for grab?

@Veykril
Copy link
Member

Veykril commented Feb 23, 2025

yes

@Shourya742
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-completion autocompletion C-bug Category: bug E-easy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants