Skip to content

Commit 724ba7f

Browse files
committedOct 22, 2023
Auto merge of rust-lang#117041 - matthiaskrgr:rollup-b18h0ln, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - rust-lang#116985 (Use gdb.ValuePrinter tag class) - rust-lang#116989 (Skip test if Unix sockets are unsupported) - rust-lang#117034 (Don't crash on empty match in the `nonexhaustive_omitted_patterns` lint) - rust-lang#117037 (rustdoc book doc example error) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 3932c87 + 77d8a73 commit 724ba7f

File tree

5 files changed

+180
-152
lines changed

5 files changed

+180
-152
lines changed
 

‎compiler/rustc_mir_build/src/thir/pattern/usefulness.rs

+3
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,9 @@ fn collect_nonexhaustive_missing_variants<'p, 'tcx>(
884884
cx: &MatchCheckCtxt<'p, 'tcx>,
885885
column: &[&DeconstructedPat<'p, 'tcx>],
886886
) -> Vec<WitnessPat<'tcx>> {
887+
if column.is_empty() {
888+
return Vec::new();
889+
}
887890
let ty = column[0].ty();
888891
let pcx = &PatCtxt { cx, ty, span: DUMMY_SP, is_top_level: false };
889892

‎library/std/src/fs/tests.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -1717,7 +1717,7 @@ fn windows_unix_socket_exists() {
17171717
let tmp = tmpdir();
17181718
let socket_path = tmp.join("socket");
17191719

1720-
// std doesn't current support Unix sockets on Windows so manually create one here.
1720+
// std doesn't currently support Unix sockets on Windows so manually create one here.
17211721
net::init();
17221722
unsafe {
17231723
let socket = c::WSASocketW(
@@ -1728,7 +1728,16 @@ fn windows_unix_socket_exists() {
17281728
0,
17291729
c::WSA_FLAG_OVERLAPPED | c::WSA_FLAG_NO_HANDLE_INHERIT,
17301730
);
1731-
assert_ne!(socket, c::INVALID_SOCKET);
1731+
// AF_UNIX is not supported on earlier versions of Windows,
1732+
// so skip this test if it's unsupported and we're not in CI.
1733+
if socket == c::INVALID_SOCKET {
1734+
let error = c::WSAGetLastError();
1735+
if env::var_os("CI").is_none() && error == c::WSAEAFNOSUPPORT {
1736+
return;
1737+
} else {
1738+
panic!("Creating AF_UNIX socket failed (OS error {error})");
1739+
}
1740+
}
17321741
let mut addr = c::SOCKADDR_UN { sun_family: c::AF_UNIX, sun_path: mem::zeroed() };
17331742
let bytes = socket_path.as_os_str().as_encoded_bytes();
17341743
addr.sun_path[..bytes.len()].copy_from_slice(bytes);

‎src/doc/rustdoc/src/write-documentation/what-to-include.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ and your test suite, this example needs some additional code:
7373
``````text
7474
/// Example
7575
/// ```rust
76-
/// # main() -> Result<(), std::num::ParseIntError> {
76+
/// # fn main() -> Result<(), std::num::ParseIntError> {
7777
/// let fortytwo = "42".parse::<u32>()?;
7878
/// println!("{} + 10 = {}", fortytwo, fortytwo+10);
7979
/// # Ok(())

‎src/etc/gdb_providers.py

+158-149
Original file line numberDiff line numberDiff line change
@@ -18,70 +18,79 @@ def unwrap_unique_or_non_null(unique_or_nonnull):
1818
return ptr if ptr.type.code == gdb.TYPE_CODE_PTR else ptr[ptr.type.fields()[0]]
1919

2020

21-
class EnumProvider:
21+
# GDB 14 has a tag class that indicates that extension methods are ok
22+
# to call. Use of this tag only requires that printers hide local
23+
# attributes and methods by prefixing them with "_".
24+
if hasattr(gdb, 'ValuePrinter'):
25+
printer_base = gdb.ValuePrinter
26+
else:
27+
printer_base = object
28+
29+
30+
class EnumProvider(printer_base):
2231
def __init__(self, valobj):
2332
content = valobj[valobj.type.fields()[0]]
2433
fields = content.type.fields()
25-
self.empty = len(fields) == 0
26-
if not self.empty:
34+
self._empty = len(fields) == 0
35+
if not self._empty:
2736
if len(fields) == 1:
2837
discriminant = 0
2938
else:
3039
discriminant = int(content[fields[0]]) + 1
31-
self.active_variant = content[fields[discriminant]]
32-
self.name = fields[discriminant].name
33-
self.full_name = "{}::{}".format(valobj.type.name, self.name)
40+
self._active_variant = content[fields[discriminant]]
41+
self._name = fields[discriminant].name
42+
self._full_name = "{}::{}".format(valobj.type.name, self._name)
3443
else:
35-
self.full_name = valobj.type.name
44+
self._full_name = valobj.type.name
3645

3746
def to_string(self):
38-
return self.full_name
47+
return self._full_name
3948

4049
def children(self):
41-
if not self.empty:
42-
yield self.name, self.active_variant
50+
if not self._empty:
51+
yield self._name, self._active_variant
4352

4453

45-
class StdStringProvider:
54+
class StdStringProvider(printer_base):
4655
def __init__(self, valobj):
47-
self.valobj = valobj
56+
self._valobj = valobj
4857
vec = valobj["vec"]
49-
self.length = int(vec["len"])
50-
self.data_ptr = unwrap_unique_or_non_null(vec["buf"]["ptr"])
58+
self._length = int(vec["len"])
59+
self._data_ptr = unwrap_unique_or_non_null(vec["buf"]["ptr"])
5160

5261
def to_string(self):
53-
return self.data_ptr.lazy_string(encoding="utf-8", length=self.length)
62+
return self._data_ptr.lazy_string(encoding="utf-8", length=self._length)
5463

5564
@staticmethod
5665
def display_hint():
5766
return "string"
5867

5968

60-
class StdOsStringProvider:
69+
class StdOsStringProvider(printer_base):
6170
def __init__(self, valobj):
62-
self.valobj = valobj
63-
buf = self.valobj["inner"]["inner"]
71+
self._valobj = valobj
72+
buf = self._valobj["inner"]["inner"]
6473
is_windows = "Wtf8Buf" in buf.type.name
6574
vec = buf[ZERO_FIELD] if is_windows else buf
6675

67-
self.length = int(vec["len"])
68-
self.data_ptr = unwrap_unique_or_non_null(vec["buf"]["ptr"])
76+
self._length = int(vec["len"])
77+
self._data_ptr = unwrap_unique_or_non_null(vec["buf"]["ptr"])
6978

7079
def to_string(self):
71-
return self.data_ptr.lazy_string(encoding="utf-8", length=self.length)
80+
return self._data_ptr.lazy_string(encoding="utf-8", length=self._length)
7281

7382
def display_hint(self):
7483
return "string"
7584

7685

77-
class StdStrProvider:
86+
class StdStrProvider(printer_base):
7887
def __init__(self, valobj):
79-
self.valobj = valobj
80-
self.length = int(valobj["length"])
81-
self.data_ptr = valobj["data_ptr"]
88+
self._valobj = valobj
89+
self._length = int(valobj["length"])
90+
self._data_ptr = valobj["data_ptr"]
8291

8392
def to_string(self):
84-
return self.data_ptr.lazy_string(encoding="utf-8", length=self.length)
93+
return self._data_ptr.lazy_string(encoding="utf-8", length=self._length)
8594

8695
@staticmethod
8796
def display_hint():
@@ -103,139 +112,139 @@ def _enumerate_array_elements(element_ptrs):
103112

104113
yield key, element
105114

106-
class StdSliceProvider:
115+
class StdSliceProvider(printer_base):
107116
def __init__(self, valobj):
108-
self.valobj = valobj
109-
self.length = int(valobj["length"])
110-
self.data_ptr = valobj["data_ptr"]
117+
self._valobj = valobj
118+
self._length = int(valobj["length"])
119+
self._data_ptr = valobj["data_ptr"]
111120

112121
def to_string(self):
113-
return "{}(size={})".format(self.valobj.type, self.length)
122+
return "{}(size={})".format(self._valobj.type, self._length)
114123

115124
def children(self):
116125
return _enumerate_array_elements(
117-
self.data_ptr + index for index in xrange(self.length)
126+
self._data_ptr + index for index in xrange(self._length)
118127
)
119128

120129
@staticmethod
121130
def display_hint():
122131
return "array"
123132

124-
class StdVecProvider:
133+
class StdVecProvider(printer_base):
125134
def __init__(self, valobj):
126-
self.valobj = valobj
127-
self.length = int(valobj["len"])
128-
self.data_ptr = unwrap_unique_or_non_null(valobj["buf"]["ptr"])
135+
self._valobj = valobj
136+
self._length = int(valobj["len"])
137+
self._data_ptr = unwrap_unique_or_non_null(valobj["buf"]["ptr"])
129138

130139
def to_string(self):
131-
return "Vec(size={})".format(self.length)
140+
return "Vec(size={})".format(self._length)
132141

133142
def children(self):
134143
return _enumerate_array_elements(
135-
self.data_ptr + index for index in xrange(self.length)
144+
self._data_ptr + index for index in xrange(self._length)
136145
)
137146

138147
@staticmethod
139148
def display_hint():
140149
return "array"
141150

142151

143-
class StdVecDequeProvider:
152+
class StdVecDequeProvider(printer_base):
144153
def __init__(self, valobj):
145-
self.valobj = valobj
146-
self.head = int(valobj["head"])
147-
self.size = int(valobj["len"])
148-
self.cap = int(valobj["buf"]["cap"])
149-
self.data_ptr = unwrap_unique_or_non_null(valobj["buf"]["ptr"])
154+
self._valobj = valobj
155+
self._head = int(valobj["head"])
156+
self._size = int(valobj["len"])
157+
self._cap = int(valobj["buf"]["cap"])
158+
self._data_ptr = unwrap_unique_or_non_null(valobj["buf"]["ptr"])
150159

151160
def to_string(self):
152-
return "VecDeque(size={})".format(self.size)
161+
return "VecDeque(size={})".format(self._size)
153162

154163
def children(self):
155164
return _enumerate_array_elements(
156-
(self.data_ptr + ((self.head + index) % self.cap)) for index in xrange(self.size)
165+
(self._data_ptr + ((self._head + index) % self._cap)) for index in xrange(self._size)
157166
)
158167

159168
@staticmethod
160169
def display_hint():
161170
return "array"
162171

163172

164-
class StdRcProvider:
173+
class StdRcProvider(printer_base):
165174
def __init__(self, valobj, is_atomic=False):
166-
self.valobj = valobj
167-
self.is_atomic = is_atomic
168-
self.ptr = unwrap_unique_or_non_null(valobj["ptr"])
169-
self.value = self.ptr["data" if is_atomic else "value"]
170-
self.strong = self.ptr["strong"]["v" if is_atomic else "value"]["value"]
171-
self.weak = self.ptr["weak"]["v" if is_atomic else "value"]["value"] - 1
175+
self._valobj = valobj
176+
self._is_atomic = is_atomic
177+
self._ptr = unwrap_unique_or_non_null(valobj["ptr"])
178+
self._value = self._ptr["data" if is_atomic else "value"]
179+
self._strong = self._ptr["strong"]["v" if is_atomic else "value"]["value"]
180+
self._weak = self._ptr["weak"]["v" if is_atomic else "value"]["value"] - 1
172181

173182
def to_string(self):
174-
if self.is_atomic:
175-
return "Arc(strong={}, weak={})".format(int(self.strong), int(self.weak))
183+
if self._is_atomic:
184+
return "Arc(strong={}, weak={})".format(int(self._strong), int(self._weak))
176185
else:
177-
return "Rc(strong={}, weak={})".format(int(self.strong), int(self.weak))
186+
return "Rc(strong={}, weak={})".format(int(self._strong), int(self._weak))
178187

179188
def children(self):
180-
yield "value", self.value
181-
yield "strong", self.strong
182-
yield "weak", self.weak
189+
yield "value", self._value
190+
yield "strong", self._strong
191+
yield "weak", self._weak
183192

184193

185-
class StdCellProvider:
194+
class StdCellProvider(printer_base):
186195
def __init__(self, valobj):
187-
self.value = valobj["value"]["value"]
196+
self._value = valobj["value"]["value"]
188197

189198
def to_string(self):
190199
return "Cell"
191200

192201
def children(self):
193-
yield "value", self.value
202+
yield "value", self._value
194203

195204

196-
class StdRefProvider:
205+
class StdRefProvider(printer_base):
197206
def __init__(self, valobj):
198-
self.value = valobj["value"].dereference()
199-
self.borrow = valobj["borrow"]["borrow"]["value"]["value"]
207+
self._value = valobj["value"].dereference()
208+
self._borrow = valobj["borrow"]["borrow"]["value"]["value"]
200209

201210
def to_string(self):
202-
borrow = int(self.borrow)
211+
borrow = int(self._borrow)
203212
if borrow >= 0:
204213
return "Ref(borrow={})".format(borrow)
205214
else:
206215
return "Ref(borrow_mut={})".format(-borrow)
207216

208217
def children(self):
209-
yield "*value", self.value
210-
yield "borrow", self.borrow
218+
yield "*value", self._value
219+
yield "borrow", self._borrow
211220

212221

213-
class StdRefCellProvider:
222+
class StdRefCellProvider(printer_base):
214223
def __init__(self, valobj):
215-
self.value = valobj["value"]["value"]
216-
self.borrow = valobj["borrow"]["value"]["value"]
224+
self._value = valobj["value"]["value"]
225+
self._borrow = valobj["borrow"]["value"]["value"]
217226

218227
def to_string(self):
219-
borrow = int(self.borrow)
228+
borrow = int(self._borrow)
220229
if borrow >= 0:
221230
return "RefCell(borrow={})".format(borrow)
222231
else:
223232
return "RefCell(borrow_mut={})".format(-borrow)
224233

225234
def children(self):
226-
yield "value", self.value
227-
yield "borrow", self.borrow
235+
yield "value", self._value
236+
yield "borrow", self._borrow
228237

229238

230-
class StdNonZeroNumberProvider:
239+
class StdNonZeroNumberProvider(printer_base):
231240
def __init__(self, valobj):
232241
fields = valobj.type.fields()
233242
assert len(fields) == 1
234243
field = list(fields)[0]
235-
self.value = str(valobj[field.name])
244+
self._value = str(valobj[field.name])
236245

237246
def to_string(self):
238-
return self.value
247+
return self._value
239248

240249

241250
# Yields children (in a provider's sense of the word) for a BTreeMap.
@@ -280,15 +289,15 @@ def cast_to_internal(node):
280289
yield child
281290

282291

283-
class StdBTreeSetProvider:
292+
class StdBTreeSetProvider(printer_base):
284293
def __init__(self, valobj):
285-
self.valobj = valobj
294+
self._valobj = valobj
286295

287296
def to_string(self):
288-
return "BTreeSet(size={})".format(self.valobj["map"]["length"])
297+
return "BTreeSet(size={})".format(self._valobj["map"]["length"])
289298

290299
def children(self):
291-
inner_map = self.valobj["map"]
300+
inner_map = self._valobj["map"]
292301
for i, (child, _) in enumerate(children_of_btree_map(inner_map)):
293302
yield "[{}]".format(i), child
294303

@@ -297,15 +306,15 @@ def display_hint():
297306
return "array"
298307

299308

300-
class StdBTreeMapProvider:
309+
class StdBTreeMapProvider(printer_base):
301310
def __init__(self, valobj):
302-
self.valobj = valobj
311+
self._valobj = valobj
303312

304313
def to_string(self):
305-
return "BTreeMap(size={})".format(self.valobj["length"])
314+
return "BTreeMap(size={})".format(self._valobj["length"])
306315

307316
def children(self):
308-
for i, (key, val) in enumerate(children_of_btree_map(self.valobj)):
317+
for i, (key, val) in enumerate(children_of_btree_map(self._valobj)):
309318
yield "key{}".format(i), key
310319
yield "val{}".format(i), val
311320

@@ -315,124 +324,124 @@ def display_hint():
315324

316325

317326
# BACKCOMPAT: rust 1.35
318-
class StdOldHashMapProvider:
327+
class StdOldHashMapProvider(printer_base):
319328
def __init__(self, valobj, show_values=True):
320-
self.valobj = valobj
321-
self.show_values = show_values
322-
323-
self.table = self.valobj["table"]
324-
self.size = int(self.table["size"])
325-
self.hashes = self.table["hashes"]
326-
self.hash_uint_type = self.hashes.type
327-
self.hash_uint_size = self.hashes.type.sizeof
328-
self.modulo = 2 ** self.hash_uint_size
329-
self.data_ptr = self.hashes[ZERO_FIELD]["pointer"]
330-
331-
self.capacity_mask = int(self.table["capacity_mask"])
332-
self.capacity = (self.capacity_mask + 1) % self.modulo
333-
334-
marker = self.table["marker"].type
335-
self.pair_type = marker.template_argument(0)
336-
self.pair_type_size = self.pair_type.sizeof
337-
338-
self.valid_indices = []
339-
for idx in range(self.capacity):
340-
data_ptr = self.data_ptr.cast(self.hash_uint_type.pointer())
329+
self._valobj = valobj
330+
self._show_values = show_values
331+
332+
self._table = self._valobj["table"]
333+
self._size = int(self._table["size"])
334+
self._hashes = self._table["hashes"]
335+
self._hash_uint_type = self._hashes.type
336+
self._hash_uint_size = self._hashes.type.sizeof
337+
self._modulo = 2 ** self._hash_uint_size
338+
self._data_ptr = self._hashes[ZERO_FIELD]["pointer"]
339+
340+
self._capacity_mask = int(self._table["capacity_mask"])
341+
self._capacity = (self._capacity_mask + 1) % self._modulo
342+
343+
marker = self._table["marker"].type
344+
self._pair_type = marker.template_argument(0)
345+
self._pair_type_size = self._pair_type.sizeof
346+
347+
self._valid_indices = []
348+
for idx in range(self._capacity):
349+
data_ptr = self._data_ptr.cast(self._hash_uint_type.pointer())
341350
address = data_ptr + idx
342351
hash_uint = address.dereference()
343352
hash_ptr = hash_uint[ZERO_FIELD]["pointer"]
344353
if int(hash_ptr) != 0:
345-
self.valid_indices.append(idx)
354+
self._valid_indices.append(idx)
346355

347356
def to_string(self):
348-
if self.show_values:
349-
return "HashMap(size={})".format(self.size)
357+
if self._show_values:
358+
return "HashMap(size={})".format(self._size)
350359
else:
351-
return "HashSet(size={})".format(self.size)
360+
return "HashSet(size={})".format(self._size)
352361

353362
def children(self):
354-
start = int(self.data_ptr) & ~1
363+
start = int(self._data_ptr) & ~1
355364

356-
hashes = self.hash_uint_size * self.capacity
357-
align = self.pair_type_size
358-
len_rounded_up = (((((hashes + align) % self.modulo - 1) % self.modulo) & ~(
359-
(align - 1) % self.modulo)) % self.modulo - hashes) % self.modulo
365+
hashes = self._hash_uint_size * self._capacity
366+
align = self._pair_type_size
367+
len_rounded_up = (((((hashes + align) % self._modulo - 1) % self._modulo) & ~(
368+
(align - 1) % self._modulo)) % self._modulo - hashes) % self._modulo
360369

361370
pairs_offset = hashes + len_rounded_up
362-
pairs_start = gdb.Value(start + pairs_offset).cast(self.pair_type.pointer())
371+
pairs_start = gdb.Value(start + pairs_offset).cast(self._pair_type.pointer())
363372

364-
for index in range(self.size):
365-
table_index = self.valid_indices[index]
366-
idx = table_index & self.capacity_mask
373+
for index in range(self._size):
374+
table_index = self._valid_indices[index]
375+
idx = table_index & self._capacity_mask
367376
element = (pairs_start + idx).dereference()
368-
if self.show_values:
377+
if self._show_values:
369378
yield "key{}".format(index), element[ZERO_FIELD]
370379
yield "val{}".format(index), element[FIRST_FIELD]
371380
else:
372381
yield "[{}]".format(index), element[ZERO_FIELD]
373382

374383
def display_hint(self):
375-
return "map" if self.show_values else "array"
384+
return "map" if self._show_values else "array"
376385

377386

378-
class StdHashMapProvider:
387+
class StdHashMapProvider(printer_base):
379388
def __init__(self, valobj, show_values=True):
380-
self.valobj = valobj
381-
self.show_values = show_values
389+
self._valobj = valobj
390+
self._show_values = show_values
382391

383-
table = self.table()
392+
table = self._table()
384393
table_inner = table["table"]
385394
capacity = int(table_inner["bucket_mask"]) + 1
386395
ctrl = table_inner["ctrl"]["pointer"]
387396

388-
self.size = int(table_inner["items"])
389-
self.pair_type = table.type.template_argument(0).strip_typedefs()
397+
self._size = int(table_inner["items"])
398+
self._pair_type = table.type.template_argument(0).strip_typedefs()
390399

391-
self.new_layout = not table_inner.type.has_key("data")
392-
if self.new_layout:
393-
self.data_ptr = ctrl.cast(self.pair_type.pointer())
400+
self._new_layout = not table_inner.type.has_key("data")
401+
if self._new_layout:
402+
self._data_ptr = ctrl.cast(self._pair_type.pointer())
394403
else:
395-
self.data_ptr = table_inner["data"]["pointer"]
404+
self._data_ptr = table_inner["data"]["pointer"]
396405

397-
self.valid_indices = []
406+
self._valid_indices = []
398407
for idx in range(capacity):
399408
address = ctrl + idx
400409
value = address.dereference()
401410
is_presented = value & 128 == 0
402411
if is_presented:
403-
self.valid_indices.append(idx)
412+
self._valid_indices.append(idx)
404413

405-
def table(self):
406-
if self.show_values:
407-
hashbrown_hashmap = self.valobj["base"]
408-
elif self.valobj.type.fields()[0].name == "map":
414+
def _table(self):
415+
if self._show_values:
416+
hashbrown_hashmap = self._valobj["base"]
417+
elif self._valobj.type.fields()[0].name == "map":
409418
# BACKCOMPAT: rust 1.47
410419
# HashSet wraps std::collections::HashMap, which wraps hashbrown::HashMap
411-
hashbrown_hashmap = self.valobj["map"]["base"]
420+
hashbrown_hashmap = self._valobj["map"]["base"]
412421
else:
413422
# HashSet wraps hashbrown::HashSet, which wraps hashbrown::HashMap
414-
hashbrown_hashmap = self.valobj["base"]["map"]
423+
hashbrown_hashmap = self._valobj["base"]["map"]
415424
return hashbrown_hashmap["table"]
416425

417426
def to_string(self):
418-
if self.show_values:
419-
return "HashMap(size={})".format(self.size)
427+
if self._show_values:
428+
return "HashMap(size={})".format(self._size)
420429
else:
421-
return "HashSet(size={})".format(self.size)
430+
return "HashSet(size={})".format(self._size)
422431

423432
def children(self):
424-
pairs_start = self.data_ptr
433+
pairs_start = self._data_ptr
425434

426-
for index in range(self.size):
427-
idx = self.valid_indices[index]
428-
if self.new_layout:
435+
for index in range(self._size):
436+
idx = self._valid_indices[index]
437+
if self._new_layout:
429438
idx = -(idx + 1)
430439
element = (pairs_start + idx).dereference()
431-
if self.show_values:
440+
if self._show_values:
432441
yield "key{}".format(index), element[ZERO_FIELD]
433442
yield "val{}".format(index), element[FIRST_FIELD]
434443
else:
435444
yield "[{}]".format(index), element[ZERO_FIELD]
436445

437446
def display_hint(self):
438-
return "map" if self.show_values else "array"
447+
return "map" if self._show_values else "array"

‎tests/ui/rfcs/rfc-2008-non-exhaustive/omitted-patterns.rs

+7
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,10 @@ fn main() {
251251
pub fn takes_non_exhaustive(_: NonExhaustiveEnum) {
252252
let _closure = |_: NonExhaustiveEnum| {};
253253
}
254+
255+
// ICE #117033
256+
enum Void {}
257+
#[deny(non_exhaustive_omitted_patterns)]
258+
pub fn void(v: Void) -> ! {
259+
match v {}
260+
}

0 commit comments

Comments
 (0)
Please sign in to comment.