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

Rollup of 9 pull requests #107309

Merged
merged 25 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
656db98
Tweak E0597
estebank Jan 15, 2023
e4f61af
Fix fulldeps-ui tests
estebank Jan 15, 2023
be2ec32
Account for `*` when looking for inner-most path in expression
estebank Jan 17, 2023
c6111e8
Account for field access when looking for inner-most path in expression
estebank Jan 17, 2023
7b8251e
Account for method call and indexing when looking for inner-most path…
estebank Jan 17, 2023
e1f630f
Add `OnceCell<T>: !Sync` impl for diagnostics
Noratrieb Jan 16, 2023
6d0c91f
Add `rustc_on_unimplemented` on `Sync` for cell types
Noratrieb Jan 16, 2023
62a1e76
Add hint for missing lifetime bound on trait object when type alias i…
Dec 6, 2022
7f5ce94
Bring tests back into rustc source tarball
tmiasko Jan 23, 2023
e65b361
rustdoc: rearrange HTML in primitive reference links
notriddle Jan 24, 2023
e6e93e0
add test where we ignore hr implied bounds
lcnr Jan 24, 2023
ad73936
Delete `SimplifyArmIdentity` and `SimplifyBranchSame` mir opts
JakobDegen Jan 24, 2023
11a94f2
rustdoc: prevent scroll bar on source viewer
kadiwa4 Jan 24, 2023
430dab0
implement builtin candidate
BoxyUwU Jan 24, 2023
2f924b0
sorry erica
BoxyUwU Jan 24, 2023
a418e39
no without_constness
BoxyUwU Jan 24, 2023
f21728f
Rollup merge of #105345 - yanchen4791:issue-103582-fix, r=jackh726
matthiaskrgr Jan 25, 2023
9e3f330
Rollup merge of #106897 - estebank:issue-99430, r=davidtwco
matthiaskrgr Jan 25, 2023
22e62a4
Rollup merge of #106944 - Nilstrieb:there-once-was-a-diagnostic, r=Wa…
matthiaskrgr Jan 25, 2023
b7baa9f
Rollup merge of #107239 - tmiasko:tests, r=Mark-Simulacrum
matthiaskrgr Jan 25, 2023
2ed3639
Rollup merge of #107244 - notriddle:notriddle/primitive-reference-lin…
matthiaskrgr Jan 25, 2023
c20e0da
Rollup merge of #107255 - lcnr:implied-b-hr, r=oli-obk
matthiaskrgr Jan 25, 2023
c2f46df
Rollup merge of #107256 - JakobDegen:delete-sai, r=cjgillot
matthiaskrgr Jan 25, 2023
f268c7b
Rollup merge of #107266 - kadiwa4:source_viewer_scrollbar, r=notriddle
matthiaskrgr Jan 25, 2023
a20b86f
Rollup merge of #107282 - BoxyUwU:erica_builtin_pointee_impls, r=comp…
matthiaskrgr Jan 25, 2023
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
Next Next commit
Tweak E0597
  • Loading branch information
estebank committed Jan 15, 2023
commit 656db98bd99caf7e5c5e81ad11ed8922e28c46fb
6 changes: 3 additions & 3 deletions compiler/rustc_borrowck/src/borrowck_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
desc,
);

err.span_label(borrow_span, format!("borrow of {} occurs here", borrow_desc));
err.span_label(borrow_span, format!("{} is borrowed here", borrow_desc));
err.span_label(span, format!("use of borrowed {}", borrow_desc));
err
}
Expand Down Expand Up @@ -250,8 +250,8 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
desc,
);

err.span_label(borrow_span, format!("borrow of {} occurs here", desc));
err.span_label(span, format!("assignment to borrowed {} occurs here", desc));
err.span_label(borrow_span, format!("{} is borrowed here", desc));
err.span_label(span, format!("{} is assigned to here but it was already borrowed", desc));
err
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1742,7 +1742,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&self.local_names,
&mut err,
"",
None,
Some(borrow_span),
None,
);
}
Expand Down
28 changes: 28 additions & 0 deletions compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! Print diagnostics to explain why values are borrowed.

