Skip to content

Commit 1da727e

Browse files
committed
Auto merge of rust-lang#134057 - GuillaumeGomez:rollup-kzesbgh, r=GuillaumeGomez
Rollup of 9 pull requests Successful merges: - rust-lang#133184 (wasi/fs: Improve stopping condition for <ReadDir as Iterator>::next) - rust-lang#133955 (Pass the arch rather than full target name to windows_registry::find_tool) - rust-lang#133967 ([AIX] Pass -bnoipath when adding rust upstream dynamic crates) - rust-lang#133970 ([AIX] Replace sa_sigaction with sa_union.__su_sigaction for AIX) - rust-lang#133980 ([AIX] Remove option "-n" from AIX "ln" command) - rust-lang#133996 (Move most tests for `-l` and `#[link(..)]` into `tests/ui/link-native-libs`) - rust-lang#134017 (Don't use `AsyncFnOnce::CallOnceFuture` bounds for signature deduction) - rust-lang#134023 (handle cygwin environment in `install::sanitize_sh`) - rust-lang#134053 (rustdoc: rename `issue-\d+.rs` tests to have meaningful names (part 10)) r? `@ghost` `@rustbot` modify labels: rollup
2 parents f6cb952 + 0a7c477 commit 1da727e

File tree

85 files changed

