Skip to content

Commit aa35e73

Browse files
committed
Auto merge of #59922 - Centril:rollup-0qmx4jg, r=Centril
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
2 parents 99da733 + ba17313 commit aa35e73

File tree

211 files changed

+1327
-631
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

211 files changed

+1327
-631
lines changed

src/libproc_macro/bridge/rpc.rs

+13-23
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,22 @@ pub(super) trait DecodeMut<'a, 's, S>: Sized {
2424
}
2525

2626
macro_rules! rpc_encode_decode {
27-
(uleb128 $ty:ty) => {
27+
(le $ty:ty) => {
2828
impl<S> Encode<S> for $ty {
29-
fn encode(mut self, w: &mut Writer, s: &mut S) {
30-
let mut byte = 0x80;
31-
while byte & 0x80 != 0 {
32-
byte = (self & 0x7f) as u8;
33-
self >>= 7;
34-
if self != 0 {
35-
byte |= 0x80;
36-
}
37-
byte.encode(w, s);
38-
}
29+
fn encode(self, w: &mut Writer, _: &mut S) {
30+
w.write_all(&self.to_le_bytes()).unwrap();
3931
}
4032
}
4133

4234
impl<S> DecodeMut<'_, '_, S> for $ty {
43-
fn decode(r: &mut Reader<'_>, s: &mut S) -> Self {
44-
let mut byte = 0x80;
45-
let mut v = 0;
46-
let mut shift = 0;
47-
while byte & 0x80 != 0 {
48-
byte = u8::decode(r, s);
49-
v |= ((byte & 0x7f) as Self) << shift;
50-
shift += 7;
51-
}
52-
v
35+
fn decode(r: &mut Reader<'_>, _: &mut S) -> Self {
36+
const N: usize = ::std::mem::size_of::<$ty>();
37+
38+
let mut bytes = [0; N];
39+
bytes.copy_from_slice(&r[..N]);
40+
*r = &r[N..];
41+
42+
Self::from_le_bytes(bytes)
5343
}
5444
}
5545
};
@@ -136,8 +126,8 @@ impl<S> DecodeMut<'_, '_, S> for u8 {
136126
}
137127
}
138128

139-
rpc_encode_decode!(uleb128 u32);
140-
rpc_encode_decode!(uleb128 usize);
129+
rpc_encode_decode!(le u32);
130+
rpc_encode_decode!(le usize);
141131

142132
impl<S> Encode<S> for bool {
143133
fn encode(self, w: &mut Writer, s: &mut S) {

src/librustc/infer/error_reporting/mod.rs

+27-1
Original file line numberDiff line numberDiff line change
@@ -604,13 +604,39 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
604604
source,
605605
ref prior_arms,
606606
last_ty,
607+
discrim_hir_id,
607608
..
608609
} => match source {
609610
hir::MatchSource::IfLetDesugar { .. } => {
610611
let msg = "`if let` arms have incompatible types";
611612
err.span_label(cause.span, msg);
612613
}
613-
hir::MatchSource::TryDesugar => {}
614+
hir::MatchSource::TryDesugar => {
615+
if let Some(ty::error::ExpectedFound { expected, .. }) = exp_found {
616+
let discrim_expr = self.tcx.hir().expect_expr_by_hir_id(discrim_hir_id);
617+
let discrim_ty = if let hir::ExprKind::Call(_, args) = &discrim_expr.node {
618+
let arg_expr = args.first().expect("try desugaring call w/out arg");
619+
self.in_progress_tables.and_then(|tables| {
620+
tables.borrow().expr_ty_opt(arg_expr)
621+
})
622+
} else {
623+
bug!("try desugaring w/out call expr as discriminant");
624+
};
625+
626+
match discrim_ty {
627+
Some(ty) if expected == ty => {
628+
let source_map = self.tcx.sess.source_map();
629+
err.span_suggestion(
630+
source_map.end_point(cause.span),
631+
"try removing this `?`",
632+
"".to_string(),
633+
Applicability::MachineApplicable,
634+
);
635+
},
636+
_ => {},
637+
}
638+
}
639+
}
614640
_ => {
615641
let msg = "`match` arms have incompatible types";
616642
err.span_label(cause.span, msg);

src/librustc/traits/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ pub enum ObligationCauseCode<'tcx> {
226226
source: hir::MatchSource,
227227
prior_arms: Vec<Span>,
228228
last_ty: Ty<'tcx>,
229+
discrim_hir_id: hir::HirId,
229230
},
230231

231232
/// Computing common supertype in the pattern guard for the arms of a match expression

src/librustc/traits/structural_impls.rs

+2
Original file line numberDiff line numberDiff line change
@@ -519,13 +519,15 @@ impl<'a, 'tcx> Lift<'tcx> for traits::ObligationCauseCode<'a> {
519519
source,
520520
ref prior_arms,
521521
last_ty,
522+
discrim_hir_id,
522523
} => {
523524
tcx.lift(&last_ty).map(|last_ty| {
524525
super::MatchExpressionArm {
525526
arm_span,
526527
source,
527528
prior_arms: prior_arms.clone(),
528529
last_ty,
530+
discrim_hir_id,
529531
}
530532
})
531533
}

src/librustc_mir/const_eval.rs

+3-16
Original file line numberDiff line numberDiff line change
@@ -615,22 +615,9 @@ pub fn const_eval_raw_provider<'a, 'tcx>(
615615
let cid = key.value;
616616
let def_id = cid.instance.def.def_id();
617617

618-
if let Some(id) = tcx.hir().as_local_hir_id(def_id) {
619-
let tables = tcx.typeck_tables_of(def_id);
620-
621-
// Do match-check before building MIR
622-
// FIXME(#59378) check_match may have errored but we're not checking for that anymore
623-
tcx.check_match(def_id);
624-
625-
if let hir::BodyOwnerKind::Const = tcx.hir().body_owner_kind_by_hir_id(id) {
626-
tcx.mir_const_qualif(def_id);
627-
}
628-
629-
// Do not continue into miri if typeck errors occurred; it will fail horribly
630-
if tables.tainted_by_errors {
631-
return Err(ErrorHandled::Reported)
632-
}
633-
};
618+
if def_id.is_local() && tcx.typeck_tables_of(def_id).tainted_by_errors {
619+
return Err(ErrorHandled::Reported);
620+
}
634621

635622
let (res, ecx) = eval_body_and_ecx(tcx, cid, None, key.param_env);
636623
res.and_then(|place| {

src/librustc_resolve/lib.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -3731,9 +3731,16 @@ impl<'a> Resolver<'a> {
37313731
def, path.len() - i - 1
37323732
));
37333733
} else {
3734+
let label = format!(
3735+
"`{}` is {} {}, not a module",
3736+
ident,
3737+
def.article(),
3738+
def.kind_name(),
3739+
);
3740+
37343741
return PathResult::Failed {
37353742
span: ident.span,
3736-
label: format!("not a module `{}`", ident),
3743+
label,
37373744
suggestion: None,
37383745
is_error_from_last_segment: is_last,
37393746
};

src/librustc_typeck/check/_match.rs

+1
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
732732
source: match_src,
733733
prior_arms: other_arms.clone(),
734734
last_ty: prior_arm_ty.unwrap(),
735+
discrim_hir_id: discrim.hir_id,
735736
})
736737
};
737738
coercion.coerce(self, &cause, &arm.body, arm_ty);

src/libstd/sys/wasi/ext/io.rs

+55
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use crate::fs;
66
use crate::io;
77
use crate::sys;
8+
use crate::net;
89
use crate::sys_common::{AsInner, FromInner, IntoInner};
910

1011
/// Raw file descriptors.
@@ -50,6 +51,60 @@ pub trait IntoRawFd {
5051
fn into_raw_fd(self) -> RawFd;
5152
}
5253

54+
impl AsRawFd for net::TcpStream {
55+
fn as_raw_fd(&self) -> RawFd {
56+
self.as_inner().fd().as_raw()
57+
}
58+
}
59+
60+
impl FromRawFd for net::TcpStream {
61+
unsafe fn from_raw_fd(fd: RawFd) -> net::TcpStream {
62+
net::TcpStream::from_inner(sys::net::TcpStream::from_inner(fd))
63+
}
64+
}
65+
66+
impl IntoRawFd for net::TcpStream {
67+
fn into_raw_fd(self) -> RawFd {
68+
self.into_inner().into_fd().into_raw()
69+
}
70+
}
71+
72+
impl AsRawFd for net::TcpListener {
73+
fn as_raw_fd(&self) -> RawFd {
74+
self.as_inner().fd().as_raw()
75+
}
76+
}
77+
78+
impl FromRawFd for net::TcpListener {
79+
unsafe fn from_raw_fd(fd: RawFd) -> net::TcpListener {
80+
net::TcpListener::from_inner(sys::net::TcpListener::from_inner(fd))
81+
}
82+
}
83+
84+
impl IntoRawFd for net::TcpListener {
85+
fn into_raw_fd(self) -> RawFd {
86+
self.into_inner().into_fd().into_raw()
87+
}
88+
}
89+
90+
impl AsRawFd for net::UdpSocket {
91+
fn as_raw_fd(&self) -> RawFd {
92+
self.as_inner().fd().as_raw()
93+
}
94+
}
95+
96+
impl FromRawFd for net::UdpSocket {
97+
unsafe fn from_raw_fd(fd: RawFd) -> net::UdpSocket {
98+
net::UdpSocket::from_inner(sys::net::UdpSocket::from_inner(fd))
99+
}
100+
}
101+
102+
impl IntoRawFd for net::UdpSocket {
103+
fn into_raw_fd(self) -> RawFd {
104+
self.into_inner().into_fd().into_raw()
105+
}
106+
}
107+
53108
impl AsRawFd for fs::File {
54109
fn as_raw_fd(&self) -> RawFd {
55110
self.as_inner().fd().as_raw()

0 commit comments

Comments
 (0)