Skip to content

Commit e4c1446

Browse files
committed
Auto merge of #114481 - matthiaskrgr:rollup-58pczpl, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - #113945 (Fix wrong span for trait selection failure error reporting) - #114351 ([rustc_span][perf] Remove unnecessary string joins and allocs.) - #114418 (bump parking_lot to 0.12) - #114434 (Improve spans for indexing expressions) - #114450 (Fix ICE failed to get layout for ReferencesError) - #114461 (Fix unwrap on None) - #114462 (interpret: add mplace_to_ref helper method) - #114472 (Reword `confusable_idents` lint) - #114477 (Account for `Rc` and `Arc` when suggesting to clone) r? `@ghost` `@rustbot` modify labels: rollup
2 parents fe896ef + 35b2713 commit e4c1446

File tree

111 files changed

+466
-202
lines changed

Some content is hidden

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

111 files changed

+466
-202
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3469,7 +3469,7 @@ dependencies = [
34693469
"libc",
34703470
"measureme",
34713471
"memmap2",
3472-
"parking_lot 0.11.2",
3472+
"parking_lot 0.12.1",
34733473
"rustc-hash",
34743474
"rustc-rayon",
34753475
"rustc-rayon-core",
@@ -4190,7 +4190,7 @@ dependencies = [
41904190
name = "rustc_query_system"
41914191
version = "0.0.0"
41924192
dependencies = [
4193-
"parking_lot 0.11.2",
4193+
"parking_lot 0.12.1",
41944194
"rustc-rayon-core",
41954195
"rustc_ast",
41964196
"rustc_data_structures",

compiler/rustc_ast/src/ast.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1462,7 +1462,8 @@ pub enum ExprKind {
14621462
/// Access of a named (e.g., `obj.foo`) or unnamed (e.g., `obj.0`) struct field.
14631463
Field(P<Expr>, Ident),
14641464
/// An indexing operation (e.g., `foo[2]`).
1465-
Index(P<Expr>, P<Expr>),
1465+
/// The span represents the span of the `[2]`, including brackets.
1466+
Index(P<Expr>, P<Expr>, Span),
14661467
/// A range (e.g., `1..2`, `1..`, `..2`, `1..=2`, `..=2`; and `..` in destructuring assignment).
14671468
Range(Option<P<Expr>>, Option<P<Expr>>, RangeLimits),
14681469
/// An underscore, used in destructuring assignment to ignore a value.

compiler/rustc_ast/src/mut_visit.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,14 +1400,15 @@ pub fn noop_visit_expr<T: MutVisitor>(
14001400
fn_decl,
14011401
body,
14021402
fn_decl_span,
1403-
fn_arg_span: _,
1403+
fn_arg_span,
14041404
}) => {
14051405
vis.visit_closure_binder(binder);
14061406
visit_constness(constness, vis);
14071407
vis.visit_asyncness(asyncness);
14081408
vis.visit_fn_decl(fn_decl);
14091409
vis.visit_expr(body);
14101410
vis.visit_span(fn_decl_span);
1411+
vis.visit_span(fn_arg_span);
14111412
}
14121413
ExprKind::Block(blk, label) => {
14131414
vis.visit_block(blk);
@@ -1420,9 +1421,10 @@ pub fn noop_visit_expr<T: MutVisitor>(
14201421
vis.visit_expr(expr);
14211422
vis.visit_span(await_kw_span);
14221423
}
1423-
ExprKind::Assign(el, er, _) => {
1424+
ExprKind::Assign(el, er, span) => {
14241425
vis.visit_expr(el);
14251426
vis.visit_expr(er);
1427+
vis.visit_span(span);
14261428
}
14271429
ExprKind::AssignOp(_op, el, er) => {
14281430
vis.visit_expr(el);
@@ -1432,9 +1434,10 @@ pub fn noop_visit_expr<T: MutVisitor>(
14321434
vis.visit_expr(el);
14331435
vis.visit_ident(ident);
14341436
}
1435-
ExprKind::Index(el, er) => {
1437+
ExprKind::Index(el, er, brackets_span) => {
14361438
vis.visit_expr(el);
14371439
vis.visit_expr(er);
1440+
vis.visit_span(brackets_span);
14381441
}
14391442
ExprKind::Range(e1, e2, _lim) => {
14401443
visit_opt(e1, |e1| vis.visit_expr(e1));

compiler/rustc_ast/src/util/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ pub fn contains_exterior_struct_lit(value: &ast::Expr) -> bool {
390390
| ast::ExprKind::Cast(x, _)
391391
| ast::ExprKind::Type(x, _)
392392
| ast::ExprKind::Field(x, _)
393-
| ast::ExprKind::Index(x, _) => {
393+
| ast::ExprKind::Index(x, _, _) => {
394394
// &X { y: 1 }, X { y: 1 }.y
395395
contains_exterior_struct_lit(x)
396396
}

compiler/rustc_ast/src/visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
885885
visitor.visit_expr(subexpression);
886886
visitor.visit_ident(*ident);
887887
}
888-
ExprKind::Index(main_expression, index_expression) => {
888+
ExprKind::Index(main_expression, index_expression, _) => {
889889
visitor.visit_expr(main_expression);
890890
visitor.visit_expr(index_expression)
891891
}

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
240240
ExprKind::Field(el, ident) => {
241241
hir::ExprKind::Field(self.lower_expr(el), self.lower_ident(*ident))
242242
}
243-
ExprKind::Index(el, er) => {
244-
hir::ExprKind::Index(self.lower_expr(el), self.lower_expr(er))
243+
ExprKind::Index(el, er, brackets_span) => {
244+
hir::ExprKind::Index(self.lower_expr(el), self.lower_expr(er), *brackets_span)
245245
}
246246
ExprKind::Range(Some(e1), Some(e2), RangeLimits::Closed) => {
247247
self.lower_expr_range_closed(e.span, e1, e2)

compiler/rustc_ast_pretty/src/pprust/state/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ impl<'a> State<'a> {
477477
self.word(".");
478478
self.print_ident(*ident);
479479
}
480-
ast::ExprKind::Index(expr, index) => {
480+
ast::ExprKind::Index(expr, index, _) => {
481481
self.print_expr_maybe_paren(expr, parser::PREC_POSTFIX);
482482
self.word("[");
483483
self.print_expr(index);

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,9 +751,19 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
751751
)
752752
.must_apply_modulo_regions()
753753
{
754+
let msg = if let ty::Adt(def, _) = ty.kind()
755+
&& [
756+
tcx.get_diagnostic_item(sym::Arc),
757+
tcx.get_diagnostic_item(sym::Rc),
758+
].contains(&Some(def.did()))
759+
{
760+
"clone the value to increment its reference count"
761+
} else {
762+
"consider cloning the value if the performance cost is acceptable"
763+
};
754764
err.span_suggestion_verbose(
755765
span.shrink_to_hi(),
756-
"consider cloning the value if the performance cost is acceptable",
766+
msg,
757767
suggestion,
758768
Applicability::MachineApplicable,
759769
);

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
7979
| hir::ExprKind::Unary(hir::UnOp::Deref, inner)
8080
| hir::ExprKind::Field(inner, _)
8181
| hir::ExprKind::MethodCall(_, inner, _, _)
82-
| hir::ExprKind::Index(inner, _) = &expr.kind
82+
| hir::ExprKind::Index(inner, _, _) = &expr.kind
8383
{
8484
expr = inner;
8585
}

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
567567
}
568568
};
569569
if let hir::ExprKind::Assign(place, rv, _sp) = expr.kind
570-
&& let hir::ExprKind::Index(val, index) = place.kind
570+
&& let hir::ExprKind::Index(val, index, _) = place.kind
571571
&& (expr.span == self.assign_span || place.span == self.assign_span)
572572
{
573573
// val[index] = rv;
@@ -620,7 +620,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
620620
);
621621
self.suggested = true;
622622
} else if let hir::ExprKind::MethodCall(_path, receiver, _, sp) = expr.kind
623-
&& let hir::ExprKind::Index(val, index) = receiver.kind
623+
&& let hir::ExprKind::Index(val, index, _) = receiver.kind
624624
&& expr.span == self.assign_span
625625
{
626626
// val[index].path(args..);

0 commit comments

Comments
 (0)