Skip to content

Commit a09d36d

Browse files
committed
Auto merge of rust-lang#97180 - Dylan-DPC:rollup-aa5j2yw, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - rust-lang#96539 (Add release notes for 1.61.0) - rust-lang#97142 (move processing of `source_scope_data` into `MutVisitor`'s impl of `Integrator` when inline) - rust-lang#97155 (Fix doc typo) - rust-lang#97169 (Improve `u32 as char` cast diagnostic) - rust-lang#97170 (Remove unnecessay .report() on ExitCode) - rust-lang#97171 (Add regression test for rust-lang#88119) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents c067287 + 1fb9be0 commit a09d36d

File tree

9 files changed

+216
-59
lines changed

9 files changed

+216
-59
lines changed

RELEASES.md

+126
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,129 @@
1+
Version 1.61.0 (2022-05-19)
2+
==========================
3+
4+
Language
5+
--------
6+
7+
- [`const fn` signatures can now include generic trait bounds][93827]
8+
- [`const fn` signatures can now use `impl Trait` in argument and return position][93827]
9+
- [Function pointers can now be created, cast, and passed around in a `const fn`][93827]
10+
- [Recursive calls can now set the value of a function's opaque `impl Trait` return type][94081]
11+
12+
Compiler
13+
--------
14+
15+
- [Linking modifier syntax in `#[link]` attributes and on the command line, as well as the `whole-archive` modifier specifically, are now supported][93901]
16+
- [The `char` type is now described as UTF-32 in debuginfo][89887]
17+
- The [`#[target_feature]`][target_feature] attribute [can now be used with aarch64 features][90621]
18+
- X86 [`#[target_feature = "adx"]` is now stable][93745]
19+
20+
Libraries
21+
---------
22+
23+
- [`ManuallyDrop<T>` is now documented to have the same layout as `T`][88375]
24+
- [`#[ignore = "…"]` messages are printed when running tests][92714]
25+
- [Consistently show absent stdio handles on Windows as NULL handles][93263]
26+
- [Make `std::io::stdio::lock()` return `'static` handles.][93965] Previously, the creation of locked handles to stdin/stdout/stderr would borrow the handles being locked, which prevented writing `let out = std::io::stdout().lock();` because `out` would outlive the return value of `stdout()`. Such code now works, eliminating a common pitfall that affected many Rust users.
27+
- [`Vec::from_raw_parts` is now less restrictive about its inputs][95016]
28+
- [`std::thread::available_parallelism` now takes cgroup quotas into account.][92697] Since `available_parallelism` is often used to create a thread pool for parallel computation, which may be CPU-bound for performance, `available_parallelism` will return a value consistent with the ability to use that many threads continuously, if possible. For instance, in a container with 8 virtual CPUs but quotas only allowing for 50% usage, `available_parallelism` will return 4.
29+
30+
Stabilized APIs
31+
---------------
32+
33+
- [`Pin::static_mut`]
34+
- [`Pin::static_ref`]
35+
- [`Vec::retain_mut`]
36+
- [`VecDeque::retain_mut`]
37+
- [`Write` for `Cursor<[u8; N]>`][cursor-write-array]
38+
- [`std::os::unix::net::SocketAddr::from_pathname`]
39+
- [`std::process::ExitCode`] and [`std::process::Termination`]. The stabilization of these two APIs now makes it possible for programs to return errors from `main` with custom exit codes.
40+
- [`std::thread::JoinHandle::is_finished`]
41+
42+
These APIs are now usable in const contexts:
43+
44+
- [`<*const T>::offset` and `<*mut T>::offset`][ptr-offset]
45+
- [`<*const T>::wrapping_offset` and `<*mut T>::wrapping_offset`][ptr-wrapping_offset]
46+
- [`<*const T>::add` and `<*mut T>::add`][ptr-add]
47+
- [`<*const T>::sub` and `<*mut T>::sub`][ptr-sub]
48+
- [`<*const T>::wrapping_add` and `<*mut T>::wrapping_add`][ptr-wrapping_add]
49+
- [`<*const T>::wrapping_sub` and `<*mut T>::wrapping_sub`][ptr-wrapping_sub]
50+
- [`<[T]>::as_mut_ptr`][slice-as_mut_ptr]
51+
- [`<[T]>::as_ptr_range`][slice-as_ptr_range]
52+
- [`<[T]>::as_mut_ptr_range`][slice-as_mut_ptr_range]
53+
54+
Cargo
55+
-----
56+
57+
No feature changes, but see compatibility notes.
58+
59+
Compatibility Notes
60+
-------------------
61+
62+
- Previously native static libraries were linked as `whole-archive` in some cases, but now rustc tries not to use `whole-archive` unless explicitly requested. This [change][93901] may result in linking errors in some cases. To fix such errors, native libraries linked from the command line, build scripts, or [`#[link]` attributes][link-attr] need to
63+
- (more common) either be reordered to respect dependencies between them (if `a` depends on `b` then `a` should go first and `b` second)
64+
- (less common) or be updated to use the [`+whole-archive`] modifier.
65+
- [Catching a second unwind from FFI code while cleaning up from a Rust panic now causes the process to abort][92911]
66+
- [Proc macros no longer see `ident` matchers wrapped in groups][92472]
67+
- [The number of `#` in `r#` raw string literals is now required to be less than 256][95251]
68+
- [When checking that a dyn type satisfies a trait bound, supertrait bounds are now enforced][92285]
69+
- [`cargo vendor` now only accepts one value for each `--sync` flag][cargo/10448]
70+
- [`cfg` predicates in `all()` and `any()` are always evaluated to detect errors, instead of short-circuiting.][94295] The compatibility considerations here arise in nightly-only code that used the short-circuiting behavior of `all` to write something like `cfg(all(feature = "nightly", syntax-requiring-nightly))`, which will now fail to compile. Instead, use either `cfg_attr(feature = "nightly", ...)` or nested uses of `cfg`.
71+
- [bootstrap: static-libstdcpp is now enabled by default, and can now be disabled when llvm-tools is enabled][94832]
72+
73+
Internal Changes
74+
----------------
75+
76+
These changes provide no direct user facing benefits, but represent significant
77+
improvements to the internals and overall performance of rustc
78+
and related tools.
79+
80+
- [debuginfo: Refactor debuginfo generation for types][94261]
81+
- [Remove the everybody loops pass][93913]
82+
83+
[88375]: https://github.com/rust-lang/rust/pull/88375/
84+
[89887]: https://github.com/rust-lang/rust/pull/89887/
85+
[90621]: https://github.com/rust-lang/rust/pull/90621/
86+
[92285]: https://github.com/rust-lang/rust/pull/92285/
87+
[92472]: https://github.com/rust-lang/rust/pull/92472/
88+
[92697]: https://github.com/rust-lang/rust/pull/92697/
89+
[92714]: https://github.com/rust-lang/rust/pull/92714/
90+
[92911]: https://github.com/rust-lang/rust/pull/92911/
91+
[93263]: https://github.com/rust-lang/rust/pull/93263/
92+
[93745]: https://github.com/rust-lang/rust/pull/93745/
93+
[93827]: https://github.com/rust-lang/rust/pull/93827/
94+
[93901]: https://github.com/rust-lang/rust/pull/93901/
95+
[93913]: https://github.com/rust-lang/rust/pull/93913/
96+
[93965]: https://github.com/rust-lang/rust/pull/93965/
97+
[94081]: https://github.com/rust-lang/rust/pull/94081/
98+
[94261]: https://github.com/rust-lang/rust/pull/94261/
99+
[94295]: https://github.com/rust-lang/rust/pull/94295/
100+
[94832]: https://github.com/rust-lang/rust/pull/94832/
101+
[95016]: https://github.com/rust-lang/rust/pull/95016/
102+
[95251]: https://github.com/rust-lang/rust/pull/95251/
103+
[`+whole-archive`]: https://doc.rust-lang.org/stable/rustc/command-line-arguments.html#linking-modifiers-whole-archive
104+
[`Pin::static_mut`]: https://doc.rust-lang.org/stable/std/pin/struct.Pin.html#method.static_mut
105+
[`Pin::static_ref`]: https://doc.rust-lang.org/stable/std/pin/struct.Pin.html#method.static_ref
106+
[`Vec::retain_mut`]: https://doc.rust-lang.org/stable/std/vec/struct.Vec.html#method.retain_mut
107+
[`VecDeque::retain_mut`]: https://doc.rust-lang.org/stable/std/collections/struct.VecDeque.html#method.retain_mut
108+
[`std::os::unix::net::SocketAddr::from_pathname`]: https://doc.rust-lang.org/stable/std/os/unix/net/struct.SocketAddr.html#method.from_pathname
109+
[`std::process::ExitCode`]: https://doc.rust-lang.org/stable/std/process/struct.ExitCode.html
110+
[`std::process::Termination`]: https://doc.rust-lang.org/stable/std/process/trait.Termination.html
111+
[`std::thread::JoinHandle::is_finished`]: https://doc.rust-lang.org/stable/std/thread/struct.JoinHandle.html#method.is_finished
112+
[cargo/10448]: https://github.com/rust-lang/cargo/pull/10448/
113+
[cursor-write-array]: https://doc.rust-lang.org/stable/std/io/struct.Cursor.html#impl-Write-4
114+
[link-attr]: https://doc.rust-lang.org/stable/reference/items/external-blocks.html#the-link-attribute
115+
[ptr-add]: https://doc.rust-lang.org/stable/std/primitive.pointer.html#method.add
116+
[ptr-offset]: https://doc.rust-lang.org/stable/std/primitive.pointer.html#method.offset
117+
[ptr-sub]: https://doc.rust-lang.org/stable/std/primitive.pointer.html#method.sub
118+
[ptr-wrapping_add]: https://doc.rust-lang.org/stable/std/primitive.pointer.html#method.wrapping_add
119+
[ptr-wrapping_offset]: https://doc.rust-lang.org/stable/std/primitive.pointer.html#method.wrapping_offset
120+
[ptr-wrapping_sub]: https://doc.rust-lang.org/stable/std/primitive.pointer.html#method.wrapping_sub
121+
[slice-as_mut_ptr]: https://doc.rust-lang.org/stable/std/primitive.slice.html#method.as_mut_ptr
122+
[slice-as_mut_ptr_range]: https://doc.rust-lang.org/stable/std/primitive.slice.html#method.as_mut_ptr_range
123+
[slice-as_ptr_range]: https://doc.rust-lang.org/stable/std/primitive.slice.html#method.as_ptr_range
124+
[target_feature]: https://doc.rust-lang.org/reference/attributes/codegen.html#the-target_feature-attribute
125+
126+
1127
Version 1.60.0 (2022-04-07)
2128
==========================
3129

compiler/rustc_mir_transform/src/inline.rs

+27-28
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,8 @@ impl<'tcx> Inliner<'tcx> {
554554
new_scopes: SourceScope::new(caller_body.source_scopes.len())..,
555555
new_blocks: BasicBlock::new(caller_body.basic_blocks().len())..,
556556
destination: dest,
557-
return_block: callsite.target,
557+
callsite_scope: caller_body.source_scopes[callsite.source_info.scope].clone(),
558+
callsite,
558559
cleanup_block: cleanup,
559560
in_cleanup_block: false,
560561
tcx: self.tcx,
@@ -566,31 +567,6 @@ impl<'tcx> Inliner<'tcx> {
566567
// (or existing ones, in a few special cases) in the caller.
567568
integrator.visit_body(&mut callee_body);
568569

569-
for scope in &mut callee_body.source_scopes {
570-
// FIXME(eddyb) move this into a `fn visit_scope_data` in `Integrator`.
571-
if scope.parent_scope.is_none() {
572-
let callsite_scope = &caller_body.source_scopes[callsite.source_info.scope];
573-
574-
// Attach the outermost callee scope as a child of the callsite
575-
// scope, via the `parent_scope` and `inlined_parent_scope` chains.
576-
scope.parent_scope = Some(callsite.source_info.scope);
577-
assert_eq!(scope.inlined_parent_scope, None);
578-
scope.inlined_parent_scope = if callsite_scope.inlined.is_some() {
579-
Some(callsite.source_info.scope)
580-
} else {
581-
callsite_scope.inlined_parent_scope
582-
};
583-
584-
// Mark the outermost callee scope as an inlined one.
585-
assert_eq!(scope.inlined, None);
586-
scope.inlined = Some((callsite.callee, callsite.source_info.span));
587-
} else if scope.inlined_parent_scope.is_none() {
588-
// Make it easy to find the scope with `inlined` set above.
589-
scope.inlined_parent_scope =
590-
Some(integrator.map_scope(OUTERMOST_SOURCE_SCOPE));
591-
}
592-
}
593-
594570
// If there are any locals without storage markers, give them storage only for the
595571
// duration of the call.
596572
for local in callee_body.vars_and_temps_iter() {
@@ -786,7 +762,8 @@ struct Integrator<'a, 'tcx> {
786762
new_scopes: RangeFrom<SourceScope>,
787763
new_blocks: RangeFrom<BasicBlock>,
788764
destination: Place<'tcx>,
789-
return_block: Option<BasicBlock>,
765+
callsite_scope: SourceScopeData<'tcx>,
766+
callsite: &'a CallSite<'tcx>,
790767
cleanup_block: Option<BasicBlock>,
791768
in_cleanup_block: bool,
792769
tcx: TyCtxt<'tcx>,
@@ -832,6 +809,28 @@ impl<'tcx> MutVisitor<'tcx> for Integrator<'_, 'tcx> {
832809
*local = self.map_local(*local);
833810
}
834811

812+
fn visit_source_scope_data(&mut self, scope_data: &mut SourceScopeData<'tcx>) {
813+
self.super_source_scope_data(scope_data);
814+
if scope_data.parent_scope.is_none() {
815+
// Attach the outermost callee scope as a child of the callsite
816+
// scope, via the `parent_scope` and `inlined_parent_scope` chains.
817+
scope_data.parent_scope = Some(self.callsite.source_info.scope);
818+
assert_eq!(scope_data.inlined_parent_scope, None);
819+
scope_data.inlined_parent_scope = if self.callsite_scope.inlined.is_some() {
820+
Some(self.callsite.source_info.scope)
821+
} else {
822+
self.callsite_scope.inlined_parent_scope
823+
};
824+
825+
// Mark the outermost callee scope as an inlined one.
826+
assert_eq!(scope_data.inlined, None);
827+
scope_data.inlined = Some((self.callsite.callee, self.callsite.source_info.span));
828+
} else if scope_data.inlined_parent_scope.is_none() {
829+
// Make it easy to find the scope with `inlined` set above.
830+
scope_data.inlined_parent_scope = Some(self.map_scope(OUTERMOST_SOURCE_SCOPE));
831+
}
832+
}
833+
835834
fn visit_source_scope(&mut self, scope: &mut SourceScope) {
836835
*scope = self.map_scope(*scope);
837836
}
@@ -938,7 +937,7 @@ impl<'tcx> MutVisitor<'tcx> for Integrator<'_, 'tcx> {
938937
}
939938
}
940939
TerminatorKind::Return => {
941-
terminator.kind = if let Some(tgt) = self.return_block {
940+
terminator.kind = if let Some(tgt) = self.callsite.target {
942941
TerminatorKind::Goto { target: tgt }
943942
} else {
944943
TerminatorKind::Unreachable

compiler/rustc_typeck/src/check/cast.rs

+16-10
Original file line numberDiff line numberDiff line change
@@ -347,16 +347,22 @@ impl<'a, 'tcx> CastCheck<'tcx> {
347347
);
348348
err.span_label(self.span, "invalid cast");
349349
if self.expr_ty.is_numeric() {
350-
err.span_help(
351-
self.span,
352-
if self.expr_ty == fcx.tcx.types.i8 {
353-
"try casting from `u8` instead"
354-
} else if self.expr_ty == fcx.tcx.types.u32 {
355-
"try `char::from_u32` instead"
356-
} else {
357-
"try `char::from_u32` instead (via a `u32`)"
358-
},
359-
);
350+
if self.expr_ty == fcx.tcx.types.u32 {
351+
match fcx.tcx.sess.source_map().span_to_snippet(self.expr.span) {
352+
Ok(snippet) => err.span_suggestion(
353+
self.span,
354+
"try `char::from_u32` instead",
355+
format!("char::from_u32({snippet})"),
356+
Applicability::MachineApplicable,
357+
),
358+
359+
Err(_) => err.span_help(self.span, "try `char::from_u32` instead"),
360+
};
361+
} else if self.expr_ty == fcx.tcx.types.i8 {
362+
err.span_help(self.span, "try casting from `u8` instead");
363+
} else {
364+
err.span_help(self.span, "try `char::from_u32` instead (via a `u32`)");
365+
};
360366
}
361367
err.emit();
362368
}

library/core/src/sync/atomic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2830,7 +2830,7 @@ unsafe fn atomic_umin<T: Copy>(dst: *mut T, val: T, order: Ordering) -> T {
28302830
/// A fence 'A' which has (at least) [`Release`] ordering semantics, synchronizes
28312831
/// with a fence 'B' with (at least) [`Acquire`] semantics, if and only if there
28322832
/// exist operations X and Y, both operating on some atomic object 'M' such
2833-
/// that A is sequenced before X, Y is synchronized before B and Y observes
2833+
/// that A is sequenced before X, Y is sequenced before B and Y observes
28342834
/// the change to M. This provides a happens-before dependence between A and B.
28352835
///
28362836
/// ```text

library/std/src/process.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2136,7 +2136,7 @@ pub trait Termination {
21362136
impl Termination for () {
21372137
#[inline]
21382138
fn report(self) -> ExitCode {
2139-
ExitCode::SUCCESS.report()
2139+
ExitCode::SUCCESS
21402140
}
21412141
}
21422142

@@ -2162,7 +2162,7 @@ impl<E: fmt::Debug> Termination for Result<!, E> {
21622162
fn report(self) -> ExitCode {
21632163
let Err(err) = self;
21642164
eprintln!("Error: {err:?}");
2165-
ExitCode::FAILURE.report()
2165+
ExitCode::FAILURE
21662166
}
21672167
}
21682168

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// check-pass
2+
3+
#![allow(incomplete_features)]
4+
#![feature(const_trait_impl, generic_const_exprs)]
5+
6+
trait ConstName {
7+
const NAME_BYTES: &'static [u8];
8+
}
9+
10+
impl const ConstName for u8 {
11+
const NAME_BYTES: &'static [u8] = b"u8";
12+
}
13+
14+
const fn name_len<T: ?Sized + ConstName>() -> usize {
15+
T::NAME_BYTES.len()
16+
}
17+
18+
impl<T: ?Sized + ConstName> const ConstName for &T
19+
where
20+
[(); name_len::<T>()]:,
21+
{
22+
const NAME_BYTES: &'static [u8] = b"&T";
23+
}
24+
25+
impl<T: ?Sized + ConstName> const ConstName for &mut T
26+
where
27+
[(); name_len::<T>()]:,
28+
{
29+
const NAME_BYTES: &'static [u8] = b"&mut T";
30+
}
31+
32+
pub const ICE_1: &'static [u8] = <&&mut u8 as ConstName>::NAME_BYTES;
33+
pub const ICE_2: &'static [u8] = <&mut &u8 as ConstName>::NAME_BYTES;
34+
35+
fn main() {}

src/test/ui/error-codes/E0604.stderr

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
error[E0604]: only `u8` can be cast as `char`, not `u32`
22
--> $DIR/E0604.rs:2:5
33
|
4-
LL | 1u32 as char;
5-
| ^^^^^^^^^^^^ invalid cast
6-
|
7-
help: try `char::from_u32` instead
8-
--> $DIR/E0604.rs:2:5
9-
|
104
LL | 1u32 as char;
115
| ^^^^^^^^^^^^
6+
| |
7+
| invalid cast
8+
| help: try `char::from_u32` instead: `char::from_u32(1u32)`
129

1310
error: aborting due to previous error
1411

src/test/ui/error-festival.stderr

+3-6
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,11 @@ LL | | }
5656
error[E0604]: only `u8` can be cast as `char`, not `u32`
5757
--> $DIR/error-festival.rs:25:5
5858
|
59-
LL | 0u32 as char;
60-
| ^^^^^^^^^^^^ invalid cast
61-
|
62-
help: try `char::from_u32` instead
63-
--> $DIR/error-festival.rs:25:5
64-
|
6559
LL | 0u32 as char;
6660
| ^^^^^^^^^^^^
61+
| |
62+
| invalid cast
63+
| help: try `char::from_u32` instead: `char::from_u32(0u32)`
6764

6865
error[E0605]: non-primitive cast: `u8` as `Vec<u8>`
6966
--> $DIR/error-festival.rs:29:5

src/test/ui/mismatched_types/cast-rfc0401.stderr

+3-6
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,11 @@ LL | let _ = E::A as bool;
9797
error[E0604]: only `u8` can be cast as `char`, not `u32`
9898
--> $DIR/cast-rfc0401.rs:41:13
9999
|
100-
LL | let _ = 0x61u32 as char;
101-
| ^^^^^^^^^^^^^^^ invalid cast
102-
|
103-
help: try `char::from_u32` instead
104-
--> $DIR/cast-rfc0401.rs:41:13
105-
|
106100
LL | let _ = 0x61u32 as char;
107101
| ^^^^^^^^^^^^^^^
102+
| |
103+
| invalid cast
104+
| help: try `char::from_u32` instead: `char::from_u32(0x61u32)`
108105

109106
error[E0606]: casting `bool` as `f32` is invalid
110107
--> $DIR/cast-rfc0401.rs:43:13

0 commit comments

Comments
 (0)