Skip to content

Commit d0126e8

Browse files
committed
Auto merge of #67080 - JohnTitor:rollup-2t6fm3u, r=JohnTitor
Rollup of 10 pull requests Successful merges: - #66649 (VxWorks: fix issues in accessing environment variables) - #66764 (Tweak wording of `collect()` on bad target type) - #66900 (Clean up error codes) - #66974 ([CI] fix the `! isCI` check in src/ci/run.sh) - #66979 (Add long error for E0631 and update ui tests.) - #67017 (cleanup long error explanations) - #67021 (Fix docs for formatting delegations) - #67041 (add ExitStatusExt into prelude) - #67065 (Fix fetching arguments on the wasm32-wasi target) - #67066 (Update the revision of wasi-libc used in wasm32-wasi) Failed merges: r? @ghost
2 parents 7b482cd + acd2b08 commit d0126e8

37 files changed

+148
-59
lines changed

src/ci/docker/dist-various-2/build-wasi-toolchain.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export PATH=`pwd`/clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-14.04/bin:$PATH
1212
git clone https://github.com/CraneStation/wasi-libc
1313

1414
cd wasi-libc
15-
git reset --hard a94d2d04e7722b323573da2bd04e909a5763d35b
15+
git reset --hard f645f498dfbbbc00a7a97874d33082d3605c3f21
1616
make -j$(nproc) INSTALL_DIR=/wasm32-wasi install
1717

1818
cd ..

src/ci/run.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fi
2323
ci_dir=`cd $(dirname $0) && pwd`
2424
source "$ci_dir/shared.sh"
2525

26-
if [ ! isCI ] || isCiBranch auto || isCiBranch beta; then
26+
if ! isCI || isCiBranch auto || isCiBranch beta; then
2727
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set build.print-step-timings --enable-verbose-tests"
2828
fi
2929

