Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3fcf43b

Browse files
committedJun 29, 2022
Auto merge of rust-lang#98669 - Dylan-DPC:rollup-8uzhcip, r=Dylan-DPC
Rollup of 7 pull requests Successful merges: - rust-lang#98415 (Migrate some `rustc_borrowck` diagnostics to `SessionDiagnostic`) - rust-lang#98479 (Add `fetch_not` method on `AtomicBool`) - rust-lang#98499 (Erase regions in New Abstract Consts) - rust-lang#98516 (library: fix uefi va_list type definition) - rust-lang#98554 (Fix box with custom allocator in miri) - rust-lang#98607 (Clean up arg mismatch diagnostic, generalize tuple wrap suggestion) - rust-lang#98625 (emit Retag for compound types with reference fields) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 66c83ff + 68228be commit 3fcf43b

File tree

39 files changed

+511
-271
lines changed

39 files changed

+511
-271
lines changed
 

‎Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3595,6 +3595,7 @@ dependencies = [
35953595
"rustc_index",
35963596
"rustc_infer",
35973597
"rustc_lexer",
3598+
"rustc_macros",
35983599
"rustc_middle",
35993600
"rustc_mir_dataflow",
36003601
"rustc_serialize",

‎compiler/rustc_borrowck/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ rustc_hir = { path = "../rustc_hir" }
1919
rustc_index = { path = "../rustc_index" }
2020
rustc_infer = { path = "../rustc_infer" }
2121
rustc_lexer = { path = "../rustc_lexer" }
22+
rustc_macros = { path = "../rustc_macros" }
2223
rustc_middle = { path = "../rustc_middle" }
2324
rustc_const_eval = { path = "../rustc_const_eval" }
2425
rustc_mir_dataflow = { path = "../rustc_mir_dataflow" }

‎compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ use std::fmt;
1919
use std::rc::Rc;
2020

2121
use crate::region_infer::values::RegionElement;
22+
use crate::session_diagnostics::HigherRankedErrorCause;
23+
use crate::session_diagnostics::HigherRankedLifetimeError;
24+
use crate::session_diagnostics::HigherRankedSubtypeError;
2225
use crate::MirBorrowckCtxt;
2326

2427
#[derive(Clone)]
@@ -69,7 +72,7 @@ impl<'tcx> UniverseInfo<'tcx> {
6972
// up in the existing UI tests. Consider investigating this
7073
// some more.
7174
mbcx.buffer_error(
72-
mbcx.infcx.tcx.sess.struct_span_err(cause.span, "higher-ranked subtype error"),
75+
mbcx.infcx.tcx.sess.create_err(HigherRankedSubtypeError { span: cause.span }),
7376
);
7477
}
7578
}
@@ -216,9 +219,12 @@ impl<'tcx> TypeOpInfo<'tcx> for PredicateQuery<'tcx> {
216219
tcx: TyCtxt<'tcx>,
217220
span: Span,
218221
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
219-
let mut err = tcx.sess.struct_span_err(span, "higher-ranked lifetime error");
220-
err.note(&format!("could not prove {}", self.canonical_query.value.value.predicate));
221-
err
222+
tcx.sess.create_err(HigherRankedLifetimeError {
223+
cause: Some(HigherRankedErrorCause::CouldNotProve {
224+
predicate: self.canonical_query.value.value.predicate.to_string(),
225+
}),
226+
span,
227+
})
222228
}
223229

224230
fn base_universe(&self) -> ty::UniverseIndex {
@@ -263,9 +269,12 @@ where
263269
tcx: TyCtxt<'tcx>,
264270
span: Span,
265271
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
266-
let mut err = tcx.sess.struct_span_err(span, "higher-ranked lifetime error");
267-
err.note(&format!("could not normalize `{}`", self.canonical_query.value.value.value));
268-
err
272+
tcx.sess.create_err(HigherRankedLifetimeError {
273+
cause: Some(HigherRankedErrorCause::CouldNotNormalize {
274+
value: self.canonical_query.value.value.value.to_string(),
275+
}),
276+
span,
277+
})
269278
}
270279

271280
fn base_universe(&self) -> ty::UniverseIndex {
@@ -326,7 +335,7 @@ impl<'tcx> TypeOpInfo<'tcx> for AscribeUserTypeQuery<'tcx> {
326335
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
327336
// FIXME: This error message isn't great, but it doesn't show up in the existing UI tests,
328337
// and is only the fallback when the nice error fails. Consider improving this some more.
329-
tcx.sess.struct_span_err(span, "higher-ranked lifetime error")
338+
tcx.sess.create_err(HigherRankedLifetimeError { cause: None, span })
330339
}
331340

332341
fn base_universe(&self) -> ty::UniverseIndex {
@@ -366,7 +375,7 @@ impl<'tcx> TypeOpInfo<'tcx> for crate::type_check::InstantiateOpaqueType<'tcx> {
366375
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
367376
// FIXME: This error message isn't great, but it doesn't show up in the existing UI tests,
368377
// and is only the fallback when the nice error fails. Consider improving this some more.
369-
tcx.sess.struct_span_err(span, "higher-ranked lifetime error for opaque type!")
378+
tcx.sess.create_err(HigherRankedLifetimeError { cause: None, span })
370379
}
371380

