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 1195bea

Browse files
committedJul 30, 2021
Auto merge of rust-lang#87615 - JohnTitor:rollup-t5jpmrg, r=JohnTitor
Rollup of 10 pull requests Successful merges: - rust-lang#87052 (Optimize fmt::PadAdapter::wrap) - rust-lang#87522 (Fix assert in diy_float) - rust-lang#87553 (Fix typo in rustc_driver::version) - rust-lang#87554 (2229: Discr should be read when PatKind is Range) - rust-lang#87564 (min_type_alias_impl_trait is going to be removed in 1.56) - rust-lang#87574 (Update the examples in `String` and `VecDeque::retain`) - rust-lang#87583 (Refactor compression cache in v0 symbol mangler) - rust-lang#87585 (Add missing links for core::char types) - rust-lang#87594 (fs File get_path procfs usage for netbsd same as linux.) - rust-lang#87602 ([backtraces]: look for the `begin` symbol only after seeing `end`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents f739552 + 84e1882 commit 1195bea

File tree

14 files changed

+143
-70
lines changed

14 files changed

+143
-70
lines changed
 

‎compiler/rustc_driver/src/lib.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -764,13 +764,7 @@ pub fn version(binary: &str, matches: &getopts::Matches) {
764764
println!("release: {}", unw(util::release_str()));
765765

766766
let debug_flags = matches.opt_strs("Z");
767-
let backend_name = debug_flags.iter().find_map(|x| {
768-
if x.starts_with("codegen-backend=") {
769-
Some(&x["codegen-backends=".len()..])
770-
} else {
771-
None
772-
}
773-
});
767+
let backend_name = debug_flags.iter().find_map(|x| x.strip_prefix("codegen-backend="));
774768
get_codegen_backend(&None, backend_name).print_version();
775769
}
776770
}

‎compiler/rustc_feature/src/removed.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ declare_features! (
153153
Some("the implementation was not maintainable, the feature may get reintroduced once the current refactorings are done")),
154154

155155
/// Allows the use of type alias impl trait in function return positions
156-
(removed, min_type_alias_impl_trait, "1.55.0", Some(63063), None,
156+
(removed, min_type_alias_impl_trait, "1.56.0", Some(63063), None,
157157
Some("removed in favor of full type_alias_impl_trait")),
158158

159159
// -------------------------------------------------------------------------

‎compiler/rustc_symbol_mangling/src/v0.rs

+32-45
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,12 @@ pub(super) fn mangle(
2323
let substs = tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), instance.substs);
2424

2525
let prefix = "_R";
26-
let mut cx = SymbolMangler {
26+
let mut cx = &mut SymbolMangler {
2727
tcx,
28-
compress: Some(Box::new(CompressionCaches {
29-
start_offset: prefix.len(),
30-
31-
paths: FxHashMap::default(),
32-
types: FxHashMap::default(),
33-
consts: FxHashMap::default(),
34-
})),
28+
start_offset: prefix.len(),
29+
paths: FxHashMap::default(),
30+
types: FxHashMap::default(),
31+
consts: FxHashMap::default(),
3532
binders: vec![],
3633
out: String::from(prefix),
3734
};
@@ -52,17 +49,7 @@ pub(super) fn mangle(
5249
if let Some(instantiating_crate) = instantiating_crate {
5350
cx = cx.print_def_path(instantiating_crate.as_def_id(), &[]).unwrap();
5451
}
55-
cx.out
56-
}
57-
58-
struct CompressionCaches<'tcx> {
59-
// The length of the prefix in `out` (e.g. 2 for `_R`).
60-
start_offset: usize,
61-
62-
// The values are start positions in `out`, in bytes.
63-
paths: FxHashMap<(DefId, &'tcx [GenericArg<'tcx>]), usize>,
64-
types: FxHashMap<Ty<'tcx>, usize>,
65-
consts: FxHashMap<&'tcx ty::Const<'tcx>, usize>,
52+
std::mem::take(&mut cx.out)
6653
}
6754

