Skip to content

Commit

Permalink
Auto merge of #59922 - Centril:rollup-0qmx4jg, r=Centril
Browse files Browse the repository at this point in the history
Rollup of 8 pull requests

Successful merges:

 - #59781 (Remove check_match from const_eval)
 - #59820 (proc_macro: stop using LEB128 for RPC.)
 - #59846 (clarify what the item is in "not a module" error)
 - #59847 (Error when using `catch` after `try`)
 - #59859 (Suggest removing `?` to resolve type errors.)
 - #59862 (Tweak unstable diagnostic output)
 - #59866 (Recover from missing semicolon based on the found token)
 - #59892 (Impl RawFd conversion traits for WASI TcpListener, TcpStream and UdpSocket)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Apr 13, 2019
2 parents 99da733 + ba17313 commit aa35e73
Show file tree
Hide file tree
Showing 211 changed files with 1,327 additions and 631 deletions.
36 changes: 13 additions & 23 deletions src/libproc_macro/bridge/rpc.rs
Expand Up @@ -24,32 +24,22 @@ pub(super) trait DecodeMut<'a, 's, S>: Sized {
}

macro_rules! rpc_encode_decode {
(uleb128 $ty:ty) => {
(le $ty:ty) => {
impl<S> Encode<S> for $ty {
fn encode(mut self, w: &mut Writer, s: &mut S) {
let mut byte = 0x80;
while byte & 0x80 != 0 {
byte = (self & 0x7f) as u8;
self >>= 7;
if self != 0 {
byte |= 0x80;
}
byte.encode(w, s);
}
fn encode(self, w: &mut Writer, _: &mut S) {
w.write_all(&self.to_le_bytes()).unwrap();
}
}

impl<S> DecodeMut<'_, '_, S> for $ty {
fn decode(r: &mut Reader<'_>, s: &mut S) -> Self {
let mut byte = 0x80;
let mut v = 0;
let mut shift = 0;
while byte & 0x80 != 0 {
byte = u8::decode(r, s);
v |= ((byte & 0x7f) as Self) << shift;
shift += 7;
}
v
fn decode(r: &mut Reader<'_>, _: &mut S) -> Self {
const N: usize = ::std::mem::size_of::<$ty>();

let mut bytes = [0; N];
bytes.copy_from_slice(&r[..N]);
*r = &r[N..];

Self::from_le_bytes(bytes)
}
}
};
Expand Down Expand Up @@ -136,8 +126,8 @@ impl<S> DecodeMut<'_, '_, S> for u8 {
}
}

rpc_encode_decode!(uleb128 u32);
rpc_encode_decode!(uleb128 usize);
rpc_encode_decode!(le u32);
rpc_encode_decode!(le usize);

impl<S> Encode<S> for bool {
fn encode(self, w: &mut Writer, s: &mut S) {
Expand Down
28 changes: 27 additions & 1 deletion src/librustc/infer/error_reporting/mod.rs
Expand Up @@ -604,13 +604,39 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
source,
ref prior_arms,
last_ty,
discrim_hir_id,
..
} => match source {
hir::MatchSource::IfLetDesugar { .. } => {
let msg = "`if let` arms have incompatible types";
err.span_label(cause.span, msg);
}
hir::MatchSource::TryDesugar => {}
hir::MatchSource::TryDesugar => {
if let Some(ty::error::ExpectedFound { expected, .. }) = exp_found {
let discrim_expr = self.tcx.hir().expect_expr_by_hir_id(discrim_hir_id);
let discrim_ty = if let hir::ExprKind::Call(_, args) = &discrim_expr.node {
let arg_expr = args.first().expect("try desugaring call w/out arg");
self.in_progress_tables.and_then(|tables| {
tables.borrow().expr_ty_opt(arg_expr)
})
} else {
bug!("try desugaring w/out call expr as discriminant");
};

match discrim_ty {
Some(ty) if expected == ty => {
let source_map = self.tcx.sess.source_map();
err.span_suggestion(
source_map.end_point(cause.span),
"try removing this `?`",
"".to_string(),
Applicability::MachineApplicable,
);
},
_ => {},
}
}
}
_ => {
let msg = "`match` arms have incompatible types";
err.span_label(cause.span, msg);
Expand Down
1 change: 1 addition & 0 deletions src/librustc/traits/mod.rs
Expand Up @@ -226,6 +226,7 @@ pub enum ObligationCauseCode<'tcx> {
source: hir::MatchSource,
prior_arms: Vec<Span>,
last_ty: Ty<'tcx>,
discrim_hir_id: hir::HirId,
},

/// Computing common supertype in the pattern guard for the arms of a match expression
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/traits/structural_impls.rs
Expand Up @@ -519,13 +519,15 @@ impl<'a, 'tcx> Lift<'tcx> for traits::ObligationCauseCode<'a> {
source,
ref prior_arms,
last_ty,
discrim_hir_id,
} => {
tcx.lift(&last_ty).map(|last_ty| {
super::MatchExpressionArm {
arm_span,
source,
prior_arms: prior_arms.clone(),
last_ty,
discrim_hir_id,
}
})
}
Expand Down
19 changes: 3 additions & 16 deletions src/librustc_mir/const_eval.rs
Expand Up @@ -615,22 +615,9 @@ pub fn const_eval_raw_provider<'a, 'tcx>(
let cid = key.value;
let def_id = cid.instance.def.def_id();

if let Some(id) = tcx.hir().as_local_hir_id(def_id) {
let tables = tcx.typeck_tables_of(def_id);

// Do match-check before building MIR
// FIXME(#59378) check_match may have errored but we're not checking for that anymore
tcx.check_match(def_id);

if let hir::BodyOwnerKind::Const = tcx.hir().body_owner_kind_by_hir_id(id) {
tcx.mir_const_qualif(def_id);
}

// Do not continue into miri if typeck errors occurred; it will fail horribly
if tables.tainted_by_errors {
return Err(ErrorHandled::Reported)
}
};
if def_id.is_local() && tcx.typeck_tables_of(def_id).tainted_by_errors {
return Err(ErrorHandled::Reported);
}

let (res, ecx) = eval_body_and_ecx(tcx, cid, None, key.param_env);
res.and_then(|place| {
Expand Down
9 changes: 8 additions & 1 deletion src/librustc_resolve/lib.rs
Expand Up @@ -3731,9 +3731,16 @@ impl<'a> Resolver<'a> {
def, path.len() - i - 1
));
} else {
let label = format!(
"`{}` is {} {}, not a module",
ident,
def.article(),
def.kind_name(),
);

return PathResult::Failed {
span: ident.span,
label: format!("not a module `{}`", ident),
label,
suggestion: None,
is_error_from_last_segment: is_last,
};
Expand Down
1 change: 1 addition & 0 deletions src/librustc_typeck/check/_match.rs
Expand Up @@ -732,6 +732,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
source: match_src,
prior_arms: other_arms.clone(),
last_ty: prior_arm_ty.unwrap(),
discrim_hir_id: discrim.hir_id,
})
};
coercion.coerce(self, &cause, &arm.body, arm_ty);
Expand Down
55 changes: 55 additions & 0 deletions src/libstd/sys/wasi/ext/io.rs
Expand Up @@ -5,6 +5,7 @@
use crate::fs;
use crate::io;
use crate::sys;
use crate::net;
use crate::sys_common::{AsInner, FromInner, IntoInner};

/// Raw file descriptors.
Expand Down Expand Up @@ -50,6 +51,60 @@ pub trait IntoRawFd {
fn into_raw_fd(self) -> RawFd;
}

impl AsRawFd for net::TcpStream {
fn as_raw_fd(&self) -> RawFd {
self.as_inner().fd().as_raw()
}
}

impl FromRawFd for net::TcpStream {
unsafe fn from_raw_fd(fd: RawFd) -> net::TcpStream {
net::TcpStream::from_inner(sys::net::TcpStream::from_inner(fd))
}
}

impl IntoRawFd for net::TcpStream {
fn into_raw_fd(self) -> RawFd {
self.into_inner().into_fd().into_raw()
}
}

impl AsRawFd for net::TcpListener {
fn as_raw_fd(&self) -> RawFd {
self.as_inner().fd().as_raw()
}
}

impl FromRawFd for net::TcpListener {
unsafe fn from_raw_fd(fd: RawFd) -> net::TcpListener {
net::TcpListener::from_inner(sys::net::TcpListener::from_inner(fd))
}
}

impl IntoRawFd for net::TcpListener {
fn into_raw_fd(self) -> RawFd {
self.into_inner().into_fd().into_raw()
}
}

impl AsRawFd for net::UdpSocket {
fn as_raw_fd(&self) -> RawFd {
self.as_inner().fd().as_raw()
}
}

impl FromRawFd for net::UdpSocket {
unsafe fn from_raw_fd(fd: RawFd) -> net::UdpSocket {
net::UdpSocket::from_inner(sys::net::UdpSocket::from_inner(fd))
}
}

impl IntoRawFd for net::UdpSocket {
fn into_raw_fd(self) -> RawFd {
self.into_inner().into_fd().into_raw()
}
}

impl AsRawFd for fs::File {
fn as_raw_fd(&self) -> RawFd {
self.as_inner().fd().as_raw()
Expand Down

0 comments on commit aa35e73

Please sign in to comment.