372381
fn base_universe(&self) -> ty::UniverseIndex {

‎compiler/rustc_borrowck/src/diagnostics/region_errors.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use rustc_span::symbol::Ident;
2424
use rustc_span::Span;
2525

2626
use crate::borrowck_errors;
27+
use crate::session_diagnostics::GenericDoesNotLiveLongEnough;
2728

2829
use super::{OutlivesSuggestionBuilder, RegionName};
2930
use crate::region_infer::BlameConstraint;
@@ -196,9 +197,11 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
196197
// to report it; we could probably handle it by
197198
// iterating over the universal regions and reporting
198199
// an error that multiple bounds are required.
199-
self.buffer_error(self.infcx.tcx.sess.struct_span_err(
200-
type_test_span,
201-
&format!("`{}` does not live long enough", type_test.generic_kind),
200+
self.buffer_error(self.infcx.tcx.sess.create_err(
201+
GenericDoesNotLiveLongEnough {
202+
kind: type_test.generic_kind.to_string(),
203+
span: type_test_span,
204+
},
202205
));
203206
}
204207
}

‎compiler/rustc_borrowck/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ mod places_conflict;
7676
mod prefixes;
7777
mod region_infer;
7878
mod renumber;
79+
mod session_diagnostics;
7980
mod type_check;
8081
mod universal_regions;
8182
mod used_muts;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic};
2+
use rustc_middle::ty::Ty;
3+
use rustc_span::Span;
4+
5+
#[derive(SessionDiagnostic)]
6+
#[error(borrowck::move_unsized, code = "E0161")]
7+
pub(crate) struct MoveUnsized<'tcx> {
8+
pub ty: Ty<'tcx>,
9+
#[primary_span]
10+
#[label]
11+
pub span: Span,
12+
}
13+
14+
#[derive(SessionDiagnostic)]
15+
#[error(borrowck::higher_ranked_lifetime_error)]
16+
pub(crate) struct HigherRankedLifetimeError {
17+
#[subdiagnostic]
18+
pub cause: Option<HigherRankedErrorCause>,
19+
#[primary_span]
20+
pub span: Span,
21+
}
22+
23+
#[derive(SessionSubdiagnostic)]
24+
pub(crate) enum HigherRankedErrorCause {
25+
#[note(borrowck::could_not_prove)]
26+
CouldNotProve { predicate: String },
27+
#[note(borrowck::could_not_normalize)]
28+
CouldNotNormalize { value: String },
29+
}
30+
31+
#[derive(SessionDiagnostic)]
32+
#[error(borrowck::higher_ranked_subtype_error)]
33+
pub(crate) struct HigherRankedSubtypeError {
34+
#[primary_span]
35+
pub span: Span,
36+
}
37+
38+
#[derive(SessionDiagnostic)]
39+
#[error(borrowck::generic_does_not_live_long_enough)]
40+
pub(crate) struct GenericDoesNotLiveLongEnough {
41+
pub kind: String,
42+
#[primary_span]
43+
pub span: Span,
44+
}

‎compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use hir::OpaqueTyOrigin;
99
use rustc_data_structures::frozen::Frozen;
1010
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1111
use rustc_data_structures::vec_map::VecMap;
12-
use rustc_errors::struct_span_err;
1312
use rustc_hir as hir;
1413
use rustc_hir::def::DefKind;
1514
use rustc_hir::def_id::LocalDefId;
@@ -48,6 +47,7 @@ use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
4847
use rustc_mir_dataflow::move_paths::MoveData;
4948
use rustc_mir_dataflow::ResultsCursor;
5049

50+
use crate::session_diagnostics::MoveUnsized;
5151
use crate::{
5252
borrow_set::BorrowSet,
5353
constraints::{OutlivesConstraint, OutlivesConstraintSet},
@@ -1780,19 +1780,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
17801780
// slot or local, so to find all unsized rvalues it is enough
17811781
// to check all temps, return slots and locals.
17821782
if self.reported_errors.replace((ty, span)).is_none() {
1783-
let mut diag = struct_span_err!(
1784-
self.tcx().sess,
1785-
span,
1786-
E0161,
1787-
"cannot move a value of type {0}: the size of {0} \
1788-
cannot be statically determined",
1789-
ty
1790-
);
1791-
17921783
// While this is located in `nll::typeck` this error is not
17931784
// an NLL error, it's a required check to prevent creation
17941785
// of unsized rvalues in a call expression.
1795-
diag.emit();
1786+
self.tcx().sess.emit_err(MoveUnsized { ty, span });
17961787
}
17971788
}
17981789
}

