Skip to content

Commit 8cabd20

Browse files
authored
Rollup merge of #73594 - Aaron1011:revert/move-fn-self-msg, r=petrochenkov
Revert PR #72389 - "Explain move errors that occur due to method calls involving `self" r? @petrochenkov
2 parents 02efde0 + 2959352 commit 8cabd20

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+104
-733
lines changed

src/bootstrap/test.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -554,10 +554,7 @@ impl Step for Clippy {
554554

555555
builder.add_rustc_lib_path(compiler, &mut cargo);
556556

557-
// FIXME: Disable clippy tests for now, they're failing on master
558-
// (generally this would mean a toolstate failure but we don't have
559-
// toolstate for clippy anymore).
560-
// builder.run(&mut cargo.into());
557+
builder.run(&mut cargo.into());
561558
}
562559
}
563560

src/librustc_ast_lowering/expr.rs

+5-19
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_data_structures::thin_vec::ThinVec;
99
use rustc_errors::struct_span_err;
1010
use rustc_hir as hir;
1111
use rustc_hir::def::Res;
12-
use rustc_span::source_map::{respan, DesugaringKind, ForLoopLoc, Span, Spanned};
12+
use rustc_span::source_map::{respan, DesugaringKind, Span, Spanned};
1313
use rustc_span::symbol::{sym, Ident, Symbol};
1414
use rustc_target::asm;
1515
use std::collections::hash_map::Entry;
@@ -25,7 +25,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
2525
}
2626

2727
pub(super) fn lower_expr_mut(&mut self, e: &Expr) -> hir::Expr<'hir> {
28-
let mut span = e.span;
2928
ensure_sufficient_stack(|| {
3029
let kind = match e.kind {
3130
ExprKind::Box(ref inner) => hir::ExprKind::Box(self.lower_expr(inner)),
@@ -54,7 +53,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
5453
hir::ExprKind::MethodCall(hir_seg, seg.ident.span, args, span)
5554
}
5655
ExprKind::Binary(binop, ref lhs, ref rhs) => {
57-
span = self.mark_span_with_reason(DesugaringKind::Operator, e.span, None);
5856
let binop = self.lower_binop(binop);
5957
let lhs = self.lower_expr(lhs);
6058
let rhs = self.lower_expr(rhs);
@@ -224,7 +222,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
224222
hir::Expr {
225223
hir_id: self.lower_node_id(e.id),
226224
kind,
227-
span,
225+
span: e.span,
228226
attrs: e.attrs.iter().map(|a| self.lower_attr(a)).collect::<Vec<_>>().into(),
229227
}
230228
})
@@ -239,7 +237,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
239237
}
240238

241239
fn lower_binop(&mut self, b: BinOp) -> hir::BinOp {
242-
let span = self.mark_span_with_reason(DesugaringKind::Operator, b.span, None);
243240
Spanned {
244241
node: match b.node {
245242
BinOpKind::Add => hir::BinOpKind::Add,
@@ -261,7 +258,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
261258
BinOpKind::Ge => hir::BinOpKind::Ge,
262259
BinOpKind::Gt => hir::BinOpKind::Gt,
263260
},
264-
span,
261+
span: b.span,
265262
}
266263
}
267264

@@ -1363,14 +1360,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
13631360
body: &Block,
13641361
opt_label: Option<Label>,
13651362
) -> hir::Expr<'hir> {
1366-
let orig_head_span = head.span;
13671363
// expand <head>
13681364
let mut head = self.lower_expr_mut(head);
1369-
let desugared_span = self.mark_span_with_reason(
1370-
DesugaringKind::ForLoop(ForLoopLoc::Head),
1371-
orig_head_span,
1372-
None,
1373-
);
1365+
let desugared_span = self.mark_span_with_reason(DesugaringKind::ForLoop, head.span, None);
13741366
head.span = desugared_span;
13751367

13761368
let iter = Ident::with_dummy_span(sym::iter);
@@ -1465,16 +1457,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
14651457
// `mut iter => { ... }`
14661458
let iter_arm = self.arm(iter_pat, loop_expr);
14671459

