Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Copy link
Copy Markdown
Contributor

@ujjwalvishwakarma2006 ujjwalvishwakarma2006 Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, I think it would be helpful to include the corresponding issue link near the top of the file. It's a bit hectic to search for the issue by number instead of having a direct link in the code. This way, one can easily ctrl + click on the link or use the gf or ge motion in Vim or Neovim.

I am unsure if other reviewers have the same opinion. If they do, please update in all such files ( :
If you want to make it more beautiful, you can put the link in between angle brackets <>.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, I think it would be helpful to include the corresponding issue link near the top of the file. It's a bit hectic to search for the issue by number instead of having a direct link in the code. This way, one can easily ctrl + click on the link or use the gf or ge motion in Vim or Neovim.

I am unsure if other reviewers have the same opinion. If they do, please update in all such files ( : If you want to make it more beautiful, you can put the link in between angle brackets <>.

Must have missed those three, thank you.

Copy link
Copy Markdown
Contributor

@ujjwalvishwakarma2006 ujjwalvishwakarma2006 Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although tests/ui/borrowck is still a better choice in my opinion, it may also belong to following:

  • tests/ui/lifetimes: Because variable line doesn't live long enough, and the description of tests/ui/lifetimes in the tests/ui/README.md says:

Broad directory on lifetimes, including proper specifiers, lifetimes not living long enough, or undeclared lifetime names.

But, since it's the job of the borrow-checker to handle this functionality, your choice is better. It's just another option.

Personal opinion 1: The file name can be prefixed with add- so that it will become add-assign-...; just clearer.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Issue 52126: With respect to variance, the assign-op's like += were
//! Test for https://github.com/rust-lang/rust/issues/52126
// With respect to variance, the assign-op's like += were
// accidentally lumped together with other binary op's. In both cases
// we were coercing the LHS of the op to the expected supertype.
//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0597]: `line` does not live long enough
--> $DIR/issue-52126-assign-op-invariance.rs:34:28
--> $DIR/assign-op-invariance-lifetime.rs:35:28
|
LL | for line in vec!["123456789".to_string(), "12345678".to_string()] {
| ---- binding `line` declared here
Expand Down
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ run-pass
// Regression test for #21400 which itself was extracted from
// Test for https://github.com/rust-lang/rust/issues/21400 extracted from
// stackoverflow.com/questions/28031155/is-my-borrow-checker-drunk/28031580

fn main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Issue link https://github.com/rust-lang/rust/issues/45697
// Test that assignments to an `&mut` pointer which is found in a
// borrowed (but otherwise non-aliasable) location is illegal.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0503]: cannot use `*y.pointer` because it was mutably borrowed
--> $DIR/issue-45697-1.rs:20:9
--> $DIR/borrowed-mut-pointer-assign-overflow-off.rs:21:9
|
LL | let z = copy_borrowed_ptr(&mut y);
| ------ `y` is borrowed here
Expand All @@ -10,7 +10,7 @@ LL | *z.pointer += 1;
| --------------- borrow later used here

error[E0506]: cannot assign to `*y.pointer` because it is borrowed
--> $DIR/issue-45697-1.rs:20:9
--> $DIR/borrowed-mut-pointer-assign-overflow-off.rs:21:9
|
LL | let z = copy_borrowed_ptr(&mut y);
| ------ `*y.pointer` is borrowed here
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Issue link https://github.com/rust-lang/rust/issues/45697
// Test that assignments to an `&mut` pointer which is found in a
// borrowed (but otherwise non-aliasable) location is illegal.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0503]: cannot use `*y.pointer` because it was mutably borrowed
--> $DIR/issue-45697.rs:20:9
--> $DIR/borrowed-mut-pointer-assign-overflow-on.rs:21:9
|
LL | let z = copy_borrowed_ptr(&mut y);
| ------ `y` is borrowed here
Expand All @@ -10,7 +10,7 @@ LL | *z.pointer += 1;
| --------------- borrow later used here

error[E0506]: cannot assign to `*y.pointer` because it is borrowed
--> $DIR/issue-45697.rs:20:9
--> $DIR/borrowed-mut-pointer-assign-overflow-on.rs:21:9
|
LL | let z = copy_borrowed_ptr(&mut y);
| ------ `*y.pointer` is borrowed here
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Regression test for https://github.com/rust-lang/rust/issues/41498
//@ run-pass
// regression test for issue #41498.

struct S;
impl S {
fn mutate(&mut self) {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Regression test for https://github.com/rust-lang/rust/issues/40288
fn save_ref<'a>(refr: &'a i32, to: &mut [&'a i32]) {
for val in &mut *to {
*val = refr;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0506]: cannot assign to `*refr` because it is borrowed
--> $DIR/issue-40288.rs:16:5
--> $DIR/cannot-assign-borrowed-ref-in-slice.rs:17:5
|
LL | save_ref(&*refr, &mut out);
| ------ `*refr` is borrowed here
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Regression test for https://github.com/rust-lang/rust/issues/41726
use std::collections::HashMap;
fn main() {
let things: HashMap<String, Vec<String>> = HashMap::new();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0596]: cannot borrow data in an index of `HashMap<String, Vec<String>>` as mutable
--> $DIR/issue-41726.rs:5:9
--> $DIR/cannot-borrow-index-of-hashmap-in-for.rs:6:9
|
LL | things[src.as_str()].sort();
| ^^^^^^^^^^^^^^^^^^^^ cannot borrow as mutable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Regression test for https://github.com/rust-lang/rust/issues/44405
use std::ops::Index;

struct Test;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0596]: cannot borrow data in an index of `Container` as mutable
--> $DIR/issue-44405.rs:21:5
--> $DIR/cannot-borrow-index-output-mutably.rs:22:5
|
LL | container[&mut val].test();
| ^^^^^^^^^^^^^^^^^^^ cannot borrow as mutable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Regression test for https://github.com/rust-lang/rust/issues/4335
#![feature(fn_traits)]

fn id<T>(t: T) -> T { t }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0507]: cannot move out of `*v`, as `v` is a captured variable in an `FnMut` closure
--> $DIR/issue-4335.rs:6:20
--> $DIR/cannot-move-out-of-borrowed-ref-closure.rs:7:20
|
LL | fn f<'r, T>(v: &'r T) -> Box<dyn FnMut() -> T + 'r> {
| - ----- move occurs because `*v` has type `T`, which does not implement the `Copy` trait
Expand All @@ -12,7 +12,7 @@ LL | id(Box::new(|| *v))
|
= help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but `FnOnce` closures may consume them only once
help: if `T` implemented `Clone`, you could clone the value
--> $DIR/issue-4335.rs:5:10
--> $DIR/cannot-move-out-of-borrowed-ref-closure.rs:6:10
|
LL | fn f<'r, T>(v: &'r T) -> Box<dyn FnMut() -> T + 'r> {
| ^ consider constraining this type parameter with `Clone`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Regression test for https://github.com/rust-lang/rust/issues/26619
pub struct History<'a> { pub _s: &'a str }

impl<'a> History<'a> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0515]: cannot return value referencing function parameter
--> $DIR/issue-26619.rs:5:76
--> $DIR/cannot-return-ref-to-fn-param-in-filter-map.rs:6:76
|
LL | for s in vec!["1|2".to_string()].into_iter().filter_map(|ref line| self.make_entry(line)) {
| -------- ^^^^^^^^^^^^^^^^^^^^^ returns a value referencing data owned by the current function
Expand Down
Copy link
Copy Markdown
Contributor

@ujjwalvishwakarma2006 ujjwalvishwakarma2006 Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry I forgot, this one too ( :

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0515]: cannot return reference to temporary value
--> $DIR/issue-27592.rs:16:14
--> $DIR/cannot-return-ref-to-temporary-format-args.rs:16:14
|
LL | write(|| format_args!("{}", String::from("Hello world")));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ returns a reference to data owned by the current function

error[E0515]: cannot return value referencing temporary value
--> $DIR/issue-27592.rs:16:14
--> $DIR/cannot-return-ref-to-temporary-format-args.rs:16:14
|
LL | write(|| format_args!("{}", String::from("Hello world")));
| ^^^^^^^^^^^^^^^^^^^---------------------------^
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Regression test for https://github.com/rust-lang/rust/issues/18566
use std::ops::Deref;

struct MyPtr<'a>(&'a mut usize);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0499]: cannot borrow `*s` as mutable more than once at a time
--> $DIR/issue-18566.rs:23:19
--> $DIR/deref-and-mut-borrow-conflict.rs:24:19
|
LL | MyPtr(s).poke(s);
| - ---- ^ second mutable borrow occurs here
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Regression test for https://github.com/rust-lang/rust/issues/28971
enum Foo {
Bar(u8)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0599]: no variant, associated function, or constant named `Baz` found for enum `Foo` in the current scope
--> $DIR/issue-28971.rs:7:18
--> $DIR/fnmut-borrow-error-in-closure-match.rs:8:18
|
LL | enum Foo {
| -------- variant, associated function, or constant `Baz` not found for this enum
Expand All @@ -14,7 +14,7 @@ LL + Foo::Bar(..) => (),
|

error[E0596]: cannot borrow `f` as mutable, as it is not declared as mutable
--> $DIR/issue-28971.rs:15:5
--> $DIR/fnmut-borrow-error-in-closure-match.rs:16:5
|
LL | f();
| ^ cannot borrow as mutable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Regression test for https://github.com/rust-lang/rust/issues/42106
fn do_something<T>(collection: &mut Vec<T>) {
let _a = &collection;
collection.swap(1, 2); //~ ERROR also borrowed as immutable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0502]: cannot borrow `*collection` as mutable because it is also borrowed as immutable
--> $DIR/issue-42106.rs:3:5
--> $DIR/immutable-borrow-prevents-mut-method.rs:4:5
|
LL | let _a = &collection;
| ----------- immutable borrow occurs here
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Regression test for https://github.com/rust-lang/rust/issues/18783
use std::cell::RefCell;

fn main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0499]: cannot borrow `y` as mutable more than once at a time
--> $DIR/issue-18783.rs:7:21
--> $DIR/mut-borrow-conflict-in-closures-vec.rs:8:21
|
LL | c.push(Box::new(|| y = 0));
| -- - first borrow occurs due to use of `y` in closure
Expand All @@ -14,7 +14,7 @@ LL | }
| - first borrow might be used here, when `c` is dropped and runs the destructor for type `RefCell<Vec<Box<dyn FnMut()>>>`