‎compiler/rustc_const_eval/src/interpret/cast.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -366,22 +366,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
366366
}
367367
(&ty::Adt(def_a, _), &ty::Adt(def_b, _)) => {
368368
assert_eq!(def_a, def_b);
369-
if def_a.is_box() || def_b.is_box() {
370-
if !def_a.is_box() || !def_b.is_box() {
371-
span_bug!(
372-
self.cur_span(),
373-
"invalid unsizing between {:?} -> {:?}",
374-
src.layout.ty,
375-
cast_ty.ty
376-
);
377-
}
378-
return self.unsize_into_ptr(
379-
src,
380-
dest,
381-
src.layout.ty.boxed_ty(),
382-
cast_ty.ty.boxed_ty(),
383-
);
384-
}
385369

386370
// unsizing of generic struct with pointer fields
387371
// Example: `Arc<T>` -> `Arc<Trait>`

‎compiler/rustc_const_eval/src/interpret/validity.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,13 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
594594
Ok(true)
595595
}
596596
ty::Adt(def, ..) if def.is_box() => {
597-
self.check_safe_pointer(value, "box")?;
597+
let unique = self.ecx.operand_field(value, 0)?;
598+
let nonnull = self.ecx.operand_field(&unique, 0)?;
599+
let ptr = self.ecx.operand_field(&nonnull, 0)?;
600+
self.check_safe_pointer(&ptr, "box")?;
601+
602+
// Check other fields of Box
603+
self.walk_value(value)?;
598604
Ok(true)
599605
}
600606
ty::FnPtr(_sig) => {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
borrowck-move-unsized =
2+
cannot move a value of type `{$ty}`
3+
.label = the size of `{$ty}` cannot be statically determined
4+
5+
borrowck-higher-ranked-lifetime-error =
6+
higher-ranked lifetime error
7+
8+
borrowck-could-not-prove =
9+
could not prove `{$predicate}`
10+
11+
borrowck-could-not-normalize =
12+
could not normalize `{$value}`
13+
14+
borrowck-higher-ranked-subtype-error =
15+
higher-ranked subtype error
16+
17+
generic-does-not-live-long-enough =
18+
`{$kind}` does not live long enough

‎compiler/rustc_error_messages/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ fluent_messages! {
3535
privacy => "../locales/en-US/privacy.ftl",
3636
typeck => "../locales/en-US/typeck.ftl",
3737
builtin_macros => "../locales/en-US/builtin_macros.ftl",
38+
borrowck => "../locales/en-US/borrowck.ftl",
3839
}
3940

4041
pub use fluent_generated::{self as fluent, DEFAULT_LOCALE_RESOURCES};

‎compiler/rustc_errors/src/emitter.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,19 @@ pub trait Emitter {
281281
let message = bundle.get_message(&identifier).expect("missing diagnostic in fluent bundle");
282282
let value = match attr {
283283
Some(attr) => {
284-
message.get_attribute(attr).expect("missing attribute in fluent message").value()
284+
if let Some(attr) = message.get_attribute(attr) {
285+
attr.value()
286+
} else {
287+
panic!("missing attribute `{attr}` in fluent message `{identifier}`")
288+
}
289+
}
290+
None => {
291+
if let Some(value) = message.value() {
292+
value
293+
} else {
294+
panic!("missing value in fluent message `{identifier}`")
295+
}
285296
}
286-
None => message.value().expect("missing value in fluent message"),
287297
};
288298

289299
let mut err = vec![];

‎compiler/rustc_infer/src/infer/error_reporting/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,8 @@ pub fn same_type_modulo_infer<'tcx>(a: Ty<'tcx>, b: Ty<'tcx>) -> bool {
342342
)
343343
| (&ty::Infer(ty::InferTy::TyVar(_)), _)
344344
| (_, &ty::Infer(ty::InferTy::TyVar(_))) => true,
345-
(&ty::Ref(reg_a, ty_a, mut_a), &ty::Ref(reg_b, ty_b, mut_b)) => {
346-
reg_a == reg_b && mut_a == mut_b && same_type_modulo_infer(*ty_a, *ty_b)
345+
(&ty::Ref(_, ty_a, mut_a), &ty::Ref(_, ty_b, mut_b)) => {
346+
mut_a == mut_b && same_type_modulo_infer(*ty_a, *ty_b)
347347
}
348348
_ => a == b,
349349
}

‎compiler/rustc_mir_transform/src/add_retag.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ fn is_stable(place: PlaceRef<'_>) -> bool {
3333
})
3434
}
3535

