Skip to content

Commit 8e1b82b

Browse files
committed
Remove suggestion to use atomics
1 parent 83a0ed6 commit 8e1b82b

9 files changed

+1
-60
lines changed

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use core::ops::ControlFlow;
55

66
use hir::{ExprKind, Param};
77
use rustc_abi::FieldIdx;
8-
use rustc_data_structures::fx::FxHashMap;
98
use rustc_errors::{Applicability, Diag};
109
use rustc_hir::intravisit::Visitor;
1110
use rustc_hir::{self as hir, BindingMode, ByRef, Node};
@@ -923,8 +922,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
923922
}
924923
}
925924

926-
/// When modifying a binding from inside of an `Fn` closure, point at the binding definition
927-
/// and suggest using an `std::sync` type that would allow the code to compile.
925+
/// When modifying a binding from inside of an `Fn` closure, point at the binding definition.
928926
fn point_at_binding_outside_closure(
929927
&self,
930928
err: &mut Diag<'_>,
@@ -956,31 +954,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
956954
&& let hir::def::Res::Local(hir_id) = path.res
957955
&& let hir::Node::Pat(pat) = self.infcx.tcx.hir_node(hir_id)
958956
{
959-
let hir = self.infcx.tcx.hir();
960-
let def_id = hir.enclosing_body_owner(self.mir_hir_id());
961-
let typeck_results = self.infcx.tcx.typeck(def_id);
962-
let ty = typeck_results.node_type_opt(expr.hir_id);
963-
if let Some(ty) = ty {
964-
let mutex = format!("std::sync::atomic::Mutex<{ty}>");
965-
let mutex = mutex.as_str();
966-
let suggestions: FxHashMap<_, _> = [
967-
(self.infcx.tcx.types.isize, "std::sync::atomic::AtomicIsize"),
968-
(self.infcx.tcx.types.usize, "std::sync::atomic::AtomicUsize"),
969-
(self.infcx.tcx.types.i64, "std::sync::atomic::AtomicI64"),
970-
(self.infcx.tcx.types.u64, "std::sync::atomic::AtomicU64"),
971-
(self.infcx.tcx.types.i32, "std::sync::atomic::AtomicI32"),
972-
(self.infcx.tcx.types.u32, "std::sync::atomic::AtomicU32"),
973-
(self.infcx.tcx.types.i16, "std::sync::atomic::AtomicI16"),
974-
(self.infcx.tcx.types.u16, "std::sync::atomic::AtomicU16"),
975-
(self.infcx.tcx.types.i8, "std::sync::atomic::AtomicI8"),
976-
(self.infcx.tcx.types.u8, "std::sync::atomic::AtomicU8"),
977-
(self.infcx.tcx.types.bool, "std::sync::atomic::AtomicBool"),
978-
]
979-
.into_iter()
980-
.collect();
981-
let ty = suggestions.get(&ty).unwrap_or(&mutex);
982-
err.help(format!("consider using `{ty}` instead, which allows for multiple threads to access and modify the value"));
983-
}
984957
let name = upvar.to_string(self.infcx.tcx);
985958
err.span_label(
986959
pat.span,

tests/ui/async-await/async-closures/wrong-fn-kind.stderr

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ LL | needs_async_fn(async || {
3636
LL |
3737
LL | x += 1;
3838
| - mutable borrow occurs due to use of `x` in closure
39-
|
40-
= help: consider using `std::sync::atomic::AtomicI32` instead, which allows for multiple threads to access and modify the value
4139

4240
error: aborting due to 2 previous errors
4341

tests/ui/borrowck/borrow-immutable-upvar-mutation.stderr

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ LL | let _f = to_fn(|| x = 42);
1111
| | |
1212
| | in this closure
1313
| expects `Fn` instead of `FnMut`
14-
|
15-
= help: consider using `std::sync::atomic::AtomicI32` instead, which allows for multiple threads to access and modify the value
1614

1715
error[E0596]: cannot borrow `y` as mutable, as it is a captured variable in a `Fn` closure
1816
--> $DIR/borrow-immutable-upvar-mutation.rs:24:31
@@ -27,8 +25,6 @@ LL | let _g = to_fn(|| set(&mut y));
2725
| | |
2826
| | in this closure
2927
| expects `Fn` instead of `FnMut`
30-
|
31-
= help: consider using `std::sync::atomic::AtomicUsize` instead, which allows for multiple threads to access and modify the value
3228

3329
error[E0594]: cannot assign to `z`, as it is a captured variable in a `Fn` closure
3430
--> $DIR/borrow-immutable-upvar-mutation.rs:29:22
@@ -44,8 +40,6 @@ LL | to_fn(|| z = 42);
4440
| | |
4541
| | in this closure
4642
| expects `Fn` instead of `FnMut`
47-
|
48-
= help: consider using `std::sync::atomic::AtomicUsize` instead, which allows for multiple threads to access and modify the value
4943

5044
error[E0594]: cannot assign to `x`, as it is a captured variable in a `Fn` closure
5145
--> $DIR/borrow-immutable-upvar-mutation.rs:36:32

tests/ui/borrowck/borrow-raw-address-of-mutability.stderr

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ LL | let f = make_fn(|| {
4848
| expects `Fn` instead of `FnMut`
4949
LL | let y = &raw mut x;
5050
| ^^^^^^^^^^ cannot borrow as mutable
51-
|
52-
= help: consider using `std::sync::atomic::AtomicI32` instead, which allows for multiple threads to access and modify the value
5351

5452
error[E0596]: cannot borrow `x` as mutable, as it is a captured variable in a `Fn` closure
5553
--> $DIR/borrow-raw-address-of-mutability.rs:35:17

tests/ui/borrowck/mutability-errors.stderr

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,6 @@ LL | fn_ref(|| {
148148
| expects `Fn` instead of `FnMut`
149149
LL | x = (1,);
150150
| ^^^^^^^^ cannot assign
151-
|
152-
= help: consider using `std::sync::atomic::Mutex<(i32,)>` instead, which allows for multiple threads to access and modify the value
153151

154152
error[E0594]: cannot assign to `x.0`, as `Fn` closures cannot mutate their captured variables
155153
--> $DIR/mutability-errors.rs:41:9
@@ -166,8 +164,6 @@ LL | fn_ref(|| {
166164
LL | x = (1,);
167165
LL | x.0 = 1;
168166
| ^^^^^^^ cannot assign
169-
|
170-
= help: consider using `std::sync::atomic::Mutex<(i32,)>` instead, which allows for multiple threads to access and modify the value
171167

172168
error[E0596]: cannot borrow `x` as mutable, as it is a captured variable in a `Fn` closure
173169
--> $DIR/mutability-errors.rs:42:9
@@ -184,8 +180,6 @@ LL | fn_ref(|| {
184180
...
185181
LL | &mut x;
186182
| ^^^^^^ cannot borrow as mutable
187-
|
188-
= help: consider using `std::sync::atomic::Mutex<(i32,)>` instead, which allows for multiple threads to access and modify the value
189183

190184
error[E0596]: cannot borrow `x.0` as mutable, as `Fn` closures cannot mutate their captured variables
191185
--> $DIR/mutability-errors.rs:43:9
@@ -202,8 +196,6 @@ LL | fn_ref(|| {
202196
...
203197
LL | &mut x.0;
204198
| ^^^^^^^^ cannot borrow as mutable
205-
|
206-
= help: consider using `std::sync::atomic::Mutex<(i32,)>` instead, which allows for multiple threads to access and modify the value
207199

208200
error[E0594]: cannot assign to `x`, as it is a captured variable in a `Fn` closure
209201
--> $DIR/mutability-errors.rs:46:9

tests/ui/closures/aliasability-violation-with-closure-21600.stderr

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ LL | call_it(|| x.gen_mut());
1212
| | |
1313
| | in this closure
1414
| expects `Fn` instead of `FnMut`
15-
|
16-
= help: consider using `std::sync::atomic::Mutex<A>` instead, which allows for multiple threads to access and modify the value
1715

1816
error[E0596]: cannot borrow `x` as mutable, as it is a captured variable in a `Fn` closure
1917
--> $DIR/aliasability-violation-with-closure-21600.rs:15:17
@@ -32,8 +30,6 @@ LL | call_it(|| x.gen_mut());
3230
| ^^ - mutable borrow occurs due to use of `x` in closure
3331
| |
3432
| cannot borrow as mutable
35-
|
36-
= help: consider using `std::sync::atomic::Mutex<A>` instead, which allows for multiple threads to access and modify the value
3733

3834
error: aborting due to 2 previous errors
3935

tests/ui/closures/wrong-closure-arg-suggestion-125325.stderr

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ LL | s.assoc_func(|| x = ());
1212
| | | cannot assign
1313
| | in this closure
1414
| expects `Fn` instead of `FnMut`
15-
|
16-
= help: consider using `std::sync::atomic::Mutex<()>` instead, which allows for multiple threads to access and modify the value
1715

1816
error[E0594]: cannot assign to `x`, as it is a captured variable in a `Fn` closure
1917
--> $DIR/wrong-closure-arg-suggestion-125325.rs:25:13
@@ -29,8 +27,6 @@ LL | func(|| x = ())
2927
| | |
3028
| | in this closure
3129
| expects `Fn` instead of `FnMut`
32-
|
33-
= help: consider using `std::sync::atomic::Mutex<()>` instead, which allows for multiple threads to access and modify the value
3430

3531
error: aborting due to 2 previous errors
3632

tests/ui/nll/closure-captures.stderr

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ LL | ||
5858
| ^^ cannot borrow as mutable
5959
LL | x = 1;}
6060
| - mutable borrow occurs due to use of `x` in closure
61-
|
62-
= help: consider using `std::sync::atomic::AtomicI32` instead, which allows for multiple threads to access and modify the value
6361

6462
error[E0596]: cannot borrow `x` as mutable, as it is a captured variable in a `Fn` closure
6563
--> $DIR/closure-captures.rs:31:9
@@ -103,8 +101,6 @@ LL | ||
103101
| ^^ cannot borrow as mutable
104102
LL | x = 1;}
105103
| - mutable borrow occurs due to use of `x` in closure
106-
|
107-
= help: consider using `std::sync::atomic::AtomicI32` instead, which allows for multiple threads to access and modify the value
108104

109105
error[E0594]: cannot assign to `x`, as it is not declared as mutable
110106
--> $DIR/closure-captures.rs:43:5

tests/ui/unboxed-closures/unboxed-closures-mutated-upvar-from-fn-closure.stderr

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ LL | call(|| {
1212
| expects `Fn` instead of `FnMut`
1313
LL | counter += 1;
1414
| ^^^^^^^^^^^^ cannot assign
15-
|
16-
= help: consider using `std::sync::atomic::AtomicI32` instead, which allows for multiple threads to access and modify the value
1715

1816
error: aborting due to 1 previous error
1917

0 commit comments

Comments
 (0)