Skip to content

Commit b08d071

Browse files
committed
Auto merge of #69748 - Mark-Simulacrum:beta-next, r=Mark-Simulacrum
[beta] another round of backports for 1.42 This backports the following pull requests: * Fix a leak in `DiagnosticBuilder::into_diagnostic`. #69628 * stash API: remove panic to fix ICE. #69623 * Do not ICE on invalid type node after parse recovery #69583 * Backport only: avoid ICE on bad placeholder type #69324 * add regression test for issue #68794 #69168 * Update compiler-builtins to 0.1.25 #69086 * Update RELEASES.md for 1.42.0 #68989
2 parents 4e1c5f0 + cead378 commit b08d071

19 files changed

+257
-772
lines changed

Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -575,9 +575,9 @@ dependencies = [
575575

576576
[[package]]
577577
name = "compiler_builtins"
578-
version = "0.1.24"
578+
version = "0.1.25"
579579
source = "registry+https://github.com/rust-lang/crates.io-index"
580-
checksum = "b9975aefa63997ef75ca9cf013ff1bb81487aaa0b622c21053afd3b92979a7af"
580+
checksum = "438ac08ddc5efe81452f984a9e33ba425b00b31d1f48e6acd9e2210aa28cc52e"
581581
dependencies = [
582582
"cc",
583583
"rustc-std-workspace-core",

RELEASES.md

+98
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,100 @@
1+
Version 1.42.0 (2020-03-12)
2+
==========================
3+
4+
Language
5+
--------
6+
- [You can now use the slice pattern syntax with subslices.][67712] e.g.
7+
```rust
8+
fn foo(words: &[&str]) {
9+
match words {
10+
["Hello", "World", "!", ..] => println!("Hello World!"),
11+
["Foo", "Bar", ..] => println!("Baz"),
12+
rest => println!("{:?}", rest),
13+
}
14+
}
15+
```
16+
- [You can now use `#[repr(transparent)]` on univariant `enum`s.][68122] Meaning
17+
that you can create an enum that has the exact layout and ABI of the type
18+
it contains.
19+
- [There are some *syntax-only* changes:][67131]
20+
- `default` is syntactically allowed before items in `trait` definitions.
21+
- Items in `impl`s (i.e. `const`s, `type`s, and `fn`s) may syntactically
22+
leave out their bodies in favor of `;`.
23+
- Bounds on associated types in `impl`s are now syntactically allowed
24+
(e.g. `type Foo: Ord;`).
25+
- `...` (the C-variadic type) may occur syntactically directly as the type of
26+
any function parameter.
27+
28+
These are still rejected *semantically*, so you will likely receive an error
29+
but these changes can be seen and parsed by procedural macros and
30+
conditional compilation.
31+
32+
Compiler
33+
--------
34+
- [Added tier 2\* support for `armv7a-none-eabi`.][68253]
35+
- [Added tier 2 support for `riscv64gc-unknown-linux-gnu`.][68339]
36+
- [`Option::{expect,unwrap}` and
37+
`Result::{expect, expect_err, unwrap, unwrap_err}` now produce panic messages
38+
pointing to the location where they were called, rather than
39+
`core`'s internals. ][67887]
40+
41+
\* Refer to Rust's [platform support page][forge-platform-support] for more
42+
information on Rust's tiered platform support.
43+
44+
Libraries
45+
---------
46+
- [`iter::Empty<T>` now implements `Send` and `Sync` for any `T`.][68348]
47+
- [`Pin::{map_unchecked, map_unchecked_mut}` no longer require the return type
48+
to implement `Sized`.][67935]
49+
- [`io::Cursor` now derives `PartialEq` and `Eq`.][67233]
50+
- [`Layout::new` is now `const`.][66254]
51+
- [Added Standard Library support for `riscv64gc-unknown-linux-gnu`.][66899]
52+
53+
54+
Stabilized APIs
55+
---------------
56+
- [`CondVar::wait_while`]
57+
- [`CondVar::wait_timeout_while`]
58+
- [`DebugMap::key`]
59+
- [`DebugMap::value`]
60+
- [`ManuallyDrop::take`]
61+
- [`matches!`]
62+
- [`ptr::slice_from_raw_parts_mut`]
63+
- [`ptr::slice_from_raw_parts`]
64+
65+
Cargo
66+
-----
67+
- [You no longer need to include `extern crate proc_macro;` to be able to
68+
`use proc_macro;` in the `2018` edition.][cargo/7700]
69+
70+
Compatibility Notes
71+
-------------------
72+
- [`Error::description` has been deprecated, and its use will now produce a
73+
warning.][66919] It's recommended to use `Display`/`to_string` instead.
74+
75+
[68253]: https://github.com/rust-lang/rust/pull/68253/
76+
[68348]: https://github.com/rust-lang/rust/pull/68348/
77+
[67935]: https://github.com/rust-lang/rust/pull/67935/
78+
[68339]: https://github.com/rust-lang/rust/pull/68339/
79+
[68122]: https://github.com/rust-lang/rust/pull/68122/
80+
[67712]: https://github.com/rust-lang/rust/pull/67712/
81+
[67887]: https://github.com/rust-lang/rust/pull/67887/
82+
[67131]: https://github.com/rust-lang/rust/pull/67131/
83+
[67233]: https://github.com/rust-lang/rust/pull/67233/
84+
[66899]: https://github.com/rust-lang/rust/pull/66899/
85+
[66919]: https://github.com/rust-lang/rust/pull/66919/
86+
[66254]: https://github.com/rust-lang/rust/pull/66254/
87+
[cargo/7700]: https://github.com/rust-lang/cargo/pull/7700
88+
[`DebugMap::key`]: https://doc.rust-lang.org/stable/std/fmt/struct.DebugMap.html#method.key
89+
[`DebugMap::value`]: https://doc.rust-lang.org/stable/std/fmt/struct.DebugMap.html#method.value
90+
[`ManuallyDrop::take`]: https://doc.rust-lang.org/stable/std/mem/struct.ManuallyDrop.html#method.take
91+
[`matches!`]: https://doc.rust-lang.org/stable/std/macro.matches.html
92+
[`ptr::slice_from_raw_parts_mut`]: https://doc.rust-lang.org/stable/std/ptr/fn.slice_from_raw_parts_mut.html
93+
[`ptr::slice_from_raw_parts`]: https://doc.rust-lang.org/stable/std/ptr/fn.slice_from_raw_parts.html
94+
[`CondVar::wait_while`]: https://doc.rust-lang.org/stable/std/sync/struct.Condvar.html#method.wait_while
95+
[`CondVar::wait_timeout_while`]: https://doc.rust-lang.org/stable/std/sync/struct.Condvar.html#method.wait_timeout_while
96+
97+
198
Version 1.41.1 (2020-02-27)
299
===========================
3100

@@ -8,6 +105,7 @@ Version 1.41.1 (2020-02-27)
8105
[69225]: https://github.com/rust-lang/rust/issues/69225
9106
[69145]: https://github.com/rust-lang/rust/pull/69145
10107

108+
11109
Version 1.41.0 (2020-01-30)
12110
===========================
13111

src/librustc_errors/diagnostic_builder.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,11 @@ impl<'a> DiagnosticBuilder<'a> {
132132

133133
let handler = self.0.handler;
134134

135-
// We need to use `ptr::read` because `DiagnosticBuilder` implements `Drop`.
136-
let diagnostic;
137-
unsafe {
138-
diagnostic = std::ptr::read(&self.0.diagnostic);
139-
std::mem::forget(self);
140-
};
135+
// We must use `Level::Cancelled` for `dummy` to avoid an ICE about an
136+
// unused diagnostic.
137+
let dummy = Diagnostic::new(Level::Cancelled, "");
138+
let diagnostic = std::mem::replace(&mut self.0.diagnostic, dummy);
139+
141140
// Logging here is useful to help track down where in logs an error was
142141
// actually emitted.
143142
debug!("buffer: diagnostic={:?}", diagnostic);

src/librustc_errors/lib.rs

+4-14
Original file line numberDiff line numberDiff line change
@@ -446,22 +446,12 @@ impl Handler {
446446
}
447447

448448
/// Stash a given diagnostic with the given `Span` and `StashKey` as the key for later stealing.
449-
/// If the diagnostic with this `(span, key)` already exists, this will result in an ICE.
450449
pub fn stash_diagnostic(&self, span: Span, key: StashKey, diag: Diagnostic) {
451450
let mut inner = self.inner.borrow_mut();
452-
if let Some(mut old_diag) = inner.stashed_diagnostics.insert((span, key), diag) {
453-
// We are removing a previously stashed diagnostic which should not happen.
454-
old_diag.level = Bug;
455-
old_diag.note(&format!(
456-
"{}:{}: already existing stashed diagnostic with (span = {:?}, key = {:?})",
457-
file!(),
458-
line!(),
459-
span,
460-
key
461-
));
462-
inner.emit_diag_at_span(old_diag, span);
463-
panic!(ExplicitBug);
464-
}
451+
// FIXME(Centril, #69537): Consider reintroducing panic on overwriting a stashed diagnostic
452+
// if/when we have a more robust macro-friendly replacement for `(span, key)` as a key.
453+
// See the PR for a discussion.
454+
inner.stashed_diagnostics.insert((span, key), diag);
465455
}
466456

467457
/// Steal a previously stashed diagnostic with the given `Span` and `StashKey` as the key.

src/librustc_typeck/check/expr.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13111311
ty_span: Span,
13121312
) {
13131313
if variant.recovered {
1314+
self.set_tainted_by_errors();
13141315
return;
13151316
}
13161317
let mut err = self.type_error_struct_with_diag(

src/librustc_typeck/collect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ impl AstConv<'tcx> for ItemCtxt<'tcx> {
316316
}
317317

318318
fn ty_infer(&self, _: Option<&ty::GenericParamDef>, span: Span) -> Ty<'tcx> {
319-
self.tcx().sess.delay_span_bug(span, "bad placeholder type");
319+
placeholder_type_error(self.tcx(), span, &[], vec![span], false);
320320
self.tcx().types.err
321321
}
322322

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Regression test for issue #68794
2+
#
3+
# Verify that no text relocations are accidentally introduced by linking a
4+
# minimal rust staticlib.
5+
#
6+
# The test links a rust static library into a shared library, and checks that
7+
# the linker doesn't have to flag the resulting file as containing TEXTRELs.
8+
9+
-include ../tools.mk
10+
11+
# only-linux
12+
13+
all:
14+
$(RUSTC) foo.rs
15+
$(CC) bar.c $(call STATICLIB,foo) -fPIC -shared -o $(call DYLIB,bar) \
16+
$(EXTRACFLAGS) $(EXTRACXXFLAGS)
17+
readelf -d $(call DYLIB,bar) | grep TEXTREL; test $$? -eq 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
void foo();
2+
3+
int main() {
4+
foo();
5+
return 0;
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![crate_type = "staticlib"]
2+
3+
#[no_mangle]
4+
pub extern "C" fn foo(x: u32) {
5+
// using the println! makes it so that enough code from the standard
6+
// library is included (see issue #68794)
7+
println!("foo: {}", x);
8+
}

src/test/ui/did_you_mean/bad-assoc-ty.rs

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type D = (u8, u8)::AssocTy;
1717
type E = _::AssocTy;
1818
//~^ ERROR missing angle brackets in associated item path
1919
//~| ERROR the type placeholder `_` is not allowed within types on item signatures
20+
//~| ERROR the type placeholder `_` is not allowed within types on item signatures
2021

2122
type F = &'static (u8)::AssocTy;
2223
//~^ ERROR missing angle brackets in associated item path

src/test/ui/did_you_mean/bad-assoc-ty.stderr

+16-10
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,25 @@ LL | type E = _::AssocTy;
2929
| ^^^^^^^^^^ help: try: `<_>::AssocTy`
3030

3131
error: missing angle brackets in associated item path
32-
--> $DIR/bad-assoc-ty.rs:21:19
32+
--> $DIR/bad-assoc-ty.rs:22:19
3333
|
3434
LL | type F = &'static (u8)::AssocTy;
3535
| ^^^^^^^^^^^^^ help: try: `<(u8)>::AssocTy`
3636

3737
error: missing angle brackets in associated item path
38-
--> $DIR/bad-assoc-ty.rs:27:10
38+
--> $DIR/bad-assoc-ty.rs:28:10
3939
|
4040
LL | type G = dyn 'static + (Send)::AssocTy;
4141
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `<dyn 'static + (Send)>::AssocTy`
4242

4343
error: missing angle brackets in associated item path
44-
--> $DIR/bad-assoc-ty.rs:44:10
44+
--> $DIR/bad-assoc-ty.rs:45:10
4545
|
4646
LL | type I = ty!()::AssocTy;
4747
| ^^^^^^^^^^^^^^ help: try: `<ty!()>::AssocTy`
4848

4949
error: missing angle brackets in associated item path
50-
--> $DIR/bad-assoc-ty.rs:37:19
50+
--> $DIR/bad-assoc-ty.rs:38:19
5151
|
5252
LL | ($ty: ty) => ($ty::AssocTy);
5353
| ^^^^^^^^^^^^ help: try: `<$ty>::AssocTy`
@@ -85,26 +85,32 @@ error[E0121]: the type placeholder `_` is not allowed within types on item signa
8585
LL | type E = _::AssocTy;
8686
| ^ not allowed in type signatures
8787

88+
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
89+
--> $DIR/bad-assoc-ty.rs:17:10
90+
|
91+
LL | type E = _::AssocTy;
92+
| ^ not allowed in type signatures
93+
8894
error[E0223]: ambiguous associated type
89-
--> $DIR/bad-assoc-ty.rs:21:19
95+
--> $DIR/bad-assoc-ty.rs:22:19
9096
|
9197
LL | type F = &'static (u8)::AssocTy;
9298
| ^^^^^^^^^^^^^ help: use fully-qualified syntax: `<u8 as Trait>::AssocTy`
9399

94100
error[E0223]: ambiguous associated type
95-
--> $DIR/bad-assoc-ty.rs:27:10
101+
--> $DIR/bad-assoc-ty.rs:28:10
96102
|
97103
LL | type G = dyn 'static + (Send)::AssocTy;
98104
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use fully-qualified syntax: `<(dyn std::marker::Send + 'static) as Trait>::AssocTy`
99105

100106
error[E0223]: ambiguous associated type
101-
--> $DIR/bad-assoc-ty.rs:33:10
107+
--> $DIR/bad-assoc-ty.rs:34:10
102108
|
103109
LL | type H = Fn(u8) -> (u8)::Output;
104110
| ^^^^^^^^^^^^^^^^^^^^^^ help: use fully-qualified syntax: `<(dyn std::ops::Fn(u8) -> u8 + 'static) as Trait>::Output`
105111

106112
error[E0223]: ambiguous associated type
107-
--> $DIR/bad-assoc-ty.rs:37:19
113+
--> $DIR/bad-assoc-ty.rs:38:19
108114
|
109115
LL | ($ty: ty) => ($ty::AssocTy);
110116
| ^^^^^^^^^^^^ help: use fully-qualified syntax: `<u8 as Trait>::AssocTy`
@@ -113,12 +119,12 @@ LL | type J = ty!(u8);
113119
| ------- in this macro invocation
114120

115121
error[E0223]: ambiguous associated type
116-
--> $DIR/bad-assoc-ty.rs:44:10
122+
--> $DIR/bad-assoc-ty.rs:45:10
117123
|
118124
LL | type I = ty!()::AssocTy;
119125
| ^^^^^^^^^^^^^^ help: use fully-qualified syntax: `<u8 as Trait>::AssocTy`
120126

121-
error: aborting due to 19 previous errors
127+
error: aborting due to 20 previous errors
122128

123129
Some errors have detailed explanations: E0121, E0223.
124130
For more information about an error, try `rustc --explain E0121`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
macro_rules! suite {
2+
( $( $fn:ident; )* ) => {
3+
$(
4+
const A = "A".$fn();
5+
//~^ ERROR the name `A` is defined multiple times
6+
//~| ERROR missing type for `const` item
7+
//~| ERROR the type placeholder `_` is not allowed within types
8+
)*
9+
}
10+
}
11+
12+
suite! {
13+
len;
14+
is_empty;
15+
}
16+
17+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
error[E0428]: the name `A` is defined multiple times
2+
--> $DIR/issue-69396-const-no-type-in-macro.rs:4:13
3+
|
4+
LL | const A = "A".$fn();
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
| |
7+
| `A` redefined here
8+
| previous definition of the value `A` here
9+
...
10+
LL | / suite! {
11+
LL | | len;
12+
LL | | is_empty;
13+
LL | | }
14+
| |_- in this macro invocation
15+
|
16+
= note: `A` must be defined only once in the value namespace of this module
17+
18+
error: missing type for `const` item
19+
--> $DIR/issue-69396-const-no-type-in-macro.rs:4:19
20+
|
21+
LL | const A = "A".$fn();
22+
| ^ help: provide a type for the item: `A: usize`
23+
...
24+
LL | / suite! {
25+
LL | | len;
26+
LL | | is_empty;
27+
LL | | }
28+
| |_- in this macro invocation
29+
30+
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
31+
--> $DIR/issue-69396-const-no-type-in-macro.rs:4:19
32+
|
33+
LL | const A = "A".$fn();
34+
| ^
35+
| |
36+
| not allowed in type signatures
37+
| help: replace `_` with the correct type: `bool`
38+
...
39+
LL | / suite! {
40+
LL | | len;
41+
LL | | is_empty;
42+
LL | | }
43+
| |_- in this macro invocation
44+
45+
error: aborting due to 3 previous errors
46+
47+
Some errors have detailed explanations: E0121, E0428.
48+
For more information about an error, try `rustc --explain E0121`.

src/test/ui/self/self-infer.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ struct S;
22

33
impl S {
44
fn f(self: _) {} //~ERROR the type placeholder `_` is not allowed within types on item sig
5+
//~^ ERROR the type placeholder `_` is not allowed within types on item sig
56
fn g(self: &_) {} //~ERROR the type placeholder `_` is not allowed within types on item sig
7+
//~^ ERROR the type placeholder `_` is not allowed within types on item sig
68
}
79

810
fn main() {}

0 commit comments

Comments
 (0)