36-
/// Determine whether this type may be a reference (or box), and thus needs retagging.
37-
fn may_be_reference(ty: Ty<'_>) -> bool {
36+
/// Determine whether this type may contain a reference (or box), and thus needs retagging.
37+
/// We will only recurse `depth` times into Tuples/ADTs to bound the cost of this.
38+
fn may_contain_reference<'tcx>(ty: Ty<'tcx>, depth: u32, tcx: TyCtxt<'tcx>) -> bool {
3839
match ty.kind() {
3940
// Primitive types that are not references
4041
ty::Bool
@@ -50,8 +51,20 @@ fn may_be_reference(ty: Ty<'_>) -> bool {
5051
// References
5152
ty::Ref(..) => true,
5253
ty::Adt(..) if ty.is_box() => true,
53-
// Compound types are not references
54-
ty::Array(..) | ty::Slice(..) | ty::Tuple(..) | ty::Adt(..) => false,
54+
// Compound types: recurse
55+
ty::Array(ty, _) | ty::Slice(ty) => {
56+
// This does not branch so we keep the depth the same.
57+
may_contain_reference(*ty, depth, tcx)
58+
}
59+
ty::Tuple(tys) => {
60+
depth == 0 || tys.iter().any(|ty| may_contain_reference(ty, depth - 1, tcx))
61+
}
62+
ty::Adt(adt, subst) => {
63+
depth == 0
64+
|| adt.variants().iter().any(|v| {
65+
v.fields.iter().any(|f| may_contain_reference(f.ty(tcx, subst), depth - 1, tcx))
66+
})
67+
}
5568
// Conservative fallback
5669
_ => true,
5770
}
@@ -83,7 +96,7 @@ impl<'tcx> MirPass<'tcx> for AddRetag {
8396
// FIXME: Instead of giving up for unstable places, we should introduce
8497
// a temporary and retag on that.
8598
is_stable(place.as_ref())
86-
&& may_be_reference(place.ty(&*local_decls, tcx).ty)
99+
&& may_contain_reference(place.ty(&*local_decls, tcx).ty, /*depth*/ 3, tcx)
87100
&& is_not_temp(&local_decls[place.local])
88101
};
89102
let place_base_raw = |place: &Place<'tcx>| {

‎compiler/rustc_trait_selection/src/traits/const_evaluatable.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ impl<'tcx> AbstractConst<'tcx> {
236236
) -> Result<Option<AbstractConst<'tcx>>, ErrorGuaranteed> {
237237
let inner = tcx.thir_abstract_const_opt_const_arg(uv.def)?;
238238
debug!("AbstractConst::new({:?}) = {:?}", uv, inner);
239-
Ok(inner.map(|inner| AbstractConst { inner, substs: uv.substs }))
239+
Ok(inner.map(|inner| AbstractConst { inner, substs: tcx.erase_regions(uv.substs) }))
240240
}
241241

242242
pub fn from_const(
@@ -416,6 +416,7 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
416416
// `AbstractConst`s should not contain any promoteds as they require references which
417417
// are not allowed.
418418
assert_eq!(ct.promoted, None);
419+
assert_eq!(ct, self.tcx.erase_regions(ct));
419420
}
420421
}
421422
}

‎compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

Lines changed: 169 additions & 177 deletions
Large diffs are not rendered by default.

‎library/core/src/ffi/mod.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ impl fmt::Debug for c_void {
231231
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios")),
232232
target_family = "wasm",
233233
target_arch = "asmjs",
234-
windows
234+
target_os = "uefi",
235+
windows,
235236
))]
236237
#[repr(transparent)]
237238
#[unstable(
@@ -254,7 +255,8 @@ pub struct VaListImpl<'f> {
254255
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios")),
255256
target_family = "wasm",
256257
target_arch = "asmjs",
257-
windows
258+
target_os = "uefi",
259+
windows,
258260
))]
259261
#[unstable(
260262
feature = "c_variadic",
@@ -276,7 +278,8 @@ impl<'f> fmt::Debug for VaListImpl<'f> {
276278
#[cfg(all(
277279
target_arch = "aarch64",
278280
not(any(target_os = "macos", target_os = "ios")),
279-
not(windows)
281+
not(target_os = "uefi"),
282+
not(windows),
280283
))]
281284
#[repr(C)]
282285
#[derive(Debug)]
@@ -297,7 +300,7 @@ pub struct VaListImpl<'f> {
297300
}
298301

299302
/// PowerPC ABI implementation of a `va_list`.
300-
#[cfg(all(target_arch = "powerpc", not(windows)))]
303+
#[cfg(all(target_arch = "powerpc", not(target_os = "uefi"), not(windows)))]
301304
#[repr(C)]
302305
#[derive(Debug)]
303306
#[unstable(
@@ -317,7 +320,7 @@ pub struct VaListImpl<'f> {
317320
}
318321

319322
/// x86_64 ABI implementation of a `va_list`.
320-
#[cfg(all(target_arch = "x86_64", not(windows)))]
323+
#[cfg(all(target_arch = "x86_64", not(target_os = "uefi"), not(windows)))]
321324
#[repr(C)]
322325
#[derive(Debug)]
323326
#[unstable(
@@ -354,7 +357,8 @@ pub struct VaList<'a, 'f: 'a> {
354357
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios")),
355358
target_family = "wasm",
356359
target_arch = "asmjs",
357-
windows
360+
target_os = "uefi",
361+
windows,
358362
))]
359363
inner: VaListImpl<'f>,
360364

@@ -363,7 +367,8 @@ pub struct VaList<'a, 'f: 'a> {
363367
any(not(target_arch = "aarch64"), not(any(target_os = "macos", target_os = "ios"))),
364368
not(target_family = "wasm"),
365369
not(target_arch = "asmjs"),
366-
not(windows)
370+
not(target_os = "uefi"),
371+
not(windows),
367372
))]
368373
inner: &'a mut VaListImpl<'f>,
369374