+290
-194
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+290
-194
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -1015,12 +1015,8 @@ fn link_natively(
10151015
&& (code < 1000 || code > 9999)
10161016
{
10171017
let is_vs_installed = windows_registry::find_vs_version().is_ok();
1018-
// FIXME(cc-rs#1265) pass only target arch to find_tool()
1019-
let has_linker = windows_registry::find_tool(
1020-
sess.opts.target_triple.tuple(),
1021-
"link.exe",
1022-
)
1023-
.is_some();
1018+
let has_linker =
1019+
windows_registry::find_tool(&sess.target.arch, "link.exe").is_some();
10241020

10251021
sess.dcx().emit_note(errors::LinkExeUnexpectedError);
10261022
if is_vs_installed && has_linker {
@@ -2745,6 +2741,15 @@ fn add_upstream_rust_crates(
27452741
.find(|(ty, _)| *ty == crate_type)
27462742
.expect("failed to find crate type in dependency format list");
27472743

2744+
if sess.target.is_like_aix {
2745+
// Unlike ELF linkers, AIX doesn't feature `DT_SONAME` to override
2746+
// the dependency name when outputing a shared library. Thus, `ld` will
2747+
// use the full path to shared libraries as the dependency if passed it
2748+
// by default unless `noipath` is passed.
2749+
// https://www.ibm.com/docs/en/aix/7.3?topic=l-ld-command.
2750+
cmd.link_or_cc_arg("-bnoipath");
2751+
}
2752+
27482753
for &cnum in &codegen_results.crate_info.used_crates {
27492754
// We may not pass all crates through to the linker. Some crates may appear statically in
27502755
// an existing dylib, meaning we'll pick up all the symbols from the dylib.

compiler/rustc_codegen_ssa/src/back/linker.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ pub(crate) fn get_linker<'a>(
5050
self_contained: bool,
5151
target_cpu: &'a str,
5252
) -> Box<dyn Linker + 'a> {
53-
// FIXME(cc-rs#1265) pass only target arch to find_tool()
54-
let msvc_tool = windows_registry::find_tool(sess.opts.target_triple.tuple(), "link.exe");
53+
let msvc_tool = windows_registry::find_tool(&sess.target.arch, "link.exe");
5554

5655
// If our linker looks like a batch script on Windows then to execute this
5756
// we'll need to spawn `cmd` explicitly. This is primarily done to handle

compiler/rustc_hir_typeck/src/closure.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -454,28 +454,24 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
454454
closure_kind: hir::ClosureKind,
455455
projection: ty::PolyProjectionPredicate<'tcx>,
456456
) -> Option<ExpectedSig<'tcx>> {
457-
let tcx = self.tcx;
458-
459-
let trait_def_id = projection.trait_def_id(tcx);
457+
let def_id = projection.projection_def_id();
460458

461459
// For now, we only do signature deduction based off of the `Fn` and `AsyncFn` traits,
462460
// for closures and async closures, respectively.
463461
match closure_kind {
464-
hir::ClosureKind::Closure
465-
if self.tcx.fn_trait_kind_from_def_id(trait_def_id).is_some() =>
466-
{
462+
hir::ClosureKind::Closure if self.tcx.is_lang_item(def_id, LangItem::FnOnceOutput) => {
467463
self.extract_sig_from_projection(cause_span, projection)
468464
}
469465
hir::ClosureKind::CoroutineClosure(hir::CoroutineDesugaring::Async)
470-
if self.tcx.async_fn_trait_kind_from_def_id(trait_def_id).is_some() =>
466+
if self.tcx.is_lang_item(def_id, LangItem::AsyncFnOnceOutput) =>
471467
{
472468
self.extract_sig_from_projection(cause_span, projection)
473469
}
474470
// It's possible we've passed the closure to a (somewhat out-of-fashion)
475471
// `F: FnOnce() -> Fut, Fut: Future<Output = T>` style bound. Let's still
476472
// guide inference here, since it's beneficial for the user.
477473
hir::ClosureKind::CoroutineClosure(hir::CoroutineDesugaring::Async)
478-
if self.tcx.fn_trait_kind_from_def_id(trait_def_id).is_some() =>
474+
if self.tcx.is_lang_item(def_id, LangItem::FnOnceOutput) =>
479475
{
480476
self.extract_sig_from_projection_and_future_bound(cause_span, projection)
481477
}

library/std/src/sys/pal/wasi/fs.rs

+105-70
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,27 @@ pub struct FileAttr {
2727

2828
pub struct ReadDir {
2929
inner: Arc<ReadDirInner>,
30-
cookie: Option<wasi::Dircookie>,
31-
buf: Vec<u8>,
32-
offset: usize,
33-
cap: usize,
30+
state: ReadDirState,
31+
}
32+
33+
enum ReadDirState {
34+
/// Fill `buf` with `buf.len()` bytes starting from `next_read_offset`.
35+
FillBuffer {
36+
next_read_offset: wasi::Dircookie,
37+
buf: Vec<u8>,
38+
},
39+
ProcessEntry {
40+
buf: Vec<u8>,
41+
next_read_offset: Option<wasi::Dircookie>,
42+
offset: usize,
43+
},
44+
/// There is no more data to get in [`Self::FillBuffer`]; keep returning
45+
/// entries via ProcessEntry until `buf` is exhausted.
46+
RunUntilExhaustion {
47+
buf: Vec<u8>,
48+
offset: usize,
49+
},
50+
Done,
3451
}
3552

3653
struct ReadDirInner {
@@ -147,11 +164,8 @@ impl FileType {
147164
impl ReadDir {
148165
fn new(dir: File, root: PathBuf) -> ReadDir {
149166
ReadDir {
150-
cookie: Some(0),
151-
buf: vec![0; 128],
152-
offset: 0,
153-
cap: 0,
154167
inner: Arc::new(ReadDirInner { dir, root }),
168+
state: ReadDirState::FillBuffer { next_read_offset: 0, buf: vec![0; 128] },
155169
}
156170
}
157171
}
@@ -162,78 +176,99 @@ impl fmt::Debug for ReadDir {
162176
}
163177
}
164178

179+
impl core::iter::FusedIterator for ReadDir {}
180+
165181
impl Iterator for ReadDir {
166182
type Item = io::Result<DirEntry>;
167183

168184
fn next(&mut self) -> Option<io::Result<DirEntry>> {
169-
loop {
170-
// If we've reached the capacity of our buffer then we need to read
171-
// some more from the OS, otherwise we pick up at our old offset.
172-
let offset = if self.offset == self.cap {
173-
let cookie = self.cookie.take()?;
174-
match self.inner.dir.fd.readdir(&mut self.buf, cookie) {
175-
Ok(bytes) => self.cap = bytes,
176-
Err(e) => return Some(Err(e)),
177-
}
178-
self.offset = 0;
179-
self.cookie = Some(cookie);
180-
181-
// If we didn't actually read anything, this is in theory the
182-
// end of the directory.
183-
if self.cap == 0 {
184-
self.cookie = None;
185-
return None;
186-
}
187-
188-
0
189-
} else {
190-
self.offset
191-
};
192-
let data = &self.buf[offset..self.cap];
193-
194-
// If we're not able to read a directory entry then that means it
195-
// must have been truncated at the end of the buffer, so reset our
196-
// offset so we can go back and reread into the buffer, picking up
197-
// where we last left off.
198-
let dirent_size = mem::size_of::<wasi::Dirent>();
199-
if data.len() < dirent_size {
200-
assert!(self.cookie.is_some());
201-
assert!(self.buf.len() >= dirent_size);
202-
self.offset = self.cap;
203-
continue;
204-
}
205-
let (dirent, data) = data.split_at(dirent_size);
206-
let dirent = unsafe { ptr::read_unaligned(dirent.as_ptr() as *const wasi::Dirent) };
207-
208-
// If the file name was truncated, then we need to reinvoke
209-
// `readdir` so we truncate our buffer to start over and reread this
210-
// descriptor. Note that if our offset is 0 that means the file name
211-
// is massive and we need a bigger buffer.
212-
if data.len() < dirent.d_namlen as usize {
213-
if offset == 0 {
214-
let amt_to_add = self.buf.capacity();
215-
self.buf.extend(iter::repeat(0).take(amt_to_add));
185+
match &mut self.state {
186+
ReadDirState::FillBuffer { next_read_offset, ref mut buf } => {
187+
let result = self.inner.dir.fd.readdir(buf, *next_read_offset);
188+
match result {
189+
Ok(read_bytes) => {
190+
if read_bytes < buf.len() {
191+
buf.truncate(read_bytes);
192+
self.state =
193+
ReadDirState::RunUntilExhaustion { buf: mem::take(buf), offset: 0 };
194+
} else {
195+
debug_assert_eq!(read_bytes, buf.len());
196+
self.state = ReadDirState::ProcessEntry {
197+
buf: mem::take(buf),
198+
offset: 0,
199+
next_read_offset: Some(*next_read_offset),
200+
};
201+
}
202+
self.next()
203+
}
204+
Err(e) => {
205+
self.state = ReadDirState::Done;
206+
return Some(Err(e));
207+
}
216208
}
217-
assert!(self.cookie.is_some());
218-
self.offset = self.cap;
219-
continue;
220209
}
221-
self.cookie = Some(dirent.d_next);
222-
self.offset = offset + dirent_size + dirent.d_namlen as usize;
210+
ReadDirState::ProcessEntry { ref mut buf, next_read_offset, offset } => {
211+
let contents = &buf[*offset..];
212+
const DIRENT_SIZE: usize = crate::mem::size_of::<wasi::Dirent>();
213+
if contents.len() >= DIRENT_SIZE {
214+
let (dirent, data) = contents.split_at(DIRENT_SIZE);
215+
let dirent =
216+
unsafe { ptr::read_unaligned(dirent.as_ptr() as *const wasi::Dirent) };
217+
// If the file name was truncated, then we need to reinvoke
218+
// `readdir` so we truncate our buffer to start over and reread this
219+
// descriptor.
220+
if data.len() < dirent.d_namlen as usize {
221+
if buf.len() < dirent.d_namlen as usize + DIRENT_SIZE {
222+
buf.resize(dirent.d_namlen as usize + DIRENT_SIZE, 0);
223+
}
224+
if let Some(next_read_offset) = *next_read_offset {
225+
self.state =
226+
ReadDirState::FillBuffer { next_read_offset, buf: mem::take(buf) };
227+
} else {
228+
self.state = ReadDirState::Done;
229+
}
230+
231+
return self.next();
232+
}
233+
next_read_offset.as_mut().map(|cookie| {
234+
*cookie = dirent.d_next;
235+
});
236+
*offset = *offset + DIRENT_SIZE + dirent.d_namlen as usize;
223237

224-
let name = &data[..(dirent.d_namlen as usize)];
238+
let name = &data[..(dirent.d_namlen as usize)];
239+
240+
// These names are skipped on all other platforms, so let's skip
241+
// them here too
242+
if name == b"." || name == b".." {
243+
return self.next();
244+
}
225245

226-
// These names are skipped on all other platforms, so let's skip
227-
// them here too
228-
if name == b"." || name == b".." {
229-
continue;
246+
return Some(Ok(DirEntry {
247+
meta: dirent,
248+
name: name.to_vec(),
249+
inner: self.inner.clone(),
250+
}));
251+
} else if let Some(next_read_offset) = *next_read_offset {
252+
self.state = ReadDirState::FillBuffer { next_read_offset, buf: mem::take(buf) };
253+
} else {
254+
self.state = ReadDirState::Done;
255+
}
256+
self.next()
230257
}
258+
ReadDirState::RunUntilExhaustion { buf, offset } => {
259+
if *offset >= buf.len() {
260+
self.state = ReadDirState::Done;
261+
} else {
262+
self.state = ReadDirState::ProcessEntry {
263+
buf: mem::take(buf),
264+
offset: *offset,
265+
next_read_offset: None,
266+
};
267+
}
231268

232-
return Some(Ok(DirEntry {
233-
meta: dirent,
234-
name: name.to_vec(),
235-
inner: self.inner.clone(),
236-
}));
269+
self.next()
270+
}
271+
ReadDirState::Done => None,
237272
}
238273
}
239274
}

src/bootstrap/src/core/build_steps/install.rs

+13-12
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ const SHELL: &str = "sh";
2121

2222
/// We have to run a few shell scripts, which choke quite a bit on both `\`
2323
/// characters and on `C:\` paths, so normalize both of them away.
24-
fn sanitize_sh(path: &Path) -> String {
24+
fn sanitize_sh(path: &Path, is_cygwin: bool) -> String {
2525
let path = path.to_str().unwrap().replace('\\', "/");
26-
return change_drive(unc_to_lfs(&path)).unwrap_or(path);
26+
return if is_cygwin { path } else { change_drive(unc_to_lfs(&path)).unwrap_or(path) };
2727

2828
fn unc_to_lfs(s: &str) -> &str {
2929
s.strip_prefix("//?/").unwrap_or(s)
@@ -71,6 +71,7 @@ fn install_sh(
7171
let prefix = default_path(&builder.config.prefix, "/usr/local");
7272
let sysconfdir = prefix.join(default_path(&builder.config.sysconfdir, "/etc"));
7373
let destdir_env = env::var_os("DESTDIR").map(PathBuf::from);
74+
let is_cygwin = builder.config.build.is_cygwin();
7475

7576
// Sanity checks on the write access of user.
7677
//
@@ -103,14 +104,14 @@ fn install_sh(
103104

104105
let mut cmd = command(SHELL);
105106
cmd.current_dir(&empty_dir)
106-
.arg(sanitize_sh(&tarball.decompressed_output().join("install.sh")))
107-
.arg(format!("--prefix={}", prepare_dir(&destdir_env, prefix)))
108-
.arg(format!("--sysconfdir={}", prepare_dir(&destdir_env, sysconfdir)))
109-
.arg(format!("--datadir={}", prepare_dir(&destdir_env, datadir)))
110-
.arg(format!("--docdir={}", prepare_dir(&destdir_env, docdir)))
111-
.arg(format!("--bindir={}", prepare_dir(&destdir_env, bindir)))
112-
.arg(format!("--libdir={}", prepare_dir(&destdir_env, libdir)))
113-
.arg(format!("--mandir={}", prepare_dir(&destdir_env, mandir)))
107+
.arg(sanitize_sh(&tarball.decompressed_output().join("install.sh"), is_cygwin))
108+
.arg(format!("--prefix={}", prepare_dir(&destdir_env, prefix, is_cygwin)))
109+
.arg(format!("--sysconfdir={}", prepare_dir(&destdir_env, sysconfdir, is_cygwin)))
110+
.arg(format!("--datadir={}", prepare_dir(&destdir_env, datadir, is_cygwin)))
111+
.arg(format!("--docdir={}", prepare_dir(&destdir_env, docdir, is_cygwin)))
112+
.arg(format!("--bindir={}", prepare_dir(&destdir_env, bindir, is_cygwin)))
113+
.arg(format!("--libdir={}", prepare_dir(&destdir_env, libdir, is_cygwin)))
114+
.arg(format!("--mandir={}", prepare_dir(&destdir_env, mandir, is_cygwin)))
114115
.arg("--disable-ldconfig");
115116
cmd.run(builder);
116117
t!(fs::remove_dir_all(&empty_dir));
@@ -120,7 +121,7 @@ fn default_path(config: &Option<PathBuf>, default: &str) -> PathBuf {
120121
config.as_ref().cloned().unwrap_or_else(|| PathBuf::from(default))
121122
}
122123

123-
fn prepare_dir(destdir_env: &Option<PathBuf>, mut path: PathBuf) -> String {
124+
fn prepare_dir(destdir_env: &Option<PathBuf>, mut path: PathBuf, is_cygwin: bool) -> String {
124125
// The DESTDIR environment variable is a standard way to install software in a subdirectory
125126
// while keeping the original directory structure, even if the prefix or other directories
126127
// contain absolute paths.
@@ -146,7 +147,7 @@ fn prepare_dir(destdir_env: &Option<PathBuf>, mut path: PathBuf) -> String {
146147
assert!(path.is_absolute(), "could not make the path relative");
147148
}
148149

149-
sanitize_sh(&path)
150+
sanitize_sh(&path, is_cygwin)
150151
}
151152

152153
macro_rules! install {

src/bootstrap/src/core/config/config.rs

+6
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,12 @@ impl TargetSelection {
565565
self.ends_with("windows-gnu")
566566
}
567567

568+
pub fn is_cygwin(&self) -> bool {
569+
self.is_windows() &&
570+
// ref. https://cygwin.com/pipermail/cygwin/2022-February/250802.html
571+
env::var("OSTYPE").is_ok_and(|v| v.to_lowercase().contains("cygwin"))
572+
}
573+
568574
/// Path to the file defining the custom target, if any.
569575
pub fn filepath(&self) -> Option<&Path> {
570576
self.file.as_ref().map(Path::new)

src/tools/tidy/src/issues.txt

+5-5
Original file line numberDiff line numberDiff line change
@@ -2295,8 +2295,6 @@ ui/issues/issue-43853.rs
22952295
ui/issues/issue-4387.rs
22962296
ui/issues/issue-43910.rs
22972297
ui/issues/issue-43923.rs
2298-
ui/issues/issue-43925.rs
2299-
ui/issues/issue-43926.rs
23002298
ui/issues/issue-43988.rs
23012299
ui/issues/issue-44023.rs
23022300
ui/issues/issue-44056.rs
@@ -2545,8 +2543,6 @@ ui/issues/issue-6936.rs
25452543
ui/issues/issue-69455.rs
25462544
ui/issues/issue-69602-type-err-during-codegen-ice.rs
25472545
ui/issues/issue-69683.rs
2548-
ui/issues/issue-70093/issue-70093-link-directives.rs
2549-
ui/issues/issue-70093/issue-70093.rs
25502546
ui/issues/issue-7012.rs
25512547
ui/issues/issue-70381.rs
25522548
ui/issues/issue-7044.rs
@@ -2711,11 +2707,15 @@ ui/limits/issue-17913.rs
27112707
ui/limits/issue-55878.rs
27122708
ui/limits/issue-69485-var-size-diffs-too-large.rs
27132709
ui/limits/issue-75158-64.rs
2710+
ui/link-native-libs/issue-109144.rs
2711+
ui/link-native-libs/issue-43925.rs
2712+
ui/link-native-libs/issue-43926.rs
2713+
ui/link-native-libs/issue-70093/issue-70093-link-directives.rs
2714+
ui/link-native-libs/issue-70093/issue-70093.rs
27142715
ui/linkage-attr/auxiliary/issue-12133-dylib.rs
27152716
ui/linkage-attr/auxiliary/issue-12133-dylib2.rs
27162717
ui/linkage-attr/auxiliary/issue-12133-rlib.rs
27172718
ui/linkage-attr/issue-10755.rs
2718-
ui/linkage-attr/issue-109144.rs
27192719
ui/linkage-attr/issue-12133-1.rs
27202720
ui/linkage-attr/issue-12133-2.rs
27212721
ui/linkage-attr/issue-12133-3.rs

src/tools/tidy/src/ui_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use ignore::Walk;
1717
const ENTRY_LIMIT: u32 = 901;
1818
// FIXME: The following limits should be reduced eventually.
1919

20-
const ISSUES_ENTRY_LIMIT: u32 = 1672;
20+
const ISSUES_ENTRY_LIMIT: u32 = 1667;
2121

2222
const EXPECTED_TEST_FILE_EXTENSIONS: &[&str] = &[
2323
"rs", // test source files

0 commit comments

Comments
 (0)