Skip to content

Commit f7ddba0

Browse files
committed
Remove suggestion to use atomics
1 parent 758869a commit f7ddba0

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
@@ -6,7 +6,6 @@ use core::ops::ControlFlow;
66
use either::Either;
77
use hir::{ExprKind, Param};
88
use rustc_abi::FieldIdx;
9-
use rustc_data_structures::fx::FxHashMap;
109
use rustc_errors::{Applicability, Diag};
1110
use rustc_hir::intravisit::Visitor;
1211
use rustc_hir::{self as hir, BindingMode, ByRef, Node};
@@ -952,8 +951,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
952951
}
953952
}
954953

955-
/// When modifying a binding from inside of an `Fn` closure, point at the binding definition
956-
/// and suggest using an `std::sync` type that would allow the code to compile.
954+
/// When modifying a binding from inside of an `Fn` closure, point at the binding definition.
957955
fn point_at_binding_outside_closure(
958956
&self,
959957
err: &mut Diag<'_>,
@@ -985,31 +983,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
985983
&& let hir::def::Res::Local(hir_id) = path.res
986984
&& let hir::Node::Pat(pat) = self.infcx.tcx.hir_node(hir_id)
987985
{
988-
let hir = self.infcx.tcx.hir();
989-
let def_id = hir.enclosing_body_owner(self.mir_hir_id());
990-
let typeck_results = self.infcx.tcx.typeck(def_id);
991-
let ty = typeck_results.node_type_opt(expr.hir_id);
992-
if let Some(ty) = ty {
993-
let mutex = format!("std::sync::atomic::Mutex<{ty}>");
994-
let mutex = mutex.as_str();
995-
let suggestions: FxHashMap<_, _> = [
996-
(self.infcx.tcx.types.isize, "std::sync::atomic::AtomicIsize"),
997-
(self.infcx.tcx.types.usize, "std::sync::atomic::AtomicUsize"),
998-
(self.infcx.tcx.types.i64, "std::sync::atomic::AtomicI64"),
999-
(self.infcx.tcx.types.u64, "std::sync::atomic::AtomicU64"),
1000-
(self.infcx.tcx.types.i32, "std::sync::atomic::AtomicI32"),
1001-
(self.infcx.tcx.types.u32, "std::sync::atomic::AtomicU32"),
1002-
(self.infcx.tcx.types.i16, "std::sync::atomic::AtomicI16"),
1003-
(self.infcx.tcx.types.u16, "std::sync::atomic::AtomicU16"),
1004-
(self.infcx.tcx.types.i8, "std::sync::atomic::AtomicI8"),
1005-
(self.infcx.tcx.types.u8, "std::sync::atomic::AtomicU8"),
1006-
(self.infcx.tcx.types.bool, "std::sync::atomic::AtomicBool"),
1007-
]
1008-
.into_iter()
1009-
.collect();
1010-
let ty = suggestions.get(&ty).unwrap_or(&mutex);
1011-
err.help(format!("consider using `{ty}` instead, which allows for multiple threads to access and modify the value"));
1012-
}
1013986
let name = upvar.to_string(self.infcx.tcx);
1014987
err.span_label(
1015988
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)