Skip to content

Commit aa31bad

Browse files
committed
Auto merge of rust-lang#124222 - GuillaumeGomez:rollup-ws1zju7, r=GuillaumeGomez
Rollup of 4 pull requests Successful merges: - rust-lang#124069 (enable clippy for bootstrap on CI PRs (in `mingw-check` image)) - rust-lang#124089 (Fix watchOS and visionOS for pread64 and pwrite64 calls) - rust-lang#124184 (Suggest using `unsigned_abs` in `abs` documentation) - rust-lang#124198 (Flip spans for precise capturing syntax not capturing a ty/const param, and for implicit captures of lifetime params) r? `@ghost` `@rustbot` modify labels: rollup
2 parents fecb7b4 + 43d5e00 commit aa31bad

34 files changed

+303
-246
lines changed

compiler/rustc_hir_analysis/messages.ftl

+5-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ hir_analysis_param_in_ty_of_assoc_const_binding =
351351
*[normal] the {$param_def_kind} `{$param_name}` is defined here
352352
}
353353
354-
hir_analysis_param_not_captured = `impl Trait` must mention all {$kind} parameters in scope
354+
hir_analysis_param_not_captured = `impl Trait` must mention all {$kind} parameters in scope in `use<...>`
355355
.label = {$kind} parameter is implicitly captured by this `impl Trait`
356356
.note = currently, all {$kind} parameters are required to be mentioned in the precise captures list
357357
@@ -405,6 +405,10 @@ hir_analysis_self_in_impl_self =
405405
`Self` is not valid in the self type of an impl block
406406
.note = replace `Self` with a different type
407407
408+
hir_analysis_self_ty_not_captured = `impl Trait` must mention the `Self` type of the trait in `use<...>`
409+
.label = `Self` type parameter is implicitly captured by this `impl Trait`
410+
.note = currently, all type parameters are required to be mentioned in the precise captures list
411+
408412
hir_analysis_simd_ffi_highly_experimental = use of SIMD type{$snip} in FFI is highly experimental and may result in invalid code
409413
.help = add `#![feature(simd_ffi)]` to the crate attributes to enable
410414

compiler/rustc_hir_analysis/src/check/check.rs

+32-17
Original file line numberDiff line numberDiff line change
@@ -580,37 +580,52 @@ fn check_opaque_precise_captures<'tcx>(tcx: TyCtxt<'tcx>, opaque_def_id: LocalDe
580580