6855
struct BinderLevel {
@@ -81,9 +68,15 @@ struct BinderLevel {
8168

8269
struct SymbolMangler<'tcx> {
8370
tcx: TyCtxt<'tcx>,
84-
compress: Option<Box<CompressionCaches<'tcx>>>,
8571
binders: Vec<BinderLevel>,
8672
out: String,
73+
74+
/// The length of the prefix in `out` (e.g. 2 for `_R`).
75+
start_offset: usize,
76+
/// The values are start positions in `out`, in bytes.
77+
paths: FxHashMap<(DefId, &'tcx [GenericArg<'tcx>]), usize>,
78+
types: FxHashMap<Ty<'tcx>, usize>,
79+
consts: FxHashMap<&'tcx ty::Const<'tcx>, usize>,
8780
}
8881

8982
impl SymbolMangler<'tcx> {
@@ -160,13 +153,13 @@ impl SymbolMangler<'tcx> {
160153
self.push(ident);
161154
}
162155

163-
fn path_append_ns(
164-
mut self,
165-
print_prefix: impl FnOnce(Self) -> Result<Self, !>,
156+
fn path_append_ns<'a>(
157+
mut self: &'a mut Self,
158+
print_prefix: impl FnOnce(&'a mut Self) -> Result<&'a mut Self, !>,
166159
ns: char,
167160
disambiguator: u64,
168161
name: &str,
169-
) -> Result<Self, !> {
162+
) -> Result<&'a mut Self, !> {
170163
self.push("N");
171164
self.out.push(ns);
172165
self = print_prefix(self)?;
@@ -175,17 +168,17 @@ impl SymbolMangler<'tcx> {
175168
Ok(self)
176169
}
177170

178-
fn print_backref(mut self, i: usize) -> Result<Self, !> {
171+
fn print_backref(&mut self, i: usize) -> Result<&mut Self, !> {
179172
self.push("B");
180-
self.push_integer_62((i - self.compress.as_ref().unwrap().start_offset) as u64);
173+
self.push_integer_62((i - self.start_offset) as u64);
181174
Ok(self)
182175
}
183176

184-
fn in_binder<T>(
185-
mut self,
177+
fn in_binder<'a, T>(
178+
mut self: &'a mut Self,
186179
value: &ty::Binder<'tcx, T>,
187-
print_value: impl FnOnce(Self, &T) -> Result<Self, !>,
188-
) -> Result<Self, !>
180+
print_value: impl FnOnce(&'a mut Self, &T) -> Result<&'a mut Self, !>,
181+
) -> Result<&'a mut Self, !>
189182
where
190183
T: TypeFoldable<'tcx>,
191184
{
@@ -218,7 +211,7 @@ impl SymbolMangler<'tcx> {
218211
}
219212
}
220213

221-
impl Printer<'tcx> for SymbolMangler<'tcx> {
214+
impl Printer<'tcx> for &mut SymbolMangler<'tcx> {
222215
type Error = !;
223216

224217
type Path = Self;
@@ -236,7 +229,7 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
236229
def_id: DefId,
237230
substs: &'tcx [GenericArg<'tcx>],
238231
) -> Result<Self::Path, Self::Error> {
239-
if let Some(&i) = self.compress.as_ref().and_then(|c| c.paths.get(&(def_id, substs))) {
232+
if let Some(&i) = self.paths.get(&(def_id, substs)) {
240233
return self.print_backref(i);
241234
}
242235
let start = self.out.len();
@@ -246,9 +239,7 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
246239
// Only cache paths that do not refer to an enclosing
247240
// binder (which would change depending on context).
248241
if !substs.iter().any(|k| k.has_escaping_bound_vars()) {
249-
if let Some(c) = &mut self.compress {
250-
c.paths.insert((def_id, substs), start);
251-
}
242+
self.paths.insert((def_id, substs), start);
252243
}
253244
Ok(self)
254245
}
@@ -312,7 +303,7 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
312303
Ok(self)
313304
}
314305