1468-
let into_iter_span = self.mark_span_with_reason(
1469-
DesugaringKind::ForLoop(ForLoopLoc::IntoIter),
1470-
orig_head_span,
1471-
None,
1472-
);
1473-
14741460
// `match ::std::iter::IntoIterator::into_iter(<head>) { ... }`
14751461
let into_iter_expr = {
14761462
let into_iter_path = &[sym::iter, sym::IntoIterator, sym::into_iter];
1477-
self.expr_call_std_path(into_iter_span, into_iter_path, arena_vec![self; head])
1463+
self.expr_call_std_path(desugared_span, into_iter_path, arena_vec![self; head])
14781464
};
14791465

14801466
let match_expr = self.arena.alloc(self.expr_match(

src/librustc_infer/infer/error_reporting/need_type_info.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
468468
let msg = if let Some(simple_ident) = pattern.simple_ident() {
469469
match pattern.span.desugaring_kind() {
470470
None => format!("consider giving `{}` {}", simple_ident, suffix),
471-
Some(DesugaringKind::ForLoop(_)) => {
471+
Some(DesugaringKind::ForLoop) => {
472472
"the element type for this iterator is not specified".to_string()
473473
}
474474
_ => format!("this needs {}", suffix),

src/librustc_metadata/rmeta/decoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1318,13 +1318,13 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
13181318
}
13191319
}
13201320

1321-
fn get_fn_param_names(&self, tcx: TyCtxt<'tcx>, id: DefIndex) -> &'tcx [Ident] {
1321+
fn get_fn_param_names(&self, tcx: TyCtxt<'tcx>, id: DefIndex) -> &'tcx [Symbol] {
13221322
let param_names = match self.kind(id) {
13231323
EntryKind::Fn(data) | EntryKind::ForeignFn(data) => data.decode(self).param_names,
13241324
EntryKind::AssocFn(data) => data.decode(self).fn_data.param_names,
13251325
_ => Lazy::empty(),
13261326
};
1327-
tcx.arena.alloc_from_iter(param_names.decode((self, tcx)))
1327+
tcx.arena.alloc_from_iter(param_names.decode(self))
13281328
}
13291329

13301330
fn exported_symbols(

src/librustc_metadata/rmeta/encoder.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use rustc_middle::ty::{self, SymbolName, Ty, TyCtxt};
3030
use rustc_serialize::{opaque, Encodable, Encoder, SpecializedEncoder, UseSpecializedEncodable};
3131
use rustc_session::config::CrateType;
3232
use rustc_span::source_map::Spanned;
33-
use rustc_span::symbol::{sym, Ident, Symbol};
33+
use rustc_span::symbol::{kw, sym, Ident, Symbol};
3434
use rustc_span::{self, ExternalSource, FileName, SourceFile, Span};
3535
use rustc_target::abi::VariantIdx;
3636
use std::hash::Hash;
@@ -1009,12 +1009,18 @@ impl EncodeContext<'tcx> {
10091009
}
10101010
}
10111011

1012-
fn encode_fn_param_names_for_body(&mut self, body_id: hir::BodyId) -> Lazy<[Ident]> {
1013-
self.tcx.dep_graph.with_ignore(|| self.lazy(self.tcx.hir().body_param_names(body_id)))
1012+
fn encode_fn_param_names_for_body(&mut self, body_id: hir::BodyId) -> Lazy<[Symbol]> {
1013+
self.tcx.dep_graph.with_ignore(|| {
1014+
let body = self.tcx.hir().body(body_id);
1015+
self.lazy(body.params.iter().map(|arg| match arg.pat.kind {
1016+
hir::PatKind::Binding(_, _, ident, _) => ident.name,
1017+
_ => kw::Invalid,
1018+
}))
1019+
})
10141020
}
10151021

1016-
fn encode_fn_param_names(&mut self, param_names: &[Ident]) -> Lazy<[Ident]> {
1017-
self.lazy(param_names.iter())
1022+
fn encode_fn_param_names(&mut self, param_names: &[Ident]) -> Lazy<[Symbol]> {
1023+
self.lazy(param_names.iter().map(|ident| ident.name))
10181024
}
10191025

10201026
fn encode_optimized_mir(&mut self, def_id: LocalDefId) {

src/librustc_metadata/rmeta/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_serialize::opaque::Encoder;
1919
use rustc_session::config::SymbolManglingVersion;
2020
use rustc_session::CrateDisambiguator;
2121
use rustc_span::edition::Edition;
22-
use rustc_span::symbol::{Ident, Symbol};
22+
use rustc_span::symbol::Symbol;
2323
use rustc_span::{self, Span};
2424
use rustc_target::spec::{PanicStrategy, TargetTriple};
2525

@@ -327,7 +327,7 @@ struct ModData {
327327
struct FnData {
328328
asyncness: hir::IsAsync,
329329
constness: hir::Constness,
330-
param_names: Lazy<[Ident]>,
330+
param_names: Lazy<[Symbol]>,
331331
}
332332

333333
#[derive(RustcEncodable, RustcDecodable)]

src/librustc_middle/hir/map/mod.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_hir::*;
1414
use rustc_index::vec::IndexVec;
1515
use rustc_span::hygiene::MacroKind;
1616
use rustc_span::source_map::Spanned;
17-
use rustc_span::symbol::{kw, Ident, Symbol};
17+
use rustc_span::symbol::{kw, Symbol};
1818
use rustc_span::Span;
1919
use rustc_target::spec::abi::Abi;
2020

@@ -374,13 +374,6 @@ impl<'hir> Map<'hir> {
374374
})
375375
}
376376

377-
pub fn body_param_names(&self, id: BodyId) -> impl Iterator<Item = Ident> + 'hir {
378-
self.body(id).params.iter().map(|arg| match arg.pat.kind {
379-
PatKind::Binding(_, _, ident, _) => ident,
380-
_ => Ident::new(kw::Invalid, rustc_span::DUMMY_SP),
381-
})
382-
}
383-
384377
/// Returns the `BodyOwnerKind` of this `LocalDefId`.
385378
///
386379
/// Panics if `LocalDefId` does not have an associated body.

src/librustc_middle/hir/mod.rs

+4-16
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ use rustc_data_structures::fingerprint::Fingerprint;
1212
use rustc_data_structures::fx::FxHashMap;
1313
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
1414
use rustc_hir::def_id::{LocalDefId, LOCAL_CRATE};
15-
use rustc_hir::*;
15+
use rustc_hir::Body;
16+
use rustc_hir::HirId;
17+
use rustc_hir::ItemLocalId;
18+
use rustc_hir::Node;
1619
use rustc_index::vec::IndexVec;
1720

1821
pub struct Owner<'tcx> {
@@ -76,20 +79,5 @@ pub fn provide(providers: &mut Providers<'_>) {
7679
};
7780
providers.hir_owner = |tcx, id| tcx.index_hir(LOCAL_CRATE).map[id].signature;
7881
providers.hir_owner_nodes = |tcx, id| tcx.index_hir(LOCAL_CRATE).map[id].with_bodies.as_deref();
79-
providers.fn_arg_names = |tcx, id| {
80-
let hir = tcx.hir();
81-
let hir_id = hir.as_local_hir_id(id.expect_local());
82-
if let Some(body_id) = hir.maybe_body_owned_by(hir_id) {
83-
tcx.arena.alloc_from_iter(hir.body_param_names(body_id))
84-
} else if let Node::TraitItem(&TraitItem {
85-
kind: TraitItemKind::Fn(_, TraitFn::Required(idents)),
86-
..
87-
}) = hir.get(hir_id)
88-
{
89-
tcx.arena.alloc_slice(idents)
90-
} else {
91-
span_bug!(hir.span(hir_id), "fn_arg_names: unexpected item {:?}", id);
92-
}
93-
};
9482
map::provide(providers);
9583
}

src/librustc_middle/lint.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,7 @@ pub fn struct_lint_level<'s, 'd>(
339339
pub fn in_external_macro(sess: &Session, span: Span) -> bool {
340340
let expn_data = span.ctxt().outer_expn_data();
341341
match expn_data.kind {
342-
ExpnKind::Root
343-
| ExpnKind::Desugaring(DesugaringKind::ForLoop(_))
344-
| ExpnKind::Desugaring(DesugaringKind::Operator) => false,
342+
ExpnKind::Root | ExpnKind::Desugaring(DesugaringKind::ForLoop) => false,
345343
ExpnKind::AstPass(_) | ExpnKind::Desugaring(_) => true, // well, it's "external"
346344
ExpnKind::Macro(MacroKind::Bang, _) => {
347345
// Dummy span for the `def_site` means it's an external macro.

src/librustc_middle/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ rustc_queries! {
723723
}
724724

725725
Other {
726-
query fn_arg_names(def_id: DefId) -> &'tcx [rustc_span::symbol::Ident] {
726+
query fn_arg_names(def_id: DefId) -> &'tcx [Symbol] {
727727
desc { |tcx| "looking up function parameter names for `{}`", tcx.def_path_str(def_id) }
728728
}
729729
/// Gets the rendered value of the specified constant or associated constant.

src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs

+7-65
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ use crate::borrow_check::{
2424
};
2525

2626
use super::{
27-
explain_borrow::BorrowExplanation, FnSelfUseKind, IncludingDowncast, RegionName,
28-
RegionNameSource, UseSpans,
27+
explain_borrow::BorrowExplanation, IncludingDowncast, RegionName, RegionNameSource, UseSpans,
2928
};
3029

3130
#[derive(Debug)]
@@ -151,70 +150,13 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
151150
format!("value moved{} here, in previous iteration of loop", move_msg),
152151
);
153152
} else {
154-
if let UseSpans::FnSelfUse { var_span, fn_call_span, fn_span, kind } =
155-
move_spans
156-
{
157-
let place_name = self
158-
.describe_place(moved_place.as_ref())
159-
.map(|n| format!("`{}`", n))
160-
.unwrap_or_else(|| "value".to_owned());
161-
match kind {
162-
FnSelfUseKind::FnOnceCall => {
163-
err.span_label(
164-
fn_call_span,
165-
&format!("{} moved due to this call", place_name),
166-
);
167-
err.span_note(
168-
var_span,
169-
"this value implements `FnOnce`, which causes it to be moved when called",
170-
);
171-
}
172-
FnSelfUseKind::Operator { self_arg } => {
173-
err.span_label(
174-
fn_call_span,
175-
&format!("{} moved due to usage in operator", place_name),
176-
);
177-
if self.fn_self_span_reported.insert(fn_span) {
178-
err.span_note(
179-
self_arg.span,
180-
"calling this operator moves the left-hand side",
181-
);
182-
}
183-
}
184-
FnSelfUseKind::Normal { self_arg, implicit_into_iter } => {
185-
if implicit_into_iter {
186-
err.span_label(
187-
fn_call_span,
188-
&format!(
189-
"{} moved due to this implicit call to `.into_iter()`",
190-
place_name
191-
),
192-
);
193-
} else {
194-
err.span_label(
195-
fn_call_span,
196-
&format!("{} moved due to this method call", place_name),
197-
);
198-
}
199-
// Avoid pointing to the same function in multiple different
200-
// error messages
201-
if self.fn_self_span_reported.insert(self_arg.span) {
202-
err.span_note(
203-
self_arg.span,
204-
&format!("this function consumes the receiver `self` by taking ownership of it, which moves {}", place_name)
205-
);
206-
}
207-
}
208-
}
209-
} else {
210-
err.span_label(move_span, format!("value moved{} here", move_msg));
211-
move_spans.var_span_label(
212-
&mut err,
213-
format!("variable moved due to use{}", move_spans.describe()),
214-
);
215-
}
153+
err.span_label(move_span, format!("value moved{} here", move_msg));
154+
move_spans.var_span_label(
155+
&mut err,
156+
format!("variable moved due to use{}", move_spans.describe()),
157+
);
216158
}
217-
if let Some(DesugaringKind::ForLoop(_)) = move_span.desugaring_kind() {
159+
if Some(DesugaringKind::ForLoop) == move_span.desugaring_kind() {
218160
let sess = self.infcx.tcx.sess;
219161
if let Ok(snippet) = sess.source_map().span_to_snippet(move_span) {
220162
err.span_suggestion(

src/librustc_mir/borrow_check/diagnostics/explain_borrow.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
509509
// Used in a closure.
510510
(LaterUseKind::ClosureCapture, var_span)
511511
}
512-
UseSpans::OtherUse(span) | UseSpans::FnSelfUse { var_span: span, .. } => {
512+
UseSpans::OtherUse(span) => {
513513
let block = &self.body.basic_blocks()[location.block];
514514

515515
let kind = if let Some(&Statement {

0 commit comments

Comments
 (0)