use rustc_errors::{Applicability, Diagnostic};
use rustc_hir as hir;
use rustc_hir::intravisit::Visitor;
use rustc_index::vec::IndexVec;
use rustc_infer::infer::NllRegionVariableOrigin;
use rustc_middle::mir::{
Expand All @@ -11,6 +13,7 @@ use rustc_middle::ty::adjustment::PointerCast;
use rustc_middle::ty::{self, RegionVid, TyCtxt};
use rustc_span::symbol::{kw, Symbol};
use rustc_span::{sym, DesugaringKind, Span};
use rustc_trait_selection::traits::error_reporting::FindExprBySpan;

use crate::region_infer::{BlameConstraint, ExtraConstraintInfo};
use crate::{
Expand Down Expand Up @@ -63,6 +66,31 @@ impl<'tcx> BorrowExplanation<'tcx> {
borrow_span: Option<Span>,
multiple_borrow_span: Option<(Span, Span)>,
) {
if let Some(span) = borrow_span {
let def_id = body.source.def_id();
if let Some(node) = tcx.hir().get_if_local(def_id)
&& let Some(body_id) = node.body_id()
{
let body = tcx.hir().body(body_id);
let mut expr_finder = FindExprBySpan::new(span);
expr_finder.visit_expr(body.value);
if let Some(mut expr) = expr_finder.result {
while let hir::ExprKind::AddrOf(_, _, inner) = &expr.kind {
expr = inner;
}
if let hir::ExprKind::Path(hir::QPath::Resolved(None, p)) = expr.kind
&& let [hir::PathSegment { ident, args: None, .. }] = p.segments
&& let hir::def::Res::Local(hir_id) = p.res
&& let Some(hir::Node::Pat(pat)) = tcx.hir().find(hir_id)
{
err.span_label(
pat.span,
&format!("binding `{ident}` declared here"),
);
}
}
}
}
match *self {
BorrowExplanation::UsedLater(later_use_kind, var_or_use_span, path_span) => {
let message = match later_use_kind {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/diagnostics/move_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
};
self.note_type_does_not_implement_copy(err, &place_desc, place_ty, Some(span), "");

use_spans.args_span_label(err, format!("move out of {place_desc} occurs here"));
use_spans.args_span_label(err, format!("{place_desc} is moved here"));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2827,7 +2827,7 @@ pub struct FindExprBySpan<'hir> {
}

impl<'hir> FindExprBySpan<'hir> {
fn new(span: Span) -> Self {
pub fn new(span: Span) -> Self {
Self { span, result: None, ty_result: None }
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/asm/type-check-4.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ error[E0506]: cannot assign to `a` because it is borrowed
--> $DIR/type-check-4.rs:14:9
|
LL | let p = &a;
| -- borrow of `a` occurs here
| -- `a` is borrowed here
LL | asm!("{}", out(reg) a);
| ^^^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `a` occurs here
| ^^^^^^^^^^^^^^^^^^^^^^ `a` is assigned to here but it was already borrowed
LL |
LL | println!("{}", p);
| - borrow later used here
Expand All @@ -13,7 +13,7 @@ error[E0503]: cannot use `a` because it was mutably borrowed
--> $DIR/type-check-4.rs:22:28
|
LL | let p = &mut a;
| ------ borrow of `a` occurs here
| ------ `a` is borrowed here
LL | asm!("{}", in(reg) a);
| ^ use of borrowed `a`
LL |
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/associated-types/associated-types-outlives.stderr
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
error[E0505]: cannot move out of `x` because it is borrowed
--> $DIR/associated-types-outlives.rs:22:14
|
LL | F: for<'a> FnOnce(<T as Foo<'a>>::Bar)>(x: T, f: F) {
| - binding `x` declared here
...
LL | 's: loop { y = denormalise(&x); break }
| -- borrow of `x` occurs here
LL | drop(x);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ error[E0506]: cannot assign to `*x` because it is borrowed
LL | pub async fn async_fn(x: &mut i32) -> &i32 {
| - let's call the lifetime of this reference `'1`
LL | let y = &*x;
| --- borrow of `*x` occurs here
| --- `*x` is borrowed here
LL | *x += 1;
| ^^^^^^^ assignment to borrowed `*x` occurs here
| ^^^^^^^ `*x` is assigned to here but it was already borrowed
LL | y
| - returning this value requires that `*x` is borrowed for `'1`

error[E0506]: cannot assign to `*x` because it is borrowed
--> $DIR/issue-74072-lifetime-name-annotations.rs:16:9
|
LL | let y = &*x;
| --- borrow of `*x` occurs here
| --- `*x` is borrowed here
LL | *x += 1;
| ^^^^^^^ assignment to borrowed `*x` occurs here
| ^^^^^^^ `*x` is assigned to here but it was already borrowed
LL | y
| - returning this value requires that `*x` is borrowed for `'1`
LL | })()
Expand All @@ -28,19 +28,19 @@ error[E0506]: cannot assign to `*x` because it is borrowed
LL | (async move || -> &i32 {
| - let's call the lifetime of this reference `'1`
LL | let y = &*x;
| --- borrow of `*x` occurs here
| --- `*x` is borrowed here
LL | *x += 1;
| ^^^^^^^ assignment to borrowed `*x` occurs here
| ^^^^^^^ `*x` is assigned to here but it was already borrowed
LL | y
| - returning this value requires that `*x` is borrowed for `'1`

error[E0506]: cannot assign to `*x` because it is borrowed
--> $DIR/issue-74072-lifetime-name-annotations.rs:32:9
|
LL | let y = &*x;
| --- borrow of `*x` occurs here
| --- `*x` is borrowed here
LL | *x += 1;
| ^^^^^^^ assignment to borrowed `*x` occurs here
| ^^^^^^^ `*x` is assigned to here but it was already borrowed
LL | y
| - returning this value requires that `*x` is borrowed for `'1`
LL | }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ error[E0506]: cannot assign to `*x` because it is borrowed
LL | pub async fn async_fn(x: &mut i32) -> (&i32, &i32) {
| - let's call the lifetime of this reference `'1`
LL | let y = &*x;
| --- borrow of `*x` occurs here
| --- `*x` is borrowed here
LL | *x += 1;
| ^^^^^^^ assignment to borrowed `*x` occurs here
| ^^^^^^^ `*x` is assigned to here but it was already borrowed
LL | (&32, y)
| -------- returning this value requires that `*x` is borrowed for `'1`

Expand Down
12 changes: 6 additions & 6 deletions tests/ui/async-await/multiple-lifetimes/ret-ref.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ error[E0506]: cannot assign to `a` because it is borrowed
--> $DIR/ret-ref.rs:16:5
|
LL | let future = multiple_named_lifetimes(&a, &b);
| -- borrow of `a` occurs here
| -- `a` is borrowed here
LL | a += 1;
| ^^^^^^ assignment to borrowed `a` occurs here
| ^^^^^^ `a` is assigned to here but it was already borrowed
LL | b += 1;
LL | let p = future.await;
| ------ borrow later used here
Expand All @@ -13,21 +13,21 @@ error[E0506]: cannot assign to `b` because it is borrowed
--> $DIR/ret-ref.rs:17:5
|
LL | let future = multiple_named_lifetimes(&a, &b);
| -- borrow of `b` occurs here
| -- `b` is borrowed here
LL | a += 1;
LL | b += 1;
| ^^^^^^ assignment to borrowed `b` occurs here
| ^^^^^^ `b` is assigned to here but it was already borrowed
LL | let p = future.await;
| ------ borrow later used here

error[E0506]: cannot assign to `a` because it is borrowed
--> $DIR/ret-ref.rs:28:5
|
LL | let future = multiple_named_lifetimes(&a, &b);
| -- borrow of `a` occurs here
| -- `a` is borrowed here
LL | let p = future.await;
LL | a += 1;
| ^^^^^^ assignment to borrowed `a` occurs here
| ^^^^^^ `a` is assigned to here but it was already borrowed
LL | b += 1;
LL | drop(p);
| - borrow later used here
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/augmented-assignments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ impl AddAssign for Int {
}

fn main() {
let mut x = Int(1);
let mut x = Int(1); //~ NOTE binding `x` declared here
x
//~^ NOTE borrow of `x` occurs here
+=
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/augmented-assignments.stderr
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
error[E0505]: cannot move out of `x` because it is borrowed
--> $DIR/augmented-assignments.rs:16:5
|
LL | let mut x = Int(1);
| ----- binding `x` declared here
LL | x
| - borrow of `x` occurs here
...
Expand Down
5 changes: 5 additions & 0 deletions tests/ui/binop/binop-move-semantics.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ LL | fn move_then_borrow<T: Add<Output=()> + Clone + Copy>(x: T) {
error[E0505]: cannot move out of `x` because it is borrowed
--> $DIR/binop-move-semantics.rs:21:5
|
LL | fn move_borrowed<T: Add<Output=()>>(x: T, mut y: T) {
| - binding `x` declared here
LL | let m = &x;
| -- borrow of `x` occurs here
...
Expand All @@ -53,6 +55,9 @@ LL | use_mut(n); use_imm(m);
error[E0505]: cannot move out of `y` because it is borrowed
--> $DIR/binop-move-semantics.rs:23:5
|
LL | fn move_borrowed<T: Add<Output=()>>(x: T, mut y: T) {
| ----- binding `y` declared here
LL | let m = &x;
LL | let n = &mut y;
| ------ borrow of `y` occurs here
...
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/borrowck/borrowck-anon-fields-variant.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0503]: cannot use `y` because it was mutably borrowed
--> $DIR/borrowck-anon-fields-variant.rs:16:19
|
LL | Foo::Y(ref mut a, _) => a,
| --------- borrow of `y.0` occurs here
| --------- `y.0` is borrowed here
...
LL | let b = match y {
| ^ use of borrowed `y.0`
Expand All @@ -14,7 +14,7 @@ error[E0503]: cannot use `y` because it was mutably borrowed
--> $DIR/borrowck-anon-fields-variant.rs:34:19
|
LL | Foo::Y(ref mut a, _) => a,
| --------- borrow of `y.0` occurs here
| --------- `y.0` is borrowed here
...
LL | let b = match y {
| ^ use of borrowed `y.0`
Expand Down
12 changes: 6 additions & 6 deletions tests/ui/borrowck/borrowck-assign-comp.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ error[E0506]: cannot assign to `p.x` because it is borrowed
--> $DIR/borrowck-assign-comp.rs:10:5
|
LL | let q = &p;
| -- borrow of `p.x` occurs here
| -- `p.x` is borrowed here
...
LL | p.x = 5;
| ^^^^^^^ assignment to borrowed `p.x` occurs here
| ^^^^^^^ `p.x` is assigned to here but it was already borrowed
LL | q.x;
| --- borrow later used here

error[E0506]: cannot assign to `p` because it is borrowed
--> $DIR/borrowck-assign-comp.rs:20:5
|
LL | let q = &p.y;
| ---- borrow of `p` occurs here
| ---- `p` is borrowed here
LL | p = Point {x: 5, y: 7};
| ^^^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `p` occurs here
| ^^^^^^^^^^^^^^^^^^^^^^ `p` is assigned to here but it was already borrowed
LL | p.x; // silence warning
LL | *q; // stretch loan
| -- borrow later used here
Expand All @@ -24,9 +24,9 @@ error[E0506]: cannot assign to `p.y` because it is borrowed
--> $DIR/borrowck-assign-comp.rs:31:5
|
LL | let q = &p.y;
| ---- borrow of `p.y` occurs here
| ---- `p.y` is borrowed here
LL | p.y = 5;
| ^^^^^^^ assignment to borrowed `p.y` occurs here
| ^^^^^^^ `p.y` is assigned to here but it was already borrowed
LL | *q;
| -- borrow later used here

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0503]: cannot use `*y.pointer` because it was mutably borrowed
--> $DIR/borrowck-assign-to-andmut-in-borrowed-loc.rs:18:9
|
LL | let z = copy_borrowed_ptr(&mut y);
| ------ borrow of `y` occurs here
| ------ `y` is borrowed here
LL | *y.pointer += 1;
| ^^^^^^^^^^^^^^^ use of borrowed `y`
...
Expand All @@ -13,9 +13,9 @@ error[E0506]: cannot assign to `*y.pointer` because it is borrowed
--> $DIR/borrowck-assign-to-andmut-in-borrowed-loc.rs:18:9
|
LL | let z = copy_borrowed_ptr(&mut y);
| ------ borrow of `*y.pointer` occurs here
| ------ `*y.pointer` is borrowed here
LL | *y.pointer += 1;
| ^^^^^^^^^^^^^^^ assignment to borrowed `*y.pointer` occurs here
| ^^^^^^^^^^^^^^^ `*y.pointer` is assigned to here but it was already borrowed
...
LL | *z.pointer += 1;
| --------------- borrow later used here
Expand Down
16 changes: 8 additions & 8 deletions tests/ui/borrowck/borrowck-closures-mut-and-imm.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ error[E0506]: cannot assign to `x` because it is borrowed
LL | let c2 = || x * 5;
| -- - borrow occurs due to use in closure
| |
| borrow of `x` occurs here
| `x` is borrowed here
LL | x = 5;
| ^^^^^ assignment to borrowed `x` occurs here
| ^^^^^ `x` is assigned to here but it was already borrowed
LL |
LL | drop(c2);
| -- borrow later used here
Expand All @@ -62,9 +62,9 @@ error[E0506]: cannot assign to `x` because it is borrowed
LL | let c1 = || get(&x);
| -- - borrow occurs due to use in closure
| |
| borrow of `x` occurs here
| `x` is borrowed here
LL | x = 5;
| ^^^^^ assignment to borrowed `x` occurs here
| ^^^^^ `x` is assigned to here but it was already borrowed
LL |
LL | drop(c1);
| -- borrow later used here
Expand All @@ -75,9 +75,9 @@ error[E0506]: cannot assign to `*x` because it is borrowed
LL | let c1 = || get(&*x);
| -- -- borrow occurs due to use in closure
| |
| borrow of `*x` occurs here
| `*x` is borrowed here
LL | *x = 5;
| ^^^^^^ assignment to borrowed `*x` occurs here
| ^^^^^^ `*x` is assigned to here but it was already borrowed
LL |
LL | drop(c1);
| -- borrow later used here
Expand All @@ -88,9 +88,9 @@ error[E0506]: cannot assign to `*x.f` because it is borrowed
LL | let c1 = || get(&*x.f);
| -- ---- borrow occurs due to use in closure
| |
| borrow of `*x.f` occurs here
| `*x.f` is borrowed here
LL | *x.f = 5;
| ^^^^^^^^ assignment to borrowed `*x.f` occurs here
| ^^^^^^^^ `*x.f` is assigned to here but it was already borrowed
LL |
LL | drop(c1);
| -- borrow later used here
Expand Down
Loading