315-
fn print_region(mut self, region: ty::Region<'_>) -> Result<Self::Region, Self::Error> {
306+
fn print_region(self, region: ty::Region<'_>) -> Result<Self::Region, Self::Error> {
316307
let i = match *region {
317308
// Erased lifetimes use the index 0, for a
318309
// shorter mangling of `L_`.
@@ -367,7 +358,7 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
367358
return Ok(self);
368359
}
369360

370-
if let Some(&i) = self.compress.as_ref().and_then(|c| c.types.get(&ty)) {
361+
if let Some(&i) = self.types.get(&ty) {
371362
return self.print_backref(i);
372363
}
373364
let start = self.out.len();
@@ -476,9 +467,7 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
476467
// Only cache types that do not refer to an enclosing
477468
// binder (which would change depending on context).
478469
if !ty.has_escaping_bound_vars() {
479-
if let Some(c) = &mut self.compress {
480-
c.types.insert(ty, start);
481-
}
470+
self.types.insert(ty, start);
482471
}
483472
Ok(self)
484473
}
@@ -545,7 +534,7 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
545534
}
546535

547536
fn print_const(mut self, ct: &'tcx ty::Const<'tcx>) -> Result<Self::Const, Self::Error> {
548-
if let Some(&i) = self.compress.as_ref().and_then(|c| c.consts.get(&ct)) {
537+
if let Some(&i) = self.consts.get(&ct) {
549538
return self.print_backref(i);
550539
}
551540
let start = self.out.len();
@@ -583,14 +572,12 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
583572
// Only cache consts that do not refer to an enclosing
584573
// binder (which would change depending on context).
585574
if !ct.has_escaping_bound_vars() {
586-
if let Some(c) = &mut self.compress {
587-
c.consts.insert(ct, start);
588-
}
575+
self.consts.insert(ct, start);
589576
}
590577
Ok(self)
591578
}
592579

593-
fn path_crate(mut self, cnum: CrateNum) -> Result<Self::Path, Self::Error> {
580+
fn path_crate(self, cnum: CrateNum) -> Result<Self::Path, Self::Error> {
594581
self.push("C");
595582
let stable_crate_id = self.tcx.def_path_hash(cnum.as_def_id()).stable_crate_id();
596583
self.push_disambiguator(stable_crate_id.to_u64());

‎compiler/rustc_typeck/src/expr_use_visitor.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,21 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
267267
}
268268
}
269269
}
270-
PatKind::Lit(_) => {
271-
// If the PatKind is a Lit then we want
270+
PatKind::Lit(_) | PatKind::Range(..) => {
271+
// If the PatKind is a Lit or a Range then we want
272272
// to borrow discr.
273273
needs_to_be_read = true;
274274
}
275-
_ => {}
275+
PatKind::Or(_)
276+
| PatKind::Box(_)
277+
| PatKind::Slice(..)
278+
| PatKind::Ref(..)
279+
| PatKind::Wild => {
280+
// If the PatKind is Or, Box, Slice or Ref, the decision is made later
281+
// as these patterns contains subpatterns
282+
// If the PatKind is Wild, the decision is made based on the other patterns being
283+
// examined
284+
}
276285
}
277286
}));
278287
}

