Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2430c48

Browse files
committedJul 21, 2024
Auto merge of rust-lang#128011 - matthiaskrgr:rollup-0vmf75y, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#127720 ([`macro_metavar_expr_concat`] Allow `concat` in repetitions) - rust-lang#127734 (Windows: move BSD socket shims to netc) - rust-lang#127752 (Ignore allocation bytes in one more mir-opt test) - rust-lang#127839 (Fix git safe-directory path for docker images) - rust-lang#127867 (Add `wasm32-wasip2` to `build-manifest` tool) - rust-lang#127958 (Cleanup rmake.rs setup in compiletest) - rust-lang#127975 (Fix trait bounds display) - rust-lang#128005 (Remove _tls_used hack) r? `@ghost` `@rustbot` modify labels: rollup
2 parents c1a631d + 8fe93c9 commit 2430c48

File tree

19 files changed

+458
-280
lines changed

19 files changed

+458
-280
lines changed
 

‎compiler/rustc_expand/src/mbe/macro_check.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -352,10 +352,10 @@ fn check_occurrences(
352352
check_ops_is_prefix(psess, node_id, macros, binders, ops, span, name);
353353
}
354354
TokenTree::MetaVarExpr(dl, ref mve) => {
355-
let Some(name) = mve.ident().map(MacroRulesNormalizedIdent::new) else {
356-
return;
357-
};
358-
check_ops_is_prefix(psess, node_id, macros, binders, ops, dl.entire(), name);
355+
mve.for_each_metavar((), |_, ident| {
356+
let name = MacroRulesNormalizedIdent::new(*ident);
357+
check_ops_is_prefix(psess, node_id, macros, binders, ops, dl.entire(), name);
358+
});
359359
}
360360
TokenTree::Delimited(.., ref del) => {
361361
check_nested_occurrences(psess, node_id, &del.tts, macros, binders, ops, guar);

‎compiler/rustc_expand/src/mbe/metavar_expr.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,18 @@ impl MetaVarExpr {
111111
Ok(rslt)
112112
}
113113

114-
pub(crate) fn ident(&self) -> Option<Ident> {
115-
match *self {
116-
MetaVarExpr::Count(ident, _) | MetaVarExpr::Ignore(ident) => Some(ident),
117-
MetaVarExpr::Concat { .. } | MetaVarExpr::Index(..) | MetaVarExpr::Len(..) => None,
114+
pub(crate) fn for_each_metavar<A>(&self, mut aux: A, mut cb: impl FnMut(A, &Ident) -> A) -> A {
115+
match self {
116+
MetaVarExpr::Concat(elems) => {
117+
for elem in elems {
118+
if let MetaVarExprConcatElem::Var(ident) = elem {
119+
aux = cb(aux, ident)
120+
}
121+
}
122+
aux
123+
}
124+
MetaVarExpr::Count(ident, _) | MetaVarExpr::Ignore(ident) => cb(aux, ident),
125+
MetaVarExpr::Index(..) | MetaVarExpr::Len(..) => aux,
118126
}
119127
}
120128
}

‎compiler/rustc_expand/src/mbe/transcribe.rs

+56-37
Original file line numberDiff line numberDiff line change
@@ -557,17 +557,13 @@ fn lockstep_iter_size(
557557
}
558558
}
559559
TokenTree::MetaVarExpr(_, expr) => {
560-
let default_rslt = LockstepIterSize::Unconstrained;
561-
let Some(ident) = expr.ident() else {
562-
return default_rslt;
563-
};
564-
let name = MacroRulesNormalizedIdent::new(ident);
565-
match lookup_cur_matched(name, interpolations, repeats) {
566-
Some(MatchedSeq(ads)) => {
567-
default_rslt.with(LockstepIterSize::Constraint(ads.len(), name))
568-
}
569-
_ => default_rslt,
570-
}
560+
expr.for_each_metavar(LockstepIterSize::Unconstrained, |lis, ident| {
561+
lis.with(lockstep_iter_size(
562+
&TokenTree::MetaVar(ident.span, *ident),
563+
interpolations,
564+
repeats,
565+
))
566+
})
571567
}
572568
TokenTree::Token(..) => LockstepIterSize::Unconstrained,
573569
}
@@ -695,7 +691,23 @@ fn transcribe_metavar_expr<'a>(
695691
let symbol = match element {
696692
MetaVarExprConcatElem::Ident(elem) => elem.name,
697693
MetaVarExprConcatElem::Literal(elem) => *elem,
698-
MetaVarExprConcatElem::Var(elem) => extract_var_symbol(dcx, *elem, interp)?,
694+
MetaVarExprConcatElem::Var(ident) => {
695+
match matched_from_ident(dcx, *ident, interp)? {
696+
NamedMatch::MatchedSeq(named_matches) => {
697+
let curr_idx = repeats.last().unwrap().0;
698+
match &named_matches[curr_idx] {
699+
// FIXME(c410-f3r) Nested repetitions are unimplemented
700+
MatchedSeq(_) => unimplemented!(),
701+
MatchedSingle(pnr) => {
702+
extract_symbol_from_pnr(dcx, pnr, ident.span)?
703+
}
704+
}
705+
}
706+
NamedMatch::MatchedSingle(pnr) => {
707+
extract_symbol_from_pnr(dcx, pnr, ident.span)?
708+
}
709+
}
710+
}
699711
};
700712
concatenated.push_str(symbol.as_str());
701713
}
@@ -752,41 +764,48 @@ fn transcribe_metavar_expr<'a>(
752764
}
753765

