]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #87615 - JohnTitor:rollup-t5jpmrg, r=JohnTitor
authorbors <bors@rust-lang.org>
Fri, 30 Jul 2021 09:43:32 +0000 (09:43 +0000)
committerbors <bors@rust-lang.org>
Fri, 30 Jul 2021 09:43:32 +0000 (09:43 +0000)
Rollup of 10 pull requests

Successful merges:

 - #87052 (Optimize fmt::PadAdapter::wrap)
 - #87522 (Fix assert in diy_float)
 - #87553 (Fix typo in rustc_driver::version)
 - #87554 (2229: Discr should be read when PatKind is Range)
 - #87564 (min_type_alias_impl_trait is going to be removed in 1.56)
 - #87574 (Update the examples in `String` and `VecDeque::retain`)
 - #87583 (Refactor compression cache in v0 symbol mangler)
 - #87585 (Add missing links for core::char types)
 - #87594 (fs File get_path procfs usage for netbsd same as linux.)
 - #87602 ([backtraces]: look for the `begin` symbol only after seeing `end`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup

14 files changed:
compiler/rustc_driver/src/lib.rs
compiler/rustc_feature/src/removed.rs
compiler/rustc_symbol_mangling/src/v0.rs
compiler/rustc_typeck/src/expr_use_visitor.rs
library/alloc/src/collections/vec_deque/mod.rs
library/alloc/src/string.rs
library/core/src/char/decode.rs
library/core/src/fmt/builders.rs
library/core/src/num/diy_float.rs
library/std/src/sys/unix/fs.rs
library/std/src/sys_common/backtrace.rs
src/test/ui/closures/2229_closure_analysis/issue-87426.rs [new file with mode: 0644]
src/test/ui/panics/panic-short-backtrace-windows-x86_64.rs [new file with mode: 0644]
src/test/ui/panics/panic-short-backtrace-windows-x86_64.run.stderr [new file with mode: 0644]

index 326fefa59ab0576606321958686833549d2bd9f5..84dd69ebd963496696d0ed03e9d7d5bc1d4a40b5 100644 (file)
@@ -764,13 +764,7 @@ fn unw(x: Option<&str>) -> &str {
         println!("release: {}", unw(util::release_str()));
 
         let debug_flags = matches.opt_strs("Z");
-        let backend_name = debug_flags.iter().find_map(|x| {
-            if x.starts_with("codegen-backend=") {
-                Some(&x["codegen-backends=".len()..])
-            } else {
-                None
-            }
-        });
+        let backend_name = debug_flags.iter().find_map(|x| x.strip_prefix("codegen-backend="));
         get_codegen_backend(&None, backend_name).print_version();
     }
 }
index 0aa7e82c204927fa9cabd2aeb1bdef1ff58ce7ca..f63c207a540c2ff72c32320733d572b59d40295f 100644 (file)
@@ -153,7 +153,7 @@ macro_rules! declare_features {
      Some("the implementation was not maintainable, the feature may get reintroduced once the current refactorings are done")),
 
     /// Allows the use of type alias impl trait in function return positions
-    (removed, min_type_alias_impl_trait, "1.55.0", Some(63063), None,
+    (removed, min_type_alias_impl_trait, "1.56.0", Some(63063), None,
      Some("removed in favor of full type_alias_impl_trait")),
 
     // -------------------------------------------------------------------------
index 14442806fc0b757104c1d4fb58adae3ddf0734a0..c4c1ec8ce4e0a2ca109d6aa669dc4802a9dec415 100644 (file)
@@ -23,15 +23,12 @@ pub(super) fn mangle(
     let substs = tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), instance.substs);
 
     let prefix = "_R";
