Skip to content

Commit 45b48b9

Browse files
committed
Auto merge of #52735 - Mark-Simulacrum:rollup, r=Mark-Simulacrum
Rollup of 16 pull requests Successful merges: - #52558 (Add tests for ICEs which no longer repro) - #52610 (Clarify what a task is) - #52617 (Don't match on region kinds when reporting NLL errors) - #52635 (Fix #[linkage] propagation though generic functions) - #52647 (Suggest to take and ignore args while closure args count mismatching) - #52649 (Point spans to inner elements of format strings) - #52654 (Format linker args in a way that works for gcc and ld) - #52667 (update the stdsimd submodule) - #52674 (Impl Executor for Box<E: Executor>) - #52690 (ARM: expose `rclass` and `dsp` target features) - #52692 (Improve readability in a few sorts) - #52695 (Hide some lints which are not quite right the way they are reported to the user) - #52718 (State default capacity for BufReader/BufWriter) - #52721 (std::ops::Try impl for std::task::Poll) - #52723 (rustc: Register crates under their real names) - #52734 (sparc ABI issue - structure returning from function is returned in 64bit registers (with tests)) Failed merges: - #52678 ([NLL] Use better spans in some errors) r? @ghost
2 parents bfbf837 + 995d719 commit 45b48b9

File tree

109 files changed

+1355
-436
lines changed

Some content is hidden

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

109 files changed

+1355
-436
lines changed

src/liballoc/boxed.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ use core::marker::{Unpin, Unsize};
6767
use core::mem::{self, PinMut};
6868
use core::ops::{CoerceUnsized, Deref, DerefMut, Generator, GeneratorState};
6969
use core::ptr::{self, NonNull, Unique};
70-
use core::task::{Context, Poll};
70+
use core::task::{Context, Poll, Executor, SpawnErrorKind, SpawnObjError};
7171

7272
use raw_vec::RawVec;
7373
use str::from_boxed_utf8_unchecked;
@@ -972,6 +972,19 @@ unsafe impl<'a, T, F> UnsafeFutureObj<'a, T> for PinBox<F>
972972
}
973973
}
974974