@@ -375,7 +380,8 @@ pub struct VaList<'a, 'f: 'a> {
375380
all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios")),
376381
target_family = "wasm",
377382
target_arch = "asmjs",
378-
windows
383+
target_os = "uefi",
384+
windows,
379385
))]
380386
#[unstable(
381387
feature = "c_variadic",
@@ -396,7 +402,8 @@ impl<'f> VaListImpl<'f> {
396402
any(not(target_arch = "aarch64"), not(any(target_os = "macos", target_os = "ios"))),
397403
not(target_family = "wasm"),
398404
not(target_arch = "asmjs"),
399-
not(windows)
405+
not(target_os = "uefi"),
406+
not(windows),
400407
))]
401408
#[unstable(
402409
feature = "c_variadic",

‎library/core/src/sync/atomic.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,42 @@ impl AtomicBool {
854854
unsafe { atomic_xor(self.v.get(), val as u8, order) != 0 }
855855
}
856856

857+
/// Logical "not" with a boolean value.
858+
///
859+
/// Performs a logical "not" operation on the current value, and sets
860+
/// the new value to the result.
861+
///
862+
/// Returns the previous value.
863+
///
864+
/// `fetch_not` takes an [`Ordering`] argument which describes the memory ordering
865+
/// of this operation. All ordering modes are possible. Note that using
866+
/// [`Acquire`] makes the store part of this operation [`Relaxed`], and
867+
/// using [`Release`] makes the load part [`Relaxed`].
868+
///
869+
/// **Note:** This method is only available on platforms that support atomic
870+
/// operations on `u8`.
871+
///
872+
/// # Examples
873+
///
874+
/// ```
875+
/// #![feature(atomic_bool_fetch_not)]
876+
/// use std::sync::atomic::{AtomicBool, Ordering};
877+
///
878+
/// let foo = AtomicBool::new(true);
879+
/// assert_eq!(foo.fetch_not(Ordering::SeqCst), true);
880+
/// assert_eq!(foo.load(Ordering::SeqCst), false);
881+
///
882+
/// let foo = AtomicBool::new(false);
883+
/// assert_eq!(foo.fetch_not(Ordering::SeqCst), false);
884+
/// assert_eq!(foo.load(Ordering::SeqCst), true);
885+
/// ```
886+
#[inline]
887+
#[unstable(feature = "atomic_bool_fetch_not", issue = "98485")]
888+
#[cfg(target_has_atomic = "8")]
889+
pub fn fetch_not(&self, order: Ordering) -> bool {
890+
self.fetch_xor(true, order)
891+
}
892+
857893
/// Returns a mutable pointer to the underlying [`bool`].
858894
///
859895
/// Doing non-atomic reads and writes on the resulting integer can be a data race.

‎src/test/mir-opt/retag.array_casts.SimplifyCfg-elaborate-drops.after.mir

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ fn array_casts() -> () {
129129
_18 = &(*_35); // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
130130
Retag(_18); // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
131131
_13 = (move _14, move _18); // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
132+
Retag(_13); // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
132133
StorageDead(_18); // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
133134
StorageDead(_14); // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
134135
StorageLive(_20); // scope 5 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
@@ -171,6 +172,7 @@ fn array_casts() -> () {
171172
Retag(_32); // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
172173
StorageLive(_34); // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
173174
_34 = Option::<Arguments>::None; // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
175+
Retag(_34); // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
174176
_28 = core::panicking::assert_failed::<usize, usize>(move _29, move _30, move _32, move _34); // scope 8 at $SRC_DIR/core/src/macros/mod.rs:LL:COL
175177
// mir::Constant
176178
// + span: $SRC_DIR/core/src/macros/mod.rs:LL:COL
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// check-pass
2+
#![feature(generic_const_exprs)]
3+
#![allow(incomplete_features)]
4+
5+
struct Num<const N: usize>;
6+
7+
trait NumT {
8+
const VALUE: usize;
9+
}
10+
11+
impl<const N: usize> NumT for Num<N> {
12+
const VALUE: usize = N;
13+
}
14+
15+
struct Foo<'a, N: NumT>(&'a [u32; N::VALUE]) where [(); N::VALUE]:;
16+
17+
trait Bar {
18+
type Size: NumT;
19+
20+
fn bar<'a>(foo: &Foo<'a, Self::Size>) where [(); Self::Size::VALUE]: {
21+
todo!();
22+
}
23+
}
24+
25+
trait Baz<'a> {
26+
type Size: NumT;
27+
28+
fn baz(foo: &Foo<'a, Self::Size>) where [(); Self::Size::VALUE]: {
29+
todo!();
30+
}
31+
}
32+
33+
fn main() {}

‎src/test/ui/dst/dst-index.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
error[E0161]: cannot move a value of type str: the size of str cannot be statically determined
1+
error[E0161]: cannot move a value of type `str`
22
--> $DIR/dst-index.rs:31:5
33
|
44
LL | S[0];
5-
| ^^^^
5+
| ^^^^ the size of `str` cannot be statically determined
66