-    let mut cx = SymbolMangler {
+    let mut cx = &mut SymbolMangler {
         tcx,
-        compress: Some(Box::new(CompressionCaches {
-            start_offset: prefix.len(),
-
-            paths: FxHashMap::default(),
-            types: FxHashMap::default(),
-            consts: FxHashMap::default(),
-        })),
+        start_offset: prefix.len(),
+        paths: FxHashMap::default(),
+        types: FxHashMap::default(),
+        consts: FxHashMap::default(),
         binders: vec![],
         out: String::from(prefix),
     };
@@ -52,17 +49,7 @@ pub(super) fn mangle(
     if let Some(instantiating_crate) = instantiating_crate {
         cx = cx.print_def_path(instantiating_crate.as_def_id(), &[]).unwrap();
     }
-    cx.out
-}
-
-struct CompressionCaches<'tcx> {
-    // The length of the prefix in `out` (e.g. 2 for `_R`).
-    start_offset: usize,
-
-    // The values are start positions in `out`, in bytes.
-    paths: FxHashMap<(DefId, &'tcx [GenericArg<'tcx>]), usize>,
-    types: FxHashMap<Ty<'tcx>, usize>,
-    consts: FxHashMap<&'tcx ty::Const<'tcx>, usize>,
+    std::mem::take(&mut cx.out)
 }
 
 struct BinderLevel {
@@ -81,9 +68,15 @@ struct BinderLevel {
 
 struct SymbolMangler<'tcx> {
     tcx: TyCtxt<'tcx>,
-    compress: Option<Box<CompressionCaches<'tcx>>>,
     binders: Vec<BinderLevel>,
     out: String,
+
+    /// The length of the prefix in `out` (e.g. 2 for `_R`).
+    start_offset: usize,
+    /// The values are start positions in `out`, in bytes.
+    paths: FxHashMap<(DefId, &'tcx [GenericArg<'tcx>]), usize>,
+    types: FxHashMap<Ty<'tcx>, usize>,
+    consts: FxHashMap<&'tcx ty::Const<'tcx>, usize>,
 }
 
 impl SymbolMangler<'tcx> {
@@ -160,13 +153,13 @@ fn push_ident(&mut self, ident: &str) {
         self.push(ident);
     }
 
