Skip to content

Rollup of 5 pull requests #71653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from
3 changes: 3 additions & 0 deletions src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1012,4 +1012,7 @@ pub enum CargoMessage<'a> {
BuildScriptExecuted {
package_id: Cow<'a, str>,
},
BuildFinished {
success: bool,
},
}
27 changes: 14 additions & 13 deletions src/librustc_mir_build/hair/pattern/const_to_pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,22 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
cv.ty, structural
);
if let Some(non_sm_ty) = structural {
let adt_def = match non_sm_ty {
traits::NonStructuralMatchTy::Adt(adt_def) => adt_def,
let msg = match non_sm_ty {
traits::NonStructuralMatchTy::Adt(adt_def) => {
let path = self.tcx().def_path_str(adt_def.did);
format!(
"to use a constant of type `{}` in a pattern, \
`{}` must be annotated with `#[derive(PartialEq, Eq)]`",
path, path,
)
}
traits::NonStructuralMatchTy::Dynamic => {
format!("trait objects cannot be used in patterns")
}
traits::NonStructuralMatchTy::Param => {
bug!("use of constant whose type is a parameter inside a pattern")
}
};
let path = self.tcx().def_path_str(adt_def.did);

let make_msg = || -> String {
format!(
"to use a constant of type `{}` in a pattern, \
`{}` must be annotated with `#[derive(PartialEq, Eq)]`",
path, path,
)
};

// double-check there even *is* a semantic `PartialEq` to dispatch to.
//
Expand Down Expand Up @@ -145,13 +146,13 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {

if !ty_is_partial_eq {
// span_fatal avoids ICE from resolution of non-existent method (rare case).
self.tcx().sess.span_fatal(self.span, &make_msg());
self.tcx().sess.span_fatal(self.span, &msg);
} else {
self.tcx().struct_span_lint_hir(
lint::builtin::INDIRECT_STRUCTURAL_MATCH,
self.id,
self.span,
|lint| lint.build(&make_msg()).emit(),
|lint| lint.build(&msg).emit(),
);
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/librustc_trait_selection/traits/structural_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use rustc_span::Span;
pub enum NonStructuralMatchTy<'tcx> {
Adt(&'tcx AdtDef),
Param,
Dynamic,
}

/// This method traverses the structure of `ty`, trying to find an
Expand Down Expand Up @@ -137,6 +138,10 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for Search<'a, 'tcx> {
self.found = Some(NonStructuralMatchTy::Param);
return true; // Stop visiting.
}
ty::Dynamic(..) => {
self.found = Some(NonStructuralMatchTy::Dynamic);
return true; // Stop visiting.
}
ty::RawPtr(..) => {
// structural-match ignores substructure of
// `*const _`/`*mut _`, so skip `super_visit_with`.
Expand Down
5 changes: 3 additions & 2 deletions src/libstd/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,9 @@ pub trait Read {
/// Like `read`, except that it reads into a slice of buffers.
///
/// Data is copied to fill each buffer in order, with the final buffer
/// written to possibly being only partially filled. This method must behave
/// as a single call to `read` with the buffers concatenated would.
/// written to possibly being only partially filled. This method must
/// behave equivalently to a single call to `read` with concatenated
/// buffers.
///
/// The default implementation calls `read` with either the first nonempty
/// buffer provided, or an empty one if none exists.
Expand Down
15 changes: 15 additions & 0 deletions src/test/ui/const-generics/issues/issue-63322-forbid-dyn.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#![feature(const_generics)]
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash

trait A {}
struct B;
impl A for B {}

fn test<const T: &'static dyn A>() {
//~^ ERROR the types of const generic parameters must derive `PartialEq` and `Eq`
unimplemented!()
}

fn main() {
test::<{ &B }>();
}
17 changes: 17 additions & 0 deletions src/test/ui/const-generics/issues/issue-63322-forbid-dyn.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
--> $DIR/issue-63322-forbid-dyn.rs:1:12
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default

error[E0741]: the types of const generic parameters must derive `PartialEq` and `Eq`
--> $DIR/issue-63322-forbid-dyn.rs:8:18
|
LL | fn test<const T: &'static dyn A>() {
| ^^^^^^^^^^^^^^ `&'static (dyn A + 'static)` doesn't derive both `PartialEq` and `Eq`

error: aborting due to previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0741`.
18 changes: 18 additions & 0 deletions src/test/ui/const-generics/issues/issue-69654.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#![feature(const_generics)]
#![allow(incomplete_features)]

trait Bar<O> {}
impl<O> Bar<O> for [u8; O] {}
//~^ ERROR expected value, found type parameter `O`

struct Foo<const O: usize> {}
impl<const O: usize> Foo<O>
where
[u8; O]: Bar<[(); O]>,
{
fn foo() {}
}

fn main() {
Foo::foo();
}
14 changes: 14 additions & 0 deletions src/test/ui/const-generics/issues/issue-69654.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0423]: expected value, found type parameter `O`
--> $DIR/issue-69654.rs:5:25
|
LL | impl<O> Bar<O> for [u8; O] {}
| ^ help: a tuple variant with a similar name exists: `Ok`
|
::: $SRC_DIR/libcore/result.rs:LL:COL
|
LL | Ok(#[stable(feature = "rust1", since = "1.0.0")] T),
| --------------------------------------------------- similarly named tuple variant `Ok` defined here

error: aborting due to previous error

For more information about this error, try `rustc --explain E0423`.
10 changes: 10 additions & 0 deletions src/test/ui/match/issue-70972-dyn-trait.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const F: &'static dyn Send = &7u32;

fn main() {
let a: &dyn Send = &7u32;
match a {
F => panic!(),
//~^ ERROR trait objects cannot be used in patterns
_ => {}
}
}
8 changes: 8 additions & 0 deletions src/test/ui/match/issue-70972-dyn-trait.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: trait objects cannot be used in patterns
--> $DIR/issue-70972-dyn-trait.rs:6:9
|
LL | F => panic!(),
| ^

error: aborting due to previous error

18 changes: 18 additions & 0 deletions src/test/ui/process-termination/process-termination-blocking-io.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// program should terminate even if a thread is blocked on I/O.
// https://github.com/fortanix/rust-sgx/issues/109

// run-pass

use std::{net::TcpListener, sync::mpsc, thread};

fn main() {
let (tx, rx) = mpsc::channel();
thread::spawn(move || {
let listen = TcpListener::bind("0:0").unwrap();
tx.send(()).unwrap();
while let Ok(_) = listen.accept() {}
});
rx.recv().unwrap();
for _ in 0..3 { thread::yield_now(); }
println!("Exiting main thread");
}
12 changes: 12 additions & 0 deletions src/test/ui/process-termination/process-termination-simple.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// program should terminate when std::process::exit is called from any thread

// run-pass

use std::{process, thread};

fn main() {
let h = thread::spawn(|| {
process::exit(0);
});
let _ = h.join();
}