7-
error[E0161]: cannot move a value of type dyn Debug: the size of dyn Debug cannot be statically determined
7+
error[E0161]: cannot move a value of type `dyn Debug`
88
--> $DIR/dst-index.rs:34:5
99
|
1010
LL | T[0];
11-
| ^^^^
11+
| ^^^^ the size of `dyn Debug` cannot be statically determined
1212

1313
error[E0507]: cannot move out of index of `S`
1414
--> $DIR/dst-index.rs:31:5

‎src/test/ui/error-codes/E0161.base.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0161]: cannot move a value of type dyn Bar: the size of dyn Bar cannot be statically determined
1+
error[E0161]: cannot move a value of type `dyn Bar`
22
--> $DIR/E0161.rs:16:5
33
|
44
LL | x.f();
5-
| ^^^^^
5+
| ^^^^^ the size of `dyn Bar` cannot be statically determined
66

77
error: aborting due to previous error
88

‎src/test/ui/higher-rank-trait-bounds/issue-59311.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ error: higher-ranked lifetime error
44
LL | v.t(|| {});
55
| ^^^^^^^^^^
66
|
7-
= note: could not prove [closure@$DIR/issue-59311.rs:17:9: 17:14] well-formed
7+
= note: could not prove `[closure@$DIR/issue-59311.rs:17:9: 17:14] well-formed`
88

99
error: higher-ranked lifetime error
1010
--> $DIR/issue-59311.rs:17:9
1111
|
1212
LL | v.t(|| {});
1313
| ^^^^^
1414
|
15-
= note: could not prove for<'a> &'a V: 'static
15+
= note: could not prove `for<'a> &'a V: 'static`
1616

1717
error: aborting due to 2 previous errors
1818

‎src/test/ui/lifetimes/re-empty-in-error.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: higher-ranked lifetime error
44
LL | foo(&10);
55
| ^^^^^^^^
66
|
7-
= note: could not prove for<'b, 'r> &'b (): 'r
7+
= note: could not prove `for<'b, 'r> &'b (): 'r`
88

99
error: aborting due to previous error
1010

‎src/test/ui/mir/issue-67947.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
struct Bug {
22
A: [(); { *"" }.len()],
3-
//~^ ERROR: cannot move a value of type str
3+
//~^ ERROR: cannot move a value of type `str`
44
//~| ERROR: cannot move out of a shared reference
55
}
66

‎src/test/ui/mir/issue-67947.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0161]: cannot move a value of type str: the size of str cannot be statically determined
1+
error[E0161]: cannot move a value of type `str`
22
--> $DIR/issue-67947.rs:2:13
33
|
44
LL | A: [(); { *"" }.len()],
5-
| ^^^^^^^
5+
| ^^^^^^^ the size of `str` cannot be statically determined
66

77
error[E0507]: cannot move out of a shared reference
88
--> $DIR/issue-67947.rs:2:15

‎src/test/ui/object-safety/object-safety-by-value-self-use.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ trait Baz {
1212
}
1313

1414
fn use_bar(t: Box<dyn Bar>) {
15-
t.bar() //~ ERROR cannot move a value of type dyn Bar
15+
t.bar() //~ ERROR cannot move a value of type `dyn Bar`
1616
}
1717

1818
fn main() { }

‎src/test/ui/object-safety/object-safety-by-value-self-use.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0161]: cannot move a value of type dyn Bar: the size of dyn Bar cannot be statically determined
1+
error[E0161]: cannot move a value of type `dyn Bar`
22
--> $DIR/object-safety-by-value-self-use.rs:15:5
33
|
44
LL | t.bar()
5-
| ^^^^^^^
5+
| ^^^^^^^ the size of `dyn Bar` cannot be statically determined
66

77
error: aborting due to previous error
88

‎src/test/ui/proc-macro/signature.stderr

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ LL | / pub unsafe extern "C" fn foo(a: i32, b: u32) -> u32 {
55
LL | |
66
LL | | loop {}
77
LL | | }
8-
| | ^
9-
| | |
10-
| |_call the function in a closure: `|| unsafe { /* code */ }`
11-
| required by a bound introduced by this call
8+
| |_^ call the function in a closure: `|| unsafe { /* code */ }`
129
|
1310
= help: the trait `Fn<(proc_macro::TokenStream,)>` is not implemented for `unsafe extern "C" fn(i32, u32) -> u32 {foo}`
1411
= note: unsafe function cannot be called generically without an unsafe block