‎library/alloc/src/collections/vec_deque/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -2107,7 +2107,8 @@ impl<T, A: Allocator> VecDeque<T, A> {
21072107
/// assert_eq!(buf, [2, 4]);
21082108
/// ```
21092109
///
2110-
/// The exact order may be useful for tracking external state, like an index.
2110+
/// Because the elements are visited exactly once in the original order,
2111+
/// external state may be used to decide which elements to keep.
21112112
///
21122113
/// ```
21132114
/// use std::collections::VecDeque;
@@ -2116,8 +2117,8 @@ impl<T, A: Allocator> VecDeque<T, A> {
21162117
/// buf.extend(1..6);
21172118
///
21182119
/// let keep = [false, true, true, false, true];
2119-
/// let mut i = 0;
2120-
/// buf.retain(|_| (keep[i], i += 1).0);
2120+
/// let mut iter = keep.iter();
2121+
/// buf.retain(|_| *iter.next().unwrap());
21212122
/// assert_eq!(buf, [2, 3, 5]);
21222123
/// ```
21232124
#[stable(feature = "vec_deque_retain", since = "1.4.0")]

‎library/alloc/src/string.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1350,13 +1350,14 @@ impl String {
13501350
/// assert_eq!(s, "foobar");
13511351
/// ```
13521352
///
1353-
/// The exact order may be useful for tracking external state, like an index.
1353+
/// Because the elements are visited exactly once in the original order,
1354+
/// external state may be used to decide which elements to keep.
13541355
///
13551356
/// ```
13561357
/// let mut s = String::from("abcde");
13571358
/// let keep = [false, true, true, false, true];
1358-
/// let mut i = 0;
1359-
/// s.retain(|_| (keep[i], i += 1).0);
1359+
/// let mut iter = keep.iter();
1360+
/// s.retain(|_| *iter.next().unwrap());
13601361
/// assert_eq!(s, "bce");
13611362
/// ```
13621363
#[inline]

‎library/core/src/char/decode.rs

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ use crate::fmt;
55
use super::from_u32_unchecked;
66

77
/// An iterator that decodes UTF-16 encoded code points from an iterator of `u16`s.
8+
///
9+
/// This `struct` is created by the [`decode_utf16`] method on [`char`]. See its
10+
/// documentation for more.
11+
///
12+
/// [`decode_utf16`]: char::decode_utf16
813
#[stable(feature = "decode_utf16", since = "1.9.0")]
914
#[derive(Clone, Debug)]
1015
pub struct DecodeUtf16<I>
@@ -16,6 +21,8 @@ where
1621
}
1722

1823
/// An error that can be returned when decoding UTF-16 code points.
24+
///
25+
/// This `struct` is created when using the [`DecodeUtf16`] type.
1926
#[stable(feature = "decode_utf16", since = "1.9.0")]
2027
#[derive(Debug, Clone, Eq, PartialEq)]
2128
pub struct DecodeUtf16Error {

‎library/core/src/fmt/builders.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ impl<'buf, 'state> PadAdapter<'buf, 'state> {
2323
slot: &'slot mut Option<Self>,
2424
state: &'state mut PadAdapterState,
2525
) -> fmt::Formatter<'slot> {
26-
fmt.wrap_buf(move |buf| {
27-
*slot = Some(PadAdapter { buf, state });
28-
slot.as_mut().unwrap()
29-
})
26+
fmt.wrap_buf(move |buf| slot.insert(PadAdapter { buf, state }))
3027
}
3128
}
3229

‎library/core/src/num/diy_float.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl Fp {
6565
f <<= 1;
6666
e -= 1;
6767
}
68-
debug_assert!(f >= (1 >> 63));
68+
debug_assert!(f >= (1 << 63));
6969
Fp { f, e }
7070
}
7171

‎library/std/src/sys/unix/fs.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ impl FromInner<c_int> for File {
939939

940940
impl fmt::Debug for File {
941941
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
942-
#[cfg(target_os = "linux")]
942+
#[cfg(any(target_os = "linux", target_os = "netbsd"))]
943943
fn get_path(fd: c_int) -> Option<PathBuf> {
944944
let mut p = PathBuf::from("/proc/self/fd");
945945
p.push(&fd.to_string());
@@ -976,7 +976,12 @@ impl fmt::Debug for File {
976976
Some(PathBuf::from(OsString::from_vec(buf)))
977977
}
978978

979-
#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "vxworks")))]
979+
#[cfg(not(any(
980+
target_os = "linux",
981+
target_os = "macos",
982+
target_os = "vxworks",
983+
target_os = "netbsd"
984+
)))]
980985
fn get_path(_fd: c_int) -> Option<PathBuf> {
981986
// FIXME(#24570): implement this for other Unix platforms
982987
None

‎library/std/src/sys_common/backtrace.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ unsafe fn _print_fmt(fmt: &mut fmt::Formatter<'_>, print_fmt: PrintFmt) -> fmt::
7575
hit = true;
7676
if print_fmt == PrintFmt::Short {
7777
if let Some(sym) = symbol.name().and_then(|s| s.as_str()) {
78-
if sym.contains("__rust_begin_short_backtrace") {
78+
if start && sym.contains("__rust_begin_short_backtrace") {
7979
stop = true;
8080
return;
8181
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// run-pass
2+
// edition:2021
3+
4+
pub fn foo() {
5+
let ref_x_ck = 123;
6+
let _y = || match ref_x_ck {
7+
2_000_000..=3_999_999 => { println!("A")}
8+
_ => { println!("B")}
9+
};
10+
}
11+
12+
fn main() {
13+
foo();
14+
}

0 commit comments

Comments
 (0)
Please sign in to comment.