975+
#[unstable(feature = "futures_api", issue = "50547")]
976+
impl<E> Executor for Box<E>
977+
where E: Executor + ?Sized
978+
{
979+
fn spawn_obj(&mut self, task: FutureObj<'static, ()>) -> Result<(), SpawnObjError> {
980+
(**self).spawn_obj(task)
981+
}
982+
983+
fn status(&self) -> Result<(), SpawnErrorKind> {
984+
(**self).status()
985+
}
986+
}
987+
975988
#[unstable(feature = "futures_api", issue = "50547")]
976989
impl<'a, F: Future<Output = ()> + Send + 'a> From<PinBox<F>> for FutureObj<'a, ()> {
977990
fn from(boxed: PinBox<F>) -> Self {

src/libcore/task/executor.rs

+18-12
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,27 @@ use future::{FutureObj, LocalFutureObj};
1717

1818
/// A task executor.
1919
///
20-
/// A *task* is a `()`-producing async value that runs at the top level, and will
21-
/// be `poll`ed until completion. It's also the unit at which wake-up
22-
/// notifications occur. Executors, such as thread pools, allow tasks to be
23-
/// spawned and are responsible for putting tasks onto ready queues when
24-
/// they are woken up, and polling them when they are ready.
20+
/// Futures are polled until completion by tasks, a kind of lightweight
21+
/// "thread". A *task executor* is responsible for the creation of these tasks
22+
/// and the coordination of their execution on real operating system threads. In
23+
/// particular, whenever a task signals that it can make further progress via a
24+
/// wake-up notification, it is the responsibility of the task executor to put
25+
/// the task into a queue to continue executing it, i.e. polling the future in
26+
/// it, later.
2527
pub trait Executor {
26-
/// Spawn the given task, polling it until completion.
28+
/// Spawns a new task with the given future. The future will be polled until
29+
/// completion.
2730
///
2831
/// # Errors
2932
///
3033
/// The executor may be unable to spawn tasks, either because it has
3134
/// been shut down or is resource-constrained.
32-
fn spawn_obj(&mut self, task: FutureObj<'static, ()>) -> Result<(), SpawnObjError>;
35+
fn spawn_obj(
36+
&mut self,
37+
future: FutureObj<'static, ()>,
38+
) -> Result<(), SpawnObjError>;
3339

34-
/// Determine whether the executor is able to spawn new tasks.
40+
/// Determines whether the executor is able to spawn new tasks.
3541
///
3642
/// # Returns
3743
///
@@ -75,8 +81,8 @@ pub struct SpawnObjError {
7581
/// The kind of error
7682
pub kind: SpawnErrorKind,
7783

78-
/// The task for which spawning was attempted
79-
pub task: FutureObj<'static, ()>,
84+
/// The future for which spawning inside a task was attempted
85+
pub future: FutureObj<'static, ()>,
8086
}
8187

8288
/// The result of a failed spawn
@@ -85,6 +91,6 @@ pub struct SpawnLocalObjError {
8591
/// The kind of error
8692
pub kind: SpawnErrorKind,
8793

88-
/// The task for which spawning was attempted
89-
pub task: LocalFutureObj<'static, ()>,
94+
/// The future for which spawning inside a task was attempted
95+
pub future: LocalFutureObj<'static, ()>,
9096
}

src/libcore/task/poll.rs

+54
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
reason = "futures in libcore are unstable",
1313
issue = "50547")]
1414

15+
use ops::Try;
16+
use result::Result;
17+
1518
/// Indicates whether a value is available or if the current task has been
1619
/// scheduled to receive a wakeup instead.
1720
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
@@ -39,6 +42,7 @@ impl<T> Poll<T> {
3942
}
4043

4144
/// Returns whether this is `Poll::Ready`
45+
#[inline]
4246
pub fn is_ready(&self) -> bool {
4347
match *self {
4448
Poll::Ready(_) => true,
@@ -47,6 +51,7 @@ impl<T> Poll<T> {
4751
}
4852

4953
/// Returns whether this is `Poll::Pending`
54+
#[inline]
5055
pub fn is_pending(&self) -> bool {
5156
!self.is_ready()
5257
}
@@ -81,3 +86,52 @@ impl<T> From<T> for Poll<T> {
8186
Poll::Ready(t)
8287
}
8388
}
89+
90+
impl<T, E> Try for Poll<Result<T, E>> {
91+
type Ok = Poll<T>;
92+
type Error = E;
93+
94+
#[inline]
95+
fn into_result(self) -> Result<Self::Ok, Self::Error> {
96+
match self {
97+
Poll::Ready(Ok(x)) => Ok(Poll::Ready(x)),
98+
Poll::Ready(Err(e)) => Err(e),
99+
Poll::Pending => Ok(Poll::Pending),
100+
}
101+
}
102+
103+
#[inline]
104+
fn from_error(e: Self::Error) -> Self {
105+
Poll::Ready(Err(e))
106+
}
107+
108+
#[inline]
109+
fn from_ok(x: Self::Ok) -> Self {
110+
x.map(Ok)
111+
}
112+
}
113+
114+
impl<T, E> Try for Poll<Option<Result<T, E>>> {
115+
type Ok = Poll<Option<T>>;
116+
type Error = E;
117+
118+
#[inline]
119+
fn into_result(self) -> Result<Self::Ok, Self::Error> {
120+
match self {
121+
Poll::Ready(Some(Ok(x))) => Ok(Poll::Ready(Some(x))),
122+
Poll::Ready(Some(Err(e))) => Err(e),
123+
Poll::Ready(None) => Ok(Poll::Ready(None)),
124+
Poll::Pending => Ok(Poll::Pending),
125+
}
126+
}
127+
128+
#[inline]
129+
fn from_error(e: Self::Error) -> Self {
130+
Poll::Ready(Some(Err(e)))
131+
}
132+
133+
#[inline]
134+
fn from_ok(x: Self::Ok) -> Self {
135+
x.map(|x| x.map(Ok))
136+
}
137+
}

src/libfmt_macros/lib.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ pub struct Parser<'a> {
154154
style: Option<usize>,
155155
/// How many newlines have been seen in the string so far, to adjust the error spans
156156
seen_newlines: usize,
157+
/// Start and end byte offset of every successfuly parsed argument
158+
pub arg_places: Vec<(usize, usize)>,
157159
}
158160

159161
impl<'a> Iterator for Parser<'a> {
@@ -168,9 +170,13 @@ impl<'a> Iterator for Parser<'a> {
168170
if self.consume('{') {
169171
Some(String(self.string(pos + 1)))
170172
} else {
171-
let ret = Some(NextArgument(self.argument()));
172-
self.must_consume('}');
173-
ret
173+
let mut arg = self.argument();
174+
if let Some(arg_pos) = self.must_consume('}').map(|end| {
175+
(pos + raw + 1, end + raw + 2)
176+
}) {
177+
self.arg_places.push(arg_pos);
178+
}
179+
Some(NextArgument(arg))
174180
}
175181
}
176182
'}' => {
@@ -211,6 +217,7 @@ impl<'a> Parser<'a> {
211217
curarg: 0,
212218
style,
213219
seen_newlines: 0,
220+
arg_places: vec![],
214221
}
215222
}
216223

@@ -271,20 +278,22 @@ impl<'a> Parser<'a> {
271278

272279
/// Forces consumption of the specified character. If the character is not
273280
/// found, an error is emitted.
274-
fn must_consume(&mut self, c: char) {
281+
fn must_consume(&mut self, c: char) -> Option<usize> {
275282
self.ws();
276283
let raw = self.style.unwrap_or(0);
277284

278285
let padding = raw + self.seen_newlines;
279286
if let Some(&(pos, maybe)) = self.cur.peek() {
280287
if c == maybe {
281288
self.cur.next();
289+
Some(pos)
282290
} else {
283291
let pos = pos + padding + 1;
284292
self.err(format!("expected `{:?}`, found `{:?}`", c, maybe),
285293
format!("expected `{}`", c),
286294
pos,
287295
pos);
296+
None
288297
}
289298
} else {
290299
let msg = format!("expected `{:?}` but string was terminated", c);
@@ -302,6 +311,7 @@ impl<'a> Parser<'a> {
302311
} else {
303312
self.err(msg, format!("expected `{:?}`", c), pos, pos);
304313
}
314+
None
305315
}
306316
}
307317

src/librustc/traits/error_reporting.rs

+24
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,30 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10501050
if let Some(found_span) = found_span {
10511051
err.span_label(found_span, format!("takes {}", found_str));
10521052

1053+
// Suggest to take and ignore the arguments with expected_args_length `_`s if
1054+
// found arguments is empty (assume the user just wants to ignore args in this case).
1055+
// For example, if `expected_args_length` is 2, suggest `|_, _|`.
1056+
if found_args.is_empty() && is_closure {
1057+
let mut underscores = "_".repeat(expected_args.len())
1058+
.split("")
1059+
.filter(|s| !s.is_empty())
1060+
.collect::<Vec<_>>()
1061+
.join(", ");
1062+
err.span_suggestion_with_applicability(
1063+
found_span,
1064+
&format!(
1065+
"consider changing the closure to take and ignore the expected argument{}",
1066+
if expected_args.len() < 2 {
1067+
""
1068+
} else {
1069+
"s"
1070+
}
1071+
),
1072+
format!("|{}|", underscores),
1073+
Applicability::MachineApplicable,
1074+
);
1075+
}
1076+
10531077
if let &[ArgKind::Tuple(_, ref fields)] = &found_args[..] {
10541078
if fields.len() == expected_args.len() {
10551079
let sugg = fields.iter()

src/librustc_codegen_llvm/back/linker.rs

+19-17
Original file line numberDiff line numberDiff line change
@@ -218,24 +218,26 @@ impl<'a> GccLinker<'a> {
218218
}
219219

220220
impl<'a> Linker for GccLinker<'a> {
221-
fn link_dylib(&mut self, lib: &str) { self.hint_dynamic(); self.cmd.arg("-l").arg(lib); }
222-
fn link_staticlib(&mut self, lib: &str) { self.hint_static(); self.cmd.arg("-l").arg(lib); }
221+
fn link_dylib(&mut self, lib: &str) { self.hint_dynamic(); self.cmd.arg(format!("-l{}",lib)); }
222+
fn link_staticlib(&mut self, lib: &str) {
223+
self.hint_static(); self.cmd.arg(format!("-l{}",lib));
224+
}
223225
fn link_rlib(&mut self, lib: &Path) { self.hint_static(); self.cmd.arg(lib); }
224226
fn include_path(&mut self, path: &Path) { self.cmd.arg("-L").arg(path); }
225227
fn framework_path(&mut self, path: &Path) { self.cmd.arg("-F").arg(path); }
226228
fn output_filename(&mut self, path: &Path) { self.cmd.arg("-o").arg(path); }
227229
fn add_object(&mut self, path: &Path) { self.cmd.arg(path); }
228230
fn position_independent_executable(&mut self) { self.cmd.arg("-pie"); }
229231
fn no_position_independent_executable(&mut self) { self.cmd.arg("-no-pie"); }
230-
fn full_relro(&mut self) { self.linker_arg("-z,relro,-z,now"); }
231-
fn partial_relro(&mut self) { self.linker_arg("-z,relro"); }
232-
fn no_relro(&mut self) { self.linker_arg("-z,norelro"); }
232+
fn full_relro(&mut self) { self.linker_arg("-zrelro"); self.linker_arg("-znow"); }
233+
fn partial_relro(&mut self) { self.linker_arg("-zrelro"); }
234+
fn no_relro(&mut self) { self.linker_arg("-znorelro"); }
233235
fn build_static_executable(&mut self) { self.cmd.arg("-static"); }
234236
fn args(&mut self, args: &[String]) { self.cmd.args(args); }
235237

236238
fn link_rust_dylib(&mut self, lib: &str, _path: &Path) {
237239
self.hint_dynamic();
238-
self.cmd.arg("-l").arg(lib);
240+
self.cmd.arg(format!("-l{}",lib));
239241
}
240242

241243
fn link_framework(&mut self, framework: &str) {
@@ -253,23 +255,22 @@ impl<'a> Linker for GccLinker<'a> {
253255
self.hint_static();
254256
let target = &self.sess.target.target;
255257
if !target.options.is_like_osx {
256-
self.linker_arg("--whole-archive").cmd.arg("-l").arg(lib);
258+
self.linker_arg("--whole-archive").cmd.arg(format!("-l{}",lib));
257259
self.linker_arg("--no-whole-archive");
258260
} else {
259261
// -force_load is the macOS equivalent of --whole-archive, but it
260262
// involves passing the full path to the library to link.
261-
let mut v = OsString::from("-force_load,");
262-
v.push(&archive::find_library(lib, search_path, &self.sess));
263-
self.linker_arg(&v);
263+
self.linker_arg("-force_load");
264+
let lib = archive::find_library(lib, search_path, &self.sess);
265+
self.linker_arg(&lib);
264266
}
265267
}
266268

267269
fn link_whole_rlib(&mut self, lib: &Path) {
268270
self.hint_static();
269271
if self.sess.target.target.options.is_like_osx {
270-
let mut v = OsString::from("-force_load,");
271-
v.push(lib);
272-
self.linker_arg(&v);
272+
self.linker_arg("-force_load");
273+
self.linker_arg(&lib);
273274
} else {
274275
self.linker_arg("--whole-archive").cmd.arg(lib);
275276
self.linker_arg("--no-whole-archive");
@@ -294,8 +295,7 @@ impl<'a> Linker for GccLinker<'a> {
294295
if self.sess.target.target.options.is_like_osx {
295296
self.linker_arg("-dead_strip");
296297
} else if self.sess.target.target.options.is_like_solaris {
297-
self.linker_arg("-z");
298-
self.linker_arg("ignore");
298+
self.linker_arg("-zignore");
299299

300300
// If we're building a dylib, we don't use --gc-sections because LLVM
301301
// has already done the best it can do, and we also don't want to
@@ -369,7 +369,8 @@ impl<'a> Linker for GccLinker<'a> {
369369
// the right `-Wl,-install_name` with an `@rpath` in it.
370370
if self.sess.opts.cg.rpath ||
371371
self.sess.opts.debugging_opts.osx_rpath_install_name {
372-
let mut v = OsString::from("-install_name,@rpath/");
372+
self.linker_arg("-install_name");
373+
let mut v = OsString::from("@rpath/");
373374
v.push(out_filename.file_name().unwrap());
374375
self.linker_arg(&v);
375376
}
@@ -448,7 +449,8 @@ impl<'a> Linker for GccLinker<'a> {
448449
}
449450

450451
fn subsystem(&mut self, subsystem: &str) {
451-
self.linker_arg(&format!("--subsystem,{}", subsystem));
452+
self.linker_arg("--subsystem");
453+
self.linker_arg(&subsystem);
452454
}
453455

454456
fn finalize(&mut self) -> Command {

0 commit comments

Comments
 (0)