Skip to content

Commit

Permalink
Auto merge of #69748 - Mark-Simulacrum:beta-next, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
[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
  • Loading branch information
bors committed Mar 6, 2020
2 parents 4e1c5f0 + cead378 commit b08d071
Show file tree
Hide file tree
Showing 19 changed files with 257 additions and 772 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -575,9 +575,9 @@ dependencies = [

[[package]]
name = "compiler_builtins"
version = "0.1.24"
version = "0.1.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9975aefa63997ef75ca9cf013ff1bb81487aaa0b622c21053afd3b92979a7af"
checksum = "438ac08ddc5efe81452f984a9e33ba425b00b31d1f48e6acd9e2210aa28cc52e"
dependencies = [
"cc",
"rustc-std-workspace-core",
Expand Down
98 changes: 98 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,100 @@
Version 1.42.0 (2020-03-12)
==========================

Language
--------
- [You can now use the slice pattern syntax with subslices.][67712] e.g.
```rust
fn foo(words: &[&str]) {
match words {
["Hello", "World", "!", ..] => println!("Hello World!"),
["Foo", "Bar", ..] => println!("Baz"),
rest => println!("{:?}", rest),
}
}
```
- [You can now use `#[repr(transparent)]` on univariant `enum`s.][68122] Meaning
that you can create an enum that has the exact layout and ABI of the type
it contains.
- [There are some *syntax-only* changes:][67131]
- `default` is syntactically allowed before items in `trait` definitions.
- Items in `impl`s (i.e. `const`s, `type`s, and `fn`s) may syntactically
leave out their bodies in favor of `;`.
- Bounds on associated types in `impl`s are now syntactically allowed
(e.g. `type Foo: Ord;`).
- `...` (the C-variadic type) may occur syntactically directly as the type of
any function parameter.

These are still rejected *semantically*, so you will likely receive an error
but these changes can be seen and parsed by procedural macros and
conditional compilation.

Compiler
--------
- [Added tier 2\* support for `armv7a-none-eabi`.][68253]
- [Added tier 2 support for `riscv64gc-unknown-linux-gnu`.][68339]
- [`Option::{expect,unwrap}` and
`Result::{expect, expect_err, unwrap, unwrap_err}` now produce panic messages
pointing to the location where they were called, rather than
`core`'s internals. ][67887]

\* Refer to Rust's [platform support page][forge-platform-support] for more
information on Rust's tiered platform support.

Libraries
---------
- [`iter::Empty<T>` now implements `Send` and `Sync` for any `T`.][68348]
- [`Pin::{map_unchecked, map_unchecked_mut}` no longer require the return type
to implement `Sized`.][67935]
- [`io::Cursor` now derives `PartialEq` and `Eq`.][67233]
- [`Layout::new` is now `const`.][66254]
- [Added Standard Library support for `riscv64gc-unknown-linux-gnu`.][66899]


Stabilized APIs
---------------
- [`CondVar::wait_while`]
- [`CondVar::wait_timeout_while`]
- [`DebugMap::key`]
- [`DebugMap::value`]
- [`ManuallyDrop::take`]
- [`matches!`]
- [`ptr::slice_from_raw_parts_mut`]
- [`ptr::slice_from_raw_parts`]

Cargo
-----
- [You no longer need to include `extern crate proc_macro;` to be able to
`use proc_macro;` in the `2018` edition.][cargo/7700]

Compatibility Notes
-------------------
- [`Error::description` has been deprecated, and its use will now produce a
warning.][66919] It's recommended to use `Display`/`to_string` instead.

[68253]: https://github.com/rust-lang/rust/pull/68253/
[68348]: https://github.com/rust-lang/rust/pull/68348/
[67935]: https://github.com/rust-lang/rust/pull/67935/
[68339]: https://github.com/rust-lang/rust/pull/68339/
[68122]: https://github.com/rust-lang/rust/pull/68122/
[67712]: https://github.com/rust-lang/rust/pull/67712/
[67887]: https://github.com/rust-lang/rust/pull/67887/
[67131]: https://github.com/rust-lang/rust/pull/67131/
[67233]: https://github.com/rust-lang/rust/pull/67233/
[66899]: https://github.com/rust-lang/rust/pull/66899/
[66919]: https://github.com/rust-lang/rust/pull/66919/
[66254]: https://github.com/rust-lang/rust/pull/66254/
[cargo/7700]: https://github.com/rust-lang/cargo/pull/7700
[`DebugMap::key`]: https://doc.rust-lang.org/stable/std/fmt/struct.DebugMap.html#method.key
[`DebugMap::value`]: https://doc.rust-lang.org/stable/std/fmt/struct.DebugMap.html#method.value
[`ManuallyDrop::take`]: https://doc.rust-lang.org/stable/std/mem/struct.ManuallyDrop.html#method.take
[`matches!`]: https://doc.rust-lang.org/stable/std/macro.matches.html
[`ptr::slice_from_raw_parts_mut`]: https://doc.rust-lang.org/stable/std/ptr/fn.slice_from_raw_parts_mut.html
[`ptr::slice_from_raw_parts`]: https://doc.rust-lang.org/stable/std/ptr/fn.slice_from_raw_parts.html
[`CondVar::wait_while`]: https://doc.rust-lang.org/stable/std/sync/struct.Condvar.html#method.wait_while
[`CondVar::wait_timeout_while`]: https://doc.rust-lang.org/stable/std/sync/struct.Condvar.html#method.wait_timeout_while


Version 1.41.1 (2020-02-27)
===========================

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


Version 1.41.0 (2020-01-30)
===========================

Expand Down
11 changes: 5 additions & 6 deletions src/librustc_errors/diagnostic_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,11 @@ impl<'a> DiagnosticBuilder<'a> {

let handler = self.0.handler;

// We need to use `ptr::read` because `DiagnosticBuilder` implements `Drop`.
let diagnostic;
unsafe {
diagnostic = std::ptr::read(&self.0.diagnostic);
std::mem::forget(self);
};
// We must use `Level::Cancelled` for `dummy` to avoid an ICE about an
// unused diagnostic.
let dummy = Diagnostic::new(Level::Cancelled, "");
let diagnostic = std::mem::replace(&mut self.0.diagnostic, dummy);

// Logging here is useful to help track down where in logs an error was
// actually emitted.
debug!("buffer: diagnostic={:?}", diagnostic);
Expand Down
18 changes: 4 additions & 14 deletions src/librustc_errors/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,22 +446,12 @@ impl Handler {
}

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

/// Steal a previously stashed diagnostic with the given `Span` and `StashKey` as the key.
Expand Down
1 change: 1 addition & 0 deletions src/librustc_typeck/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
ty_span: Span,
) {
if variant.recovered {
self.set_tainted_by_errors();
return;
}
let mut err = self.type_error_struct_with_diag(
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ impl AstConv<'tcx> for ItemCtxt<'tcx> {
}

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Regression test for issue #68794
#
# Verify that no text relocations are accidentally introduced by linking a
# minimal rust staticlib.
#
# The test links a rust static library into a shared library, and checks that
# the linker doesn't have to flag the resulting file as containing TEXTRELs.

-include ../tools.mk

# only-linux

all:
$(RUSTC) foo.rs
$(CC) bar.c $(call STATICLIB,foo) -fPIC -shared -o $(call DYLIB,bar) \
$(EXTRACFLAGS) $(EXTRACXXFLAGS)
readelf -d $(call DYLIB,bar) | grep TEXTREL; test $$? -eq 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
void foo();

int main() {
foo();
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![crate_type = "staticlib"]

#[no_mangle]
pub extern "C" fn foo(x: u32) {
// using the println! makes it so that enough code from the standard
// library is included (see issue #68794)
println!("foo: {}", x);
}
1 change: 1 addition & 0 deletions src/test/ui/did_you_mean/bad-assoc-ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type D = (u8, u8)::AssocTy;
type E = _::AssocTy;
//~^ ERROR missing angle brackets in associated item path
//~| ERROR the type placeholder `_` is not allowed within types on item signatures
//~| ERROR the type placeholder `_` is not allowed within types on item signatures

type F = &'static (u8)::AssocTy;
//~^ ERROR missing angle brackets in associated item path
Expand Down
26 changes: 16 additions & 10 deletions src/test/ui/did_you_mean/bad-assoc-ty.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,25 @@ LL | type E = _::AssocTy;
| ^^^^^^^^^^ help: try: `<_>::AssocTy`

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

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

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

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

error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/bad-assoc-ty.rs:17:10
|
LL | type E = _::AssocTy;
| ^ not allowed in type signatures

error[E0223]: ambiguous associated type
--> $DIR/bad-assoc-ty.rs:21:19
--> $DIR/bad-assoc-ty.rs:22:19
|
LL | type F = &'static (u8)::AssocTy;
| ^^^^^^^^^^^^^ help: use fully-qualified syntax: `<u8 as Trait>::AssocTy`

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

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

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

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

error: aborting due to 19 previous errors
error: aborting due to 20 previous errors

Some errors have detailed explanations: E0121, E0223.
For more information about an error, try `rustc --explain E0121`.
17 changes: 17 additions & 0 deletions src/test/ui/issues/issue-69396-const-no-type-in-macro.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
macro_rules! suite {
( $( $fn:ident; )* ) => {
$(
const A = "A".$fn();
//~^ ERROR the name `A` is defined multiple times
//~| ERROR missing type for `const` item
//~| ERROR the type placeholder `_` is not allowed within types
)*
}
}

suite! {
len;
is_empty;
}

fn main() {}
48 changes: 48 additions & 0 deletions src/test/ui/issues/issue-69396-const-no-type-in-macro.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
error[E0428]: the name `A` is defined multiple times
--> $DIR/issue-69396-const-no-type-in-macro.rs:4:13
|
LL | const A = "A".$fn();
| ^^^^^^^^^^^^^^^^^^^^
| |
| `A` redefined here
| previous definition of the value `A` here
...
LL | / suite! {
LL | | len;
LL | | is_empty;
LL | | }
| |_- in this macro invocation
|
= note: `A` must be defined only once in the value namespace of this module

error: missing type for `const` item
--> $DIR/issue-69396-const-no-type-in-macro.rs:4:19
|
LL | const A = "A".$fn();
| ^ help: provide a type for the item: `A: usize`
...
LL | / suite! {
LL | | len;
LL | | is_empty;
LL | | }
| |_- in this macro invocation

error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/issue-69396-const-no-type-in-macro.rs:4:19
|
LL | const A = "A".$fn();
| ^
| |
| not allowed in type signatures
| help: replace `_` with the correct type: `bool`
...
LL | / suite! {
LL | | len;
LL | | is_empty;
LL | | }
| |_- in this macro invocation

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0121, E0428.
For more information about an error, try `rustc --explain E0121`.
2 changes: 2 additions & 0 deletions src/test/ui/self/self-infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ struct S;

impl S {
fn f(self: _) {} //~ERROR the type placeholder `_` is not allowed within types on item sig
//~^ ERROR the type placeholder `_` is not allowed within types on item sig
fn g(self: &_) {} //~ERROR the type placeholder `_` is not allowed within types on item sig
//~^ ERROR the type placeholder `_` is not allowed within types on item sig
}

fn main() {}
Loading

0 comments on commit b08d071

Please sign in to comment.