754766
/// Extracts an metavariable symbol that can be an identifier, a token tree or a literal.
755-
fn extract_var_symbol<'a>(
767+
fn extract_symbol_from_pnr<'a>(
756768
dcx: DiagCtxtHandle<'a>,
757-
ident: Ident,
758-
interp: &FxHashMap<MacroRulesNormalizedIdent, NamedMatch>,
769+
pnr: &ParseNtResult,
770+
span_err: Span,
759771
) -> PResult<'a, Symbol> {
760-
if let NamedMatch::MatchedSingle(pnr) = matched_from_ident(dcx, ident, interp)? {
761-
if let ParseNtResult::Ident(nt_ident, is_raw) = pnr {
772+
match pnr {
773+
ParseNtResult::Ident(nt_ident, is_raw) => {
762774
if let IdentIsRaw::Yes = is_raw {
763-
return Err(dcx.struct_span_err(ident.span, RAW_IDENT_ERR));
775+
return Err(dcx.struct_span_err(span_err, RAW_IDENT_ERR));
764776
}
765777
return Ok(nt_ident.name);
766778
}
767-
768-
if let ParseNtResult::Tt(TokenTree::Token(Token { kind, .. }, _)) = pnr {
769-
if let TokenKind::Ident(symbol, is_raw) = kind {
770-
if let IdentIsRaw::Yes = is_raw {
771-
return Err(dcx.struct_span_err(ident.span, RAW_IDENT_ERR));
772-
}
773-
return Ok(*symbol);
774-
}
775-
776-
if let TokenKind::Literal(Lit { kind: LitKind::Str, symbol, suffix: None }) = kind {
777-
return Ok(*symbol);
779+
ParseNtResult::Tt(TokenTree::Token(
780+
Token { kind: TokenKind::Ident(symbol, is_raw), .. },
781+
_,
782+
)) => {
783+
if let IdentIsRaw::Yes = is_raw {
784+
return Err(dcx.struct_span_err(span_err, RAW_IDENT_ERR));
778785
}
786+
return Ok(*symbol);
779787
}
780-
781-
if let ParseNtResult::Nt(nt) = pnr
782-
&& let Nonterminal::NtLiteral(expr) = &**nt
783-
&& let ExprKind::Lit(Lit { kind: LitKind::Str, symbol, suffix: None }) = &expr.kind
788+
ParseNtResult::Tt(TokenTree::Token(
789+
Token {
790+
kind: TokenKind::Literal(Lit { kind: LitKind::Str, symbol, suffix: None }),
791+
..
792+
},
793+
_,
794+
)) => {
795+
return Ok(*symbol);
796+
}
797+
ParseNtResult::Nt(nt)
798+
if let Nonterminal::NtLiteral(expr) = &**nt
799+
&& let ExprKind::Lit(Lit { kind: LitKind::Str, symbol, suffix: None }) =
800+
&expr.kind =>
784801
{
785802
return Ok(*symbol);
786803
}
804+
_ => Err(dcx
805+
.struct_err(
806+
"metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt`",
807+
)
808+
.with_note("currently only string literals are supported")
809+
.with_span(span_err)),
787810
}
788-
Err(dcx
789-
.struct_err("metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt`")
790-
.with_note("currently only string literals are supported")
791-
.with_span(ident.span))
792811
}

‎library/std/src/sys/pal/windows/c.rs

+1-96
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
use crate::ffi::CStr;
1010
use crate::mem;
11-
use crate::os::raw::{c_char, c_int, c_uint, c_ulong, c_ushort, c_void};
11+
use crate::os::raw::{c_uint, c_ulong, c_ushort, c_void};
1212
use crate::os::windows::io::{AsRawHandle, BorrowedHandle};
1313
use crate::ptr;
1414

@@ -19,12 +19,6 @@ pub use windows_sys::*;
1919

2020
pub type WCHAR = u16;
2121

22-
pub type socklen_t = c_int;
23-
pub type ADDRESS_FAMILY = c_ushort;
24-
pub use FD_SET as fd_set;
25-
pub use LINGER as linger;
26-
pub use TIMEVAL as timeval;
27-
2822
pub const INVALID_HANDLE_VALUE: HANDLE = ::core::ptr::without_provenance_mut(-1i32 as _);
2923

3024
// https://learn.microsoft.com/en-us/cpp/c-runtime-library/exit-success-exit-failure?view=msvc-170
@@ -42,20 +36,6 @@ pub const INIT_ONCE_STATIC_INIT: INIT_ONCE = INIT_ONCE { Ptr: ptr::null_mut() };
4236
pub const OBJ_DONT_REPARSE: u32 = windows_sys::OBJ_DONT_REPARSE as u32;
4337
pub const FRS_ERR_SYSVOL_POPULATE_TIMEOUT: u32 =
4438
windows_sys::FRS_ERR_SYSVOL_POPULATE_TIMEOUT as u32;
45-
pub const AF_INET: c_int = windows_sys::AF_INET as c_int;
46-
pub const AF_INET6: c_int = windows_sys::AF_INET6 as c_int;
47-
48-
#[repr(C)]
49-
pub struct ip_mreq {
50-
pub imr_multiaddr: in_addr,
51-
pub imr_interface: in_addr,
52-
}
53-
54-
#[repr(C)]
55-
pub struct ipv6_mreq {
56-
pub ipv6mr_multiaddr: in6_addr,
57-
pub ipv6mr_interface: c_uint,
58-
}
5939

6040
// Equivalent to the `NT_SUCCESS` C preprocessor macro.
6141
// See: https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/using-ntstatus-values
@@ -127,45 +107,6 @@ pub struct MOUNT_POINT_REPARSE_BUFFER {
127107
pub PathBuffer: WCHAR,
128108
}
129109

130-
#[repr(C)]
131-
pub struct SOCKADDR_STORAGE_LH {
132-
pub ss_family: ADDRESS_FAMILY,
133-
pub __ss_pad1: [c_char; 6],
134-
pub __ss_align: i64,
135-
pub __ss_pad2: [c_char; 112],
136-
}
137-
138-
#[repr(C)]
139-
#[derive(Copy, Clone)]
140-
pub struct sockaddr_in {
141-
pub sin_family: ADDRESS_FAMILY,
142-
pub sin_port: c_ushort,
143-
pub sin_addr: in_addr,
144-
pub sin_zero: [c_char; 8],
145-
}
146-
147-
#[repr(C)]
148-
#[derive(Copy, Clone)]
149-
pub struct sockaddr_in6 {
150-
pub sin6_family: ADDRESS_FAMILY,
151-
pub sin6_port: c_ushort,
152-
pub sin6_flowinfo: c_ulong,
153-
pub sin6_addr: in6_addr,
154-
pub sin6_scope_id: c_ulong,
155-
}
156-
157-
#[repr(C)]
158-
#[derive(Copy, Clone)]
159-
pub struct in_addr {
160-
pub s_addr: u32,
161-
}
162-
163-
#[repr(C)]
164-
#[derive(Copy, Clone)]
165-
pub struct in6_addr {
166-
pub s6_addr: [u8; 16],
167-
}
168-
169110
// Desktop specific functions & types
170111
cfg_if::cfg_if! {
171112
if #[cfg(not(target_vendor = "uwp"))] {
@@ -205,42 +146,6 @@ pub unsafe extern "system" fn ReadFileEx(
205146
)
206147
}
207148

208-
// POSIX compatibility shims.
209-
pub unsafe fn recv(socket: SOCKET, buf: *mut c_void, len: c_int, flags: c_int) -> c_int {
210-
windows_sys::recv(socket, buf.cast::<u8>(), len, flags)
211-
}
212-
pub unsafe fn send(socket: SOCKET, buf: *const c_void, len: c_int, flags: c_int) -> c_int {
213-
windows_sys::send(socket, buf.cast::<u8>(), len, flags)
214-
}
215-
pub unsafe fn recvfrom(
216-
socket: SOCKET,
217-
buf: *mut c_void,
218-
len: c_int,
219-
flags: c_int,
220-
addr: *mut SOCKADDR,
221-
addrlen: *mut c_int,
222-
) -> c_int {
223-
windows_sys::recvfrom(socket, buf.cast::<u8>(), len, flags, addr, addrlen)
224-
}
225-
pub unsafe fn sendto(
226-
socket: SOCKET,
227-
buf: *const c_void,
228-
len: c_int,
229-
flags: c_int,
230-
addr: *const SOCKADDR,
231-
addrlen: c_int,
232-
) -> c_int {
233-
windows_sys::sendto(socket, buf.cast::<u8>(), len, flags, addr, addrlen)
234-
}
235-
pub unsafe fn getaddrinfo(
236-
node: *const c_char,
237-
service: *const c_char,
238-
hints: *const ADDRINFOA,
239-
res: *mut *mut ADDRINFOA,
240-
) -> c_int {
241-
windows_sys::getaddrinfo(node.cast::<u8>(), service.cast::<u8>(), hints, res)
242-
}
243-
244149
cfg_if::cfg_if! {
245150
if #[cfg(not(target_vendor = "uwp"))] {
246151
pub unsafe fn NtReadFile(

‎library/std/src/sys/pal/windows/c/bindings.txt

+1
Original file line numberDiff line numberDiff line change
@@ -2059,6 +2059,7 @@ Windows.Win32.Networking.WinSock.SOCK_RDM
20592059
Windows.Win32.Networking.WinSock.SOCK_SEQPACKET
20602060
Windows.Win32.Networking.WinSock.SOCK_STREAM
20612061
Windows.Win32.Networking.WinSock.SOCKADDR
2062+
Windows.Win32.Networking.WinSock.SOCKADDR_STORAGE
20622063
Windows.Win32.Networking.WinSock.SOCKADDR_UN
20632064
Windows.Win32.Networking.WinSock.SOCKET
20642065
Windows.Win32.Networking.WinSock.SOCKET_ERROR

‎library/std/src/sys/pal/windows/c/windows_sys.rs

+8
Original file line numberDiff line numberDiff line change
@@ -2890,6 +2890,14 @@ pub struct SOCKADDR {
28902890
}
28912891
#[repr(C)]
28922892
#[derive(Clone, Copy)]
2893+
pub struct SOCKADDR_STORAGE {
2894+
pub ss_family: ADDRESS_FAMILY,
2895+
pub __ss_pad1: [i8; 6],
2896+
pub __ss_align: i64,
2897+
pub __ss_pad2: [i8; 112],
2898+
}
2899+
#[repr(C)]
2900+
#[derive(Clone, Copy)]
28932901
pub struct SOCKADDR_UN {
28942902
pub sun_family: ADDRESS_FAMILY,
28952903
pub sun_path: [i8; 108],
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.