src/libcore/fmt/mod.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ pub trait Display {
662662
/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
663663
/// let val = self.0;
664664
///
665-
/// write!(f, "{:o}", val) // delegate to i32's implementation
665+
/// fmt::Octal::fmt(&val, f) // delegate to i32's implementation
666666
/// }
667667
/// }
668668
///
@@ -712,7 +712,7 @@ pub trait Octal {
712712
/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
713713
/// let val = self.0;
714714
///
715-
/// write!(f, "{:b}", val) // delegate to i32's implementation
715+
/// fmt::Binary::fmt(&val, f) // delegate to i32's implementation
716716
/// }
717717
/// }
718718
///
@@ -771,7 +771,7 @@ pub trait Binary {
771771
/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
772772
/// let val = self.0;
773773
///
774-
/// write!(f, "{:x}", val) // delegate to i32's implementation
774+
/// fmt::LowerHex::fmt(&val, f) // delegate to i32's implementation
775775
/// }
776776
/// }
777777
///
@@ -824,7 +824,7 @@ pub trait LowerHex {
824824
/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
825825
/// let val = self.0;
826826
///
827-
/// write!(f, "{:X}", val) // delegate to i32's implementation
827+
/// fmt::UpperHex::fmt(&val, f) // delegate to i32's implementation
828828
/// }
829829
/// }
830830
///
@@ -869,7 +869,8 @@ pub trait UpperHex {
869869
/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
870870
/// // use `as` to convert to a `*const T`, which implements Pointer, which we can use
871871
///
872-
/// write!(f, "{:p}", self as *const Length)
872+
/// let ptr = self as *const Self;
873+
/// fmt::Pointer::fmt(&ptr, f)
873874
/// }
874875
/// }
875876
///

src/libcore/iter/traits/collect.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@
9191
/// ```
9292
#[stable(feature = "rust1", since = "1.0.0")]
9393
#[rustc_on_unimplemented(
94-
message="a collection of type `{Self}` cannot be built from an iterator \
94+
message="a value of type `{Self}` cannot be built from an iterator \
9595
over elements of type `{A}`",
96-
label="a collection of type `{Self}` cannot be built from `std::iter::Iterator<Item={A}>`",
96+
label="value of type `{Self}` cannot be built from `std::iter::Iterator<Item={A}>`",
9797
)]
9898
pub trait FromIterator<A>: Sized {
9999
/// Creates a value from an iterator.

src/librustc_error_codes/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ E0622: include_str!("./error_codes/E0622.md"),
347347
E0623: include_str!("./error_codes/E0623.md"),
348348
E0624: include_str!("./error_codes/E0624.md"),
349349
E0626: include_str!("./error_codes/E0626.md"),
350+
E0631: include_str!("./error_codes/E0631.md"),
350351
E0633: include_str!("./error_codes/E0633.md"),
351352
E0635: include_str!("./error_codes/E0635.md"),
352353
E0636: include_str!("./error_codes/E0636.md"),
@@ -580,7 +581,6 @@ E0745: include_str!("./error_codes/E0745.md"),
580581
// rustc_const_unstable attribute must be paired with stable/unstable
581582
// attribute
582583
E0630,
583-
E0631, // type mismatch in closure arguments
584584
E0632, // cannot provide explicit generic arguments when `impl Trait` is
585585
// used in argument position
586586
E0634, // type has conflicting packed representaton hints

src/librustc_error_codes/error_codes/E0092.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
You tried to declare an undefined atomic operation function.
1+
An undefined atomic operation function was declared.
2+
23
Erroneous code example:
34

45
```compile_fail,E0092
@@ -11,8 +12,8 @@ extern "rust-intrinsic" {
1112
```
1213

1314
Please check you didn't make a mistake in the function's name. All intrinsic
14-
functions are defined in librustc_codegen_llvm/intrinsic.rs and in
15-
libcore/intrinsics.rs in the Rust source code. Example:
15+
functions are defined in `librustc_codegen_llvm/intrinsic.rs` and in
16+
`libcore/intrinsics.rs` in the Rust source code. Example:
1617

1718
```
1819
#![feature(intrinsics)]

src/librustc_error_codes/error_codes/E0093.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
You declared an unknown intrinsic function. Erroneous code example:
1+
An unknown intrinsic function was declared.
2+
3+
Erroneous code example:
24

35
```compile_fail,E0093
46
#![feature(intrinsics)]
@@ -15,8 +17,8 @@ fn main() {
1517
```
1618

1719
Please check you didn't make a mistake in the function's name. All intrinsic
18-
functions are defined in librustc_codegen_llvm/intrinsic.rs and in
19-
libcore/intrinsics.rs in the Rust source code. Example:
20+
functions are defined in `librustc_codegen_llvm/intrinsic.rs` and in
21+
`libcore/intrinsics.rs` in the Rust source code. Example:
2022

2123
```
2224
#![feature(intrinsics)]

src/librustc_error_codes/error_codes/E0094.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
You gave an invalid number of type parameters to an intrinsic function.
1+
An invalid number of type parameters was given to an intrinsic function.
2+
23
Erroneous code example:
34

45
```compile_fail,E0094

src/librustc_error_codes/error_codes/E0106.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ This error indicates that a lifetime is missing from a type. If it is an error
22
inside a function signature, the problem may be with failing to adhere to the
33
lifetime elision rules (see below).
44

5-
Here are some simple examples of where you'll run into this error:
5+
Erroneous code examples:
66

77
```compile_fail,E0106
88
struct Foo1 { x: &bool }
@@ -27,7 +27,7 @@ function signatures which allows you to leave out lifetimes in certain cases.
2727
For more background on lifetime elision see [the book][book-le].
2828

2929
The lifetime elision rules require that any function signature with an elided
30-
output lifetime must either have
30+
output lifetime must either have:
3131

3232
- exactly one input lifetime
3333
- or, multiple input lifetimes, but the function must also be a method with a
+20-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
This error means that an incorrect number of generic arguments were provided:
1+
An incorrect number of generic arguments were provided.
2+
3+
Erroneous code example:
24

35
```compile_fail,E0107
46
struct Foo<T> { x: T }
@@ -9,19 +11,34 @@ struct Baz<S, T> { x: Foo<S, T> } // error: wrong number of type arguments:
911
// expected 1, found 2
1012
1113
fn foo<T, U>(x: T, y: U) {}
14+
fn f() {}
1215
1316
fn main() {
1417
let x: bool = true;
1518
foo::<bool>(x); // error: wrong number of type arguments:
1619
// expected 2, found 1
1720
foo::<bool, i32, i32>(x, 2, 4); // error: wrong number of type arguments:
1821
// expected 2, found 3
22+
f::<'static>(); // error: wrong number of lifetime arguments
23+
// expected 0, found 1
1924
}
25+
```
26+
27+
When using/declaring an item with generic arguments, you must provide the exact
28+
same number:
29+
30+
```
31+
struct Foo<T> { x: T }
32+
33+
struct Bar<T> { x: Foo<T> } // ok!
34+
struct Baz<S, T> { x: Foo<S>, y: Foo<T> } // ok!
2035
36+
fn foo<T, U>(x: T, y: U) {}
2137
fn f() {}
2238
2339
fn main() {
24-
f::<'static>(); // error: wrong number of lifetime arguments:
25-
// expected 0, found 1
40+
let x: bool = true;
41+
foo::<bool, u32>(x, 12); // ok!
42+
f(); // ok!
2643
}
2744
```

src/librustc_error_codes/error_codes/E0109.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
You tried to provide a generic argument to a type which doesn't need it.
2+
23
Erroneous code example:
34

45
```compile_fail,E0109

src/librustc_error_codes/error_codes/E0116.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
You can only define an inherent implementation for a type in the same crate
2-
where the type was defined. For example, an `impl` block as below is not allowed
3-
since `Vec` is defined in the standard library:
1+
An inherent implementation was defined for a type outside the current crate.
2+
3+
Erroneous code example:
44

55
```compile_fail,E0116
66
impl Vec<u8> { } // error
77
```
88

9+
You can only define an inherent implementation for a type in the same crate
10+
where the type was defined. For example, an `impl` block as above is not allowed
11+
since `Vec` is defined in the standard library.
12+
913
To fix this problem, you can do either of these things:
1014

1115
- define a trait that has the desired associated functions/types/constants and

src/librustc_error_codes/error_codes/E0117.md

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
The `Drop` trait was implemented on a non-struct type.
2+
3+
Erroneous code example:
4+
5+
```compile_fail,E0117
6+
impl Drop for u32 {}
7+
```
8+
19
This error indicates a violation of one of Rust's orphan rules for trait
210
implementations. The rule prohibits any implementation of a foreign trait (a
311
trait defined in another crate) where
@@ -6,12 +14,6 @@ trait defined in another crate) where
614
- all of the parameters being passed to the trait (if there are any) are also
715
foreign.
816

9-
Here's one example of this error:
10-
11-
```compile_fail,E0117
12-
impl Drop for u32 {}
13-
```
14-
1517
To avoid this kind of error, ensure that at least one local type is referenced
1618
by the `impl`:
1719

src/librustc_error_codes/error_codes/E0118.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
You're trying to write an inherent implementation for something which isn't a
2-
struct nor an enum. Erroneous code example:
1+
An inherent implementation was defined for something which isn't a struct nor
2+
an enum.
3+
4+
Erroneous code example:
35

46
```compile_fail,E0118
57
impl (u8, u8) { // error: no base type found for inherent implementation

src/librustc_error_codes/error_codes/E0119.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
There are conflicting trait implementations for the same type.
2-
Example of erroneous code:
2+
3+
Erroneous code example:
34

45
```compile_fail,E0119
56
trait MyTrait {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
This error indicates a type mismatch in closure arguments.
2+
3+
Erroneous code example:
4+
5+
```compile_fail,E0631
6+
fn foo<F: Fn(i32)>(f: F) {
7+
}
8+
9+
fn main() {
10+
foo(|x: &str| {});
11+
}
12+
```
13+
14+
The error occurs because `foo` accepts a closure that takes an `i32` argument,
15+
but in `main`, it is passed a closure with a `&str` argument.
16+
17+
This can be resolved by changing the type annotation or removing it entirely
18+
if it can be inferred.
19+
20+
```
21+
fn foo<F: Fn(i32)>(f: F) {
22+
}
23+
24+
fn main() {
25+
foo(|x: i32| {});
26+
}
27+
```

src/libstd/sys/vxworks/ext/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,7 @@ pub mod prelude {
1818
#[doc(no_inline)]
1919
#[stable(feature = "rust1", since = "1.0.0")]
2020
pub use super::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
21+
#[doc(no_inline)]
22+
#[stable(feature = "rust1", since = "1.0.0")]
23+
pub use super::process::ExitStatusExt;
2124
}

src/libstd/sys/vxworks/os.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@ use crate::path::{self, PathBuf, Path};
1111
use crate::ptr;
1212
use crate::slice;
1313
use crate::str;
14-
use crate::sys_common::mutex::Mutex;
14+
use crate::sys_common::mutex::{Mutex, MutexGuard};
1515
use crate::sys::cvt;
1616
/*use sys::fd; this one is probably important */
1717
use crate::vec;
1818

1919
const TMPBUF_SZ: usize = 128;
20-
static ENV_LOCK: Mutex = Mutex::new();
21-
2220

2321
// This is a terrible fix
2422
use crate::sys::os_str::Buf;
@@ -200,11 +198,18 @@ pub unsafe fn environ() -> *mut *const *const c_char {
200198
&mut environ
201199
}
202200

201+
pub unsafe fn env_lock() -> MutexGuard<'static> {
202+
// We never call `ENV_LOCK.init()`, so it is UB to attempt to
203+
// acquire this mutex reentrantly!
204+
static ENV_LOCK: Mutex = Mutex::new();
205+
ENV_LOCK.lock()
206+
}
207+
203208
/// Returns a vector of (variable, value) byte-vector pairs for all the
204209
/// environment variables of the current process.
205210
pub fn env() -> Env {
206211
unsafe {
207-
let _guard = ENV_LOCK.lock();
212+
let _guard = env_lock();
208213
let mut environ = *environ();
209214
if environ == ptr::null() {
210215
panic!("os::env() failure getting env string from OS: {}",
@@ -244,7 +249,7 @@ pub fn getenv(k: &OsStr) -> io::Result<Option<OsString>> {
244249
// always None as well
245250
let k = CString::new(k.as_bytes())?;
246251
unsafe {
247-
let _guard = ENV_LOCK.lock();
252+
let _guard = env_lock();
248253
let s = libc::getenv(k.as_ptr()) as *const libc::c_char;
249254
let ret = if s.is_null() {
250255
None
@@ -260,7 +265,7 @@ pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> {
260265
let v = CString::new(v.as_bytes())?;
261266

262267
unsafe {
263-
let _guard = ENV_LOCK.lock();
268+
let _guard = env_lock();
264269
cvt(libc::setenv(k.as_ptr(), v.as_ptr(), 1)).map(|_| ())
265270
}
266271
}
@@ -269,7 +274,7 @@ pub fn unsetenv(n: &OsStr) -> io::Result<()> {
269274
let nbuf = CString::new(n.as_bytes())?;
270275

271276
unsafe {
272-
let _guard = ENV_LOCK.lock();
277+
let _guard = env_lock();
273278
cvt(libc::unsetenv(nbuf.as_ptr())).map(|_| ())
274279
}
275280
}

src/libstd/sys/vxworks/process/process_vxworks.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ impl Command {
1515
-> io::Result<(Process, StdioPipes)> {
1616
use crate::sys::{cvt_r};
1717
const CLOEXEC_MSG_FOOTER: &'static [u8] = b"NOEX";
18+
let envp = self.capture_env();
1819

1920
if self.saw_nul() {
2021
return Err(io::Error::new(ErrorKind::InvalidInput,
@@ -52,12 +53,19 @@ impl Command {
5253
t!(cvt(libc::chdir(cwd.as_ptr())));
5354
}
5455

56+
let c_envp = envp.as_ref().map(|c| c.as_ptr())
57+
.unwrap_or_else(|| *sys::os::environ() as *const _);
58+
let stack_size = thread::min_stack();
59+
60+
// ensure that access to the environment is synchronized
61+
let _lock = sys::os::env_lock();
62+
5563
let ret = libc::rtpSpawn(
5664
self.get_argv()[0], // executing program
5765
self.get_argv().as_ptr() as *mut *const c_char, // argv
58-
*sys::os::environ() as *mut *const c_char,
66+
c_envp as *mut *const c_char,
5967
100 as c_int, // initial priority
60-
thread::min_stack(), // initial stack size.
68+
stack_size, // initial stack size.
6169
0, // options
6270
0 // task options
6371
);

0 commit comments

Comments
 (0)