‎src/test/ui/suggestions/args-instead-of-tuple.stderr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ note: tuple variant defined here
99
|
1010
LL | Ok(#[stable(feature = "rust1", since = "1.0.0")] T),
1111
| ^^
12-
help: use parentheses to construct a tuple
12+
help: wrap these arguments in parentheses to construct a tuple
1313
|
1414
LL | let _: Result<(i32, i8), ()> = Ok((1, 2));
1515
| + +
@@ -25,7 +25,7 @@ note: tuple variant defined here
2525
|
2626
LL | Some(#[stable(feature = "rust1", since = "1.0.0")] T),
2727
| ^^^^
28-
help: use parentheses to construct a tuple
28+
help: wrap these arguments in parentheses to construct a tuple
2929
|
3030
LL | let _: Option<(i32, i8, &'static str)> = Some((1, 2, "hi"));
3131
| + +
@@ -97,7 +97,7 @@ note: function defined here
9797
|
9898
LL | fn two_ints(_: (i32, i32)) {
9999
| ^^^^^^^^ -------------
100-
help: use parentheses to construct a tuple
100+
help: wrap these arguments in parentheses to construct a tuple
101101
|
102102
LL | two_ints((1, 2));
103103
| + +
@@ -113,7 +113,7 @@ note: function defined here
113113
|
114114
LL | fn with_generic<T: Copy + Send>((a, b): (i32, T)) {
115115
| ^^^^^^^^^^^^ ----------------
116-
help: use parentheses to construct a tuple
116+
help: wrap these arguments in parentheses to construct a tuple
117117
|
118118
LL | with_generic((3, 4));
119119
| + +
@@ -129,7 +129,7 @@ note: function defined here
129129
|
130130
LL | fn with_generic<T: Copy + Send>((a, b): (i32, T)) {
131131
| ^^^^^^^^^^^^ ----------------
132-
help: use parentheses to construct a tuple
132+
help: wrap these arguments in parentheses to construct a tuple
133133
|
134134
LL | with_generic((a, b));
135135
| + +
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
fn foo(s: &str, a: (i32, i32), s2: &str) {}
2+
3+
fn bar(s: &str, a: (&str,), s2: &str) {}
4+
5+
fn main() {
6+
foo("hi", 1, 2, "hi");
7+
//~^ ERROR this function takes 3 arguments but 4 arguments were supplied
8+
bar("hi", "hi", "hi");
9+
//~^ ERROR mismatched types
10+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
error[E0061]: this function takes 3 arguments but 4 arguments were supplied
2+
--> $DIR/add-tuple-within-arguments.rs:6:5
3+
|
4+
LL | foo("hi", 1, 2, "hi");
5+
| ^^^
6+
|
7+
note: function defined here
8+
--> $DIR/add-tuple-within-arguments.rs:1:4
9+
|
10+
LL | fn foo(s: &str, a: (i32, i32), s2: &str) {}
11+
| ^^^ ------- ------------- --------
12+
help: wrap these arguments in parentheses to construct a tuple
13+
|
14+
LL | foo("hi", (1, 2), "hi");
15+
| + +
16+
17+
error[E0308]: mismatched types
18+
--> $DIR/add-tuple-within-arguments.rs:8:15
19+
|
20+
LL | bar("hi", "hi", "hi");
21+
| --- ^^^^ expected tuple, found `&str`
22+
| |
23+
| arguments to this function are incorrect
24+
|
25+
= note: expected tuple `(&str,)`
26+
found reference `&'static str`
27+
note: function defined here
28+
--> $DIR/add-tuple-within-arguments.rs:3:4
29+
|
30+
LL | fn bar(s: &str, a: (&str,), s2: &str) {}
31+
| ^^^ ------- ---------- --------
32+
help: use a trailing comma to create a tuple with one element
33+
|
34+
LL | bar("hi", ("hi",), "hi");
35+
| + ++
36+
37+
error: aborting due to 2 previous errors
38+
39+
Some errors have detailed explanations: E0061, E0308.
40+
For more information about an error, try `rustc --explain E0061`.

‎src/test/ui/tuple/wrong_argument_ice-2.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ note: function defined here
99
|
1010
LL | fn test(t: (i32, i32)) {}
1111
| ^^^^ -------------
12-
help: use parentheses to construct a tuple
12+
help: wrap these arguments in parentheses to construct a tuple
1313
|
1414
LL | test((x.qux(), x.qux()));
1515
| + +

‎src/test/ui/tuple/wrong_argument_ice.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ note: associated function defined here
99
|
1010
LL | pub fn push_back(&mut self, value: T) {
1111
| ^^^^^^^^^
12-
help: use parentheses to construct a tuple
12+
help: wrap these arguments in parentheses to construct a tuple
1313
|
1414
LL | self.acc.push_back((self.current_provides, self.current_requires));
1515
| + +

‎src/test/ui/unsized/return-unsized-from-trait-method.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ trait Foo {
77
fn foo(f: Option<&dyn Foo>) {
88
if let Some(f) = f {
99
let _ = f.foo();
10-
//~^ ERROR cannot move a value of type [u8]: the size of [u8] cannot be statically determined
10+
//~^ ERROR cannot move a value of type `[u8]`
1111
}
1212
}
1313

‎src/test/ui/unsized/return-unsized-from-trait-method.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0161]: cannot move a value of type [u8]: the size of [u8] cannot be statically determined
1+
error[E0161]: cannot move a value of type `[u8]`
22
--> $DIR/return-unsized-from-trait-method.rs:9:17
33
|
44
LL | let _ = f.foo();
5-
| ^^^^^^^
5+
| ^^^^^^^ the size of `[u8]` cannot be statically determined
66

77
error: aborting due to previous error
88

‎src/test/ui/unsized/unsized-fn-param.stderr

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ error[E0277]: the size for values of type `str` cannot be known at compilation t
22
--> $DIR/unsized-fn-param.rs:11:11
33
|
44
LL | foo11("bar", &"baz");
5-
| ^^^^^ doesn't have a size known at compile-time
5+
| ----- ^^^^^ doesn't have a size known at compile-time
6+
| |
7+
| required by a bound introduced by this call
68
|
79
= help: the trait `Sized` is not implemented for `str`
810
= note: required for the cast from `str` to the object type `dyn AsRef<Path>`
@@ -15,7 +17,9 @@ error[E0277]: the size for values of type `str` cannot be known at compilation t
1517
--> $DIR/unsized-fn-param.rs:13:19
1618
|
1719
LL | foo12(&"bar", "baz");
18-
| ^^^^^ doesn't have a size known at compile-time
20+
| ----- ^^^^^ doesn't have a size known at compile-time
21+
| |
22+
| required by a bound introduced by this call
1923
|
2024
= help: the trait `Sized` is not implemented for `str`
2125
= note: required for the cast from `str` to the object type `dyn AsRef<Path>`
@@ -28,7 +32,9 @@ error[E0277]: the size for values of type `str` cannot be known at compilation t
2832
--> $DIR/unsized-fn-param.rs:16:11
2933
|
3034
LL | foo21("bar", &"baz");
31-
| ^^^^^ doesn't have a size known at compile-time
35+
| ----- ^^^^^ doesn't have a size known at compile-time
36+
| |
37+
| required by a bound introduced by this call
3238
|
3339
= help: the trait `Sized` is not implemented for `str`
3440
= note: required for the cast from `str` to the object type `dyn AsRef<str>`
@@ -41,7 +47,9 @@ error[E0277]: the size for values of type `str` cannot be known at compilation t
4147
--> $DIR/unsized-fn-param.rs:18:19
4248
|
4349
LL | foo22(&"bar", "baz");
44-
| ^^^^^ doesn't have a size known at compile-time
50+
| ----- ^^^^^ doesn't have a size known at compile-time
51+
| |
52+
| required by a bound introduced by this call
4553
|
4654
= help: the trait `Sized` is not implemented for `str`
4755
= note: required for the cast from `str` to the object type `dyn AsRef<str>`

‎src/test/ui/unsized/unsized3.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ fn f9<X: ?Sized>(x1: Box<S<X>>) {
4444
fn f10<X: ?Sized>(x1: Box<S<X>>) {
4545
f5(&(32, *x1));
4646
//~^ ERROR the size for values of type
47+
//~| ERROR the size for values of type
4748
}
4849

4950
pub fn main() {}

‎src/test/ui/unsized/unsized3.stderr

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,29 @@ LL - fn f9<X: ?Sized>(x1: Box<S<X>>) {
100100
LL + fn f9<X>(x1: Box<S<X>>) {
101101
|
102102

103+
error[E0277]: the size for values of type `X` cannot be known at compilation time
104+
--> $DIR/unsized3.rs:45:9
105+
|
106+
LL | fn f10<X: ?Sized>(x1: Box<S<X>>) {
107+
| - this type parameter needs to be `std::marker::Sized`
108+
LL | f5(&(32, *x1));
109+
| -- ^^^^^^^^^ doesn't have a size known at compile-time
110+
| |
111+
| required by a bound introduced by this call
112+
|
113+
note: required because it appears within the type `S<X>`
114+
--> $DIR/unsized3.rs:28:8
115+
|
116+
LL | struct S<X: ?Sized> {
117+
| ^
118+
= note: required because it appears within the type `({integer}, S<X>)`
119+
= note: tuples must have a statically known size to be initialized
120+
help: consider removing the `?Sized` bound to make the type parameter `Sized`
121+
|
122+
LL - fn f10<X: ?Sized>(x1: Box<S<X>>) {
123+
LL + fn f10<X>(x1: Box<S<X>>) {
124+
|
125+
103126
error[E0277]: the size for values of type `X` cannot be known at compilation time
104127
--> $DIR/unsized3.rs:45:8
105128
|
@@ -116,13 +139,21 @@ note: required because it appears within the type `S<X>`
116139
LL | struct S<X: ?Sized> {
117140
| ^
118141
= note: required because it appears within the type `({integer}, S<X>)`
119-
= note: tuples must have a statically known size to be initialized
142+
note: required by a bound in `f5`
143+
--> $DIR/unsized3.rs:24:7
144+
|
145+
LL | fn f5<Y>(x: &Y) {}
146+
| ^ required by this bound in `f5`
120147
help: consider removing the `?Sized` bound to make the type parameter `Sized`
121148
|
122149
LL - fn f10<X: ?Sized>(x1: Box<S<X>>) {
123150
LL + fn f10<X>(x1: Box<S<X>>) {
124151
|
152+
help: consider relaxing the implicit `Sized` restriction
153+
|
154+
LL | fn f5<Y: ?Sized>(x: &Y) {}
155+
| ++++++++
125156

126-
error: aborting due to 5 previous errors
157+
error: aborting due to 6 previous errors
127158

128159
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)
This repository has been archived.