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

nll: strange suggestion to "consider removing the * #54985

Closed
pnkfelix opened this issue Oct 11, 2018 · 9 comments
Closed

nll: strange suggestion to "consider removing the * #54985

pnkfelix opened this issue Oct 11, 2018 · 9 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-NLL Area: Non-lexical lifetimes (NLL) A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. NLL-diagnostics Working towards the "diagnostic parity" goal P-medium Medium priority

Comments

@pnkfelix
Copy link
Member

Spawned off of #54825 (comment)

For this code:

unsafe fn foo(x: *const Box<isize>) -> Box<isize> {
let y = *x; //~ ERROR cannot move out of dereference of raw pointer
return y;
}

which produces this diagnostic output:

LL | let y = *x; //~ ERROR cannot move out of dereference of raw pointer
| ^^
| |
| cannot move out of dereference of raw pointer
| help: consider removing the `*`: `x`

@nikomatsakis made this comment about the HELP on line 8:

Pre-existing but: it is...strange that we make this suggestion. It seems almost certainly wrong. It doesn't preserve the type or "intent" of the code in any particular way...? It's also distinct from what the AST checker says, which is to suggest &*x (though I would argue that is also wrong, for similar reasons). It feels like the best suggestion might be ptr::read but I'm sort of inclined to just not suggest anything at all.

@pnkfelix pnkfelix added A-NLL Area: Non-lexical lifetimes (NLL) A-diagnostics Area: Messages for errors, warnings, and lints NLL-diagnostics Working towards the "diagnostic parity" goal labels Oct 11, 2018
@estebank
Copy link
Contributor

fn add_move_hints(
&self,
error: GroupedMoveError<'tcx>,
err: &mut DiagnosticBuilder<'a>,
span: Span,
) {
let snippet = self.infcx.tcx.sess.source_map().span_to_snippet(span).unwrap();
match error {
GroupedMoveError::MovesFromPlace {
mut binds_to,
move_from,
..
} => {
let try_remove_deref = match move_from {
Place::Projection(box PlaceProjection {
elem: ProjectionElem::Deref,
..
}) => true,
_ => false,
};
if try_remove_deref && snippet.starts_with('*') {
// The snippet doesn't start with `*` in (e.g.) index
// expressions `a[b]`, which roughly desugar to
// `*Index::index(&a, b)` or
// `*IndexMut::index_mut(&mut a, b)`.
err.span_suggestion_with_applicability(
span,
"consider removing the `*`",
snippet[1..].to_owned(),
Applicability::Unspecified,
);
} else {
err.span_suggestion_with_applicability(
span,
"consider borrowing here",
format!("&{}", snippet),
Applicability::Unspecified,
);
}
binds_to.sort();
binds_to.dedup();
self.add_move_error_details(err, &binds_to);
}
GroupedMoveError::MovesFromValue { mut binds_to, .. } => {
binds_to.sort();
binds_to.dedup();
self.add_move_error_suggestions(err, &binds_to);
self.add_move_error_details(err, &binds_to);
}
// No binding. Nothing to suggest.
GroupedMoveError::OtherIllegalMove { .. } => (),
}
}

@pnkfelix
Copy link
Member Author

How bad might it be to just remove this suggestion entirely (vs attempting to fine tune when we emit it)? Can we easily weigh the good it brings vs the harm it causes?

@nikomatsakis
Copy link
Contributor

I'd prefer to just remove it entirely. I think it adds pretty little value.

@nikomatsakis
Copy link
Contributor

I could imagine using an extended error code to offer more detailed hints

@nikomatsakis
Copy link
Contributor

or else a reference to something online?

@pnkfelix
Copy link
Member Author

marking as NLL-deferred as this should not block RC2 (or even the Release, IMO).

@pnkfelix
Copy link
Member Author

NLL triage. Tagging as P-medium priority.

@pnkfelix pnkfelix added the P-medium Medium priority label Mar 20, 2019
@oli-obk oli-obk added A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. labels May 24, 2019
@oli-obk
Copy link
Contributor

oli-obk commented May 24, 2019

Diagnostics triage: marking as E-easy since it's just removing the suggestion

kungfukennyg added a commit to kungfukennyg/rust that referenced this issue Jun 4, 2019
As per issue rust-lang#54985 removes the not useful suggestion to remove asterisk in
move errors. Includes minor changes to tests in the `ui` suite to account
for the removed suggestion.
Centril added a commit to Centril/rust that referenced this issue Jun 7, 2019
…risk-suggestion, r=matthewjasper

Remove asterisk suggestion for move errors in borrowck

As per the decision in rust-lang#54985 completely removes the suggestion to add an asterisk when checking move errors. I believe I've preserved the correct behavior with the "consider borrowing here" branch of the original match arm, but I'm not positive on that.

This is my first PR to rustc so any feedback is greatly appreciated. Thanks.
Centril added a commit to Centril/rust that referenced this issue Jun 7, 2019
…risk-suggestion, r=matthewjasper

Remove asterisk suggestion for move errors in borrowck

As per the decision in rust-lang#54985 completely removes the suggestion to add an asterisk when checking move errors. I believe I've preserved the correct behavior with the "consider borrowing here" branch of the original match arm, but I'm not positive on that.

This is my first PR to rustc so any feedback is greatly appreciated. Thanks.
@awaitlink
Copy link
Contributor

Shouldn't this be closed because #61332 is now merged?

@oli-obk oli-obk closed this as completed Jun 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-NLL Area: Non-lexical lifetimes (NLL) A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. NLL-diagnostics Working towards the "diagnostic parity" goal P-medium Medium priority
Projects
None yet
Development

No branches or pull requests

6 participants