Skip to content

Rollup of 9 pull requests #104809

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

Merged
merged 129 commits into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
129 commits
Select commit Hold shift + click to select a range
7c56896
Feat: extracted method from trait impl is placed in existing impl
Aug 9, 2022
7402366
Avoid cloning IMPL node if we don't have to
Aug 10, 2022
d5e6aa3
Pre-cast impl nodes to ast::Impl in find_non_trait_impl
Sep 1, 2022
c98fc53
Generalize reborrow hints as adjustment hints
Veykril Nov 4, 2022
95d20fc
Add adjustment hint tests
Veykril Nov 4, 2022
d841ad1
Fix up adjustment hints configurations
Veykril Nov 4, 2022
e468a1a
internal: Optimize `apply_document_changes` a bit
Veykril Nov 4, 2022
28afe57
Add tests for LineEndings::normalize
Veykril Nov 5, 2022
b87a23b
Rename convertor -> converter
lowr Nov 2, 2022
41b0c54
Fix `tt::Punct`'s spacing calculation
lowr Nov 5, 2022
1dcc25a
internal: Use a process group for flycheck
Veykril Nov 5, 2022
7742077
Auto merge of #13552 - Veykril:flycheck-process-group, r=Veykril
bors Nov 7, 2022
f54c313
Auto merge of #13547 - Veykril:line-index, r=Veykril
bors Nov 7, 2022
cff7ab1
Fix typos
lnicola Nov 7, 2022
364820a
Auto merge of #13566 - lnicola:therefor, r=lnicola
bors Nov 7, 2022
f24fbc2
rustfmt
Veykril Nov 7, 2022
8ad4a1d
Update sysroot crates
Veykril Nov 7, 2022
d3d3806
Auto merge of #12991 - TiddoLangerak:extract-method-from-trait-into-i…
bors Nov 7, 2022
180b4ce
Fix the length displayed for byte string literals with escaped newlines
noritada Nov 7, 2022
c0310c1
Auto merge of #13565 - Veykril:sysroot, r=Veykril
bors Nov 7, 2022
ee2dd93
Don't trigger adjustment hints in all inlay hint tests
Veykril Nov 7, 2022
ffd7bf8
Bump Cargo rust-version fields to latest stable
Veykril Nov 7, 2022
bdf8547
Clarify the intent
noritada Nov 7, 2022
3a839ea
Auto merge of #13569 - Veykril:rust-version, r=Veykril
bors Nov 7, 2022
b0e56ef
Auto merge of #13545 - Veykril:adjustment-hints, r=Veykril
bors Nov 7, 2022
2340d70
Add test code for unescaping byte strings
noritada Nov 7, 2022
b169e1e
Remove code duplication
Veykril Nov 7, 2022
8a633fe
Auto merge of #13570 - Veykril:dedup-crates-for, r=Veykril
bors Nov 7, 2022
d1c9775
Auto merge of #13568 - noritada:fix/len-of-byte-string-with-escaped-n…
bors Nov 7, 2022
6a06f6f
Deduplicate reference search results
Veykril Nov 7, 2022
a27e4da
Auto merge of #13571 - Veykril:unique-references, r=Veykril
bors Nov 7, 2022
fa70b0a
internal: Use Cancellable in favor of Result for clarity
Veykril Nov 7, 2022
0aa0da9
Auto merge of #13572 - Veykril:cancellable, r=Veykril
bors Nov 7, 2022
1cb6ab8
internal: error instead of panic on invalid file range
Veykril Nov 7, 2022
b8b1951
Auto merge of #13573 - Veykril:invalid-file-range, r=Veykril
bors Nov 7, 2022
90e2db8
fix: Fix item completions not working properly after unit structs and…
Veykril Nov 8, 2022
236c116
Auto merge of #13581 - Veykril:unit-struct-compl, r=Veykril
bors Nov 8, 2022
4403dde
Nest Cargo.lock under Cargo.toml in Code
lnicola Nov 8, 2022
977a029
Auto merge of #13582 - lnicola:nest-cargo-toml, r=lnicola
bors Nov 8, 2022
9be0615
Don't canonicalize self type when querying FnOnce signature
Nov 8, 2022
392784a
Auto merge of #13584 - jonas-schievink:fix-signature-panic, r=jonas-s…
bors Nov 8, 2022
3c35d44
Add proc-macro dependency to rustc_private crates
Veykril Nov 9, 2022
599142c
Auto merge of #13590 - Veykril:proc-macro-rustc-src, r=Veykril
bors Nov 9, 2022
4f415fc
Ignore outermost non-delimited `Subtree` when reversing fixups
lowr Nov 10, 2022
5b07061
Test `TokenTree`s' equality modulo `Punct`s' spacing
lowr Nov 10, 2022
dea49d0
fix: check visibility of each segment in path resolution
lowr Nov 11, 2022
e75afeb
Resolve invisible defs in `fix_visibility` assist
lowr Nov 11, 2022
19306c0
Fix tests that depended on loose visibility restriction
lowr Nov 11, 2022
e35836e
Send status notification if there are no found workspaces
Veykril Nov 11, 2022
ff78d24
Auto merge of #13603 - Veykril:no-workspaces, r=Veykril
bors Nov 11, 2022
6f313ce
Auto merge of #13548 - lowr:fix/tt-punct-spacing, r=Veykril
bors Nov 11, 2022
57cc2a6
Auto merge of #13602 - lowr:fix/nameres-transitive-visibility, r=Veykril
bors Nov 11, 2022
e50712c
fix: Fix hover in attributed items not preferring similar kinded tokens
Veykril Nov 11, 2022
add8539
Auto merge of #13604 - Veykril:hover-attr, r=Veykril
bors Nov 11, 2022
c6c932d
chore: Align config property
poliorcetics Sep 24, 2022
0d4737a
feat: Support passing multiple targets to cargo (for Rust 1.64.0+)
poliorcetics Sep 24, 2022
a143ff0
fix: Fix r-a eagerly showing no discovered workspace errors
Veykril Nov 11, 2022
d3531e8
Auto merge of #13605 - Veykril:empty-ws-error, r=Veykril
bors Nov 11, 2022
6674bd8
fix: Add trait alias grammar to rust.ungram
Veykril Nov 11, 2022
2656303
Auto merge of #13606 - Veykril:trait-alias, r=Veykril
bors Nov 11, 2022
6b4b7d8
internal: Add version info to unsupported proc macro abi error
Veykril Nov 11, 2022
45ec315
Auto merge of #13607 - Veykril:proc-macro-error, r=Veykril
bors Nov 11, 2022
46417ad
Update several crates to bring support for the new Tier 3 Windows tar…
mati865 Nov 13, 2022
15dfeab
Fix GAT completion not including generic parameters
Nov 15, 2022
a516b90
Auto merge of #13622 - jonas-schievink:fix-gat-completions, r=jonas-s…
bors Nov 15, 2022
7e77d4e
Strip comments and attributes off of all trait item completions
Nov 15, 2022
8292dd8
Auto merge of #13623 - jonas-schievink:strip-trait-item-completions, …
bors Nov 15, 2022
0dd0dfb
Auto merge of #13615 - mati865:miow-update, r=jonas-schievink
bors Nov 15, 2022
1ad11b5
fix: resolve inference variable before applying adjustments
lowr Nov 16, 2022
92e393c
Auto merge of #13624 - lowr:fix/unsize-array-inference-variable, r=ln…
bors Nov 16, 2022
7577c44
Update proc-macro-srv tests
lowr Nov 16, 2022
9cf5c22
Auto merge of #13625 - lowr:fix/proc-macro-src-test, r=lnicola
bors Nov 16, 2022
693c631
Throw error on failure in loading llvm-plugin
dfordivam Nov 17, 2022
cd6459e
Make "Remove dbg!()" assist work on selections
Nov 17, 2022
e162d58
Auto merge of #13629 - jonas-schievink:remove-dbg-selection, r=jonas-…
bors Nov 17, 2022
656d886
Make it more obvious which SCIP features we do not yet emit in code
Veykril Nov 18, 2022
bee27eb
Auto merge of #13632 - Veykril:scip, r=Veykril
bors Nov 18, 2022
073a63b
feat: Allow viewing the full compiler diagnostic in a readonly textview
Veykril Nov 18, 2022
8452844
Fix tests checking the data value
Veykril Nov 18, 2022
791cb87
Auto merge of #13633 - Veykril:vscode-full-diagnostics, r=Veykril
bors Nov 18, 2022
52bc15f
fix: Fix proc-macro-srv search paths for Arch Linux
Veykril Nov 18, 2022
a3f8fd7
fix: format expression parsing edge-cases
kartva Nov 19, 2022
dc8254c
fix: Fix nested macro diagnostics pointing at macro expansion files
Veykril Nov 19, 2022
ac60077
Auto merge of #13639 - Veykril:macro-diags, r=Veykril
bors Nov 19, 2022
6d4b2b4
run cargo fmt
kartva Nov 19, 2022
a4f071a
fix(assists): remove `item_const` which had default value when implem…
bvanjoi Nov 19, 2022
8050fdb
Auto merge of #13642 - bvanjoi:fix-13292, r=Veykril
bors Nov 19, 2022
2d9ed4f
Auto merge of #13641 - DesmondWillowbrook:fix-move-format-string, r=V…
bors Nov 19, 2022
38fa47f
Auto merge of #13290 - poliorcetics:multiple-targets, r=Veykril
bors Nov 19, 2022
e39d90a
Improve grammar of architecture.md
ZZzzaaKK Nov 20, 2022
ebbc549
Fix typo on 'configuration' anchor
VannTen Nov 20, 2022
75e1de8
Auto merge of #13649 - ZZzzaaKK:master, r=lnicola
bors Nov 20, 2022
2656297
Auto merge of #13653 - VannTen:fix/doc-typo-vim-lsp, r=Veykril
bors Nov 20, 2022
1e7f6a7
Pass InferCtxt to DropRangeVisitor so we can resolve vars
compiler-errors Nov 23, 2022
024bb8c
Pass ParamEnv down instead of using ParamEnv of a module
compiler-errors Nov 23, 2022
aa73e29
Improve accessibility:
GuillaumeGomez Nov 23, 2022
409203a
Use ObligationCtxt::normalize
spastorino Nov 23, 2022
37c3521
:arrow_up: rust-analyzer
lnicola Nov 23, 2022
11a5386
Move `get_associated_type` from `clippy` to `rustc_lint`
WaffleLapkin Nov 22, 2022
0d4a5c7
Make `deref_into_dyn_supertrait` lint the impl and not the usage
WaffleLapkin Nov 22, 2022
20f3de5
Use nicer spans for `deref_into_dyn_supertrait`
WaffleLapkin Nov 23, 2022
9abd785
Add regression test for issue 99938
est31 Nov 23, 2022
9e72e35
Suggest `.clone()` or `ref binding` on E0382
estebank Nov 3, 2022
4a51f37
Do not suggest `ref` multiple times for the same binding
estebank Nov 3, 2022
4f2f59b
Fix clippy code
estebank Nov 3, 2022
14a3d57
Use `type_implements_trait`
estebank Nov 3, 2022
42d7174
Extract suggestion logic to its own method
estebank Nov 3, 2022
c0e4817
Remove logic duplication
estebank Nov 3, 2022
d687d46
Tweak output in for loops
estebank Nov 3, 2022
e6e7a6d
Fix wording
estebank Nov 3, 2022
24f80ea
Fix rustfmt
estebank Nov 3, 2022
5993f5d
Tweak output to account for alternative bindings in the same pattern
estebank Nov 3, 2022
53a711f
Fix rebase
estebank Nov 3, 2022
3c905d4
review comments: inline bindings and fix typo
estebank Nov 12, 2022
3a471b5
Account for `x @ y` and suggest `ref x @ ref y`
estebank Nov 15, 2022
0da4c44
Account for closures
estebank Nov 16, 2022
78b8d12
Fix rebase
estebank Nov 23, 2022
c620a97
Disable dyn* upcasting
compiler-errors Nov 19, 2022
8f79fc2
Properly handle `Pin<&mut dyn* Trait>` receiver in codegen
compiler-errors Nov 19, 2022
b60b76c
Adjust tests
compiler-errors Nov 24, 2022
5197ef6
Rollup merge of #103908 - estebank:consider-cloning, r=compiler-errors
matthiaskrgr Nov 24, 2022
1e0df88
Rollup merge of #104517 - dfordivam:patch-1, r=cuviper
matthiaskrgr Nov 24, 2022
b43c2e7
Rollup merge of #104594 - compiler-errors:dyn-star-rcvr, r=eholk,este…
matthiaskrgr Nov 24, 2022
c08c57e
Rollup merge of #104742 - WaffleLapkin:forbidden-SUPER-deref, r=compi…
matthiaskrgr Nov 24, 2022
6938717
Rollup merge of #104753 - compiler-errors:drop-tracking-var-ice, r=ol…
matthiaskrgr Nov 24, 2022
84ff4ab
Rollup merge of #104771 - est31:if_let_chain_broken_mir_test, r=david…
matthiaskrgr Nov 24, 2022
a337156
Rollup merge of #104772 - GuillaumeGomez:small-accessibility-improvem…
matthiaskrgr Nov 24, 2022
2190b16
Rollup merge of #104775 - spastorino:use-obligation-ctxt-normalize, r…
matthiaskrgr Nov 24, 2022
1afbd6e
Rollup merge of #104778 - lnicola:rust-analyzer-2022-11-23, r=lnicola
matthiaskrgr Nov 24, 2022
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
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1376,7 +1376,7 @@ pub enum ExprKind {
/// Conditionless loop (can be exited with `break`, `continue`, or `return`).
///
/// `'label: loop { block }`
Loop(P<Block>, Option<Label>),
Loop(P<Block>, Option<Label>, Span),
/// A `match` block.
Match(P<Expr>, Vec<Arm>),
/// A closure (e.g., `move |a, b, c| a + b + c`).
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_ast/src/mut_visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1355,9 +1355,10 @@ pub fn noop_visit_expr<T: MutVisitor>(
vis.visit_block(body);
visit_opt(label, |label| vis.visit_label(label));
}
ExprKind::Loop(body, label) => {
ExprKind::Loop(body, label, span) => {
vis.visit_block(body);
visit_opt(label, |label| vis.visit_label(label));
vis.visit_span(span);
}
ExprKind::Match(expr, arms) => {
vis.visit_expr(expr);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
visitor.visit_expr(subexpression);
visitor.visit_block(block);
}
ExprKind::Loop(block, opt_label) => {
ExprKind::Loop(block, opt_label, _) => {
walk_list!(visitor, visit_label, opt_label);
visitor.visit_block(block);
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
let span = this.mark_span_with_reason(DesugaringKind::WhileLoop, e.span, None);
this.lower_expr_while_in_loop_scope(span, cond, body, *opt_label)
}),
ExprKind::Loop(body, opt_label) => self.with_loop_scope(e.id, |this| {
ExprKind::Loop(body, opt_label, span) => self.with_loop_scope(e.id, |this| {
hir::ExprKind::Loop(
this.lower_block(body, false),
this.lower_label(*opt_label),
hir::LoopSource::Loop,
DUMMY_SP,
this.lower_span(*span),
)
}),
ExprKind::TryBlock(body) => self.lower_expr_try_block(body),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_pretty/src/pprust/state/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ impl<'a> State<'a> {
self.space();
self.print_block_with_attrs(blk, attrs);
}
ast::ExprKind::Loop(ref blk, opt_label) => {
ast::ExprKind::Loop(ref blk, opt_label, _) => {
if let Some(label) = opt_label {
self.print_ident(label.ident);
self.word_space(":");
Expand Down
224 changes: 194 additions & 30 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
);
}

self.add_moved_or_invoked_closure_note(location, used_place, &mut err);
let closure = self.add_moved_or_invoked_closure_note(location, used_place, &mut err);

let mut is_loop_move = false;
let mut in_pattern = false;
let mut seen_spans = FxHashSet::default();

for move_site in &move_site_vec {
let move_out = self.move_data.moves[(*move_site).moi];
Expand All @@ -191,37 +192,25 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
is_loop_move = true;
}

self.explain_captures(
&mut err,
span,
move_span,
move_spans,
*moved_place,
partially_str,
loop_message,
move_msg,
is_loop_move,
maybe_reinitialized_locations.is_empty(),
);

if let (UseSpans::PatUse(span), []) =
(move_spans, &maybe_reinitialized_locations[..])
{
if maybe_reinitialized_locations.is_empty() {
err.span_suggestion_verbose(
span.shrink_to_lo(),
&format!(
"borrow this field in the pattern to avoid moving {}",
self.describe_place(moved_place.as_ref())
.map(|n| format!("`{}`", n))
.unwrap_or_else(|| "the value".to_string())
),
"ref ",
Applicability::MachineApplicable,
);
in_pattern = true;
if !seen_spans.contains(&move_span) {
if !closure {
self.suggest_ref_or_clone(mpi, move_span, &mut err, &mut in_pattern);
}

self.explain_captures(
&mut err,
span,
move_span,
move_spans,
*moved_place,
partially_str,
loop_message,
move_msg,
is_loop_move,
maybe_reinitialized_locations.is_empty(),
);
}
seen_spans.insert(move_span);
}

use_spans.var_path_only_subdiag(&mut err, desired_action);
Expand Down Expand Up @@ -317,6 +306,160 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
}
}

fn suggest_ref_or_clone(
&mut self,
mpi: MovePathIndex,
move_span: Span,
err: &mut DiagnosticBuilder<'_, ErrorGuaranteed>,
in_pattern: &mut bool,
) {
struct ExpressionFinder<'hir> {
expr_span: Span,
expr: Option<&'hir hir::Expr<'hir>>,
pat: Option<&'hir hir::Pat<'hir>>,
parent_pat: Option<&'hir hir::Pat<'hir>>,
}
impl<'hir> Visitor<'hir> for ExpressionFinder<'hir> {
fn visit_expr(&mut self, e: &'hir hir::Expr<'hir>) {
if e.span == self.expr_span {
self.expr = Some(e);
}
hir::intravisit::walk_expr(self, e);
}
fn visit_pat(&mut self, p: &'hir hir::Pat<'hir>) {
if p.span == self.expr_span {
self.pat = Some(p);
}
if let hir::PatKind::Binding(hir::BindingAnnotation::NONE, _, i, sub) = p.kind {
if i.span == self.expr_span || p.span == self.expr_span {
self.pat = Some(p);
}
// Check if we are in a situation of `ident @ ident` where we want to suggest
// `ref ident @ ref ident` or `ref ident @ Struct { ref ident }`.
if let Some(subpat) = sub && self.pat.is_none() {
self.visit_pat(subpat);
if self.pat.is_some() {
self.parent_pat = Some(p);
}
return;
}
}
hir::intravisit::walk_pat(self, p);
}
}
let hir = self.infcx.tcx.hir();
if let Some(hir::Node::Item(hir::Item {
kind: hir::ItemKind::Fn(_, _, body_id),
..
})) = hir.find(hir.local_def_id_to_hir_id(self.mir_def_id()))
&& let Some(hir::Node::Expr(expr)) = hir.find(body_id.hir_id)
{
let place = &self.move_data.move_paths[mpi].place;
let span = place.as_local()
.map(|local| self.body.local_decls[local].source_info.span);
let mut finder = ExpressionFinder {
expr_span: move_span,
expr: None,
pat: None,
parent_pat: None,
};
finder.visit_expr(expr);
if let Some(span) = span && let Some(expr) = finder.expr {
for (_, expr) in hir.parent_iter(expr.hir_id) {
if let hir::Node::Expr(expr) = expr {
if expr.span.contains(span) {
// If the let binding occurs within the same loop, then that
// loop isn't relevant, like in the following, the outermost `loop`
// doesn't play into `x` being moved.
// ```
// loop {
// let x = String::new();
// loop {
// foo(x);
// }
// }
// ```
break;
}
if let hir::ExprKind::Loop(.., loop_span) = expr.kind {
err.span_label(loop_span, "inside of this loop");
}
}
}
let typeck = self.infcx.tcx.typeck(self.mir_def_id());
let hir_id = hir.get_parent_node(expr.hir_id);
if let Some(parent) = hir.find(hir_id) {
let (def_id, args, offset) = if let hir::Node::Expr(parent_expr) = parent
&& let hir::ExprKind::MethodCall(_, _, args, _) = parent_expr.kind
&& let Some(def_id) = typeck.type_dependent_def_id(parent_expr.hir_id)
{
(def_id.as_local(), args, 1)
} else if let hir::Node::Expr(parent_expr) = parent
&& let hir::ExprKind::Call(call, args) = parent_expr.kind
&& let ty::FnDef(def_id, _) = typeck.node_type(call.hir_id).kind()
{
(def_id.as_local(), args, 0)
} else {
(None, &[][..], 0)
};
if let Some(def_id) = def_id
&& let Some(node) = hir.find(hir.local_def_id_to_hir_id(def_id))
&& let Some(fn_sig) = node.fn_sig()
&& let Some(ident) = node.ident()
&& let Some(pos) = args.iter().position(|arg| arg.hir_id == expr.hir_id)
&& let Some(arg) = fn_sig.decl.inputs.get(pos + offset)
{
let mut span: MultiSpan = arg.span.into();
span.push_span_label(
arg.span,
"this parameter takes ownership of the value".to_string(),
);
let descr = match node.fn_kind() {
Some(hir::intravisit::FnKind::ItemFn(..)) | None => "function",
Some(hir::intravisit::FnKind::Method(..)) => "method",
Some(hir::intravisit::FnKind::Closure) => "closure",
};
span.push_span_label(
ident.span,
format!("in this {descr}"),
);
err.span_note(
span,
format!(
"consider changing this parameter type in {descr} `{ident}` to \
borrow instead if owning the value isn't necessary",
),
);
}
let place = &self.move_data.move_paths[mpi].place;
let ty = place.ty(self.body, self.infcx.tcx).ty;
if let hir::Node::Expr(parent_expr) = parent
&& let hir::ExprKind::Call(call_expr, _) = parent_expr.kind
&& let hir::ExprKind::Path(
hir::QPath::LangItem(LangItem::IntoIterIntoIter, _, _)
) = call_expr.kind
{
// Do not suggest `.clone()` in a `for` loop, we already suggest borrowing.
} else {
self.suggest_cloning(err, ty, move_span);
}
}
}
if let Some(pat) = finder.pat {
*in_pattern = true;
let mut sugg = vec![(pat.span.shrink_to_lo(), "ref ".to_string())];
if let Some(pat) = finder.parent_pat {
sugg.insert(0, (pat.span.shrink_to_lo(), "ref ".to_string()));
}
err.multipart_suggestion_verbose(
"borrow this binding in the pattern to avoid moving the value",
sugg,
Applicability::MachineApplicable,
);
}
}
}

fn report_use_of_uninitialized(
&self,
mpi: MovePathIndex,
Expand Down Expand Up @@ -590,6 +733,27 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
true
}

fn suggest_cloning(&self, err: &mut Diagnostic, ty: Ty<'tcx>, span: Span) {
let tcx = self.infcx.tcx;
// Try to find predicates on *generic params* that would allow copying `ty`
let infcx = tcx.infer_ctxt().build();
if infcx
.type_implements_trait(
tcx.lang_items().clone_trait().unwrap(),
[tcx.erase_regions(ty)],
self.param_env,
)
.must_apply_modulo_regions()
{
err.span_suggestion_verbose(
span.shrink_to_hi(),
"consider cloning the value if the performance cost is acceptable",
".clone()".to_string(),
Applicability::MachineApplicable,
);
}
}

fn suggest_adding_copy_bounds(&self, err: &mut Diagnostic, ty: Ty<'tcx>, span: Span) {
let tcx = self.infcx.tcx;
let generics = tcx.generics_of(self.mir_def_id());
Expand Down
8 changes: 5 additions & 3 deletions compiler/rustc_borrowck/src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
location: Location,
place: PlaceRef<'tcx>,
diag: &mut Diagnostic,
) {
) -> bool {
debug!("add_moved_or_invoked_closure_note: location={:?} place={:?}", location, place);
let mut target = place.local_or_deref_local();
for stmt in &self.body[location.block].statements[location.statement_index..] {
Expand Down Expand Up @@ -106,7 +106,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
{
place.local_or_deref_local().unwrap()
}
_ => return,
_ => return false,
};

debug!("add_moved_or_invoked_closure_note: closure={:?}", closure);
Expand All @@ -125,7 +125,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
ty::place_to_string_for_capture(self.infcx.tcx, hir_place)
),
);
return;
return true;
}
}
}
Expand All @@ -149,9 +149,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
ty::place_to_string_for_capture(self.infcx.tcx, hir_place)
),
);
return true;
}
}
}
false
}

/// End-user visible description of `place` if one can be found.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/assert/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ impl<'cx, 'a> Context<'cx, 'a> {
| ExprKind::InlineAsm(_)
| ExprKind::Let(_, _, _)
| ExprKind::Lit(_)
| ExprKind::Loop(_, _)
| ExprKind::Loop(_, _, _)
| ExprKind::MacCall(_)
| ExprKind::Match(_, _)
| ExprKind::Path(_, _)
Expand Down
Loading