-    fn path_append_ns(
-        mut self,
-        print_prefix: impl FnOnce(Self) -> Result<Self, !>,
+    fn path_append_ns<'a>(
+        mut self: &'a mut Self,
+        print_prefix: impl FnOnce(&'a mut Self) -> Result<&'a mut Self, !>,
         ns: char,
         disambiguator: u64,
         name: &str,
-    ) -> Result<Self, !> {
+    ) -> Result<&'a mut Self, !> {
         self.push("N");
         self.out.push(ns);
         self = print_prefix(self)?;
@@ -175,17 +168,17 @@ fn path_append_ns(
         Ok(self)
     }
 
-    fn print_backref(mut self, i: usize) -> Result<Self, !> {
+    fn print_backref(&mut self, i: usize) -> Result<&mut Self, !> {
         self.push("B");
-        self.push_integer_62((i - self.compress.as_ref().unwrap().start_offset) as u64);
+        self.push_integer_62((i - self.start_offset) as u64);
         Ok(self)
     }
 
-    fn in_binder<T>(
-        mut self,
+    fn in_binder<'a, T>(
+        mut self: &'a mut Self,
         value: &ty::Binder<'tcx, T>,
-        print_value: impl FnOnce(Self, &T) -> Result<Self, !>,
-    ) -> Result<Self, !>
+        print_value: impl FnOnce(&'a mut Self, &T) -> Result<&'a mut Self, !>,
+    ) -> Result<&'a mut Self, !>
     where
         T: TypeFoldable<'tcx>,
     {
@@ -218,7 +211,7 @@ fn in_binder<T>(
     }
 }
 
-impl Printer<'tcx> for SymbolMangler<'tcx> {
+impl Printer<'tcx> for &mut SymbolMangler<'tcx> {
     type Error = !;
 
     type Path = Self;
@@ -236,7 +229,7 @@ fn print_def_path(
         def_id: DefId,
         substs: &'tcx [GenericArg<'tcx>],
     ) -> Result<Self::Path, Self::Error> {
-        if let Some(&i) = self.compress.as_ref().and_then(|c| c.paths.get(&(def_id, substs))) {
+        if let Some(&i) = self.paths.get(&(def_id, substs)) {
             return self.print_backref(i);
         }
         let start = self.out.len();
@@ -246,9 +239,7 @@ fn print_def_path(
         // Only cache paths that do not refer to an enclosing
         // binder (which would change depending on context).
         if !substs.iter().any(|k| k.has_escaping_bound_vars()) {
-            if let Some(c) = &mut self.compress {
-                c.paths.insert((def_id, substs), start);
-            }
+            self.paths.insert((def_id, substs), start);
         }
         Ok(self)
     }
@@ -312,7 +303,7 @@ fn print_impl_path(
         Ok(self)
     }
 
-    fn print_region(mut self, region: ty::Region<'_>) -> Result<Self::Region, Self::Error> {
+    fn print_region(self, region: ty::Region<'_>) -> Result<Self::Region, Self::Error> {
         let i = match *region {
             // Erased lifetimes use the index 0, for a
             // shorter mangling of `L_`.
@@ -367,7 +358,7 @@ fn print_type(mut self, ty: Ty<'tcx>) -> Result<Self::Type, Self::Error> {
             return Ok(self);
         }
 
-        if let Some(&i) = self.compress.as_ref().and_then(|c| c.types.get(&ty)) {
+        if let Some(&i) = self.types.get(&ty) {
             return self.print_backref(i);
         }
         let start = self.out.len();
@@ -476,9 +467,7 @@ fn print_type(mut self, ty: Ty<'tcx>) -> Result<Self::Type, Self::Error> {
         // Only cache types that do not refer to an enclosing
         // binder (which would change depending on context).
         if !ty.has_escaping_bound_vars() {
-            if let Some(c) = &mut self.compress {
-                c.types.insert(ty, start);
-            }
+            self.types.insert(ty, start);
         }
         Ok(self)
     }
@@ -545,7 +534,7 @@ fn print_dyn_existential(
     }
 
     fn print_const(mut self, ct: &'tcx ty::Const<'tcx>) -> Result<Self::Const, Self::Error> {
-        if let Some(&i) = self.compress.as_ref().and_then(|c| c.consts.get(&ct)) {
+        if let Some(&i) = self.consts.get(&ct) {
             return self.print_backref(i);
         }
         let start = self.out.len();
@@ -583,14 +572,12 @@ fn print_const(mut self, ct: &'tcx ty::Const<'tcx>) -> Result<Self::Const, Self:
         // Only cache consts that do not refer to an enclosing
         // binder (which would change depending on context).
         if !ct.has_escaping_bound_vars() {
-            if let Some(c) = &mut self.compress {
-                c.consts.insert(ct, start);
-            }
+            self.consts.insert(ct, start);
         }
         Ok(self)
     }
 
-    fn path_crate(mut self, cnum: CrateNum) -> Result<Self::Path, Self::Error> {
+    fn path_crate(self, cnum: CrateNum) -> Result<Self::Path, Self::Error> {
         self.push("C");
         let stable_crate_id = self.tcx.def_path_hash(cnum.as_def_id()).stable_crate_id();
         self.push_disambiguator(stable_crate_id.to_u64());
index 6c76a8960bbe1a2a509ae6165787ef30c4c65822..1d7852d964c1dd428108c9934c0ffbe40e0886ce 100644 (file)
@@ -267,12 +267,21 @@ pub fn walk_expr(&mut self, expr: &hir::Expr<'_>) {
                                     }
                                 }
                             }
-                            PatKind::Lit(_) => {
-                                // If the PatKind is a Lit then we want
+                            PatKind::Lit(_) | PatKind::Range(..) => {
+                                // If the PatKind is a Lit or a Range then we want
                                 // to borrow discr.
                                 needs_to_be_read = true;
                             }
-                            _ => {}
+                            PatKind::Or(_)
+                            | PatKind::Box(_)
+                            | PatKind::Slice(..)
+                            | PatKind::Ref(..)
+                            | PatKind::Wild => {
+                                // If the PatKind is Or, Box, Slice or Ref, the decision is made later
+                                // as these patterns contains subpatterns
+                                // If the PatKind is Wild, the decision is made based on the other patterns being
+                                // examined
+                            }
                         }
                     }));
                 }
index 386c7c2612d572e91ece1bc0254b2a6407b3cf26..3cf6c56f43a579b089d2e8282c5256fe3498fdbc 100644 (file)
@@ -2107,7 +2107,8 @@ pub fn append(&mut self, other: &mut Self) {
     /// assert_eq!(buf, [2, 4]);
     /// ```
     ///
-    /// The exact order may be useful for tracking external state, like an index.
+    /// Because the elements are visited exactly once in the original order,
+    /// external state may be used to decide which elements to keep.
     ///
     /// ```
     /// use std::collections::VecDeque;
@@ -2116,8 +2117,8 @@ pub fn append(&mut self, other: &mut Self) {
     /// buf.extend(1..6);
     ///
     /// let keep = [false, true, true, false, true];
-    /// let mut i = 0;
-    /// buf.retain(|_| (keep[i], i += 1).0);
+    /// let mut iter = keep.iter();
+    /// buf.retain(|_| *iter.next().unwrap());
     /// assert_eq!(buf, [2, 3, 5]);
     /// ```
     #[stable(feature = "vec_deque_retain", since = "1.4.0")]
index bc5ab3637ae6ce56f0c3e3e183b96f403306e4a4..5411316f55af0ebccccce55e096c2fad7595afab 100644 (file)
@@ -1350,13 +1350,14 @@ pub fn remove_matches<'a, P>(&'a mut self, pat: P)
     /// assert_eq!(s, "foobar");
     /// ```
     ///
-    /// The exact order may be useful for tracking external state, like an index.
+    /// Because the elements are visited exactly once in the original order,
+    /// external state may be used to decide which elements to keep.
     ///
     /// ```
     /// let mut s = String::from("abcde");
     /// let keep = [false, true, true, false, true];
-    /// let mut i = 0;
-    /// s.retain(|_| (keep[i], i += 1).0);
+    /// let mut iter = keep.iter();
+    /// s.retain(|_| *iter.next().unwrap());
     /// assert_eq!(s, "bce");
     /// ```
     #[inline]
index 5e7784730e3c9c56141712d816641ac68690c0bc..4784418f98c507d0313a14c314ac90191b1ce640 100644 (file)
@@ -5,6 +5,11 @@
 use super::from_u32_unchecked;
 
 /// An iterator that decodes UTF-16 encoded code points from an iterator of `u16`s.
+///
+/// This `struct` is created by the [`decode_utf16`] method on [`char`]. See its
+/// documentation for more.
+///
+/// [`decode_utf16`]: char::decode_utf16
 #[stable(feature = "decode_utf16", since = "1.9.0")]
 #[derive(Clone, Debug)]
 pub struct DecodeUtf16<I>
@@ -16,6 +21,8 @@ pub struct DecodeUtf16<I>
 }
 
 /// An error that can be returned when decoding UTF-16 code points.
+///
+/// This `struct` is created when using the [`DecodeUtf16`] type.
 #[stable(feature = "decode_utf16", since = "1.9.0")]
 #[derive(Debug, Clone, Eq, PartialEq)]
 pub struct DecodeUtf16Error {
index b660788c0515fb5b6d1d36f63b3da858b555788b..8e7b03d02f157db216cb9fb71440374600cfe997 100644 (file)
@@ -23,10 +23,7 @@ fn wrap<'slot, 'fmt: 'buf + 'slot>(
         slot: &'slot mut Option<Self>,
         state: &'state mut PadAdapterState,
     ) -> fmt::Formatter<'slot> {
-        fmt.wrap_buf(move |buf| {
-            *slot = Some(PadAdapter { buf, state });
-            slot.as_mut().unwrap()
-        })
+        fmt.wrap_buf(move |buf| slot.insert(PadAdapter { buf, state }))
     }
 }
 
index 0a609417dcf4cbedf8fe12d92dd9078d9f852946..ce7f6475d059914370b50d7768f3311cca539df7 100644 (file)
@@ -65,7 +65,7 @@ pub fn normalize(&self) -> Fp {
             f <<= 1;
             e -= 1;
         }
-        debug_assert!(f >= (1 >> 63));
+        debug_assert!(f >= (1 << 63));
         Fp { f, e }
     }
 
index 5c8c94971c33c0de8d4ad71d9f30910528eac37c..7f69ebbeb4de60df54a3317946568fd07f0e2a54 100644 (file)
@@ -939,7 +939,7 @@ fn from_inner(fd: c_int) -> File {
 
 impl fmt::Debug for File {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        #[cfg(target_os = "linux")]
+        #[cfg(any(target_os = "linux", target_os = "netbsd"))]
         fn get_path(fd: c_int) -> Option<PathBuf> {
             let mut p = PathBuf::from("/proc/self/fd");
             p.push(&fd.to_string());
@@ -976,7 +976,12 @@ fn get_path(fd: c_int) -> Option<PathBuf> {
             Some(PathBuf::from(OsString::from_vec(buf)))
         }
 
-        #[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "vxworks")))]
+        #[cfg(not(any(
+            target_os = "linux",
+            target_os = "macos",
+            target_os = "vxworks",
+            target_os = "netbsd"
+        )))]
         fn get_path(_fd: c_int) -> Option<PathBuf> {
             // FIXME(#24570): implement this for other Unix platforms
             None
index a549770d8b37823dd30112db435af4e2985a504d..e6a099f0e81a0ad141b1f2950e34ed78c8987db4 100644 (file)
@@ -75,7 +75,7 @@ unsafe fn _print_fmt(fmt: &mut fmt::Formatter<'_>, print_fmt: PrintFmt) -> fmt::
             hit = true;
             if print_fmt == PrintFmt::Short {
                 if let Some(sym) = symbol.name().and_then(|s| s.as_str()) {
-                    if sym.contains("__rust_begin_short_backtrace") {
+                    if start && sym.contains("__rust_begin_short_backtrace") {
                         stop = true;
                         return;
                     }
diff --git a/src/test/ui/closures/2229_closure_analysis/issue-87426.rs b/src/test/ui/closures/2229_closure_analysis/issue-87426.rs
new file mode 100644 (file)
index 0000000..7450697
--- /dev/null
@@ -0,0 +1,14 @@
+// run-pass
+// edition:2021
+
+pub fn foo() {
+    let ref_x_ck = 123;
+    let _y = || match ref_x_ck {
+        2_000_000..=3_999_999 => { println!("A")}
+        _ => { println!("B")}
+    };
+}
+
+fn main() {
+    foo();
+}
diff --git a/src/test/ui/panics/panic-short-backtrace-windows-x86_64.rs b/src/test/ui/panics/panic-short-backtrace-windows-x86_64.rs
new file mode 100644 (file)
index 0000000..fd01337
--- /dev/null
@@ -0,0 +1,49 @@
+// Regression test for #87481: short backtrace formatting cut off the entire stack trace.
+
+// Codegen-units is specified here so that we can replicate a typical rustc invocation which
+// is not normally limited to 1 CGU. This is important so that the `__rust_begin_short_backtrace`
+// and `__rust_end_short_backtrace` symbols are not marked internal to the CGU and thus will be
+// named in the symbol table.
+// compile-flags: -O -Ccodegen-units=8
+
+// run-fail
+// check-run-results
+// exec-env:RUST_BACKTRACE=1
+
+// We need to normalize out frame 5 because without debug info, dbghelp.dll doesn't know where CGU
+// internal functions like `main` start or end and so it will return whatever symbol happens
+// to be located near the address.
+// normalize-stderr-test: "5: .*" -> "5: some Rust fn"
+
+// Backtraces are pretty broken in general on i686-pc-windows-msvc (#62897).
+// only-x86_64-pc-windows-msvc
+
+fn main() {
+    a();
+}
+
+// Make these no_mangle so dbghelp.dll can figure out the symbol names.
+
+#[no_mangle]
+#[inline(never)]
+fn a() {
+    b();
+}
+
+#[no_mangle]
+#[inline(never)]
+fn b() {
+    c();
+}
+
+#[no_mangle]
+#[inline(never)]
+fn c() {
+    d();
+}
+
+#[no_mangle]
+#[inline(never)]
+fn d() {
+    panic!("d was called");
+}
diff --git a/src/test/ui/panics/panic-short-backtrace-windows-x86_64.run.stderr b/src/test/ui/panics/panic-short-backtrace-windows-x86_64.run.stderr
new file mode 100644 (file)
index 0000000..799a8b3
--- /dev/null
@@ -0,0 +1,9 @@
+thread 'main' panicked at 'd was called', $DIR/panic-short-backtrace-windows-x86_64.rs:48:5
+stack backtrace:
+   0: std::panicking::begin_panic
+   1: d
+   2: c
+   3: b
+   4: a
+   5: some Rust fn
+note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.