error[E0499]: cannot borrow `y` as mutable more than once at a time
--> $DIR/issue-18783.rs:16:29
--> $DIR/mut-borrow-conflict-in-closures-vec.rs:17:29
|
LL | Push::push(&c, Box::new(|| y = 0));
| -- - first borrow occurs due to use of `y` in closure
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Regression test for https://github.com/rust-lang/rust/issues/25579
//@ check-pass

enum Sexpression {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Regression test for https://github.com/rust-lang/rust/issues/28839
//@ run-pass

pub struct Foo;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Regression test for https://github.com/rust-lang/rust/issues/29053
//@ run-pass
fn main() {
let x: &'static str = "x";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Regression test for https://github.com/rust-lang/rust/issues/47703
//@ check-pass

struct MyStruct<'a> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Regression test for https://github.com/rust-lang/rust/issues/47703
//@ check-pass

struct AtomicRefMut<'a> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Regression test for https://github.com/rust-lang/rust/issues/47703
//@ check-pass

struct WithDrop;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0382]: use of moved value: `s`
--> $DIR/issue-29723.rs:10:13
--> $DIR/use-moved-value-in-match-guard-drop.rs:10:13
|
LL | let s = String::new();
| - move occurs because `s` has type `String`, which does not implement the `Copy` trait
Expand All @@ -16,7 +16,7 @@ LL | 0 if { drop(s.clone()); false } => String::from("oops"),
| ++++++++

error[E0382]: use of moved value: `s`
--> $DIR/issue-29723.rs:18:14
--> $DIR/use-moved-value-in-match-guard-drop.rs:18:14
|
LL | let s = String::new();
| - move occurs because `s` has type `String`, which does not implement the `Copy` trait
Expand Down
Loading