581581
match param.kind {
582582
ty::GenericParamDefKind::Lifetime => {
583+
let use_span = tcx.def_span(param.def_id);
584+
let opaque_span = tcx.def_span(opaque_def_id);
583585
// Check if the lifetime param was captured but isn't named in the precise captures list.
584586
if variances[param.index as usize] == ty::Invariant {
585-
let param_span = if let DefKind::OpaqueTy =
586-
tcx.def_kind(tcx.parent(param.def_id))
587+
if let DefKind::OpaqueTy = tcx.def_kind(tcx.parent(param.def_id))
587588
&& let ty::ReEarlyParam(ty::EarlyParamRegion { def_id, .. })
588589
| ty::ReLateParam(ty::LateParamRegion {
589590
bound_region: ty::BoundRegionKind::BrNamed(def_id, _),
590591
..
591592
}) = *tcx
592593
.map_opaque_lifetime_to_parent_lifetime(param.def_id.expect_local())
593594
{
594-
Some(tcx.def_span(def_id))
595+
tcx.dcx().emit_err(errors::LifetimeNotCaptured {
596+
opaque_span,
597+
use_span,
598+
param_span: tcx.def_span(def_id),
599+
});
595600
} else {
596-
None
597-
};
598-
// FIXME(precise_capturing): Structured suggestion for this would be useful
599-
tcx.dcx().emit_err(errors::LifetimeNotCaptured {
600-
use_span: tcx.def_span(param.def_id),
601-
param_span,
602-
opaque_span: tcx.def_span(opaque_def_id),
603-
});
601+
// If the `use_span` is actually just the param itself, then we must
602+
// have not duplicated the lifetime but captured the original.
603+
// The "effective" `use_span` will be the span of the opaque itself,
604+
// and the param span will be the def span of the param.
605+
tcx.dcx().emit_err(errors::LifetimeNotCaptured {
606+
opaque_span,
607+
use_span: opaque_span,
608+
param_span: use_span,
609+
});
610+
}
604611
continue;
605612
}
606613
}
607614
ty::GenericParamDefKind::Type { .. } => {
608-
// FIXME(precise_capturing): Structured suggestion for this would be useful
609-
tcx.dcx().emit_err(errors::ParamNotCaptured {
610-
param_span: tcx.def_span(param.def_id),
611-
opaque_span: tcx.def_span(opaque_def_id),
612-
kind: "type",
613-
});
615+
if matches!(tcx.def_kind(param.def_id), DefKind::Trait | DefKind::TraitAlias) {
616+
// FIXME(precise_capturing): Structured suggestion for this would be useful
617+
tcx.dcx().emit_err(errors::SelfTyNotCaptured {
618+
trait_span: tcx.def_span(param.def_id),
619+
opaque_span: tcx.def_span(opaque_def_id),
620+
});
621+
} else {
622+
// FIXME(precise_capturing): Structured suggestion for this would be useful
623+
tcx.dcx().emit_err(errors::ParamNotCaptured {
624+
param_span: tcx.def_span(param.def_id),
625+
opaque_span: tcx.def_span(opaque_def_id),
626+
kind: "type",
627+
});
628+
}
614629
}
615630
ty::GenericParamDefKind::Const { .. } => {
616631
// FIXME(precise_capturing): Structured suggestion for this would be useful

compiler/rustc_hir_analysis/src/errors/precise_captures.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,29 @@ use rustc_span::{Span, Symbol};
66
#[note]
77
pub struct ParamNotCaptured {
88
#[primary_span]
9-
pub param_span: Span,
10-
#[label]
119
pub opaque_span: Span,
10+
#[label]
11+
pub param_span: Span,
1212
pub kind: &'static str,
1313
}
1414

15+
#[derive(Diagnostic)]
16+
#[diag(hir_analysis_self_ty_not_captured)]
17+
#[note]
18+
pub struct SelfTyNotCaptured {
19+
#[primary_span]
20+
pub opaque_span: Span,
21+
#[label]
22+
pub trait_span: Span,
23+
}
24+
1525
#[derive(Diagnostic)]
1626
#[diag(hir_analysis_lifetime_not_captured)]
1727
pub struct LifetimeNotCaptured {
1828
#[primary_span]
1929
pub use_span: Span,
2030
#[label(hir_analysis_param_label)]
21-
pub param_span: Option<Span>,
31+
pub param_span: Span,
2232
#[label]
2333
pub opaque_span: Span,
2434
}

library/core/src/num/int_macros.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3199,7 +3199,8 @@ macro_rules! int_impl {
31993199
/// that code in debug mode will trigger a panic on this case and
32003200
/// optimized code will return
32013201
#[doc = concat!("`", stringify!($SelfT), "::MIN`")]
3202-
/// without a panic.
3202+
/// without a panic. If you do not want this behavior consider
3203+
/// using [`unsigned_abs`](Self::unsigned_abs) instead.
32033204
///
32043205
/// # Examples
32053206
///

library/std/src/sys/pal/unix/fd.rs

+64-36
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,9 @@ const READ_LIMIT: usize = libc::ssize_t::MAX as usize;
4545
#[cfg(any(
4646
target_os = "dragonfly",
4747
target_os = "freebsd",
48-
target_os = "ios",
49-
target_os = "tvos",
50-
target_os = "macos",
5148
target_os = "netbsd",
5249
target_os = "openbsd",
53-
target_os = "watchos",
54-
target_os = "visionos",
50+
target_vendor = "apple",
5551
))]
5652
const fn max_iov() -> usize {
5753
libc::IOV_MAX as usize
@@ -72,17 +68,13 @@ const fn max_iov() -> usize {
7268
target_os = "dragonfly",
7369
target_os = "emscripten",
7470
target_os = "freebsd",
75-
target_os = "ios",
76-
target_os = "tvos",
7771
target_os = "linux",
78-
target_os = "macos",
7972
target_os = "netbsd",
8073
target_os = "nto",
8174
target_os = "openbsd",
8275
target_os = "horizon",
8376
target_os = "vita",
84-
target_os = "watchos",
85-
target_os = "visionos",
77+
target_vendor = "apple",
8678
)))]
8779
const fn max_iov() -> usize {
8880
16 // The minimum value required by POSIX.
@@ -201,13 +193,10 @@ impl FileDesc {
201193
target_os = "fuchsia",
202194
target_os = "hurd",
203195
target_os = "illumos",
204-
target_os = "ios",
205-
target_os = "tvos",
206196
target_os = "linux",
207-
target_os = "macos",
208197
target_os = "netbsd",
209198
target_os = "openbsd",
210-
target_os = "watchos",
199+
target_vendor = "apple",
211200
)))]
212201
pub fn read_vectored_at(&self, bufs: &mut [IoSliceMut<'_>], offset: u64) -> io::Result<usize> {
213202
io::default_read_vectored(|b| self.read_at(b, offset), bufs)
@@ -241,15 +230,7 @@ impl FileDesc {
241230
Ok(ret as usize)
242231
}
243232

244-
// We support old MacOS and iOS versions that do not have `preadv`. There is
245-
// no `syscall` possible in these platform.
246-
#[cfg(any(
247-
all(target_os = "android", target_pointer_width = "32"),
248-
target_os = "ios", // ios 14.0
249-
target_os = "tvos", // tvos 14.0
250-
target_os = "macos", // macos 11.0
251-
target_os = "watchos", // watchos 7.0
252-
))]
233+
#[cfg(all(target_os = "android", target_pointer_width = "32"))]
253234
pub fn read_vectored_at(&self, bufs: &mut [IoSliceMut<'_>], offset: u64) -> io::Result<usize> {
254235
super::weak::weak!(fn preadv64(libc::c_int, *const libc::iovec, libc::c_int, off64_t) -> isize);
255236

@@ -269,6 +250,35 @@ impl FileDesc {
269250
}
270251
}
271252

253+
// We support old MacOS, iOS, watchOS, tvOS and visionOS. `preadv` was added in the following
254+
// Apple OS versions:
255+
// ios 14.0
256+
// tvos 14.0
257+
// macos 11.0
258+
// watchos 7.0
259+
//
260+
// These versions may be newer than the minimum supported versions of OS's we support so we must
261+
// use "weak" linking.
262+
#[cfg(target_vendor = "apple")]
263+
pub fn read_vectored_at(&self, bufs: &mut [IoSliceMut<'_>], offset: u64) -> io::Result<usize> {
264+
super::weak::weak!(fn preadv(libc::c_int, *const libc::iovec, libc::c_int, off64_t) -> isize);
265+
266+
match preadv.get() {
267+
Some(preadv) => {
268+
let ret = cvt(unsafe {
269+
preadv(
270+
self.as_raw_fd(),
271+
bufs.as_mut_ptr() as *mut libc::iovec as *const libc::iovec,
272+
cmp::min(bufs.len(), max_iov()) as libc::c_int,
273+
offset as _,
274+
)
275+
})?;
276+
Ok(ret as usize)
277+
}
278+
None => io::default_read_vectored(|b| self.read_at(b, offset), bufs),
279+
}
280+
}
281+
272282
pub fn write(&self, buf: &[u8]) -> io::Result<usize> {
273283
let ret = cvt(unsafe {
274284
libc::write(
@@ -360,13 +370,10 @@ impl FileDesc {
360370
target_os = "fuchsia",
361371
target_os = "hurd",
362372
target_os = "illumos",
363-
target_os = "ios",
364-
target_os = "tvos",
365373
target_os = "linux",
366-
target_os = "macos",
367374
target_os = "netbsd",
368375
target_os = "openbsd",
369-
target_os = "watchos",
376+
target_vendor = "apple",
370377
)))]
371378
pub fn write_vectored_at(&self, bufs: &[IoSlice<'_>], offset: u64) -> io::Result<usize> {
372379
io::default_write_vectored(|b| self.write_at(b, offset), bufs)
@@ -400,15 +407,7 @@ impl FileDesc {
400407
Ok(ret as usize)
401408
}
402409

403-
// We support old MacOS and iOS versions that do not have `pwritev`. There is
404-
// no `syscall` possible in these platform.
405-
#[cfg(any(
406-
all(target_os = "android", target_pointer_width = "32"),
407-
target_os = "ios", // ios 14.0
408-
target_os = "tvos", // tvos 14.0
409-
target_os = "macos", // macos 11.0
410-
target_os = "watchos", // watchos 7.0
411-
))]
410+
#[cfg(all(target_os = "android", target_pointer_width = "32"))]
412411
pub fn write_vectored_at(&self, bufs: &[IoSlice<'_>], offset: u64) -> io::Result<usize> {
413412
super::weak::weak!(fn pwritev64(libc::c_int, *const libc::iovec, libc::c_int, off64_t) -> isize);
414413

@@ -428,6 +427,35 @@ impl FileDesc {
428427
}
429428
}
430429

430+
// We support old MacOS, iOS, watchOS, tvOS and visionOS. `pwritev` was added in the following
431+
// Apple OS versions:
432+
// ios 14.0
433+
// tvos 14.0
434+
// macos 11.0
435+
// watchos 7.0
436+
//
437+
// These versions may be newer than the minimum supported versions of OS's we support so we must
438+
// use "weak" linking.
439+
#[cfg(target_vendor = "apple")]
440+
pub fn write_vectored_at(&self, bufs: &[IoSlice<'_>], offset: u64) -> io::Result<usize> {
441+
super::weak::weak!(fn pwritev(libc::c_int, *const libc::iovec, libc::c_int, off64_t) -> isize);
442+
443+
match pwritev.get() {
444+
Some(pwritev) => {
445+
let ret = cvt(unsafe {
446+
pwritev(
447+
self.as_raw_fd(),
448+
bufs.as_ptr() as *const libc::iovec,
449+
cmp::min(bufs.len(), max_iov()) as libc::c_int,
450+
offset as _,
451+
)
452+
})?;
453+
Ok(ret as usize)
454+
}
455+
None => io::default_write_vectored(|b| self.write_at(b, offset), bufs),
456+
}
457+
}
458+
431459
#[cfg(not(any(
432460
target_env = "newlib",
433461
target_os = "solaris",

library/std/src/sys/pal/unix/weak.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::ptr;
2828
use crate::sync::atomic::{self, AtomicPtr, Ordering};
2929

3030
// We can use true weak linkage on ELF targets.
31-
#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "tvos")))]
31+
#[cfg(all(unix, not(target_vendor = "apple")))]
3232
pub(crate) macro weak {
3333
(fn $name:ident($($t:ty),*) -> $ret:ty) => (
3434
let ref $name: ExternWeak<unsafe extern "C" fn($($t),*) -> $ret> = {
@@ -43,7 +43,7 @@ pub(crate) macro weak {
4343
}
4444

4545
// On non-ELF targets, use the dlsym approximation of weak linkage.
46-
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "tvos"))]
46+
#[cfg(target_vendor = "apple")]
4747
pub(crate) use self::dlsym as weak;
4848

4949
pub(crate) struct ExternWeak<F: Copy> {

src/bootstrap/src/bin/main.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ fn main() {
3737

3838
build_lock = fd_lock::RwLock::new(t!(fs::OpenOptions::new()
3939
.write(true)
40+
.truncate(true)
4041
.create(true)
4142
.open(&lock_path)));
4243
_build_lock_guard = match build_lock.try_write() {
@@ -143,8 +144,8 @@ fn check_version(config: &Config) -> Option<String> {
143144
// then use the one from the config.toml. This way we never show the same warnings
144145
// more than once.
145146
if let Ok(t) = fs::read_to_string(&warned_id_path) {
146-
let last_warned_id =
147-
usize::from_str(&t).expect(&format!("{} is corrupted.", warned_id_path.display()));
147+
let last_warned_id = usize::from_str(&t)
148+
.unwrap_or_else(|_| panic!("{} is corrupted.", warned_id_path.display()));
148149

149150
// We only use the last_warned_id if it exists in `CONFIG_CHANGE_HISTORY`.
150151
// Otherwise, we may retrieve all the changes if it's not the highest value.

0 commit comments

Comments
 (0)