Skip to content

Commit 4e5fe04

Browse files
committed
Do not report errors from move path builder.
1 parent 3d2b696 commit 4e5fe04

File tree

11 files changed

+288
-155
lines changed

11 files changed

+288
-155
lines changed

compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ mod mutability_errors;
4646
mod region_errors;
4747

4848
pub(crate) use bound_region_errors::{ToUniverseInfo, UniverseInfo};
49+
pub(crate) use move_errors::MoveError;
4950
pub(crate) use mutability_errors::AccessKind;
5051
pub(crate) use outlives_suggestion::OutlivesSuggestionBuilder;
5152
pub(crate) use region_errors::{ErrorConstraintInfo, RegionErrorKind, RegionErrors};

compiler/rustc_borrowck/src/diagnostics/move_errors.rs

Lines changed: 70 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
11
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed};
22
use rustc_middle::mir::*;
33
use rustc_middle::ty;
4-
use rustc_mir_dataflow::move_paths::{
5-
IllegalMoveOrigin, IllegalMoveOriginKind, LookupResult, MoveError, MovePathIndex,
6-
};
4+
use rustc_mir_dataflow::move_paths::{IllegalMoveOriginKind, LookupResult, MovePathIndex};
75
use rustc_span::{BytePos, Span};
86

97
use crate::diagnostics::CapturedMessageOpt;
108
use crate::diagnostics::{DescribePlaceOpt, UseSpans};
119
use crate::prefixes::PrefixSet;
1210
use crate::MirBorrowckCtxt;
1311

12+
#[derive(Debug)]
13+
pub(crate) struct MoveError<'tcx> {
14+
place: Place<'tcx>,
15+
location: Location,
16+
kind: IllegalMoveOriginKind<'tcx>,
17+
}
18+
19+
impl<'tcx> MoveError<'tcx> {
20+
pub(crate) fn new(
21+
place: Place<'tcx>,
22+
location: Location,
23+
kind: IllegalMoveOriginKind<'tcx>,
24+
) -> Self {
25+
MoveError { place, location, kind }
26+
}
27+
}
28+
1429
// Often when desugaring a pattern match we may have many individual moves in
1530
// MIR that are all part of one operation from the user's point-of-view. For
1631
// example:
@@ -53,87 +68,77 @@ enum GroupedMoveError<'tcx> {
5368
}
5469

5570
impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
56-
pub(crate) fn report_move_errors(&mut self, move_errors: Vec<(Place<'tcx>, MoveError<'tcx>)>) {
57-
let grouped_errors = self.group_move_errors(move_errors);
71+
pub(crate) fn report_move_errors(&mut self) {
72+
let grouped_errors = self.group_move_errors();
5873
for error in grouped_errors {
5974
self.report(error);
6075
}
6176
}
6277

63-
fn group_move_errors(
64-
&self,
65-
errors: Vec<(Place<'tcx>, MoveError<'tcx>)>,
66-
) -> Vec<GroupedMoveError<'tcx>> {
78+
fn group_move_errors(&mut self) -> Vec<GroupedMoveError<'tcx>> {
6779
let mut grouped_errors = Vec::new();
68-
for (original_path, error) in errors {
69-
self.append_to_grouped_errors(&mut grouped_errors, original_path, error);
80+
let errors = std::mem::take(&mut self.move_errors);
81+
for error in errors {
82+
self.append_to_grouped_errors(&mut grouped_errors, error);
7083
}
7184
grouped_errors
7285
}
7386

7487
fn append_to_grouped_errors(
7588
&self,
7689
grouped_errors: &mut Vec<GroupedMoveError<'tcx>>,
77-
original_path: Place<'tcx>,
7890
error: MoveError<'tcx>,
7991
) {
80-
match error {
81-
MoveError::UnionMove { .. } => {
82-
unimplemented!("don't know how to report union move errors yet.")
83-
}
84-
MoveError::IllegalMove { cannot_move_out_of: IllegalMoveOrigin { location, kind } } => {
85-
// Note: that the only time we assign a place isn't a temporary
86-
// to a user variable is when initializing it.
87-
// If that ever stops being the case, then the ever initialized
88-
// flow could be used.
89-
if let Some(StatementKind::Assign(box (
90-
place,
91-
Rvalue::Use(Operand::Move(move_from)),
92-
))) = self.body.basic_blocks[location.block]
93-
.statements
94-
.get(location.statement_index)
95-
.map(|stmt| &stmt.kind)
92+
let MoveError { place: original_path, location, kind } = error;
93+
94+
// Note: that the only time we assign a place isn't a temporary
95+
// to a user variable is when initializing it.
96+
// If that ever stops being the case, then the ever initialized
97+
// flow could be used.
98+
if let Some(StatementKind::Assign(box (place, Rvalue::Use(Operand::Move(move_from))))) =
99+
self.body.basic_blocks[location.block]
100+
.statements
101+
.get(location.statement_index)
102+
.map(|stmt| &stmt.kind)
103+
{
104+
if let Some(local) = place.as_local() {
105+
let local_decl = &self.body.local_decls[local];
106+
// opt_match_place is the
107+
// match_span is the span of the expression being matched on
108+
// match *x.y { ... } match_place is Some(*x.y)
109+
// ^^^^ match_span is the span of *x.y
110+
//
111+
// opt_match_place is None for let [mut] x = ... statements,
112+
// whether or not the right-hand side is a place expression
113+
if let LocalInfo::User(BindingForm::Var(VarBindingForm {
114+
opt_match_place: Some((opt_match_place, match_span)),
115+
binding_mode: _,
116+
opt_ty_info: _,
117+
pat_span: _,
118+
})) = *local_decl.local_info()
96119
{
97-
if let Some(local) = place.as_local() {
98-
let local_decl = &self.body.local_decls[local];
99-
// opt_match_place is the
100-
// match_span is the span of the expression being matched on
101-
// match *x.y { ... } match_place is Some(*x.y)
102-
// ^^^^ match_span is the span of *x.y
103-
//
104-
// opt_match_place is None for let [mut] x = ... statements,
105-
// whether or not the right-hand side is a place expression
106-
if let LocalInfo::User(BindingForm::Var(VarBindingForm {
107-
opt_match_place: Some((opt_match_place, match_span)),
108-
binding_mode: _,
109-
opt_ty_info: _,
110-
pat_span: _,
111-
})) = *local_decl.local_info()
112-
{
113-
let stmt_source_info = self.body.source_info(location);
114-
self.append_binding_error(
115-
grouped_errors,
116-
kind,
117-
original_path,
118-
*move_from,
119-
local,
120-
opt_match_place,
121-
match_span,
122-
stmt_source_info.span,
123-
);
124-
return;
125-
}
126-
}
120+
let stmt_source_info = self.body.source_info(location);
121+
self.append_binding_error(
122+
grouped_errors,
123+
kind,
124+
original_path,
125+
*move_from,
126+
local,
127+
opt_match_place,
128+
match_span,
129+
stmt_source_info.span,
130+
);
131+
return;
127132
}
128-
129-
let move_spans = self.move_spans(original_path.as_ref(), location);
130-
grouped_errors.push(GroupedMoveError::OtherIllegalMove {
131-
use_spans: move_spans,
132-
original_path,
133-
kind,
134-
});
135133
}
136134
}
135+
136+
let move_spans = self.move_spans(original_path.as_ref(), location);
137+
grouped_errors.push(GroupedMoveError::OtherIllegalMove {
138+
use_spans: move_spans,
139+
original_path,
140+
kind,
141+
});
137142
}
138143

139144
fn append_binding_error(

0 commit comments

Comments
 (0)