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

For move errors, suggest match ergonomics instead of ref #53147

Merged
merged 27 commits into from
Aug 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7b10133
Fix some random stuff
ashtneoi Aug 2, 2018
a05f82f
Suggest match ergonomics, not `ref`/`ref mut`
ashtneoi Aug 7, 2018
3a5812b
Add more TODOs
ashtneoi Aug 7, 2018
1e87908
Accept whitespace between `&` and `mut`
ashtneoi Aug 7, 2018
54ddb36
Test move errors for index expressions
ashtneoi Aug 8, 2018
8080bdf
Fix move errors for index expressions
ashtneoi Aug 8, 2018
b05e9a7
Add backquotes around variable name
ashtneoi Aug 12, 2018
701c74e
Make move error suggestions clearer
ashtneoi Aug 12, 2018
10aaba8
Make move errors more consistent with typeck errors
ashtneoi Aug 12, 2018
8135372
Change TODOs to FIXMEs
ashtneoi Aug 12, 2018
40b5118
Remove unnecessary underscore
ashtneoi Aug 12, 2018
20ae08b
Dedup suggestions
ashtneoi Aug 13, 2018
6cf4e14
Coalesce var-is-not-Copy notes per move
ashtneoi Aug 13, 2018
0a82abc
Test patterns in tuples
ashtneoi Aug 13, 2018
a583aa6
Remove unnecessary comment
ashtneoi Aug 13, 2018
d6dbdee
Remove incorrect space
ashtneoi Aug 13, 2018
9a0020a
Bless UI tests
ashtneoi Aug 13, 2018
81c27c6
Add another FIXME about suggestions
ashtneoi Aug 14, 2018
3c3a7ba
Allocate fewer Strings at a time
ashtneoi Aug 14, 2018
6a24abb
Fix compiletest JSON error message
ashtneoi Aug 14, 2018
a5b008c
Test move-into-Fn/FnMut errors too
ashtneoi Aug 14, 2018
bd2b54c
Bless tests
ashtneoi Aug 14, 2018
671d7e0
Change a method name and clarify a comment
ashtneoi Aug 14, 2018
4c4e1ef
Add files I forgot to commit earlier
ashtneoi Aug 15, 2018
f4229b8
Re-bless test
ashtneoi Aug 15, 2018
f335fb0
Move tests into their own directory
ashtneoi Aug 16, 2018
0023dd9
Split tests more and bless them again
ashtneoi Aug 16, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,8 @@ pub enum BorrowKind {

/// Data must be immutable but not aliasable. This kind of borrow
/// cannot currently be expressed by the user and is used only in
/// implicit closure bindings. It is needed when you the closure
/// is borrowing or mutating a mutable referent, e.g.:
/// implicit closure bindings. It is needed when the closure is
/// borrowing or mutating a mutable referent, e.g.:
///
/// let x: &mut isize = ...;
/// let y = || *x += 5;
Expand All @@ -443,7 +443,7 @@ pub enum BorrowKind {
/// let y = (&mut Env { &x }, fn_ptr); // Closure is pair of env and fn
/// fn fn_ptr(env: &mut Env) { **env.x += 5; }
///
/// This is then illegal because you cannot mutate a `&mut` found
/// This is then illegal because you cannot mutate an `&mut` found
/// in an aliasable location. To solve, you'd have to translate with
/// an `&mut` borrow:
///
Expand Down Expand Up @@ -523,6 +523,8 @@ pub struct VarBindingForm<'tcx> {
/// (b) it gives a way to separate this case from the remaining cases
/// for diagnostics.
pub opt_match_place: Option<(Option<Place<'tcx>>, Span)>,
/// Span of the pattern in which this variable was bound.
pub pat_span: Span,
}

#[derive(Clone, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)]
Expand All @@ -540,7 +542,8 @@ CloneTypeFoldableAndLiftImpls! { BindingForm<'tcx>, }
impl_stable_hash_for!(struct self::VarBindingForm<'tcx> {
binding_mode,
opt_ty_info,
opt_match_place
opt_match_place,
pat_span
});

mod binding_form_impl {
Expand Down Expand Up @@ -673,7 +676,7 @@ pub struct LocalDecl<'tcx> {
/// ROOT SCOPE
/// │{ argument x: &str }
/// │
/// │ │{ #[allow(unused_mut] } // this is actually split into 2 scopes
/// │ │{ #[allow(unused_mut)] } // this is actually split into 2 scopes
/// │ │ // in practice because I'm lazy.
/// │ │
/// │ │← x.source_info.scope
Expand Down Expand Up @@ -710,6 +713,7 @@ impl<'tcx> LocalDecl<'tcx> {
binding_mode: ty::BindingMode::BindByValue(_),
opt_ty_info: _,
opt_match_place: _,
pat_span: _,
}))) => true,

// FIXME: might be able to thread the distinction between
Expand All @@ -729,6 +733,7 @@ impl<'tcx> LocalDecl<'tcx> {
binding_mode: ty::BindingMode::BindByValue(_),
opt_ty_info: _,
opt_match_place: _,
pat_span: _,
}))) => true,

Some(ClearCrossCrate::Set(BindingForm::ImplicitSelf)) => true,
Expand Down Expand Up @@ -906,7 +911,7 @@ pub enum TerminatorKind<'tcx> {

/// Drop the Place and assign the new value over it. This ensures
/// that the assignment to `P` occurs *even if* the destructor for
/// place unwinds. Its semantics are best explained by by the
/// place unwinds. Its semantics are best explained by the
/// elaboration:
///
/// ```
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_borrowck/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
ty::BindByReference(..) => {
let let_span = self.tcx.hir.span(node_id);
let suggestion = suggest_ref_mut(self.tcx, let_span);
if let Some((let_span, replace_str)) = suggestion {
if let Some(replace_str) = suggestion {
db.span_suggestion(
let_span,
"use a mutable reference instead",
Expand Down
Loading