]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #66797 - mlodato517:mlodato517-array-doc-typo, r=Dylan-DPC
authorTyler Mandry <tmandry@gmail.com>
Wed, 27 Nov 2019 21:28:51 +0000 (15:28 -0600)
committerGitHub <noreply@github.com>
Wed, 27 Nov 2019 21:28:51 +0000 (15:28 -0600)
Fixes small typo in array docs r? @steveklabnik

Fixes a small typo in the array documentation.

Also, wasn't sure which [message](https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#pull-requests) to put this in, and will definitely update the commit message if it is supposed to be the PR description but for "safety" - r? @steveklabnik

291 files changed:
src/doc/rustdoc/src/documentation-tests.md
src/liballoc/boxed.rs
src/liballoc/rc.rs
src/liballoc/sync.rs
src/liballoc/vec.rs
src/libcore/ascii.rs
src/libcore/char/convert.rs
src/libcore/char/decode.rs
src/libcore/char/methods.rs
src/libcore/char/mod.rs
src/libcore/clone.rs
src/libcore/cmp.rs
src/libcore/convert.rs
src/libcore/default.rs
src/libcore/ffi.rs
src/libcore/fmt/float.rs
src/libcore/fmt/mod.rs
src/libcore/hash/mod.rs
src/libcore/hash/sip.rs
src/libcore/iter/adapters/flatten.rs
src/libcore/iter/sources.rs
src/libcore/iter/traits/accum.rs
src/libcore/iter/traits/double_ended.rs
src/libcore/macros/mod.rs
src/libcore/mem/manually_drop.rs
src/libcore/num/bignum.rs
src/libcore/num/dec2flt/algorithm.rs
src/libcore/num/dec2flt/mod.rs
src/libcore/num/dec2flt/num.rs
src/libcore/num/dec2flt/parse.rs
src/libcore/num/dec2flt/rawfp.rs
src/libcore/num/diy_float.rs
src/libcore/num/f32.rs
src/libcore/num/f64.rs
src/libcore/num/flt2dec/decoder.rs
src/libcore/num/flt2dec/mod.rs
src/libcore/num/flt2dec/strategy/dragon.rs
src/libcore/num/flt2dec/strategy/grisu.rs
src/libcore/num/wrapping.rs
src/libcore/ops/arith.rs
src/libcore/ops/bit.rs
src/libcore/ops/deref.rs
src/libcore/ops/function.rs
src/libcore/ops/index.rs
src/libcore/ops/mod.rs
src/libcore/ops/range.rs
src/libcore/ops/unsize.rs
src/libcore/option.rs
src/libcore/pin.rs
src/libcore/prelude/v1.rs
src/libcore/ptr/non_null.rs
src/libcore/ptr/unique.rs
src/libcore/slice/sort.rs
src/libcore/task/mod.rs
src/libcore/task/poll.rs
src/libcore/task/wake.rs
src/libcore/time.rs
src/libcore/tuple.rs
src/libcore/unicode/bool_trie.rs
src/libcore/unit.rs
src/librustc/infer/error_reporting/mod.rs
src/librustc/mir/interpret/value.rs
src/librustc/mir/mod.rs
src/librustc/mir/visit.rs
src/librustc/session/config.rs
src/librustc/traits/error_reporting.rs
src/librustc/util/common.rs
src/librustc_codegen_llvm/builder.rs
src/librustc_codegen_llvm/consts.rs
src/librustc_codegen_llvm/debuginfo/create_scope_map.rs
src/librustc_codegen_llvm/debuginfo/metadata.rs
src/librustc_codegen_llvm/intrinsic.rs
src/librustc_codegen_ssa/mir/analyze.rs
src/librustc_codegen_ssa/mir/debuginfo.rs
src/librustc_codegen_ssa/mir/mod.rs
src/librustc_error_codes/error_codes/E0015.md
src/librustc_error_codes/error_codes/E0062.md
src/librustc_error_codes/error_codes/E0063.md
src/librustc_error_codes/error_codes/E0067.md
src/librustc_error_codes/error_codes/E0069.md
src/librustc_error_codes/error_codes/E0070.md
src/librustc_error_codes/error_codes/E0071.md
src/librustc_error_codes/error_codes/E0072.md
src/librustc_error_codes/error_codes/E0075.md
src/librustc_error_codes/error_codes/E0076.md
src/librustc_error_codes/error_codes/E0077.md
src/librustc_error_codes/error_codes/E0107.md
src/librustc_error_codes/error_codes/E0369.md
src/librustc_error_codes/error_codes/E0404.md
src/librustc_error_codes/error_codes/E0458.md
src/librustc_error_codes/error_codes/E0633.md
src/librustc_error_codes/error_codes/E0635.md
src/librustc_error_codes/error_codes/E0636.md
src/librustc_error_codes/error_codes/E0641.md
src/librustc_error_codes/error_codes/E0644.md
src/librustc_error_codes/error_codes/E0706.md
src/librustc_error_codes/error_codes/E0745.md
src/librustc_errors/lib.rs
src/librustc_lint/types.rs
src/librustc_metadata/creader.rs
src/librustc_metadata/rmeta/decoder.rs
src/librustc_metadata/rmeta/encoder.rs
src/librustc_metadata/rmeta/mod.rs
src/librustc_metadata/rmeta/table.rs
src/librustc_mir/borrow_check/conflict_errors.rs
src/librustc_mir/borrow_check/error_reporting.rs
src/librustc_mir/borrow_check/mod.rs
src/librustc_mir/borrow_check/move_errors.rs
src/librustc_mir/borrow_check/mutability_errors.rs
src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs
src/librustc_mir/borrow_check/nll/mod.rs
src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs
src/librustc_mir/borrow_check/nll/region_infer/error_reporting/outlives_suggestion.rs
src/librustc_mir/borrow_check/nll/region_infer/error_reporting/region_name.rs
src/librustc_mir/borrow_check/nll/region_infer/error_reporting/var_name.rs
src/librustc_mir/borrow_check/nll/region_infer/mod.rs
src/librustc_mir/borrow_check/nll/type_check/input_output.rs
src/librustc_mir/build/expr/into.rs
src/librustc_mir/build/matches/mod.rs
src/librustc_mir/build/matches/simplify.rs
src/librustc_mir/build/mod.rs
src/librustc_mir/interpret/eval_context.rs
src/librustc_mir/interpret/intern.rs
src/librustc_mir/interpret/memory.rs
src/librustc_mir/interpret/operand.rs
src/librustc_mir/lib.rs
src/librustc_mir/shim.rs
src/librustc_mir/transform/const_prop.rs
src/librustc_mir/transform/generator.rs
src/librustc_mir/transform/inline.rs
src/librustc_mir/transform/promote_consts.rs
src/librustc_mir/transform/qualify_min_const_fn.rs
src/librustc_mir/transform/simplify.rs
src/librustc_mir/transform/uniform_array_move_out.rs
src/librustc_mir/util/def_use.rs
src/librustc_mir/util/graphviz.rs
src/librustc_mir/util/liveness.rs
src/librustc_mir/util/pretty.rs
src/librustc_parse/parser/item.rs
src/librustc_parse/parser/mod.rs
src/librustc_passes/loops.rs
src/librustc_resolve/resolve_imports.rs
src/librustc_target/spec/aarch64_pc_windows_msvc.rs
src/librustc_target/spec/hermit_kernel_base.rs [new file with mode: 0644]
src/librustc_target/spec/mod.rs
src/librustc_target/spec/riscv64gc_unknown_linux_gnu.rs [new file with mode: 0644]
src/librustc_target/spec/x86_64_unknown_hermit_kernel.rs [new file with mode: 0644]
src/librustc_typeck/check/mod.rs
src/librustc_typeck/check/wfcheck.rs
src/librustdoc/passes/collect_intra_doc_links.rs
src/librustdoc/passes/mod.rs
src/libsyntax/ast.rs
src/libsyntax/feature_gate/check.rs
src/libsyntax_expand/mbe/macro_check.rs
src/libsyntax_ext/format.rs
src/libsyntax_ext/proc_macro_harness.rs
src/rustllvm/PassWrapper.cpp
src/test/incremental/hashes/for_loops.rs
src/test/incremental/hashes/let_expressions.rs
src/test/incremental/hashes/loop_expressions.rs
src/test/incremental/hashes/while_loops.rs
src/test/mir-opt/box_expr.rs
src/test/mir-opt/const_prop/const_prop_fails_gracefully.rs
src/test/mir-opt/const_prop/ref_deref.rs
src/test/mir-opt/const_prop/reify_fn_ptr.rs
src/test/mir-opt/const_prop/slice_len.rs
src/test/mir-opt/generator-storage-dead-unwind.rs
src/test/mir-opt/inline-closure-borrows-arg.rs
src/test/mir-opt/inline-closure-captures.rs [new file with mode: 0644]
src/test/mir-opt/inline-closure.rs
src/test/mir-opt/issue-41110.rs
src/test/mir-opt/issue-41888.rs
src/test/mir-opt/issue-49232.rs
src/test/mir-opt/match-arm-scopes.rs
src/test/mir-opt/nll/region-subtyping-basic.rs
src/test/mir-opt/packed-struct-drop-aligned.rs
src/test/mir-opt/simplify_try.rs
src/test/rustdoc-ui/deny-intra-link-resolution-failure.stderr
src/test/rustdoc-ui/doc-without-codeblock.rs
src/test/rustdoc-ui/doc-without-codeblock.stderr
src/test/rustdoc-ui/intra-doc-alias-ice.stderr
src/test/rustdoc-ui/intra-link-span-ice-55723.rs
src/test/rustdoc-ui/intra-link-span-ice-55723.stderr
src/test/rustdoc-ui/intra-links-anchors.rs [new file with mode: 0644]
src/test/rustdoc-ui/intra-links-anchors.stderr [new file with mode: 0644]
src/test/rustdoc-ui/intra-links-warning-crlf.stderr
src/test/rustdoc-ui/intra-links-warning.stderr
src/test/rustdoc-ui/lint-group.rs
src/test/rustdoc-ui/lint-group.stderr
src/test/rustdoc-ui/lint-missing-doc-code-example.stderr
src/test/rustdoc-ui/private-item-doc-test.rs
src/test/rustdoc-ui/private-item-doc-test.stderr
src/test/rustdoc/intra-doc-link-enum-struct-field.rs [new file with mode: 0644]
src/test/rustdoc/intra-links-anchors.rs [new file with mode: 0644]
src/test/ui/allocator/two-allocators.stderr
src/test/ui/borrowck/borrowck-move-error-with-note.stderr
src/test/ui/borrowck/borrowck-move-out-of-vec-tail.stderr
src/test/ui/borrowck/borrowck-vec-pattern-nesting.rs
src/test/ui/borrowck/borrowck-vec-pattern-nesting.stderr
src/test/ui/consts/control-flow/exhaustive-c-like-enum-match.rs [new file with mode: 0644]
src/test/ui/consts/control-flow/single-arm-match-wild.rs [new file with mode: 0644]
src/test/ui/consts/issue-66345.rs [new file with mode: 0644]
src/test/ui/if/ifmt-bad-arg.stderr
src/test/ui/issues/issue-12567.stderr
src/test/ui/issues/issue-40402-ref-hints/issue-40402-2.stderr
src/test/ui/label/label_break_value_continue.stderr
src/test/ui/lint/lint-ctypes.rs
src/test/ui/lint/lint-ctypes.stderr
src/test/ui/macros/macro-multiple-matcher-bindings.stderr
src/test/ui/macros/macro-reexport-removed.stderr
src/test/ui/macros/unknown-builtin.stderr
src/test/ui/nll/move-errors.stderr
src/test/ui/on-unimplemented/expected-comma-found-token.stderr
src/test/ui/parser/pat-lt-bracket-6.stderr
src/test/ui/parser/pat-lt-bracket-7.stderr
src/test/ui/parser/recover-enum.rs
src/test/ui/parser/recover-enum.stderr
src/test/ui/rfc-2008-non-exhaustive/auxiliary/monovariants.rs [new file with mode: 0644]
src/test/ui/rfc-2008-non-exhaustive/borrowck-exhaustive.rs [new file with mode: 0644]
src/test/ui/rfc-2008-non-exhaustive/borrowck-non-exhaustive.rs [new file with mode: 0644]
src/test/ui/rfc-2008-non-exhaustive/borrowck-non-exhaustive.stderr [new file with mode: 0644]
src/test/ui/self/arbitrary-self-types-not-object-safe.curr.stderr
src/test/ui/self/arbitrary-self-types-not-object-safe.object_safe_for_dispatch.stderr
src/test/ui/self/arbitrary-self-types-not-object-safe.rs
src/test/ui/self/arbitrary-self-types-not-object-safe.stderr
src/test/ui/self/arbitrary_self_types_nested.rs [new file with mode: 0644]
src/test/ui/self/arbitrary_self_types_struct.rs
src/test/ui/self/arbitrary_self_types_trait.rs
src/test/ui/self/arbitrary_self_types_unsized_struct.rs
src/test/ui/self/elision/alias-async.rs
src/test/ui/self/elision/alias.rs
src/test/ui/self/elision/assoc-async.rs
src/test/ui/self/elision/assoc.rs
src/test/ui/self/elision/lt-alias-async.rs
src/test/ui/self/elision/lt-alias.rs
src/test/ui/self/elision/lt-assoc-async.rs
src/test/ui/self/elision/lt-assoc.rs
src/test/ui/self/elision/lt-ref-self-async.nll.stderr
src/test/ui/self/elision/lt-ref-self-async.rs
src/test/ui/self/elision/lt-ref-self-async.stderr
src/test/ui/self/elision/lt-ref-self.nll.stderr
src/test/ui/self/elision/lt-ref-self.rs
src/test/ui/self/elision/lt-ref-self.stderr
src/test/ui/self/elision/lt-self-async.rs
src/test/ui/self/elision/lt-self.rs
src/test/ui/self/elision/lt-struct-async.rs
src/test/ui/self/elision/lt-struct.rs
src/test/ui/self/elision/ref-alias-async.rs
src/test/ui/self/elision/ref-alias.rs
src/test/ui/self/elision/ref-assoc-async.rs
src/test/ui/self/elision/ref-assoc.rs
src/test/ui/self/elision/ref-mut-alias-async.rs
src/test/ui/self/elision/ref-mut-alias.rs
src/test/ui/self/elision/ref-mut-self-async.nll.stderr
src/test/ui/self/elision/ref-mut-self-async.rs
src/test/ui/self/elision/ref-mut-self-async.stderr
src/test/ui/self/elision/ref-mut-self.nll.stderr
src/test/ui/self/elision/ref-mut-self.rs
src/test/ui/self/elision/ref-mut-self.stderr
src/test/ui/self/elision/ref-mut-struct-async.nll.stderr
src/test/ui/self/elision/ref-mut-struct-async.rs
src/test/ui/self/elision/ref-mut-struct-async.stderr
src/test/ui/self/elision/ref-mut-struct.nll.stderr
src/test/ui/self/elision/ref-mut-struct.rs
src/test/ui/self/elision/ref-mut-struct.stderr
src/test/ui/self/elision/ref-self-async.nll.stderr
src/test/ui/self/elision/ref-self-async.rs
src/test/ui/self/elision/ref-self-async.stderr
src/test/ui/self/elision/ref-struct-async.nll.stderr
src/test/ui/self/elision/ref-struct-async.rs
src/test/ui/self/elision/ref-struct-async.stderr
src/test/ui/self/elision/ref-struct.nll.stderr
src/test/ui/self/elision/ref-struct.rs
src/test/ui/self/elision/ref-struct.stderr
src/test/ui/self/elision/self-async.rs
src/test/ui/self/elision/self.rs
src/test/ui/self/elision/struct-async.rs
src/test/ui/self/elision/struct.rs
src/test/ui/similar-tokens.stderr
src/test/ui/suggestions/dont-suggest-ref/duplicate-suggestions.stderr
src/test/ui/suggestions/dont-suggest-ref/simple.stderr
src/test/ui/tuple/tuple-struct-fields/test.stderr
src/test/ui/tuple/tuple-struct-fields/test2.stderr
src/test/ui/tuple/tuple-struct-fields/test3.stderr
src/test/ui/type-alias-impl-trait/issue-63263-closure-return.rs [new file with mode: 0644]
src/test/ui/type/type-mismatch-same-crate-name.rs
src/test/ui/type/type-mismatch-same-crate-name.stderr
src/test/ui/unsized/unsized-fn-param.rs [new file with mode: 0644]
src/test/ui/unsized/unsized-fn-param.stderr [new file with mode: 0644]
src/tools/tidy/src/features.rs
src/tools/tidy/src/style.rs

index bc1da5ff15a8c2de2557c5ce49720c006adab2a8..96fa4344b04b726525805979156a6a12ba25219a 100644 (file)
@@ -1,7 +1,7 @@
 # Documentation tests
 
 `rustdoc` supports executing your documentation examples as tests. This makes sure
-that your tests are up to date and working.
+that examples within your documentation are up to date and working.
 
 The basic idea is this:
 
index 567b8ea722491edbe2c9bfe9218b1632038dbc92..51ad3a04e87fe6b7791ce14af0ff204f094b864b 100644 (file)
@@ -152,6 +152,33 @@ pub fn new_uninit() -> Box<mem::MaybeUninit<T>> {
         Box(ptr.cast().into())
     }
 
+    /// Constructs a new `Box` with uninitialized contents, with the memory
+    /// being filled with `0` bytes.
+    ///
+    /// See [`MaybeUninit::zeroed`][zeroed] for examples of correct and incorrect usage
+    /// of this method.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// #![feature(new_uninit)]
+    ///
+    /// let zero = Box::<u32>::new_zeroed();
+    /// let zero = unsafe { zero.assume_init() };
+    ///
+    /// assert_eq!(*zero, 0)
+    /// ```
+    ///
+    /// [zeroed]: ../../std/mem/union.MaybeUninit.html#method.zeroed
+    #[unstable(feature = "new_uninit", issue = "63291")]
+    pub fn new_zeroed() -> Box<mem::MaybeUninit<T>> {
+        unsafe {
+            let mut uninit = Self::new_uninit();
+            ptr::write_bytes::<T>(uninit.as_mut_ptr(), 0, 1);
+            uninit
+        }
+    }
+
     /// Constructs a new `Pin<Box<T>>`. If `T` does not implement `Unpin`, then
     /// `x` will be pinned in memory and unable to be moved.
     #[stable(feature = "pin", since = "1.33.0")]
index a11f9e8c145799c707f009cbbf0552230fd2bd5f..ec08965674ad7d62f223c39d4f33d8aed7194109 100644 (file)
@@ -361,6 +361,35 @@ pub fn new_uninit() -> Rc<mem::MaybeUninit<T>> {
         }
     }
 
+    /// Constructs a new `Rc` with uninitialized contents, with the memory
+    /// being filled with `0` bytes.
+    ///
+    /// See [`MaybeUninit::zeroed`][zeroed] for examples of correct and
+    /// incorrect usage of this method.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// #![feature(new_uninit)]
+    ///
+    /// use std::rc::Rc;
+    ///
+    /// let zero = Rc::<u32>::new_zeroed();
+    /// let zero = unsafe { zero.assume_init() };
+    ///
+    /// assert_eq!(*zero, 0)
+    /// ```
+    ///
+    /// [zeroed]: ../../std/mem/union.MaybeUninit.html#method.zeroed
+    #[unstable(feature = "new_uninit", issue = "63291")]
+    pub fn new_zeroed() -> Rc<mem::MaybeUninit<T>> {
+        unsafe {
+            let mut uninit = Self::new_uninit();
+            ptr::write_bytes::<T>(Rc::get_mut_unchecked(&mut uninit).as_mut_ptr(), 0, 1);
+            uninit
+        }
+    }
+
     /// Constructs a new `Pin<Rc<T>>`. If `T` does not implement `Unpin`, then
     /// `value` will be pinned in memory and unable to be moved.
     #[stable(feature = "pin", since = "1.33.0")]
index 4b10f089c2950f3ad4213e686e60ac1ba456628d..0deb321d6231f7ced4deefa306fed276b4ce4e68 100644 (file)
@@ -341,6 +341,35 @@ pub fn new_uninit() -> Arc<mem::MaybeUninit<T>> {
         }
     }
 
+    /// Constructs a new `Arc` with uninitialized contents, with the memory
+    /// being filled with `0` bytes.
+    ///
+    /// See [`MaybeUninit::zeroed`][zeroed] for examples of correct and incorrect usage
+    /// of this method.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// #![feature(new_uninit)]
+    ///
+    /// use std::sync::Arc;
+    ///
+    /// let zero = Arc::<u32>::new_zeroed();
+    /// let zero = unsafe { zero.assume_init() };
+    ///
+    /// assert_eq!(*zero, 0)
+    /// ```
+    ///
+    /// [zeroed]: ../../std/mem/union.MaybeUninit.html#method.zeroed
+    #[unstable(feature = "new_uninit", issue = "63291")]
+    pub fn new_zeroed() -> Arc<mem::MaybeUninit<T>> {
+        unsafe {
+            let mut uninit = Self::new_uninit();
+            ptr::write_bytes::<T>(Arc::get_mut_unchecked(&mut uninit).as_mut_ptr(), 0, 1);
+            uninit
+        }
+    }
+
     /// Constructs a new `Pin<Arc<T>>`. If `T` does not implement `Unpin`, then
     /// `data` will be pinned in memory and unable to be moved.
     #[stable(feature = "pin", since = "1.33.0")]
index 07e4358d644c61fd4cb11a51d2180bef2f06aa91..da31ed178f441f7fc339398af1482828a9218080 100644 (file)
@@ -629,6 +629,8 @@ pub fn shrink_to_fit(&mut self) {
     /// The capacity will remain at least as large as both the length
     /// and the supplied value.
     ///
+    /// # Panics
+    ///
     /// Panics if the current capacity is smaller than the supplied
     /// minimum capacity.
     ///
index 9b588525bd6982775644f7035e3641141388ebe6..e78dfd1ed4abfca43a6b2d1d304b78ff505790ca 100644 (file)
@@ -12,8 +12,8 @@
 #![stable(feature = "core_ascii", since = "1.26.0")]
 
 use crate::fmt;
-use crate::ops::Range;
 use crate::iter::FusedIterator;
+use crate::ops::Range;
 use crate::str::from_utf8_unchecked;
 
 /// An iterator over the escaped version of a byte.
@@ -100,7 +100,7 @@ pub fn escape_default(c: u8) -> EscapeDefault {
         b'\\' => ([b'\\', b'\\', 0, 0], 2),
         b'\'' => ([b'\\', b'\'', 0, 0], 2),
         b'"' => ([b'\\', b'"', 0, 0], 2),
-        b'\x20' ..= b'\x7e' => ([c, 0, 0, 0], 1),
+        b'\x20'..=b'\x7e' => ([c, 0, 0, 0], 1),
         _ => ([b'\\', b'x', hexify(c >> 4), hexify(c & 0xf)], 4),
     };
 
@@ -108,7 +108,7 @@ pub fn escape_default(c: u8) -> EscapeDefault {
 
     fn hexify(b: u8) -> u8 {
         match b {
-            0 ..= 9 => b'0' + b,
+            0..=9 => b'0' + b,
             _ => b'a' + b - 10,
         }
     }
@@ -117,9 +117,15 @@ fn hexify(b: u8) -> u8 {
 #[stable(feature = "rust1", since = "1.0.0")]
 impl Iterator for EscapeDefault {
     type Item = u8;
-    fn next(&mut self) -> Option<u8> { self.range.next().map(|i| self.data[i]) }
-    fn size_hint(&self) -> (usize, Option<usize>) { self.range.size_hint() }
-    fn last(mut self) -> Option<u8> { self.next_back() }
+    fn next(&mut self) -> Option<u8> {
+        self.range.next().map(|i| self.data[i])
+    }
+    fn size_hint(&self) -> (usize, Option<usize>) {
+        self.range.size_hint()
+    }
+    fn last(mut self) -> Option<u8> {
+        self.next_back()
+    }
 }
 #[stable(feature = "rust1", since = "1.0.0")]
 impl DoubleEndedIterator for EscapeDefault {
index 28f520744956135539159da9449d148c0833d0b6..dd21c72e745dd70498f59caf1220b999ff4be538 100644 (file)
@@ -158,7 +158,6 @@ fn from(i: u8) -> Self {
     }
 }
 
-
 /// An error which can be returned when parsing a char.
 #[stable(feature = "char_from_str", since = "1.20.0")]
 #[derive(Clone, Debug, PartialEq, Eq)]
@@ -167,16 +166,16 @@ pub struct ParseCharError {
 }
 
 impl ParseCharError {
-    #[unstable(feature = "char_error_internals",
-               reason = "this method should not be available publicly",
-               issue = "0")]
+    #[unstable(
+        feature = "char_error_internals",
+        reason = "this method should not be available publicly",
+        issue = "0"
+    )]
     #[doc(hidden)]
     pub fn __description(&self) -> &str {
         match self.kind {
-            CharErrorKind::EmptyString => {
-                "cannot parse char from empty string"
-            },
-            CharErrorKind::TooManyChars => "too many characters in string"
+            CharErrorKind::EmptyString => "cannot parse char from empty string",
+            CharErrorKind::TooManyChars => "too many characters in string",
         }
     }
 }
@@ -194,7 +193,6 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
     }
 }
 
-
 #[stable(feature = "char_from_str", since = "1.20.0")]
 impl FromStr for char {
     type Err = ParseCharError;
@@ -203,18 +201,13 @@ impl FromStr for char {
     fn from_str(s: &str) -> Result<Self, Self::Err> {
         let mut chars = s.chars();
         match (chars.next(), chars.next()) {
-            (None, _) => {
-                Err(ParseCharError { kind: CharErrorKind::EmptyString })
-            },
+            (None, _) => Err(ParseCharError { kind: CharErrorKind::EmptyString }),
             (Some(c), None) => Ok(c),
-            _ => {
-                Err(ParseCharError { kind: CharErrorKind::TooManyChars })
-            }
+            _ => Err(ParseCharError { kind: CharErrorKind::TooManyChars }),
         }
     }
 }
 
-
 #[stable(feature = "try_from", since = "1.34.0")]
 impl TryFrom<u32> for char {
     type Error = CharTryFromError;
@@ -304,11 +297,7 @@ pub fn from_digit(num: u32, radix: u32) -> Option<char> {
     }
     if num < radix {
         let num = num as u8;
-        if num < 10 {
-            Some((b'0' + num) as char)
-        } else {
-            Some((b'a' + num - 10) as char)
-        }
+        if num < 10 { Some((b'0' + num) as char) } else { Some((b'a' + num - 10) as char) }
     } else {
         None
     }
index ae09251c776de4e9d2b352054b6aec9b255b5773..5e7784730e3c9c56141712d816641ac68690c0bc 100644 (file)
@@ -8,7 +8,8 @@
 #[stable(feature = "decode_utf16", since = "1.9.0")]
 #[derive(Clone, Debug)]
 pub struct DecodeUtf16<I>
-    where I: Iterator<Item = u16>
+where
+    I: Iterator<Item = u16>,
 {
     iter: I,
     buf: Option<u16>,
@@ -70,10 +71,7 @@ pub struct DecodeUtf16Error {
 #[stable(feature = "decode_utf16", since = "1.9.0")]
 #[inline]
 pub fn decode_utf16<I: IntoIterator<Item = u16>>(iter: I) -> DecodeUtf16<I::IntoIter> {
-    DecodeUtf16 {
-        iter: iter.into_iter(),
-        buf: None,
-    }
+    DecodeUtf16 { iter: iter.into_iter(), buf: None }
 }
 
 #[stable(feature = "decode_utf16", since = "1.9.0")]
@@ -83,7 +81,7 @@ impl<I: Iterator<Item = u16>> Iterator for DecodeUtf16<I> {
     fn next(&mut self) -> Option<Result<char, DecodeUtf16Error>> {
         let u = match self.buf.take() {
             Some(buf) => buf,
-            None => self.iter.next()?
+            None => self.iter.next()?,
         };
 
         if u < 0xD800 || 0xDFFF < u {
index c048bab287dd2aa0408f639689ce19fb4622f105..1ec614edbe2ebdd1d67728e2e613fcda3f946489 100644 (file)
@@ -130,11 +130,7 @@ pub fn to_digit(self, radix: u32) -> Option<u32> {
             }
         };
 
-        if val < radix {
-            Some(val)
-        } else {
-            None
-        }
+        if val < radix { Some(val) } else { None }
     }
 
     /// Returns an iterator that yields the hexadecimal Unicode escape of a
@@ -950,11 +946,7 @@ pub const fn is_ascii(&self) -> bool {
     #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
     #[inline]
     pub fn to_ascii_uppercase(&self) -> char {
-        if self.is_ascii() {
-            (*self as u8).to_ascii_uppercase() as char
-        } else {
-            *self
-        }
+        if self.is_ascii() { (*self as u8).to_ascii_uppercase() as char } else { *self }
     }
 
     /// Makes a copy of the value in its ASCII lower case equivalent.
@@ -982,11 +974,7 @@ pub fn to_ascii_uppercase(&self) -> char {
     #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
     #[inline]
     pub fn to_ascii_lowercase(&self) -> char {
-        if self.is_ascii() {
-            (*self as u8).to_ascii_lowercase() as char
-        } else {
-            *self
-        }
+        if self.is_ascii() { (*self as u8).to_ascii_lowercase() as char } else { *self }
     }
 
     /// Checks that two values are an ASCII case-insensitive match.
index dedd2f758b6cb299336ccb15373165bd0a98f2fc..a655ee6e7e32ae542c353662dadeea32a4194930 100644 (file)
 mod methods;
 
 // stable re-exports
-#[stable(feature = "rust1", since = "1.0.0")]
-pub use self::convert::{from_u32, from_digit};
 #[stable(feature = "char_from_unchecked", since = "1.5.0")]
 pub use self::convert::from_u32_unchecked;
-#[stable(feature = "char_from_str", since = "1.20.0")]
-pub use self::convert::ParseCharError;
 #[stable(feature = "try_from", since = "1.34.0")]
 pub use self::convert::CharTryFromError;
+#[stable(feature = "char_from_str", since = "1.20.0")]
+pub use self::convert::ParseCharError;
+#[stable(feature = "rust1", since = "1.0.0")]
+pub use self::convert::{from_digit, from_u32};
 #[stable(feature = "decode_utf16", since = "1.9.0")]
 pub use self::decode::{decode_utf16, DecodeUtf16, DecodeUtf16Error};
 
 use crate::iter::FusedIterator;
 
 // UTF-8 ranges and tags for encoding characters
-const TAG_CONT: u8     = 0b1000_0000;
-const TAG_TWO_B: u8    = 0b1100_0000;
-const TAG_THREE_B: u8  = 0b1110_0000;
-const TAG_FOUR_B: u8   = 0b1111_0000;
-const MAX_ONE_B: u32   =     0x80;
-const MAX_TWO_B: u32   =    0x800;
-const MAX_THREE_B: u32 =  0x10000;
+const TAG_CONT: u8 = 0b1000_0000;
+const TAG_TWO_B: u8 = 0b1100_0000;
+const TAG_THREE_B: u8 = 0b1110_0000;
+const TAG_FOUR_B: u8 = 0b1111_0000;
+const MAX_ONE_B: u32 = 0x80;
+const MAX_TWO_B: u32 = 0x800;
+const MAX_THREE_B: u32 = 0x10000;
 
 /*
     Lu  Uppercase_Letter        an uppercase letter
@@ -190,11 +190,11 @@ fn last(self) -> Option<char> {
         match self.state {
             EscapeUnicodeState::Done => None,
 
-            EscapeUnicodeState::RightBrace |
-            EscapeUnicodeState::Value |
-            EscapeUnicodeState::LeftBrace |
-            EscapeUnicodeState::Type |
-            EscapeUnicodeState::Backslash => Some('}'),
+            EscapeUnicodeState::RightBrace
+            | EscapeUnicodeState::Value
+            | EscapeUnicodeState::LeftBrace
+            | EscapeUnicodeState::Type
+            EscapeUnicodeState::Backslash => Some('}'),
         }
     }
 }
@@ -204,14 +204,15 @@ impl ExactSizeIterator for EscapeUnicode {
     #[inline]
     fn len(&self) -> usize {
         // The match is a single memory access with no branching
-        self.hex_digit_idx + match self.state {
-            EscapeUnicodeState::Done => 0,
-            EscapeUnicodeState::RightBrace => 1,
-            EscapeUnicodeState::Value => 2,
-            EscapeUnicodeState::LeftBrace => 3,
-            EscapeUnicodeState::Type => 4,
-            EscapeUnicodeState::Backslash => 5,
-        }
+        self.hex_digit_idx
+            + match self.state {
+                EscapeUnicodeState::Done => 0,
+                EscapeUnicodeState::RightBrace => 1,
+                EscapeUnicodeState::Value => 2,
+                EscapeUnicodeState::LeftBrace => 3,
+                EscapeUnicodeState::Type => 4,
+                EscapeUnicodeState::Backslash => 5,
+            }
     }
 }
 
@@ -238,7 +239,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 #[derive(Clone, Debug)]
 #[stable(feature = "rust1", since = "1.0.0")]
 pub struct EscapeDefault {
-    state: EscapeDefaultState
+    state: EscapeDefaultState,
 }
 
 #[derive(Clone, Debug)]
@@ -284,24 +285,20 @@ fn nth(&mut self, n: usize) -> Option<char> {
             EscapeDefaultState::Backslash(c) if n == 0 => {
                 self.state = EscapeDefaultState::Char(c);
                 Some('\\')
-            },
+            }
             EscapeDefaultState::Backslash(c) if n == 1 => {
                 self.state = EscapeDefaultState::Done;
                 Some(c)
-            },
+            }
             EscapeDefaultState::Backslash(_) => {
                 self.state = EscapeDefaultState::Done;
                 None
-            },
+            }
             EscapeDefaultState::Char(c) => {
                 self.state = EscapeDefaultState::Done;
 
-                if n == 0 {
-                    Some(c)
-                } else {
-                    None
-                }
-            },
+                if n == 0 { Some(c) } else { None }
+            }
             EscapeDefaultState::Done => None,
             EscapeDefaultState::Unicode(ref mut i) => i.nth(n),
         }
@@ -355,12 +352,16 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 #[stable(feature = "char_escape_debug", since = "1.20.0")]
 impl Iterator for EscapeDebug {
     type Item = char;
-    fn next(&mut self) -> Option<char> { self.0.next() }
-    fn size_hint(&self) -> (usize, Option<usize>) { self.0.size_hint() }
+    fn next(&mut self) -> Option<char> {
+        self.0.next()
+    }
+    fn size_hint(&self) -> (usize, Option<usize>) {
+        self.0.size_hint()
+    }
 }
 
 #[stable(feature = "char_escape_debug", since = "1.20.0")]
-impl ExactSizeIterator for EscapeDebug { }
+impl ExactSizeIterator for EscapeDebug {}
 
 #[stable(feature = "fused", since = "1.26.0")]
 impl FusedIterator for EscapeDebug {}
@@ -440,7 +441,7 @@ impl CaseMappingIter {
     fn new(chars: [char; 3]) -> CaseMappingIter {
         if chars[2] == '\0' {
             if chars[1] == '\0' {
-                CaseMappingIter::One(chars[0])  // Including if chars[0] == '\0'
+                CaseMappingIter::One(chars[0]) // Including if chars[0] == '\0'
             } else {
                 CaseMappingIter::Two(chars[0], chars[1])
             }
@@ -493,9 +494,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
                 f.write_char(b)?;
                 f.write_char(c)
             }
-            CaseMappingIter::One(c) => {
-                f.write_char(c)
-            }
+            CaseMappingIter::One(c) => f.write_char(c),
             CaseMappingIter::Zero => Ok(()),
         }
     }
index 86dd77f10f324f5a84812685a19427679fdbce67..6e7a46ba62aabf2c39f77e0103d5cd6a13650d56 100644 (file)
 /// [impls]: #implementors
 #[stable(feature = "rust1", since = "1.0.0")]
 #[lang = "clone"]
-pub trait Clone : Sized {
+pub trait Clone: Sized {
     /// Returns a copy of the value.
     ///
     /// # Examples
@@ -137,7 +137,9 @@ fn clone_from(&mut self, source: &Self) {
 #[rustc_builtin_macro]
 #[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
 #[allow_internal_unstable(core_intrinsics, derive_clone_copy)]
-pub macro Clone($item:item) { /* compiler built-in */ }
+pub macro Clone($item:item) {
+    /* compiler built-in */
+}
 
 // FIXME(aburka): these structs are used solely by #[derive] to
 // assert that every component of a type implements Clone or Copy.
@@ -145,16 +147,24 @@ fn clone_from(&mut self, source: &Self) {
 // These structs should never appear in user code.
 #[doc(hidden)]
 #[allow(missing_debug_implementations)]
-#[unstable(feature = "derive_clone_copy",
-           reason = "deriving hack, should not be public",
-           issue = "0")]
-pub struct AssertParamIsClone<T: Clone + ?Sized> { _field: crate::marker::PhantomData<T> }
+#[unstable(
+    feature = "derive_clone_copy",
+    reason = "deriving hack, should not be public",
+    issue = "0"
+)]
+pub struct AssertParamIsClone<T: Clone + ?Sized> {
+    _field: crate::marker::PhantomData<T>,
+}
 #[doc(hidden)]
 #[allow(missing_debug_implementations)]
-#[unstable(feature = "derive_clone_copy",
-           reason = "deriving hack, should not be public",
-           issue = "0")]
-pub struct AssertParamIsCopy<T: Copy + ?Sized> { _field: crate::marker::PhantomData<T> }
+#[unstable(
+    feature = "derive_clone_copy",
+    reason = "deriving hack, should not be public",
+    issue = "0"
+)]
+pub struct AssertParamIsCopy<T: Copy + ?Sized> {
+    _field: crate::marker::PhantomData<T>,
+}
 
 /// Implementations of `Clone` for primitive types.
 ///
@@ -217,5 +227,4 @@ fn clone(&self) -> Self {
             *self
         }
     }
-
 }
index eb5121dd0e0812cd7e5b77129a189b2e98c00129..eea3dc39d345ea3ea6aa8c35b5aad8e2b5cd747b 100644 (file)
@@ -464,9 +464,9 @@ fn lt(&self, other: &Self) -> bool { other.0 < self.0 }
     #[inline]
     fn le(&self, other: &Self) -> bool { other.0 <= self.0 }
     #[inline]
-    fn ge(&self, other: &Self) -> bool { other.0 >= self.0 }
-    #[inline]
     fn gt(&self, other: &Self) -> bool { other.0 > self.0 }
+    #[inline]
+    fn ge(&self, other: &Self) -> bool { other.0 >= self.0 }
 }
 
 #[stable(feature = "reverse_cmp_key", since = "1.19.0")]
@@ -1176,9 +1176,9 @@ fn lt(&self, other: & &B) -> bool { PartialOrd::lt(*self, *other) }
         #[inline]
         fn le(&self, other: & &B) -> bool { PartialOrd::le(*self, *other) }
         #[inline]
-        fn ge(&self, other: & &B) -> bool { PartialOrd::ge(*self, *other) }
-        #[inline]
         fn gt(&self, other: & &B) -> bool { PartialOrd::gt(*self, *other) }
+        #[inline]
+        fn ge(&self, other: & &B) -> bool { PartialOrd::ge(*self, *other) }
     }
     #[stable(feature = "rust1", since = "1.0.0")]
     impl<A: ?Sized> Ord for &A where A: Ord {
@@ -1208,9 +1208,9 @@ fn lt(&self, other: &&mut B) -> bool { PartialOrd::lt(*self, *other) }
         #[inline]
         fn le(&self, other: &&mut B) -> bool { PartialOrd::le(*self, *other) }
         #[inline]
-        fn ge(&self, other: &&mut B) -> bool { PartialOrd::ge(*self, *other) }
-        #[inline]
         fn gt(&self, other: &&mut B) -> bool { PartialOrd::gt(*self, *other) }
+        #[inline]
+        fn ge(&self, other: &&mut B) -> bool { PartialOrd::ge(*self, *other) }
     }
     #[stable(feature = "rust1", since = "1.0.0")]
     impl<A: ?Sized> Ord for &mut A where A: Ord {
index 89a269bdb8eb94d4f84dd7a7aba4fde0f4455a5f..08802b3a97a0c0b88a3dc88ee0471856de7ca8c3 100644 (file)
@@ -95,7 +95,9 @@
 /// ```
 #[stable(feature = "convert_id", since = "1.33.0")]
 #[inline]
-pub const fn identity<T>(x: T) -> T { x }
+pub const fn identity<T>(x: T) -> T {
+    x
+}
 
 /// Used to do a cheap reference-to-reference conversion.
 ///
@@ -364,12 +366,10 @@ pub trait Into<T>: Sized {
 /// [`from`]: trait.From.html#tymethod.from
 /// [book]: ../../book/ch09-00-error-handling.html
 #[stable(feature = "rust1", since = "1.0.0")]
-#[rustc_on_unimplemented(
-    on(
-        all(_Self="&str", T="std::string::String"),
-        note="to coerce a `{T}` into a `{Self}`, use `&*` as a prefix",
-    )
-)]
+#[rustc_on_unimplemented(on(
+    all(_Self = "&str", T = "std::string::String"),
+    note = "to coerce a `{T}` into a `{Self}`, use `&*` as a prefix",
+))]
 pub trait From<T>: Sized {
     /// Performs the conversion.
     #[stable(feature = "rust1", since = "1.0.0")]
@@ -490,7 +490,9 @@ pub trait TryFrom<T>: Sized {
 
 // As lifts over &
 #[stable(feature = "rust1", since = "1.0.0")]
-impl<T: ?Sized, U: ?Sized> AsRef<U> for &T where T: AsRef<U>
+impl<T: ?Sized, U: ?Sized> AsRef<U> for &T
+where
+    T: AsRef<U>,
 {
     fn as_ref(&self) -> &U {
         <T as AsRef<U>>::as_ref(*self)
@@ -499,7 +501,9 @@ fn as_ref(&self) -> &U {
 
 // As lifts over &mut
 #[stable(feature = "rust1", since = "1.0.0")]
-impl<T: ?Sized, U: ?Sized> AsRef<U> for &mut T where T: AsRef<U>
+impl<T: ?Sized, U: ?Sized> AsRef<U> for &mut T
+where
+    T: AsRef<U>,
 {
     fn as_ref(&self) -> &U {
         <T as AsRef<U>>::as_ref(*self)
@@ -516,7 +520,9 @@ fn as_ref(&self) -> &U {
 
 // AsMut lifts over &mut
 #[stable(feature = "rust1", since = "1.0.0")]
-impl<T: ?Sized, U: ?Sized> AsMut<U> for &mut T where T: AsMut<U>
+impl<T: ?Sized, U: ?Sized> AsMut<U> for &mut T
+where
+    T: AsMut<U>,
 {
     fn as_mut(&mut self) -> &mut U {
         (*self).as_mut()
@@ -533,7 +539,9 @@ fn as_mut(&mut self) -> &mut U {
 
 // From implies Into
 #[stable(feature = "rust1", since = "1.0.0")]
-impl<T, U> Into<U> for T where U: From<T>
+impl<T, U> Into<U> for T
+where
+    U: From<T>,
 {
     fn into(self) -> U {
         U::from(self)
@@ -543,7 +551,9 @@ fn into(self) -> U {
 // From (and thus Into) is reflexive
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<T> From<T> for T {
-    fn from(t: T) -> T { t }
+    fn from(t: T) -> T {
+        t
+    }
 }
 
 /// **Stability note:** This impl does not yet exist, but we are
@@ -552,15 +562,19 @@ fn from(t: T) -> T { t }
 ///
 /// [#64715]: https://github.com/rust-lang/rust/issues/64715
 #[stable(feature = "convert_infallible", since = "1.34.0")]
-#[rustc_reservation_impl="permitting this impl would forbid us from adding \
-`impl<T> From<!> for T` later; see rust-lang/rust#64715 for details"]
+#[rustc_reservation_impl = "permitting this impl would forbid us from adding \
+                            `impl<T> From<!> for T` later; see rust-lang/rust#64715 for details"]
 impl<T> From<!> for T {
-    fn from(t: !) -> T { t }
+    fn from(t: !) -> T {
+        t
+    }
 }
 
 // TryFrom implies TryInto
 #[stable(feature = "try_from", since = "1.34.0")]
-impl<T, U> TryInto<U> for T where U: TryFrom<T>
+impl<T, U> TryInto<U> for T
+where
+    U: TryFrom<T>,
 {
     type Error = U::Error;
 
@@ -572,7 +586,10 @@ fn try_into(self) -> Result<U, U::Error> {
 // Infallible conversions are semantically equivalent to fallible conversions
 // with an uninhabited error type.
 #[stable(feature = "try_from", since = "1.34.0")]
-impl<T, U> TryFrom<U> for T where U: Into<T> {
+impl<T, U> TryFrom<U> for T
+where
+    U: Into<T>,
+{
     type Error = Infallible;
 
     fn try_from(value: U) -> Result<Self, Self::Error> {
index 1aadc77cfb8da75b3bd68747866e75bbba6911e1..15ac3aea8b7baa2832e726fdd31325a5ab43dfb8 100644 (file)
@@ -119,7 +119,9 @@ pub trait Default: Sized {
 #[rustc_builtin_macro]
 #[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
 #[allow_internal_unstable(core_intrinsics)]
-pub macro Default($item:item) { /* compiler built-in */ }
+pub macro Default($item:item) {
+    /* compiler built-in */
+}
 
 macro_rules! default_impl {
     ($t:ty, $v:expr, $doc:tt) => {
index 499dd0facd38c6ba47948122a1ddc3313b29585c..74ec24939a3109716e91f1c7d61cdc192480a876 100644 (file)
@@ -1,5 +1,4 @@
 #![stable(feature = "", since = "1.30.0")]
-
 #![allow(non_camel_case_types)]
 
 //! Utilities related to FFI bindings.
 #[repr(u8)]
 #[stable(feature = "core_c_void", since = "1.30.0")]
 pub enum c_void {
-    #[unstable(feature = "c_void_variant", reason = "temporary implementation detail",
-               issue = "0")]
-    #[doc(hidden)] __variant1,
-    #[unstable(feature = "c_void_variant", reason = "temporary implementation detail",
-               issue = "0")]
-    #[doc(hidden)] __variant2,
+    #[unstable(
+        feature = "c_void_variant",
+        reason = "temporary implementation detail",
+        issue = "0"
+    )]
+    #[doc(hidden)]
+    __variant1,
+    #[unstable(
+        feature = "c_void_variant",
+        reason = "temporary implementation detail",
+        issue = "0"
+    )]
+    #[doc(hidden)]
+    __variant2,
 }
 
 #[stable(feature = "std_debug", since = "1.16.0")]
@@ -53,17 +60,20 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 
 /// Basic implementation of a `va_list`.
 // The name is WIP, using `VaListImpl` for now.
-#[cfg(any(all(not(target_arch = "aarch64"), not(target_arch = "powerpc"),
-              not(target_arch = "x86_64")),
-          all(target_arch = "aarch64", target_os = "ios"),
-          target_arch = "wasm32",
-          target_arch = "asmjs",
-          windows))]
+#[cfg(any(
+    all(not(target_arch = "aarch64"), not(target_arch = "powerpc"), not(target_arch = "x86_64")),
+    all(target_arch = "aarch64", target_os = "ios"),
+    target_arch = "wasm32",
+    target_arch = "asmjs",
+    windows
+))]
 #[repr(transparent)]
-#[unstable(feature = "c_variadic",
-           reason = "the `c_variadic` feature has not been properly tested on \
-                     all supported platforms",
-           issue = "44930")]
+#[unstable(
+    feature = "c_variadic",
+    reason = "the `c_variadic` feature has not been properly tested on \
+              all supported platforms",
+    issue = "44930"
+)]
 #[lang = "va_list"]
 pub struct VaListImpl<'f> {
     ptr: *mut c_void,
@@ -73,16 +83,19 @@ pub struct VaListImpl<'f> {
     _marker: PhantomData<&'f mut &'f c_void>,
 }
 
-#[cfg(any(all(not(target_arch = "aarch64"), not(target_arch = "powerpc"),
-              not(target_arch = "x86_64")),
-          all(target_arch = "aarch64", target_os = "ios"),
-          target_arch = "wasm32",
-          target_arch = "asmjs",
-          windows))]
-#[unstable(feature = "c_variadic",
-           reason = "the `c_variadic` feature has not been properly tested on \
-                     all supported platforms",
-           issue = "44930")]
+#[cfg(any(
+    all(not(target_arch = "aarch64"), not(target_arch = "powerpc"), not(target_arch = "x86_64")),
+    all(target_arch = "aarch64", target_os = "ios"),
+    target_arch = "wasm32",
+    target_arch = "asmjs",
+    windows
+))]
+#[unstable(
+    feature = "c_variadic",
+    reason = "the `c_variadic` feature has not been properly tested on \
+              all supported platforms",
+    issue = "44930"
+)]
 impl<'f> fmt::Debug for VaListImpl<'f> {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         write!(f, "va_list* {:p}", self.ptr)
@@ -97,10 +110,12 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 #[cfg(all(target_arch = "aarch64", not(target_os = "ios"), not(windows)))]
 #[repr(C)]
 #[derive(Debug)]
-#[unstable(feature = "c_variadic",
-           reason = "the `c_variadic` feature has not been properly tested on \
-                     all supported platforms",
-           issue = "44930")]
+#[unstable(
+    feature = "c_variadic",
+    reason = "the `c_variadic` feature has not been properly tested on \
+              all supported platforms",
+    issue = "44930"
+)]
 #[lang = "va_list"]
 pub struct VaListImpl<'f> {
     stack: *mut c_void,
@@ -115,10 +130,12 @@ pub struct VaListImpl<'f> {
 #[cfg(all(target_arch = "powerpc", not(windows)))]
 #[repr(C)]
 #[derive(Debug)]
-#[unstable(feature = "c_variadic",
-           reason = "the `c_variadic` feature has not been properly tested on \
-                     all supported platforms",
-           issue = "44930")]
+#[unstable(
+    feature = "c_variadic",
+    reason = "the `c_variadic` feature has not been properly tested on \
+              all supported platforms",
+    issue = "44930"
+)]
 #[lang = "va_list"]
 pub struct VaListImpl<'f> {
     gpr: u8,
@@ -133,10 +150,12 @@ pub struct VaListImpl<'f> {
 #[cfg(all(target_arch = "x86_64", not(windows)))]
 #[repr(C)]
 #[derive(Debug)]
-#[unstable(feature = "c_variadic",
-           reason = "the `c_variadic` feature has not been properly tested on \
-                     all supported platforms",
-           issue = "44930")]
+#[unstable(
+    feature = "c_variadic",
+    reason = "the `c_variadic` feature has not been properly tested on \
+              all supported platforms",
+    issue = "44930"
+)]
 #[lang = "va_list"]
 pub struct VaListImpl<'f> {
     gp_offset: i32,
@@ -149,76 +168,86 @@ pub struct VaListImpl<'f> {
 /// A wrapper for a `va_list`
 #[repr(transparent)]
 #[derive(Debug)]
-#[unstable(feature = "c_variadic",
-           reason = "the `c_variadic` feature has not been properly tested on \
-                     all supported platforms",
-           issue = "44930")]
+#[unstable(
+    feature = "c_variadic",
+    reason = "the `c_variadic` feature has not been properly tested on \
+              all supported platforms",
+    issue = "44930"
+)]
 pub struct VaList<'a, 'f: 'a> {
-    #[cfg(any(all(not(target_arch = "aarch64"), not(target_arch = "powerpc"),
-                  not(target_arch = "x86_64")),
-              all(target_arch = "aarch64", target_os = "ios"),
-              target_arch = "wasm32",
-              target_arch = "asmjs",
-              windows))]
+    #[cfg(any(
+        all(
+            not(target_arch = "aarch64"),
+            not(target_arch = "powerpc"),
+            not(target_arch = "x86_64")
+        ),
+        all(target_arch = "aarch64", target_os = "ios"),
+        target_arch = "wasm32",
+        target_arch = "asmjs",
+        windows
+    ))]
     inner: VaListImpl<'f>,
 
-    #[cfg(all(any(target_arch = "aarch64", target_arch = "powerpc",
-                  target_arch = "x86_64"),
-              any(not(target_arch = "aarch64"), not(target_os = "ios")),
-              not(target_arch = "wasm32"),
-              not(target_arch = "asmjs"),
-              not(windows)))]
+    #[cfg(all(
+        any(target_arch = "aarch64", target_arch = "powerpc", target_arch = "x86_64"),
+        any(not(target_arch = "aarch64"), not(target_os = "ios")),
+        not(target_arch = "wasm32"),
+        not(target_arch = "asmjs"),
+        not(windows)
+    ))]
     inner: &'a mut VaListImpl<'f>,
 
     _marker: PhantomData<&'a mut VaListImpl<'f>>,
 }
 
-#[cfg(any(all(not(target_arch = "aarch64"), not(target_arch = "powerpc"),
-              not(target_arch = "x86_64")),
-          all(target_arch = "aarch64", target_os = "ios"),
-          target_arch = "wasm32",
-          target_arch = "asmjs",
-          windows))]
-#[unstable(feature = "c_variadic",
-           reason = "the `c_variadic` feature has not been properly tested on \
-                     all supported platforms",
-           issue = "44930")]
+#[cfg(any(
+    all(not(target_arch = "aarch64"), not(target_arch = "powerpc"), not(target_arch = "x86_64")),
+    all(target_arch = "aarch64", target_os = "ios"),
+    target_arch = "wasm32",
+    target_arch = "asmjs",
+    windows
+))]
+#[unstable(
+    feature = "c_variadic",
+    reason = "the `c_variadic` feature has not been properly tested on \
+              all supported platforms",
+    issue = "44930"
+)]
 impl<'f> VaListImpl<'f> {
     /// Convert a `VaListImpl` into a `VaList` that is binary-compatible with C's `va_list`.
     #[inline]
     pub fn as_va_list<'a>(&'a mut self) -> VaList<'a, 'f> {
-        VaList {
-            inner: VaListImpl { ..*self },
-            _marker: PhantomData,
-        }
+        VaList { inner: VaListImpl { ..*self }, _marker: PhantomData }
     }
 }
 
-#[cfg(all(any(target_arch = "aarch64", target_arch = "powerpc",
-              target_arch = "x86_64"),
-          any(not(target_arch = "aarch64"), not(target_os = "ios")),
-          not(target_arch = "wasm32"),
-          not(target_arch = "asmjs"),
-          not(windows)))]
-#[unstable(feature = "c_variadic",
-           reason = "the `c_variadic` feature has not been properly tested on \
-                     all supported platforms",
-           issue = "44930")]
+#[cfg(all(
+    any(target_arch = "aarch64", target_arch = "powerpc", target_arch = "x86_64"),
+    any(not(target_arch = "aarch64"), not(target_os = "ios")),
+    not(target_arch = "wasm32"),
+    not(target_arch = "asmjs"),
+    not(windows)
+))]
+#[unstable(
+    feature = "c_variadic",
+    reason = "the `c_variadic` feature has not been properly tested on \
+              all supported platforms",
+    issue = "44930"
+)]
 impl<'f> VaListImpl<'f> {
     /// Convert a `VaListImpl` into a `VaList` that is binary-compatible with C's `va_list`.
     #[inline]
     pub fn as_va_list<'a>(&'a mut self) -> VaList<'a, 'f> {
-        VaList {
-            inner: self,
-            _marker: PhantomData,
-        }
+        VaList { inner: self, _marker: PhantomData }
     }
 }
 
-#[unstable(feature = "c_variadic",
-           reason = "the `c_variadic` feature has not been properly tested on \
-                     all supported platforms",
-           issue = "44930")]
+#[unstable(
+    feature = "c_variadic",
+    reason = "the `c_variadic` feature has not been properly tested on \
+              all supported platforms",
+    issue = "44930"
+)]
 impl<'a, 'f: 'a> Deref for VaList<'a, 'f> {
     type Target = VaListImpl<'f>;
 
@@ -228,10 +257,12 @@ fn deref(&self) -> &VaListImpl<'f> {
     }
 }
 
-#[unstable(feature = "c_variadic",
-           reason = "the `c_variadic` feature has not been properly tested on \
-                     all supported platforms",
-           issue = "44930")]
+#[unstable(
+    feature = "c_variadic",
+    reason = "the `c_variadic` feature has not been properly tested on \
+              all supported platforms",
+    issue = "44930"
+)]
 impl<'a, 'f: 'a> DerefMut for VaList<'a, 'f> {
     #[inline]
     fn deref_mut(&mut self) -> &mut VaListImpl<'f> {
@@ -252,10 +283,12 @@ mod sealed_trait {
     /// Trait which whitelists the allowed types to be used with [VaList::arg]
     ///
     /// [VaList::va_arg]: struct.VaList.html#method.arg
-    #[unstable(feature = "c_variadic",
-               reason = "the `c_variadic` feature has not been properly tested on \
-                         all supported platforms",
-               issue = "44930")]
+    #[unstable(
+        feature = "c_variadic",
+        reason = "the `c_variadic` feature has not been properly tested on \
+                  all supported platforms",
+        issue = "44930"
+    )]
     pub trait VaArgSafe {}
 }
 
@@ -271,25 +304,31 @@ impl sealed_trait::VaArgSafe for $t {}
     }
 }
 
-impl_va_arg_safe!{i8, i16, i32, i64, usize}
-impl_va_arg_safe!{u8, u16, u32, u64, isize}
-impl_va_arg_safe!{f64}
+impl_va_arg_safe! {i8, i16, i32, i64, usize}
+impl_va_arg_safe! {u8, u16, u32, u64, isize}
+impl_va_arg_safe! {f64}
 
-#[unstable(feature = "c_variadic",
-           reason = "the `c_variadic` feature has not been properly tested on \
-                     all supported platforms",
-           issue = "44930")]
+#[unstable(
+    feature = "c_variadic",
+    reason = "the `c_variadic` feature has not been properly tested on \
+              all supported platforms",
+    issue = "44930"
+)]
 impl<T> sealed_trait::VaArgSafe for *mut T {}
-#[unstable(feature = "c_variadic",
-           reason = "the `c_variadic` feature has not been properly tested on \
-                     all supported platforms",
-           issue = "44930")]
+#[unstable(
+    feature = "c_variadic",
+    reason = "the `c_variadic` feature has not been properly tested on \
+              all supported platforms",
+    issue = "44930"
+)]
 impl<T> sealed_trait::VaArgSafe for *const T {}
 
-#[unstable(feature = "c_variadic",
-           reason = "the `c_variadic` feature has not been properly tested on \
-                     all supported platforms",
-           issue = "44930")]
+#[unstable(
+    feature = "c_variadic",
+    reason = "the `c_variadic` feature has not been properly tested on \
+              all supported platforms",
+    issue = "44930"
+)]
 impl<'f> VaListImpl<'f> {
     /// Advance to the next arg.
     #[inline]
@@ -299,7 +338,9 @@ pub unsafe fn arg<T: sealed_trait::VaArgSafe>(&mut self) -> T {
 
     /// Copies the `va_list` at the current location.
     pub unsafe fn with_copy<F, R>(&self, f: F) -> R
-            where F: for<'copy> FnOnce(VaList<'copy, 'f>) -> R {
+    where
+        F: for<'copy> FnOnce(VaList<'copy, 'f>) -> R,
+    {
         let mut ap = self.clone();
         let ret = f(ap.as_va_list());
         va_end(&mut ap);
@@ -307,10 +348,12 @@ pub unsafe fn with_copy<F, R>(&self, f: F) -> R
     }
 }
 
-#[unstable(feature = "c_variadic",
-           reason = "the `c_variadic` feature has not been properly tested on \
-                     all supported platforms",
-           issue = "44930")]
+#[unstable(
+    feature = "c_variadic",
+    reason = "the `c_variadic` feature has not been properly tested on \
+              all supported platforms",
+    issue = "44930"
+)]
 impl<'f> Clone for VaListImpl<'f> {
     #[inline]
     fn clone(&self) -> Self {
@@ -323,10 +366,12 @@ fn clone(&self) -> Self {
     }
 }
 
-#[unstable(feature = "c_variadic",
-           reason = "the `c_variadic` feature has not been properly tested on \
-                     all supported platforms",
-           issue = "44930")]
+#[unstable(
+    feature = "c_variadic",
+    reason = "the `c_variadic` feature has not been properly tested on \
+              all supported platforms",
+    issue = "44930"
+)]
 impl<'f> Drop for VaListImpl<'f> {
     fn drop(&mut self) {
         // FIXME: this should call `va_end`, but there's no clean way to
index b52b56b1bdbc28f7cb0d5d5dfcbbe67e0108d668..284e94926dc8524f173dc13ea263a5488fbf50e6 100644 (file)
@@ -1,4 +1,4 @@
-use crate::fmt::{Formatter, Result, LowerExp, UpperExp, Display, Debug};
+use crate::fmt::{Debug, Display, Formatter, LowerExp, Result, UpperExp};
 use crate::mem::MaybeUninit;
 use crate::num::flt2dec;
 
@@ -7,9 +7,14 @@
 // Don't inline this so callers don't use the stack space this function
 // requires unless they have to.
 #[inline(never)]
-fn float_to_decimal_common_exact<T>(fmt: &mut Formatter<'_>, num: &T,
-                                    sign: flt2dec::Sign, precision: usize) -> Result
-    where T: flt2dec::DecodableFloat
+fn float_to_decimal_common_exact<T>(
+    fmt: &mut Formatter<'_>,
+    num: &T,
+    sign: flt2dec::Sign,
+    precision: usize,
+) -> Result
+where
+    T: flt2dec::DecodableFloat,
 {
     unsafe {
         let mut buf = MaybeUninit::<[u8; 1024]>::uninit(); // enough for f32 and f64
@@ -19,9 +24,15 @@ fn float_to_decimal_common_exact<T>(fmt: &mut Formatter<'_>, num: &T,
         // we decided whether that is valid or not.
         // We can do this only because we are libstd and coupled to the compiler.
         // (FWIW, using `freeze` would not be enough; `flt2dec::Part` is an enum!)
-        let formatted = flt2dec::to_exact_fixed_str(flt2dec::strategy::grisu::format_exact,
-                                                    *num, sign, precision,
-                                                    false, buf.get_mut(), parts.get_mut());
+        let formatted = flt2dec::to_exact_fixed_str(
+            flt2dec::strategy::grisu::format_exact,
+            *num,
+            sign,
+            precision,
+            false,
+            buf.get_mut(),
+            parts.get_mut(),
+        );
         fmt.pad_formatted_parts(&formatted)
     }
 }
@@ -29,33 +40,49 @@ fn float_to_decimal_common_exact<T>(fmt: &mut Formatter<'_>, num: &T,
 // Don't inline this so callers that call both this and the above won't wind
 // up using the combined stack space of both functions in some cases.
 #[inline(never)]
-fn float_to_decimal_common_shortest<T>(fmt: &mut Formatter<'_>, num: &T,
-                                       sign: flt2dec::Sign, precision: usize) -> Result
-    where T: flt2dec::DecodableFloat
+fn float_to_decimal_common_shortest<T>(
+    fmt: &mut Formatter<'_>,
+    num: &T,
+    sign: flt2dec::Sign,
+    precision: usize,
+) -> Result
+where
+    T: flt2dec::DecodableFloat,
 {
     unsafe {
         // enough for f32 and f64
         let mut buf = MaybeUninit::<[u8; flt2dec::MAX_SIG_DIGITS]>::uninit();
         let mut parts = MaybeUninit::<[flt2dec::Part<'_>; 4]>::uninit();
         // FIXME(#53491)
-        let formatted = flt2dec::to_shortest_str(flt2dec::strategy::grisu::format_shortest, *num,
-                                                 sign, precision, false, buf.get_mut(),
-                                                 parts.get_mut());
+        let formatted = flt2dec::to_shortest_str(
+            flt2dec::strategy::grisu::format_shortest,
+            *num,
+            sign,
+            precision,
+            false,
+            buf.get_mut(),
+            parts.get_mut(),
+        );
         fmt.pad_formatted_parts(&formatted)
     }
 }
 
 // Common code of floating point Debug and Display.
-fn float_to_decimal_common<T>(fmt: &mut Formatter<'_>, num: &T,
-                              negative_zero: bool, min_precision: usize) -> Result
-    where T: flt2dec::DecodableFloat
+fn float_to_decimal_common<T>(
+    fmt: &mut Formatter<'_>,
+    num: &T,
+    negative_zero: bool,
+    min_precision: usize,
+) -> Result
+where
+    T: flt2dec::DecodableFloat,
 {
     let force_sign = fmt.sign_plus();
     let sign = match (force_sign, negative_zero) {
         (false, false) => flt2dec::Sign::Minus,
-        (false, true)  => flt2dec::Sign::MinusRaw,
-        (true,  false) => flt2dec::Sign::MinusPlus,
-        (true,  true)  => flt2dec::Sign::MinusPlusRaw,
+        (false, true) => flt2dec::Sign::MinusRaw,
+        (true, false) => flt2dec::Sign::MinusPlus,
+        (true, true) => flt2dec::Sign::MinusPlusRaw,
     };
 
     if let Some(precision) = fmt.precision {
@@ -68,18 +95,29 @@ fn float_to_decimal_common<T>(fmt: &mut Formatter<'_>, num: &T,
 // Don't inline this so callers don't use the stack space this function
 // requires unless they have to.
 #[inline(never)]
-fn float_to_exponential_common_exact<T>(fmt: &mut Formatter<'_>, num: &T,
-                                        sign: flt2dec::Sign, precision: usize,
-                                        upper: bool) -> Result
-    where T: flt2dec::DecodableFloat
+fn float_to_exponential_common_exact<T>(
+    fmt: &mut Formatter<'_>,
+    num: &T,
+    sign: flt2dec::Sign,
+    precision: usize,
+    upper: bool,
+) -> Result
+where
+    T: flt2dec::DecodableFloat,
 {
     unsafe {
         let mut buf = MaybeUninit::<[u8; 1024]>::uninit(); // enough for f32 and f64
         let mut parts = MaybeUninit::<[flt2dec::Part<'_>; 6]>::uninit();
         // FIXME(#53491)
-        let formatted = flt2dec::to_exact_exp_str(flt2dec::strategy::grisu::format_exact,
-                                                  *num, sign, precision,
-                                                  upper, buf.get_mut(), parts.get_mut());
+        let formatted = flt2dec::to_exact_exp_str(
+            flt2dec::strategy::grisu::format_exact,
+            *num,
+            sign,
+            precision,
+            upper,
+            buf.get_mut(),
+            parts.get_mut(),
+        );
         fmt.pad_formatted_parts(&formatted)
     }
 }
@@ -87,31 +125,42 @@ fn float_to_exponential_common_exact<T>(fmt: &mut Formatter<'_>, num: &T,
 // Don't inline this so callers that call both this and the above won't wind
 // up using the combined stack space of both functions in some cases.
 #[inline(never)]
-fn float_to_exponential_common_shortest<T>(fmt: &mut Formatter<'_>,
-                                           num: &T, sign: flt2dec::Sign,
-                                           upper: bool) -> Result
-    where T: flt2dec::DecodableFloat
+fn float_to_exponential_common_shortest<T>(
+    fmt: &mut Formatter<'_>,
+    num: &T,
+    sign: flt2dec::Sign,
+    upper: bool,
+) -> Result
+where
+    T: flt2dec::DecodableFloat,
 {
     unsafe {
         // enough for f32 and f64
         let mut buf = MaybeUninit::<[u8; flt2dec::MAX_SIG_DIGITS]>::uninit();
         let mut parts = MaybeUninit::<[flt2dec::Part<'_>; 6]>::uninit();
         // FIXME(#53491)
-        let formatted = flt2dec::to_shortest_exp_str(flt2dec::strategy::grisu::format_shortest,
-                                                     *num, sign, (0, 0), upper,
-                                                     buf.get_mut(), parts.get_mut());
+        let formatted = flt2dec::to_shortest_exp_str(
+            flt2dec::strategy::grisu::format_shortest,
+            *num,
+            sign,
+            (0, 0),
+            upper,
+            buf.get_mut(),
+            parts.get_mut(),
+        );
         fmt.pad_formatted_parts(&formatted)
     }
 }
 
 // Common code of floating point LowerExp and UpperExp.
 fn float_to_exponential_common<T>(fmt: &mut Formatter<'_>, num: &T, upper: bool) -> Result
-    where T: flt2dec::DecodableFloat
+where
+    T: flt2dec::DecodableFloat,
 {
     let force_sign = fmt.sign_plus();
     let sign = match force_sign {
         false => flt2dec::Sign::Minus,
-        true  => flt2dec::Sign::MinusPlus,
+        true => flt2dec::Sign::MinusPlus,
     };
 
     if let Some(precision) = fmt.precision {
@@ -123,7 +172,7 @@ fn float_to_exponential_common<T>(fmt: &mut Formatter<'_>, num: &T, upper: bool)
 }
 
 macro_rules! floating {
-    ($ty:ident) => (
+    ($ty:ident) => {
         #[stable(feature = "rust1", since = "1.0.0")]
         impl Debug for $ty {
             fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
@@ -151,7 +200,7 @@ fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
                 float_to_exponential_common(fmt, self, true)
             }
         }
-    )
+    };
 }
 
 floating! { f32 }
index 07dca9ad214ecca2265600105f2e43389247312f..4c941e2dfe6dec8df0fd84212b6c0cf59db3d221 100644 (file)
@@ -4,7 +4,7 @@
 
 #![stable(feature = "rust1", since = "1.0.0")]
 
-use crate::cell::{UnsafeCell, Cell, RefCell, Ref, RefMut};
+use crate::cell::{Cell, Ref, RefCell, RefMut, UnsafeCell};
 use crate::marker::PhantomData;
 use crate::mem;
 use crate::num::flt2dec;
@@ -13,9 +13,9 @@
 use crate::slice;
 use crate::str;
 
+mod builders;
 mod float;
 mod num;
-mod builders;
 
 #[stable(feature = "fmt_flags_align", since = "1.28.0")]
 /// Possible alignments returned by `Formatter::align`
@@ -33,10 +33,9 @@ pub enum Alignment {
 }
 
 #[stable(feature = "debug_builders", since = "1.2.0")]
-pub use self::builders::{DebugStruct, DebugTuple, DebugSet, DebugList, DebugMap};
+pub use self::builders::{DebugList, DebugMap, DebugSet, DebugStruct, DebugTuple};
 
-#[unstable(feature = "fmt_internals", reason = "internal to format_args!",
-           issue = "0")]
+#[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "0")]
 #[doc(hidden)]
 pub mod rt {
     pub mod v1;
@@ -234,7 +233,7 @@ pub struct Formatter<'a> {
     width: Option<usize>,
     precision: Option<usize>,
 
-    buf: &'a mut (dyn Write+'a),
+    buf: &'a mut (dyn Write + 'a),
     curarg: slice::Iter<'a, ArgumentV1<'a>>,
     args: &'a [ArgumentV1<'a>],
 }
@@ -260,8 +259,7 @@ struct Void {
 /// types, and then this struct is used to canonicalize arguments to one type.
 #[derive(Copy, Clone)]
 #[allow(missing_debug_implementations)]
-#[unstable(feature = "fmt_internals", reason = "internal to format_args!",
-           issue = "0")]
+#[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "0")]
 #[doc(hidden)]
 pub struct ArgumentV1<'a> {
     value: &'a Void,
@@ -275,21 +273,13 @@ fn show_usize(x: &usize, f: &mut Formatter<'_>) -> Result {
     }
 
     #[doc(hidden)]
-    #[unstable(feature = "fmt_internals", reason = "internal to format_args!",
-               issue = "0")]
-    pub fn new<'b, T>(x: &'b T,
-                      f: fn(&T, &mut Formatter<'_>) -> Result) -> ArgumentV1<'b> {
-        unsafe {
-            ArgumentV1 {
-                formatter: mem::transmute(f),
-                value: mem::transmute(x)
-            }
-        }
+    #[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "0")]
+    pub fn new<'b, T>(x: &'b T, f: fn(&T, &mut Formatter<'_>) -> Result) -> ArgumentV1<'b> {
+        unsafe { ArgumentV1 { formatter: mem::transmute(f), value: mem::transmute(x) } }
     }
 
     #[doc(hidden)]
-    #[unstable(feature = "fmt_internals", reason = "internal to format_args!",
-               issue = "0")]
+    #[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "0")]
     pub fn from_usize(x: &usize) -> ArgumentV1<'_> {
         ArgumentV1::new(x, ArgumentV1::show_usize)
     }
@@ -305,21 +295,23 @@ fn as_usize(&self) -> Option<usize> {
 
 // flags available in the v1 format of format_args
 #[derive(Copy, Clone)]
-enum FlagV1 { SignPlus, SignMinus, Alternate, SignAwareZeroPad, DebugLowerHex, DebugUpperHex }
+enum FlagV1 {
+    SignPlus,
+    SignMinus,
+    Alternate,
+    SignAwareZeroPad,
+    DebugLowerHex,
+    DebugUpperHex,
+}
 
 impl<'a> Arguments<'a> {
     /// When using the format_args!() macro, this function is used to generate the
     /// Arguments structure.
-    #[doc(hidden)] #[inline]
-    #[unstable(feature = "fmt_internals", reason = "internal to format_args!",
-               issue = "0")]
-    pub fn new_v1(pieces: &'a [&'a str],
-                  args: &'a [ArgumentV1<'a>]) -> Arguments<'a> {
-        Arguments {
-            pieces,
-            fmt: None,
-            args,
-        }
+    #[doc(hidden)]
+    #[inline]
+    #[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "0")]
+    pub fn new_v1(pieces: &'a [&'a str], args: &'a [ArgumentV1<'a>]) -> Arguments<'a> {
+        Arguments { pieces, fmt: None, args }
     }
 
     /// This function is used to specify nonstandard formatting parameters.
@@ -328,29 +320,26 @@ pub fn new_v1(pieces: &'a [&'a str],
     /// `CountIsParam` or `CountIsNextParam` has to point to an argument
     /// created with `argumentusize`. However, failing to do so doesn't cause
     /// unsafety, but will ignore invalid .
-    #[doc(hidden)] #[inline]
-    #[unstable(feature = "fmt_internals", reason = "internal to format_args!",
-               issue = "0")]
-    pub fn new_v1_formatted(pieces: &'a [&'a str],
-                            args: &'a [ArgumentV1<'a>],
-                            fmt: &'a [rt::v1::Argument]) -> Arguments<'a> {
-        Arguments {
-            pieces,
-            fmt: Some(fmt),
-            args,
-        }
+    #[doc(hidden)]
+    #[inline]
+    #[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "0")]
+    pub fn new_v1_formatted(
+        pieces: &'a [&'a str],
+        args: &'a [ArgumentV1<'a>],
+        fmt: &'a [rt::v1::Argument],
+    ) -> Arguments<'a> {
+        Arguments { pieces, fmt: Some(fmt), args }
     }
 
     /// Estimates the length of the formatted text.
     ///
     /// This is intended to be used for setting initial `String` capacity
     /// when using `format!`. Note: this is neither the lower nor upper bound.
-    #[doc(hidden)] #[inline]
-    #[unstable(feature = "fmt_internals", reason = "internal to format_args!",
-               issue = "0")]
+    #[doc(hidden)]
+    #[inline]
+    #[unstable(feature = "fmt_internals", reason = "internal to format_args!", issue = "0")]
     pub fn estimated_capacity(&self) -> usize {
-        let pieces_length: usize = self.pieces.iter()
-            .map(|x| x.len()).sum();
+        let pieces_length: usize = self.pieces.iter().map(|x| x.len()).sum();
 
         if self.args.is_empty() {
             pieces_length
@@ -514,10 +503,13 @@ fn fmt(&self, fmt: &mut Formatter<'_>) -> Result {
 /// ```
 #[stable(feature = "rust1", since = "1.0.0")]
 #[rustc_on_unimplemented(
-    on(crate_local, label="`{Self}` cannot be formatted using `{{:?}}`",
-                    note="add `#[derive(Debug)]` or manually implement `{Debug}`"),
-    message="`{Self}` doesn't implement `{Debug}`",
-    label="`{Self}` cannot be formatted using `{{:?}}` because it doesn't implement `{Debug}`",
+    on(
+        crate_local,
+        label = "`{Self}` cannot be formatted using `{{:?}}`",
+        note = "add `#[derive(Debug)]` or manually implement `{Debug}`"
+    ),
+    message = "`{Self}` doesn't implement `{Debug}`",
+    label = "`{Self}` cannot be formatted using `{{:?}}` because it doesn't implement `{Debug}`"
 )]
 #[doc(alias = "{:?}")]
 #[rustc_diagnostic_item = "debug_trait"]
@@ -553,7 +545,9 @@ pub(crate) mod macros {
     #[rustc_builtin_macro]
     #[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
     #[allow_internal_unstable(core_intrinsics)]
-    pub macro Debug($item:item) { /* compiler built-in */ }
+    pub macro Debug($item:item) {
+        /* compiler built-in */
+    }
 }
 #[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
 #[doc(inline)]
@@ -594,14 +588,14 @@ pub(crate) mod macros {
 /// ```
 #[rustc_on_unimplemented(
     on(
-        _Self="std::path::Path",
-        label="`{Self}` cannot be formatted with the default formatter; call `.display()` on it",
-        note="call `.display()` or `.to_string_lossy()` to safely print paths, \
-              as they may contain non-Unicode data"
+        _Self = "std::path::Path",
+        label = "`{Self}` cannot be formatted with the default formatter; call `.display()` on it",
+        note = "call `.display()` or `.to_string_lossy()` to safely print paths, \
+                as they may contain non-Unicode data"
     ),
-    message="`{Self}` doesn't implement `{Display}`",
-    label="`{Self}` cannot be formatted with the default formatter",
-    note="in format strings you may be able to use `{{:?}}` (or {{:#?}} for pretty-print) instead",
+    message = "`{Self}` doesn't implement `{Display}`",
+    label = "`{Self}` cannot be formatted with the default formatter",
+    note = "in format strings you may be able to use `{{:?}}` (or {{:#?}} for pretty-print) instead"
 )]
 #[doc(alias = "{}")]
 #[stable(feature = "rust1", since = "1.0.0")]
@@ -1073,7 +1067,9 @@ fn write(self, buf: &mut dyn Write) -> Result {
 
 impl<'a> Formatter<'a> {
     fn wrap_buf<'b, 'c, F>(&'b mut self, wrap: F) -> Formatter<'c>
-        where 'b: 'c, F: FnOnce(&'b mut (dyn Write+'b)) -> &'c mut (dyn Write+'c)
+    where
+        'b: 'c,
+        F: FnOnce(&'b mut (dyn Write + 'b)) -> &'c mut (dyn Write + 'c),
     {
         Formatter {
             // We want to change this
@@ -1106,7 +1102,7 @@ fn run(&mut self, arg: &rt::v1::Argument) -> Result {
 
         // Extract the correct argument
         let value = match arg.position {
-            rt::v1::Position::Next => { *self.curarg.next().unwrap() }
+            rt::v1::Position::Next => *self.curarg.next().unwrap(),
             rt::v1::Position::At(i) => self.args[i],
         };
 
@@ -1118,12 +1114,8 @@ fn getcount(&mut self, cnt: &rt::v1::Count) -> Option<usize> {
         match *cnt {
             rt::v1::Count::Is(n) => Some(n),
             rt::v1::Count::Implied => None,
-            rt::v1::Count::Param(i) => {
-                self.args[i].as_usize()
-            }
-            rt::v1::Count::NextParam => {
-                self.curarg.next()?.as_usize()
-            }
+            rt::v1::Count::Param(i) => self.args[i].as_usize(),
+            rt::v1::Count::NextParam => self.curarg.next()?.as_usize(),
         }
     }
 
@@ -1174,18 +1166,16 @@ fn getcount(&mut self, cnt: &rt::v1::Count) -> Option<usize> {
     /// assert_eq!(&format!("{:0>#8}", Foo::new(-1)), "00-Foo 1");
     /// ```
     #[stable(feature = "rust1", since = "1.0.0")]
-    pub fn pad_integral(&mut self,
-                        is_nonnegative: bool,
-                        prefix: &str,
-                        buf: &str)
-                        -> Result {
+    pub fn pad_integral(&mut self, is_nonnegative: bool, prefix: &str, buf: &str) -> Result {
         let mut width = buf.len();
 
         let mut sign = None;
         if !is_nonnegative {
-            sign = Some('-'); width += 1;
+            sign = Some('-');
+            width += 1;
         } else if self.sign_plus() {
-            sign = Some('+'); width += 1;
+            sign = Some('+');
+            width += 1;
         }
 
         let prefix = if self.alternate() {
@@ -1201,11 +1191,7 @@ fn write_prefix(f: &mut Formatter<'_>, sign: Option<char>, prefix: Option<&str>)
             if let Some(c) = sign {
                 f.buf.write_char(c)?;
             }
-            if let Some(prefix) = prefix {
-                f.buf.write_str(prefix)
-            } else {
-                Ok(())
-            }
+            if let Some(prefix) = prefix { f.buf.write_str(prefix) } else { Ok(()) }
         }
 
         // The `width` field is more of a `min-width` parameter at this point.
@@ -1301,9 +1287,7 @@ pub fn pad(&mut self, s: &str) -> Result {
             None => self.buf.write_str(s),
             // If we're under the maximum width, check if we're over the minimum
             // width, if so it's as easy as just emitting the string.
-            Some(width) if s.chars().count() >= width => {
-                self.buf.write_str(s)
-            }
+            Some(width) if s.chars().count() >= width => self.buf.write_str(s),
             // If we're under both the maximum and the minimum width, then fill
             // up the minimum width with the specified string + some alignment.
             Some(width) => {
@@ -1321,17 +1305,16 @@ pub fn pad(&mut self, s: &str) -> Result {
     fn padding(
         &mut self,
         padding: usize,
-        default: rt::v1::Alignment
+        default: rt::v1::Alignment,
     ) -> result::Result<PostPadding, Error> {
         let align = match self.align {
             rt::v1::Alignment::Unknown => default,
-            _ => self.align
+            _ => self.align,
         };
 
         let (pre_pad, post_pad) = match align {
             rt::v1::Alignment::Left => (0, padding),
-            rt::v1::Alignment::Right |
-            rt::v1::Alignment::Unknown => (padding, 0),
+            rt::v1::Alignment::Right | rt::v1::Alignment::Unknown => (padding, 0),
             rt::v1::Alignment::Center => (padding / 2, (padding + 1) / 2),
         };
 
@@ -1368,7 +1351,8 @@ fn pad_formatted_parts(&mut self, formatted: &flt2dec::Formatted<'_>) -> Result
 
             // remaining parts go through the ordinary padding process.
             let len = formatted.len();
-            let ret = if width <= len { // no padding
+            let ret = if width <= len {
+                // no padding
                 self.write_formatted_parts(&formatted)
             } else {
                 let post_padding = self.padding(width - len, align)?;
@@ -1473,10 +1457,14 @@ pub fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result {
 
     /// Flags for formatting
     #[stable(feature = "rust1", since = "1.0.0")]
-    #[rustc_deprecated(since = "1.24.0",
-                       reason = "use the `sign_plus`, `sign_minus`, `alternate`, \
-                                 or `sign_aware_zero_pad` methods instead")]
-    pub fn flags(&self) -> u32 { self.flags }
+    #[rustc_deprecated(
+        since = "1.24.0",
+        reason = "use the `sign_plus`, `sign_minus`, `alternate`, \
+                  or `sign_aware_zero_pad` methods instead"
+    )]
+    pub fn flags(&self) -> u32 {
+        self.flags
+    }
 
     /// Character used as 'fill' whenever there is alignment.
     ///
@@ -1506,7 +1494,9 @@ pub fn flags(&self) -> u32 { self.flags }
     /// assert_eq!(&format!("{:t>6}", Foo), "tttttt");
     /// ```
     #[stable(feature = "fmt_flags", since = "1.5.0")]
-    pub fn fill(&self) -> char { self.fill }
+    pub fn fill(&self) -> char {
+        self.fill
+    }
 
     /// Flag indicating what form of alignment was requested.
     ///
@@ -1574,7 +1564,9 @@ pub fn align(&self) -> Option<Alignment> {
     /// assert_eq!(&format!("{}", Foo(23)), "Foo(23)");
     /// ```
     #[stable(feature = "fmt_flags", since = "1.5.0")]
-    pub fn width(&self) -> Option<usize> { self.width }
+    pub fn width(&self) -> Option<usize> {
+        self.width
+    }
 
     /// Optionally specified precision for numeric types.
     ///
@@ -1601,7 +1593,9 @@ pub fn width(&self) -> Option<usize> { self.width }
     /// assert_eq!(&format!("{}", Foo(23.2)), "Foo(23.20)");
     /// ```
     #[stable(feature = "fmt_flags", since = "1.5.0")]
-    pub fn precision(&self) -> Option<usize> { self.precision }
+    pub fn precision(&self) -> Option<usize> {
+        self.precision
+    }
 
     /// Determines if the `+` flag was specified.
     ///
@@ -1629,7 +1623,9 @@ pub fn precision(&self) -> Option<usize> { self.precision }
     /// assert_eq!(&format!("{}", Foo(23)), "Foo(23)");
     /// ```
     #[stable(feature = "fmt_flags", since = "1.5.0")]
-    pub fn sign_plus(&self) -> bool { self.flags & (1 << FlagV1::SignPlus as u32) != 0 }
+    pub fn sign_plus(&self) -> bool {
+        self.flags & (1 << FlagV1::SignPlus as u32) != 0
+    }
 
     /// Determines if the `-` flag was specified.
     ///
@@ -1655,7 +1651,9 @@ pub fn sign_plus(&self) -> bool { self.flags & (1 << FlagV1::SignPlus as u32) !=
     /// assert_eq!(&format!("{}", Foo(23)), "Foo(23)");
     /// ```
     #[stable(feature = "fmt_flags", since = "1.5.0")]
-    pub fn sign_minus(&self) -> bool { self.flags & (1 << FlagV1::SignMinus as u32) != 0 }
+    pub fn sign_minus(&self) -> bool {
+        self.flags & (1 << FlagV1::SignMinus as u32) != 0
+    }
 
     /// Determines if the `#` flag was specified.
     ///
@@ -1680,7 +1678,9 @@ pub fn sign_minus(&self) -> bool { self.flags & (1 << FlagV1::SignMinus as u32)
     /// assert_eq!(&format!("{}", Foo(23)), "23");
     /// ```
     #[stable(feature = "fmt_flags", since = "1.5.0")]
-    pub fn alternate(&self) -> bool { self.flags & (1 << FlagV1::Alternate as u32) != 0 }
+    pub fn alternate(&self) -> bool {
+        self.flags & (1 << FlagV1::Alternate as u32) != 0
+    }
 
     /// Determines if the `0` flag was specified.
     ///
@@ -1709,9 +1709,13 @@ pub fn sign_aware_zero_pad(&self) -> bool {
 
     // FIXME: Decide what public API we want for these two flags.
     // https://github.com/rust-lang/rust/issues/48584
-    fn debug_lower_hex(&self) -> bool { self.flags & (1 << FlagV1::DebugLowerHex as u32) != 0 }
+    fn debug_lower_hex(&self) -> bool {
+        self.flags & (1 << FlagV1::DebugLowerHex as u32) != 0
+    }
 
-    fn debug_upper_hex(&self) -> bool { self.flags & (1 << FlagV1::DebugUpperHex as u32) != 0 }
+    fn debug_upper_hex(&self) -> bool {
+        self.flags & (1 << FlagV1::DebugUpperHex as u32) != 0
+    }
 
     /// Creates a [`DebugStruct`] builder designed to assist with creation of
     /// [`fmt::Debug`] implementations for structs.
@@ -2067,11 +2071,15 @@ fn fmt(&self, f: &mut Formatter<'_>) -> Result {
 
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<T: ?Sized> Debug for *const T {
-    fn fmt(&self, f: &mut Formatter<'_>) -> Result { Pointer::fmt(self, f) }
+    fn fmt(&self, f: &mut Formatter<'_>) -> Result {
+        Pointer::fmt(self, f)
+    }
 }
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<T: ?Sized> Debug for *mut T {
-    fn fmt(&self, f: &mut Formatter<'_>) -> Result { Pointer::fmt(self, f) }
+    fn fmt(&self, f: &mut Formatter<'_>) -> Result {
+        Pointer::fmt(self, f)
+    }
 }
 
 macro_rules! peel {
@@ -2129,9 +2137,7 @@ fn fmt(&self, f: &mut Formatter<'_>) -> Result {
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<T: Copy + Debug> Debug for Cell<T> {
     fn fmt(&self, f: &mut Formatter<'_>) -> Result {
-        f.debug_struct("Cell")
-            .field("value", &self.get())
-            .finish()
+        f.debug_struct("Cell").field("value", &self.get()).finish()
     }
 }
 
@@ -2139,11 +2145,7 @@ fn fmt(&self, f: &mut Formatter<'_>) -> Result {
 impl<T: ?Sized + Debug> Debug for RefCell<T> {
     fn fmt(&self, f: &mut Formatter<'_>) -> Result {
         match self.try_borrow() {
-            Ok(borrow) => {
-                f.debug_struct("RefCell")
-                    .field("value", &borrow)
-                    .finish()
-            }
+            Ok(borrow) => f.debug_struct("RefCell").field("value", &borrow).finish(),
             Err(_) => {
                 // The RefCell is mutably borrowed so we can't look at its value
                 // here. Show a placeholder instead.
@@ -2155,9 +2157,7 @@ fn fmt(&self, f: &mut Formatter<'_>) -> Result {
                     }
                 }
 
-                f.debug_struct("RefCell")
-                    .field("value", &BorrowedPlaceholder)
-                    .finish()
+                f.debug_struct("RefCell").field("value", &BorrowedPlaceholder).finish()
             }
         }
     }
index 0082363692df67572c8c9e86d806e1d2e7a71a0d..0db8d86ebbf529cc56f89ece36e15ff4275478b5 100644 (file)
@@ -192,7 +192,8 @@ pub trait Hash {
     /// [`Hasher`]: trait.Hasher.html
     #[stable(feature = "hash_slice", since = "1.3.0")]
     fn hash_slice<H: Hasher>(data: &[Self], state: &mut H)
-        where Self: Sized
+    where
+        Self: Sized,
     {
         for piece in data {
             piece.hash(state);
@@ -206,7 +207,9 @@ pub(crate) mod macros {
     #[rustc_builtin_macro]
     #[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
     #[allow_internal_unstable(core_intrinsics)]
-    pub macro Hash($item:item) { /* compiler built-in */ }
+    pub macro Hash($item:item) {
+        /* compiler built-in */
+    }
 }
 #[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
 #[doc(inline)]
@@ -666,7 +669,6 @@ fn hash<H: Hasher>(&self, state: &mut H) {
         }
     }
 
-
     #[stable(feature = "rust1", since = "1.0.0")]
     impl<T: ?Sized + Hash> Hash for &T {
         fn hash<H: Hasher>(&self, state: &mut H) {
@@ -689,9 +691,7 @@ fn hash<H: Hasher>(&self, state: &mut H) {
                 state.write_usize(*self as *const () as usize);
             } else {
                 // Fat pointer
-                let (a, b) = unsafe {
-                    *(self as *const Self as *const (usize, usize))
-                };
+                let (a, b) = unsafe { *(self as *const Self as *const (usize, usize)) };
                 state.write_usize(a);
                 state.write_usize(b);
             }
@@ -706,9 +706,7 @@ fn hash<H: Hasher>(&self, state: &mut H) {
                 state.write_usize(*self as *const () as usize);
             } else {
                 // Fat pointer
-                let (a, b) = unsafe {
-                    *(self as *const Self as *const (usize, usize))
-                };
+                let (a, b) = unsafe { *(self as *const Self as *const (usize, usize)) };
                 state.write_usize(a);
                 state.write_usize(b);
             }
index 194d9e6e2f8ad498da7873b60a7a0ec90cab0e0f..0aa3b97ebcf15d6725ad2598f537dd5259c9cae6 100644 (file)
@@ -4,10 +4,10 @@
 
 #![allow(deprecated)] // the types in this module are deprecated
 
-use crate::marker::PhantomData;
-use crate::ptr;
 use crate::cmp;
+use crate::marker::PhantomData;
 use crate::mem;
+use crate::ptr;
 
 /// An implementation of SipHash 1-3.
 ///
 ///
 /// See: <https://131002.net/siphash>
 #[unstable(feature = "hashmap_internals", issue = "0")]
-#[rustc_deprecated(since = "1.13.0",
-                   reason = "use `std::collections::hash_map::DefaultHasher` instead")]
+#[rustc_deprecated(
+    since = "1.13.0",
+    reason = "use `std::collections::hash_map::DefaultHasher` instead"
+)]
 #[derive(Debug, Clone, Default)]
 #[doc(hidden)]
 pub struct SipHasher13 {
@@ -28,8 +30,10 @@ pub struct SipHasher13 {
 ///
 /// See: <https://131002.net/siphash/>
 #[unstable(feature = "hashmap_internals", issue = "0")]
-#[rustc_deprecated(since = "1.13.0",
-                   reason = "use `std::collections::hash_map::DefaultHasher` instead")]
+#[rustc_deprecated(
+    since = "1.13.0",
+    reason = "use `std::collections::hash_map::DefaultHasher` instead"
+)]
 #[derive(Debug, Clone, Default)]
 struct SipHasher24 {
     hasher: Hasher<Sip24Rounds>,
@@ -48,8 +52,10 @@ struct SipHasher24 {
 /// it is not intended for cryptographic purposes. As such, all
 /// cryptographic uses of this implementation are _strongly discouraged_.
 #[stable(feature = "rust1", since = "1.0.0")]
-#[rustc_deprecated(since = "1.13.0",
-                   reason = "use `std::collections::hash_map::DefaultHasher` instead")]
+#[rustc_deprecated(
+    since = "1.13.0",
+    reason = "use `std::collections::hash_map::DefaultHasher` instead"
+)]
 #[derive(Debug, Clone, Default)]
 pub struct SipHasher(SipHasher24);
 
@@ -58,9 +64,9 @@ struct Hasher<S: Sip> {
     k0: u64,
     k1: u64,
     length: usize, // how many bytes we've processed
-    state: State, // hash State
-    tail: u64, // unprocessed bytes le
-    ntail: usize, // how many bytes in tail are valid
+    state: State,  // hash State
+    tail: u64,     // unprocessed bytes le
+    ntail: usize,  // how many bytes in tail are valid
     _marker: PhantomData<S>,
 }
 
@@ -78,18 +84,23 @@ struct State {
 }
 
 macro_rules! compress {
-    ($state:expr) => ({
-        compress!($state.v0, $state.v1, $state.v2, $state.v3)
-    });
-    ($v0:expr, $v1:expr, $v2:expr, $v3:expr) =>
-    ({
-        $v0 = $v0.wrapping_add($v1); $v1 = $v1.rotate_left(13); $v1 ^= $v0;
+    ($state:expr) => {{ compress!($state.v0, $state.v1, $state.v2, $state.v3) }};
+    ($v0:expr, $v1:expr, $v2:expr, $v3:expr) => {{
+        $v0 = $v0.wrapping_add($v1);
+        $v1 = $v1.rotate_left(13);
+        $v1 ^= $v0;
         $v0 = $v0.rotate_left(32);
-        $v2 = $v2.wrapping_add($v3); $v3 = $v3.rotate_left(16); $v3 ^= $v2;
-        $v0 = $v0.wrapping_add($v3); $v3 = $v3.rotate_left(21); $v3 ^= $v0;
-        $v2 = $v2.wrapping_add($v1); $v1 = $v1.rotate_left(17); $v1 ^= $v2;
+        $v2 = $v2.wrapping_add($v3);
+        $v3 = $v3.rotate_left(16);
+        $v3 ^= $v2;
+        $v0 = $v0.wrapping_add($v3);
+        $v3 = $v3.rotate_left(21);
+        $v3 ^= $v0;
+        $v2 = $v2.wrapping_add($v1);
+        $v1 = $v1.rotate_left(17);
+        $v1 ^= $v2;
         $v2 = $v2.rotate_left(32);
-    });
+    }};
 }
 
 /// Loads an integer of the desired type from a byte stream, in LE order. Uses
@@ -98,15 +109,16 @@ macro_rules! compress {
 ///
 /// Unsafe because: unchecked indexing at i..i+size_of(int_ty)
 macro_rules! load_int_le {
-    ($buf:expr, $i:expr, $int_ty:ident) =>
-    ({
-       debug_assert!($i + mem::size_of::<$int_ty>() <= $buf.len());
-       let mut data = 0 as $int_ty;
-       ptr::copy_nonoverlapping($buf.get_unchecked($i),
-                                &mut data as *mut _ as *mut u8,
-                                mem::size_of::<$int_ty>());
-       data.to_le()
-    });
+    ($buf:expr, $i:expr, $int_ty:ident) => {{
+        debug_assert!($i + mem::size_of::<$int_ty>() <= $buf.len());
+        let mut data = 0 as $int_ty;
+        ptr::copy_nonoverlapping(
+            $buf.get_unchecked($i),
+            &mut data as *mut _ as *mut u8,
+            mem::size_of::<$int_ty>(),
+        );
+        data.to_le()
+    }};
 }
 
 /// Loads an u64 using up to 7 bytes of a byte slice.
@@ -137,8 +149,10 @@ impl SipHasher {
     /// Creates a new `SipHasher` with the two initial keys set to 0.
     #[inline]
     #[stable(feature = "rust1", since = "1.0.0")]
-    #[rustc_deprecated(since = "1.13.0",
-                       reason = "use `std::collections::hash_map::DefaultHasher` instead")]
+    #[rustc_deprecated(
+        since = "1.13.0",
+        reason = "use `std::collections::hash_map::DefaultHasher` instead"
+    )]
     pub fn new() -> SipHasher {
         SipHasher::new_with_keys(0, 0)
     }
@@ -146,12 +160,12 @@ pub fn new() -> SipHasher {
     /// Creates a `SipHasher` that is keyed off the provided keys.
     #[inline]
     #[stable(feature = "rust1", since = "1.0.0")]
-    #[rustc_deprecated(since = "1.13.0",
-                       reason = "use `std::collections::hash_map::DefaultHasher` instead")]
+    #[rustc_deprecated(
+        since = "1.13.0",
+        reason = "use `std::collections::hash_map::DefaultHasher` instead"
+    )]
     pub fn new_with_keys(key0: u64, key1: u64) -> SipHasher {
-        SipHasher(SipHasher24 {
-            hasher: Hasher::new_with_keys(key0, key1)
-        })
+        SipHasher(SipHasher24 { hasher: Hasher::new_with_keys(key0, key1) })
     }
 }
 
@@ -159,8 +173,10 @@ impl SipHasher13 {
     /// Creates a new `SipHasher13` with the two initial keys set to 0.
     #[inline]
     #[unstable(feature = "hashmap_internals", issue = "0")]
-    #[rustc_deprecated(since = "1.13.0",
-                       reason = "use `std::collections::hash_map::DefaultHasher` instead")]
+    #[rustc_deprecated(
+        since = "1.13.0",
+        reason = "use `std::collections::hash_map::DefaultHasher` instead"
+    )]
     pub fn new() -> SipHasher13 {
         SipHasher13::new_with_keys(0, 0)
     }
@@ -168,12 +184,12 @@ pub fn new() -> SipHasher13 {
     /// Creates a `SipHasher13` that is keyed off the provided keys.
     #[inline]
     #[unstable(feature = "hashmap_internals", issue = "0")]
-    #[rustc_deprecated(since = "1.13.0",
-                       reason = "use `std::collections::hash_map::DefaultHasher` instead")]
+    #[rustc_deprecated(
+        since = "1.13.0",
+        reason = "use `std::collections::hash_map::DefaultHasher` instead"
+    )]
     pub fn new_with_keys(key0: u64, key1: u64) -> SipHasher13 {
-        SipHasher13 {
-            hasher: Hasher::new_with_keys(key0, key1)
-        }
+        SipHasher13 { hasher: Hasher::new_with_keys(key0, key1) }
     }
 }
 
@@ -184,12 +200,7 @@ fn new_with_keys(key0: u64, key1: u64) -> Hasher<S> {
             k0: key0,
             k1: key1,
             length: 0,
-            state: State {
-                v0: 0,
-                v1: 0,
-                v2: 0,
-                v3: 0,
-            },
+            state: State { v0: 0, v1: 0, v2: 0, v3: 0 },
             tail: 0,
             ntail: 0,
             _marker: PhantomData,
@@ -294,7 +305,7 @@ fn write(&mut self, msg: &[u8]) {
             self.tail |= unsafe { u8to64_le(msg, 0, cmp::min(length, needed)) } << 8 * self.ntail;
             if length < needed {
                 self.ntail += length;
-                return
+                return;
             } else {
                 self.state.v3 ^= self.tail;
                 S::c_rounds(&mut self.state);
index a45173f614ded742bec4edbb59566bc065f6d569..0a7a9f26f891257211a68aff95006aed783eb152 100644 (file)
@@ -1,7 +1,7 @@
 use crate::fmt;
 use crate::ops::Try;
 
-use super::super::{Iterator, DoubleEndedIterator, FusedIterator};
+use super::super::{DoubleEndedIterator, FusedIterator, Iterator};
 use super::Map;
 
 /// An iterator that maps each element to an iterator, and yields the elements
@@ -15,7 +15,7 @@
 #[must_use = "iterators are lazy and do nothing unless consumed"]
 #[stable(feature = "rust1", since = "1.0.0")]
 pub struct FlatMap<I, U: IntoIterator, F> {
-    inner: FlattenCompat<Map<I, F>, <U as IntoIterator>::IntoIter>
+    inner: FlattenCompat<Map<I, F>, <U as IntoIterator>::IntoIter>,
 }
 impl<I: Iterator, U: IntoIterator, F: FnMut(I::Item) -> U> FlatMap<I, U, F> {
     pub(in super::super) fn new(iter: I, f: F) -> FlatMap<I, U, F> {
@@ -28,7 +28,9 @@ impl<I: Clone, U, F: Clone> Clone for FlatMap<I, U, F>
 where
     U: Clone + IntoIterator<IntoIter: Clone>,
 {
-    fn clone(&self) -> Self { FlatMap { inner: self.inner.clone() } }
+    fn clone(&self) -> Self {
+        FlatMap { inner: self.inner.clone() }
+    }
 }
 
 #[stable(feature = "core_impl_debug", since = "1.9.0")]
@@ -43,26 +45,35 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<I: Iterator, U: IntoIterator, F> Iterator for FlatMap<I, U, F>
-    where F: FnMut(I::Item) -> U,
+where
+    F: FnMut(I::Item) -> U,
 {
     type Item = U::Item;
 
     #[inline]
-    fn next(&mut self) -> Option<U::Item> { self.inner.next() }
+    fn next(&mut self) -> Option<U::Item> {
+        self.inner.next()
+    }
 
     #[inline]
-    fn size_hint(&self) -> (usize, Option<usize>) { self.inner.size_hint() }
+    fn size_hint(&self) -> (usize, Option<usize>) {
+        self.inner.size_hint()
+    }
 
     #[inline]
-    fn try_fold<Acc, Fold, R>(&mut self, init: Acc, fold: Fold) -> R where
-        Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, R: Try<Ok=Acc>
+    fn try_fold<Acc, Fold, R>(&mut self, init: Acc, fold: Fold) -> R
+    where
+        Self: Sized,
+        Fold: FnMut(Acc, Self::Item) -> R,
+        R: Try<Ok = Acc>,
     {
         self.inner.try_fold(init, fold)
     }
 
     #[inline]
     fn fold<Acc, Fold>(self, init: Acc, fold: Fold) -> Acc
-        where Fold: FnMut(Acc, Self::Item) -> Acc,
+    where
+        Fold: FnMut(Acc, Self::Item) -> Acc,
     {
         self.inner.fold(init, fold)
     }
@@ -75,18 +86,24 @@ impl<I: DoubleEndedIterator, U, F> DoubleEndedIterator for FlatMap<I, U, F>
     U: IntoIterator<IntoIter: DoubleEndedIterator>,
 {
     #[inline]
-    fn next_back(&mut self) -> Option<U::Item> { self.inner.next_back() }
+    fn next_back(&mut self) -> Option<U::Item> {
+        self.inner.next_back()
+    }
 
     #[inline]
-    fn try_rfold<Acc, Fold, R>(&mut self, init: Acc, fold: Fold) -> R where
-        Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, R: Try<Ok=Acc>
+    fn try_rfold<Acc, Fold, R>(&mut self, init: Acc, fold: Fold) -> R
+    where
+        Self: Sized,
+        Fold: FnMut(Acc, Self::Item) -> R,
+        R: Try<Ok = Acc>,
     {
         self.inner.try_rfold(init, fold)
     }
 
     #[inline]
     fn rfold<Acc, Fold>(self, init: Acc, fold: Fold) -> Acc
-        where Fold: FnMut(Acc, Self::Item) -> Acc,
+    where
+        Fold: FnMut(Acc, Self::Item) -> Acc,
     {
         self.inner.rfold(init, fold)
     }
@@ -94,7 +111,12 @@ fn rfold<Acc, Fold>(self, init: Acc, fold: Fold) -> Acc
 
 #[stable(feature = "fused", since = "1.26.0")]
 impl<I, U, F> FusedIterator for FlatMap<I, U, F>
-    where I: FusedIterator, U: IntoIterator, F: FnMut(I::Item) -> U {}
+where
+    I: FusedIterator,
+    U: IntoIterator,
+    F: FnMut(I::Item) -> U,
+{
+}
 
 /// An iterator that flattens one level of nesting in an iterator of things
 /// that can be turned into iterators.
@@ -133,7 +155,9 @@ impl<I, U> Clone for Flatten<I>
     I: Clone + Iterator<Item: IntoIterator<IntoIter = U, Item = U::Item>>,
     U: Clone + Iterator,
 {
-    fn clone(&self) -> Self { Flatten { inner: self.inner.clone() } }
+    fn clone(&self) -> Self {
+        Flatten { inner: self.inner.clone() }
+    }
 }
 
 #[stable(feature = "iterator_flatten", since = "1.29.0")]
@@ -145,21 +169,29 @@ impl<I, U> Iterator for Flatten<I>
     type Item = U::Item;
 
     #[inline]
-    fn next(&mut self) -> Option<U::Item> { self.inner.next() }
+    fn next(&mut self) -> Option<U::Item> {
+        self.inner.next()
+    }
 
     #[inline]
-    fn size_hint(&self) -> (usize, Option<usize>) { self.inner.size_hint() }
+    fn size_hint(&self) -> (usize, Option<usize>) {
+        self.inner.size_hint()
+    }
 
     #[inline]
-    fn try_fold<Acc, Fold, R>(&mut self, init: Acc, fold: Fold) -> R where
-        Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, R: Try<Ok=Acc>
+    fn try_fold<Acc, Fold, R>(&mut self, init: Acc, fold: Fold) -> R
+    where
+        Self: Sized,
+        Fold: FnMut(Acc, Self::Item) -> R,
+        R: Try<Ok = Acc>,
     {
         self.inner.try_fold(init, fold)
     }
 
     #[inline]
     fn fold<Acc, Fold>(self, init: Acc, fold: Fold) -> Acc
-        where Fold: FnMut(Acc, Self::Item) -> Acc,
+    where
+        Fold: FnMut(Acc, Self::Item) -> Acc,
     {
         self.inner.fold(init, fold)
     }
@@ -172,18 +204,24 @@ impl<I, U> DoubleEndedIterator for Flatten<I>
     U: DoubleEndedIterator,
 {
     #[inline]
-    fn next_back(&mut self) -> Option<U::Item> { self.inner.next_back() }
+    fn next_back(&mut self) -> Option<U::Item> {
+        self.inner.next_back()
+    }
 
     #[inline]
-    fn try_rfold<Acc, Fold, R>(&mut self, init: Acc, fold: Fold) -> R where
-        Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, R: Try<Ok=Acc>
+    fn try_rfold<Acc, Fold, R>(&mut self, init: Acc, fold: Fold) -> R
+    where
+        Self: Sized,
+        Fold: FnMut(Acc, Self::Item) -> R,
+        R: Try<Ok = Acc>,
     {
         self.inner.try_rfold(init, fold)
     }
 
     #[inline]
     fn rfold<Acc, Fold>(self, init: Acc, fold: Fold) -> Acc
-        where Fold: FnMut(Acc, Self::Item) -> Acc,
+    where
+        Fold: FnMut(Acc, Self::Item) -> Acc,
     {
         self.inner.rfold(init, fold)
     }
@@ -194,7 +232,8 @@ impl<I, U> FusedIterator for Flatten<I>
 where
     I: FusedIterator<Item: IntoIterator<IntoIter = U, Item = U::Item>>,
     U: Iterator,
-{}
+{
+}
 
 /// Real logic of both `Flatten` and `FlatMap` which simply delegate to
 /// this type.
@@ -222,7 +261,9 @@ impl<I, U> Iterator for FlattenCompat<I, U>
     fn next(&mut self) -> Option<U::Item> {
         loop {
             if let Some(ref mut inner) = self.frontiter {
-                if let elt@Some(_) = inner.next() { return elt }
+                if let elt @ Some(_) = inner.next() {
+                    return elt;
+                }
             }
             match self.iter.next() {
                 None => return self.backiter.as_mut()?.next(),
@@ -238,13 +279,16 @@ fn size_hint(&self) -> (usize, Option<usize>) {
         let lo = flo.saturating_add(blo);
         match (self.iter.size_hint(), fhi, bhi) {
             ((0, Some(0)), Some(a), Some(b)) => (lo, a.checked_add(b)),
-            _ => (lo, None)
+            _ => (lo, None),
         }
     }
 
     #[inline]
-    fn try_fold<Acc, Fold, R>(&mut self, mut init: Acc, mut fold: Fold) -> R where
-        Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, R: Try<Ok=Acc>
+    fn try_fold<Acc, Fold, R>(&mut self, mut init: Acc, mut fold: Fold) -> R
+    where
+        Self: Sized,
+        Fold: FnMut(Acc, Self::Item) -> R,
+        R: Try<Ok = Acc>,
     {
         #[inline]
         fn flatten<'a, T: IntoIterator, Acc, R: Try<Ok = Acc>>(
@@ -277,7 +321,8 @@ fn flatten<'a, T: IntoIterator, Acc, R: Try<Ok = Acc>>(
 
     #[inline]
     fn fold<Acc, Fold>(self, init: Acc, ref mut fold: Fold) -> Acc
-        where Fold: FnMut(Acc, Self::Item) -> Acc,
+    where
+        Fold: FnMut(Acc, Self::Item) -> Acc,
     {
         #[inline]
         fn flatten<U: Iterator, Acc>(
@@ -286,7 +331,8 @@ fn flatten<U: Iterator, Acc>(
             move |acc, iter| iter.fold(acc, &mut *fold)
         }
 
-        self.frontiter.into_iter()
+        self.frontiter
+            .into_iter()
             .chain(self.iter.map(IntoIterator::into_iter))
             .chain(self.backiter)
             .fold(init, flatten(fold))
@@ -302,7 +348,9 @@ impl<I, U> DoubleEndedIterator for FlattenCompat<I, U>
     fn next_back(&mut self) -> Option<U::Item> {
         loop {
             if let Some(ref mut inner) = self.backiter {
-                if let elt@Some(_) = inner.next_back() { return elt }
+                if let elt @ Some(_) = inner.next_back() {
+                    return elt;
+                }
             }
             match self.iter.next_back() {
                 None => return self.frontiter.as_mut()?.next_back(),
@@ -312,14 +360,18 @@ fn next_back(&mut self) -> Option<U::Item> {
     }
 
     #[inline]
-    fn try_rfold<Acc, Fold, R>(&mut self, mut init: Acc, mut fold: Fold) -> R where
-        Self: Sized, Fold: FnMut(Acc, Self::Item) -> R, R: Try<Ok=Acc>
+    fn try_rfold<Acc, Fold, R>(&mut self, mut init: Acc, mut fold: Fold) -> R
+    where
+        Self: Sized,
+        Fold: FnMut(Acc, Self::Item) -> R,
+        R: Try<Ok = Acc>,
     {
         #[inline]
         fn flatten<'a, T: IntoIterator, Acc, R: Try<Ok = Acc>>(
             backiter: &'a mut Option<T::IntoIter>,
             fold: &'a mut impl FnMut(Acc, T::Item) -> R,
-        ) -> impl FnMut(Acc, T) -> R + 'a where
+        ) -> impl FnMut(Acc, T) -> R + 'a
+        where
             T::IntoIter: DoubleEndedIterator,
         {
             move |acc, x| {
@@ -348,7 +400,8 @@ fn flatten<'a, T: IntoIterator, Acc, R: Try<Ok = Acc>>(
 
     #[inline]
     fn rfold<Acc, Fold>(self, init: Acc, ref mut fold: Fold) -> Acc
-        where Fold: FnMut(Acc, Self::Item) -> Acc,
+    where
+        Fold: FnMut(Acc, Self::Item) -> Acc,
     {
         #[inline]
         fn flatten<U: DoubleEndedIterator, Acc>(
@@ -357,7 +410,8 @@ fn flatten<U: DoubleEndedIterator, Acc>(
             move |acc, iter| iter.rfold(acc, &mut *fold)
         }
 
-        self.frontiter.into_iter()
+        self.frontiter
+            .into_iter()
             .chain(self.iter.map(IntoIterator::into_iter))
             .chain(self.backiter)
             .rfold(init, flatten(fold))
index 183176005ede9605ba289c018d6adbe18f6d69c5..ffac7d4e995389981fcb65d557cba78457751df4 100644 (file)
@@ -12,7 +12,7 @@
 #[derive(Clone, Debug)]
 #[stable(feature = "rust1", since = "1.0.0")]
 pub struct Repeat<A> {
-    element: A
+    element: A,
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
@@ -20,15 +20,21 @@ impl<A: Clone> Iterator for Repeat<A> {
     type Item = A;
 
     #[inline]
-    fn next(&mut self) -> Option<A> { Some(self.element.clone()) }
+    fn next(&mut self) -> Option<A> {
+        Some(self.element.clone())
+    }
     #[inline]
-    fn size_hint(&self) -> (usize, Option<usize>) { (usize::MAX, None) }
+    fn size_hint(&self) -> (usize, Option<usize>) {
+        (usize::MAX, None)
+    }
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<A: Clone> DoubleEndedIterator for Repeat<A> {
     #[inline]
-    fn next_back(&mut self) -> Option<A> { Some(self.element.clone()) }
+    fn next_back(&mut self) -> Option<A> {
+        Some(self.element.clone())
+    }
 }
 
 #[stable(feature = "fused", since = "1.26.0")]
@@ -91,7 +97,7 @@ unsafe impl<A: Clone> TrustedLen for Repeat<A> {}
 #[inline]
 #[stable(feature = "rust1", since = "1.0.0")]
 pub fn repeat<T: Clone>(elt: T) -> Repeat<T> {
-    Repeat{element: elt}
+    Repeat { element: elt }
 }
 
 /// An iterator that repeats elements of type `A` endlessly by
@@ -104,7 +110,7 @@ pub fn repeat<T: Clone>(elt: T) -> Repeat<T> {
 #[derive(Copy, Clone, Debug)]
 #[stable(feature = "iterator_repeat_with", since = "1.28.0")]
 pub struct RepeatWith<F> {
-    repeater: F
+    repeater: F,
 }
 
 #[stable(feature = "iterator_repeat_with", since = "1.28.0")]
@@ -112,10 +118,14 @@ impl<A, F: FnMut() -> A> Iterator for RepeatWith<F> {
     type Item = A;
 
     #[inline]
-    fn next(&mut self) -> Option<A> { Some((self.repeater)()) }
+    fn next(&mut self) -> Option<A> {
+        Some((self.repeater)())
+    }
 
     #[inline]
-    fn size_hint(&self) -> (usize, Option<usize>) { (usize::MAX, None) }
+    fn size_hint(&self) -> (usize, Option<usize>) {
+        (usize::MAX, None)
+    }
 }
 
 #[stable(feature = "iterator_repeat_with", since = "1.28.0")]
@@ -213,7 +223,7 @@ fn next(&mut self) -> Option<T> {
         None
     }
 
-    fn size_hint(&self) -> (usize, Option<usize>){
+    fn size_hint(&self) -> (usize, Option<usize>) {
         (0, Some(0))
     }
 }
@@ -283,7 +293,7 @@ pub const fn empty<T>() -> Empty<T> {
 #[derive(Clone, Debug)]
 #[stable(feature = "iter_once", since = "1.2.0")]
 pub struct Once<T> {
-    inner: crate::option::IntoIter<T>
+    inner: crate::option::IntoIter<T>,
 }
 
 #[stable(feature = "iter_once", since = "1.2.0")]
@@ -530,7 +540,8 @@ pub fn once_with<A, F: FnOnce() -> A>(gen: F) -> OnceWith<F> {
 #[inline]
 #[stable(feature = "iter_from_fn", since = "1.34.0")]
 pub fn from_fn<T, F>(f: F) -> FromFn<F>
-    where F: FnMut() -> Option<T>
+where
+    F: FnMut() -> Option<T>,
 {
     FromFn(f)
 }
@@ -547,7 +558,8 @@ pub fn from_fn<T, F>(f: F) -> FromFn<F>
 
 #[stable(feature = "iter_from_fn", since = "1.34.0")]
 impl<T, F> Iterator for FromFn<F>
-    where F: FnMut() -> Option<T>
+where
+    F: FnMut() -> Option<T>,
 {
     type Item = T;
 
@@ -577,15 +589,13 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 /// ```
 #[stable(feature = "iter_successors", since = "1.34.0")]
 pub fn successors<T, F>(first: Option<T>, succ: F) -> Successors<T, F>
-    where F: FnMut(&T) -> Option<T>
+where
+    F: FnMut(&T) -> Option<T>,
 {
     // If this function returned `impl Iterator<Item=T>`
     // it could be based on `unfold` and not need a dedicated type.
     // However having a named `Successors<T, F>` type allows it to be `Clone` when `T` and `F` are.
-    Successors {
-        next: first,
-        succ,
-    }
+    Successors { next: first, succ }
 }
 
 /// An new iterator where each successive item is computed based on the preceding one.
@@ -603,7 +613,8 @@ pub struct Successors<T, F> {
 
 #[stable(feature = "iter_successors", since = "1.34.0")]
 impl<T, F> Iterator for Successors<T, F>
-    where F: FnMut(&T) -> Option<T>
+where
+    F: FnMut(&T) -> Option<T>,
 {
     type Item = T;
 
@@ -616,24 +627,16 @@ fn next(&mut self) -> Option<Self::Item> {
 
     #[inline]
     fn size_hint(&self) -> (usize, Option<usize>) {
-        if self.next.is_some() {
-            (1, None)
-        } else {
-            (0, Some(0))
-        }
+        if self.next.is_some() { (1, None) } else { (0, Some(0)) }
     }
 }
 
 #[stable(feature = "iter_successors", since = "1.34.0")]
-impl<T, F> FusedIterator for Successors<T, F>
-    where F: FnMut(&T) -> Option<T>
-{}
+impl<T, F> FusedIterator for Successors<T, F> where F: FnMut(&T) -> Option<T> {}
 
 #[stable(feature = "iter_successors", since = "1.34.0")]
 impl<T: fmt::Debug, F> fmt::Debug for Successors<T, F> {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        f.debug_struct("Successors")
-            .field("next", &self.next)
-            .finish()
+        f.debug_struct("Successors").field("next", &self.next).finish()
     }
 }
index 818f03303298f7b250d50486ca144b629f0a9954..65af671ddf2045005f24cf1a8b92a1eea5eb7e4b 100644 (file)
@@ -1,6 +1,6 @@
-use crate::ops::{Mul, Add};
-use crate::num::Wrapping;
 use crate::iter;
+use crate::num::Wrapping;
+use crate::ops::{Add, Mul};
 
 /// Trait to represent types that can be created by summing up an iterator.
 ///
@@ -17,7 +17,7 @@ pub trait Sum<A = Self>: Sized {
     /// Method which takes an iterator and generates `Self` from the elements by
     /// "summing up" the items.
     #[stable(feature = "iter_arith_traits", since = "1.12.0")]
-    fn sum<I: Iterator<Item=A>>(iter: I) -> Self;
+    fn sum<I: Iterator<Item = A>>(iter: I) -> Self;
 }
 
 /// Trait to represent types that can be created by multiplying elements of an
@@ -36,7 +36,7 @@ pub trait Product<A = Self>: Sized {
     /// Method which takes an iterator and generates `Self` from the elements by
     /// multiplying the items.
     #[stable(feature = "iter_arith_traits", since = "1.12.0")]
-    fn product<I: Iterator<Item=A>>(iter: I) -> Self;
+    fn product<I: Iterator<Item = A>>(iter: I) -> Self;
 }
 
 // N.B., explicitly use Add and Mul here to inherit overflow checks
@@ -115,9 +115,10 @@ fn product<I: Iterator<Item=&'a $a>>(iter: I) -> $a {
 integer_sum_product! { i8 i16 i32 i64 i128 isize u8 u16 u32 u64 u128 usize }
 float_sum_product! { f32 f64 }
 
-#[stable(feature = "iter_arith_traits_result", since="1.16.0")]
+#[stable(feature = "iter_arith_traits_result", since = "1.16.0")]
 impl<T, U, E> Sum<Result<U, E>> for Result<T, E>
-    where T: Sum<U>,
+where
+    T: Sum<U>,
 {
     /// Takes each element in the `Iterator`: if it is an `Err`, no further
     /// elements are taken, and the `Err` is returned. Should no `Err` occur,
@@ -137,21 +138,24 @@ impl<T, U, E> Sum<Result<U, E>> for Result<T, E>
     /// assert_eq!(res, Ok(3));
     /// ```
     fn sum<I>(iter: I) -> Result<T, E>
-        where I: Iterator<Item = Result<U, E>>,
+    where
+        I: Iterator<Item = Result<U, E>>,
     {
         iter::process_results(iter, |i| i.sum())
     }
 }
 
-#[stable(feature = "iter_arith_traits_result", since="1.16.0")]
+#[stable(feature = "iter_arith_traits_result", since = "1.16.0")]
 impl<T, U, E> Product<Result<U, E>> for Result<T, E>
-    where T: Product<U>,
+where
+    T: Product<U>,
 {
     /// Takes each element in the `Iterator`: if it is an `Err`, no further
     /// elements are taken, and the `Err` is returned. Should no `Err` occur,
     /// the product of all elements is returned.
     fn product<I>(iter: I) -> Result<T, E>
-        where I: Iterator<Item = Result<U, E>>,
+    where
+        I: Iterator<Item = Result<U, E>>,
     {
         iter::process_results(iter, |i| i.product())
     }
index 006b243ca42aa8c328060987edbf9c90013c2ff4..104724d9fb63a2bae43f7e5c14f0fa08a0928054 100644 (file)
@@ -1,5 +1,5 @@
-use crate::ops::Try;
 use crate::iter::LoopState;
+use crate::ops::Try;
 
 /// An iterator able to yield elements from both ends.
 ///
@@ -113,7 +113,9 @@ pub trait DoubleEndedIterator: Iterator {
     #[stable(feature = "iter_nth_back", since = "1.37.0")]
     fn nth_back(&mut self, mut n: usize) -> Option<Self::Item> {
         for x in self.rev() {
-            if n == 0 { return Some(x) }
+            if n == 0 {
+                return Some(x);
+            }
             n -= 1;
         }
         None
@@ -157,7 +159,7 @@ fn try_rfold<B, F, R>(&mut self, init: B, mut f: F) -> R
     where
         Self: Sized,
         F: FnMut(B, Self::Item) -> R,
-        R: Try<Ok=B>
+        R: Try<Ok = B>,
     {
         let mut accum = init;
         while let Some(x) = self.next_back() {
@@ -279,7 +281,7 @@ fn ok<B, T>(mut f: impl FnMut(B, T) -> B) -> impl FnMut(B, T) -> Result<B, !> {
     fn rfind<P>(&mut self, predicate: P) -> Option<Self::Item>
     where
         Self: Sized,
-        P: FnMut(&Self::Item) -> bool
+        P: FnMut(&Self::Item) -> bool,
     {
         #[inline]
         fn check<T>(
index 7f27e62fb159836b3984ccdf1b635592d78f7939..cf460745ffa3032faea6500731a7c0cffcbeda80 100644 (file)
@@ -337,13 +337,17 @@ macro_rules! matches {
 #[rustc_deprecated(since = "1.39.0", reason = "use the `?` operator instead")]
 #[doc(alias = "?")]
 macro_rules! r#try {
-    ($expr:expr) => (match $expr {
-        $crate::result::Result::Ok(val) => val,
-        $crate::result::Result::Err(err) => {
-            return $crate::result::Result::Err($crate::convert::From::from(err))
+    ($expr:expr) => {
+        match $expr {
+            $crate::result::Result::Ok(val) => val,
+            $crate::result::Result::Err(err) => {
+                return $crate::result::Result::Err($crate::convert::From::from(err));
+            }
         }
-    });
-    ($expr:expr,) => ($crate::r#try!($expr));
+    };
+    ($expr:expr,) => {
+        $crate::r#try!($expr)
+    };
 }
 
 /// Writes formatted data into a buffer.
@@ -734,8 +738,8 @@ pub(crate) mod builtin {
     #[rustc_builtin_macro]
     #[macro_export]
     macro_rules! compile_error {
-        ($msg:expr) => ({ /* compiler built-in */ });
-        ($msg:expr,) => ({ /* compiler built-in */ })
+        ($msg:expr) => {{ /* compiler built-in */ }};
+        ($msg:expr,) => {{ /* compiler built-in */ }};
     }
 
     /// Constructs parameters for the other string-formatting macros.
@@ -788,20 +792,23 @@ macro_rules! compile_error {
     #[rustc_builtin_macro]
     #[macro_export]
     macro_rules! format_args {
-        ($fmt:expr) => ({ /* compiler built-in */ });
-        ($fmt:expr, $($args:tt)*) => ({ /* compiler built-in */ })
+        ($fmt:expr) => {{ /* compiler built-in */ }};
+        ($fmt:expr, $($args:tt)*) => {{ /* compiler built-in */ }};
     }
 
     /// Same as `format_args`, but adds a newline in the end.
-    #[unstable(feature = "format_args_nl", issue = "0",
-               reason = "`format_args_nl` is only for internal \
-                         language use and is subject to change")]
+    #[unstable(
+        feature = "format_args_nl",
+        issue = "0",
+        reason = "`format_args_nl` is only for internal \
+                  language use and is subject to change"
+    )]
     #[allow_internal_unstable(fmt_internals)]
     #[rustc_builtin_macro]
     #[macro_export]
     macro_rules! format_args_nl {
-        ($fmt:expr) => ({ /* compiler built-in */ });
-        ($fmt:expr, $($args:tt)*) => ({ /* compiler built-in */ })
+        ($fmt:expr) => {{ /* compiler built-in */ }};
+        ($fmt:expr, $($args:tt)*) => {{ /* compiler built-in */ }};
     }
 
     /// Inspects an environment variable at compile time.
@@ -839,8 +846,8 @@ macro_rules! format_args_nl {
     #[rustc_builtin_macro]
     #[macro_export]
     macro_rules! env {
-        ($name:expr) => ({ /* compiler built-in */ });
-        ($name:expr,) => ({ /* compiler built-in */ })
+        ($name:expr) => {{ /* compiler built-in */ }};
+        ($name:expr,) => {{ /* compiler built-in */ }};
     }
 
     /// Optionally inspects an environment variable at compile time.
@@ -866,8 +873,8 @@ macro_rules! env {
     #[rustc_builtin_macro]
     #[macro_export]
     macro_rules! option_env {
-        ($name:expr) => ({ /* compiler built-in */ });
-        ($name:expr,) => ({ /* compiler built-in */ })
+        ($name:expr) => {{ /* compiler built-in */ }};
+        ($name:expr,) => {{ /* compiler built-in */ }};
     }
 
     /// Concatenates identifiers into one identifier.
@@ -894,13 +901,16 @@ macro_rules! option_env {
     /// // fn concat_idents!(new, fun, name) { } // not usable in this way!
     /// # }
     /// ```
-    #[unstable(feature = "concat_idents", issue = "29599",
-               reason = "`concat_idents` is not stable enough for use and is subject to change")]
+    #[unstable(
+        feature = "concat_idents",
+        issue = "29599",
+        reason = "`concat_idents` is not stable enough for use and is subject to change"
+    )]
     #[rustc_builtin_macro]
     #[macro_export]
     macro_rules! concat_idents {
-        ($($e:ident),+) => ({ /* compiler built-in */ });
-        ($($e:ident,)+) => ({ /* compiler built-in */ })
+        ($($e:ident),+) => {{ /* compiler built-in */ }};
+        ($($e:ident,)+) => {{ /* compiler built-in */ }};
     }
 
     /// Concatenates literals into a static string slice.
@@ -922,8 +932,8 @@ macro_rules! concat_idents {
     #[rustc_builtin_macro]
     #[macro_export]
     macro_rules! concat {
-        ($($e:expr),*) => ({ /* compiler built-in */ });
-        ($($e:expr,)*) => ({ /* compiler built-in */ })
+        ($($e:expr),*) => {{ /* compiler built-in */ }};
+        ($($e:expr,)*) => {{ /* compiler built-in */ }};
     }
 
     /// Expands to the line number on which it was invoked.
@@ -950,7 +960,11 @@ macro_rules! concat {
     #[stable(feature = "rust1", since = "1.0.0")]
     #[rustc_builtin_macro]
     #[macro_export]
-    macro_rules! line { () => { /* compiler built-in */ } }
+    macro_rules! line {
+        () => {
+            /* compiler built-in */
+        };
+    }
 
     /// Expands to the column number at which it was invoked.
     ///
@@ -976,7 +990,11 @@ macro_rules! line { () => { /* compiler built-in */ } }
     #[stable(feature = "rust1", since = "1.0.0")]
     #[rustc_builtin_macro]
     #[macro_export]
-    macro_rules! column { () => { /* compiler built-in */ } }
+    macro_rules! column {
+        () => {
+            /* compiler built-in */
+        };
+    }
 
     /// Expands to the file name in which it was invoked.
     ///
@@ -1001,7 +1019,11 @@ macro_rules! column { () => { /* compiler built-in */ } }
     #[stable(feature = "rust1", since = "1.0.0")]
     #[rustc_builtin_macro]
     #[macro_export]
-    macro_rules! file { () => { /* compiler built-in */ } }
+    macro_rules! file {
+        () => {
+            /* compiler built-in */
+        };
+    }
 
     /// Stringifies its arguments.
     ///
@@ -1021,7 +1043,11 @@ macro_rules! file { () => { /* compiler built-in */ } }
     #[stable(feature = "rust1", since = "1.0.0")]
     #[rustc_builtin_macro]
     #[macro_export]
-    macro_rules! stringify { ($($t:tt)*) => { /* compiler built-in */ } }
+    macro_rules! stringify {
+        ($($t:tt)*) => {
+            /* compiler built-in */
+        };
+    }
 
     /// Includes a utf8-encoded file as a string.
     ///
@@ -1057,8 +1083,8 @@ macro_rules! stringify { ($($t:tt)*) => { /* compiler built-in */ } }
     #[rustc_builtin_macro]
     #[macro_export]
     macro_rules! include_str {
-        ($file:expr) => ({ /* compiler built-in */ });
-        ($file:expr,) => ({ /* compiler built-in */ })
+        ($file:expr) => {{ /* compiler built-in */ }};
+        ($file:expr,) => {{ /* compiler built-in */ }};
     }
 
     /// Includes a file as a reference to a byte array.
@@ -1095,8 +1121,8 @@ macro_rules! include_str {
     #[rustc_builtin_macro]
     #[macro_export]
     macro_rules! include_bytes {
-        ($file:expr) => ({ /* compiler built-in */ });
-        ($file:expr,) => ({ /* compiler built-in */ })
+        ($file:expr) => {{ /* compiler built-in */ }};
+        ($file:expr,) => {{ /* compiler built-in */ }};
     }
 
     /// Expands to a string that represents the current module path.
@@ -1119,7 +1145,11 @@ macro_rules! include_bytes {
     #[stable(feature = "rust1", since = "1.0.0")]
     #[rustc_builtin_macro]
     #[macro_export]
-    macro_rules! module_path { () => { /* compiler built-in */ } }
+    macro_rules! module_path {
+        () => {
+            /* compiler built-in */
+        };
+    }
 
     /// Evaluates boolean combinations of configuration flags at compile-time.
     ///
@@ -1144,7 +1174,11 @@ macro_rules! module_path { () => { /* compiler built-in */ } }
     #[stable(feature = "rust1", since = "1.0.0")]
     #[rustc_builtin_macro]
     #[macro_export]
-    macro_rules! cfg { ($($cfg:tt)*) => { /* compiler built-in */ } }
+    macro_rules! cfg {
+        ($($cfg:tt)*) => {
+            /* compiler built-in */
+        };
+    }
 
     /// Parses a file as an expression or an item according to the context.
     ///
@@ -1189,8 +1223,8 @@ macro_rules! cfg { ($($cfg:tt)*) => { /* compiler built-in */ } }
     #[rustc_builtin_macro]
     #[macro_export]
     macro_rules! include {
-        ($file:expr) => ({ /* compiler built-in */ });
-        ($file:expr,) => ({ /* compiler built-in */ })
+        ($file:expr) => {{ /* compiler built-in */ }};
+        ($file:expr,) => {{ /* compiler built-in */ }};
     }
 
     /// Asserts that a boolean expression is `true` at runtime.
@@ -1242,9 +1276,9 @@ macro_rules! include {
     #[rustc_builtin_macro]
     #[macro_export]
     macro_rules! assert {
-        ($cond:expr) => ({ /* compiler built-in */ });
-        ($cond:expr,) => ({ /* compiler built-in */ });
-        ($cond:expr, $($arg:tt)+) => ({ /* compiler built-in */ })
+        ($cond:expr) => {{ /* compiler built-in */ }};
+        ($cond:expr,) => {{ /* compiler built-in */ }};
+        ($cond:expr, $($arg:tt)+) => {{ /* compiler built-in */ }};
     }
 
     /// Inline assembly.
@@ -1252,75 +1286,118 @@ macro_rules! assert {
     /// Read the [unstable book] for the usage.
     ///
     /// [unstable book]: ../unstable-book/library-features/asm.html
-    #[unstable(feature = "asm", issue = "29722",
-               reason = "inline assembly is not stable enough for use and is subject to change")]
+    #[unstable(
+        feature = "asm",
+        issue = "29722",
+        reason = "inline assembly is not stable enough for use and is subject to change"
+    )]
     #[rustc_builtin_macro]
     #[macro_export]
-    macro_rules! asm { ("assembly template"
+    macro_rules! asm {
+        ("assembly template"
                         : $("output"(operand),)*
                         : $("input"(operand),)*
                         : $("clobbers",)*
-                        : $("options",)*) => { /* compiler built-in */ } }
+                        : $("options",)*) => {
+            /* compiler built-in */
+        };
+    }
 
     /// Module-level inline assembly.
-    #[unstable(feature = "global_asm", issue = "35119",
-               reason = "`global_asm!` is not stable enough for use and is subject to change")]
+    #[unstable(
+        feature = "global_asm",
+        issue = "35119",
+        reason = "`global_asm!` is not stable enough for use and is subject to change"
+    )]
     #[rustc_builtin_macro]
     #[macro_export]
-    macro_rules! global_asm { ("assembly") => { /* compiler built-in */ } }
+    macro_rules! global_asm {
+        ("assembly") => {
+            /* compiler built-in */
+        };
+    }
 
     /// Prints passed tokens into the standard output.
-    #[unstable(feature = "log_syntax", issue = "29598",
-               reason = "`log_syntax!` is not stable enough for use and is subject to change")]
+    #[unstable(
+        feature = "log_syntax",
+        issue = "29598",
+        reason = "`log_syntax!` is not stable enough for use and is subject to change"
+    )]
     #[rustc_builtin_macro]
     #[macro_export]
-    macro_rules! log_syntax { ($($arg:tt)*) => { /* compiler built-in */ } }
+    macro_rules! log_syntax {
+        ($($arg:tt)*) => {
+            /* compiler built-in */
+        };
+    }
 
     /// Enables or disables tracing functionality used for debugging other macros.
-    #[unstable(feature = "trace_macros", issue = "29598",
-               reason = "`trace_macros` is not stable enough for use and is subject to change")]
+    #[unstable(
+        feature = "trace_macros",
+        issue = "29598",
+        reason = "`trace_macros` is not stable enough for use and is subject to change"
+    )]
     #[rustc_builtin_macro]
     #[macro_export]
     macro_rules! trace_macros {
-        (true) => ({ /* compiler built-in */ });
-        (false) => ({ /* compiler built-in */ })
+        (true) => {{ /* compiler built-in */ }};
+        (false) => {{ /* compiler built-in */ }};
     }
 
     /// Attribute macro applied to a function to turn it into a unit test.
     #[stable(feature = "rust1", since = "1.0.0")]
     #[allow_internal_unstable(test, rustc_attrs)]
     #[rustc_builtin_macro]
-    pub macro test($item:item) { /* compiler built-in */ }
+    pub macro test($item:item) {
+        /* compiler built-in */
+    }
 
     /// Attribute macro applied to a function to turn it into a benchmark test.
-    #[unstable(soft, feature = "test", issue = "50297",
-               reason = "`bench` is a part of custom test frameworks which are unstable")]
+    #[unstable(
+        feature = "test",
+        issue = "50297",
+        soft,
+        reason = "`bench` is a part of custom test frameworks which are unstable"
+    )]
     #[allow_internal_unstable(test, rustc_attrs)]
     #[rustc_builtin_macro]
-    pub macro bench($item:item) { /* compiler built-in */ }
+    pub macro bench($item:item) {
+        /* compiler built-in */
+    }
 
     /// An implementation detail of the `#[test]` and `#[bench]` macros.
-    #[unstable(feature = "custom_test_frameworks", issue = "50297",
-               reason = "custom test frameworks are an unstable feature")]
+    #[unstable(
+        feature = "custom_test_frameworks",
+        issue = "50297",
+        reason = "custom test frameworks are an unstable feature"
+    )]
     #[allow_internal_unstable(test, rustc_attrs)]
     #[rustc_builtin_macro]
-    pub macro test_case($item:item) { /* compiler built-in */ }
+    pub macro test_case($item:item) {
+        /* compiler built-in */
+    }
 
     /// Attribute macro applied to a static to register it as a global allocator.
     #[stable(feature = "global_allocator", since = "1.28.0")]
     #[allow_internal_unstable(rustc_attrs)]
     #[rustc_builtin_macro]
-    pub macro global_allocator($item:item) { /* compiler built-in */ }
+    pub macro global_allocator($item:item) {
+        /* compiler built-in */
+    }
 
     /// Unstable implementation detail of the `rustc` compiler, do not use.
     #[rustc_builtin_macro]
     #[stable(feature = "rust1", since = "1.0.0")]
     #[allow_internal_unstable(core_intrinsics, libstd_sys_internals)]
-    pub macro RustcDecodable($item:item) { /* compiler built-in */ }
+    pub macro RustcDecodable($item:item) {
+        /* compiler built-in */
+    }
 
     /// Unstable implementation detail of the `rustc` compiler, do not use.
     #[rustc_builtin_macro]
     #[stable(feature = "rust1", since = "1.0.0")]
     #[allow_internal_unstable(core_intrinsics)]
-    pub macro RustcEncodable($item:item) { /* compiler built-in */ }
+    pub macro RustcEncodable($item:item) {
+        /* compiler built-in */
+    }
 }
index bb353993236289b2ae4d131d9d4352fb34b0b8b4..34fc0618ea2ae182655e4db3e02b95a2ef9c846f 100644 (file)
@@ -1,5 +1,5 @@
-use crate::ptr;
 use crate::ops::{Deref, DerefMut};
+use crate::ptr;
 
 /// A wrapper to inhibit compiler from automatically calling `T`’s destructor.
 ///
index 342ac69748d92a5d35d97cb53d8af2f7fcee56d6..b8ddd5322a1da04245272c1dfdc98f0c8aa99d67 100644 (file)
 // This module is only for dec2flt and flt2dec, and only public because of coretests.
 // It is not intended to ever be stabilized.
 #![doc(hidden)]
-#![unstable(feature = "core_private_bignum",
-            reason = "internal routines only exposed for testing",
-            issue = "0")]
+#![unstable(
+    feature = "core_private_bignum",
+    reason = "internal routines only exposed for testing",
+    issue = "0"
+)]
 #![macro_use]
 
-use crate::mem;
 use crate::intrinsics;
+use crate::mem;
 
 /// Arithmetic operations required by bignums.
 pub trait FullOps: Sized {
@@ -36,10 +38,8 @@ pub trait FullOps: Sized {
 
     /// Returns `(quo, rem)` such that `borrow * 2^W + self = quo * other + rem`
     /// and `0 <= rem < other`, where `W` is the number of bits in `Self`.
-    fn full_div_rem(self,
-                    other: Self,
-                    borrow: Self)
-                    -> (Self /* quotient */, Self /* remainder */);
+    fn full_div_rem(self, other: Self, borrow: Self)
+    -> (Self /* quotient */, Self /* remainder */);
 }
 
 macro_rules! impl_full_ops {
@@ -98,7 +98,7 @@ fn full_div_rem(self, other: $ty, borrow: $ty) -> ($ty, $ty) {
 const SMALL_POW5: [(u64, usize); 3] = [(125, 3), (15625, 6), (1_220_703_125, 13)];
 
 macro_rules! define_bignum {
-    ($name:ident: type=$ty:ty, n=$n:expr) => (
+    ($name:ident: type=$ty:ty, n=$n:expr) => {
         /// Stack-allocated arbitrary-precision (up to certain limit) integer.
         ///
         /// This is backed by a fixed-size array of given type ("digit").
@@ -115,7 +115,7 @@ pub struct $name {
             size: usize,
             /// Digits. `[a, b, c, ...]` represents `a + b*2^W + c*2^(2W) + ...`
             /// where `W` is the number of bits in the digit type.
-            base: [$ty; $n]
+            base: [$ty; $n],
         }
 
         impl $name {
@@ -180,7 +180,7 @@ pub fn bit_length(&self) -> usize {
                 }
                 // This could be optimized with leading_zeros() and bit shifts, but that's
                 // probably not worth the hassle.
-                let digitbits = mem::size_of::<$ty>()* 8;
+                let digitbits = mem::size_of::<$ty>() * 8;
                 let mut i = nonzero.len() * digitbits - 1;
                 while self.get_bit(i) == 0 {
                     i -= 1;
@@ -272,12 +272,12 @@ pub fn mul_pow2(&mut self, bits: usize) -> &mut $name {
                 let bits = bits % digitbits;
 
                 assert!(digits < $n);
-                debug_assert!(self.base[$n-digits..].iter().all(|&v| v == 0));
-                debug_assert!(bits == 0 || (self.base[$n-digits-1] >> (digitbits - bits)) == 0);
+                debug_assert!(self.base[$n - digits..].iter().all(|&v| v == 0));
+                debug_assert!(bits == 0 || (self.base[$n - digits - 1] >> (digitbits - bits)) == 0);
 
                 // shift by `digits * digitbits` bits
                 for i in (0..self.size).rev() {
-                    self.base[i+digits] = self.base[i];
+                    self.base[i + digits] = self.base[i];
                 }
                 for i in 0..digits {
                     self.base[i] = 0;
@@ -287,14 +287,14 @@ pub fn mul_pow2(&mut self, bits: usize) -> &mut $name {
                 let mut sz = self.size + digits;
                 if bits > 0 {
                     let last = sz;
-                    let overflow = self.base[last-1] >> (digitbits - bits);
+                    let overflow = self.base[last - 1] >> (digitbits - bits);
                     if overflow > 0 {
                         self.base[last] = overflow;
                         sz += 1;
                     }
-                    for i in (digits+1..last).rev() {
-                        self.base[i] = (self.base[i] << bits) |
-                                       (self.base[i-1] >> (digitbits - bits));
+                    for i in (digits + 1..last).rev() {
+                        self.base[i] =
+                            (self.base[i] << bits) | (self.base[i - 1] >> (digitbits - bits));
                     }
                     self.base[digits] <<= bits;
                     // self.base[..digits] is zero, no need to shift
@@ -331,7 +331,6 @@ pub fn mul_pow5(&mut self, mut e: usize) -> &mut $name {
                 self
             }
 
-
             /// Multiplies itself by a number described by `other[0] + other[1] * 2^W +
             /// other[2] * 2^(2W) + ...` (where `W` is the number of bits in the digit type)
             /// and returns its own mutable reference.
@@ -342,7 +341,9 @@ pub fn mul_digits<'a>(&'a mut self, other: &[$ty]) -> &'a mut $name {
 
                     let mut retsz = 0;
                     for (i, &a) in aa.iter().enumerate() {
-                        if a == 0 { continue; }
+                        if a == 0 {
+                            continue;
+                        }
                         let mut sz = bb.len();
                         let mut carry = 0;
                         for (j, &b) in bb.iter().enumerate() {
@@ -430,11 +431,12 @@ pub fn div_rem(&self, d: &$name, q: &mut $name, r: &mut $name) {
         }
 
         impl crate::cmp::PartialEq for $name {
-            fn eq(&self, other: &$name) -> bool { self.base[..] == other.base[..] }
+            fn eq(&self, other: &$name) -> bool {
+                self.base[..] == other.base[..]
+            }
         }
 
-        impl crate::cmp::Eq for $name {
-        }
+        impl crate::cmp::Eq for $name {}
 
         impl crate::cmp::PartialOrd for $name {
             fn partial_cmp(&self, other: &$name) -> crate::option::Option<crate::cmp::Ordering> {
@@ -462,17 +464,17 @@ impl crate::fmt::Debug for $name {
             fn fmt(&self, f: &mut crate::fmt::Formatter<'_>) -> crate::fmt::Result {
                 use crate::mem;
 
-                let sz = if self.size < 1 {1} else {self.size};
+                let sz = if self.size < 1 { 1 } else { self.size };
                 let digitlen = mem::size_of::<$ty>() * 2;
 
-                write!(f, "{:#x}", self.base[sz-1])?;
-                for &v in self.base[..sz-1].iter().rev() {
+                write!(f, "{:#x}", self.base[sz - 1])?;
+                for &v in self.base[..sz - 1].iter().rev() {
                     write!(f, "_{:01$x}", v, digitlen)?;
                 }
                 crate::result::Result::Ok(())
             }
         }
-    )
+    };
 }
 
 /// The digit type for `Big32x40`.
index 641463026261d9525264f2c3324473b74ad53d30..c5f6903f379c405cc294695ddb5d129044ba67c0 100644 (file)
@@ -1,11 +1,11 @@
 //! The various algorithms from the paper.
 
 use crate::cmp::min;
-use crate::cmp::Ordering::{Less, Equal, Greater};
-use crate::num::diy_float::Fp;
-use crate::num::dec2flt::table;
-use crate::num::dec2flt::rawfp::{self, Unpacked, RawFloat, fp_to_float, next_float, prev_float};
+use crate::cmp::Ordering::{Equal, Greater, Less};
 use crate::num::dec2flt::num::{self, Big};
+use crate::num::dec2flt::rawfp::{self, fp_to_float, next_float, prev_float, RawFloat, Unpacked};
+use crate::num::dec2flt::table;
+use crate::num::diy_float::Fp;
 
 /// Number of significand bits in Fp
 const P: u32 = 64;
@@ -23,9 +23,9 @@ fn power_of_ten(e: i16) -> Fp {
 
 // In most architectures, floating point operations have an explicit bit size, therefore the
 // precision of the computation is determined on a per-operation basis.
-#[cfg(any(not(target_arch="x86"), target_feature="sse2"))]
+#[cfg(any(not(target_arch = "x86"), target_feature = "sse2"))]
 mod fpu_precision {
-    pub fn set_precision<T>() { }
+    pub fn set_precision<T>() {}
 }
 
 // On x86, the x87 FPU is used for float operations if the SSE/SSE2 extensions are not available.
@@ -33,7 +33,7 @@ pub fn set_precision<T>() { }
 // round to 80 bits causing double rounding to happen when values are eventually represented as
 // 32/64 bit float values. To overcome this, the FPU control word can be set so that the
 // computations are performed in the desired precision.
-#[cfg(all(target_arch="x86", not(target_feature="sse2")))]
+#[cfg(all(target_arch = "x86", not(target_feature = "sse2")))]
 mod fpu_precision {
     use crate::mem::size_of;
 
index 4536bbc94ad803e5d83117437d581d9a52541a25..6fe9af8cbd8ee93bd2cd00067a398a0f594a233d 100644 (file)
 //! turned into {positive,negative} {zero,infinity}.
 
 #![doc(hidden)]
-#![unstable(feature = "dec2flt",
-            reason = "internal routines only exposed for testing",
-            issue = "0")]
+#![unstable(
+    feature = "dec2flt",
+    reason = "internal routines only exposed for testing",
+    issue = "0"
+)]
 
 use crate::fmt;
 use crate::str::FromStr;
 
-use self::parse::{parse_decimal, Decimal, Sign, ParseResult};
 use self::num::digits_to_big;
+use self::parse::{parse_decimal, Decimal, ParseResult, Sign};
 use self::rawfp::RawFloat;
 
 mod algorithm;
-mod table;
 mod num;
+mod table;
 // These two have their own tests.
-pub mod rawfp;
 pub mod parse;
+pub mod rawfp;
 
 macro_rules! from_str_float_impl {
     ($t:ty) => {
@@ -155,7 +157,7 @@ fn from_str(src: &str) -> Result<Self, ParseFloatError> {
                 dec2flt(src)
             }
         }
-    }
+    };
 }
 from_str_float_impl!(f32);
 from_str_float_impl!(f64);
@@ -171,7 +173,7 @@ fn from_str(src: &str) -> Result<Self, ParseFloatError> {
 #[derive(Debug, Clone, PartialEq, Eq)]
 #[stable(feature = "rust1", since = "1.0.0")]
 pub struct ParseFloatError {
-    kind: FloatErrorKind
+    kind: FloatErrorKind,
 }
 
 #[derive(Debug, Clone, PartialEq, Eq)]
@@ -181,10 +183,12 @@ enum FloatErrorKind {
 }
 
 impl ParseFloatError {
-    #[unstable(feature = "int_error_internals",
-               reason = "available through Error trait and this method should \
-                         not be exposed publicly",
-               issue = "0")]
+    #[unstable(
+        feature = "int_error_internals",
+        reason = "available through Error trait and this method should \
+                  not be exposed publicly",
+        issue = "0"
+    )]
     #[doc(hidden)]
     pub fn __description(&self) -> &str {
         match self.kind {
@@ -222,7 +226,7 @@ fn extract_sign(s: &str) -> (Sign, &str) {
 /// Converts a decimal string into a floating point number.
 fn dec2flt<T: RawFloat>(s: &str) -> Result<T, ParseFloatError> {
     if s.is_empty() {
-        return Err(pfe_empty())
+        return Err(pfe_empty());
     }
     let (sign, s) = extract_sign(s);
     let flt = match parse_decimal(s) {
@@ -232,8 +236,10 @@ fn dec2flt<T: RawFloat>(s: &str) -> Result<T, ParseFloatError> {
         ParseResult::Invalid => match s {
             "inf" => T::INFINITY,
             "NaN" => T::NAN,
-            _ => { return Err(pfe_invalid()); }
-        }
+            _ => {
+                return Err(pfe_invalid());
+            }
+        },
     };
 
     match sign {
index 4d50516ce546bb79e4461ee0c98a0da10fd04614..208783dd32fd5df8c271cbb0c69e308b4f3e1f2b 100644 (file)
@@ -2,7 +2,7 @@
 
 // FIXME This module's name is a bit unfortunate, since other modules also import `core::num`.
 
-use crate::cmp::Ordering::{self, Less, Equal, Greater};
+use crate::cmp::Ordering::{self, Equal, Greater, Less};
 
 pub use crate::num::bignum::Big32x40 as Big;
 
@@ -36,7 +36,10 @@ pub fn compare_with_half_ulp(f: &Big, ones_place: usize) -> Ordering {
 /// 1. using `FromStr` on `&[u8]` requires `from_utf8_unchecked`, which is bad, and
 /// 2. piecing together the results of `integral.parse()` and `fractional.parse()` is
 ///    more complicated than this entire function.
-pub fn from_str_unchecked<'a, T>(bytes: T) -> u64 where T : IntoIterator<Item=&'a u8> {
+pub fn from_str_unchecked<'a, T>(bytes: T) -> u64
+where
+    T: IntoIterator<Item = &'a u8>,
+{
     let mut result = 0;
     for &c in bytes {
         result = result * 10 + (c - b'0') as u64;
@@ -61,14 +64,9 @@ pub fn digits_to_big(integral: &[u8], fractional: &[u8]) -> Big {
 pub fn to_u64(x: &Big) -> u64 {
     assert!(x.bit_length() < 64);
     let d = x.digits();
-    if d.len() < 2 {
-        d[0] as u64
-    } else {
-        (d[1] as u64) << 32 | d[0] as u64
-    }
+    if d.len() < 2 { d[0] as u64 } else { (d[1] as u64) << 32 | d[0] as u64 }
 }
 
-
 /// Extracts a range of bits.
 
 /// Index 0 is the least significant bit and the range is half-open as usual.
index cf3664a8748867a375802be4556a83a7b907e34c..93b08bce853c7e44e143229016be2572232b07af 100644 (file)
@@ -10,8 +10,8 @@
 //! modules rely on to not panic (or overflow) in turn.
 //! To make matters worse, all that happens in a single pass over the input.
 //! So, be careful when modifying anything, and double-check with the other modules.
+use self::ParseResult::{Invalid, ShortcutToInf, ShortcutToZero, Valid};
 use super::num;
-use self::ParseResult::{Valid, ShortcutToInf, ShortcutToZero, Invalid};
 
 #[derive(Debug)]
 pub enum Sign {
index fdbdaa238e0f2f63896eb81d19f33fe07b2599c0..a127c6c3fa7ceef4b886664e4ae35da7a95951b2 100644 (file)
 //! Many functions in this module only handle normal numbers. The dec2flt routines conservatively
 //! take the universally-correct slow path (Algorithm M) for very small and very large numbers.
 //! That algorithm needs only next_float() which does handle subnormals and zeros.
-use crate::cmp::Ordering::{Less, Equal, Greater};
+use crate::cmp::Ordering::{Equal, Greater, Less};
 use crate::convert::{TryFrom, TryInto};
-use crate::ops::{Add, Mul, Div, Neg};
 use crate::fmt::{Debug, LowerExp};
-use crate::num::diy_float::Fp;
-use crate::num::FpCategory::{Infinite, Zero, Subnormal, Normal, Nan};
-use crate::num::FpCategory;
 use crate::num::dec2flt::num::{self, Big};
 use crate::num::dec2flt::table;
+use crate::num::diy_float::Fp;
+use crate::num::FpCategory;
+use crate::num::FpCategory::{Infinite, Nan, Normal, Subnormal, Zero};
+use crate::ops::{Add, Div, Mul, Neg};
 
 #[derive(Copy, Clone, Debug)]
 pub struct Unpacked {
@@ -44,13 +44,8 @@ pub fn new(sig: u64, k: i16) -> Self {
 /// See the parent module's doc comment for why this is necessary.
 ///
 /// Should **never ever** be implemented for other types or be used outside the dec2flt module.
-pub trait RawFloat
-    : Copy
-    + Debug
-    + LowerExp
-    + Mul<Output=Self>
-    + Div<Output=Self>
-    + Neg<Output=Self>
+pub trait RawFloat:
+    Copy + Debug + LowerExp + Mul<Output = Self> + Div<Output = Self> + Neg<Output = Self>
 {
     const INFINITY: Self;
     const NAN: Self;
@@ -144,7 +139,7 @@ macro_rules! other_constants {
         const INFINITY: Self = $crate::$type::INFINITY;
         const NAN: Self = $crate::$type::NAN;
         const ZERO: Self = 0.0;
-    }
+    };
 }
 
 impl RawFloat for f32 {
@@ -163,11 +158,8 @@ fn integer_decode(self) -> (u64, i16, i8) {
         let bits = self.to_bits();
         let sign: i8 = if bits >> 31 == 0 { 1 } else { -1 };
         let mut exponent: i16 = ((bits >> 23) & 0xff) as i16;
-        let mantissa = if exponent == 0 {
-            (bits & 0x7fffff) << 1
-        } else {
-            (bits & 0x7fffff) | 0x800000
-        };
+        let mantissa =
+            if exponent == 0 { (bits & 0x7fffff) << 1 } else { (bits & 0x7fffff) | 0x800000 };
         // Exponent bias + mantissa shift
         exponent -= 127 + 23;
         (mantissa as u64, exponent, sign)
@@ -188,12 +180,17 @@ fn short_fast_pow10(e: usize) -> Self {
         table::F32_SHORT_POWERS[e]
     }
 
-    fn classify(self) -> FpCategory { self.classify() }
-    fn to_bits(self) -> Self::Bits { self.to_bits() }
-    fn from_bits(v: Self::Bits) -> Self { Self::from_bits(v) }
+    fn classify(self) -> FpCategory {
+        self.classify()
+    }
+    fn to_bits(self) -> Self::Bits {
+        self.to_bits()
+    }
+    fn from_bits(v: Self::Bits) -> Self {
+        Self::from_bits(v)
+    }
 }
 
-
 impl RawFloat for f64 {
     type Bits = u64;
 
@@ -235,9 +232,15 @@ fn short_fast_pow10(e: usize) -> Self {
         table::F64_SHORT_POWERS[e]
     }
 
-    fn classify(self) -> FpCategory { self.classify() }
-    fn to_bits(self) -> Self::Bits { self.to_bits() }
-    fn from_bits(v: Self::Bits) -> Self { Self::from_bits(v) }
+    fn classify(self) -> FpCategory {
+        self.classify()
+    }
+    fn to_bits(self) -> Self::Bits {
+        self.to_bits()
+    }
+    fn from_bits(v: Self::Bits) -> Self {
+        Self::from_bits(v)
+    }
 }
 
 /// Converts an `Fp` to the closest machine float type.
@@ -248,7 +251,7 @@ pub fn fp_to_float<T: RawFloat>(x: Fp) -> T {
     let e = x.e + 63;
     if e > T::MAX_EXP {
         panic!("fp_to_float: exponent {} too large", e)
-    }  else if e > T::MIN_EXP {
+    } else if e > T::MIN_EXP {
         encode_normal(round_normal::<T>(x))
     } else {
         panic!("fp_to_float: exponent {} too small", e)
@@ -278,14 +281,15 @@ pub fn round_normal<T: RawFloat>(x: Fp) -> Unpacked {
 /// Inverse of `RawFloat::unpack()` for normalized numbers.
 /// Panics if the significand or exponent are not valid for normalized numbers.
 pub fn encode_normal<T: RawFloat>(x: Unpacked) -> T {
-    debug_assert!(T::MIN_SIG <= x.sig && x.sig <= T::MAX_SIG,
-        "encode_normal: significand not normalized");
+    debug_assert!(
+        T::MIN_SIG <= x.sig && x.sig <= T::MAX_SIG,
+        "encode_normal: significand not normalized"
+    );
     // Remove the hidden bit
     let sig_enc = x.sig & !(1 << T::EXPLICIT_SIG_BITS);
     // Adjust the exponent for exponent bias and mantissa shift
     let k_enc = x.k + T::MAX_EXP + T::EXPLICIT_SIG_BITS as i16;
-    debug_assert!(k_enc != 0 && k_enc < T::MAX_ENCODED_EXP,
-        "encode_normal: exponent out of range");
+    debug_assert!(k_enc != 0 && k_enc < T::MAX_ENCODED_EXP, "encode_normal: exponent out of range");
     // Leave sign bit at 0 ("+"), our numbers are all positive
     let bits = (k_enc as u64) << T::EXPLICIT_SIG_BITS | sig_enc;
     T::from_bits(bits.try_into().unwrap_or_else(|_| unreachable!()))
@@ -315,7 +319,7 @@ pub fn big_to_fp(f: &Big) -> Fp {
         Equal | Greater => match leading.checked_add(1) {
             Some(f) => Fp { f, e }.normalize(),
             None => Fp { f: 1 << 63, e: e + 1 },
-        }
+        },
     }
 }
 
@@ -354,8 +358,6 @@ pub fn next_float<T: RawFloat>(x: T) -> T {
         // want, and the mantissa bits become zero. Because of the hidden bit convention, this
         // too is exactly what we want!
         // Finally, f64::MAX + 1 = 7eff...f + 1 = 7ff0...0 = f64::INFINITY.
-        Zero | Subnormal | Normal => {
-            T::from_bits(x.to_bits() + T::Bits::from(1u8))
-        }
+        Zero | Subnormal | Normal => T::from_bits(x.to_bits() + T::Bits::from(1u8)),
     }
 }
index cdf332989492f564c213a19ae4970e4053419894..0e601d45a2124ba8bfc569641fe7e9f5eb4102b4 100644 (file)
@@ -3,9 +3,11 @@
 // This module is only for dec2flt and flt2dec, and only public because of coretests.
 // It is not intended to ever be stabilized.
 #![doc(hidden)]
-#![unstable(feature = "core_private_diy_float",
-            reason = "internal routines only exposed for testing",
-            issue = "0")]
+#![unstable(
+    feature = "core_private_diy_float",
+    reason = "internal routines only exposed for testing",
+    issue = "0"
+)]
 
 /// A custom 64-bit floating point type, representing `f * 2^e`.
 #[derive(Copy, Clone, Debug)]
@@ -74,9 +76,6 @@ pub fn normalize_to(&self, e: i16) -> Fp {
         assert!(edelta >= 0);
         let edelta = edelta as usize;
         assert_eq!(self.f << edelta >> edelta, self.f);
-        Fp {
-            f: self.f << edelta,
-            e,
-        }
+        Fp { f: self.f << edelta, e }
     }
 }
index 7662bba6b5e139deaf01f225fce4a2eb5d8b6181..38b3fab6d7535d8fae77d86cc31ba75b30c005c0 100644 (file)
@@ -75,6 +75,12 @@ pub mod consts {
     #[stable(feature = "rust1", since = "1.0.0")]
     pub const PI: f32 = 3.14159265358979323846264338327950288_f32;
 
+    /// The full circle constant (τ)
+    ///
+    /// Equal to 2π.
+    #[unstable(feature = "tau_constant", issue = "66770")]
+    pub const TAU: f32 = 6.28318530717958647692528676655900577_f32;
+
     /// π/2
     #[stable(feature = "rust1", since = "1.0.0")]
     pub const FRAC_PI_2: f32 = 1.57079632679489661923132169163975144_f32;
index 4a2a35dfb099928ef79a262b8e3b1f779eea845e..f093bae9590eab2939bb61e6ada2faf2ad3631a6 100644 (file)
@@ -75,6 +75,12 @@ pub mod consts {
     #[stable(feature = "rust1", since = "1.0.0")]
     pub const PI: f64 = 3.14159265358979323846264338327950288_f64;
 
+    /// The full circle constant (τ)
+    ///
+    /// Equal to 2π.
+    #[unstable(feature = "tau_constant", issue = "66770")]
+    pub const TAU: f64 = 6.28318530717958647692528676655900577_f64;
+
     /// π/2
     #[stable(feature = "rust1", since = "1.0.0")]
     pub const FRAC_PI_2: f64 = 1.57079632679489661923132169163975144_f64;
index ee0f18ba295e994247183ae600be8380470b10c1..2b74effbe2e988e5ae7645091a1e6d95cba985e9 100644 (file)
@@ -1,8 +1,8 @@
 //! Decodes a floating-point value into individual parts and error ranges.
 
-use crate::{f32, f64};
-use crate::num::FpCategory;
 use crate::num::dec2flt::rawfp::RawFloat;
+use crate::num::FpCategory;
+use crate::{f32, f64};
 
 /// Decoded unsigned finite value, such that:
 ///
@@ -47,11 +47,15 @@ pub trait DecodableFloat: RawFloat + Copy {
 }
 
 impl DecodableFloat for f32 {
-    fn min_pos_norm_value() -> Self { f32::MIN_POSITIVE }
+    fn min_pos_norm_value() -> Self {
+        f32::MIN_POSITIVE
+    }
 }
 
 impl DecodableFloat for f64 {
-    fn min_pos_norm_value() -> Self { f64::MIN_POSITIVE }
+    fn min_pos_norm_value() -> Self {
+        f64::MIN_POSITIVE
+    }
 }
 
 /// Returns a sign (true when negative) and `FullDecoded` value
@@ -67,20 +71,29 @@ pub fn decode<T: DecodableFloat>(v: T) -> (/*negative?*/ bool, FullDecoded) {
             // neighbors: (mant - 2, exp) -- (mant, exp) -- (mant + 2, exp)
             // Float::integer_decode always preserves the exponent,
             // so the mantissa is scaled for subnormals.
-            FullDecoded::Finite(Decoded { mant, minus: 1, plus: 1,
-                                          exp, inclusive: even })
+            FullDecoded::Finite(Decoded { mant, minus: 1, plus: 1, exp, inclusive: even })
         }
         FpCategory::Normal => {
             let minnorm = <T as DecodableFloat>::min_pos_norm_value().integer_decode();
             if mant == minnorm.0 {
                 // neighbors: (maxmant, exp - 1) -- (minnormmant, exp) -- (minnormmant + 1, exp)
                 // where maxmant = minnormmant * 2 - 1
-                FullDecoded::Finite(Decoded { mant: mant << 2, minus: 1, plus: 2,
-                                              exp: exp - 2, inclusive: even })
+                FullDecoded::Finite(Decoded {
+                    mant: mant << 2,
+                    minus: 1,
+                    plus: 2,
+                    exp: exp - 2,
+                    inclusive: even,
+                })
             } else {
                 // neighbors: (mant - 1, exp) -- (mant, exp) -- (mant + 1, exp)
-                FullDecoded::Finite(Decoded { mant: mant << 1, minus: 1, plus: 1,
-                                              exp: exp - 1, inclusive: even })
+                FullDecoded::Finite(Decoded {
+                    mant: mant << 1,
+                    minus: 1,
+                    plus: 1,
+                    exp: exp - 1,
+                    inclusive: even,
+                })
             }
         }
     };
index 6d42a77744966cad5240f5cffbae10f280a045b4..63df5613453238988f1720f79eaf6fec1b97ca74 100644 (file)
 // while this is extensively documented, this is in principle private which is
 // only made public for testing. do not expose us.
 #![doc(hidden)]
-#![unstable(feature = "flt2dec",
-            reason = "internal routines only exposed for testing",
-            issue = "0")]
+#![unstable(
+    feature = "flt2dec",
+    reason = "internal routines only exposed for testing",
+    issue = "0"
+)]
 
+pub use self::decoder::{decode, DecodableFloat, Decoded, FullDecoded};
 use crate::i16;
-pub use self::decoder::{decode, DecodableFloat, FullDecoded, Decoded};
 
-pub mod estimator;
 pub mod decoder;
+pub mod estimator;
 
 /// Digit-generation algorithms.
 pub mod strategy {
@@ -144,17 +146,24 @@ pub mod strategy {
 #[doc(hidden)]
 pub fn round_up(d: &mut [u8], n: usize) -> Option<u8> {
     match d[..n].iter().rposition(|&c| c != b'9') {
-        Some(i) => { // d[i+1..n] is all nines
+        Some(i) => {
+            // d[i+1..n] is all nines
             d[i] += 1;
-            for j in i+1..n { d[j] = b'0'; }
+            for j in i + 1..n {
+                d[j] = b'0';
+            }
             None
         }
-        None if n > 0 => { // 999..999 rounds to 1000..000 with an increased exponent
+        None if n > 0 => {
+            // 999..999 rounds to 1000..000 with an increased exponent
             d[0] = b'1';
-            for j in 1..n { d[j] = b'0'; }
+            for j in 1..n {
+                d[j] = b'0';
+            }
             Some(b'0')
         }
-        None => { // an empty buffer rounds up (a bit strange but reasonable)
+        None => {
+            // an empty buffer rounds up (a bit strange but reasonable)
             Some(b'1')
         }
     }
@@ -176,8 +185,19 @@ impl<'a> Part<'a> {
     pub fn len(&self) -> usize {
         match *self {
             Part::Zero(nzeroes) => nzeroes,
-            Part::Num(v) => if v < 1_000 { if v < 10 { 1 } else if v < 100 { 2 } else { 3 } }
-                            else { if v < 10_000 { 4 } else { 5 } },
+            Part::Num(v) => {
+                if v < 1_000 {
+                    if v < 10 {
+                        1
+                    } else if v < 100 {
+                        2
+                    } else {
+                        3
+                    }
+                } else {
+                    if v < 10_000 { 4 } else { 5 }
+                }
+            }
             Part::Copy(buf) => buf.len(),
         }
     }
@@ -190,7 +210,9 @@ pub fn write(&self, out: &mut [u8]) -> Option<usize> {
         if out.len() >= len {
             match *self {
                 Part::Zero(nzeroes) => {
-                    for c in &mut out[..nzeroes] { *c = b'0'; }
+                    for c in &mut out[..nzeroes] {
+                        *c = b'0';
+                    }
                 }
                 Part::Num(mut v) => {
                     for c in out[..len].iter_mut().rev() {
@@ -234,7 +256,9 @@ pub fn len(&self) -> usize {
     /// Returns the number of written bytes, or `None` if the buffer is not enough.
     /// (It may still leave partially written bytes in the buffer; do not rely on that.)
     pub fn write(&self, out: &mut [u8]) -> Option<usize> {
-        if out.len() < self.sign.len() { return None; }
+        if out.len() < self.sign.len() {
+            return None;
+        }
         out[..self.sign.len()].copy_from_slice(self.sign);
 
         let mut written = self.sign.len();
@@ -254,8 +278,12 @@ pub fn write(&self, out: &mut [u8]) -> Option<usize> {
 /// it will be ignored and full digits will be printed. It is only used to print
 /// additional zeroes after rendered digits. Thus `frac_digits` of 0 means that
 /// it will only print given digits and nothing else.
-fn digits_to_dec_str<'a>(buf: &'a [u8], exp: i16, frac_digits: usize,
-                         parts: &'a mut [Part<'a>]) -> &'a [Part<'a>] {
+fn digits_to_dec_str<'a>(
+    buf: &'a [u8],
+    exp: i16,
+    frac_digits: usize,
+    parts: &'a mut [Part<'a>],
+) -> &'a [Part<'a>] {
     assert!(!buf.is_empty());
     assert!(buf[0] > b'0');
     assert!(parts.len() >= 4);
@@ -322,8 +350,13 @@ fn digits_to_dec_str<'a>(buf: &'a [u8], exp: i16, frac_digits: usize,
 /// it will be ignored and full digits will be printed. It is only used to print
 /// additional zeroes after rendered digits. Thus, `min_digits == 0` means that
 /// it will only print the given digits and nothing else.
-fn digits_to_exp_str<'a>(buf: &'a [u8], exp: i16, min_ndigits: usize, upper: bool,
-                         parts: &'a mut [Part<'a>]) -> &'a [Part<'a>] {
+fn digits_to_exp_str<'a>(
+    buf: &'a [u8],
+    exp: i16,
+    min_ndigits: usize,
+    upper: bool,
+    parts: &'a mut [Part<'a>],
+) -> &'a [Part<'a>] {
     assert!(!buf.is_empty());
     assert!(buf[0] > b'0');
     assert!(parts.len() >= 6);
@@ -359,11 +392,11 @@ fn digits_to_exp_str<'a>(buf: &'a [u8], exp: i16, min_ndigits: usize, upper: boo
 #[derive(Copy, Clone, PartialEq, Eq, Debug)]
 pub enum Sign {
     /// Prints `-` only for the negative non-zero values.
-    Minus,        // -inf -1  0  0  1  inf nan
+    Minus, // -inf -1  0  0  1  inf nan
     /// Prints `-` only for any negative values (including the negative zero).
-    MinusRaw,     // -inf -1 -0  0  1  inf nan
+    MinusRaw, // -inf -1 -0  0  1  inf nan
     /// Prints `-` for the negative non-zero values, or `+` otherwise.
-    MinusPlus,    // -inf -1 +0 +0 +1 +inf nan
+    MinusPlus, // -inf -1 +0 +0 +1 +inf nan
     /// Prints `-` for any negative values (including the negative zero), or `+` otherwise.
     MinusPlusRaw, // -inf -1 -0 +0 +1 +inf nan
 }
@@ -374,11 +407,35 @@ fn determine_sign(sign: Sign, decoded: &FullDecoded, negative: bool) -> &'static
     match (*decoded, sign) {
         (FullDecoded::Nan, _) => b"",
         (FullDecoded::Zero, Sign::Minus) => b"",
-        (FullDecoded::Zero, Sign::MinusRaw) => if negative { b"-" } else { b"" },
+        (FullDecoded::Zero, Sign::MinusRaw) => {
+            if negative {
+                b"-"
+            } else {
+                b""
+            }
+        }
         (FullDecoded::Zero, Sign::MinusPlus) => b"+",
-        (FullDecoded::Zero, Sign::MinusPlusRaw) => if negative { b"-" } else { b"+" },
-        (_, Sign::Minus) | (_, Sign::MinusRaw) => if negative { b"-" } else { b"" },
-        (_, Sign::MinusPlus) | (_, Sign::MinusPlusRaw) => if negative { b"-" } else { b"+" },
+        (FullDecoded::Zero, Sign::MinusPlusRaw) => {
+            if negative {
+                b"-"
+            } else {
+                b"+"
+            }
+        }
+        (_, Sign::Minus) | (_, Sign::MinusRaw) => {
+            if negative {
+                b"-"
+            } else {
+                b""
+            }
+        }
+        (_, Sign::MinusPlus) | (_, Sign::MinusPlusRaw) => {
+            if negative {
+                b"-"
+            } else {
+                b"+"
+            }
+        }
     }
 }
 
@@ -400,10 +457,19 @@ fn determine_sign(sign: Sign, decoded: &FullDecoded, negative: bool) -> &'static
 /// The byte buffer should be at least `MAX_SIG_DIGITS` bytes long.
 /// There should be at least 4 parts available, due to the worst case like
 /// `[+][0.][0000][2][0000]` with `frac_digits = 10`.
-pub fn to_shortest_str<'a, T, F>(mut format_shortest: F, v: T,
-                                 sign: Sign, frac_digits: usize, _upper: bool,
-                                 buf: &'a mut [u8], parts: &'a mut [Part<'a>]) -> Formatted<'a>
-        where T: DecodableFloat, F: FnMut(&Decoded, &mut [u8]) -> (usize, i16) {
+pub fn to_shortest_str<'a, T, F>(
+    mut format_shortest: F,
+    v: T,
+    sign: Sign,
+    frac_digits: usize,
+    _upper: bool,
+    buf: &'a mut [u8],
+    parts: &'a mut [Part<'a>],
+) -> Formatted<'a>
+where
+    T: DecodableFloat,
+    F: FnMut(&Decoded, &mut [u8]) -> (usize, i16),
+{
     assert!(parts.len() >= 4);
     assert!(buf.len() >= MAX_SIG_DIGITS);
 
@@ -419,7 +485,8 @@ pub fn to_shortest_str<'a, T, F>(mut format_shortest: F, v: T,
             Formatted { sign, parts: &parts[..1] }
         }
         FullDecoded::Zero => {
-            if frac_digits > 0 { // [0.][0000]
+            if frac_digits > 0 {
+                // [0.][0000]
                 parts[0] = Part::Copy(b"0.");
                 parts[1] = Part::Zero(frac_digits);
                 Formatted { sign, parts: &parts[..2] }
@@ -430,8 +497,7 @@ pub fn to_shortest_str<'a, T, F>(mut format_shortest: F, v: T,
         }
         FullDecoded::Finite(ref decoded) => {
             let (len, exp) = format_shortest(decoded, buf);
-            Formatted { sign,
-                        parts: digits_to_dec_str(&buf[..len], exp, frac_digits, parts) }
+            Formatted { sign, parts: digits_to_dec_str(&buf[..len], exp, frac_digits, parts) }
         }
     }
 }
@@ -455,10 +521,19 @@ pub fn to_shortest_str<'a, T, F>(mut format_shortest: F, v: T,
 /// The byte buffer should be at least `MAX_SIG_DIGITS` bytes long.
 /// There should be at least 6 parts available, due to the worst case like
 /// `[+][1][.][2345][e][-][6]`.
-pub fn to_shortest_exp_str<'a, T, F>(mut format_shortest: F, v: T,
-                                     sign: Sign, dec_bounds: (i16, i16), upper: bool,
-                                     buf: &'a mut [u8], parts: &'a mut [Part<'a>]) -> Formatted<'a>
-        where T: DecodableFloat, F: FnMut(&Decoded, &mut [u8]) -> (usize, i16) {
+pub fn to_shortest_exp_str<'a, T, F>(
+    mut format_shortest: F,
+    v: T,
+    sign: Sign,
+    dec_bounds: (i16, i16),
+    upper: bool,
+    buf: &'a mut [u8],
+    parts: &'a mut [Part<'a>],
+) -> Formatted<'a>
+where
+    T: DecodableFloat,
+    F: FnMut(&Decoded, &mut [u8]) -> (usize, i16),
+{
     assert!(parts.len() >= 6);
     assert!(buf.len() >= MAX_SIG_DIGITS);
     assert!(dec_bounds.0 <= dec_bounds.1);
@@ -534,10 +609,19 @@ fn estimate_max_buf_len(exp: i16) -> usize {
 /// (The tipping point for `f64` is about 800, so 1000 bytes should be enough.)
 /// There should be at least 6 parts available, due to the worst case like
 /// `[+][1][.][2345][e][-][6]`.
-pub fn to_exact_exp_str<'a, T, F>(mut format_exact: F, v: T,
-                                  sign: Sign, ndigits: usize, upper: bool,
-                                  buf: &'a mut [u8], parts: &'a mut [Part<'a>]) -> Formatted<'a>
-        where T: DecodableFloat, F: FnMut(&Decoded, &mut [u8], i16) -> (usize, i16) {
+pub fn to_exact_exp_str<'a, T, F>(
+    mut format_exact: F,
+    v: T,
+    sign: Sign,
+    ndigits: usize,
+    upper: bool,
+    buf: &'a mut [u8],
+    parts: &'a mut [Part<'a>],
+) -> Formatted<'a>
+where
+    T: DecodableFloat,
+    F: FnMut(&Decoded, &mut [u8], i16) -> (usize, i16),
+{
     assert!(parts.len() >= 6);
     assert!(ndigits > 0);
 
@@ -553,7 +637,8 @@ pub fn to_exact_exp_str<'a, T, F>(mut format_exact: F, v: T,
             Formatted { sign, parts: &parts[..1] }
         }
         FullDecoded::Zero => {
-            if ndigits > 1 { // [0.][0000][e0]
+            if ndigits > 1 {
+                // [0.][0000][e0]
                 parts[0] = Part::Copy(b"0.");
                 parts[1] = Part::Zero(ndigits - 1);
                 parts[2] = Part::Copy(if upper { b"E0" } else { b"e0" });
@@ -569,8 +654,7 @@ pub fn to_exact_exp_str<'a, T, F>(mut format_exact: F, v: T,
 
             let trunc = if ndigits < maxlen { ndigits } else { maxlen };
             let (len, exp) = format_exact(decoded, &mut buf[..trunc], i16::MIN);
-            Formatted { sign,
-                        parts: digits_to_exp_str(&buf[..len], exp, ndigits, upper, parts) }
+            Formatted { sign, parts: digits_to_exp_str(&buf[..len], exp, ndigits, upper, parts) }
         }
     }
 }
@@ -590,10 +674,19 @@ pub fn to_exact_exp_str<'a, T, F>(mut format_exact: F, v: T,
 /// (The tipping point for `f64` is about 800, and 1000 bytes should be enough.)
 /// There should be at least 4 parts available, due to the worst case like
 /// `[+][0.][0000][2][0000]` with `frac_digits = 10`.
-pub fn to_exact_fixed_str<'a, T, F>(mut format_exact: F, v: T,
-                                    sign: Sign, frac_digits: usize, _upper: bool,
-                                    buf: &'a mut [u8], parts: &'a mut [Part<'a>]) -> Formatted<'a>
-        where T: DecodableFloat, F: FnMut(&Decoded, &mut [u8], i16) -> (usize, i16) {
+pub fn to_exact_fixed_str<'a, T, F>(
+    mut format_exact: F,
+    v: T,
+    sign: Sign,
+    frac_digits: usize,
+    _upper: bool,
+    buf: &'a mut [u8],
+    parts: &'a mut [Part<'a>],
+) -> Formatted<'a>
+where
+    T: DecodableFloat,
+    F: FnMut(&Decoded, &mut [u8], i16) -> (usize, i16),
+{
     assert!(parts.len() >= 4);
 
     let (negative, full_decoded) = decode(v);
@@ -608,7 +701,8 @@ pub fn to_exact_fixed_str<'a, T, F>(mut format_exact: F, v: T,
             Formatted { sign, parts: &parts[..1] }
         }
         FullDecoded::Zero => {
-            if frac_digits > 0 { // [0.][0000]
+            if frac_digits > 0 {
+                // [0.][0000]
                 parts[0] = Part::Copy(b"0.");
                 parts[1] = Part::Zero(frac_digits);
                 Formatted { sign, parts: &parts[..2] }
@@ -631,7 +725,8 @@ pub fn to_exact_fixed_str<'a, T, F>(mut format_exact: F, v: T,
                 // `exp` was. this does not include the case that the restriction has been met
                 // only after the final rounding-up; it's a regular case with `exp = limit + 1`.
                 debug_assert_eq!(len, 0);
-                if frac_digits > 0 { // [0.][0000]
+                if frac_digits > 0 {
+                    // [0.][0000]
                     parts[0] = Part::Copy(b"0.");
                     parts[1] = Part::Zero(frac_digits);
                     Formatted { sign, parts: &parts[..2] }
@@ -640,8 +735,7 @@ pub fn to_exact_fixed_str<'a, T, F>(mut format_exact: F, v: T,
                     Formatted { sign, parts: &parts[..1] }
                 }
             } else {
-                Formatted { sign,
-                            parts: digits_to_dec_str(&buf[..len], exp, frac_digits, parts) }
+                Formatted { sign, parts: digits_to_dec_str(&buf[..len], exp, frac_digits, parts) }
             }
         }
     }
index 35fb4b927589ff6bc5e875cced022253e135af95..c8de0004352efed9e9fd24d961b4bce2ec6fee75 100644 (file)
@@ -6,38 +6,54 @@
 
 use crate::cmp::Ordering;
 
-use crate::num::flt2dec::{Decoded, MAX_SIG_DIGITS, round_up};
-use crate::num::flt2dec::estimator::estimate_scaling_factor;
-use crate::num::bignum::Digit32 as Digit;
 use crate::num::bignum::Big32x40 as Big;
+use crate::num::bignum::Digit32 as Digit;
+use crate::num::flt2dec::estimator::estimate_scaling_factor;
+use crate::num::flt2dec::{round_up, Decoded, MAX_SIG_DIGITS};
 
-static POW10: [Digit; 10] = [1, 10, 100, 1000, 10000, 100000,
-                             1000000, 10000000, 100000000, 1000000000];
-static TWOPOW10: [Digit; 10] = [2, 20, 200, 2000, 20000, 200000,
-                                2000000, 20000000, 200000000, 2000000000];
+static POW10: [Digit; 10] =
+    [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000];
+static TWOPOW10: [Digit; 10] =
+    [2, 20, 200, 2000, 20000, 200000, 2000000, 20000000, 200000000, 2000000000];
 
 // precalculated arrays of `Digit`s for 10^(2^n)
 static POW10TO16: [Digit; 2] = [0x6fc10000, 0x2386f2];
 static POW10TO32: [Digit; 4] = [0, 0x85acef81, 0x2d6d415b, 0x4ee];
 static POW10TO64: [Digit; 7] = [0, 0, 0xbf6a1f01, 0x6e38ed64, 0xdaa797ed, 0xe93ff9f4, 0x184f03];
-static POW10TO128: [Digit; 14] =
-    [0, 0, 0, 0, 0x2e953e01, 0x3df9909, 0xf1538fd, 0x2374e42f, 0xd3cff5ec, 0xc404dc08,
-     0xbccdb0da, 0xa6337f19, 0xe91f2603, 0x24e];
-static POW10TO256: [Digit; 27] =
-    [0, 0, 0, 0, 0, 0, 0, 0, 0x982e7c01, 0xbed3875b, 0xd8d99f72, 0x12152f87, 0x6bde50c6,
-     0xcf4a6e70, 0xd595d80f, 0x26b2716e, 0xadc666b0, 0x1d153624, 0x3c42d35a, 0x63ff540e,
-     0xcc5573c0, 0x65f9ef17, 0x55bc28f2, 0x80dcc7f7, 0xf46eeddc, 0x5fdcefce, 0x553f7];
+static POW10TO128: [Digit; 14] = [
+    0, 0, 0, 0, 0x2e953e01, 0x3df9909, 0xf1538fd, 0x2374e42f, 0xd3cff5ec, 0xc404dc08, 0xbccdb0da,
+    0xa6337f19, 0xe91f2603, 0x24e,
+];
+static POW10TO256: [Digit; 27] = [
+    0, 0, 0, 0, 0, 0, 0, 0, 0x982e7c01, 0xbed3875b, 0xd8d99f72, 0x12152f87, 0x6bde50c6, 0xcf4a6e70,
+    0xd595d80f, 0x26b2716e, 0xadc666b0, 0x1d153624, 0x3c42d35a, 0x63ff540e, 0xcc5573c0, 0x65f9ef17,
+    0x55bc28f2, 0x80dcc7f7, 0xf46eeddc, 0x5fdcefce, 0x553f7,
+];
 
 #[doc(hidden)]
 pub fn mul_pow10(x: &mut Big, n: usize) -> &mut Big {
     debug_assert!(n < 512);
-    if n &   7 != 0 { x.mul_small(POW10[n & 7]); }
-    if n &   8 != 0 { x.mul_small(POW10[8]); }
-    if n &  16 != 0 { x.mul_digits(&POW10TO16); }
-    if n &  32 != 0 { x.mul_digits(&POW10TO32); }
-    if n &  64 != 0 { x.mul_digits(&POW10TO64); }
-    if n & 128 != 0 { x.mul_digits(&POW10TO128); }
-    if n & 256 != 0 { x.mul_digits(&POW10TO256); }
+    if n & 7 != 0 {
+        x.mul_small(POW10[n & 7]);
+    }
+    if n & 8 != 0 {
+        x.mul_small(POW10[8]);
+    }
+    if n & 16 != 0 {
+        x.mul_digits(&POW10TO16);
+    }
+    if n & 32 != 0 {
+        x.mul_digits(&POW10TO32);
+    }
+    if n & 64 != 0 {
+        x.mul_digits(&POW10TO64);
+    }
+    if n & 128 != 0 {
+        x.mul_digits(&POW10TO128);
+    }
+    if n & 256 != 0 {
+        x.mul_digits(&POW10TO256);
+    }
     x
 }
 
@@ -52,13 +68,30 @@ fn div_2pow10(x: &mut Big, mut n: usize) -> &mut Big {
 }
 
 // only usable when `x < 16 * scale`; `scaleN` should be `scale.mul_small(N)`
-fn div_rem_upto_16<'a>(x: &'a mut Big, scale: &Big,
-                       scale2: &Big, scale4: &Big, scale8: &Big) -> (u8, &'a mut Big) {
+fn div_rem_upto_16<'a>(
+    x: &'a mut Big,
+    scale: &Big,
+    scale2: &Big,
+    scale4: &Big,
+    scale8: &Big,
+) -> (u8, &'a mut Big) {
     let mut d = 0;
-    if *x >= *scale8 { x.sub(scale8); d += 8; }
-    if *x >= *scale4 { x.sub(scale4); d += 4; }
-    if *x >= *scale2 { x.sub(scale2); d += 2; }
-    if *x >= *scale  { x.sub(scale);  d += 1; }
+    if *x >= *scale8 {
+        x.sub(scale8);
+        d += 8;
+    }
+    if *x >= *scale4 {
+        x.sub(scale4);
+        d += 4;
+    }
+    if *x >= *scale2 {
+        x.sub(scale2);
+        d += 2;
+    }
+    if *x >= *scale {
+        x.sub(scale);
+        d += 1;
+    }
     debug_assert!(*x < *scale);
     (d, x)
 }
@@ -85,7 +118,7 @@ pub fn format_shortest(d: &Decoded, buf: &mut [u8]) -> (/*#digits*/ usize, /*exp
     assert!(buf.len() >= MAX_SIG_DIGITS);
 
     // `a.cmp(&b) < rounding` is `if d.inclusive {a <= b} else {a < b}`
-    let rounding = if d.inclusive {Ordering::Greater} else {Ordering::Equal};
+    let rounding = if d.inclusive { Ordering::Greater } else { Ordering::Equal };
 
     // estimate `k_0` from original inputs satisfying `10^(k_0-1) < high <= 10^(k_0+1)`.
     // the tight bound `k` satisfying `10^(k-1) < high <= 10^k` is calculated later.
@@ -132,9 +165,12 @@ pub fn format_shortest(d: &Decoded, buf: &mut [u8]) -> (/*#digits*/ usize, /*exp
     }
 
     // cache `(2, 4, 8) * scale` for digit generation.
-    let mut scale2 = scale.clone(); scale2.mul_pow2(1);
-    let mut scale4 = scale.clone(); scale4.mul_pow2(2);
-    let mut scale8 = scale.clone(); scale8.mul_pow2(3);
+    let mut scale2 = scale.clone();
+    scale2.mul_pow2(1);
+    let mut scale4 = scale.clone();
+    scale4.mul_pow2(2);
+    let mut scale8 = scale.clone();
+    scale8.mul_pow2(3);
 
     let mut down;
     let mut up;
@@ -186,7 +222,9 @@ pub fn format_shortest(d: &Decoded, buf: &mut [u8]) -> (/*#digits*/ usize, /*exp
         // - keep generating otherwise.
         down = mant.cmp(&minus) < rounding;
         up = scale.cmp(mant.clone().add(&plus)) < rounding;
-        if down || up { break; } // we have the shortest representation, proceed to the rounding
+        if down || up {
+            break;
+        } // we have the shortest representation, proceed to the rounding
 
         // restore the invariants.
         // this makes the algorithm always terminating: `minus` and `plus` always increases,
@@ -269,22 +307,40 @@ pub fn format_exact(d: &Decoded, buf: &mut [u8], limit: i16) -> (/*#digits*/ usi
     if len > 0 {
         // cache `(2, 4, 8) * scale` for digit generation.
         // (this can be expensive, so do not calculate them when the buffer is empty.)
-        let mut scale2 = scale.clone(); scale2.mul_pow2(1);
-        let mut scale4 = scale.clone(); scale4.mul_pow2(2);
-        let mut scale8 = scale.clone(); scale8.mul_pow2(3);
+        let mut scale2 = scale.clone();
+        scale2.mul_pow2(1);
+        let mut scale4 = scale.clone();
+        scale4.mul_pow2(2);
+        let mut scale8 = scale.clone();
+        scale8.mul_pow2(3);
 
         for i in 0..len {
-            if mant.is_zero() { // following digits are all zeroes, we stop here
+            if mant.is_zero() {
+                // following digits are all zeroes, we stop here
                 // do *not* try to perform rounding! rather, fill remaining digits.
-                for c in &mut buf[i..len] { *c = b'0'; }
+                for c in &mut buf[i..len] {
+                    *c = b'0';
+                }
                 return (len, k);
             }
 
             let mut d = 0;
-            if mant >= scale8 { mant.sub(&scale8); d += 8; }
-            if mant >= scale4 { mant.sub(&scale4); d += 4; }
-            if mant >= scale2 { mant.sub(&scale2); d += 2; }
-            if mant >= scale  { mant.sub(&scale);  d += 1; }
+            if mant >= scale8 {
+                mant.sub(&scale8);
+                d += 8;
+            }
+            if mant >= scale4 {
+                mant.sub(&scale4);
+                d += 4;
+            }
+            if mant >= scale2 {
+                mant.sub(&scale2);
+                d += 2;
+            }
+            if mant >= scale {
+                mant.sub(&scale);
+                d += 1;
+            }
             debug_assert!(mant < scale);
             debug_assert!(d < 10);
             buf[i] = b'0' + d;
@@ -296,8 +352,9 @@ pub fn format_exact(d: &Decoded, buf: &mut [u8], limit: i16) -> (/*#digits*/ usi
     // if the following digits are exactly 5000..., check the prior digit and try to
     // round to even (i.e., avoid rounding up when the prior digit is even).
     let order = mant.cmp(scale.mul_small(5));
-    if order == Ordering::Greater || (order == Ordering::Equal &&
-                                      (len == 0 || buf[len-1] & 1 == 1)) {
+    if order == Ordering::Greater
+        || (order == Ordering::Equal && (len == 0 || buf[len - 1] & 1 == 1))
+    {
         // if rounding up changes the length, the exponent should also change.
         // but we've been requested a fixed number of digits, so do not alter the buffer...
         if let Some(c) = round_up(buf, len) {
index 61b50ec8ca566cba3125ce588902b8bdf56f4792..1e2db212dd0de03a22acc82b504caa37d410d0da 100644 (file)
@@ -6,12 +6,13 @@
 //!   accurately with integers. SIGPLAN Not. 45, 6 (June 2010), 233-243.
 
 use crate::num::diy_float::Fp;
-use crate::num::flt2dec::{Decoded, MAX_SIG_DIGITS, round_up};
-
+use crate::num::flt2dec::{round_up, Decoded, MAX_SIG_DIGITS};
 
 // see the comments in `format_shortest_opt` for the rationale.
-#[doc(hidden)] pub const ALPHA: i16 = -60;
-#[doc(hidden)] pub const GAMMA: i16 = -32;
+#[doc(hidden)]
+pub const ALPHA: i16 = -60;
+#[doc(hidden)]
+pub const GAMMA: i16 = -32;
 
 /*
 # the following Python code generates this table:
 */
 
 #[doc(hidden)]
-pub static CACHED_POW10: [(u64, i16, i16); 81] = [ // (f, e, k)
+pub static CACHED_POW10: [(u64, i16, i16); 81] = [
+    // (f, e, k)
     (0xe61acf033d1a45df, -1087, -308),
     (0xab70fe17c79ac6ca, -1060, -300),
     (0xff77b1fcbebcdc4f, -1034, -292),
     (0xbe5691ef416bd60c, -1007, -284),
-    (0x8dd01fad907ffc3c,  -980, -276),
-    (0xd3515c2831559a83,  -954, -268),
-    (0x9d71ac8fada6c9b5,  -927, -260),
-    (0xea9c227723ee8bcb,  -901, -252),
-    (0xaecc49914078536d,  -874, -244),
-    (0x823c12795db6ce57,  -847, -236),
-    (0xc21094364dfb5637,  -821, -228),
-    (0x9096ea6f3848984f,  -794, -220),
-    (0xd77485cb25823ac7,  -768, -212),
-    (0xa086cfcd97bf97f4,  -741, -204),
-    (0xef340a98172aace5,  -715, -196),
-    (0xb23867fb2a35b28e,  -688, -188),
-    (0x84c8d4dfd2c63f3b,  -661, -180),
-    (0xc5dd44271ad3cdba,  -635, -172),
-    (0x936b9fcebb25c996,  -608, -164),
-    (0xdbac6c247d62a584,  -582, -156),
-    (0xa3ab66580d5fdaf6,  -555, -148),
-    (0xf3e2f893dec3f126,  -529, -140),
-    (0xb5b5ada8aaff80b8,  -502, -132),
-    (0x87625f056c7c4a8b,  -475, -124),
-    (0xc9bcff6034c13053,  -449, -116),
-    (0x964e858c91ba2655,  -422, -108),
-    (0xdff9772470297ebd,  -396, -100),
-    (0xa6dfbd9fb8e5b88f,  -369,  -92),
-    (0xf8a95fcf88747d94,  -343,  -84),
-    (0xb94470938fa89bcf,  -316,  -76),
-    (0x8a08f0f8bf0f156b,  -289,  -68),
-    (0xcdb02555653131b6,  -263,  -60),
-    (0x993fe2c6d07b7fac,  -236,  -52),
-    (0xe45c10c42a2b3b06,  -210,  -44),
-    (0xaa242499697392d3,  -183,  -36),
-    (0xfd87b5f28300ca0e,  -157,  -28),
-    (0xbce5086492111aeb,  -130,  -20),
-    (0x8cbccc096f5088cc,  -103,  -12),
-    (0xd1b71758e219652c,   -77,   -4),
-    (0x9c40000000000000,   -50,    4),
-    (0xe8d4a51000000000,   -24,   12),
-    (0xad78ebc5ac620000,     3,   20),
-    (0x813f3978f8940984,    30,   28),
-    (0xc097ce7bc90715b3,    56,   36),
-    (0x8f7e32ce7bea5c70,    83,   44),
-    (0xd5d238a4abe98068,   109,   52),
-    (0x9f4f2726179a2245,   136,   60),
-    (0xed63a231d4c4fb27,   162,   68),
-    (0xb0de65388cc8ada8,   189,   76),
-    (0x83c7088e1aab65db,   216,   84),
-    (0xc45d1df942711d9a,   242,   92),
-    (0x924d692ca61be758,   269,  100),
-    (0xda01ee641a708dea,   295,  108),
-    (0xa26da3999aef774a,   322,  116),
-    (0xf209787bb47d6b85,   348,  124),
-    (0xb454e4a179dd1877,   375,  132),
-    (0x865b86925b9bc5c2,   402,  140),
-    (0xc83553c5c8965d3d,   428,  148),
-    (0x952ab45cfa97a0b3,   455,  156),
-    (0xde469fbd99a05fe3,   481,  164),
-    (0xa59bc234db398c25,   508,  172),
-    (0xf6c69a72a3989f5c,   534,  180),
-    (0xb7dcbf5354e9bece,   561,  188),
-    (0x88fcf317f22241e2,   588,  196),
-    (0xcc20ce9bd35c78a5,   614,  204),
-    (0x98165af37b2153df,   641,  212),
-    (0xe2a0b5dc971f303a,   667,  220),
-    (0xa8d9d1535ce3b396,   694,  228),
-    (0xfb9b7cd9a4a7443c,   720,  236),
-    (0xbb764c4ca7a44410,   747,  244),
-    (0x8bab8eefb6409c1a,   774,  252),
-    (0xd01fef10a657842c,   800,  260),
-    (0x9b10a4e5e9913129,   827,  268),
-    (0xe7109bfba19c0c9d,   853,  276),
-    (0xac2820d9623bf429,   880,  284),
-    (0x80444b5e7aa7cf85,   907,  292),
-    (0xbf21e44003acdd2d,   933,  300),
-    (0x8e679c2f5e44ff8f,   960,  308),
-    (0xd433179d9c8cb841,   986,  316),
-    (0x9e19db92b4e31ba9,  1013,  324),
-    (0xeb96bf6ebadf77d9,  1039,  332),
+    (0x8dd01fad907ffc3c, -980, -276),
+    (0xd3515c2831559a83, -954, -268),
+    (0x9d71ac8fada6c9b5, -927, -260),
+    (0xea9c227723ee8bcb, -901, -252),
+    (0xaecc49914078536d, -874, -244),
+    (0x823c12795db6ce57, -847, -236),
+    (0xc21094364dfb5637, -821, -228),
+    (0x9096ea6f3848984f, -794, -220),
+    (0xd77485cb25823ac7, -768, -212),
+    (0xa086cfcd97bf97f4, -741, -204),
+    (0xef340a98172aace5, -715, -196),
+    (0xb23867fb2a35b28e, -688, -188),
+    (0x84c8d4dfd2c63f3b, -661, -180),
+    (0xc5dd44271ad3cdba, -635, -172),
+    (0x936b9fcebb25c996, -608, -164),
+    (0xdbac6c247d62a584, -582, -156),
+    (0xa3ab66580d5fdaf6, -555, -148),
+    (0xf3e2f893dec3f126, -529, -140),
+    (0xb5b5ada8aaff80b8, -502, -132),
+    (0x87625f056c7c4a8b, -475, -124),
+    (0xc9bcff6034c13053, -449, -116),
+    (0x964e858c91ba2655, -422, -108),
+    (0xdff9772470297ebd, -396, -100),
+    (0xa6dfbd9fb8e5b88f, -369, -92),
+    (0xf8a95fcf88747d94, -343, -84),
+    (0xb94470938fa89bcf, -316, -76),
+    (0x8a08f0f8bf0f156b, -289, -68),
+    (0xcdb02555653131b6, -263, -60),
+    (0x993fe2c6d07b7fac, -236, -52),
+    (0xe45c10c42a2b3b06, -210, -44),
+    (0xaa242499697392d3, -183, -36),
+    (0xfd87b5f28300ca0e, -157, -28),
+    (0xbce5086492111aeb, -130, -20),
+    (0x8cbccc096f5088cc, -103, -12),
+    (0xd1b71758e219652c, -77, -4),
+    (0x9c40000000000000, -50, 4),
+    (0xe8d4a51000000000, -24, 12),
+    (0xad78ebc5ac620000, 3, 20),
+    (0x813f3978f8940984, 30, 28),
+    (0xc097ce7bc90715b3, 56, 36),
+    (0x8f7e32ce7bea5c70, 83, 44),
+    (0xd5d238a4abe98068, 109, 52),
+    (0x9f4f2726179a2245, 136, 60),
+    (0xed63a231d4c4fb27, 162, 68),
+    (0xb0de65388cc8ada8, 189, 76),
+    (0x83c7088e1aab65db, 216, 84),
+    (0xc45d1df942711d9a, 242, 92),
+    (0x924d692ca61be758, 269, 100),
+    (0xda01ee641a708dea, 295, 108),
+    (0xa26da3999aef774a, 322, 116),
+    (0xf209787bb47d6b85, 348, 124),
+    (0xb454e4a179dd1877, 375, 132),
+    (0x865b86925b9bc5c2, 402, 140),
+    (0xc83553c5c8965d3d, 428, 148),
+    (0x952ab45cfa97a0b3, 455, 156),
+    (0xde469fbd99a05fe3, 481, 164),
+    (0xa59bc234db398c25, 508, 172),
+    (0xf6c69a72a3989f5c, 534, 180),
+    (0xb7dcbf5354e9bece, 561, 188),
+    (0x88fcf317f22241e2, 588, 196),
+    (0xcc20ce9bd35c78a5, 614, 204),
+    (0x98165af37b2153df, 641, 212),
+    (0xe2a0b5dc971f303a, 667, 220),
+    (0xa8d9d1535ce3b396, 694, 228),
+    (0xfb9b7cd9a4a7443c, 720, 236),
+    (0xbb764c4ca7a44410, 747, 244),
+    (0x8bab8eefb6409c1a, 774, 252),
+    (0xd01fef10a657842c, 800, 260),
+    (0x9b10a4e5e9913129, 827, 268),
+    (0xe7109bfba19c0c9d, 853, 276),
+    (0xac2820d9623bf429, 880, 284),
+    (0x80444b5e7aa7cf85, 907, 292),
+    (0xbf21e44003acdd2d, 933, 300),
+    (0x8e679c2f5e44ff8f, 960, 308),
+    (0xd433179d9c8cb841, 986, 316),
+    (0x9e19db92b4e31ba9, 1013, 324),
+    (0xeb96bf6ebadf77d9, 1039, 332),
 ];
 
-#[doc(hidden)] pub const CACHED_POW10_FIRST_E: i16 = -1087;
-#[doc(hidden)] pub const CACHED_POW10_LAST_E: i16 = 1039;
+#[doc(hidden)]
+pub const CACHED_POW10_FIRST_E: i16 = -1087;
+#[doc(hidden)]
+pub const CACHED_POW10_LAST_E: i16 = 1039;
 
 #[doc(hidden)]
 pub fn cached_power(alpha: i16, gamma: i16) -> (i16, Fp) {
@@ -128,30 +132,39 @@ pub fn max_pow10_no_more_than(x: u32) -> (u8, u32) {
     debug_assert!(x > 0);
 
     const X9: u32 = 10_0000_0000;
-    const X8: u32 =  1_0000_0000;
-    const X7: u32 =    1000_0000;
-    const X6: u32 =     100_0000;
-    const X5: u32 =      10_0000;
-    const X4: u32 =       1_0000;
-    const X3: u32 =         1000;
-    const X2: u32 =          100;
-    const X1: u32 =           10;
+    const X8: u32 = 1_0000_0000;
+    const X7: u32 = 1000_0000;
+    const X6: u32 = 100_0000;
+    const X5: u32 = 10_0000;
+    const X4: u32 = 1_0000;
+    const X3: u32 = 1000;
+    const X2: u32 = 100;
+    const X1: u32 = 10;
 
     if x < X4 {
-        if x < X2 { if x < X1 {(0,  1)} else {(1, X1)} }
-        else      { if x < X3 {(2, X2)} else {(3, X3)} }
+        if x < X2 {
+            if x < X1 { (0, 1) } else { (1, X1) }
+        } else {
+            if x < X3 { (2, X2) } else { (3, X3) }
+        }
     } else {
-        if x < X6      { if x < X5 {(4, X4)} else {(5, X5)} }
-        else if x < X8 { if x < X7 {(6, X6)} else {(7, X7)} }
-        else           { if x < X9 {(8, X8)} else {(9, X9)} }
+        if x < X6 {
+            if x < X5 { (4, X4) } else { (5, X5) }
+        } else if x < X8 {
+            if x < X7 { (6, X6) } else { (7, X7) }
+        } else {
+            if x < X9 { (8, X8) } else { (9, X9) }
+        }
     }
 }
 
 /// The shortest mode implementation for Grisu.
 ///
 /// It returns `None` when it would return an inexact representation otherwise.
-pub fn format_shortest_opt(d: &Decoded,
-                           buf: &mut [u8]) -> Option<(/*#digits*/ usize, /*exp*/ i16)> {
+pub fn format_shortest_opt(
+    d: &Decoded,
+    buf: &mut [u8],
+) -> Option<(/*#digits*/ usize, /*exp*/ i16)> {
     assert!(d.mant > 0);
     assert!(d.minus > 0);
     assert!(d.plus > 0);
@@ -208,8 +221,8 @@ pub fn format_shortest_opt(d: &Decoded,
     // we start with the correct repr within the unsafe region, and try to find the closest repr
     // to `v` which is also within the safe region. if we can't, we give up.
     let plus1 = plus.f + 1;
-//  let plus0 = plus.f - 1; // only for explanation
-//  let minus0 = minus.f + 1; // only for explanation
+    //  let plus0 = plus.f - 1; // only for explanation
+    //  let minus0 = minus.f + 1; // only for explanation
     let minus1 = minus.f - 1;
     let e = -plus.e as usize; // shared exponent
 
@@ -235,14 +248,15 @@ pub fn format_shortest_opt(d: &Decoded,
     // (e.g., `x` = 32000, `y` = 32777; `kappa` = 2 since `y mod 10^3 = 777 < y - x = 777`.)
     // the algorithm relies on the later verification phase to exclude `y`.
     let delta1 = plus1 - minus1;
-//  let delta1int = (delta1 >> e) as usize; // only for explanation
+    //  let delta1int = (delta1 >> e) as usize; // only for explanation
     let delta1frac = delta1 & ((1 << e) - 1);
 
     // render integral parts, while checking for the accuracy at each step.
     let mut kappa = max_kappa as i16;
     let mut ten_kappa = max_ten_kappa; // 10^kappa
     let mut remainder = plus1int; // digits yet to be rendered
-    loop { // we always have at least one digit to render, as `plus1 >= 10^kappa`
+    loop {
+        // we always have at least one digit to render, as `plus1 >= 10^kappa`
         // invariants:
         // - `delta1int <= remainder < 10^(kappa+1)`
         // - `plus1int = d[0..n-1] * 10^(kappa+1) + remainder`
@@ -281,7 +295,8 @@ pub fn format_shortest_opt(d: &Decoded,
     let mut remainder = plus1frac;
     let mut threshold = delta1frac;
     let mut ulp = 1;
-    loop { // the next digit should be significant as we've tested that before breaking out
+    loop {
+        // the next digit should be significant as we've tested that before breaking out
         // invariants, where `m = max_kappa + 1` (# of digits in the integral part):
         // - `remainder < 2^e`
         // - `plus1frac * 10^(n-m) = d[m..n-1] * 2^e + remainder`
@@ -300,8 +315,15 @@ pub fn format_shortest_opt(d: &Decoded,
 
         if r < threshold {
             let ten_kappa = 1 << e; // implicit divisor
-            return round_and_weed(&mut buf[..i], exp, r, threshold,
-                                  (plus1 - v.f) * ulp, ten_kappa, ulp);
+            return round_and_weed(
+                &mut buf[..i],
+                exp,
+                r,
+                threshold,
+                (plus1 - v.f) * ulp,
+                ten_kappa,
+                ulp,
+            );
         }
 
         // restore invariants
@@ -325,8 +347,15 @@ pub fn format_shortest_opt(d: &Decoded,
     // - `plus1v = (plus1 - v) * k` (and also, `threshold > plus1v` from prior invariants)
     // - `ten_kappa = 10^kappa * k`
     // - `ulp = 2^-e * k`
-    fn round_and_weed(buf: &mut [u8], exp: i16, remainder: u64, threshold: u64, plus1v: u64,
-                      ten_kappa: u64, ulp: u64) -> Option<(usize, i16)> {
+    fn round_and_weed(
+        buf: &mut [u8],
+        exp: i16,
+        remainder: u64,
+        threshold: u64,
+        plus1v: u64,
+        ten_kappa: u64,
+        ulp: u64,
+    ) -> Option<(usize, i16)> {
         assert!(!buf.is_empty());
 
         // produce two approximations to `v` (actually `plus1 - v`) within 1.5 ulps.
@@ -381,10 +410,11 @@ fn round_and_weed(buf: &mut [u8], exp: i16, remainder: u64, threshold: u64, plus
             //
             // consequently, we should stop when `TC1 || TC2 || (TC3a && TC3b)`. the following is
             // equal to its inverse, `!TC1 && !TC2 && (!TC3a || !TC3b)`.
-            while plus1w < plus1v_up &&
-                  threshold - plus1w >= ten_kappa &&
-                  (plus1w + ten_kappa < plus1v_up ||
-                   plus1v_up - plus1w >= plus1w + ten_kappa - plus1v_up) {
+            while plus1w < plus1v_up
+                && threshold - plus1w >= ten_kappa
+                && (plus1w + ten_kappa < plus1v_up
+                    || plus1v_up - plus1w >= plus1w + ten_kappa - plus1v_up)
+            {
                 *last -= 1;
                 debug_assert!(*last > b'0'); // the shortest repr cannot end with `0`
                 plus1w += ten_kappa;
@@ -395,10 +425,11 @@ fn round_and_weed(buf: &mut [u8], exp: i16, remainder: u64, threshold: u64, plus
         //
         // this is simply same to the terminating conditions for `v + 1 ulp`, with all `plus1v_up`
         // replaced by `plus1v_down` instead. overflow analysis equally holds.
-        if plus1w < plus1v_down &&
-           threshold - plus1w >= ten_kappa &&
-           (plus1w + ten_kappa < plus1v_down ||
-            plus1v_down - plus1w >= plus1w + ten_kappa - plus1v_down) {
+        if plus1w < plus1v_down
+            && threshold - plus1w >= ten_kappa
+            && (plus1w + ten_kappa < plus1v_down
+                || plus1v_down - plus1w >= plus1w + ten_kappa - plus1v_down)
+        {
             return None;
         }
 
@@ -428,8 +459,11 @@ pub fn format_shortest(d: &Decoded, buf: &mut [u8]) -> (/*#digits*/ usize, /*exp
 /// The exact and fixed mode implementation for Grisu.
 ///
 /// It returns `None` when it would return an inexact representation otherwise.
-pub fn format_exact_opt(d: &Decoded, buf: &mut [u8], limit: i16)
-                                -> Option<(/*#digits*/ usize, /*exp*/ i16)> {
+pub fn format_exact_opt(
+    d: &Decoded,
+    buf: &mut [u8],
+    limit: i16,
+) -> Option<(/*#digits*/ usize, /*exp*/ i16)> {
     assert!(d.mant > 0);
     assert!(d.mant < (1 << 61)); // we need at least three bits of additional precision
     assert!(!buf.is_empty());
@@ -489,7 +523,8 @@ pub fn format_exact_opt(d: &Decoded, buf: &mut [u8], limit: i16)
     let mut kappa = max_kappa as i16;
     let mut ten_kappa = max_ten_kappa; // 10^kappa
     let mut remainder = vint; // digits yet to be rendered
-    loop { // we always have at least one digit to render
+    loop {
+        // we always have at least one digit to render
         // invariants:
         // - `remainder < 10^(kappa+1)`
         // - `vint = d[0..n-1] * 10^(kappa+1) + remainder`
@@ -575,8 +610,15 @@ pub fn format_exact_opt(d: &Decoded, buf: &mut [u8], limit: i16)
     // - `remainder = (v % 10^kappa) * k`
     // - `ten_kappa = 10^kappa * k`
     // - `ulp = 2^-e * k`
-    fn possibly_round(buf: &mut [u8], mut len: usize, mut exp: i16, limit: i16,
-                      remainder: u64, ten_kappa: u64, ulp: u64) -> Option<(usize, i16)> {
+    fn possibly_round(
+        buf: &mut [u8],
+        mut len: usize,
+        mut exp: i16,
+        limit: i16,
+        remainder: u64,
+        ten_kappa: u64,
+        ulp: u64,
+    ) -> Option<(usize, i16)> {
         debug_assert!(remainder < ten_kappa);
 
         //           10^kappa
@@ -593,7 +635,9 @@ fn possibly_round(buf: &mut [u8], mut len: usize, mut exp: i16, limit: i16,
         //
         // error is too large that there are at least three possible representations
         // between `v - 1 ulp` and `v + 1 ulp`. we cannot determine which one is correct.
-        if ulp >= ten_kappa { return None; }
+        if ulp >= ten_kappa {
+            return None;
+        }
 
         //    10^kappa
         //   :<------->:
@@ -607,7 +651,9 @@ fn possibly_round(buf: &mut [u8], mut len: usize, mut exp: i16, limit: i16,
         // in fact, 1/2 ulp is enough to introduce two possible representations.
         // (remember that we need a unique representation for both `v - 1 ulp` and `v + 1 ulp`.)
         // this won't overflow, as `ulp < ten_kappa` from the first check.
-        if ten_kappa - ulp <= ulp { return None; }
+        if ten_kappa - ulp <= ulp {
+            return None;
+        }
 
         //     remainder
         //       :<->|                           :
index 5fe9895d8d24f94543955286541f66ae464ec06f..0ddfbd02aa5b02250b453f8d5e31dc10da69130a 100644 (file)
@@ -4,7 +4,7 @@
 
 #[allow(unused_macros)]
 macro_rules! sh_impl_signed {
-    ($t:ident, $f:ident) => (
+    ($t:ident, $f:ident) => {
         #[stable(feature = "rust1", since = "1.0.0")]
         impl Shl<$f> for Wrapping<$t> {
             type Output = Wrapping<$t>;
@@ -19,7 +19,7 @@ fn shl(self, other: $f) -> Wrapping<$t> {
             }
         }
         forward_ref_binop! { impl Shl, shl for Wrapping<$t>, $f,
-                #[stable(feature = "wrapping_ref_ops", since = "1.39.0")] }
+        #[stable(feature = "wrapping_ref_ops", since = "1.39.0")] }
 
         #[stable(feature = "op_assign_traits", since = "1.8.0")]
         impl ShlAssign<$f> for Wrapping<$t> {
@@ -44,7 +44,7 @@ fn shr(self, other: $f) -> Wrapping<$t> {
             }
         }
         forward_ref_binop! { impl Shr, shr for Wrapping<$t>, $f,
-                #[stable(feature = "wrapping_ref_ops", since = "1.39.0")] }
+        #[stable(feature = "wrapping_ref_ops", since = "1.39.0")] }
 
         #[stable(feature = "op_assign_traits", since = "1.8.0")]
         impl ShrAssign<$f> for Wrapping<$t> {
@@ -54,11 +54,11 @@ fn shr_assign(&mut self, other: $f) {
             }
         }
         forward_ref_op_assign! { impl ShrAssign, shr_assign for Wrapping<$t>, $f }
-    )
+    };
 }
 
 macro_rules! sh_impl_unsigned {
-    ($t:ident, $f:ident) => (
+    ($t:ident, $f:ident) => {
         #[stable(feature = "rust1", since = "1.0.0")]
         impl Shl<$f> for Wrapping<$t> {
             type Output = Wrapping<$t>;
@@ -69,7 +69,7 @@ fn shl(self, other: $f) -> Wrapping<$t> {
             }
         }
         forward_ref_binop! { impl Shl, shl for Wrapping<$t>, $f,
-                #[stable(feature = "wrapping_ref_ops", since = "1.39.0")] }
+        #[stable(feature = "wrapping_ref_ops", since = "1.39.0")] }
 
         #[stable(feature = "op_assign_traits", since = "1.8.0")]
         impl ShlAssign<$f> for Wrapping<$t> {
@@ -90,7 +90,7 @@ fn shr(self, other: $f) -> Wrapping<$t> {
             }
         }
         forward_ref_binop! { impl Shr, shr for Wrapping<$t>, $f,
-                #[stable(feature = "wrapping_ref_ops", since = "1.39.0")] }
+        #[stable(feature = "wrapping_ref_ops", since = "1.39.0")] }
 
         #[stable(feature = "op_assign_traits", since = "1.8.0")]
         impl ShrAssign<$f> for Wrapping<$t> {
@@ -100,7 +100,7 @@ fn shr_assign(&mut self, other: $f) {
             }
         }
         forward_ref_op_assign! { impl ShrAssign, shr_assign for Wrapping<$t>, $f }
-    )
+    };
 }
 
 // FIXME (#23545): uncomment the remaining impls
index 3c009d644c64e3f6f3feb98f30e8150b56430cee..59a72799e256726e20dbf7728f4c94298269d7d9 100644 (file)
 #[lang = "add"]
 #[stable(feature = "rust1", since = "1.0.0")]
 #[rustc_on_unimplemented(
-    on(
-        all(_Self="{integer}", Rhs="{float}"),
-        message="cannot add a float to an integer",
-    ),
-    on(
-        all(_Self="{float}", Rhs="{integer}"),
-        message="cannot add an integer to a float",
-    ),
-    message="cannot add `{Rhs}` to `{Self}`",
-    label="no implementation for `{Self} + {Rhs}`",
+    on(all(_Self = "{integer}", Rhs = "{float}"), message = "cannot add a float to an integer",),
+    on(all(_Self = "{float}", Rhs = "{integer}"), message = "cannot add an integer to a float",),
+    message = "cannot add `{Rhs}` to `{Self}`",
+    label = "no implementation for `{Self} + {Rhs}`"
 )]
 #[doc(alias = "+")]
-pub trait Add<Rhs=Self> {
+pub trait Add<Rhs = Self> {
     /// The resulting type after applying the `+` operator.
     #[stable(feature = "rust1", since = "1.0.0")]
     type Output;
@@ -173,10 +167,12 @@ fn add(self, other: $t) -> $t { self + other }
 /// ```
 #[lang = "sub"]
 #[stable(feature = "rust1", since = "1.0.0")]
-#[rustc_on_unimplemented(message="cannot subtract `{Rhs}` from `{Self}`",
-                         label="no implementation for `{Self} - {Rhs}`")]
+#[rustc_on_unimplemented(
+    message = "cannot subtract `{Rhs}` from `{Self}`",
+    label = "no implementation for `{Self} - {Rhs}`"
+)]
 #[doc(alias = "-")]
-pub trait Sub<Rhs=Self> {
+pub trait Sub<Rhs = Self> {
     /// The resulting type after applying the `-` operator.
     #[stable(feature = "rust1", since = "1.0.0")]
     type Output;
@@ -293,10 +289,12 @@ fn sub(self, other: $t) -> $t { self - other }
 /// ```
 #[lang = "mul"]
 #[stable(feature = "rust1", since = "1.0.0")]
-#[rustc_on_unimplemented(message="cannot multiply `{Rhs}` to `{Self}`",
-                         label="no implementation for `{Self} * {Rhs}`")]
+#[rustc_on_unimplemented(
+    message = "cannot multiply `{Rhs}` to `{Self}`",
+    label = "no implementation for `{Self} * {Rhs}`"
+)]
 #[doc(alias = "*")]
-pub trait Mul<Rhs=Self> {
+pub trait Mul<Rhs = Self> {
     /// The resulting type after applying the `*` operator.
     #[stable(feature = "rust1", since = "1.0.0")]
     type Output;
@@ -417,10 +415,12 @@ fn mul(self, other: $t) -> $t { self * other }
 /// ```
 #[lang = "div"]
 #[stable(feature = "rust1", since = "1.0.0")]
-#[rustc_on_unimplemented(message="cannot divide `{Self}` by `{Rhs}`",
-                         label="no implementation for `{Self} / {Rhs}`")]
+#[rustc_on_unimplemented(
+    message = "cannot divide `{Self}` by `{Rhs}`",
+    label = "no implementation for `{Self} / {Rhs}`"
+)]
 #[doc(alias = "/")]
-pub trait Div<Rhs=Self> {
+pub trait Div<Rhs = Self> {
     /// The resulting type after applying the `/` operator.
     #[stable(feature = "rust1", since = "1.0.0")]
     type Output;
@@ -502,10 +502,12 @@ fn div(self, other: $t) -> $t { self / other }
 /// ```
 #[lang = "rem"]
 #[stable(feature = "rust1", since = "1.0.0")]
-#[rustc_on_unimplemented(message="cannot mod `{Self}` by `{Rhs}`",
-                         label="no implementation for `{Self} % {Rhs}`")]
+#[rustc_on_unimplemented(
+    message = "cannot mod `{Self}` by `{Rhs}`",
+    label = "no implementation for `{Self} % {Rhs}`"
+)]
 #[doc(alias = "%")]
-pub trait Rem<Rhs=Self> {
+pub trait Rem<Rhs = Self> {
     /// The resulting type after applying the `%` operator.
     #[stable(feature = "rust1", since = "1.0.0")]
     type Output;
@@ -534,7 +536,6 @@ fn rem(self, other: $t) -> $t { self % other }
 
 rem_impl_integer! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 }
 
-
 macro_rules! rem_impl_float {
     ($($t:ty)*) => ($(
 
@@ -616,8 +617,6 @@ pub trait Neg {
     fn neg(self) -> Self::Output;
 }
 
-
-
 macro_rules! neg_impl_core {
     ($id:ident => $body:expr, $($t:ty)*) => ($(
         #[stable(feature = "rust1", since = "1.0.0")]
@@ -679,11 +678,13 @@ macro_rules! neg_impl_unsigned {
 /// ```
 #[lang = "add_assign"]
 #[stable(feature = "op_assign_traits", since = "1.8.0")]
-#[rustc_on_unimplemented(message="cannot add-assign `{Rhs}` to `{Self}`",
-                         label="no implementation for `{Self} += {Rhs}`")]
+#[rustc_on_unimplemented(
+    message = "cannot add-assign `{Rhs}` to `{Self}`",
+    label = "no implementation for `{Self} += {Rhs}`"
+)]
 #[doc(alias = "+")]
 #[doc(alias = "+=")]
-pub trait AddAssign<Rhs=Self> {
+pub trait AddAssign<Rhs = Self> {
     /// Performs the `+=` operation.
     #[stable(feature = "op_assign_traits", since = "1.8.0")]
     fn add_assign(&mut self, rhs: Rhs);
@@ -735,11 +736,13 @@ fn add_assign(&mut self, other: $t) { *self += other }
 /// ```
 #[lang = "sub_assign"]
 #[stable(feature = "op_assign_traits", since = "1.8.0")]
-#[rustc_on_unimplemented(message="cannot subtract-assign `{Rhs}` from `{Self}`",
-                         label="no implementation for `{Self} -= {Rhs}`")]
+#[rustc_on_unimplemented(
+    message = "cannot subtract-assign `{Rhs}` from `{Self}`",
+    label = "no implementation for `{Self} -= {Rhs}`"
+)]
 #[doc(alias = "-")]
 #[doc(alias = "-=")]
-pub trait SubAssign<Rhs=Self> {
+pub trait SubAssign<Rhs = Self> {
     /// Performs the `-=` operation.
     #[stable(feature = "op_assign_traits", since = "1.8.0")]
     fn sub_assign(&mut self, rhs: Rhs);
@@ -782,11 +785,13 @@ fn sub_assign(&mut self, other: $t) { *self -= other }
 /// ```
 #[lang = "mul_assign"]
 #[stable(feature = "op_assign_traits", since = "1.8.0")]
-#[rustc_on_unimplemented(message="cannot multiply-assign `{Rhs}` to `{Self}`",
-                         label="no implementation for `{Self} *= {Rhs}`")]
+#[rustc_on_unimplemented(
+    message = "cannot multiply-assign `{Rhs}` to `{Self}`",
+    label = "no implementation for `{Self} *= {Rhs}`"
+)]
 #[doc(alias = "*")]
 #[doc(alias = "*=")]
-pub trait MulAssign<Rhs=Self> {
+pub trait MulAssign<Rhs = Self> {
     /// Performs the `*=` operation.
     #[stable(feature = "op_assign_traits", since = "1.8.0")]
     fn mul_assign(&mut self, rhs: Rhs);
@@ -829,11 +834,13 @@ fn mul_assign(&mut self, other: $t) { *self *= other }
 /// ```
 #[lang = "div_assign"]
 #[stable(feature = "op_assign_traits", since = "1.8.0")]
-#[rustc_on_unimplemented(message="cannot divide-assign `{Self}` by `{Rhs}`",
-                         label="no implementation for `{Self} /= {Rhs}`")]
+#[rustc_on_unimplemented(
+    message = "cannot divide-assign `{Self}` by `{Rhs}`",
+    label = "no implementation for `{Self} /= {Rhs}`"
+)]
 #[doc(alias = "/")]
 #[doc(alias = "/=")]
-pub trait DivAssign<Rhs=Self> {
+pub trait DivAssign<Rhs = Self> {
     /// Performs the `/=` operation.
     #[stable(feature = "op_assign_traits", since = "1.8.0")]
     fn div_assign(&mut self, rhs: Rhs);
@@ -879,11 +886,13 @@ fn div_assign(&mut self, other: $t) { *self /= other }
 /// ```
 #[lang = "rem_assign"]
 #[stable(feature = "op_assign_traits", since = "1.8.0")]
-#[rustc_on_unimplemented(message="cannot mod-assign `{Self}` by `{Rhs}``",
-                         label="no implementation for `{Self} %= {Rhs}`")]
+#[rustc_on_unimplemented(
+    message = "cannot mod-assign `{Self}` by `{Rhs}``",
+    label = "no implementation for `{Self} %= {Rhs}`"
+)]
 #[doc(alias = "%")]
 #[doc(alias = "%=")]
-pub trait RemAssign<Rhs=Self> {
+pub trait RemAssign<Rhs = Self> {
     /// Performs the `%=` operation.
     #[stable(feature = "op_assign_traits", since = "1.8.0")]
     fn rem_assign(&mut self, rhs: Rhs);
index a8f862f6c05a55f010d0e2dca351e90faaa2d976..bcfff4a223bec7b63fad2b0f3d96c00dae05c9bc 100644 (file)
@@ -112,9 +112,11 @@ fn not(self) -> $t { !self }
 #[lang = "bitand"]
 #[doc(alias = "&")]
 #[stable(feature = "rust1", since = "1.0.0")]
-#[rustc_on_unimplemented(message="no implementation for `{Self} & {Rhs}`",
-                         label="no implementation for `{Self} & {Rhs}`")]
-pub trait BitAnd<Rhs=Self> {
+#[rustc_on_unimplemented(
+    message = "no implementation for `{Self} & {Rhs}`",
+    label = "no implementation for `{Self} & {Rhs}`"
+)]
+pub trait BitAnd<Rhs = Self> {
     /// The resulting type after applying the `&` operator.
     #[stable(feature = "rust1", since = "1.0.0")]
     type Output;
@@ -196,9 +198,11 @@ fn bitand(self, rhs: $t) -> $t { self & rhs }
 #[lang = "bitor"]
 #[doc(alias = "|")]
 #[stable(feature = "rust1", since = "1.0.0")]
-#[rustc_on_unimplemented(message="no implementation for `{Self} | {Rhs}`",
-                         label="no implementation for `{Self} | {Rhs}`")]
-pub trait BitOr<Rhs=Self> {
+#[rustc_on_unimplemented(
+    message = "no implementation for `{Self} | {Rhs}`",
+    label = "no implementation for `{Self} | {Rhs}`"
+)]
+pub trait BitOr<Rhs = Self> {
     /// The resulting type after applying the `|` operator.
     #[stable(feature = "rust1", since = "1.0.0")]
     type Output;
@@ -283,9 +287,11 @@ fn bitor(self, rhs: $t) -> $t { self | rhs }
 #[lang = "bitxor"]
 #[doc(alias = "^")]
 #[stable(feature = "rust1", since = "1.0.0")]
-#[rustc_on_unimplemented(message="no implementation for `{Self} ^ {Rhs}`",
-                         label="no implementation for `{Self} ^ {Rhs}`")]
-pub trait BitXor<Rhs=Self> {
+#[rustc_on_unimplemented(
+    message = "no implementation for `{Self} ^ {Rhs}`",
+    label = "no implementation for `{Self} ^ {Rhs}`"
+)]
+pub trait BitXor<Rhs = Self> {
     /// The resulting type after applying the `^` operator.
     #[stable(feature = "rust1", since = "1.0.0")]
     type Output;
@@ -371,9 +377,11 @@ fn bitxor(self, other: $t) -> $t { self ^ other }
 #[lang = "shl"]
 #[doc(alias = "<<")]
 #[stable(feature = "rust1", since = "1.0.0")]
-#[rustc_on_unimplemented(message="no implementation for `{Self} << {Rhs}`",
-                         label="no implementation for `{Self} << {Rhs}`")]
-pub trait Shl<Rhs=Self> {
+#[rustc_on_unimplemented(
+    message = "no implementation for `{Self} << {Rhs}`",
+    label = "no implementation for `{Self} << {Rhs}`"
+)]
+pub trait Shl<Rhs = Self> {
     /// The resulting type after applying the `<<` operator.
     #[stable(feature = "rust1", since = "1.0.0")]
     type Output;
@@ -385,7 +393,7 @@ pub trait Shl<Rhs=Self> {
 }
 
 macro_rules! shl_impl {
-    ($t:ty, $f:ty) => (
+    ($t:ty, $f:ty) => {
         #[stable(feature = "rust1", since = "1.0.0")]
         impl Shl<$f> for $t {
             type Output = $t;
@@ -398,7 +406,7 @@ fn shl(self, other: $f) -> $t {
         }
 
         forward_ref_binop! { impl Shl, shl for $t, $f }
-    )
+    };
 }
 
 macro_rules! shl_impl_all {
@@ -480,9 +488,11 @@ macro_rules! shl_impl_all {
 #[lang = "shr"]
 #[doc(alias = ">>")]
 #[stable(feature = "rust1", since = "1.0.0")]
-#[rustc_on_unimplemented(message="no implementation for `{Self} >> {Rhs}`",
-                         label="no implementation for `{Self} >> {Rhs}`")]
-pub trait Shr<Rhs=Self> {
+#[rustc_on_unimplemented(
+    message = "no implementation for `{Self} >> {Rhs}`",
+    label = "no implementation for `{Self} >> {Rhs}`"
+)]
+pub trait Shr<Rhs = Self> {
     /// The resulting type after applying the `>>` operator.
     #[stable(feature = "rust1", since = "1.0.0")]
     type Output;
@@ -494,7 +504,7 @@ pub trait Shr<Rhs=Self> {
 }
 
 macro_rules! shr_impl {
-    ($t:ty, $f:ty) => (
+    ($t:ty, $f:ty) => {
         #[stable(feature = "rust1", since = "1.0.0")]
         impl Shr<$f> for $t {
             type Output = $t;
@@ -507,7 +517,7 @@ fn shr(self, other: $f) -> $t {
         }
 
         forward_ref_binop! { impl Shr, shr for $t, $f }
-    )
+    };
 }
 
 macro_rules! shr_impl_all {
@@ -596,9 +606,11 @@ macro_rules! shr_impl_all {
 #[lang = "bitand_assign"]
 #[doc(alias = "&=")]
 #[stable(feature = "op_assign_traits", since = "1.8.0")]
-#[rustc_on_unimplemented(message="no implementation for `{Self} &= {Rhs}`",
-                         label="no implementation for `{Self} &= {Rhs}`")]
-pub trait BitAndAssign<Rhs=Self> {
+#[rustc_on_unimplemented(
+    message = "no implementation for `{Self} &= {Rhs}`",
+    label = "no implementation for `{Self} &= {Rhs}`"
+)]
+pub trait BitAndAssign<Rhs = Self> {
     /// Performs the `&=` operation.
     #[stable(feature = "op_assign_traits", since = "1.8.0")]
     fn bitand_assign(&mut self, rhs: Rhs);
@@ -645,9 +657,11 @@ fn bitand_assign(&mut self, other: $t) { *self &= other }
 #[lang = "bitor_assign"]
 #[doc(alias = "|=")]
 #[stable(feature = "op_assign_traits", since = "1.8.0")]
-#[rustc_on_unimplemented(message="no implementation for `{Self} |= {Rhs}`",
-                         label="no implementation for `{Self} |= {Rhs}`")]
-pub trait BitOrAssign<Rhs=Self> {
+#[rustc_on_unimplemented(
+    message = "no implementation for `{Self} |= {Rhs}`",
+    label = "no implementation for `{Self} |= {Rhs}`"
+)]
+pub trait BitOrAssign<Rhs = Self> {
     /// Performs the `|=` operation.
     #[stable(feature = "op_assign_traits", since = "1.8.0")]
     fn bitor_assign(&mut self, rhs: Rhs);
@@ -694,9 +708,11 @@ fn bitor_assign(&mut self, other: $t) { *self |= other }
 #[lang = "bitxor_assign"]
 #[doc(alias = "^=")]
 #[stable(feature = "op_assign_traits", since = "1.8.0")]
-#[rustc_on_unimplemented(message="no implementation for `{Self} ^= {Rhs}`",
-                         label="no implementation for `{Self} ^= {Rhs}`")]
-pub trait BitXorAssign<Rhs=Self> {
+#[rustc_on_unimplemented(
+    message = "no implementation for `{Self} ^= {Rhs}`",
+    label = "no implementation for `{Self} ^= {Rhs}`"
+)]
+pub trait BitXorAssign<Rhs = Self> {
     /// Performs the `^=` operation.
     #[stable(feature = "op_assign_traits", since = "1.8.0")]
     fn bitxor_assign(&mut self, rhs: Rhs);
@@ -741,16 +757,18 @@ fn bitxor_assign(&mut self, other: $t) { *self ^= other }
 #[lang = "shl_assign"]
 #[doc(alias = "<<=")]
 #[stable(feature = "op_assign_traits", since = "1.8.0")]
-#[rustc_on_unimplemented(message="no implementation for `{Self} <<= {Rhs}`",
-                         label="no implementation for `{Self} <<= {Rhs}`")]
-pub trait ShlAssign<Rhs=Self> {
+#[rustc_on_unimplemented(
+    message = "no implementation for `{Self} <<= {Rhs}`",
+    label = "no implementation for `{Self} <<= {Rhs}`"
+)]
+pub trait ShlAssign<Rhs = Self> {
     /// Performs the `<<=` operation.
     #[stable(feature = "op_assign_traits", since = "1.8.0")]
     fn shl_assign(&mut self, rhs: Rhs);
 }
 
 macro_rules! shl_assign_impl {
-    ($t:ty, $f:ty) => (
+    ($t:ty, $f:ty) => {
         #[stable(feature = "op_assign_traits", since = "1.8.0")]
         impl ShlAssign<$f> for $t {
             #[inline]
@@ -761,7 +779,7 @@ fn shl_assign(&mut self, other: $f) {
         }
 
         forward_ref_op_assign! { impl ShlAssign, shl_assign for $t, $f }
-    )
+    };
 }
 
 macro_rules! shl_assign_impl_all {
@@ -809,16 +827,18 @@ macro_rules! shl_assign_impl_all {
 #[lang = "shr_assign"]
 #[doc(alias = ">>=")]
 #[stable(feature = "op_assign_traits", since = "1.8.0")]
-#[rustc_on_unimplemented(message="no implementation for `{Self} >>= {Rhs}`",
-                         label="no implementation for `{Self} >>= {Rhs}`")]
-pub trait ShrAssign<Rhs=Self> {
+#[rustc_on_unimplemented(
+    message = "no implementation for `{Self} >>= {Rhs}`",
+    label = "no implementation for `{Self} >>= {Rhs}`"
+)]
+pub trait ShrAssign<Rhs = Self> {
     /// Performs the `>>=` operation.
     #[stable(feature = "op_assign_traits", since = "1.8.0")]
     fn shr_assign(&mut self, rhs: Rhs);
 }
 
 macro_rules! shr_assign_impl {
-    ($t:ty, $f:ty) => (
+    ($t:ty, $f:ty) => {
         #[stable(feature = "op_assign_traits", since = "1.8.0")]
         impl ShrAssign<$f> for $t {
             #[inline]
@@ -829,7 +849,7 @@ fn shr_assign(&mut self, other: $f) {
         }
 
         forward_ref_op_assign! { impl ShrAssign, shr_assign for $t, $f }
-    )
+    };
 }
 
 macro_rules! shr_assign_impl_all {
index ce0d3fd01f78fefc030dbe2d2a3b67afbfc7561c..f521355a90722a07ae2c57d1eae8f29dab72e480 100644 (file)
@@ -76,14 +76,18 @@ pub trait Deref {
 impl<T: ?Sized> Deref for &T {
     type Target = T;
 
-    fn deref(&self) -> &T { *self }
+    fn deref(&self) -> &T {
+        *self
+    }
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<T: ?Sized> Deref for &mut T {
     type Target = T;
 
-    fn deref(&self) -> &T { *self }
+    fn deref(&self) -> &T {
+        *self
+    }
 }
 
 /// Used for mutable dereferencing operations, like in `*v = 1;`.
@@ -165,7 +169,9 @@ pub trait DerefMut: Deref {
 
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<T: ?Sized> DerefMut for &mut T {
-    fn deref_mut(&mut self) -> &mut T { *self }
+    fn deref_mut(&mut self) -> &mut T {
+        *self
+    }
 }
 
 /// Indicates that a struct can be used as a method receiver, without the
index 35790324a2f62ff955857f0334dce43f21ae6dd3..505a65cee3de0265f5f0047395b656805e4ee33a 100644 (file)
 #[stable(feature = "rust1", since = "1.0.0")]
 #[rustc_paren_sugar]
 #[rustc_on_unimplemented(
-    on(Args="()", note="wrap the `{Self}` in a closure with no arguments: `|| {{ /* code */ }}"),
-    message="expected a `{Fn}<{Args}>` closure, found `{Self}`",
-    label="expected an `Fn<{Args}>` closure, found `{Self}`",
+    on(
+        Args = "()",
+        note = "wrap the `{Self}` in a closure with no arguments: `|| {{ /* code */ }}"
+    ),
+    message = "expected a `{Fn}<{Args}>` closure, found `{Self}`",
+    label = "expected an `Fn<{Args}>` closure, found `{Self}`"
 )]
 #[fundamental] // so that regex can rely that `&str: !FnMut`
 #[must_use = "closures are lazy and do nothing unless called"]
-pub trait Fn<Args> : FnMut<Args> {
+pub trait Fn<Args>: FnMut<Args> {
     /// Performs the call operation.
     #[unstable(feature = "fn_traits", issue = "29625")]
     extern "rust-call" fn call(&self, args: Args) -> Self::Output;
@@ -136,13 +139,16 @@ pub trait Fn<Args> : FnMut<Args> {
 #[stable(feature = "rust1", since = "1.0.0")]
 #[rustc_paren_sugar]
 #[rustc_on_unimplemented(
-    on(Args="()", note="wrap the `{Self}` in a closure with no arguments: `|| {{ /* code */ }}"),
-    message="expected a `{FnMut}<{Args}>` closure, found `{Self}`",
-    label="expected an `FnMut<{Args}>` closure, found `{Self}`",
+    on(
+        Args = "()",
+        note = "wrap the `{Self}` in a closure with no arguments: `|| {{ /* code */ }}"
+    ),
+    message = "expected a `{FnMut}<{Args}>` closure, found `{Self}`",
+    label = "expected an `FnMut<{Args}>` closure, found `{Self}`"
 )]
 #[fundamental] // so that regex can rely that `&str: !FnMut`
 #[must_use = "closures are lazy and do nothing unless called"]
-pub trait FnMut<Args> : FnOnce<Args> {
+pub trait FnMut<Args>: FnOnce<Args> {
     /// Performs the call operation.
     #[unstable(feature = "fn_traits", issue = "29625")]
     extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output;
@@ -207,9 +213,12 @@ pub trait FnMut<Args> : FnOnce<Args> {
 #[stable(feature = "rust1", since = "1.0.0")]
 #[rustc_paren_sugar]
 #[rustc_on_unimplemented(
-    on(Args="()", note="wrap the `{Self}` in a closure with no arguments: `|| {{ /* code */ }}"),
-    message="expected a `{FnOnce}<{Args}>` closure, found `{Self}`",
-    label="expected an `FnOnce<{Args}>` closure, found `{Self}`",
+    on(
+        Args = "()",
+        note = "wrap the `{Self}` in a closure with no arguments: `|| {{ /* code */ }}"
+    ),
+    message = "expected a `{FnOnce}<{Args}>` closure, found `{Self}`",
+    label = "expected an `FnOnce<{Args}>` closure, found `{Self}`"
 )]
 #[fundamental] // so that regex can rely that `&str: !FnMut`
 #[must_use = "closures are lazy and do nothing unless called"]
@@ -225,8 +234,9 @@ pub trait FnOnce<Args> {
 
 mod impls {
     #[stable(feature = "rust1", since = "1.0.0")]
-    impl<A,F:?Sized> Fn<A> for &F
-        where F : Fn<A>
+    impl<A, F: ?Sized> Fn<A> for &F
+    where
+        F: Fn<A>,
     {
         extern "rust-call" fn call(&self, args: A) -> F::Output {
             (**self).call(args)
@@ -234,8 +244,9 @@ extern "rust-call" fn call(&self, args: A) -> F::Output {
     }
 
     #[stable(feature = "rust1", since = "1.0.0")]
-    impl<A,F:?Sized> FnMut<A> for &F
-        where F : Fn<A>
+    impl<A, F: ?Sized> FnMut<A> for &F
+    where
+        F: Fn<A>,
     {
         extern "rust-call" fn call_mut(&mut self, args: A) -> F::Output {
             (**self).call(args)
@@ -243,8 +254,9 @@ extern "rust-call" fn call_mut(&mut self, args: A) -> F::Output {
     }
 
     #[stable(feature = "rust1", since = "1.0.0")]
-    impl<A,F:?Sized> FnOnce<A> for &F
-        where F : Fn<A>
+    impl<A, F: ?Sized> FnOnce<A> for &F
+    where
+        F: Fn<A>,
     {
         type Output = F::Output;
 
@@ -254,8 +266,9 @@ extern "rust-call" fn call_once(self, args: A) -> F::Output {
     }
 
     #[stable(feature = "rust1", since = "1.0.0")]
-    impl<A,F:?Sized> FnMut<A> for &mut F
-        where F : FnMut<A>
+    impl<A, F: ?Sized> FnMut<A> for &mut F
+    where
+        F: FnMut<A>,
     {
         extern "rust-call" fn call_mut(&mut self, args: A) -> F::Output {
             (*self).call_mut(args)
@@ -263,8 +276,9 @@ extern "rust-call" fn call_mut(&mut self, args: A) -> F::Output {
     }
 
     #[stable(feature = "rust1", since = "1.0.0")]
-    impl<A,F:?Sized> FnOnce<A> for &mut F
-        where F : FnMut<A>
+    impl<A, F: ?Sized> FnOnce<A> for &mut F
+    where
+        F: FnMut<A>,
     {
         type Output = F::Output;
         extern "rust-call" fn call_once(self, args: A) -> F::Output {
index 9cff474a760306be8f639270d67b5fed39802cd1..aae0691122415ce4d3d766b294a026314da048db 100644 (file)
@@ -51,8 +51,8 @@
 /// ```
 #[lang = "index"]
 #[rustc_on_unimplemented(
-    message="the type `{Self}` cannot be indexed by `{Idx}`",
-    label="`{Self}` cannot be indexed by `{Idx}`",
+    message = "the type `{Self}` cannot be indexed by `{Idx}`",
+    label = "`{Self}` cannot be indexed by `{Idx}`"
 )]
 #[stable(feature = "rust1", since = "1.0.0")]
 #[doc(alias = "]")]
@@ -142,22 +142,22 @@ pub trait Index<Idx: ?Sized> {
 #[lang = "index_mut"]
 #[rustc_on_unimplemented(
     on(
-        _Self="&str",
-        note="you can use `.chars().nth()` or `.bytes().nth()`
+        _Self = "&str",
+        note = "you can use `.chars().nth()` or `.bytes().nth()`
 see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>"
     ),
     on(
-        _Self="str",
-        note="you can use `.chars().nth()` or `.bytes().nth()`
+        _Self = "str",
+        note = "you can use `.chars().nth()` or `.bytes().nth()`
 see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>"
     ),
     on(
-        _Self="std::string::String",
-        note="you can use `.chars().nth()` or `.bytes().nth()`
+        _Self = "std::string::String",
+        note = "you can use `.chars().nth()` or `.bytes().nth()`
 see chapter in The Book <https://doc.rust-lang.org/book/ch08-02-strings.html#indexing-into-strings>"
     ),
-    message="the type `{Self}` cannot be mutably indexed by `{Idx}`",
-    label="`{Self}` cannot be mutably indexed by `{Idx}`",
+    message = "the type `{Self}` cannot be mutably indexed by `{Idx}`",
+    label = "`{Self}` cannot be mutably indexed by `{Idx}`"
 )]
 #[stable(feature = "rust1", since = "1.0.0")]
 #[doc(alias = "[")]
index 5d1d3efd4120f2994b0296da0e1fce596fbd1664..80ab906961ee79b5f344bdbb221d98831e9f5fad 100644 (file)
 mod unsize;
 
 #[stable(feature = "rust1", since = "1.0.0")]
-pub use self::arith::{Add, Sub, Mul, Div, Rem, Neg};
+pub use self::arith::{Add, Div, Mul, Neg, Rem, Sub};
 #[stable(feature = "op_assign_traits", since = "1.8.0")]
-pub use self::arith::{AddAssign, SubAssign, MulAssign, DivAssign, RemAssign};
+pub use self::arith::{AddAssign, DivAssign, MulAssign, RemAssign, SubAssign};
 
 #[stable(feature = "rust1", since = "1.0.0")]
-pub use self::bit::{Not, BitAnd, BitOr, BitXor, Shl, Shr};
+pub use self::bit::{BitAnd, BitOr, BitXor, Not, Shl, Shr};
 #[stable(feature = "op_assign_traits", since = "1.8.0")]
 pub use self::bit::{BitAndAssign, BitOrAssign, BitXorAssign, ShlAssign, ShrAssign};
 
 pub use self::range::{Range, RangeFrom, RangeFull, RangeTo};
 
 #[stable(feature = "inclusive_range", since = "1.26.0")]
-pub use self::range::{RangeInclusive, RangeToInclusive, RangeBounds, Bound};
+pub use self::range::{Bound, RangeBounds, RangeInclusive, RangeToInclusive};
 
 #[unstable(feature = "try_trait", issue = "42327")]
 pub use self::r#try::Try;
index 1b4c4218cc15bb95e25ab47e803e6096414fdc1b..a2250337a4dcab131b63c2c3590e2d535f0490c4 100644 (file)
@@ -399,11 +399,7 @@ impl<Idx> RangeInclusive<Idx> {
     #[inline]
     #[rustc_promotable]
     pub const fn new(start: Idx, end: Idx) -> Self {
-        Self {
-            start,
-            end,
-            is_empty: None,
-        }
+        Self { start, end, is_empty: None }
     }
 
     /// Returns the lower bound of the range (inclusive).
index d29147645f7ef8d7bfbf30442b194b23c80790f3..80fb5642a6a76d87228ab661fb03659858ca879a 100644 (file)
@@ -39,35 +39,34 @@ pub trait CoerceUnsized<T: ?Sized> {
 
 // &mut T -> &mut U
 #[unstable(feature = "coerce_unsized", issue = "27732")]
-impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<&'a mut U> for &'a mut T {}
+impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a mut U> for &'a mut T {}
 // &mut T -> &U
 #[unstable(feature = "coerce_unsized", issue = "27732")]
-impl<'a, 'b: 'a, T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b mut T {}
+impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b mut T {}
 // &mut T -> *mut U
 #[unstable(feature = "coerce_unsized", issue = "27732")]
-impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for &'a mut T {}
+impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for &'a mut T {}
 // &mut T -> *const U
 #[unstable(feature = "coerce_unsized", issue = "27732")]
-impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for &'a mut T {}
+impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for &'a mut T {}
 
 // &T -> &U
 #[unstable(feature = "coerce_unsized", issue = "27732")]
-impl<'a, 'b: 'a, T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {}
+impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {}
 // &T -> *const U
 #[unstable(feature = "coerce_unsized", issue = "27732")]
-impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for &'a T {}
+impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for &'a T {}
 
 // *mut T -> *mut U
 #[unstable(feature = "coerce_unsized", issue = "27732")]
-impl<T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
+impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
 // *mut T -> *const U
 #[unstable(feature = "coerce_unsized", issue = "27732")]
-impl<T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *mut T {}
+impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *mut T {}
 
 // *const T -> *const U
 #[unstable(feature = "coerce_unsized", issue = "27732")]
-impl<T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *const T {}
-
+impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*const U> for *const T {}
 
 /// This is used for object safety, to check that a method's receiver type can be dispatched on.
 ///
@@ -90,13 +89,13 @@ pub trait DispatchFromDyn<T> {
 
 // &T -> &U
 #[unstable(feature = "dispatch_from_dyn", issue = "0")]
-impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<&'a U> for &'a T {}
+impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<&'a U> for &'a T {}
 // &mut T -> &mut U
 #[unstable(feature = "dispatch_from_dyn", issue = "0")]
-impl<'a, T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<&'a mut U> for &'a mut T {}
+impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<&'a mut U> for &'a mut T {}
 // *const T -> *const U
 #[unstable(feature = "dispatch_from_dyn", issue = "0")]
-impl<T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<*const U> for *const T {}
+impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<*const U> for *const T {}
 // *mut T -> *mut U
 #[unstable(feature = "dispatch_from_dyn", issue = "0")]
-impl<T: ?Sized+Unsize<U>, U: ?Sized> DispatchFromDyn<*mut U> for *mut T {}
+impl<T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<*mut U> for *mut T {}
index 958f31c0fd22a824c39252b106906945c6288056..2066a484dac8091a3a294227c15093dca5e4d403 100644 (file)
 #![stable(feature = "rust1", since = "1.0.0")]
 
 use crate::iter::{FromIterator, FusedIterator, TrustedLen};
-use crate::{convert, fmt, hint, mem, ops::{self, Deref, DerefMut}};
 use crate::pin::Pin;
+use crate::{
+    convert, fmt, hint, mem,
+    ops::{self, Deref, DerefMut},
+};
 
 // Note that this is not a lang item per se, but it has a hidden dependency on
 // `Iterator`, which is one. The compiler assumes that the `next` method of
@@ -230,7 +233,10 @@ pub fn is_none(&self) -> bool {
     #[must_use]
     #[inline]
     #[unstable(feature = "option_result_contains", issue = "62358")]
-    pub fn contains<U>(&self, x: &U) -> bool where U: PartialEq<T> {
+    pub fn contains<U>(&self, x: &U) -> bool
+    where
+        U: PartialEq<T>,
+    {
         match self {
             Some(y) => x == y,
             None => false,
@@ -291,16 +297,13 @@ pub fn as_mut(&mut self) -> Option<&mut T> {
         }
     }
 
-
     /// Converts from [`Pin`]`<&Option<T>>` to `Option<`[`Pin`]`<&T>>`.
     ///
     /// [`Pin`]: ../pin/struct.Pin.html
     #[inline]
     #[stable(feature = "pin", since = "1.33.0")]
     pub fn as_pin_ref(self: Pin<&Self>) -> Option<Pin<&T>> {
-        unsafe {
-            Pin::get_ref(self).as_ref().map(|x| Pin::new_unchecked(x))
-        }
+        unsafe { Pin::get_ref(self).as_ref().map(|x| Pin::new_unchecked(x)) }
     }
 
     /// Converts from [`Pin`]`<&mut Option<T>>` to `Option<`[`Pin`]`<&mut T>>`.
@@ -309,9 +312,7 @@ pub fn as_pin_ref(self: Pin<&Self>) -> Option<Pin<&T>> {
     #[inline]
     #[stable(feature = "pin", since = "1.33.0")]
     pub fn as_pin_mut(self: Pin<&mut Self>) -> Option<Pin<&mut T>> {
-        unsafe {
-            Pin::get_unchecked_mut(self).as_mut().map(|x| Pin::new_unchecked(x))
-        }
+        unsafe { Pin::get_unchecked_mut(self).as_mut().map(|x| Pin::new_unchecked(x)) }
     }
 
     /////////////////////////////////////////////////////////////////////////
@@ -690,7 +691,7 @@ pub fn and_then<U, F: FnOnce(T) -> Option<U>>(self, f: F) -> Option<U> {
     pub fn filter<P: FnOnce(&T) -> bool>(self, predicate: P) -> Self {
         if let Some(x) = self {
             if predicate(&x) {
-                return Some(x)
+                return Some(x);
             }
         }
         None
@@ -1228,7 +1229,9 @@ impl<T> Default for Option<T> {
     /// assert!(opt.is_none());
     /// ```
     #[inline]
-    fn default() -> Option<T> { None }
+    fn default() -> Option<T> {
+        None
+    }
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
@@ -1302,7 +1305,7 @@ fn from(o: &'a mut Option<T>) -> Option<&'a mut T> {
 
 #[derive(Clone, Debug)]
 struct Item<A> {
-    opt: Option<A>
+    opt: Option<A>,
 }
 
 impl<A> Iterator for Item<A> {
@@ -1344,22 +1347,30 @@ unsafe impl<A> TrustedLen for Item<A> {}
 /// [`Option::iter`]: enum.Option.html#method.iter
 #[stable(feature = "rust1", since = "1.0.0")]
 #[derive(Debug)]
-pub struct Iter<'a, A: 'a> { inner: Item<&'a A> }
+pub struct Iter<'a, A: 'a> {
+    inner: Item<&'a A>,
+}
 
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<'a, A> Iterator for Iter<'a, A> {
     type Item = &'a A;
 
     #[inline]
-    fn next(&mut self) -> Option<&'a A> { self.inner.next() }
+    fn next(&mut self) -> Option<&'a A> {
+        self.inner.next()
+    }
     #[inline]
-    fn size_hint(&self) -> (usize, Option<usize>) { self.inner.size_hint() }
+    fn size_hint(&self) -> (usize, Option<usize>) {
+        self.inner.size_hint()
+    }
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<'a, A> DoubleEndedIterator for Iter<'a, A> {
     #[inline]
-    fn next_back(&mut self) -> Option<&'a A> { self.inner.next_back() }
+    fn next_back(&mut self) -> Option<&'a A> {
+        self.inner.next_back()
+    }
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
@@ -1390,22 +1401,30 @@ fn clone(&self) -> Self {
 /// [`Option::iter_mut`]: enum.Option.html#method.iter_mut
 #[stable(feature = "rust1", since = "1.0.0")]
 #[derive(Debug)]
-pub struct IterMut<'a, A: 'a> { inner: Item<&'a mut A> }
+pub struct IterMut<'a, A: 'a> {
+    inner: Item<&'a mut A>,
+}
 
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<'a, A> Iterator for IterMut<'a, A> {
     type Item = &'a mut A;
 
     #[inline]
-    fn next(&mut self) -> Option<&'a mut A> { self.inner.next() }
+    fn next(&mut self) -> Option<&'a mut A> {
+        self.inner.next()
+    }
     #[inline]
-    fn size_hint(&self) -> (usize, Option<usize>) { self.inner.size_hint() }
+    fn size_hint(&self) -> (usize, Option<usize>) {
+        self.inner.size_hint()
+    }
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<'a, A> DoubleEndedIterator for IterMut<'a, A> {
     #[inline]
-    fn next_back(&mut self) -> Option<&'a mut A> { self.inner.next_back() }
+    fn next_back(&mut self) -> Option<&'a mut A> {
+        self.inner.next_back()
+    }
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
@@ -1427,22 +1446,30 @@ unsafe impl<A> TrustedLen for IterMut<'_, A> {}
 /// [`Option::into_iter`]: enum.Option.html#method.into_iter
 #[derive(Clone, Debug)]
 #[stable(feature = "rust1", since = "1.0.0")]
-pub struct IntoIter<A> { inner: Item<A> }
+pub struct IntoIter<A> {
+    inner: Item<A>,
+}
 
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<A> Iterator for IntoIter<A> {
     type Item = A;
 
     #[inline]
-    fn next(&mut self) -> Option<A> { self.inner.next() }
+    fn next(&mut self) -> Option<A> {
+        self.inner.next()
+    }
     #[inline]
-    fn size_hint(&self) -> (usize, Option<usize>) { self.inner.size_hint() }
+    fn size_hint(&self) -> (usize, Option<usize>) {
+        self.inner.size_hint()
+    }
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<A> DoubleEndedIterator for IntoIter<A> {
     #[inline]
-    fn next_back(&mut self) -> Option<A> { self.inner.next_back() }
+    fn next_back(&mut self) -> Option<A> {
+        self.inner.next_back()
+    }
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
@@ -1523,14 +1550,11 @@ impl<A, V: FromIterator<A>> FromIterator<Option<A>> for Option<V> {
     ///
     /// [`Iterator`]: ../iter/trait.Iterator.html
     #[inline]
-    fn from_iter<I: IntoIterator<Item=Option<A>>>(iter: I) -> Option<V> {
+    fn from_iter<I: IntoIterator<Item = Option<A>>>(iter: I) -> Option<V> {
         // FIXME(#11084): This could be replaced with Iterator::scan when this
         // performance bug is closed.
 
-        iter.into_iter()
-            .map(|x| x.ok_or(()))
-            .collect::<Result<_, _>>()
-            .ok()
+        iter.into_iter().map(|x| x.ok_or(())).collect::<Result<_, _>>().ok()
     }
 }
 
index 1219fd09a9dfafda837a6fd27a1481cbc2070b74..88fa718ae9e62c37cb5ff890cf62c23c0fbb98ec 100644 (file)
 
 #![stable(feature = "pin", since = "1.33.0")]
 
+use crate::cmp::{self, PartialEq, PartialOrd};
 use crate::fmt;
 use crate::marker::{Sized, Unpin};
-use crate::cmp::{self, PartialEq, PartialOrd};
-use crate::ops::{Deref, DerefMut, Receiver, CoerceUnsized, DispatchFromDyn};
+use crate::ops::{CoerceUnsized, Deref, DerefMut, DispatchFromDyn, Receiver};
 
 /// A pinned pointer.
 ///
@@ -646,7 +646,8 @@ impl<'a, T: ?Sized> Pin<&'a T> {
     ///
     /// [`pin` module]: ../../std/pin/index.html#projections-and-structural-pinning
     #[stable(feature = "pin", since = "1.33.0")]
-    pub unsafe fn map_unchecked<U, F>(self, func: F) -> Pin<&'a U> where
+    pub unsafe fn map_unchecked<U, F>(self, func: F) -> Pin<&'a U>
+    where
         F: FnOnce(&T) -> &U,
     {
         let pointer = &*self.pointer;
@@ -698,7 +699,8 @@ pub fn into_ref(self) -> Pin<&'a T> {
     #[stable(feature = "pin", since = "1.33.0")]
     #[inline(always)]
     pub fn get_mut(self) -> &'a mut T
-        where T: Unpin,
+    where
+        T: Unpin,
     {
         self.pointer
     }
@@ -735,7 +737,8 @@ pub unsafe fn get_unchecked_mut(self) -> &'a mut T {
     ///
     /// [`pin` module]: ../../std/pin/index.html#projections-and-structural-pinning
     #[stable(feature = "pin", since = "1.33.0")]
-    pub unsafe fn map_unchecked_mut<U, F>(self, func: F) -> Pin<&'a mut U> where
+    pub unsafe fn map_unchecked_mut<U, F>(self, func: F) -> Pin<&'a mut U>
+    where
         F: FnOnce(&mut T) -> &mut U,
     {
         let pointer = Pin::get_unchecked_mut(self);
@@ -789,13 +792,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 // for other reasons, though, so we just need to take care not to allow such
 // impls to land in std.
 #[stable(feature = "pin", since = "1.33.0")]
-impl<P, U> CoerceUnsized<Pin<U>> for Pin<P>
-where
-    P: CoerceUnsized<U>,
-{}
+impl<P, U> CoerceUnsized<Pin<U>> for Pin<P> where P: CoerceUnsized<U> {}
 
 #[stable(feature = "pin", since = "1.33.0")]
-impl<P, U> DispatchFromDyn<Pin<U>> for Pin<P>
-where
-    P: DispatchFromDyn<U>,
-{}
+impl<P, U> DispatchFromDyn<Pin<U>> for Pin<P> where P: DispatchFromDyn<U> {}
index 7cc279a9ef2ecb83ce3ac3916b6f0b9273617861..66b5a90b77b919f6f6a1c894e3f185e2a64a5de2 100644 (file)
 pub use crate::clone::Clone;
 #[stable(feature = "core_prelude", since = "1.4.0")]
 #[doc(no_inline)]
-pub use crate::cmp::{PartialEq, PartialOrd, Eq, Ord};
+pub use crate::cmp::{Eq, Ord, PartialEq, PartialOrd};
 #[stable(feature = "core_prelude", since = "1.4.0")]
 #[doc(no_inline)]
-pub use crate::convert::{AsRef, AsMut, Into, From};
+pub use crate::convert::{AsMut, AsRef, From, Into};
 #[stable(feature = "core_prelude", since = "1.4.0")]
 #[doc(no_inline)]
 pub use crate::default::Default;
 #[stable(feature = "core_prelude", since = "1.4.0")]
 #[doc(no_inline)]
-pub use crate::iter::{Iterator, Extend, IntoIterator};
+pub use crate::iter::{DoubleEndedIterator, ExactSizeIterator};
 #[stable(feature = "core_prelude", since = "1.4.0")]
 #[doc(no_inline)]
-pub use crate::iter::{DoubleEndedIterator, ExactSizeIterator};
+pub use crate::iter::{Extend, IntoIterator, Iterator};
 #[stable(feature = "core_prelude", since = "1.4.0")]
 #[doc(no_inline)]
-pub use crate::option::Option::{self, Some, None};
+pub use crate::option::Option::{self, None, Some};
 #[stable(feature = "core_prelude", since = "1.4.0")]
 #[doc(no_inline)]
-pub use crate::result::Result::{self, Ok, Err};
+pub use crate::result::Result::{self, Err, Ok};
 
 // Re-exported built-in macros
 #[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
 #[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
 #[doc(no_inline)]
 pub use crate::{
-    asm,
-    assert,
-    cfg,
-    column,
-    compile_error,
-    concat,
-    concat_idents,
-    env,
-    file,
-    format_args,
-    format_args_nl,
-    global_asm,
-    include,
-    include_bytes,
-    include_str,
-    line,
-    log_syntax,
-    module_path,
-    option_env,
-    stringify,
-    trace_macros,
+    asm, assert, cfg, column, compile_error, concat, concat_idents, env, file, format_args,
+    format_args_nl, global_asm, include, include_bytes, include_str, line, log_syntax, module_path,
+    option_env, stringify, trace_macros,
 };
 
 #[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
 #[allow(deprecated)]
 #[doc(no_inline)]
 pub use crate::macros::builtin::{
-    RustcDecodable,
-    RustcEncodable,
-    bench,
-    global_allocator,
-    test,
-    test_case,
+    bench, global_allocator, test, test_case, RustcDecodable, RustcEncodable,
 };
index 7599991f0f15a78a49dd66c5bfc521cebdfc0d22..a121389bef3c9e5ad0bdfc56d963601fa7cc9b44 100644 (file)
@@ -1,11 +1,11 @@
+use crate::cmp::Ordering;
 use crate::convert::From;
-use crate::ops::{CoerceUnsized, DispatchFromDyn};
 use crate::fmt;
 use crate::hash;
 use crate::marker::Unsize;
 use crate::mem;
+use crate::ops::{CoerceUnsized, DispatchFromDyn};
 use crate::ptr::Unique;
-use crate::cmp::Ordering;
 
 // ignore-tidy-undocumented-unsafe
 
@@ -48,12 +48,12 @@ pub struct NonNull<T: ?Sized> {
 /// `NonNull` pointers are not `Send` because the data they reference may be aliased.
 // N.B., this impl is unnecessary, but should provide better error messages.
 #[stable(feature = "nonnull", since = "1.25.0")]
-impl<T: ?Sized> !Send for NonNull<T> { }
+impl<T: ?Sized> !Send for NonNull<T> {}
 
 /// `NonNull` pointers are not `Sync` because the data they reference may be aliased.
 // N.B., this impl is unnecessary, but should provide better error messages.
 #[stable(feature = "nonnull", since = "1.25.0")]
-impl<T: ?Sized> !Sync for NonNull<T> { }
+impl<T: ?Sized> !Sync for NonNull<T> {}
 
 impl<T: Sized> NonNull<T> {
     /// Creates a new `NonNull` that is dangling, but well-aligned.
@@ -91,11 +91,7 @@ impl<T: ?Sized> NonNull<T> {
     #[stable(feature = "nonnull", since = "1.25.0")]
     #[inline]
     pub fn new(ptr: *mut T) -> Option<Self> {
-        if !ptr.is_null() {
-            Some(unsafe { Self::new_unchecked(ptr) })
-        } else {
-            None
-        }
+        if !ptr.is_null() { Some(unsafe { Self::new_unchecked(ptr) }) } else { None }
     }
 
     /// Acquires the underlying `*mut` pointer.
@@ -131,9 +127,7 @@ pub unsafe fn as_mut(&mut self) -> &mut T {
     #[stable(feature = "nonnull_cast", since = "1.27.0")]
     #[inline]
     pub const fn cast<U>(self) -> NonNull<U> {
-        unsafe {
-            NonNull::new_unchecked(self.as_ptr() as *mut U)
-        }
+        unsafe { NonNull::new_unchecked(self.as_ptr() as *mut U) }
     }
 }
 
@@ -146,13 +140,13 @@ fn clone(&self) -> Self {
 }
 
 #[stable(feature = "nonnull", since = "1.25.0")]
-impl<T: ?Sized> Copy for NonNull<T> { }
+impl<T: ?Sized> Copy for NonNull<T> {}
 
 #[unstable(feature = "coerce_unsized", issue = "27732")]
-impl<T: ?Sized, U: ?Sized> CoerceUnsized<NonNull<U>> for NonNull<T> where T: Unsize<U> { }
+impl<T: ?Sized, U: ?Sized> CoerceUnsized<NonNull<U>> for NonNull<T> where T: Unsize<U> {}
 
 #[unstable(feature = "dispatch_from_dyn", issue = "0")]
-impl<T: ?Sized, U: ?Sized> DispatchFromDyn<NonNull<U>> for NonNull<T> where T: Unsize<U> { }
+impl<T: ?Sized, U: ?Sized> DispatchFromDyn<NonNull<U>> for NonNull<T> where T: Unsize<U> {}
 
 #[stable(feature = "nonnull", since = "1.25.0")]
 impl<T: ?Sized> fmt::Debug for NonNull<T> {
index 11a3aed1ab41b945f51be27de8498be21d2c055d..546b7c9d777f59c39c99cc67a10d062192656afb 100644 (file)
@@ -1,8 +1,8 @@
 use crate::convert::From;
-use crate::ops::{CoerceUnsized, DispatchFromDyn};
 use crate::fmt;
 use crate::marker::{PhantomData, Unsize};
 use crate::mem;
+use crate::ops::{CoerceUnsized, DispatchFromDyn};
 use crate::ptr::NonNull;
 
 // ignore-tidy-undocumented-unsafe
 ///
 /// Unlike `*mut T`, `Unique<T>` is covariant over `T`. This should always be correct
 /// for any type which upholds Unique's aliasing requirements.
-#[unstable(feature = "ptr_internals", issue = "0",
-           reason = "use `NonNull` instead and consider `PhantomData<T>` \
-                     (if you also use `#[may_dangle]`), `Send`, and/or `Sync`")]
+#[unstable(
+    feature = "ptr_internals",
+    issue = "0",
+    reason = "use `NonNull` instead and consider `PhantomData<T>` \
+              (if you also use `#[may_dangle]`), `Send`, and/or `Sync`"
+)]
 #[doc(hidden)]
 #[repr(transparent)]
 #[rustc_layout_scalar_valid_range_start(1)]
@@ -48,14 +51,14 @@ pub struct Unique<T: ?Sized> {
 /// unenforced by the type system; the abstraction using the
 /// `Unique` must enforce it.
 #[unstable(feature = "ptr_internals", issue = "0")]
-unsafe impl<T: Send + ?Sized> Send for Unique<T> { }
+unsafe impl<T: Send + ?Sized> Send for Unique<T> {}
 
 /// `Unique` pointers are `Sync` if `T` is `Sync` because the data they
 /// reference is unaliased. Note that this aliasing invariant is
 /// unenforced by the type system; the abstraction using the
 /// `Unique` must enforce it.
 #[unstable(feature = "ptr_internals", issue = "0")]
-unsafe impl<T: Sync + ?Sized> Sync for Unique<T> { }
+unsafe impl<T: Sync + ?Sized> Sync for Unique<T> {}
 
 #[unstable(feature = "ptr_internals", issue = "0")]
 impl<T: Sized> Unique<T> {
@@ -71,9 +74,7 @@ impl<T: Sized> Unique<T> {
     // FIXME: rename to dangling() to match NonNull?
     #[inline]
     pub const fn empty() -> Self {
-        unsafe {
-            Unique::new_unchecked(mem::align_of::<T>() as *mut T)
-        }
+        unsafe { Unique::new_unchecked(mem::align_of::<T>() as *mut T) }
     }
 }
 
@@ -128,9 +129,7 @@ pub unsafe fn as_mut(&mut self) -> &mut T {
     /// Casts to a pointer of another type.
     #[inline]
     pub const fn cast<U>(self) -> Unique<U> {
-        unsafe {
-            Unique::new_unchecked(self.as_ptr() as *mut U)
-        }
+        unsafe { Unique::new_unchecked(self.as_ptr() as *mut U) }
     }
 }
 
@@ -143,13 +142,13 @@ fn clone(&self) -> Self {
 }
 
 #[unstable(feature = "ptr_internals", issue = "0")]
-impl<T: ?Sized> Copy for Unique<T> { }
+impl<T: ?Sized> Copy for Unique<T> {}
 
 #[unstable(feature = "ptr_internals", issue = "0")]
-impl<T: ?Sized, U: ?Sized> CoerceUnsized<Unique<U>> for Unique<T> where T: Unsize<U> { }
+impl<T: ?Sized, U: ?Sized> CoerceUnsized<Unique<U>> for Unique<T> where T: Unsize<U> {}
 
 #[unstable(feature = "ptr_internals", issue = "0")]
-impl<T: ?Sized, U: ?Sized> DispatchFromDyn<Unique<U>> for Unique<T> where T: Unsize<U> { }
+impl<T: ?Sized, U: ?Sized> DispatchFromDyn<Unique<U>> for Unique<T> where T: Unsize<U> {}
 
 #[unstable(feature = "ptr_internals", issue = "0")]
 impl<T: ?Sized> fmt::Debug for Unique<T> {
index a719a51b61605b2c194c3894d6309c8056ba151b..019832e16f89cd20d25f6c508c55d5bfa081e72f 100644 (file)
@@ -20,13 +20,16 @@ struct CopyOnDrop<T> {
 
 impl<T> Drop for CopyOnDrop<T> {
     fn drop(&mut self) {
-        unsafe { ptr::copy_nonoverlapping(self.src, self.dest, 1); }
+        unsafe {
+            ptr::copy_nonoverlapping(self.src, self.dest, 1);
+        }
     }
 }
 
 /// Shifts the first element to the right until it encounters a greater or equal element.
 fn shift_head<T, F>(v: &mut [T], is_less: &mut F)
-    where F: FnMut(&T, &T) -> bool
+where
+    F: FnMut(&T, &T) -> bool,
 {
     let len = v.len();
     unsafe {
@@ -36,10 +39,7 @@ fn shift_head<T, F>(v: &mut [T], is_less: &mut F)
             // operation panics, `hole` will get dropped and automatically write the element back
             // into the slice.
             let mut tmp = mem::ManuallyDrop::new(ptr::read(v.get_unchecked(0)));
-            let mut hole = CopyOnDrop {
-                src: &mut *tmp,
-                dest: v.get_unchecked_mut(1),
-            };
+            let mut hole = CopyOnDrop { src: &mut *tmp, dest: v.get_unchecked_mut(1) };
             ptr::copy_nonoverlapping(v.get_unchecked(1), v.get_unchecked_mut(0), 1);
 
             for i in 2..len {
@@ -58,7 +58,8 @@ fn shift_head<T, F>(v: &mut [T], is_less: &mut F)
 
 /// Shifts the last element to the left until it encounters a smaller or equal element.
 fn shift_tail<T, F>(v: &mut [T], is_less: &mut F)
-    where F: FnMut(&T, &T) -> bool
+where
+    F: FnMut(&T, &T) -> bool,
 {
     let len = v.len();
     unsafe {
@@ -68,13 +69,10 @@ fn shift_tail<T, F>(v: &mut [T], is_less: &mut F)
             // operation panics, `hole` will get dropped and automatically write the element back
             // into the slice.
             let mut tmp = mem::ManuallyDrop::new(ptr::read(v.get_unchecked(len - 1)));
-            let mut hole = CopyOnDrop {
-                src: &mut *tmp,
-                dest: v.get_unchecked_mut(len - 2),
-            };
+            let mut hole = CopyOnDrop { src: &mut *tmp, dest: v.get_unchecked_mut(len - 2) };
             ptr::copy_nonoverlapping(v.get_unchecked(len - 2), v.get_unchecked_mut(len - 1), 1);
 
-            for i in (0..len-2).rev() {
+            for i in (0..len - 2).rev() {
                 if !is_less(&*tmp, v.get_unchecked(i)) {
                     break;
                 }
@@ -93,7 +91,8 @@ fn shift_tail<T, F>(v: &mut [T], is_less: &mut F)
 /// Returns `true` if the slice is sorted at the end. This function is `O(n)` worst-case.
 #[cold]
 fn partial_insertion_sort<T, F>(v: &mut [T], is_less: &mut F) -> bool
-    where F: FnMut(&T, &T) -> bool
+where
+    F: FnMut(&T, &T) -> bool,
 {
     // Maximum number of adjacent out-of-order pairs that will get shifted.
     const MAX_STEPS: usize = 5;
@@ -136,17 +135,19 @@ fn partial_insertion_sort<T, F>(v: &mut [T], is_less: &mut F) -> bool
 
 /// Sorts a slice using insertion sort, which is `O(n^2)` worst-case.
 fn insertion_sort<T, F>(v: &mut [T], is_less: &mut F)
-    where F: FnMut(&T, &T) -> bool
+where
+    F: FnMut(&T, &T) -> bool,
 {
     for i in 1..v.len() {
-        shift_tail(&mut v[..i+1], is_less);
+        shift_tail(&mut v[..i + 1], is_less);
     }
 }
 
 /// Sorts `v` using heapsort, which guarantees `O(n log n)` worst-case.
 #[cold]
 pub fn heapsort<T, F>(v: &mut [T], is_less: &mut F)
-    where F: FnMut(&T, &T) -> bool
+where
+    F: FnMut(&T, &T) -> bool,
 {
     // This binary heap respects the invariant `parent >= child`.
     let mut sift_down = |v: &mut [T], mut node| {
@@ -156,11 +157,8 @@ pub fn heapsort<T, F>(v: &mut [T], is_less: &mut F)
             let right = 2 * node + 2;
 
             // Choose the greater child.
-            let greater = if right < v.len() && is_less(&v[left], &v[right]) {
-                right
-            } else {
-                left
-            };
+            let greater =
+                if right < v.len() && is_less(&v[left], &v[right]) { right } else { left };
 
             // Stop if the invariant holds at `node`.
             if greater >= v.len() || !is_less(&v[node], &v[greater]) {
@@ -174,12 +172,12 @@ pub fn heapsort<T, F>(v: &mut [T], is_less: &mut F)
     };
 
     // Build the heap in linear time.
-    for i in (0 .. v.len() / 2).rev() {
+    for i in (0..v.len() / 2).rev() {
         sift_down(v, i);
     }
 
     // Pop maximal elements from the heap.
-    for i in (1 .. v.len()).rev() {
+    for i in (1..v.len()).rev() {
         v.swap(0, i);
         sift_down(&mut v[..i], 0);
     }
@@ -195,7 +193,8 @@ pub fn heapsort<T, F>(v: &mut [T], is_less: &mut F)
 ///
 /// [pdf]: http://drops.dagstuhl.de/opus/volltexte/2016/6389/pdf/LIPIcs-ESA-2016-38.pdf
 fn partition_in_blocks<T, F>(v: &mut [T], pivot: &T, is_less: &mut F) -> usize
-    where F: FnMut(&T, &T) -> bool
+where
+    F: FnMut(&T, &T) -> bool,
 {
     // Number of elements in a typical block.
     const BLOCK: usize = 128;
@@ -298,8 +297,16 @@ fn width<T>(l: *mut T, r: *mut T) -> usize {
         let count = cmp::min(width(start_l, end_l), width(start_r, end_r));
 
         if count > 0 {
-            macro_rules! left { () => { l.offset(*start_l as isize) } }
-            macro_rules! right { () => { r.offset(-(*start_r as isize) - 1) } }
+            macro_rules! left {
+                () => {
+                    l.offset(*start_l as isize)
+                };
+            }
+            macro_rules! right {
+                () => {
+                    r.offset(-(*start_r as isize) - 1)
+                };
+            }
 
             // Instead of swapping one pair at the time, it is more efficient to perform a cyclic
             // permutation. This is not strictly equivalent to swapping, but produces a similar
@@ -379,7 +386,8 @@ macro_rules! right { () => { r.offset(-(*start_r as isize) - 1) } }
 /// 1. Number of elements smaller than `v[pivot]`.
 /// 2. True if `v` was already partitioned.
 fn partition<T, F>(v: &mut [T], pivot: usize, is_less: &mut F) -> (usize, bool)
-    where F: FnMut(&T, &T) -> bool
+where
+    F: FnMut(&T, &T) -> bool,
 {
     let (mid, was_partitioned) = {
         // Place the pivot at the beginning of slice.
@@ -390,10 +398,7 @@ fn partition<T, F>(v: &mut [T], pivot: usize, is_less: &mut F) -> (usize, bool)
         // Read the pivot into a stack-allocated variable for efficiency. If a following comparison
         // operation panics, the pivot will be automatically written back into the slice.
         let mut tmp = mem::ManuallyDrop::new(unsafe { ptr::read(pivot) });
-        let _pivot_guard = CopyOnDrop {
-            src: &mut *tmp,
-            dest: pivot,
-        };
+        let _pivot_guard = CopyOnDrop { src: &mut *tmp, dest: pivot };
         let pivot = &*tmp;
 
         // Find the first pair of out-of-order elements.
@@ -429,7 +434,8 @@ fn partition<T, F>(v: &mut [T], pivot: usize, is_less: &mut F) -> (usize, bool)
 /// Returns the number of elements equal to the pivot. It is assumed that `v` does not contain
 /// elements smaller than the pivot.
 fn partition_equal<T, F>(v: &mut [T], pivot: usize, is_less: &mut F) -> usize
-    where F: FnMut(&T, &T) -> bool
+where
+    F: FnMut(&T, &T) -> bool,
 {
     // Place the pivot at the beginning of slice.
     v.swap(0, pivot);
@@ -439,10 +445,7 @@ fn partition_equal<T, F>(v: &mut [T], pivot: usize, is_less: &mut F) -> usize
     // Read the pivot into a stack-allocated variable for efficiency. If a following comparison
     // operation panics, the pivot will be automatically written back into the slice.
     let mut tmp = mem::ManuallyDrop::new(unsafe { ptr::read(pivot) });
-    let _pivot_guard = CopyOnDrop {
-        src: &mut *tmp,
-        dest: pivot,
-    };
+    let _pivot_guard = CopyOnDrop { src: &mut *tmp, dest: pivot };
     let pivot = &*tmp;
 
     // Now partition the slice.
@@ -528,7 +531,8 @@ fn break_patterns<T>(v: &mut [T]) {
 ///
 /// Elements in `v` might be reordered in the process.
 fn choose_pivot<T, F>(v: &mut [T], is_less: &mut F) -> (usize, bool)
-    where F: FnMut(&T, &T) -> bool
+where
+    F: FnMut(&T, &T) -> bool,
 {
     // Minimum length to choose the median-of-medians method.
     // Shorter slices use the simple median-of-three method.
@@ -596,7 +600,8 @@ fn choose_pivot<T, F>(v: &mut [T], is_less: &mut F) -> (usize, bool)
 /// `limit` is the number of allowed imbalanced partitions before switching to `heapsort`. If zero,
 /// this function will immediately switch to heapsort.
 fn recurse<'a, T, F>(mut v: &'a mut [T], is_less: &mut F, mut pred: Option<&'a T>, mut limit: usize)
-    where F: FnMut(&T, &T) -> bool
+where
+    F: FnMut(&T, &T) -> bool,
 {
     // Slices of up to this length get sorted using insertion sort.
     const MAX_INSERTION: usize = 20;
@@ -650,7 +655,7 @@ fn recurse<'a, T, F>(mut v: &'a mut [T], is_less: &mut F, mut pred: Option<&'a T
                 let mid = partition_equal(v, pivot, is_less);
 
                 // Continue sorting elements greater than the pivot.
-                v = &mut {v}[mid..];
+                v = &mut { v }[mid..];
                 continue;
             }
         }
@@ -661,7 +666,7 @@ fn recurse<'a, T, F>(mut v: &'a mut [T], is_less: &mut F, mut pred: Option<&'a T
         was_partitioned = was_p;
 
         // Split the slice into `left`, `pivot`, and `right`.
-        let (left, right) = {v}.split_at_mut(mid);
+        let (left, right) = { v }.split_at_mut(mid);
         let (pivot, right) = right.split_at_mut(1);
         let pivot = &pivot[0];
 
@@ -681,7 +686,8 @@ fn recurse<'a, T, F>(mut v: &'a mut [T], is_less: &mut F, mut pred: Option<&'a T
 
 /// Sorts `v` using pattern-defeating quicksort, which is `O(n log n)` worst-case.
 pub fn quicksort<T, F>(v: &mut [T], mut is_less: F)
-    where F: FnMut(&T, &T) -> bool
+where
+    F: FnMut(&T, &T) -> bool,
 {
     // Sorting has no meaningful behavior on zero-sized types.
     if mem::size_of::<T>() == 0 {
@@ -694,8 +700,13 @@ pub fn quicksort<T, F>(v: &mut [T], mut is_less: F)
     recurse(v, &mut is_less, None, limit);
 }
 
-fn partition_at_index_loop<'a, T, F>( mut v: &'a mut [T], mut index: usize, is_less: &mut F
-                                    , mut pred: Option<&'a T>) where F: FnMut(&T, &T) -> bool
+fn partition_at_index_loop<'a, T, F>(
+    mut v: &'a mut [T],
+    mut index: usize,
+    is_less: &mut F,
+    mut pred: Option<&'a T>,
+) where
+    F: FnMut(&T, &T) -> bool,
 {
     loop {
         // For slices of up to this length it's probably faster to simply sort them.
@@ -731,7 +742,7 @@ fn partition_at_index_loop<'a, T, F>( mut v: &'a mut [T], mut index: usize, is_l
         let (mid, _) = partition(v, pivot, is_less);
 
         // Split the slice into `left`, `pivot`, and `right`.
-        let (left, right) = {v}.split_at_mut(mid);
+        let (left, right) = { v }.split_at_mut(mid);
         let (pivot, right) = right.split_at_mut(1);
         let pivot = &pivot[0];
 
@@ -749,11 +760,16 @@ fn partition_at_index_loop<'a, T, F>( mut v: &'a mut [T], mut index: usize, is_l
     }
 }
 
-pub fn partition_at_index<T, F>(v: &mut [T], index: usize, mut is_less: F)
-                                -> (&mut [T], &mut T, &mut [T]) where F: FnMut(&T, &T) -> bool
+pub fn partition_at_index<T, F>(
+    v: &mut [T],
+    index: usize,
+    mut is_less: F,
+) -> (&mut [T], &mut T, &mut [T])
+where
+    F: FnMut(&T, &T) -> bool,
 {
-    use cmp::Ordering::Less;
     use cmp::Ordering::Greater;
+    use cmp::Ordering::Less;
 
     if index >= v.len() {
         panic!("partition_at_index index {} greater than length of slice {}", index, v.len());
@@ -764,14 +780,20 @@ pub fn partition_at_index<T, F>(v: &mut [T], index: usize, mut is_less: F)
     } else if index == v.len() - 1 {
         // Find max element and place it in the last position of the array. We're free to use
         // `unwrap()` here because we know v must not be empty.
-        let (max_index, _) = v.iter().enumerate().max_by(
-            |&(_, x), &(_, y)| if is_less(x, y) { Less } else { Greater }).unwrap();
+        let (max_index, _) = v
+            .iter()
+            .enumerate()
+            .max_by(|&(_, x), &(_, y)| if is_less(x, y) { Less } else { Greater })
+            .unwrap();
         v.swap(max_index, index);
     } else if index == 0 {
         // Find min element and place it in the first position of the array. We're free to use
         // `unwrap()` here because we know v must not be empty.
-        let (min_index, _) = v.iter().enumerate().min_by(
-            |&(_, x), &(_, y)| if is_less(x, y) { Less } else { Greater }).unwrap();
+        let (min_index, _) = v
+            .iter()
+            .enumerate()
+            .min_by(|&(_, x), &(_, y)| if is_less(x, y) { Less } else { Greater })
+            .unwrap();
         v.swap(min_index, index);
     } else {
         partition_at_index_loop(v, index, &mut is_less, None);
index ef090928392cd70eff1404c260d9a9dea3c3cc1b..27760749c1d4b63ddca3afbf14d25da6d2c5ef3e 100644 (file)
@@ -8,4 +8,4 @@
 
 mod wake;
 #[stable(feature = "futures_api", since = "1.36.0")]
-pub use self::wake::{Context, Waker, RawWaker, RawWakerVTable};
+pub use self::wake::{Context, RawWaker, RawWakerVTable, Waker};
index fec17c4d1a4df7b111a5ab90b38cd6a956945868..d567ae545774ef56726de81f2a55c2ac3bb3be96 100644 (file)
 pub enum Poll<T> {
     /// Represents that a value is immediately ready.
     #[stable(feature = "futures_api", since = "1.36.0")]
-    Ready(
-        #[stable(feature = "futures_api", since = "1.36.0")]
-        T
-    ),
+    Ready(#[stable(feature = "futures_api", since = "1.36.0")] T),
 
     /// Represents that a value is not ready yet.
     ///
@@ -29,7 +26,8 @@ impl<T> Poll<T> {
     /// Changes the ready value of this `Poll` with the closure provided.
     #[stable(feature = "futures_api", since = "1.36.0")]
     pub fn map<U, F>(self, f: F) -> Poll<U>
-        where F: FnOnce(T) -> U
+    where
+        F: FnOnce(T) -> U,
     {
         match self {
             Poll::Ready(t) => Poll::Ready(f(t)),
@@ -59,7 +57,8 @@ impl<T, E> Poll<Result<T, E>> {
     /// Changes the success value of this `Poll` with the closure provided.
     #[stable(feature = "futures_api", since = "1.36.0")]
     pub fn map_ok<U, F>(self, f: F) -> Poll<Result<U, E>>
-        where F: FnOnce(T) -> U
+    where
+        F: FnOnce(T) -> U,
     {
         match self {
             Poll::Ready(Ok(t)) => Poll::Ready(Ok(f(t))),
@@ -71,7 +70,8 @@ pub fn map_ok<U, F>(self, f: F) -> Poll<Result<U, E>>
     /// Changes the error value of this `Poll` with the closure provided.
     #[stable(feature = "futures_api", since = "1.36.0")]
     pub fn map_err<U, F>(self, f: F) -> Poll<Result<T, U>>
-        where F: FnOnce(E) -> U
+    where
+        F: FnOnce(E) -> U,
     {
         match self {
             Poll::Ready(Ok(t)) => Poll::Ready(Ok(t)),
@@ -85,7 +85,8 @@ impl<T, E> Poll<Option<Result<T, E>>> {
     /// Changes the success value of this `Poll` with the closure provided.
     #[unstable(feature = "poll_map", issue = "63514")]
     pub fn map_ok<U, F>(self, f: F) -> Poll<Option<Result<U, E>>>
-        where F: FnOnce(T) -> U
+    where
+        F: FnOnce(T) -> U,
     {
         match self {
             Poll::Ready(Some(Ok(t))) => Poll::Ready(Some(Ok(f(t)))),
@@ -98,7 +99,8 @@ pub fn map_ok<U, F>(self, f: F) -> Poll<Option<Result<U, E>>>
     /// Changes the error value of this `Poll` with the closure provided.
     #[unstable(feature = "poll_map", issue = "63514")]
     pub fn map_err<U, F>(self, f: F) -> Poll<Option<Result<T, U>>>
-        where F: FnOnce(E) -> U
+    where
+        F: FnOnce(E) -> U,
     {
         match self {
             Poll::Ready(Some(Ok(t))) => Poll::Ready(Some(Ok(t))),
index 6f841bd2adf41a9be45c16512042475952e85512..0759ff93ea85f0da49acb9f346068da1b0622a83 100644 (file)
@@ -40,10 +40,7 @@ impl RawWaker {
     #[rustc_promotable]
     #[stable(feature = "futures_api", since = "1.36.0")]
     pub const fn new(data: *const (), vtable: &'static RawWakerVTable) -> RawWaker {
-        RawWaker {
-            data,
-            vtable,
-        }
+        RawWaker { data, vtable }
     }
 }
 
@@ -160,12 +157,7 @@ pub const fn new(
         wake_by_ref: unsafe fn(*const ()),
         drop: unsafe fn(*const ()),
     ) -> Self {
-        Self {
-            clone,
-            wake,
-            wake_by_ref,
-            drop,
-        }
+        Self { clone, wake, wake_by_ref, drop }
     }
 }
 
@@ -188,10 +180,7 @@ impl<'a> Context<'a> {
     #[stable(feature = "futures_api", since = "1.36.0")]
     #[inline]
     pub fn from_waker(waker: &'a Waker) -> Self {
-        Context {
-            waker,
-            _marker: PhantomData,
-        }
+        Context { waker, _marker: PhantomData }
     }
 
     /// Returns a reference to the `Waker` for the current task.
@@ -205,9 +194,7 @@ pub fn waker(&self) -> &'a Waker {
 #[stable(feature = "futures_api", since = "1.36.0")]
 impl fmt::Debug for Context<'_> {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        f.debug_struct("Context")
-            .field("waker", &self.waker)
-            .finish()
+        f.debug_struct("Context").field("waker", &self.waker).finish()
     }
 }
 
@@ -291,9 +278,7 @@ pub fn will_wake(&self, other: &Waker) -> bool {
     #[inline]
     #[stable(feature = "futures_api", since = "1.36.0")]
     pub unsafe fn from_raw(waker: RawWaker) -> Waker {
-        Waker {
-            waker,
-        }
+        Waker { waker }
     }
 }
 
index 57fc1a7b76075f35f283f761fc96c5eb6d9ba010..70ec1e42fd71b6981d27c8c02e2e0ee4fd198f07 100644 (file)
@@ -12,9 +12,9 @@
 //! assert_eq!(Duration::new(5, 0), Duration::from_secs(5));
 //! ```
 
-use crate::{fmt, u64};
 use crate::iter::Sum;
-use crate::ops::{Add, Sub, Mul, Div, AddAssign, SubAssign, MulAssign, DivAssign};
+use crate::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};
+use crate::{fmt, u64};
 
 const NANOS_PER_SEC: u32 = 1_000_000_000;
 const NANOS_PER_MILLI: u32 = 1_000_000;
@@ -131,8 +131,8 @@ impl Duration {
     #[stable(feature = "duration", since = "1.3.0")]
     #[inline]
     pub fn new(secs: u64, nanos: u32) -> Duration {
-        let secs = secs.checked_add((nanos / NANOS_PER_SEC) as u64)
-            .expect("overflow in Duration::new");
+        let secs =
+            secs.checked_add((nanos / NANOS_PER_SEC) as u64).expect("overflow in Duration::new");
         let nanos = nanos % NANOS_PER_SEC;
         Duration { secs, nanos }
     }
@@ -252,7 +252,9 @@ pub const fn from_nanos(nanos: u64) -> Duration {
     /// [`subsec_nanos`]: #method.subsec_nanos
     #[stable(feature = "duration", since = "1.3.0")]
     #[inline]
-    pub const fn as_secs(&self) -> u64 { self.secs }
+    pub const fn as_secs(&self) -> u64 {
+        self.secs
+    }
 
     /// Returns the fractional part of this `Duration`, in whole milliseconds.
     ///
@@ -271,7 +273,9 @@ pub const fn as_secs(&self) -> u64 { self.secs }
     /// ```
     #[stable(feature = "duration_extras", since = "1.27.0")]
     #[inline]
-    pub const fn subsec_millis(&self) -> u32 { self.nanos / NANOS_PER_MILLI }
+    pub const fn subsec_millis(&self) -> u32 {
+        self.nanos / NANOS_PER_MILLI
+    }
 
     /// Returns the fractional part of this `Duration`, in whole microseconds.
     ///
@@ -290,7 +294,9 @@ pub const fn subsec_millis(&self) -> u32 { self.nanos / NANOS_PER_MILLI }
     /// ```
     #[stable(feature = "duration_extras", since = "1.27.0")]
     #[inline]
-    pub const fn subsec_micros(&self) -> u32 { self.nanos / NANOS_PER_MICRO }
+    pub const fn subsec_micros(&self) -> u32 {
+        self.nanos / NANOS_PER_MICRO
+    }
 
     /// Returns the fractional part of this `Duration`, in nanoseconds.
     ///
@@ -309,7 +315,9 @@ pub const fn subsec_micros(&self) -> u32 { self.nanos / NANOS_PER_MICRO }
     /// ```
     #[stable(feature = "duration", since = "1.3.0")]
     #[inline]
-    pub const fn subsec_nanos(&self) -> u32 { self.nanos }
+    pub const fn subsec_nanos(&self) -> u32 {
+        self.nanos
+    }
 
     /// Returns the total number of whole milliseconds contained by this `Duration`.
     ///
@@ -388,10 +396,7 @@ pub fn checked_add(self, rhs: Duration) -> Option<Duration> {
                 }
             }
             debug_assert!(nanos < NANOS_PER_SEC);
-            Some(Duration {
-                secs,
-                nanos,
-            })
+            Some(Duration { secs, nanos })
         } else {
             None
         }
@@ -455,14 +460,11 @@ pub fn checked_mul(self, rhs: u32) -> Option<Duration> {
         let total_nanos = self.nanos as u64 * rhs as u64;
         let extra_secs = total_nanos / (NANOS_PER_SEC as u64);
         let nanos = (total_nanos % (NANOS_PER_SEC as u64)) as u32;
-        if let Some(secs) = self.secs
-            .checked_mul(rhs as u64)
-            .and_then(|s| s.checked_add(extra_secs)) {
+        if let Some(secs) =
+            self.secs.checked_mul(rhs as u64).and_then(|s| s.checked_add(extra_secs))
+        {
             debug_assert!(nanos < NANOS_PER_SEC);
-            Some(Duration {
-                secs,
-                nanos,
-            })
+            Some(Duration { secs, nanos })
         } else {
             None
         }
@@ -549,9 +551,8 @@ pub fn as_secs_f32(&self) -> f32 {
     #[stable(feature = "duration_float", since = "1.38.0")]
     #[inline]
     pub fn from_secs_f64(secs: f64) -> Duration {
-        const MAX_NANOS_F64: f64 =
-            ((u64::MAX as u128 + 1)*(NANOS_PER_SEC as u128)) as f64;
-        let nanos =  secs * (NANOS_PER_SEC as f64);
+        const MAX_NANOS_F64: f64 = ((u64::MAX as u128 + 1) * (NANOS_PER_SEC as u128)) as f64;
+        let nanos = secs * (NANOS_PER_SEC as f64);
         if !nanos.is_finite() {
             panic!("got non-finite value when converting float to duration");
         }
@@ -561,7 +562,7 @@ pub fn from_secs_f64(secs: f64) -> Duration {
         if nanos < 0.0 {
             panic!("underflow when converting float to duration");
         }
-        let nanos =  nanos as u128;
+        let nanos = nanos as u128;
         Duration {
             secs: (nanos / (NANOS_PER_SEC as u128)) as u64,
             nanos: (nanos % (NANOS_PER_SEC as u128)) as u32,
@@ -584,9 +585,8 @@ pub fn from_secs_f64(secs: f64) -> Duration {
     #[stable(feature = "duration_float", since = "1.38.0")]
     #[inline]
     pub fn from_secs_f32(secs: f32) -> Duration {
-        const MAX_NANOS_F32: f32 =
-            ((u64::MAX as u128 + 1)*(NANOS_PER_SEC as u128)) as f32;
-        let nanos =  secs * (NANOS_PER_SEC as f32);
+        const MAX_NANOS_F32: f32 = ((u64::MAX as u128 + 1) * (NANOS_PER_SEC as u128)) as f32;
+        let nanos = secs * (NANOS_PER_SEC as f32);
         if !nanos.is_finite() {
             panic!("got non-finite value when converting float to duration");
         }
@@ -596,7 +596,7 @@ pub fn from_secs_f32(secs: f32) -> Duration {
         if nanos < 0.0 {
             panic!("underflow when converting float to duration");
         }
-        let nanos =  nanos as u128;
+        let nanos = nanos as u128;
         Duration {
             secs: (nanos / (NANOS_PER_SEC as u128)) as u64,
             nanos: (nanos % (NANOS_PER_SEC as u128)) as u32,
@@ -799,9 +799,8 @@ macro_rules! sum_durations {
         let mut total_nanos: u64 = 0;
 
         for entry in $iter {
-            total_secs = total_secs
-                .checked_add(entry.secs)
-                .expect("overflow in iter::sum over durations");
+            total_secs =
+                total_secs.checked_add(entry.secs).expect("overflow in iter::sum over durations");
             total_nanos = match total_nanos.checked_add(entry.nanos as u64) {
                 Some(n) => n,
                 None => {
@@ -816,23 +815,20 @@ macro_rules! sum_durations {
             .checked_add(total_nanos / NANOS_PER_SEC as u64)
             .expect("overflow in iter::sum over durations");
         total_nanos = total_nanos % NANOS_PER_SEC as u64;
-        Duration {
-            secs: total_secs,
-            nanos: total_nanos as u32,
-        }
+        Duration { secs: total_secs, nanos: total_nanos as u32 }
     }};
 }
 
 #[stable(feature = "duration_sum", since = "1.16.0")]
 impl Sum for Duration {
-    fn sum<I: Iterator<Item=Duration>>(iter: I) -> Duration {
+    fn sum<I: Iterator<Item = Duration>>(iter: I) -> Duration {
         sum_durations!(iter)
     }
 }
 
 #[stable(feature = "duration_sum", since = "1.16.0")]
 impl<'a> Sum<&'a Duration> for Duration {
-    fn sum<I: Iterator<Item=&'a Duration>>(iter: I) -> Duration {
+    fn sum<I: Iterator<Item = &'a Duration>>(iter: I) -> Duration {
         sum_durations!(iter)
     }
 }
@@ -922,9 +918,7 @@ fn fmt_decimal(
             } else {
                 // SAFETY: We are only writing ASCII digits into the buffer and it was
                 // initialized with '0's, so it contains valid UTF8.
-                let s = unsafe {
-                    crate::str::from_utf8_unchecked(&buf[..end])
-                };
+                let s = unsafe { crate::str::from_utf8_unchecked(&buf[..end]) };
 
                 // If the user request a precision > 9, we pad '0's at the end.
                 let w = f.precision().unwrap_or(pos);
index f05780f4a62700699830989ac597358062fcc9c9..9f8a3a1de420116d50f89d515f9930d8120ac44c 100644 (file)
@@ -1,7 +1,7 @@
 // See src/libstd/primitive_docs.rs for documentation.
 
-use crate::cmp::*;
 use crate::cmp::Ordering::*;
+use crate::cmp::*;
 
 // macro for implementing n-ary tuple functions and operations
 macro_rules! tuple_impls {
index 39584d346e4a8db5050dd6b90f8d8317868c8449..b7fba88a540f9012dbc01efd9b5758d86e30709d 100644 (file)
 /// non-BMP range of most Unicode sets.
 pub struct BoolTrie {
     // 0..0x800 (corresponding to 1 and 2 byte utf-8 sequences)
-    pub r1: [u64; 32],   // leaves
+    pub r1: [u64; 32], // leaves
 
     // 0x800..0x10000 (corresponding to 3 byte utf-8 sequences)
     pub r2: [u8; 992],      // first level
-    pub r3: &'static [u64],  // leaves
+    pub r3: &'static [u64], // leaves
 
     // 0x10000..0x110000 (corresponding to 4 byte utf-8 sequences)
-    pub r4: [u8; 256],       // first level
-    pub r5: &'static [u8],   // second level
-    pub r6: &'static [u64],  // leaves
+    pub r4: [u8; 256],      // first level
+    pub r5: &'static [u8],  // second level
+    pub r6: &'static [u64], // leaves
 }
 impl BoolTrie {
     pub fn lookup(&self, c: char) -> bool {
@@ -48,7 +48,7 @@ pub fn lookup(&self, c: char) -> bool {
 
 pub struct SmallBoolTrie {
     pub(crate) r1: &'static [u8],  // first level
-    pub(crate) r2: &'static [u64],  // leaves
+    pub(crate) r2: &'static [u64], // leaves
 }
 
 impl SmallBoolTrie {
index bf01ceb8b2d3e5bbb4dcd484e0c91a319236cc3a..f41f4a5e94a76ee5b585b9575636cfa4b7e66aab 100644 (file)
@@ -15,7 +15,7 @@
 /// ```
 #[stable(feature = "unit_from_iter", since = "1.23.0")]
 impl FromIterator<()> for () {
-    fn from_iter<I: IntoIterator<Item=()>>(iter: I) -> Self {
+    fn from_iter<I: IntoIterator<Item = ()>>(iter: I) -> Self {
         iter.into_iter().for_each(|()| {})
     }
 }
index f8f69936021f320ec7b8d201b4c088175d89fd05..b670658a10a50702fbd2ee351872dcc2d0ca5394 100644 (file)
@@ -463,7 +463,6 @@ fn check_and_note_conflicting_crates(
         &self,
         err: &mut DiagnosticBuilder<'_>,
         terr: &TypeError<'tcx>,
-        sp: Span,
     ) {
         use hir::def_id::CrateNum;
         use hir::map::DisambiguatedDefPathData;
@@ -577,14 +576,10 @@ fn path_generic_args(
                 };
                 if same_path().unwrap_or(false) {
                     let crate_name = self.tcx.crate_name(did1.krate);
-                    err.span_note(
-                        sp,
-                        &format!(
-                            "Perhaps two different versions \
-                             of crate `{}` are being used?",
-                            crate_name
-                        ),
-                    );
+                    err.note(&format!(
+                        "perhaps two different versions of crate `{}` are being used?",
+                        crate_name
+                    ));
                 }
             }
         };
@@ -1434,7 +1429,7 @@ pub fn note_type_err(
             .unwrap_or_else(|| {
                 self.tcx.hir().body_owner_def_id(hir::BodyId { hir_id: cause.body_id })
             });
-        self.check_and_note_conflicting_crates(diag, terr, span);
+        self.check_and_note_conflicting_crates(diag, terr);
         self.tcx.note_and_explain_type_err(diag, terr, span, body_owner_def_id);
 
         // It reads better to have the error origin as the final
index 52c72de7579e1e22f76ecb7c50355e2eba972986..f82af62c5f39d40845e17fc6f10d80c79c292b41 100644 (file)
@@ -458,7 +458,7 @@ fn from(ptr: Pointer<Tag>) -> Self {
     }
 }
 
-#[derive(Clone, Copy, Eq, PartialEq, RustcEncodable, RustcDecodable, HashStable)]
+#[derive(Clone, Copy, Eq, PartialEq, RustcEncodable, RustcDecodable, HashStable, Hash)]
 pub enum ScalarMaybeUndef<Tag = (), Id = AllocId> {
     Scalar(Scalar<Tag, Id>),
     Undef,
index bd793fd07bf22e00ad04a9ccf8016778f281bd09..4103d25fbd173f56847297aa97fbf8944f02543e 100644 (file)
@@ -141,14 +141,8 @@ pub struct Body<'tcx> {
     /// This is used for the "rust-call" ABI.
     pub spread_arg: Option<Local>,
 
-    /// Names and capture modes of all the closure upvars, assuming
-    /// the first argument is either the closure or a reference to it.
-    //
-    // NOTE(eddyb) This is *strictly* a temporary hack for codegen
-    // debuginfo generation, and will be removed at some point.
-    // Do **NOT** use it for anything else; upvar information should not be
-    // in the MIR, so please rely on local crate HIR or other side-channels.
-    pub __upvar_debuginfo_codegen_only_do_not_use: Vec<UpvarDebuginfo>,
+    /// Debug information pertaining to user variables, including captures.
+    pub var_debug_info: Vec<VarDebugInfo<'tcx>>,
 
     /// Mark this MIR of a const context other than const functions as having converted a `&&` or
     /// `||` expression into `&` or `|` respectively. This is problematic because if we ever stop
@@ -170,11 +164,10 @@ pub fn new(
         basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>,
         source_scopes: IndexVec<SourceScope, SourceScopeData>,
         source_scope_local_data: ClearCrossCrate<IndexVec<SourceScope, SourceScopeLocalData>>,
-        yield_ty: Option<Ty<'tcx>>,
         local_decls: LocalDecls<'tcx>,
         user_type_annotations: CanonicalUserTypeAnnotations<'tcx>,
         arg_count: usize,
-        __upvar_debuginfo_codegen_only_do_not_use: Vec<UpvarDebuginfo>,
+        var_debug_info: Vec<VarDebugInfo<'tcx>>,
         span: Span,
         control_flow_destroyed: Vec<(Span, String)>,
     ) -> Self {
@@ -191,14 +184,14 @@ pub fn new(
             basic_blocks,
             source_scopes,
             source_scope_local_data,
-            yield_ty,
+            yield_ty: None,
             generator_drop: None,
             generator_layout: None,
             local_decls,
             user_type_annotations,
             arg_count,
-            __upvar_debuginfo_codegen_only_do_not_use,
             spread_arg: None,
+            var_debug_info,
             span,
             cache: cache::Cache::new(),
             control_flow_destroyed,
@@ -280,7 +273,7 @@ pub fn local_kind(&self, local: Local) -> LocalKind {
             LocalKind::ReturnPointer
         } else if index < self.arg_count + 1 {
             LocalKind::Arg
-        } else if self.local_decls[local].name.is_some() {
+        } else if self.local_decls[local].is_user_variable() {
             LocalKind::Var
         } else {
             LocalKind::Temp
@@ -728,12 +721,6 @@ pub struct LocalDecl<'tcx> {
     // FIXME(matthewjasper) Don't store in this in `Body`
     pub user_ty: UserTypeProjections,
 
-    /// The name of the local, used in debuginfo and pretty-printing.
-    ///
-    /// Note that function arguments can also have this set to `Some(_)`
-    /// to generate better debuginfo.
-    pub name: Option<Name>,
-
     /// The *syntactic* (i.e., not visibility) source scope the local is defined
     /// in. If the local was defined in a let-statement, this
     /// is *within* the let-statement, rather than outside
@@ -785,9 +772,9 @@ pub struct LocalDecl<'tcx> {
     /// `drop(x)`, we want it to refer to `x: u32`.
     ///
     /// To allow both uses to work, we need to have more than a single scope
-    /// for a local. We have the `source_info.scope` represent the
-    /// "syntactic" lint scope (with a variable being under its let
-    /// block) while the `visibility_scope` represents the "local variable"
+    /// for a local. We have the `source_info.scope` represent the "syntactic"
+    /// lint scope (with a variable being under its let block) while the
+    /// `var_debug_info.source_info.scope` represents the "local variable"
     /// scope (where the "rest" of a block is under all prior let-statements).
     ///
     /// The end result looks like this:
@@ -806,18 +793,14 @@ pub struct LocalDecl<'tcx> {
     ///  │ │
     ///  │ │ │{ let y: u32 }
     ///  │ │ │
-    ///  │ │ │← y.visibility_scope
+    ///  │ │ │← y.var_debug_info.source_info.scope
     ///  │ │ │← `y + 2`
     ///  │
     ///  │ │{ let x: u32 }
-    ///  │ │← x.visibility_scope
+    ///  │ │← x.var_debug_info.source_info.scope
     ///  │ │← `drop(x)` // This accesses `x: u32`.
     /// ```
     pub source_info: SourceInfo,
-
-    /// Source scope within which the local is visible (for debuginfo)
-    /// (see `source_info` for more details).
-    pub visibility_scope: SourceScope,
 }
 
 /// Extra information about a local that's used for diagnostics.
@@ -955,9 +938,7 @@ fn new_local(ty: Ty<'tcx>, mutability: Mutability, internal: bool, span: Span) -
             mutability,
             ty,
             user_ty: UserTypeProjections::none(),
-            name: None,
             source_info: SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE },
-            visibility_scope: OUTERMOST_SOURCE_SCOPE,
             internal,
             local_info: LocalInfo::Other,
             is_block_tail: None,
@@ -974,22 +955,27 @@ pub fn new_return_place(return_ty: Ty<'_>, span: Span) -> LocalDecl<'_> {
             ty: return_ty,
             user_ty: UserTypeProjections::none(),
             source_info: SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE },
-            visibility_scope: OUTERMOST_SOURCE_SCOPE,
             internal: false,
             is_block_tail: None,
-            name: None, // FIXME maybe we do want some name here?
             local_info: LocalInfo::Other,
         }
     }
 }
 
-/// A closure capture, with its name and mode.
-#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)]
-pub struct UpvarDebuginfo {
-    pub debug_name: Name,
+/// Debug information pertaining to a user variable.
+#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable, TypeFoldable)]
+pub struct VarDebugInfo<'tcx> {
+    pub name: Name,
 
-    /// If true, the capture is behind a reference.
-    pub by_ref: bool,
+    /// Source info of the user variable, including the scope
+    /// within which the variable is visible (to debuginfo)
+    /// (see `LocalDecl`'s `source_info` field for more details).
+    pub source_info: SourceInfo,
+
+    /// Where the data for this user variable is to be found.
+    /// NOTE(eddyb) There's an unenforced invariant that this `Place` is
+    /// based on a `Local`, not a `Static`, and contains no indexing.
+    pub place: Place<'tcx>,
 }
 
 ///////////////////////////////////////////////////////////////////////////
@@ -2758,16 +2744,6 @@ pub struct GeneratorLayout<'tcx> {
     /// have conflicts with each other are allowed to overlap in the computed
     /// layout.
     pub storage_conflicts: BitMatrix<GeneratorSavedLocal, GeneratorSavedLocal>,
-
-    /// The names and scopes of all the stored generator locals.
-    ///
-    /// N.B., this is *strictly* a temporary hack for codegen
-    /// debuginfo generation, and will be removed at some point.
-    /// Do **NOT** use it for anything else, local information should not be
-    /// in the MIR, please rely on local crate HIR or other side-channels.
-    //
-    // FIXME(tmandry): see above.
-    pub __local_debuginfo_codegen_only_do_not_use: IndexVec<GeneratorSavedLocal, LocalDecl<'tcx>>,
 }
 
 #[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)]
@@ -2946,7 +2922,6 @@ pub enum ClosureOutlivesSubject<'tcx> {
     MirPhase,
     Mutability,
     SourceInfo,
-    UpvarDebuginfo,
     FakeReadCause,
     RetagKind,
     SourceScope,
index fc0e77aab43a4d9a38cebb573df5d6ba3475679c..464d4c74366e5e92166b8c381dd136d7ce2bf0b9 100644 (file)
@@ -221,6 +221,11 @@ fn visit_local_decl(&mut self,
                 self.super_local_decl(local, local_decl);
             }
 
+            fn visit_var_debug_info(&mut self,
+                                    var_debug_info: & $($mutability)* VarDebugInfo<'tcx>) {
+                self.super_var_debug_info(var_debug_info);
+            }
+
             fn visit_local(&mut self,
                             _local: & $($mutability)? Local,
                             _context: PlaceContext,
@@ -279,6 +284,10 @@ macro_rules! type_annotations {
                     );
                 }
 
+                for var_debug_info in &$($mutability)? body.var_debug_info {
+                    self.visit_var_debug_info(var_debug_info);
+                }
+
                 self.visit_span(&$($mutability)? body.span);
             }
 
@@ -687,9 +696,7 @@ fn super_local_decl(&mut self,
                     mutability: _,
                     ty,
                     user_ty,
-                    name: _,
                     source_info,
-                    visibility_scope,
                     internal: _,
                     local_info: _,
                     is_block_tail: _,
@@ -703,7 +710,23 @@ fn super_local_decl(&mut self,
                     self.visit_user_type_projection(user_ty);
                 }
                 self.visit_source_info(source_info);
-                self.visit_source_scope(visibility_scope);
+            }
+
+            fn super_var_debug_info(&mut self,
+                                    var_debug_info: & $($mutability)? VarDebugInfo<'tcx>) {
+                let VarDebugInfo {
+                    name: _,
+                    source_info,
+                    place,
+                } = var_debug_info;
+
+                self.visit_source_info(source_info);
+                let location = START_BLOCK.start_location();
+                self.visit_place(
+                    place,
+                    PlaceContext::NonUse(NonUseContext::VarDebugInfo),
+                    location,
+                );
             }
 
             fn super_source_scope(&mut self,
@@ -1029,6 +1052,8 @@ pub enum NonUseContext {
     StorageDead,
     /// User type annotation assertions for NLL.
     AscribeUserTy,
+    /// The data of an user variable, for debug info.
+    VarDebugInfo,
 }
 
 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
index 5d01025c5b508a6b7a3c4ab9d7297cebafb9d74b..6733250e1e8d89b875918e6c5a651e2c839651c6 100644 (file)
@@ -12,7 +12,7 @@
 use rustc_target::spec::{Target, TargetTriple};
 
 use syntax;
-use syntax::ast::{self, IntTy, UintTy};
+use syntax::ast;
 use syntax::source_map::{FileName, FilePathMapping};
 use syntax::edition::{Edition, EDITION_NAME_LIST, DEFAULT_EDITION};
 use syntax::symbol::{sym, Symbol};
@@ -36,8 +36,7 @@
 
 pub struct Config {
     pub target: Target,
-    pub isize_ty: IntTy,
-    pub usize_ty: UintTy,
+    pub ptr_width: u32,
 }
 
 #[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
@@ -1621,10 +1620,10 @@ pub fn build_target_config(opts: &Options, sp: &Handler) -> Config {
         FatalError.raise();
     });
 
-    let (isize_ty, usize_ty) = match &target.target_pointer_width[..] {
-        "16" => (ast::IntTy::I16, ast::UintTy::U16),
-        "32" => (ast::IntTy::I32, ast::UintTy::U32),
-        "64" => (ast::IntTy::I64, ast::UintTy::U64),
+    let ptr_width = match &target.target_pointer_width[..] {
+        "16" => 16,
+        "32" => 32,
+        "64" => 64,
         w => sp.fatal(&format!(
             "target specification was invalid: \
              unrecognized target-pointer-width {}",
@@ -1634,8 +1633,7 @@ pub fn build_target_config(opts: &Options, sp: &Handler) -> Config {
 
     Config {
         target,
-        isize_ty,
-        usize_ty,
+        ptr_width,
     }
 }
 
index f8efa0b9de204de2148a0c0e920450e4b70f75e4..65d08ab03aaaf699bd60872ff6d53a5ec4198609 100644 (file)
@@ -166,7 +166,7 @@ fn report_fulfillment_error(
         body_id: Option<hir::BodyId>,
         fallback_has_occurred: bool,
     ) {
-        debug!("report_fulfillment_errors({:?})", error);
+        debug!("report_fulfillment_error({:?})", error);
         match error.code {
             FulfillmentErrorCode::CodeSelectionError(ref selection_error) => {
                 self.report_selection_error(
index 3e52a6aa50850c12901e0f9b8c5cac6e418a5374..8581a5b220ac6ac6e7c82e31e8023696f0de7604 100644 (file)
@@ -7,7 +7,6 @@
 use std::time::{Duration, Instant};
 
 use syntax::symbol::{Symbol, sym};
-use rustc_macros::HashStable;
 use crate::session::Session;
 
 #[cfg(test)]
 // The name of the associated type for `Fn` return types.
 pub const FN_OUTPUT_NAME: Symbol = sym::Output;
 
-// Useful type to use with `Result<>` indicate that an error has already
-// been reported to the user, so no need to continue checking.
-#[derive(Clone, Copy, Debug, RustcEncodable, RustcDecodable, HashStable)]
-pub struct ErrorReported;
+pub use errors::ErrorReported;
 
 thread_local!(static TIME_DEPTH: Cell<usize> = Cell::new(0));
 
index 312c41b88b0924601c3620b121e5ebf648ed7a65..6f72466c559dc82484a318b71b087474fb51e233 100644 (file)
@@ -325,8 +325,8 @@ fn checked_binop(
         use rustc::ty::{Int, Uint};
 
         let new_kind = match ty.kind {
-            Int(Isize) => Int(self.tcx.sess.target.isize_ty),
-            Uint(Usize) => Uint(self.tcx.sess.target.usize_ty),
+            Int(t @ Isize) => Int(t.normalize(self.tcx.sess.target.ptr_width)),
+            Uint(t @ Usize) => Uint(t.normalize(self.tcx.sess.target.ptr_width)),
             ref t @ Uint(_) | ref t @ Int(_) => t.clone(),
             _ => panic!("tried to get overflow intrinsic for op applied to non-int type")
         };
index bcf0154e3f8796f318533b71604cc148cbb938c4..541b3d9476b3372657588df035fdf14025e00506 100644 (file)
@@ -233,11 +233,13 @@ impl CodegenCx<'ll, 'tcx> {
                     ref attrs, span, kind: hir::ItemKind::Static(..), ..
                 }) => {
                     let sym_str = sym.as_str();
-                    if self.get_declared_value(&sym_str).is_some() {
-                        span_bug!(span, "Conflicting symbol names for static?");
+                    if let Some(g) = self.get_declared_value(&sym_str) {
+                        if self.val_ty(g) != self.type_ptr_to(llty) {
+                            span_bug!(span, "Conflicting types for static");
+                        }
                     }
 
-                    let g = self.define_global(&sym_str, llty).unwrap();
+                    let g = self.declare_global(&sym_str, llty);
 
                     if !self.tcx.is_reachable_non_generic(def_id) {
                         unsafe {
index 6ee76b71fced68f3855833f6f6b352f058d3daa5..91d5a22b0228d4bcc184a1ba336b814683f2784d 100644 (file)
@@ -23,12 +23,10 @@ pub fn compute_mir_scopes(
 ) {
     // Find all the scopes with variables defined in them.
     let mut has_variables = BitSet::new_empty(mir.source_scopes.len());
-    // FIXME(eddyb) base this on `decl.name`, or even better, on debuginfo.
     // FIXME(eddyb) take into account that arguments always have debuginfo,
     // irrespective of their name (assuming full debuginfo is enabled).
-    for var in mir.vars_iter() {
-        let decl = &mir.local_decls[var];
-        has_variables.insert(decl.visibility_scope);
+    for var_debug_info in &mir.var_debug_info {
+        has_variables.insert(var_debug_info.source_info.scope);
     }
 
     // Instantiate all scopes.
index 2e16ae4c73f88283ee492ecfbe8ce65e40d9048b..1847e4e9fa951963091cc616ae2d98b1477e44ff 100644 (file)
 use crate::value::Value;
 
 use rustc_codegen_ssa::traits::*;
+use rustc_index::vec::{Idx, IndexVec};
 use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
 use rustc::hir::CodegenFnAttrFlags;
 use rustc::hir::def::CtorKind;
 use rustc::hir::def_id::{DefId, CrateNum, LOCAL_CRATE};
 use rustc::ich::NodeIdHashingMode;
-use rustc::mir::Field;
-use rustc::mir::GeneratorLayout;
+use rustc::mir::{self, Field, GeneratorLayout};
 use rustc::mir::interpret::truncate;
 use rustc_data_structures::fingerprint::Fingerprint;
 use rustc::ty::Instance;
@@ -1316,6 +1316,45 @@ fn use_enum_fallback(cx: &CodegenCx<'_, '_>) -> bool {
         || llvm_util::get_major_version() < 8;
 }
 
+// FIXME(eddyb) maybe precompute this? Right now it's computed once
+// per generator monomorphization, but it doesn't depend on substs.
+fn generator_layout_and_saved_local_names(
+    tcx: TyCtxt<'tcx>,
+    def_id: DefId,
+) -> (&'tcx GeneratorLayout<'tcx>, IndexVec<mir::GeneratorSavedLocal, Option<ast::Name>>) {
+    let body = tcx.optimized_mir(def_id);
+    let generator_layout = body.generator_layout.as_ref().unwrap();
+    let mut generator_saved_local_names =
+        IndexVec::from_elem(None, &generator_layout.field_tys);
+
+    let state_arg = mir::PlaceBase::Local(mir::Local::new(1));
+    for var in &body.var_debug_info {
+        if var.place.base != state_arg {
+            continue;
+        }
+        match var.place.projection[..] {
+            [
+                // Deref of the `Pin<&mut Self>` state argument.
+                mir::ProjectionElem::Field(..),
+                mir::ProjectionElem::Deref,
+
+                // Field of a variant of the state.
+                mir::ProjectionElem::Downcast(_, variant),
+                mir::ProjectionElem::Field(field, _),
+            ] => {
+                let name = &mut generator_saved_local_names[
+                    generator_layout.variant_fields[variant][field]
+                ];
+                if name.is_none() {
+                    name.replace(var.name);
+                }
+            }
+            _ => {}
+        }
+    }
+    (generator_layout, generator_saved_local_names)
+}
+
 /// Describes the members of an enum value; an enum is described as a union of
 /// structs in DWARF. This `MemberDescriptionFactory` provides the description for
 /// the members of this union; so for every variant of the given enum, this
@@ -1332,12 +1371,25 @@ struct EnumMemberDescriptionFactory<'ll, 'tcx> {
 impl EnumMemberDescriptionFactory<'ll, 'tcx> {
     fn create_member_descriptions(&self, cx: &CodegenCx<'ll, 'tcx>)
                                   -> Vec<MemberDescription<'ll>> {
+        let generator_variant_info_data = match self.enum_type.kind {
+            ty::Generator(def_id, ..) => {
+                Some(generator_layout_and_saved_local_names(cx.tcx, def_id))
+            }
+            _ => None,
+        };
+
         let variant_info_for = |index: VariantIdx| {
-            match &self.enum_type.kind {
+            match self.enum_type.kind {
                 ty::Adt(adt, _) => VariantInfo::Adt(&adt.variants[index]),
-                ty::Generator(def_id, substs, _) => {
-                    let generator_layout = cx.tcx.generator_layout(*def_id);
-                    VariantInfo::Generator(substs, generator_layout, index)
+                ty::Generator(_, substs, _) => {
+                    let (generator_layout, generator_saved_local_names) =
+                        generator_variant_info_data.as_ref().unwrap();
+                    VariantInfo::Generator {
+                        substs,
+                        generator_layout: *generator_layout,
+                        generator_saved_local_names,
+                        variant_index: index,
+                    }
                 }
                 _ => bug!(),
             }
@@ -1608,16 +1660,21 @@ enum EnumDiscriminantInfo<'ll> {
 }
 
 #[derive(Copy, Clone)]
-enum VariantInfo<'tcx> {
+enum VariantInfo<'a, 'tcx> {
     Adt(&'tcx ty::VariantDef),
-    Generator(SubstsRef<'tcx>, &'tcx GeneratorLayout<'tcx>, VariantIdx),
+    Generator {
+        substs: SubstsRef<'tcx>,
+        generator_layout: &'tcx GeneratorLayout<'tcx>,
+        generator_saved_local_names: &'a IndexVec<mir::GeneratorSavedLocal, Option<ast::Name>>,
+        variant_index: VariantIdx,
+    },
 }
 
-impl<'tcx> VariantInfo<'tcx> {
+impl<'tcx> VariantInfo<'_, 'tcx> {
     fn map_struct_name<R>(&self, f: impl FnOnce(&str) -> R) -> R {
         match self {
             VariantInfo::Adt(variant) => f(&variant.ident.as_str()),
-            VariantInfo::Generator(substs, _, variant_index) =>
+            VariantInfo::Generator { substs, variant_index, .. } =>
                 f(&substs.as_generator().variant_name(*variant_index)),
         }
     }
@@ -1625,7 +1682,7 @@ fn map_struct_name<R>(&self, f: impl FnOnce(&str) -> R) -> R {
     fn variant_name(&self) -> String {
         match self {
             VariantInfo::Adt(variant) => variant.ident.to_string(),
-            VariantInfo::Generator(_, _, variant_index) => {
+            VariantInfo::Generator { variant_index, .. } => {
                 // Since GDB currently prints out the raw discriminant along
                 // with every variant, make each variant name be just the value
                 // of the discriminant. The struct name for the variant includes
@@ -1636,17 +1693,20 @@ fn variant_name(&self) -> String {
     }
 
     fn field_name(&self, i: usize) -> String {
-        let field_name = match self {
+        let field_name = match *self {
             VariantInfo::Adt(variant) if variant.ctor_kind != CtorKind::Fn =>
-                Some(variant.fields[i].ident.to_string()),
-            VariantInfo::Generator(_, generator_layout, variant_index) => {
-                let field = generator_layout.variant_fields[*variant_index][i.into()];
-                let decl = &generator_layout.__local_debuginfo_codegen_only_do_not_use[field];
-                decl.name.map(|name| name.to_string())
-            }
+                Some(variant.fields[i].ident.name),
+            VariantInfo::Generator {
+                generator_layout,
+                generator_saved_local_names,
+                variant_index,
+                ..
+            } => generator_saved_local_names[
+                generator_layout.variant_fields[variant_index][i.into()]
+            ],
             _ => None,
         };
-        field_name.unwrap_or_else(|| format!("__{}", i))
+        field_name.map(|name| name.to_string()).unwrap_or_else(|| format!("__{}", i))
     }
 }
 
@@ -1657,7 +1717,7 @@ fn field_name(&self, i: usize) -> String {
 fn describe_enum_variant(
     cx: &CodegenCx<'ll, 'tcx>,
     layout: layout::TyLayout<'tcx>,
-    variant: VariantInfo<'tcx>,
+    variant: VariantInfo<'_, 'tcx>,
     discriminant_info: EnumDiscriminantInfo<'ll>,
     containing_scope: &'ll DIScope,
     span: Span,
index 12ec4e107487405bcae9deeb2732cc9ceba4882b..aa55f3a19e2be45edd4e0fcdad72dc2cb8466b2e 100644 (file)
@@ -1926,7 +1926,7 @@ macro_rules! arith {
 fn int_type_width_signed(ty: Ty<'_>, cx: &CodegenCx<'_, '_>) -> Option<(u64, bool)> {
     match ty.kind {
         ty::Int(t) => Some((match t {
-            ast::IntTy::Isize => cx.tcx.sess.target.isize_ty.bit_width().unwrap() as u64,
+            ast::IntTy::Isize => cx.tcx.sess.target.ptr_width as u64,
             ast::IntTy::I8 => 8,
             ast::IntTy::I16 => 16,
             ast::IntTy::I32 => 32,
@@ -1934,7 +1934,7 @@ fn int_type_width_signed(ty: Ty<'_>, cx: &CodegenCx<'_, '_>) -> Option<(u64, boo
             ast::IntTy::I128 => 128,
         }, true)),
         ty::Uint(t) => Some((match t {
-            ast::UintTy::Usize => cx.tcx.sess.target.usize_ty.bit_width().unwrap() as u64,
+            ast::UintTy::Usize => cx.tcx.sess.target.ptr_width as u64,
             ast::UintTy::U8 => 8,
             ast::UintTy::U16 => 16,
             ast::UintTy::U32 => 32,
index 2e5dc3db31af90c89ef94eecb8f408a655ecfbd4..e44551fcbcdfe3e3e8b02429b62dd85c731c5bf9 100644 (file)
@@ -5,7 +5,9 @@
 use rustc_data_structures::graph::dominators::Dominators;
 use rustc_index::vec::{Idx, IndexVec};
 use rustc::mir::{self, Location, TerminatorKind};
-use rustc::mir::visit::{Visitor, PlaceContext, MutatingUseContext, NonMutatingUseContext};
+use rustc::mir::visit::{
+    Visitor, PlaceContext, MutatingUseContext, NonMutatingUseContext, NonUseContext,
+};
 use rustc::mir::traversal;
 use rustc::session::config::DebugInfo;
 use rustc::ty;
@@ -27,7 +29,7 @@ pub fn non_ssa_locals<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
         // FIXME(eddyb): We should figure out how to use llvm.dbg.value instead
         // of putting everything in allocas just so we can use llvm.dbg.declare.
         if fx.cx.sess().opts.debuginfo == DebugInfo::Full {
-            if mir.local_kind(local) == mir::LocalKind::Arg || decl.name.is_some() {
+            if mir.local_kind(local) == mir::LocalKind::Arg {
                 analyzer.not_ssa(local);
                 continue;
             }
@@ -114,6 +116,12 @@ fn process_place(
         let cx = self.fx.cx;
 
         if let [proj_base @ .., elem] = place_ref.projection {
+            let mut base_context = if context.is_mutating_use() {
+                PlaceContext::MutatingUse(MutatingUseContext::Projection)
+            } else {
+                PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection)
+            };
+
             // Allow uses of projections that are ZSTs or from scalar fields.
             let is_consume = match context {
                 PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy) |
@@ -145,47 +153,81 @@ fn process_place(
                         // Recurse with the same context, instead of `Projection`,
                         // potentially stopping at non-operand projections,
                         // which would trigger `not_ssa` on locals.
-                        self.process_place(
-                            &mir::PlaceRef {
-                                base: place_ref.base,
-                                projection: proj_base,
-                            },
-                            context,
-                            location,
-                        );
-                        return;
+                        base_context = context;
                     }
                 }
             }
 
-            // A deref projection only reads the pointer, never needs the place.
             if let mir::ProjectionElem::Deref = elem {
-                self.process_place(
-                    &mir::PlaceRef {
-                        base: place_ref.base,
-                        projection: proj_base,
-                    },
+                // Deref projections typically only read the pointer.
+                // (the exception being `VarDebugInfo` contexts, handled below)
+                base_context = PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy);
+
+                // Indirect debuginfo requires going through memory, that only
+                // the debugger accesses, following our emitted DWARF pointer ops.
+                //
+                // FIXME(eddyb) Investigate the possibility of relaxing this, but
+                // note that `llvm.dbg.declare` *must* be used for indirect places,
+                // even if we start using `llvm.dbg.value` for all other cases,
+                // as we don't necessarily know when the value changes, but only
+                // where it lives in memory.
+                //
+                // It's possible `llvm.dbg.declare` could support starting from
+                // a pointer that doesn't point to an `alloca`, but this would
+                // only be useful if we know the pointer being `Deref`'d comes
+                // from an immutable place, and if `llvm.dbg.declare` calls
+                // must be at the very start of the function, then only function
+                // arguments could contain such pointers.
+                if context == PlaceContext::NonUse(NonUseContext::VarDebugInfo) {
+                    // We use `NonUseContext::VarDebugInfo` for the base,
+                    // which might not force the base local to memory,
+                    // so we have to do it manually.
+                    if let mir::PlaceBase::Local(local) = place_ref.base {
+                        self.visit_local(&local, context, location);
+                    }
+                }
+            }
+
+            // `NonUseContext::VarDebugInfo` needs to flow all the
+            // way down to the base local (see `visit_local`).
+            if context == PlaceContext::NonUse(NonUseContext::VarDebugInfo) {
+                base_context = context;
+            }
+
+            self.process_place(
+                &mir::PlaceRef {
+                    base: place_ref.base,
+                    projection: proj_base,
+                },
+                base_context,
+                location
+            );
+            // HACK(eddyb) this emulates the old `visit_projection_elem`, this
+            // entire `visit_place`-like `process_place` method should be rewritten,
+            // now that we have moved to the "slice of projections" representation.
+            if let mir::ProjectionElem::Index(local) = elem {
+                self.visit_local(
+                    local,
                     PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy),
                     location
                 );
-                return;
             }
-        }
+        } else {
+            // FIXME this is super_place code, is repeated here to avoid cloning place or changing
+            // visit_place API
+            let mut context = context;
 
-        // FIXME this is super_place code, is repeated here to avoid cloning place or changing
-        // visit_place API
-        let mut context = context;
+            if !place_ref.projection.is_empty() {
+                context = if context.is_mutating_use() {
+                    PlaceContext::MutatingUse(MutatingUseContext::Projection)
+                } else {
+                    PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection)
+                };
+            }
 
-        if !place_ref.projection.is_empty() {
-            context = if context.is_mutating_use() {
-                PlaceContext::MutatingUse(MutatingUseContext::Projection)
-            } else {
-                PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection)
-            };
+            self.visit_place_base(place_ref.base, context, location);
+            self.visit_projection(place_ref.base, place_ref.projection, context, location);
         }
-
-        self.visit_place_base(place_ref.base, context, location);
-        self.visit_projection(place_ref.base, place_ref.projection, context, location);
     }
 
 }
@@ -264,6 +306,15 @@ fn visit_local(&mut self,
                 self.assign(local, location);
             }
 
+            PlaceContext::NonUse(NonUseContext::VarDebugInfo) => {
+                // We need to keep locals in `alloca`s for debuginfo.
+                // FIXME(eddyb): We should figure out how to use `llvm.dbg.value` instead
+                // of putting everything in allocas just so we can use `llvm.dbg.declare`.
+                if self.fx.cx.sess().opts.debuginfo == DebugInfo::Full {
+                    self.not_ssa(local);
+                }
+            }
+
             PlaceContext::NonUse(_) |
             PlaceContext::MutatingUse(MutatingUseContext::Retag) => {}
 
index c215db34ccbc8bec54fec479088cf5d50451eb41..bb2679e214db47c1192f530b416d891d9c9d1da8 100644 (file)
@@ -1,12 +1,12 @@
-use rustc_index::vec::{Idx, IndexVec};
+use rustc_index::vec::IndexVec;
 use rustc::hir::def_id::CrateNum;
 use rustc::mir;
 use rustc::session::config::DebugInfo;
-use rustc::ty::{self, TyCtxt};
-use rustc::ty::layout::{LayoutOf, Size, VariantIdx};
+use rustc::ty::TyCtxt;
+use rustc::ty::layout::{LayoutOf, Size};
 use crate::traits::*;
 
-use syntax_pos::{BytePos, Span, Symbol};
+use syntax_pos::{BytePos, Span};
 use syntax::symbol::kw;
 
 use super::{FunctionCx, LocalRef};
@@ -113,7 +113,7 @@ pub fn debug_introduce_local(&self, bx: &mut Bx, local: mir::Local) {
             Some(per_local) => &per_local[local],
             None => return,
         };
-        let whole_local_var = vars.iter().find(|var| {
+        let whole_local_var = vars.iter().copied().find(|var| {
             var.place.projection.is_empty()
         });
         let has_proj = || vars.iter().any(|var| {
@@ -131,7 +131,7 @@ pub fn debug_introduce_local(&self, bx: &mut Bx, local: mir::Local) {
                 // be offset to account for the hidden environment?
                 None
             } else {
-                Some(VarDebugInfo {
+                Some(mir::VarDebugInfo {
                     name: kw::Invalid,
                     source_info: self.mir.local_decls[local].source_info,
                     place: local.into(),
@@ -185,7 +185,7 @@ pub fn debug_introduce_local(&self, bx: &mut Bx, local: mir::Local) {
             _ => return,
         };
 
-        let vars = vars.iter().chain(if whole_local_var.is_none() {
+        let vars = vars.iter().copied().chain(if whole_local_var.is_none() {
             fallback_var.as_ref()
         } else {
             None
@@ -253,133 +253,20 @@ pub fn debug_introduce_locals(&self, bx: &mut Bx) {
     }
 }
 
+/// Partition all `VarDebuginfo` in `body`, by their base `Local`.
 pub fn per_local_var_debug_info(
     tcx: TyCtxt<'tcx>,
-    body: &mir::Body<'tcx>,
-) -> Option<IndexVec<mir::Local, Vec<VarDebugInfo<'tcx>>>> {
+    body: &'a mir::Body<'tcx>,
+) -> Option<IndexVec<mir::Local, Vec<&'a mir::VarDebugInfo<'tcx>>>> {
     if tcx.sess.opts.debuginfo == DebugInfo::Full || !tcx.sess.fewer_names() {
         let mut per_local = IndexVec::from_elem(vec![], &body.local_decls);
-        for (local, decl) in body.local_decls.iter_enumerated() {
-            if let Some(name) = decl.name {
-                per_local[local].push(VarDebugInfo {
-                    name,
-                    source_info: mir::SourceInfo {
-                        span: decl.source_info.span,
-                        scope: decl.visibility_scope,
-                    },
-                    place: local.into(),
-                });
-            }
-        }
-
-        let upvar_debuginfo = &body.__upvar_debuginfo_codegen_only_do_not_use;
-        if !upvar_debuginfo.is_empty() {
-
-            let env_arg = mir::Local::new(1);
-            let mut env_projs = vec![];
-
-            let pin_did = tcx.lang_items().pin_type();
-            match body.local_decls[env_arg].ty.kind {
-                ty::RawPtr(_) |
-                ty::Ref(..)  => {
-                    env_projs.push(mir::ProjectionElem::Deref);
-                }
-                ty::Adt(def, substs) if Some(def.did) == pin_did => {
-                    if let ty::Ref(..) = substs.type_at(0).kind {
-                        env_projs.push(mir::ProjectionElem::Field(
-                            mir::Field::new(0),
-                            // HACK(eddyb) field types aren't used or needed here.
-                            tcx.types.err,
-                        ));
-                        env_projs.push(mir::ProjectionElem::Deref);
-                    }
-                }
-                _ => {}
-            }
-
-            let extra_locals = {
-                let upvars = upvar_debuginfo
-                    .iter()
-                    .enumerate()
-                    .map(|(i, upvar)| {
-                        let source_info = mir::SourceInfo {
-                            span: body.span,
-                            scope: mir::OUTERMOST_SOURCE_SCOPE,
-                        };
-                        (None, i, upvar.debug_name, upvar.by_ref, source_info)
-                    });
-
-                let generator_fields = body.generator_layout.as_ref().map(|generator_layout| {
-                    generator_layout.variant_fields.iter()
-                        .enumerate()
-                        .flat_map(move |(variant_idx, fields)| {
-                            let variant_idx = Some(VariantIdx::from(variant_idx));
-                            fields.iter()
-                                .enumerate()
-                                .filter_map(move |(i, field)| {
-                                    let decl = &generator_layout.
-                                        __local_debuginfo_codegen_only_do_not_use[*field];
-                                    if let Some(name) = decl.name {
-                                        let source_info = mir::SourceInfo {
-                                            span: decl.source_info.span,
-                                            scope: decl.visibility_scope,
-                                        };
-                                        Some((variant_idx, i, name, false, source_info))
-                                    } else {
-                                        None
-                                    }
-                            })
-                        })
-                }).into_iter().flatten();
-
-                upvars.chain(generator_fields)
-            };
-
-            for (variant_idx, field, name, by_ref, source_info) in extra_locals {
-                let mut projs = env_projs.clone();
-
-                if let Some(variant_idx) = variant_idx {
-                    projs.push(mir::ProjectionElem::Downcast(None, variant_idx));
-                }
-
-                projs.push(mir::ProjectionElem::Field(
-                    mir::Field::new(field),
-                    // HACK(eddyb) field types aren't used or needed here.
-                    tcx.types.err,
-                ));
-
-                if by_ref {
-                    projs.push(mir::ProjectionElem::Deref);
-                }
-
-                per_local[env_arg].push(VarDebugInfo {
-                    name,
-                    source_info,
-                    place: mir::Place {
-                        base: mir::PlaceBase::Local(env_arg),
-                        projection: tcx.intern_place_elems(&projs),
-                    },
-                });
+        for var in &body.var_debug_info {
+            if let mir::PlaceBase::Local(local) = var.place.base {
+                per_local[local].push(var);
             }
         }
-
         Some(per_local)
     } else {
         None
     }
 }
-
-/// Debug information relatating to an user variable.
-// FIXME(eddyb) move this to the MIR bodies themselves.
-#[derive(Clone)]
-pub struct VarDebugInfo<'tcx> {
-    pub name: Symbol,
-
-    /// Source info of the user variable, including the scope
-    /// within which the variable is visible (to debuginfo)
-    /// (see `LocalDecl`'s `source_info` field for more details).
-    pub source_info: mir::SourceInfo,
-
-    /// Where the data for this user variable is to be found.
-    pub place: mir::Place<'tcx>,
-}
index fec31f07a349b73c8a8f7bee06091de23b5a0922..6041232489d0d30dcf319a018ac13149741f0346 100644 (file)
@@ -74,7 +74,9 @@ pub struct FunctionCx<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {
     /// notably `expect`.
     locals: IndexVec<mir::Local, LocalRef<'tcx, Bx::Value>>,
 
-    per_local_var_debug_info: Option<IndexVec<mir::Local, Vec<debuginfo::VarDebugInfo<'tcx>>>>,
+    /// All `VarDebuginfo` from the MIR body, partitioned by `Local`.
+    /// This is `None` if no variable debuginfo/names are needed.
+    per_local_var_debug_info: Option<IndexVec<mir::Local, Vec<&'a mir::VarDebugInfo<'tcx>>>>,
 }
 
 impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
index 361cb425809d7a1f06d8b1ca00cd8cbe2b8c61c0..021a0219d13e2b60b8e79b49f3fb37132dc6789b 100644 (file)
@@ -1,4 +1,5 @@
-A constant item was initialized with something that is not a constant expression.
+A constant item was initialized with something that is not a constant
+expression.
 
 Erroneous code example:
 
index 0ebeb1bd78ed0af2a683f564b643511db32cb2bc..64fc027b885b632b4c06debbd9c4f2a2269759b1 100644 (file)
@@ -1,6 +1,6 @@
-This error indicates that during an attempt to build a struct or struct-like
-enum variant, one of the fields was specified more than once. Erroneous code
-example:
+A struct's or struct-like enum variant's field was specified more than once.
+
+Erroneous code example:
 
 ```compile_fail,E0062
 struct Foo {
@@ -15,7 +15,9 @@ fn main() {
 }
 ```
 
-Each field should be specified exactly one time. Example:
+This error indicates that during an attempt to build a struct or struct-like
+enum variant, one of the fields was specified more than once. Each field should
+be specified exactly one time. Example:
 
 ```
 struct Foo {
index 0d1f60437acf015228ead632d8a9f09504f05401..0e611deac426fa6d081957d1530ae8149a4c3cd1 100644 (file)
@@ -1,5 +1,6 @@
-This error indicates that during an attempt to build a struct or struct-like
-enum variant, one of the fields was not provided. Erroneous code example:
+A struct's or struct-like enum variant's field was not provided.
+
+Erroneous code example:
 
 ```compile_fail,E0063
 struct Foo {
index 101b96f7983f624854157cc842dfc4b8538c6cde..11041bb53ee5527c7d154401c79b36709ee94d1b 100644 (file)
@@ -1,33 +1,15 @@
-The left-hand side of a compound assignment expression must be a place
-expression. A place expression represents a memory location and includes
-item paths (ie, namespaced variables), dereferences, indexing expressions,
-and field references.
+An invalid left-hand side expression was used on an assignment operation.
 
-Let's start with some erroneous code examples:
+Erroneous code example:
 
 ```compile_fail,E0067
-use std::collections::LinkedList;
-
-// Bad: assignment to non-place expression
-LinkedList::new() += 1;
-
-// ...
-
-fn some_func(i: &mut i32) {
-    i += 12; // Error : '+=' operation cannot be applied on a reference !
-}
+12 += 1; // error!
 ```
 
-And now some working examples:
+You need to have a place expression to be able to assign it something. For
+example:
 
 ```
-let mut i : i32 = 0;
-
-i += 12; // Good !
-
-// ...
-
-fn some_func(i: &mut i32) {
-    *i += 12; // Good !
-}
+let mut x: i8 = 12;
+x += 1; // ok!
 ```
index ad3b1803b54dbb4b12dc6d31014c2078ca50e114..7367a5c0922ea9eae793ce6df00aa69de9519108 100644 (file)
@@ -1,5 +1,7 @@
 The compiler found a function whose body contains a `return;` statement but
-whose return type is not `()`. An example of this is:
+whose return type is not `()`.
+
+Erroneous code example:
 
 ```compile_fail,E0069
 // error
index 1a56080a09734338de12867d30c25d09e34948a0..97522af3da867573aea68c34f40112e3949e61db 100644 (file)
@@ -1,41 +1,43 @@
-The left-hand side of an assignment operator must be a place expression. A
-place expression represents a memory location and can be a variable (with
-optional namespacing), a dereference, an indexing expression or a field
-reference.
+An assignment operator was used on a non-place expression.
 
-More details can be found in the [Expressions] section of the Reference.
-
-[Expressions]: https://doc.rust-lang.org/reference/expressions.html#places-rvalues-and-temporaries
-
-Now, we can go further. Here are some erroneous code examples:
+Erroneous code examples:
 
 ```compile_fail,E0070
 struct SomeStruct {
     x: i32,
-    y: i32
+    y: i32,
 }
 
-const SOME_CONST : i32 = 12;
+const SOME_CONST: i32 = 12;
 
 fn some_other_func() {}
 
 fn some_function() {
-    SOME_CONST = 14; // error : a constant value cannot be changed!
-    1 = 3; // error : 1 isn't a valid place!
-    some_other_func() = 4; // error : we cannot assign value to a function!
-    SomeStruct.x = 12; // error : SomeStruct a structure name but it is used
-                       // like a variable!
+    SOME_CONST = 14; // error: a constant value cannot be changed!
+    1 = 3; // error: 1 isn't a valid place!
+    some_other_func() = 4; // error: we cannot assign value to a function!
+    SomeStruct::x = 12; // error: SomeStruct a structure name but it is used
+                        //        like a variable!
 }
 ```
 
+The left-hand side of an assignment operator must be a place expression. A
+place expression represents a memory location and can be a variable (with
+optional namespacing), a dereference, an indexing expression or a field
+reference.
+
+More details can be found in the [Expressions] section of the Reference.
+
+[Expressions]: https://doc.rust-lang.org/reference/expressions.html#places-rvalues-and-temporaries
+
 And now let's give working examples:
 
 ```
 struct SomeStruct {
     x: i32,
-    y: i32
+    y: i32,
 }
-let mut s = SomeStruct {x: 0, y: 0};
+let mut s = SomeStruct { x: 0, y: 0 };
 
 s.x = 3; // that's good !
 
index 768dd0c7a48c29624779a101ad6c99e136c98603..bc2c03a0220826f81558b003a18cbd71a891f04e 100644 (file)
@@ -1,5 +1,5 @@
-You tried to use structure-literal syntax to create an item that is
-not a structure or enum variant.
+A structure-literal syntax was used to create an item that is not a structure
+or enum variant.
 
 Example of erroneous code:
 
@@ -9,8 +9,8 @@ let t = U32 { value: 4 }; // error: expected struct, variant or union type,
                           // found builtin type `u32`
 ```
 
-To fix this, ensure that the name was correctly spelled, and that
-the correct form of initializer was used.
+To fix this, ensure that the name was correctly spelled, and that the correct
+form of initializer was used.
 
 For example, the code above can be fixed to:
 
index e461d45f30c858902dd327acaab0328777fae3ce..8f7749abab1e5be25c01e7632f74b2a9a41f4cfe 100644 (file)
@@ -1,20 +1,23 @@
-When defining a recursive struct or enum, any use of the type being defined
-from inside the definition must occur behind a pointer (like `Box` or `&`).
-This is because structs and enums must have a well-defined size, and without
-the pointer, the size of the type would need to be unbounded.
+A recursive type has infinite size because it doesn't have an indirection.
 
-Consider the following erroneous definition of a type for a list of bytes:
+Erroneous code example:
 
 ```compile_fail,E0072
-// error, invalid recursive struct type
 struct ListNode {
     head: u8,
-    tail: Option<ListNode>,
+    tail: Option<ListNode>, // error: no indirection here so impossible to
+                            //        compute the type's size
 }
 ```
 
-This type cannot have a well-defined size, because it needs to be arbitrarily
-large (since we would be able to nest `ListNode`s to any depth). Specifically,
+When defining a recursive struct or enum, any use of the type being defined
+from inside the definition must occur behind a pointer (like `Box`, `&` or
+`Rc`). This is because structs and enums must have a well-defined size, and
+without the pointer, the size of the type would need to be unbounded.
+
+In the example, the type cannot have a well-defined size, because it needs to be
+arbitrarily large (since we would be able to nest `ListNode`s to any depth).
+Specifically,
 
 ```plain
 size of `ListNode` = 1 byte for `head`
index f15af8150baaacd25875a4eb5fddfc4cdfcef606..969c1ee71313e8f7f132d33eab18a3e850e81f76 100644 (file)
@@ -1,21 +1,23 @@
-The `#[simd]` attribute can only be applied to non empty tuple structs, because
-it doesn't make sense to try to use SIMD operations when there are no values to
-operate on.
+A `#[simd]` attribute was applied to an empty tuple struct.
 
-This will cause an error:
+Erroneous code example:
 
 ```compile_fail,E0075
 #![feature(repr_simd)]
 
 #[repr(simd)]
-struct Bad;
+struct Bad; // error!
 ```
 
-This will not:
+The `#[simd]` attribute can only be applied to non empty tuple structs, because
+it doesn't make sense to try to use SIMD operations when there are no values to
+operate on.
+
+Fixed example:
 
 ```
 #![feature(repr_simd)]
 
 #[repr(simd)]
-struct Good(u32);
+struct Good(u32); // ok!
 ```
index 466e0a96e6b018a91b5b5cd8d7d52f883f27cc7b..f293a2a5772db90a5c62caac983445ee1750bd78 100644 (file)
@@ -1,21 +1,24 @@
-When using the `#[simd]` attribute to automatically use SIMD operations in tuple
-struct, the types in the struct must all be of the same type, or the compiler
-will trigger this error.
+All types in a tuple struct aren't the same when using the `#[simd]`
+attribute.
 
-This will cause an error:
+Erroneous code example:
 
 ```compile_fail,E0076
 #![feature(repr_simd)]
 
 #[repr(simd)]
-struct Bad(u16, u32, u32);
+struct Bad(u16, u32, u32); // error!
 ```
 
-This will not:
+When using the `#[simd]` attribute to automatically use SIMD operations in tuple
+struct, the types in the struct must all be of the same type, or the compiler
+will trigger this error.
+
+Fixed example:
 
 ```
 #![feature(repr_simd)]
 
 #[repr(simd)]
-struct Good(u32, u32, u32);
+struct Good(u32, u32, u32); // ok!
 ```
index 6ae35a6aa17fe504744433e3c09cca54e20efeca..b14513c6ccf1fea776b7ce66fbbea2d92d269c8d 100644 (file)
@@ -1,20 +1,23 @@
-When using the `#[simd]` attribute on a tuple struct, the elements in the tuple
-must be machine types so SIMD operations can be applied to them.
+A tuple struct's element isn't a machine type when using the `#[simd]`
+attribute.
 
-This will cause an error:
+Erroneous code example:
 
 ```compile_fail,E0077
 #![feature(repr_simd)]
 
 #[repr(simd)]
-struct Bad(String);
+struct Bad(String); // error!
 ```
 
-This will not:
+When using the `#[simd]` attribute on a tuple struct, the elements in the tuple
+must be machine types so SIMD operations can be applied to them.
+
+Fixed example:
 
 ```
 #![feature(repr_simd)]
 
 #[repr(simd)]
-struct Good(u32, u32, u32);
+struct Good(u32, u32, u32); // ok!
 ```
index 3a8acba061c81d5d2241373f07abeb04b863f1b6..bfe0d21f3129b227862af561c5f66dd025638c7b 100644 (file)
@@ -25,4 +25,3 @@ fn main() {
                     //        expected 0, found 1
 }
 ```
-
index 08db342428c23e3b0dbd3c7d3995dd83202a1f2d..397979e564105f51da7f12e5cde05e805ab6c0a9 100644 (file)
@@ -26,4 +26,3 @@ left and may require reallocation. This requires ownership of the string
 on the left. If something should be added to a string literal, move the
 literal to the heap by allocating it with `to_owned()` like in
 `"Your text".to_owned()`.
-
index 861a50bfd8c574c0dd29531640ec3e395a69d4b6..201107c05a02c32642db633cf4f107bdc29aab3a 100644 (file)
@@ -41,4 +41,3 @@ trait Foo {
 
 fn bar<T: Foo>(t: T) {} // ok!
 ```
-
index e6baeb8f69229221f8a497026c9fc5ef2e16570c..385079d403d59be277a285625120c7442b77ce0a 100644 (file)
@@ -10,4 +10,3 @@ Please specify a valid "kind" value, from one of the following:
 * static
 * dylib
 * framework
-
index a68da1188b5a7cb5a93508d9efdba7bc20aba03f..65cdf90036adeb044aaf7486539dbad5136e86f7 100644 (file)
@@ -21,4 +21,3 @@ The `#[unwind]` attribute should be used as follows:
 
 NB. The default behavior here is "allowed", but this is unspecified
 and likely to change in the future.
-
index 2382ce0d3ff2f5fa954492231c918295df6ab7e3..a39d2be4f8f86bc61bf797d87a5d3f7ae673b1f6 100644 (file)
@@ -5,4 +5,3 @@ Erroneous code example:
 ```compile_fail,E0635
 #![feature(nonexistent_rust_feature)] // error: unknown feature
 ```
-
index dabf9b6412309cc327b3835e17c993110f51f05a..57cf72db5568928dd43d4f5b5cc6e149dfd0c495 100644 (file)
@@ -7,4 +7,3 @@ Erroneous code example:
 #![feature(rust1)]
 #![feature(rust1)] // error: the feature `rust1` has already been declared
 ```
-
index e39bebce1fea6e0dcc8cfa5f448d494a9bc5b09c..e2110042c7e8dd99288aafd36c06643379e03d0f 100644 (file)
@@ -16,4 +16,4 @@ let a = &(String::from("Hello world!")) as *const _; // Ok
 let b = 0 as *const i32; // Ok
 
 let c: *const i32 = 0 as *const _; // Ok
-```
\ No newline at end of file
+```
index 61acb084a459fc921f13777fa3416dc668f5335a..7a653bd2264fd4eb07145aa27ad8cb018fb123f2 100644 (file)
@@ -27,4 +27,3 @@ closure call itself by capturing a `&Fn()` object or `fn()` pointer
 that refers to itself. That is permitting, since the closure would be
 invoking itself via a virtual call, and hence does not directly
 reference its own *type*.
-
index bee9219af7cf60c61546840168a4e551d0b074cb..d379b8a2384c675ece632d056a724438c3a5dc47 100644 (file)
@@ -1,4 +1,4 @@
- `async fn`s are not yet supported in traits in Rust.
+`async fn`s are not yet supported in traits in Rust.
 
 Erroneous code example:
 
@@ -10,7 +10,8 @@ trait T {
 }
 ```
 
-`async fn`s return an `impl Future`, making the following two examples equivalent:
+`async fn`s return an `impl Future`, making the following two examples
+equivalent:
 
 ```edition2018,ignore (example-of-desugaring-equivalence)
 async fn foo() -> User {
@@ -23,8 +24,8 @@ fn foo(&self) -> impl Future<Output = User> + '_ {
 ```
 
 But when it comes to supporting this in traits, there are [a few implementation
-issues][async-is-hard]. One of them is returning `impl Trait` in traits is not supported,
-as it would require [Generic Associated Types] to be supported:
+issues][async-is-hard]. One of them is returning `impl Trait` in traits is not
+supported, as it would require [Generic Associated Types] to be supported:
 
 ```edition2018,ignore (example-of-desugaring-equivalence)
 impl MyDatabase {
@@ -40,13 +41,14 @@ impl MyDatabase {
 }
 ```
 
-Until these issues are resolved, you can use the [`async-trait` crate], allowing you to use
-`async fn` in traits by desugaring to "boxed futures"
+Until these issues are resolved, you can use the [`async-trait` crate], allowing
+you to use `async fn` in traits by desugaring to "boxed futures"
 (`Pin<Box<dyn Future + Send + 'async>>`).
 
-Note that using these trait methods will result in a heap allocation per-function-call. This is not
-a significant cost for the vast majority of applications, but should be considered when deciding
-whether to use this functionality in the public API of a low-level function that is expected to be
+Note that using these trait methods will result in a heap allocation
+per-function-call. This is not a significant cost for the vast majority of
+applications, but should be considered when deciding whether to use this
+functionality in the public API of a low-level function that is expected to be
 called millions of times a second.
 
 You might be interested in visiting the [async book] for further information.
index 7c478a1e0c8b1d0cfb239dff72a970b6a8ffbe17..39bebdcd3750e1f324c8e822a7c8290cda61a72a 100644 (file)
@@ -11,7 +11,7 @@ fn temp_address() {
 
 To avoid the error, first bind the temporary to a named local variable.
 
-```ignore
+```ignore (not yet implemented)
 # #![feature(raw_ref_op)]
 fn temp_address() {
     let val = 2;
index 8a1799faaf8eea42c15696c1402e078003de3b74..ae5876848185bc89c8588563813450c3644724ac 100644 (file)
@@ -993,3 +993,10 @@ macro_rules! pluralize {
         if $x != 1 { "s" } else { "" }
     };
 }
+
+// Useful type to use with `Result<>` indicate that an error has already
+// been reported to the user, so no need to continue checking.
+#[derive(Clone, Copy, Debug, RustcEncodable, RustcDecodable, Hash, PartialEq, Eq)]
+pub struct ErrorReported;
+
+rustc_data_structures::impl_stable_hash_via_hash!(ErrorReported);
index 9a4e981081fcfcd309411795bc7370dfc324e101..34241b845be04882c8c9e1415831a4299eac3702 100644 (file)
@@ -252,12 +252,7 @@ fn lint_int_literal<'a, 'tcx>(
     t: ast::IntTy,
     v: u128,
 ) {
-    let int_type = if let ast::IntTy::Isize = t {
-        cx.sess().target.isize_ty
-    } else {
-        t
-    };
-
+    let int_type = t.normalize(cx.sess().target.ptr_width);
     let (_, max) = int_ty_range(int_type);
     let max = max as u128;
     let negative = type_limits.negated_expr_id == e.hir_id;
@@ -303,11 +298,7 @@ fn lint_uint_literal<'a, 'tcx>(
     lit: &hir::Lit,
     t: ast::UintTy,
 ) {
-    let uint_type = if let ast::UintTy::Usize = t {
-        cx.sess().target.usize_ty
-    } else {
-        t
-    };
+    let uint_type = t.normalize(cx.sess().target.ptr_width);
     let (min, max) = uint_ty_range(uint_type);
     let lit_val: u128 = match lit.node {
         // _v is u8, within range by definition
@@ -600,6 +591,23 @@ fn is_repr_nullable_ptr<'tcx>(
 }
 
 impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
+
+    /// Check if the type is array and emit an unsafe type lint.
+    fn check_for_array_ty(&mut self, sp: Span, ty: Ty<'tcx>) -> bool {
+        if let ty::Array(..) = ty.kind {
+            self.emit_ffi_unsafe_type_lint(
+                ty,
+                sp,
+                "passing raw arrays by value is not FFI-safe",
+                Some("consider passing a pointer to the array"),
+            );
+            true
+        } else {
+            false
+        }
+    }
+
+
     /// Checks if the given type is "ffi-safe" (has a stable, well-defined
     /// representation which can be exported to C code).
     fn check_type_for_ffi(&self,
@@ -834,7 +842,7 @@ fn check_type_for_ffi(&self,
             ty::RawPtr(ty::TypeAndMut { ty, .. }) |
             ty::Ref(_, ty, _) => self.check_type_for_ffi(cache, ty),
 
-            ty::Array(ty, _) => self.check_type_for_ffi(cache, ty),
+            ty::Array(inner_ty, _) => self.check_type_for_ffi(cache, inner_ty),
 
             ty::FnPtr(sig) => {
                 match sig.abi() {
@@ -946,7 +954,7 @@ fn visit_ty(&mut self, ty: Ty<'tcx>) -> bool {
         }
     }
 
-    fn check_type_for_ffi_and_report_errors(&mut self, sp: Span, ty: Ty<'tcx>) {
+    fn check_type_for_ffi_and_report_errors(&mut self, sp: Span, ty: Ty<'tcx>, is_static: bool) {
         // We have to check for opaque types before `normalize_erasing_regions`,
         // which will replace opaque types with their underlying concrete type.
         if self.check_for_opaque_ty(sp, ty) {
@@ -957,6 +965,13 @@ fn check_type_for_ffi_and_report_errors(&mut self, sp: Span, ty: Ty<'tcx>) {
         // it is only OK to use this function because extern fns cannot have
         // any generic types right now:
         let ty = self.cx.tcx.normalize_erasing_regions(ParamEnv::reveal_all(), ty);
+        // C doesn't really support passing arrays by value.
+        // The only way to pass an array by value is through a struct.
+        // So we first test that the top level isn't an array,
+        // and then recursively check the types inside.
+        if !is_static && self.check_for_array_ty(sp, ty) {
+            return;
+        }
 
         match self.check_type_for_ffi(&mut FxHashSet::default(), ty) {
             FfiResult::FfiSafe => {}
@@ -975,13 +990,13 @@ fn check_foreign_fn(&mut self, id: hir::HirId, decl: &hir::FnDecl) {
         let sig = self.cx.tcx.erase_late_bound_regions(&sig);
 
         for (input_ty, input_hir) in sig.inputs().iter().zip(&decl.inputs) {
-            self.check_type_for_ffi_and_report_errors(input_hir.span, input_ty);
+            self.check_type_for_ffi_and_report_errors(input_hir.span, input_ty, false);
         }
 
         if let hir::Return(ref ret_hir) = decl.output {
             let ret_ty = sig.output();
             if !ret_ty.is_unit() {
-                self.check_type_for_ffi_and_report_errors(ret_hir.span, ret_ty);
+                self.check_type_for_ffi_and_report_errors(ret_hir.span, ret_ty, false);
             }
         }
     }
@@ -989,7 +1004,7 @@ fn check_foreign_fn(&mut self, id: hir::HirId, decl: &hir::FnDecl) {
     fn check_foreign_static(&mut self, id: hir::HirId, span: Span) {
         let def_id = self.cx.tcx.hir().local_def_id(id);
         let ty = self.cx.tcx.type_of(def_id);
-        self.check_type_for_ffi_and_report_errors(span, ty);
+        self.check_type_for_ffi_and_report_errors(span, ty, true);
     }
 }
 
index a721e381b4e9971ef560a7e374d4daea9d29d73c..7b54b98cbc13ccf031e6df75871a29ca75ad2c87 100644 (file)
@@ -698,7 +698,9 @@ fn inject_allocator_crate(&mut self, krate: &ast::Crate) {
         let has_global_allocator = match &*global_allocator_spans(krate) {
             [span1, span2, ..] => {
                 self.sess.struct_span_err(*span2, "cannot define multiple global allocators")
-                         .span_note(*span1, "the previous global allocator is defined here").emit();
+                    .span_label(*span2, "cannot define a new global allocator")
+                    .span_label(*span1, "previous global allocator is defined here")
+                    .emit();
                 true
             }
             spans => !spans.is_empty()
index 7b0cf451ff918227d3ed5afcff12badd86907028..e6ccbf5c38bf3839cd1a07273b787929164d3885 100644 (file)
@@ -1,9 +1,9 @@
 // Decoding metadata from a single crate's metadata
 
 use crate::rmeta::*;
-use crate::rmeta::table::{FixedSizeEncoding, PerDefTable};
+use crate::rmeta::table::{FixedSizeEncoding, Table};
 
-use rustc_index::vec::IndexVec;
+use rustc_index::vec::{Idx, IndexVec};
 use rustc_data_structures::sync::{Lrc, Lock, Once, AtomicCell};
 use rustc::hir::map::{DefKey, DefPath, DefPathData, DefPathHash};
 use rustc::hir::map::definitions::DefPathTable;
@@ -32,7 +32,7 @@
 use std::num::NonZeroUsize;
 use std::u32;
 
-use rustc_serialize::{Decodable, Decoder, Encodable, SpecializedDecoder, opaque};
+use rustc_serialize::{Decodable, Decoder, SpecializedDecoder, opaque};
 use syntax::attr;
 use syntax::ast::{self, Ident};
 use syntax::source_map::{self, respan, Spanned};
@@ -217,7 +217,7 @@ fn tcx(self) -> Option<TyCtxt<'tcx>> {
     }
 }
 
-impl<'a, 'tcx, T: Encodable + Decodable> Lazy<T> {
+impl<'a, 'tcx, T: Decodable> Lazy<T> {
     fn decode<M: Metadata<'a, 'tcx>>(self, metadata: M) -> T {
         let mut dcx = metadata.decoder(self.position.get());
         dcx.lazy_state = LazyState::NodeStart(self.position);
@@ -225,7 +225,7 @@ fn decode<M: Metadata<'a, 'tcx>>(self, metadata: M) -> T {
     }
 }
 
-impl<'a: 'x, 'tcx: 'x, 'x, T: Encodable + Decodable> Lazy<[T]> {
+impl<'a: 'x, 'tcx: 'x, 'x, T: Decodable> Lazy<[T]> {
     fn decode<M: Metadata<'a, 'tcx>>(
         self,
         metadata: M,
@@ -324,13 +324,13 @@ fn map_encoded_cnum_to_current(&self, cnum: CrateNum) -> CrateNum {
     }
 }
 
-impl<'a, 'tcx, T: Encodable> SpecializedDecoder<Lazy<T>> for DecodeContext<'a, 'tcx> {
+impl<'a, 'tcx, T> SpecializedDecoder<Lazy<T>> for DecodeContext<'a, 'tcx> {
     fn specialized_decode(&mut self) -> Result<Lazy<T>, Self::Error> {
         self.read_lazy_with_meta(())
     }
 }
 
-impl<'a, 'tcx, T: Encodable> SpecializedDecoder<Lazy<[T]>> for DecodeContext<'a, 'tcx> {
+impl<'a, 'tcx, T> SpecializedDecoder<Lazy<[T]>> for DecodeContext<'a, 'tcx> {
     fn specialized_decode(&mut self) -> Result<Lazy<[T]>, Self::Error> {
         let len = self.read_usize()?;
         if len == 0 {
@@ -341,10 +341,10 @@ fn specialized_decode(&mut self) -> Result<Lazy<[T]>, Self::Error> {
     }
 }
 
-impl<'a, 'tcx, T> SpecializedDecoder<Lazy<PerDefTable<T>>> for DecodeContext<'a, 'tcx>
+impl<'a, 'tcx, I: Idx, T> SpecializedDecoder<Lazy<Table<I, T>>> for DecodeContext<'a, 'tcx>
     where Option<T>: FixedSizeEncoding,
 {
-    fn specialized_decode(&mut self) -> Result<Lazy<PerDefTable<T>>, Self::Error> {
+    fn specialized_decode(&mut self) -> Result<Lazy<Table<I, T>>, Self::Error> {
         let len = self.read_usize()?;
         self.read_lazy_with_meta(len)
     }
index 483915f654dddd59810e95b9a127d8d78133e05e..8074bde61237d546853fb24f021b4dccee115d5e 100644 (file)
@@ -1,5 +1,5 @@
 use crate::rmeta::*;
-use crate::rmeta::table::{FixedSizeEncoding, PerDefTable};
+use crate::rmeta::table::FixedSizeEncoding;
 
 use rustc::middle::cstore::{LinkagePreference, NativeLibrary,
                             EncodedMetadata, ForeignModule};
@@ -8,7 +8,7 @@
 use rustc::hir::{GenericParamKind, AnonConst};
 use rustc::hir::map::definitions::DefPathTable;
 use rustc_data_structures::fingerprint::Fingerprint;
-use rustc_index::vec::IndexVec;
+use rustc_index::vec::Idx;
 use rustc::middle::dependency_format::Linkage;
 use rustc::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel,
                                       metadata_symbol_name};
@@ -47,7 +47,7 @@ struct EncodeContext<'tcx> {
     opaque: opaque::Encoder,
     tcx: TyCtxt<'tcx>,
 
-    per_def: PerDefTables<'tcx>,
+    per_def: PerDefTableBuilders<'tcx>,
 
     lazy_state: LazyState,
     type_shorthands: FxHashMap<Ty<'tcx>, usize>,
@@ -60,30 +60,6 @@ struct EncodeContext<'tcx> {
     source_file_cache: Lrc<SourceFile>,
 }
 
-#[derive(Default)]
-struct PerDefTables<'tcx> {
-    kind: PerDefTable<Lazy<EntryKind<'tcx>>>,
-    visibility: PerDefTable<Lazy<ty::Visibility>>,
-    span: PerDefTable<Lazy<Span>>,
-    attributes: PerDefTable<Lazy<[ast::Attribute]>>,
-    children: PerDefTable<Lazy<[DefIndex]>>,
-    stability: PerDefTable<Lazy<attr::Stability>>,
-    deprecation: PerDefTable<Lazy<attr::Deprecation>>,
-
-    ty: PerDefTable<Lazy<Ty<'tcx>>>,
-    fn_sig: PerDefTable<Lazy<ty::PolyFnSig<'tcx>>>,
-    impl_trait_ref: PerDefTable<Lazy<ty::TraitRef<'tcx>>>,
-    inherent_impls: PerDefTable<Lazy<[DefIndex]>>,
-    variances: PerDefTable<Lazy<[ty::Variance]>>,
-    generics: PerDefTable<Lazy<ty::Generics>>,
-    explicit_predicates: PerDefTable<Lazy<ty::GenericPredicates<'tcx>>>,
-    inferred_outlives: PerDefTable<Lazy<&'tcx [(ty::Predicate<'tcx>, Span)]>>,
-    super_predicates: PerDefTable<Lazy<ty::GenericPredicates<'tcx>>>,
-
-    mir: PerDefTable<Lazy<mir::Body<'tcx>>>,
-    promoted_mir: PerDefTable<Lazy<IndexVec<mir::Promoted, mir::Body<'tcx>>>>,
-}
-
 macro_rules! encoder_methods {
     ($($name:ident($ty:ty);)*) => {
         $(fn $name(&mut self, value: $ty) -> Result<(), Self::Error> {
@@ -122,13 +98,13 @@ fn emit_unit(&mut self) -> Result<(), Self::Error> {
     }
 }
 
-impl<'tcx, T: Encodable> SpecializedEncoder<Lazy<T>> for EncodeContext<'tcx> {
+impl<'tcx, T> SpecializedEncoder<Lazy<T>> for EncodeContext<'tcx> {
     fn specialized_encode(&mut self, lazy: &Lazy<T>) -> Result<(), Self::Error> {
         self.emit_lazy_distance(*lazy)
     }
 }
 
-impl<'tcx, T: Encodable> SpecializedEncoder<Lazy<[T]>> for EncodeContext<'tcx> {
+impl<'tcx, T> SpecializedEncoder<Lazy<[T]>> for EncodeContext<'tcx> {
     fn specialized_encode(&mut self, lazy: &Lazy<[T]>) -> Result<(), Self::Error> {
         self.emit_usize(lazy.meta)?;
         if lazy.meta == 0 {
@@ -138,10 +114,10 @@ fn specialized_encode(&mut self, lazy: &Lazy<[T]>) -> Result<(), Self::Error> {
     }
 }
 
-impl<'tcx, T> SpecializedEncoder<Lazy<PerDefTable<T>>> for EncodeContext<'tcx>
+impl<'tcx, I: Idx, T> SpecializedEncoder<Lazy<Table<I, T>>> for EncodeContext<'tcx>
     where Option<T>: FixedSizeEncoding,
 {
-    fn specialized_encode(&mut self, lazy: &Lazy<PerDefTable<T>>) -> Result<(), Self::Error> {
+    fn specialized_encode(&mut self, lazy: &Lazy<Table<I, T>>) -> Result<(), Self::Error> {
         self.emit_usize(lazy.meta)?;
         self.emit_lazy_distance(*lazy)
     }
@@ -307,14 +283,14 @@ fn encode_contents_for_lazy(self, ecx: &mut EncodeContext<'tcx>) -> usize {
     }
 }
 
-// Shorthand for `$self.$tables.$table.set($key, $self.lazy($value))`, which would
+// Shorthand for `$self.$tables.$table.set($def_id.index, $self.lazy($value))`, which would
 // normally need extra variables to avoid errors about multiple mutable borrows.
 macro_rules! record {
-    ($self:ident.$tables:ident.$table:ident[$key:expr] <- $value:expr) => {{
+    ($self:ident.$tables:ident.$table:ident[$def_id:expr] <- $value:expr) => {{
         {
             let value = $value;
             let lazy = $self.lazy(value);
-            $self.$tables.$table.set($key, lazy);
+            $self.$tables.$table.set($def_id.index, lazy);
         }
     }}
 }
@@ -509,28 +485,7 @@ fn encode_crate_root(&mut self) -> Lazy<CrateRoot<'tcx>> {
 
 
         i = self.position();
-        let per_def = LazyPerDefTables {
-            kind: self.per_def.kind.encode(&mut self.opaque),
-            visibility: self.per_def.visibility.encode(&mut self.opaque),
-            span: self.per_def.span.encode(&mut self.opaque),
-            attributes: self.per_def.attributes.encode(&mut self.opaque),
-            children: self.per_def.children.encode(&mut self.opaque),
-            stability: self.per_def.stability.encode(&mut self.opaque),
-            deprecation: self.per_def.deprecation.encode(&mut self.opaque),
-
-            ty: self.per_def.ty.encode(&mut self.opaque),
-            fn_sig: self.per_def.fn_sig.encode(&mut self.opaque),
-            impl_trait_ref: self.per_def.impl_trait_ref.encode(&mut self.opaque),
-            inherent_impls: self.per_def.inherent_impls.encode(&mut self.opaque),
-            variances: self.per_def.variances.encode(&mut self.opaque),
-            generics: self.per_def.generics.encode(&mut self.opaque),
-            explicit_predicates: self.per_def.explicit_predicates.encode(&mut self.opaque),
-            inferred_outlives: self.per_def.inferred_outlives.encode(&mut self.opaque),
-            super_predicates: self.per_def.super_predicates.encode(&mut self.opaque),
-
-            mir: self.per_def.mir.encode(&mut self.opaque),
-            promoted_mir: self.per_def.promoted_mir.encode(&mut self.opaque),
-        };
+        let per_def = self.per_def.encode(&mut self.opaque);
         let per_def_bytes = self.position() - i;
 
         // Encode the proc macro data
index 23c0204ee256bd138d5bc58f4e63907f674afae0..1bca2836a3a07c22cd7eb7be5ff5caf5f6a25cc2 100644 (file)
@@ -1,5 +1,5 @@
 use decoder::Metadata;
-use table::PerDefTable;
+use table::{Table, TableBuilder};
 
 use rustc::hir;
 use rustc::hir::def::{self, CtorKind};
@@ -15,7 +15,7 @@
 use rustc_index::vec::IndexVec;
 use rustc_data_structures::svh::Svh;
 use rustc_data_structures::sync::MetadataRef;
-use rustc_serialize::Encodable;
+use rustc_serialize::opaque::Encoder;
 use syntax::{ast, attr};
 use syntax::edition::Edition;
 use syntax::symbol::Symbol;
@@ -59,7 +59,7 @@ trait LazyMeta {
     fn min_size(meta: Self::Meta) -> usize;
 }
 
-impl<T: Encodable> LazyMeta for T {
+impl<T> LazyMeta for T {
     type Meta = ();
 
     fn min_size(_: ()) -> usize {
@@ -68,7 +68,7 @@ fn min_size(_: ()) -> usize {
     }
 }
 
-impl<T: Encodable> LazyMeta for [T] {
+impl<T> LazyMeta for [T] {
     type Meta = usize;
 
     fn min_size(len: usize) -> usize {
@@ -124,13 +124,13 @@ fn from_position_and_meta(position: NonZeroUsize, meta: T::Meta) -> Lazy<T> {
     }
 }
 
-impl<T: Encodable> Lazy<T> {
+impl<T> Lazy<T> {
     fn from_position(position: NonZeroUsize) -> Lazy<T> {
         Lazy::from_position_and_meta(position, ())
     }
 }
 
-impl<T: Encodable> Lazy<[T]> {
+impl<T> Lazy<[T]> {
     fn empty() -> Lazy<[T]> {
         Lazy::from_position_and_meta(NonZeroUsize::new(1).unwrap(), 0)
     }
@@ -166,8 +166,7 @@ enum LazyState {
 // manually, instead of relying on the default, to get the correct variance.
 // Only needed when `T` itself contains a parameter (e.g. `'tcx`).
 macro_rules! Lazy {
-    (Table<$T:ty>) => {Lazy<Table<$T>, usize>};
-    (PerDefTable<$T:ty>) => {Lazy<PerDefTable<$T>, usize>};
+    (Table<$I:ty, $T:ty>) => {Lazy<Table<$I, $T>, usize>};
     ([$T:ty]) => {Lazy<[$T], usize>};
     ($T:ty) => {Lazy<$T, ()>};
 }
@@ -232,31 +231,53 @@ macro_rules! Lazy {
     impls: Lazy<[DefIndex]>,
 }
 
-#[derive(RustcEncodable, RustcDecodable)]
-crate struct LazyPerDefTables<'tcx> {
-    kind: Lazy!(PerDefTable<Lazy!(EntryKind<'tcx>)>),
-    visibility: Lazy!(PerDefTable<Lazy<ty::Visibility>>),
-    span: Lazy!(PerDefTable<Lazy<Span>>),
-    attributes: Lazy!(PerDefTable<Lazy<[ast::Attribute]>>),
-    children: Lazy!(PerDefTable<Lazy<[DefIndex]>>),
-    stability: Lazy!(PerDefTable<Lazy<attr::Stability>>),
-    deprecation: Lazy!(PerDefTable<Lazy<attr::Deprecation>>),
-    ty: Lazy!(PerDefTable<Lazy!(Ty<'tcx>)>),
-    fn_sig: Lazy!(PerDefTable<Lazy!(ty::PolyFnSig<'tcx>)>),
-    impl_trait_ref: Lazy!(PerDefTable<Lazy!(ty::TraitRef<'tcx>)>),
-    inherent_impls: Lazy!(PerDefTable<Lazy<[DefIndex]>>),
-    variances: Lazy!(PerDefTable<Lazy<[ty::Variance]>>),
-    generics: Lazy!(PerDefTable<Lazy<ty::Generics>>),
-    explicit_predicates: Lazy!(PerDefTable<Lazy!(ty::GenericPredicates<'tcx>)>),
+/// Define `LazyPerDefTables` and `PerDefTableBuilders` at the same time.
+macro_rules! define_per_def_tables {
+    ($($name:ident: Table<DefIndex, $T:ty>),+ $(,)?) => {
+        #[derive(RustcEncodable, RustcDecodable)]
+        crate struct LazyPerDefTables<'tcx> {
+            $($name: Lazy!(Table<DefIndex, $T>)),+
+        }
+
+        #[derive(Default)]
+        struct PerDefTableBuilders<'tcx> {
+            $($name: TableBuilder<DefIndex, $T>),+
+        }
+
+        impl PerDefTableBuilders<'tcx> {
+            fn encode(&self, buf: &mut Encoder) -> LazyPerDefTables<'tcx> {
+                LazyPerDefTables {
+                    $($name: self.$name.encode(buf)),+
+                }
+            }
+        }
+    }
+}
+
+define_per_def_tables! {
+    kind: Table<DefIndex, Lazy!(EntryKind<'tcx>)>,
+    visibility: Table<DefIndex, Lazy<ty::Visibility>>,
+    span: Table<DefIndex, Lazy<Span>>,
+    attributes: Table<DefIndex, Lazy<[ast::Attribute]>>,
+    children: Table<DefIndex, Lazy<[DefIndex]>>,
+    stability: Table<DefIndex, Lazy<attr::Stability>>,
+    deprecation: Table<DefIndex, Lazy<attr::Deprecation>>,
+    ty: Table<DefIndex, Lazy!(Ty<'tcx>)>,
+    fn_sig: Table<DefIndex, Lazy!(ty::PolyFnSig<'tcx>)>,
+    impl_trait_ref: Table<DefIndex, Lazy!(ty::TraitRef<'tcx>)>,
+    inherent_impls: Table<DefIndex, Lazy<[DefIndex]>>,
+    variances: Table<DefIndex, Lazy<[ty::Variance]>>,
+    generics: Table<DefIndex, Lazy<ty::Generics>>,
+    explicit_predicates: Table<DefIndex, Lazy!(ty::GenericPredicates<'tcx>)>,
     // FIXME(eddyb) this would ideally be `Lazy<[...]>` but `ty::Predicate`
     // doesn't handle shorthands in its own (de)serialization impls,
     // as it's an `enum` for which we want to derive (de)serialization,
     // so the `ty::codec` APIs handle the whole `&'tcx [...]` at once.
     // Also, as an optimization, a missing entry indicates an empty `&[]`.
-    inferred_outlives: Lazy!(PerDefTable<Lazy!(&'tcx [(ty::Predicate<'tcx>, Span)])>),
-    super_predicates: Lazy!(PerDefTable<Lazy!(ty::GenericPredicates<'tcx>)>),
-    mir: Lazy!(PerDefTable<Lazy!(mir::Body<'tcx>)>),
-    promoted_mir: Lazy!(PerDefTable<Lazy!(IndexVec<mir::Promoted, mir::Body<'tcx>>)>),
+    inferred_outlives: Table<DefIndex, Lazy!(&'tcx [(ty::Predicate<'tcx>, Span)])>,
+    super_predicates: Table<DefIndex, Lazy!(ty::GenericPredicates<'tcx>)>,
+    mir: Table<DefIndex, Lazy!(mir::Body<'tcx>)>,
+    promoted_mir: Table<DefIndex, Lazy!(IndexVec<mir::Promoted, mir::Body<'tcx>>)>,
 }
 
 #[derive(Copy, Clone, RustcEncodable, RustcDecodable)]
index 613d92c6d7b0b9c34aa4dc995bf9f5d0e19eacc8..10122fbba1fd47f79f5b7ac56cc28d910c9603cb 100644 (file)
@@ -1,6 +1,6 @@
 use crate::rmeta::*;
 
-use rustc::hir::def_id::{DefId, DefIndex};
+use rustc_index::vec::Idx;
 use rustc_serialize::{Encodable, opaque::Encoder};
 use std::convert::TryInto;
 use std::marker::PhantomData;
@@ -117,37 +117,46 @@ fn write_to_bytes(self, b: &mut [u8]) {
     }
 }
 
-/// Random-access table (i.e. offeringconstant-time `get`/`set`), similar to
+/// Random-access table (i.e. offering constant-time `get`/`set`), similar to
 /// `Vec<Option<T>>`, but without requiring encoding or decoding all the values
 /// eagerly and in-order.
 /// A total of `(max_idx + 1) * <Option<T> as FixedSizeEncoding>::BYTE_LEN` bytes
-/// are used for a table, where `max_idx` is the largest index passed to `set`.
-// FIXME(eddyb) replace `Vec` with `[_]` here, such that `Box<Table<T>>` would be used
-// when building it, and `Lazy<Table<T>>` or `&Table<T>` when reading it.
-// (not sure if that is possible given that the `Vec` is being resized now)
-pub(super) struct Table<T> where Option<T>: FixedSizeEncoding {
-    // FIXME(eddyb) store `[u8; <Option<T>>::BYTE_LEN]` instead of `u8` in `Vec`,
-    // once that starts being allowed by the compiler (i.e. lazy normalization).
+/// are used for a table, where `max_idx` is the largest index passed to
+/// `TableBuilder::set`.
+pub(super) struct Table<I: Idx, T> where Option<T>: FixedSizeEncoding {
+    _marker: PhantomData<(fn(&I), T)>,
+    // NOTE(eddyb) this makes `Table` not implement `Sized`, but no
+    // value of `Table` is ever created (it's always behind `Lazy`).
+    _bytes: [u8],
+}
+
+/// Helper for constructing a table's serialization (also see `Table`).
+pub(super) struct TableBuilder<I: Idx, T> where Option<T>: FixedSizeEncoding {
+    // FIXME(eddyb) use `IndexVec<I, [u8; <Option<T>>::BYTE_LEN]>` instead of
+    // `Vec<u8>`, once that starts working (i.e. lazy normalization).
+    // Then again, that has the downside of not allowing `TableBuilder::encode` to
+    // obtain a `&[u8]` entirely in safe code, for writing the bytes out.
     bytes: Vec<u8>,
-    _marker: PhantomData<T>,
+    _marker: PhantomData<(fn(&I), T)>,
 }
 
-impl<T> Default for Table<T> where Option<T>: FixedSizeEncoding {
+impl<I: Idx, T> Default for TableBuilder<I, T> where Option<T>: FixedSizeEncoding {
     fn default() -> Self {
-        Table {
+        TableBuilder {
             bytes: vec![],
             _marker: PhantomData,
         }
     }
 }
 
-impl<T> Table<T> where Option<T>: FixedSizeEncoding {
-    fn set(&mut self, i: usize, value: T) {
+impl<I: Idx, T> TableBuilder<I, T> where Option<T>: FixedSizeEncoding {
+    pub(super) fn set(&mut self, i: I, value: T) {
         // FIXME(eddyb) investigate more compact encodings for sparse tables.
         // On the PR @michaelwoerister mentioned:
         // > Space requirements could perhaps be optimized by using the HAMT `popcnt`
         // > trick (i.e. divide things into buckets of 32 or 64 items and then
         // > store bit-masks of which item in each bucket is actually serialized).
+        let i = i.index();
         let needed = (i + 1) * <Option<T>>::BYTE_LEN;
         if self.bytes.len() < needed {
             self.bytes.resize(needed, 0);
@@ -156,7 +165,7 @@ fn set(&mut self, i: usize, value: T) {
         Some(value).write_to_bytes_at(&mut self.bytes, i);
     }
 
-    fn encode(&self, buf: &mut Encoder) -> Lazy<Self> {
+    pub(super) fn encode(&self, buf: &mut Encoder) -> Lazy<Table<I, T>> {
         let pos = buf.position();
         buf.emit_raw_bytes(&self.bytes);
         Lazy::from_position_and_meta(
@@ -166,7 +175,7 @@ fn encode(&self, buf: &mut Encoder) -> Lazy<Self> {
     }
 }
 
-impl<T> LazyMeta for Table<T> where Option<T>: FixedSizeEncoding {
+impl<I: Idx, T> LazyMeta for Table<I, T> where Option<T>: FixedSizeEncoding {
     type Meta = usize;
 
     fn min_size(len: usize) -> usize {
@@ -174,65 +183,18 @@ fn min_size(len: usize) -> usize {
     }
 }
 
-impl<T> Lazy<Table<T>> where Option<T>: FixedSizeEncoding {
+impl<I: Idx, T> Lazy<Table<I, T>> where Option<T>: FixedSizeEncoding {
     /// Given the metadata, extract out the value at a particular index (if any).
     #[inline(never)]
-    fn get<'a, 'tcx, M: Metadata<'a, 'tcx>>(
+    pub(super) fn get<'a, 'tcx, M: Metadata<'a, 'tcx>>(
         &self,
         metadata: M,
-        i: usize,
+        i: I,
     ) -> Option<T> {
         debug!("Table::lookup: index={:?} len={:?}", i, self.meta);
 
         let start = self.position.get();
         let bytes = &metadata.raw_bytes()[start..start + self.meta];
-        <Option<T>>::maybe_read_from_bytes_at(bytes, i)?
-    }
-}
-
-/// Like a `Table` but using `DefIndex` instead of `usize` as keys.
-// FIXME(eddyb) replace by making `Table` behave like `IndexVec`,
-// and by using `newtype_index!` to define `DefIndex`.
-pub(super) struct PerDefTable<T>(Table<T>) where Option<T>: FixedSizeEncoding;
-
-impl<T> Default for PerDefTable<T> where Option<T>: FixedSizeEncoding {
-    fn default() -> Self {
-        PerDefTable(Table::default())
-    }
-}
-
-impl<T> PerDefTable<T> where Option<T>: FixedSizeEncoding {
-    pub(super) fn set(&mut self, def_id: DefId, value: T) {
-        assert!(def_id.is_local());
-        self.0.set(def_id.index.index(), value);
-    }
-
-    pub(super) fn encode(&self, buf: &mut Encoder) -> Lazy<Self> {
-        let lazy = self.0.encode(buf);
-        Lazy::from_position_and_meta(lazy.position, lazy.meta)
-    }
-}
-
-impl<T> LazyMeta for PerDefTable<T> where Option<T>: FixedSizeEncoding {
-    type Meta = <Table<T> as LazyMeta>::Meta;
-
-    fn min_size(meta: Self::Meta) -> usize {
-        Table::<T>::min_size(meta)
-    }
-}
-
-impl<T> Lazy<PerDefTable<T>> where Option<T>: FixedSizeEncoding {
-    fn as_table(&self) -> Lazy<Table<T>> {
-        Lazy::from_position_and_meta(self.position, self.meta)
-    }
-
-    /// Given the metadata, extract out the value at a particular DefIndex (if any).
-    #[inline(never)]
-    pub(super) fn get<'a, 'tcx, M: Metadata<'a, 'tcx>>(
-        &self,
-        metadata: M,
-        def_index: DefIndex,
-    ) -> Option<T> {
-        self.as_table().get(metadata, def_index.index())
+        <Option<T>>::maybe_read_from_bytes_at(bytes, i.index())?
     }
 }
index 3595312f3f41b41bfa13e92a5d8838a032c2a60f..8508bf62d8f60e5a9c5b0f305d2715a15b9fb7d1 100644 (file)
@@ -308,7 +308,14 @@ pub(super) fn report_move_out_while_borrowed(
             location,
             borrow,
             None,
-        ).add_explanation_to_diagnostic(self.infcx.tcx, self.body, &mut err, "", Some(borrow_span));
+        ).add_explanation_to_diagnostic(
+            self.infcx.tcx,
+            self.body,
+            &self.local_names,
+            &mut err,
+            "",
+            Some(borrow_span),
+        );
         err.buffer(&mut self.errors_buffer);
     }
 
@@ -343,7 +350,14 @@ pub(super) fn report_use_while_mutably_borrowed(
         });
 
         self.explain_why_borrow_contains_point(location, borrow, None)
-            .add_explanation_to_diagnostic(self.infcx.tcx, self.body, &mut err, "", None);
+            .add_explanation_to_diagnostic(
+                self.infcx.tcx,
+                self.body,
+                &self.local_names,
+                &mut err,
+                "",
+                None,
+            );
         err
     }
 
@@ -561,6 +575,7 @@ pub(super) fn report_conflicting_borrow(
         explanation.add_explanation_to_diagnostic(
             self.infcx.tcx,
             self.body,
+            &self.local_names,
             &mut err,
             first_borrow_desc,
             None,
@@ -947,6 +962,7 @@ fn report_local_value_does_not_live_long_enough(
                 explanation.add_explanation_to_diagnostic(
                     self.infcx.tcx,
                     self.body,
+                    &self.local_names,
                     &mut err,
                     "",
                     None,
@@ -971,7 +987,7 @@ fn report_local_value_does_not_live_long_enough(
             );
 
             explanation.add_explanation_to_diagnostic(
-                self.infcx.tcx, self.body, &mut err, "", None);
+                self.infcx.tcx, self.body, &self.local_names, &mut err, "", None);
         }
 
         err
@@ -1029,7 +1045,14 @@ fn report_borrow_conflicts_with_destructor(
             _ => {}
         }
 
-        explanation.add_explanation_to_diagnostic(self.infcx.tcx, self.body, &mut err, "", None);
+        explanation.add_explanation_to_diagnostic(
+            self.infcx.tcx,
+            self.body,
+            &self.local_names,
+            &mut err,
+            "",
+            None,
+        );
 
         err.buffer(&mut self.errors_buffer);
     }
@@ -1109,7 +1132,14 @@ fn report_temporary_value_does_not_live_long_enough(
             }
             _ => {}
         }
-        explanation.add_explanation_to_diagnostic(self.infcx.tcx, self.body, &mut err, "", None);
+        explanation.add_explanation_to_diagnostic(
+            self.infcx.tcx,
+            self.body,
+            &self.local_names,
+            &mut err,
+            "",
+            None,
+        );
 
         let within = if borrow_spans.for_generator() {
             " by generator"
@@ -1264,23 +1294,17 @@ fn report_escaping_closure_capture(
             Applicability::MachineApplicable,
         );
 
-        match category {
-            ConstraintCategory::Return => {
-                err.span_note(constraint_span, "closure is returned here");
-            }
-            ConstraintCategory::OpaqueType => {
-                err.span_note(constraint_span, "generator is returned here");
-            }
+        let msg = match category {
+            ConstraintCategory::Return => "closure is returned here".to_string(),
+            ConstraintCategory::OpaqueType => "generator is returned here".to_string(),
             ConstraintCategory::CallArgument => {
                 fr_name.highlight_region_name(&mut err);
-                err.span_note(
-                    constraint_span,
-                    &format!("function requires argument type to outlive `{}`", fr_name),
-                );
+                format!("function requires argument type to outlive `{}`", fr_name)
             }
             _ => bug!("report_escaping_closure_capture called with unexpected constraint \
                        category: `{:?}`", category),
-        }
+        };
+        err.span_note(constraint_span, &msg);
         err
     }
 
@@ -1484,7 +1508,14 @@ pub(super) fn report_illegal_mutation_of_borrowed(
         );
 
         self.explain_why_borrow_contains_point(location, loan, None)
-            .add_explanation_to_diagnostic(self.infcx.tcx, self.body, &mut err, "", None);
+            .add_explanation_to_diagnostic(
+                self.infcx.tcx,
+                self.body,
+                &self.local_names,
+                &mut err,
+                "",
+                None,
+            );
 
         err.buffer(&mut self.errors_buffer);
     }
@@ -1502,14 +1533,13 @@ pub(super) fn report_illegal_reassignment(
         assigned_span: Span,
         err_place: &Place<'tcx>,
     ) {
-        let (from_arg, local_decl) = if let Some(local) = err_place.as_local() {
-            if let LocalKind::Arg = self.body.local_kind(local) {
-                (true, Some(&self.body.local_decls[local]))
-            } else {
-                (false, Some(&self.body.local_decls[local]))
-            }
-        } else {
-            (false, None)
+        let (from_arg, local_decl, local_name) = match err_place.as_local() {
+            Some(local) => (
+                self.body.local_kind(local) == LocalKind::Arg,
+                Some(&self.body.local_decls[local]),
+                self.local_names[local],
+            ),
+            None => (false, None, None),
         };
 
         // If root local is initialized immediately (everything apart from let
@@ -1559,7 +1589,7 @@ pub(super) fn report_illegal_reassignment(
             }
         }
         if let Some(decl) = local_decl {
-            if let Some(name) = decl.name {
+            if let Some(name) = local_name {
                 if decl.can_be_made_mutable() {
                     err.span_suggestion(
                         decl.source_info.span,
index 3835503b0ef35fdf8597ad6e40e2ca75ed22cbc9..a555e0b74c2b780c440720980ef2bdb3afb83769 100644 (file)
@@ -331,10 +331,10 @@ fn append_place_to_string(
 
     /// Appends end-user visible description of the `local` place to `buf`. If `local` doesn't have
     /// a name, or its name was generated by the compiler, then `Err` is returned
-    fn append_local_to_string(&self, local_index: Local, buf: &mut String) -> Result<(), ()> {
-        let local = &self.body.local_decls[local_index];
-        match local.name {
-            Some(name) if !local.from_compiler_desugaring() => {
+    fn append_local_to_string(&self, local: Local, buf: &mut String) -> Result<(), ()> {
+        let decl = &self.body.local_decls[local];
+        match self.local_names[local] {
+            Some(name) if !decl.from_compiler_desugaring() => {
                 buf.push_str(&name.as_str());
                 Ok(())
             }
index 90e39286ec84d02d41479625d11b490abdfc0468..8a74e3a74add74085eaa738787fbd8b17f275f48 100644 (file)
@@ -115,6 +115,20 @@ fn do_mir_borrowck<'a, 'tcx>(
         .as_local_hir_id(def_id)
         .expect("do_mir_borrowck: non-local DefId");
 
+    let mut local_names = IndexVec::from_elem(None, &input_body.local_decls);
+    for var_debug_info in &input_body.var_debug_info {
+        if let Some(local) = var_debug_info.place.as_local() {
+            if let Some(prev_name) = local_names[local] {
+                if var_debug_info.name != prev_name {
+                    span_bug!(var_debug_info.source_info.span,
+                        "local {:?} has many names (`{}` vs `{}`)",
+                        local, prev_name, var_debug_info.name);
+                }
+            }
+            local_names[local] = Some(var_debug_info.name);
+        }
+    }
+
     // Gather the upvars of a closure, if any.
     let tables = tcx.typeck_tables_of(def_id);
     let upvars: Vec<_> = tables
@@ -189,6 +203,7 @@ fn do_mir_borrowck<'a, 'tcx>(
         free_regions,
         body,
         &promoted,
+        &local_names,
         &upvars,
         location_table,
         param_env,
@@ -264,6 +279,7 @@ fn do_mir_borrowck<'a, 'tcx>(
         borrow_set,
         dominators,
         upvars,
+        local_names,
     };
 
     let mut state = Flows::new(
@@ -325,13 +341,8 @@ fn do_mir_borrowck<'a, 'tcx>(
         if let ClearCrossCrate::Set(ref vsi) = mbcx.body.source_scope_local_data {
             let local_decl = &mbcx.body.local_decls[local];
 
-            // Skip implicit `self` argument for closures
-            if local.index() == 1 && tcx.is_closure(mbcx.mir_def_id) {
-                continue;
-            }
-
             // Skip over locals that begin with an underscore or have no name
-            match local_decl.name {
+            match mbcx.local_names[local] {
                 Some(name) => if name.as_str().starts_with("_") {
                     continue;
                 },
@@ -463,6 +474,9 @@ fn do_mir_borrowck<'a, 'tcx>(
 
     /// Information about upvars not necessarily preserved in types or MIR
     upvars: Vec<Upvar>,
+
+    /// Names of local (user) variables (extracted from `var_debug_info`).
+    local_names: IndexVec<Local, Option<Name>>,
 }
 
 // Check that:
index b1f63d729ba9b027ce5fb0fe79d51e9f4c0b7a5e..bf61eb9f0c5c7c4af0c7e315806471e4f80a0952 100644 (file)
@@ -322,7 +322,7 @@ fn report_cannot_move_from_borrowed_content(
             if decl.is_ref_for_guard() {
                 let mut err = self.cannot_move_out_of(
                     span,
-                    &format!("`{}` in pattern guard", decl.name.unwrap()),
+                    &format!("`{}` in pattern guard", self.local_names[*local].unwrap()),
                 );
                 err.note(
                     "variables bound in patterns cannot be moved from \
@@ -558,7 +558,6 @@ fn add_move_error_details(
         err: &mut DiagnosticBuilder<'a>,
         binds_to: &[Local],
     ) {
-        let mut noncopy_var_spans = Vec::new();
         for (j, local) in binds_to.into_iter().enumerate() {
             let bind_to = &self.body.local_decls[*local];
             let binding_span = bind_to.source_info.span;
@@ -572,20 +571,16 @@ fn add_move_error_details(
             if binds_to.len() == 1 {
                 self.note_type_does_not_implement_copy(
                     err,
-                    &format!("`{}`", bind_to.name.unwrap()),
+                    &format!("`{}`", self.local_names[*local].unwrap()),
                     bind_to.ty,
                     Some(binding_span)
                 );
-            } else {
-                noncopy_var_spans.push(binding_span);
             }
         }
 
         if binds_to.len() > 1 {
-            err.span_note(
-                noncopy_var_spans,
-                "move occurs because these variables have types that \
-                    don't implement the `Copy` trait",
+            err.note("move occurs because these variables have types that \
+                      don't implement the `Copy` trait",
             );
         }
     }
index 404684c07a09c6a45805e10ab3534fcdda8b8c14..bf070c3f07d48d68aef87731bcac5b4390fdcf8e 100644 (file)
@@ -50,8 +50,7 @@ pub(super) fn report_mutability_error(
                 if access_place.as_local().is_some() {
                     reason = ", as it is not declared as mutable".to_string();
                 } else {
-                    let name = self.body.local_decls[*local]
-                        .name
+                    let name = self.local_names[*local]
                         .expect("immutable unnamed local");
                     reason = format!(", as `{}` is not declared as mutable", name);
                 }
@@ -253,7 +252,7 @@ pub(super) fn report_mutability_error(
                         // Deliberately fall into this case for all implicit self types,
                         // so that we don't fall in to the next case with them.
                         kind == mir::ImplicitSelfKind::MutRef
-                    } else if Some(kw::SelfLower) == local_decl.name {
+                    } else if Some(kw::SelfLower) == self.local_names[*local] {
                         // Otherwise, check if the name is the self kewyord - in which case
                         // we have an explicit self. Do the same thing in this case and check
                         // for a `self: &mut Self` to suggest removing the `&mut`.
@@ -290,7 +289,7 @@ pub(super) fn report_mutability_error(
                 err.span_suggestion(
                     local_decl.source_info.span,
                     "consider changing this to be mutable",
-                    format!("mut {}", local_decl.name.unwrap()),
+                    format!("mut {}", self.local_names[*local].unwrap()),
                     Applicability::MachineApplicable,
                 );
             }
@@ -415,7 +414,7 @@ pub(super) fn report_mutability_error(
                     );
                 }
 
-                match local_decl.name {
+                match self.local_names[*local] {
                     Some(name) if !local_decl.from_compiler_desugaring() => {
                         err.span_label(
                             span,
index 26bead3047d5d3ce62bde8df861e120f94256182..c7058531958e193ebf8572c17210b3306b9972ef 100644 (file)
 };
 use rustc::ty::{self, TyCtxt};
 use rustc::ty::adjustment::{PointerCast};
+use rustc_index::vec::IndexVec;
 use rustc_data_structures::fx::FxHashSet;
 use rustc_errors::DiagnosticBuilder;
 use syntax_pos::Span;
+use syntax_pos::symbol::Symbol;
 
 mod find_use;
 
@@ -56,6 +58,7 @@ pub(in crate::borrow_check) fn add_explanation_to_diagnostic<'tcx>(
         &self,
         tcx: TyCtxt<'tcx>,
         body: &Body<'tcx>,
+        local_names: &IndexVec<Local, Option<Symbol>>,
         err: &mut DiagnosticBuilder<'_>,
         borrow_desc: &str,
         borrow_span: Option<Span>,
@@ -112,7 +115,7 @@ pub(in crate::borrow_check) fn add_explanation_to_diagnostic<'tcx>(
                     _ => ("destructor", format!("type `{}`", local_decl.ty)),
                 };
 
-                match local_decl.name {
+                match local_names[dropped_local] {
                     Some(local_name) if !local_decl.from_compiler_desugaring() => {
                         let message = format!(
                             "{B}borrow might be used here, when `{LOC}` is dropped \
@@ -271,10 +274,10 @@ pub(in crate::borrow_check) fn explain_why_borrow_contains_point(
 
             Some(Cause::DropVar(local, location)) => {
                 let mut should_note_order = false;
-                if body.local_decls[local].name.is_some() {
+                if self.local_names[local].is_some() {
                     if let Some((WriteKind::StorageDeadOrDrop, place)) = kind_place {
                         if let Some(borrowed_local) = place.as_local() {
-                             if body.local_decls[borrowed_local].name.is_some()
+                            if self.local_names[borrowed_local].is_some()
                                 && local != borrowed_local
                             {
                                 should_note_order = true;
@@ -295,6 +298,7 @@ pub(in crate::borrow_check) fn explain_why_borrow_contains_point(
                     let (category, from_closure, span, region_name) =
                         self.nonlexical_regioncx.free_region_constraint_info(
                             self.body,
+                        &self.local_names,
                         &self.upvars,
                             self.mir_def_id,
                             self.infcx,
@@ -495,7 +499,7 @@ fn later_use_kind(
                             Operand::Move(place) => {
                                 if let Some(l) = place.as_local() {
                                     let local_decl = &self.body.local_decls[l];
-                                    if local_decl.name.is_none() {
+                                    if self.local_names[l].is_none() {
                                         local_decl.source_info.span
                                     } else {
                                         span
index b2e5751b902e7a9d566a0fe8fa49bbd7a4fa8111..4d67b72c98c57e4f0f11bf9b0c77823212fe419f 100644 (file)
@@ -16,6 +16,7 @@
 use rustc::ty::{self, RegionKind, RegionVid};
 use rustc_index::vec::IndexVec;
 use rustc_errors::Diagnostic;
+use syntax_pos::symbol::Symbol;
 use std::fmt::Debug;
 use std::env;
 use std::io;
@@ -158,6 +159,7 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
     universal_regions: UniversalRegions<'tcx>,
     body: &Body<'tcx>,
     promoted: &IndexVec<Promoted, Body<'tcx>>,
+    local_names: &IndexVec<Local, Option<Symbol>>,
     upvars: &[Upvar],
     location_table: &LocationTable,
     param_env: ty::ParamEnv<'tcx>,
@@ -281,7 +283,7 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
 
     // Solve the region constraints.
     let closure_region_requirements =
-        regioncx.solve(infcx, &body, upvars, def_id, errors_buffer);
+        regioncx.solve(infcx, body, local_names, upvars, def_id, errors_buffer);
 
     // Dump MIR results into a file, if that is enabled. This let us
     // write unit-tests, as well as helping with debugging.
index e6795dbfd449ca5fda2df1bc86b943b5e2ca1332..5e79a2fea9b735b7093e3e8b2dcb2aded39d28cf 100644 (file)
@@ -9,7 +9,7 @@
 use rustc::infer::error_reporting::nice_region_error::NiceRegionError;
 use rustc::infer::InferCtxt;
 use rustc::infer::NLLRegionVariableOrigin;
-use rustc::mir::{ConstraintCategory, Location, Body};
+use rustc::mir::{ConstraintCategory, Local, Location, Body};
 use rustc::ty::{self, RegionVid};
 use rustc_index::vec::IndexVec;
 use rustc_errors::DiagnosticBuilder;
@@ -17,6 +17,7 @@
 use syntax::errors::Applicability;
 use syntax::symbol::kw;
 use syntax_pos::Span;
+use syntax_pos::symbol::Symbol;
 
 use self::outlives_suggestion::OutlivesSuggestionBuilder;
 
@@ -71,6 +72,9 @@ pub struct ErrorReportingCtx<'a, 'b, 'tcx> {
     /// The MIR body we are reporting errors on (for convenience).
     body: &'b Body<'tcx>,
 
+    /// User variable names for MIR locals (where applicable).
+    local_names: &'b IndexVec<Local, Option<Symbol>>,
+
     /// Any upvars for the MIR body we have kept track of during borrow checking.
     upvars: &'b [Upvar],
 }
@@ -367,13 +371,14 @@ fn find_constraint_paths_between_regions(
     pub(super) fn report_error<'a>(
         &'a self,
         body: &Body<'tcx>,
+        local_names: &IndexVec<Local, Option<Symbol>>,
         upvars: &[Upvar],
         infcx: &'a InferCtxt<'a, 'tcx>,
         mir_def_id: DefId,
         fr: RegionVid,
         fr_origin: NLLRegionVariableOrigin,
         outlived_fr: RegionVid,
-        outlives_suggestion: &mut OutlivesSuggestionBuilder,
+        outlives_suggestion: &mut OutlivesSuggestionBuilder<'_>,
         renctx: &mut RegionErrorNamingCtx,
     ) -> DiagnosticBuilder<'a> {
         debug!("report_error(fr={:?}, outlived_fr={:?})", fr, outlived_fr);
@@ -407,6 +412,7 @@ pub(super) fn report_error<'a>(
             infcx,
             mir_def_id,
             body,
+            local_names,
             upvars,
         };
 
@@ -551,7 +557,7 @@ fn report_escaping_data_error(
         renctx: &mut RegionErrorNamingCtx,
     ) -> DiagnosticBuilder<'_> {
         let ErrorReportingCtx {
-            infcx, body, upvars, ..
+            infcx, body, upvars, local_names, ..
         } = errctx;
 
         let ErrorConstraintInfo {
@@ -559,9 +565,14 @@ fn report_escaping_data_error(
         } = errci;
 
         let fr_name_and_span =
-            self.get_var_name_and_span_for_region(infcx.tcx, body, upvars, errci.fr);
-        let outlived_fr_name_and_span =
-            self.get_var_name_and_span_for_region(infcx.tcx, body, upvars, errci.outlived_fr);
+            self.get_var_name_and_span_for_region(infcx.tcx, body, local_names, upvars, errci.fr);
+        let outlived_fr_name_and_span = self.get_var_name_and_span_for_region(
+            infcx.tcx,
+            body,
+            local_names,
+            upvars,
+            errci.outlived_fr,
+        );
 
         let escapes_from = match self.universal_regions.defining_ty {
             DefiningTy::Closure(..) => "closure",
@@ -789,6 +800,7 @@ fn add_static_impl_trait_suggestion(
     crate fn free_region_constraint_info(
         &self,
         body: &Body<'tcx>,
+        local_names: &IndexVec<Local, Option<Symbol>>,
         upvars: &[Upvar],
         mir_def_id: DefId,
         infcx: &InferCtxt<'_, 'tcx>,
@@ -804,7 +816,7 @@ fn add_static_impl_trait_suggestion(
 
         let mut renctx = RegionErrorNamingCtx::new();
         let errctx = ErrorReportingCtx {
-            infcx, body, upvars, mir_def_id,
+            infcx, body, local_names, upvars, mir_def_id,
             region_infcx: self,
         };
         let outlived_fr_name = self.give_region_a_name(&errctx, &mut renctx, outlived_region);
index 62142efe505b2931da8fc855c116851b258448ee..c0cf4eb5285c92d9528a483acc1be7cb583a25c7 100644 (file)
@@ -4,9 +4,12 @@
 use std::collections::BTreeMap;
 
 use log::debug;
-use rustc::{hir::def_id::DefId, infer::InferCtxt, mir::Body, ty::RegionVid};
+use rustc::{hir::def_id::DefId, infer::InferCtxt, ty::RegionVid};
+use rustc::mir::{Body, Local};
 use rustc_data_structures::fx::FxHashSet;
 use rustc_errors::{Diagnostic, DiagnosticBuilder};
+use rustc_index::vec::IndexVec;
+use syntax_pos::symbol::Symbol;
 
 use smallvec::SmallVec;
 
@@ -34,10 +37,12 @@ enum SuggestedConstraint {
 /// corresponding to a function definition.
 ///
 /// Adds a help note suggesting adding a where clause with the needed constraints.
-pub struct OutlivesSuggestionBuilder {
+pub struct OutlivesSuggestionBuilder<'a> {
     /// The MIR DefId of the fn with the lifetime error.
     mir_def_id: DefId,
 
+    local_names: &'a IndexVec<Local, Option<Symbol>>,
+
     /// The list of outlives constraints that need to be added. Specifically, we map each free
     /// region to all other regions that it must outlive. I will use the shorthand `fr:
     /// outlived_frs`. Not all of these regions will already have names necessarily. Some could be
@@ -46,10 +51,17 @@ pub struct OutlivesSuggestionBuilder {
     constraints_to_add: BTreeMap<RegionVid, Vec<RegionVid>>,
 }
 
-impl OutlivesSuggestionBuilder {
+impl OutlivesSuggestionBuilder<'a> {
     /// Create a new builder for the given MIR node representing a fn definition.
-    crate fn new(mir_def_id: DefId) -> Self {
-        OutlivesSuggestionBuilder { mir_def_id, constraints_to_add: BTreeMap::default() }
+    crate fn new(
+        mir_def_id: DefId,
+        local_names: &'a IndexVec<Local, Option<Symbol>>,
+    ) -> Self {
+        OutlivesSuggestionBuilder {
+            mir_def_id,
+            local_names,
+            constraints_to_add: BTreeMap::default(),
+        }
     }
 
     /// Returns `true` iff the `RegionNameSource` is a valid source for an outlives
@@ -125,6 +137,7 @@ fn compile_all_suggestions<'tcx>(
             infcx,
             body,
             mir_def_id: self.mir_def_id,
+            local_names: self.local_names,
 
             // We should not be suggesting naming upvars, so we pass in a dummy set of upvars that
             // should never be used.
index a8cc0cc044a01ce437bbae0e91ef3ca9f962c544..e59928987a03c8c70b1a4c9bbc431867e1170e30 100644 (file)
 use rustc::hir::def::{Res, DefKind};
 use rustc::hir::def_id::DefId;
 use rustc::infer::InferCtxt;
-use rustc::mir::Body;
+use rustc::mir::{Local, Body};
 use rustc::ty::subst::{SubstsRef, GenericArgKind};
 use rustc::ty::{self, RegionKind, RegionVid, Ty, TyCtxt};
 use rustc::ty::print::RegionHighlightMode;
+use rustc_index::vec::IndexVec;
 use rustc_errors::DiagnosticBuilder;
 use syntax::symbol::kw;
 use rustc_data_structures::fx::FxHashMap;
@@ -210,7 +211,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
         fr: RegionVid,
     ) -> Option<RegionName> {
         let ErrorReportingCtx {
-            infcx, body, mir_def_id, upvars, ..
+            infcx, body, mir_def_id, local_names, upvars, ..
         } = errctx;
 
         debug!("give_region_a_name(fr={:?}, counter={:?})", fr, renctx.counter);
@@ -225,7 +226,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
             .give_name_from_error_region(infcx.tcx, *mir_def_id, fr, renctx)
             .or_else(|| {
                 self.give_name_if_anonymous_region_appears_in_arguments(
-                    infcx, body, *mir_def_id, fr, renctx,
+                    infcx, body, local_names, *mir_def_id, fr, renctx,
                 )
             })
             .or_else(|| {
@@ -395,6 +396,7 @@ fn give_name_if_anonymous_region_appears_in_arguments(
         &self,
         infcx: &InferCtxt<'_, 'tcx>,
         body: &Body<'tcx>,
+        local_names: &IndexVec<Local, Option<Symbol>>,
         mir_def_id: DefId,
         fr: RegionVid,
         renctx: &mut RegionErrorNamingCtx,
@@ -415,7 +417,7 @@ fn give_name_if_anonymous_region_appears_in_arguments(
             return Some(region_name);
         }
 
-        self.give_name_if_we_cannot_match_hir_ty(infcx, body, fr, arg_ty, renctx)
+        self.give_name_if_we_cannot_match_hir_ty(infcx, body, local_names, fr, arg_ty, renctx)
     }
 
     fn give_name_if_we_can_match_hir_ty_from_argument(
@@ -463,6 +465,7 @@ fn give_name_if_we_cannot_match_hir_ty(
         &self,
         infcx: &InferCtxt<'_, 'tcx>,
         body: &Body<'tcx>,
+        local_names: &IndexVec<Local, Option<Symbol>>,
         needle_fr: RegionVid,
         argument_ty: Ty<'tcx>,
         renctx: &mut RegionErrorNamingCtx,
@@ -479,7 +482,8 @@ fn give_name_if_we_cannot_match_hir_ty(
         let assigned_region_name = if type_name.find(&format!("'{}", counter)).is_some() {
             // Only add a label if we can confirm that a region was labelled.
             let argument_index = self.get_argument_index_for_region(infcx.tcx, needle_fr)?;
-            let (_, span) = self.get_argument_name_and_span_for_region(body, argument_index);
+            let (_, span) =
+                self.get_argument_name_and_span_for_region(body, local_names, argument_index);
 
             Some(RegionName {
                 // This counter value will already have been used, so this function will increment
index 7f0e97c9ae4264a5f555f75c82e3e65dfa5d3217..1ac44c4fdb10115db4cda7fde070c5d4c144bc30 100644 (file)
@@ -3,7 +3,7 @@
 use crate::borrow_check::Upvar;
 use rustc::mir::{Local, Body};
 use rustc::ty::{RegionVid, TyCtxt};
-use rustc_index::vec::Idx;
+use rustc_index::vec::{Idx, IndexVec};
 use syntax::source_map::Span;
 use syntax_pos::symbol::Symbol;
 
@@ -12,6 +12,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
         &self,
         tcx: TyCtxt<'tcx>,
         body: &Body<'tcx>,
+        local_names: &IndexVec<Local, Option<Symbol>>,
         upvars: &[Upvar],
         fr: RegionVid,
     ) -> Option<(Option<Symbol>, Span)> {
@@ -27,8 +28,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
             })
             .or_else(|| {
                 debug!("get_var_name_and_span_for_region: attempting argument");
-                self.get_argument_index_for_region(tcx, fr)
-                    .map(|index| self.get_argument_name_and_span_for_region(body, index))
+                self.get_argument_index_for_region(tcx, fr).map(|index| {
+                    self.get_argument_name_and_span_for_region(body, local_names, index)
+                })
             })
     }
 
@@ -117,13 +119,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
     crate fn get_argument_name_and_span_for_region(
         &self,
         body: &Body<'tcx>,
+        local_names: &IndexVec<Local, Option<Symbol>>,
         argument_index: usize,
     ) -> (Option<Symbol>, Span) {
         let implicit_inputs = self.universal_regions.defining_ty.implicit_inputs();
         let argument_local = Local::new(implicit_inputs + argument_index + 1);
         debug!("get_argument_name_and_span_for_region: argument_local={:?}", argument_local);
 
-        let argument_name = body.local_decls[argument_local].name;
+        let argument_name = local_names[argument_local];
         let argument_span = body.local_decls[argument_local].source_info.span;
         debug!("get_argument_name_and_span_for_region: argument_name={:?} argument_span={:?}",
                argument_name, argument_span);
index 4de8200e6a0c7070bb7a00235bdb1dc289267a82..d44e85fa7900db2728a35bdf91ac169e8ef2ff99 100644 (file)
@@ -36,6 +36,7 @@
 use rustc_index::vec::IndexVec;
 use rustc_errors::{Diagnostic, DiagnosticBuilder};
 use syntax_pos::Span;
+use syntax_pos::symbol::Symbol;
 
 crate use self::error_reporting::{RegionName, RegionNameSource, RegionErrorNamingCtx};
 use self::values::{LivenessValues, RegionValueElements, RegionValues};
@@ -471,6 +472,7 @@ pub(super) fn solve(
         &mut self,
         infcx: &InferCtxt<'_, 'tcx>,
         body: &Body<'tcx>,
+        local_names: &IndexVec<Local, Option<Symbol>>,
         upvars: &[Upvar],
         mir_def_id: DefId,
         errors_buffer: &mut Vec<Diagnostic>,
@@ -502,6 +504,7 @@ pub(super) fn solve(
         self.check_universal_regions(
             infcx,
             body,
+            local_names,
             upvars,
             mir_def_id,
             outlives_requirements.as_mut(),
@@ -1321,13 +1324,14 @@ fn check_universal_regions(
         &self,
         infcx: &InferCtxt<'_, 'tcx>,
         body: &Body<'tcx>,
+        local_names: &IndexVec<Local, Option<Symbol>>,
         upvars: &[Upvar],
         mir_def_id: DefId,
         mut propagated_outlives_requirements: Option<&mut Vec<ClosureOutlivesRequirement<'tcx>>>,
         errors_buffer: &mut Vec<Diagnostic>,
         region_naming: &mut RegionErrorNamingCtx,
     ) {
-        let mut outlives_suggestion = OutlivesSuggestionBuilder::new(mir_def_id);
+        let mut outlives_suggestion = OutlivesSuggestionBuilder::new(mir_def_id, local_names);
 
         for (fr, fr_definition) in self.definitions.iter_enumerated() {
             match fr_definition.origin {
@@ -1338,6 +1342,7 @@ fn check_universal_regions(
                     self.check_universal_region(
                         infcx,
                         body,
+                        local_names,
                         upvars,
                         mir_def_id,
                         fr,
@@ -1374,11 +1379,12 @@ fn check_universal_region(
         &self,
         infcx: &InferCtxt<'_, 'tcx>,
         body: &Body<'tcx>,
+        local_names: &IndexVec<Local, Option<Symbol>>,
         upvars: &[Upvar],
         mir_def_id: DefId,
         longer_fr: RegionVid,
         propagated_outlives_requirements: &mut Option<&mut Vec<ClosureOutlivesRequirement<'tcx>>>,
-        outlives_suggestion: &mut OutlivesSuggestionBuilder,
+        outlives_suggestion: &mut OutlivesSuggestionBuilder<'_>,
         errors_buffer: &mut Vec<Diagnostic>,
         region_naming: &mut RegionErrorNamingCtx,
     ) {
@@ -1404,6 +1410,7 @@ fn check_universal_region(
                 representative,
                 infcx,
                 body,
+                local_names,
                 upvars,
                 mir_def_id,
                 propagated_outlives_requirements,
@@ -1422,6 +1429,7 @@ fn check_universal_region(
                 shorter_fr,
                 infcx,
                 body,
+                local_names,
                 upvars,
                 mir_def_id,
                 propagated_outlives_requirements,
@@ -1445,10 +1453,11 @@ fn check_universal_region_relation(
         shorter_fr: RegionVid,
         infcx: &InferCtxt<'_, 'tcx>,
         body: &Body<'tcx>,
+        local_names: &IndexVec<Local, Option<Symbol>>,
         upvars: &[Upvar],
         mir_def_id: DefId,
         propagated_outlives_requirements: &mut Option<&mut Vec<ClosureOutlivesRequirement<'tcx>>>,
-        outlives_suggestion: &mut OutlivesSuggestionBuilder,
+        outlives_suggestion: &mut OutlivesSuggestionBuilder<'_>,
         errors_buffer: &mut Vec<Diagnostic>,
         region_naming: &mut RegionErrorNamingCtx,
     ) -> Option<ErrorReported> {
@@ -1502,6 +1511,7 @@ fn check_universal_region_relation(
         // error. This gives better error messages in some cases.
         let db = self.report_error(
             body,
+            local_names,
             upvars,
             infcx,
             mir_def_id,
index d74dd0fc0f5f148f8a61ff50fdb40166f2e29d4a..35fb677c053cb99ae7d5955be1144fb8d2b5e739 100644 (file)
@@ -134,15 +134,27 @@ pub(super) fn equate_inputs_and_outputs(
         };
 
         // If the user explicitly annotated the output types, enforce those.
+        // Note that this only happens for closures.
         if let Some(user_provided_sig) = user_provided_sig {
             let user_provided_output_ty = user_provided_sig.output();
             let user_provided_output_ty =
                 self.normalize(user_provided_output_ty, Locations::All(output_span));
-            self.equate_normalized_input_or_output(
-                user_provided_output_ty,
+            if let Err(err) = self.eq_opaque_type_and_type(
                 mir_output_ty,
-                output_span,
-            );
+                user_provided_output_ty,
+                self.mir_def_id,
+                Locations::All(output_span),
+                ConstraintCategory::BoringNoLocation
+            ) {
+                span_mirbug!(
+                    self,
+                    Location::START,
+                    "equate_inputs_and_outputs: `{:?}=={:?}` failed with `{:?}`",
+                    mir_output_ty,
+                    user_provided_output_ty,
+                    err
+                );
+            }
         }
     }
 
index e991181189f412bc8c7fc2974f5013a2ffeae748..f5dc09ccebc1e65b96902296c5640a1fc7377934 100644 (file)
@@ -227,9 +227,7 @@ pub fn into_expr(
                         mutability: Mutability::Mut,
                         ty: ptr_ty,
                         user_ty: UserTypeProjections::none(),
-                        name: None,
                         source_info,
-                        visibility_scope: source_info.scope,
                         internal: true,
                         local_info: LocalInfo::Other,
                         is_block_tail: None,
index 514dd74dc0b3e908052e9d924825fe8a67c3e55b..032ea7d8161cbf53e75fb60b599a0595219338d9 100644 (file)
@@ -1721,6 +1721,10 @@ fn declare_binding(
         );
 
         let tcx = self.hir.tcx();
+        let debug_source_info = SourceInfo {
+            span: source_info.span,
+            scope: visibility_scope,
+        };
         let binding_mode = match mode {
             BindingMode::ByValue => ty::BindingMode::BindByValue(mutability.into()),
             BindingMode::ByRef(_) => ty::BindingMode::BindByReference(mutability.into()),
@@ -1730,9 +1734,7 @@ fn declare_binding(
             mutability,
             ty: var_ty,
             user_ty,
-            name: Some(name),
             source_info,
-            visibility_scope,
             internal: false,
             is_block_tail: None,
             local_info: LocalInfo::User(ClearCrossCrate::Set(BindingForm::Var(
@@ -1749,6 +1751,11 @@ fn declare_binding(
             ))),
         };
         let for_arm_body = self.local_decls.push(local);
+        self.var_debug_info.push(VarDebugInfo {
+            name,
+            source_info: debug_source_info,
+            place: for_arm_body.into(),
+        });
         let locals = if has_guard.0 {
             let ref_for_guard = self.local_decls.push(LocalDecl::<'tcx> {
                 // This variable isn't mutated but has a name, so has to be
@@ -1756,13 +1763,16 @@ fn declare_binding(
                 mutability: Mutability::Not,
                 ty: tcx.mk_imm_ref(tcx.lifetimes.re_erased, var_ty),
                 user_ty: UserTypeProjections::none(),
-                name: Some(name),
                 source_info,
-                visibility_scope,
                 internal: false,
                 is_block_tail: None,
                 local_info: LocalInfo::User(ClearCrossCrate::Set(BindingForm::RefForGuard)),
             });
+            self.var_debug_info.push(VarDebugInfo {
+                name,
+                source_info: debug_source_info,
+                place: ref_for_guard.into(),
+            });
             LocalsForNode::ForGuard {
                 ref_for_guard,
                 for_arm_body,
index 9b7bccca2ddf3268aaac4602d48d15dd0e2c557a..3e71b871801d1d21a79ccf2d705e27a034cc5b36 100644 (file)
@@ -164,7 +164,7 @@ fn simplify_match_pair<'pat>(&mut self,
                         self.hir.tcx().features().exhaustive_patterns &&
                         !v.uninhabited_from(self.hir.tcx(), substs, adt_def.adt_kind()).is_empty()
                     }
-                });
+                }) && (adt_def.did.is_local() || !adt_def.is_variant_list_non_exhaustive());
                 if irrefutable {
                     let place = tcx.mk_place_downcast(match_pair.place, adt_def, variant_index);
                     candidate.match_pairs.extend(self.field_match_pairs(place, subpatterns));
index 6b458cc244c9e3195564c8cdd060c1206baf8964..180f2cc089f020ca947c54a5723b2e726173da56 100644 (file)
@@ -161,8 +161,18 @@ pub fn mir_build(tcx: TyCtxt<'_>, def_id: DefId) -> Body<'_> {
                 (None, fn_sig.output())
             };
 
-            build::construct_fn(cx, id, arguments, safety, abi,
-                                return_ty, yield_ty, return_ty_span, body)
+            let mut mir = build::construct_fn(
+                cx,
+                id,
+                arguments,
+                safety,
+                abi,
+                return_ty,
+                return_ty_span,
+                body,
+            );
+            mir.yield_ty = yield_ty;
+            mir
         } else {
             // Get the revealed type of this const. This is *not* the adjusted
             // type of its body, which may be a subtype of this type. For
@@ -312,10 +322,11 @@ struct Builder<'a, 'tcx> {
     var_indices: HirIdMap<LocalsForNode>,
     local_decls: IndexVec<Local, LocalDecl<'tcx>>,
     canonical_user_type_annotations: ty::CanonicalUserTypeAnnotations<'tcx>,
-    __upvar_debuginfo_codegen_only_do_not_use: Vec<UpvarDebuginfo>,
     upvar_mutbls: Vec<Mutability>,
     unit_temp: Option<Place<'tcx>>,
 
+    var_debug_info: Vec<VarDebugInfo<'tcx>>,
+
     /// Cached block with the `RESUME` terminator; this is created
     /// when first set of cleanups are built.
     cached_resume_block: Option<BasicBlock>,
@@ -539,7 +550,6 @@ fn construct_fn<'a, 'tcx, A>(
     safety: Safety,
     abi: Abi,
     return_ty: Ty<'tcx>,
-    yield_ty: Option<Ty<'tcx>>,
     return_ty_span: Span,
     body: &'tcx hir::Body,
 ) -> Body<'tcx>
@@ -552,58 +562,14 @@ fn construct_fn<'a, 'tcx, A>(
     let tcx_hir = tcx.hir();
     let span = tcx_hir.span(fn_id);
 
-    let hir_tables = hir.tables();
     let fn_def_id = tcx_hir.local_def_id(fn_id);
 
-    // Gather the upvars of a closure, if any.
-    let mut upvar_mutbls = vec![];
-    // In analyze_closure() in upvar.rs we gathered a list of upvars used by a
-    // closure and we stored in a map called upvar_list in TypeckTables indexed
-    // with the closure's DefId. Here, we run through that vec of UpvarIds for
-    // the given closure and use the necessary information to create UpvarDecl.
-    let upvar_debuginfo: Vec<_> = hir_tables
-        .upvar_list
-        .get(&fn_def_id)
-        .into_iter()
-        .flatten()
-        .map(|(&var_hir_id, &upvar_id)| {
-            let capture = hir_tables.upvar_capture(upvar_id);
-            let by_ref = match capture {
-                ty::UpvarCapture::ByValue => false,
-                ty::UpvarCapture::ByRef(..) => true,
-            };
-            let mut debuginfo = UpvarDebuginfo {
-                debug_name: kw::Invalid,
-                by_ref,
-            };
-            let mut mutability = Mutability::Not;
-            if let Some(Node::Binding(pat)) = tcx_hir.find(var_hir_id) {
-                if let hir::PatKind::Binding(_, _, ident, _) = pat.kind {
-                    debuginfo.debug_name = ident.name;
-                    if let Some(&bm) = hir.tables.pat_binding_modes().get(pat.hir_id) {
-                        if bm == ty::BindByValue(hir::Mutability::Mutable) {
-                            mutability = Mutability::Mut;
-                        } else {
-                            mutability = Mutability::Not;
-                        }
-                    } else {
-                        tcx.sess.delay_span_bug(pat.span, "missing binding mode");
-                    }
-                }
-            }
-            upvar_mutbls.push(mutability);
-            debuginfo
-        })
-        .collect();
-
     let mut builder = Builder::new(hir,
         span,
         arguments.len(),
         safety,
         return_ty,
         return_ty_span,
-        upvar_debuginfo,
-        upvar_mutbls,
         body.generator_kind.is_some());
 
     let call_site_scope = region::Scope {
@@ -631,7 +597,7 @@ fn construct_fn<'a, 'tcx, A>(
             Place::return_place(),
             |builder| {
                 builder.in_scope(arg_scope_s, LintLevel::Inherited, |builder| {
-                    builder.args_and_body(block, &arguments, arg_scope, &body.value)
+                    builder.args_and_body(block, fn_def_id, &arguments, arg_scope, &body.value)
                 })
             },
         ));
@@ -660,7 +626,7 @@ fn construct_fn<'a, 'tcx, A>(
     info!("fn_id {:?} has attrs {:?}", fn_def_id,
           tcx.get_attrs(fn_def_id));
 
-    let mut body = builder.finish(yield_ty);
+    let mut body = builder.finish();
     body.spread_arg = spread_arg;
     body
 }
@@ -681,8 +647,6 @@ fn construct_const<'a, 'tcx>(
         Safety::Safe,
         const_ty,
         const_ty_span,
-        vec![],
-        vec![],
         false,
     );
 
@@ -704,7 +668,7 @@ fn construct_const<'a, 'tcx>(
                               TerminatorKind::Unreachable);
     }
 
-    builder.finish(None)
+    builder.finish()
 }
 
 fn construct_error<'a, 'tcx>(
@@ -714,10 +678,10 @@ fn construct_error<'a, 'tcx>(
     let owner_id = hir.tcx().hir().body_owner(body_id);
     let span = hir.tcx().hir().span(owner_id);
     let ty = hir.tcx().types.err;
-    let mut builder = Builder::new(hir, span, 0, Safety::Safe, ty, span, vec![], vec![], false);
+    let mut builder = Builder::new(hir, span, 0, Safety::Safe, ty, span, false);
     let source_info = builder.source_info(span);
     builder.cfg.terminate(START_BLOCK, source_info, TerminatorKind::Unreachable);
-    builder.finish(None)
+    builder.finish()
 }
 
 impl<'a, 'tcx> Builder<'a, 'tcx> {
@@ -727,8 +691,6 @@ fn new(hir: Cx<'a, 'tcx>,
            safety: Safety,
            return_ty: Ty<'tcx>,
            return_span: Span,
-           __upvar_debuginfo_codegen_only_do_not_use: Vec<UpvarDebuginfo>,
-           upvar_mutbls: Vec<Mutability>,
            is_generator: bool)
            -> Builder<'a, 'tcx> {
         let lint_level = LintLevel::Explicit(hir.root_lint_level);
@@ -751,10 +713,10 @@ fn new(hir: Cx<'a, 'tcx>,
                 1,
             ),
             canonical_user_type_annotations: IndexVec::new(),
-            __upvar_debuginfo_codegen_only_do_not_use,
-            upvar_mutbls,
+            upvar_mutbls: vec![],
             var_indices: Default::default(),
             unit_temp: None,
+            var_debug_info: vec![],
             cached_resume_block: None,
             cached_return_block: None,
             cached_unreachable_block: None,
@@ -769,9 +731,7 @@ fn new(hir: Cx<'a, 'tcx>,
         builder
     }
 
-    fn finish(self,
-              yield_ty: Option<Ty<'tcx>>)
-              -> Body<'tcx> {
+    fn finish(self) -> Body<'tcx> {
         for (index, block) in self.cfg.basic_blocks.iter().enumerate() {
             if block.terminator.is_none() {
                 span_bug!(self.fn_span, "no terminator on block {:?}", index);
@@ -782,11 +742,10 @@ fn finish(self,
             self.cfg.basic_blocks,
             self.source_scopes,
             ClearCrossCrate::Set(self.source_scope_local_data),
-            yield_ty,
             self.local_decls,
             self.canonical_user_type_annotations,
             self.arg_count,
-            self.__upvar_debuginfo_codegen_only_do_not_use,
+            self.var_debug_info,
             self.fn_span,
             self.hir.control_flow_destroyed(),
         )
@@ -794,6 +753,7 @@ fn finish(self,
 
     fn args_and_body(&mut self,
                      mut block: BasicBlock,
+                     fn_def_id: DefId,
                      arguments: &[ArgInfo<'tcx>],
                      argument_scope: region::Scope,
                      ast_body: &'tcx hir::Expr)
@@ -801,28 +761,100 @@ fn args_and_body(&mut self,
     {
         // Allocate locals for the function arguments
         for &ArgInfo(ty, _, arg_opt, _) in arguments.iter() {
-            // If this is a simple binding pattern, give the local a name for
-            // debuginfo and so that error reporting knows that this is a user
-            // variable. For any other pattern the pattern introduces new
-            // variables which will be named instead.
-            let (name, span) = if let Some(arg) = arg_opt {
-                (arg.pat.simple_ident().map(|ident| ident.name), arg.pat.span)
-            } else {
-                (None, self.fn_span)
+            let source_info = SourceInfo {
+                scope: OUTERMOST_SOURCE_SCOPE,
+                span: arg_opt.map_or(self.fn_span, |arg| arg.pat.span)
             };
-
-            let source_info = SourceInfo { scope: OUTERMOST_SOURCE_SCOPE, span, };
-            self.local_decls.push(LocalDecl {
+            let arg_local = self.local_decls.push(LocalDecl {
                 mutability: Mutability::Mut,
                 ty,
                 user_ty: UserTypeProjections::none(),
                 source_info,
-                visibility_scope: source_info.scope,
-                name,
                 internal: false,
                 local_info: LocalInfo::Other,
                 is_block_tail: None,
             });
+
+            // If this is a simple binding pattern, give debuginfo a nice name.
+            if let Some(arg) = arg_opt {
+                if let Some(ident) = arg.pat.simple_ident() {
+                    self.var_debug_info.push(VarDebugInfo {
+                        name: ident.name,
+                        source_info,
+                        place: arg_local.into(),
+                    });
+                }
+            }
+        }
+
+        let tcx = self.hir.tcx();
+        let tcx_hir = tcx.hir();
+        let hir_tables = self.hir.tables();
+
+        // In analyze_closure() in upvar.rs we gathered a list of upvars used by a
+        // closure and we stored in a map called upvar_list in TypeckTables indexed
+        // with the closure's DefId. Here, we run through that vec of UpvarIds for
+        // the given closure and use the necessary information to create upvar
+        // debuginfo and to fill `self.upvar_mutbls`.
+        if let Some(upvars) = hir_tables.upvar_list.get(&fn_def_id) {
+            let closure_env_arg = Local::new(1);
+            let mut closure_env_projs = vec![];
+            let mut closure_ty = self.local_decls[closure_env_arg].ty;
+            if let ty::Ref(_, ty, _) = closure_ty.kind {
+                closure_env_projs.push(ProjectionElem::Deref);
+                closure_ty = ty;
+            }
+            let (def_id, upvar_substs) = match closure_ty.kind {
+                ty::Closure(def_id, substs) => (def_id, ty::UpvarSubsts::Closure(substs)),
+                ty::Generator(def_id, substs, _) => (def_id, ty::UpvarSubsts::Generator(substs)),
+                _ => span_bug!(self.fn_span, "upvars with non-closure env ty {:?}", closure_ty)
+            };
+            let upvar_tys = upvar_substs.upvar_tys(def_id, tcx);
+            let upvars_with_tys = upvars.iter().zip(upvar_tys);
+            self.upvar_mutbls = upvars_with_tys.enumerate().map(|(i, ((&var_id, &upvar_id), ty))| {
+                let capture = hir_tables.upvar_capture(upvar_id);
+
+                let mut mutability = Mutability::Not;
+                let mut name = kw::Invalid;
+                if let Some(Node::Binding(pat)) = tcx_hir.find(var_id) {
+                    if let hir::PatKind::Binding(_, _, ident, _) = pat.kind {
+                        name = ident.name;
+
+                        if let Some(&bm) = hir_tables.pat_binding_modes().get(pat.hir_id) {
+                            if bm == ty::BindByValue(hir::Mutability::Mutable) {
+                                mutability = Mutability::Mut;
+                            } else {
+                                mutability = Mutability::Not;
+                            }
+                        } else {
+                            tcx.sess.delay_span_bug(pat.span, "missing binding mode");
+                        }
+                    }
+                }
+
+                let mut projs = closure_env_projs.clone();
+                projs.push(ProjectionElem::Field(Field::new(i), ty));
+                match capture {
+                    ty::UpvarCapture::ByValue => {}
+                    ty::UpvarCapture::ByRef(..) => {
+                        projs.push(ProjectionElem::Deref);
+                    }
+                };
+
+                self.var_debug_info.push(VarDebugInfo {
+                    name,
+                    source_info: SourceInfo {
+                        scope: OUTERMOST_SOURCE_SCOPE,
+                        span: tcx_hir.span(var_id),
+                    },
+                    place: Place {
+                        base: closure_env_arg.into(),
+                        projection: tcx.intern_place_elems(&projs),
+                    },
+                });
+
+                mutability
+            }).collect();
         }
 
         let mut scope = None;
index 2be27e41090a65151c4e34096b81edaae5ad5aab..626e81fa91186f51805acb108053987504356085 100644 (file)
@@ -733,7 +733,9 @@ pub(super) fn deallocate_local(
         if let LocalValue::Live(Operand::Indirect(MemPlace { ptr, .. })) = local {
             trace!("deallocating local");
             let ptr = ptr.to_ptr()?;
-            self.memory.dump_alloc(ptr.alloc_id);
+            if log_enabled!(::log::Level::Trace) {
+                self.memory.dump_alloc(ptr.alloc_id);
+            }
             self.memory.deallocate_local(ptr)?;
         };
         Ok(())
index 68bb0a3e435df1c386b5bfe37d08e2bd58c5eace..630f3f603449bb0fccd84250324ac0a39a934bc4 100644 (file)
@@ -3,22 +3,34 @@
 //! After a const evaluation has computed a value, before we destroy the const evaluator's session
 //! memory, we need to extract all memory allocations to the global memory pool so they stay around.
 
-use rustc::ty::{Ty, self};
-use rustc::mir::interpret::{InterpResult, ErrorHandled};
-use rustc::hir;
 use super::validity::RefTracking;
-use rustc_data_structures::fx::FxHashSet;
+use rustc::hir;
+use rustc::mir::interpret::{ErrorHandled, InterpResult};
+use rustc::ty::{self, Ty};
+use rustc_data_structures::fx::{FxHashMap, FxHashSet};
 
 use syntax::ast::Mutability;
 
 use super::{
-    ValueVisitor, MemoryKind, AllocId, MPlaceTy, Scalar,
+    AllocId, Allocation, InterpCx, Machine, MemoryKind, MPlaceTy, Scalar, ValueVisitor,
 };
-use crate::const_eval::{CompileTimeInterpreter, CompileTimeEvalContext};
 
-struct InternVisitor<'rt, 'mir, 'tcx> {
+pub trait CompileTimeMachine<'mir, 'tcx> =
+    Machine<
+        'mir,
+        'tcx,
+        MemoryKinds = !,
+        PointerTag = (),
+        ExtraFnVal = !,
+        FrameExtra = (),
+        MemoryExtra = (),
+        AllocExtra = (),
+        MemoryMap = FxHashMap<AllocId, (MemoryKind<!>, Allocation)>,
+    >;
+
+struct InternVisitor<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx>> {
     /// The ectx from which we intern.
-    ecx: &'rt mut CompileTimeEvalContext<'mir, 'tcx>,
+    ecx: &'rt mut InterpCx<'mir, 'tcx, M>,
     /// Previously encountered safe references.
     ref_tracking: &'rt mut RefTracking<(MPlaceTy<'tcx>, Mutability, InternMode)>,
     /// A list of all encountered allocations. After type-based interning, we traverse this list to
@@ -58,18 +70,15 @@ enum InternMode {
 /// `immutable` things might become mutable if `ty` is not frozen.
 /// `ty` can be `None` if there is no potential interior mutability
 /// to account for (e.g. for vtables).
-fn intern_shallow<'rt, 'mir, 'tcx>(
-    ecx: &'rt mut CompileTimeEvalContext<'mir, 'tcx>,
+fn intern_shallow<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx>>(
+    ecx: &'rt mut InterpCx<'mir, 'tcx, M>,
     leftover_allocations: &'rt mut FxHashSet<AllocId>,
     mode: InternMode,
     alloc_id: AllocId,
     mutability: Mutability,
     ty: Option<Ty<'tcx>>,
 ) -> InterpResult<'tcx, Option<IsStaticOrFn>> {
-    trace!(
-        "InternVisitor::intern {:?} with {:?}",
-        alloc_id, mutability,
-    );
+    trace!("InternVisitor::intern {:?} with {:?}", alloc_id, mutability,);
     // remove allocation
     let tcx = ecx.tcx;
     let (kind, mut alloc) = match ecx.memory.alloc_map.remove(&alloc_id) {
@@ -130,7 +139,7 @@ fn intern_shallow<'rt, 'mir, 'tcx>(
     Ok(None)
 }
 
-impl<'rt, 'mir, 'tcx> InternVisitor<'rt, 'mir, 'tcx> {
+impl<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx>> InternVisitor<'rt, 'mir, 'tcx, M> {
     fn intern_shallow(
         &mut self,
         alloc_id: AllocId,
@@ -148,15 +157,15 @@ fn intern_shallow(
     }
 }
 
-impl<'rt, 'mir, 'tcx>
-    ValueVisitor<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>>
+impl<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx>>
+    ValueVisitor<'mir, 'tcx, M>
 for
-    InternVisitor<'rt, 'mir, 'tcx>
+    InternVisitor<'rt, 'mir, 'tcx, M>
 {
     type V = MPlaceTy<'tcx>;
 
     #[inline(always)]
-    fn ecx(&self) -> &CompileTimeEvalContext<'mir, 'tcx> {
+    fn ecx(&self) -> &InterpCx<'mir, 'tcx, M> {
         &self.ecx
     }
 
@@ -265,8 +274,8 @@ fn visit_primitive(&mut self, mplace: MPlaceTy<'tcx>) -> InterpResult<'tcx> {
     }
 }
 
-pub fn intern_const_alloc_recursive(
-    ecx: &mut CompileTimeEvalContext<'mir, 'tcx>,
+pub fn intern_const_alloc_recursive<M: CompileTimeMachine<'mir, 'tcx>>(
+    ecx: &mut InterpCx<'mir, 'tcx, M>,
     // The `mutability` of the place, ignoring the type.
     place_mut: Option<hir::Mutability>,
     ret: MPlaceTy<'tcx>,
index 842ef915ad2267025cfa1a5a6ba945eeadd58f75..eccdc5b03261b8dbbe8f47ba040d1b434e2cb09c 100644 (file)
@@ -635,7 +635,9 @@ pub fn mark_immutable(&mut self, id: AllocId) -> InterpResult<'tcx> {
         Ok(())
     }
 
-    /// For debugging, print an allocation and all allocations it points to, recursively.
+    /// Print an allocation and all allocations it points to, recursively.
+    /// This prints directly to stderr, ignoring RUSTC_LOG! It is up to the caller to
+    /// control for this.
     pub fn dump_alloc(&self, id: AllocId) {
         self.dump_allocs(vec![id]);
     }
@@ -674,7 +676,7 @@ fn dump_alloc_helper<Tag, Extra>(
             }
         }
 
-        trace!(
+        eprintln!(
             "{}({} bytes, alignment {}){}",
             msg,
             alloc.size.bytes(),
@@ -695,15 +697,14 @@ fn dump_alloc_helper<Tag, Extra>(
                 write!(msg, "└{0:─^1$}┘ ", target, relocation_width as usize).unwrap();
                 pos = i + self.pointer_size();
             }
-            trace!("{}", msg);
+            eprintln!("{}", msg);
         }
     }
 
-    /// For debugging, print a list of allocations and all allocations they point to, recursively.
+    /// Print a list of allocations and all allocations they point to, recursively.
+    /// This prints directly to stderr, ignoring RUSTC_LOG! It is up to the caller to
+    /// control for this.
     pub fn dump_allocs(&self, mut allocs: Vec<AllocId>) {
-        if !log_enabled!(::log::Level::Trace) {
-            return;
-        }
         allocs.sort();
         allocs.dedup();
         let mut allocs_to_print = VecDeque::from(allocs);
@@ -735,13 +736,13 @@ pub fn dump_allocs(&self, mut allocs: Vec<AllocId>) {
                             );
                         }
                         Some(GlobalAlloc::Function(func)) => {
-                            trace!("{} {}", msg, func);
+                            eprintln!("{} {}", msg, func);
                         }
                         Some(GlobalAlloc::Static(did)) => {
-                            trace!("{} {:?}", msg, did);
+                            eprintln!("{} {:?}", msg, did);
                         }
                         None => {
-                            trace!("{} (deallocated)", msg);
+                            eprintln!("{} (deallocated)", msg);
                         }
                     }
                 },
@@ -751,12 +752,14 @@ pub fn dump_allocs(&self, mut allocs: Vec<AllocId>) {
     }
 
     pub fn leak_report(&self) -> usize {
-        trace!("### LEAK REPORT ###");
         let leaks: Vec<_> = self.alloc_map.filter_map_collect(|&id, &(kind, _)| {
             if kind.may_leak() { None } else { Some(id) }
         });
         let n = leaks.len();
-        self.dump_allocs(leaks);
+        if n > 0 {
+            eprintln!("### LEAK REPORT ###");
+            self.dump_allocs(leaks);
+        }
         n
     }
 
index 4f03b1320903a48f2eeee8fe52c0be58435514ba..8dd5807f7cfbfa85fc7237d4860ae46fc9a675d9 100644 (file)
@@ -27,7 +27,7 @@
 /// operations and fat pointers. This idea was taken from rustc's codegen.
 /// In particular, thanks to `ScalarPair`, arithmetic operations and casts can be entirely
 /// defined on `Immediate`, and do not have to work with a `Place`.
-#[derive(Copy, Clone, Debug, PartialEq, Eq, HashStable)]
+#[derive(Copy, Clone, Debug, PartialEq, Eq, HashStable, Hash)]
 pub enum Immediate<Tag=(), Id=AllocId> {
     Scalar(ScalarMaybeUndef<Tag, Id>),
     ScalarPair(ScalarMaybeUndef<Tag, Id>, ScalarMaybeUndef<Tag, Id>),
@@ -104,7 +104,7 @@ fn deref(&self) -> &Immediate<Tag> {
 /// An `Operand` is the result of computing a `mir::Operand`. It can be immediate,
 /// or still in memory. The latter is an optimization, to delay reading that chunk of
 /// memory and to avoid having to store arbitrary-sized data here.
-#[derive(Copy, Clone, Debug, PartialEq, Eq, HashStable)]
+#[derive(Copy, Clone, Debug, PartialEq, Eq, HashStable, Hash)]
 pub enum Operand<Tag=(), Id=AllocId> {
     Immediate(Immediate<Tag, Id>),
     Indirect(MemPlace<Tag, Id>),
@@ -134,7 +134,7 @@ pub fn assert_immediate(self) -> Immediate<Tag>
     }
 }
 
-#[derive(Copy, Clone, Debug, PartialEq)]
+#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
 pub struct OpTy<'tcx, Tag=()> {
     op: Operand<Tag>, // Keep this private; it helps enforce invariants.
     pub layout: TyLayout<'tcx>,
index f2707969517fe132b93fed06c760cb3ed8dd303e..cca76700ed101fa812e52e0bd7f8e1488b982b41 100644 (file)
@@ -28,6 +28,7 @@
 #![feature(range_is_empty)]
 #![feature(stmt_expr_attributes)]
 #![feature(bool_to_option)]
+#![feature(trait_alias)]
 
 #![recursion_limit="256"]
 
index 17f5e3d4e47a982a990117e2cb680e505da784da..b5cb6a92816beb656c7985e050324ca8b78b0e5a 100644 (file)
@@ -148,9 +148,7 @@ fn temp_decl(mutability: Mutability, ty: Ty<'_>, span: Span) -> LocalDecl<'_> {
         mutability,
         ty,
         user_ty: UserTypeProjections::none(),
-        name: None,
         source_info,
-        visibility_scope: source_info.scope,
         internal: false,
         local_info: LocalInfo::Other,
         is_block_tail: None,
@@ -204,7 +202,6 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option<Ty<'tcx>>)
             SourceScopeData { span: span, parent_scope: None }, 1
         ),
         ClearCrossCrate::Clear,
-        None,
         local_decls_for_sig(&sig, span),
         IndexVec::new(),
         sig.inputs().len(),
@@ -371,7 +368,6 @@ fn into_mir(self) -> Body<'tcx> {
                 SourceScopeData { span: self.span, parent_scope: None }, 1
             ),
             ClearCrossCrate::Clear,
-            None,
             self.local_decls,
             IndexVec::new(),
             self.sig.inputs().len(),
@@ -832,7 +828,6 @@ fn build_call_shim<'tcx>(
             SourceScopeData { span: span, parent_scope: None }, 1
         ),
         ClearCrossCrate::Clear,
-        None,
         local_decls,
         IndexVec::new(),
         sig.inputs().len(),
@@ -919,7 +914,6 @@ pub fn build_adt_ctor(tcx: TyCtxt<'_>, ctor_id: DefId) -> &Body<'_> {
             SourceScopeData { span: span, parent_scope: None }, 1
         ),
         ClearCrossCrate::Clear,
-        None,
         local_decls,
         IndexVec::new(),
         sig.inputs().len(),
index 1114694d2e335aebcc5bef3e231bd8724bbeaa3d..8de16308e8375c950e24fb05fdbce3684f721613 100644 (file)
@@ -30,7 +30,7 @@
     self, InterpCx, ScalarMaybeUndef, Immediate, OpTy,
     StackPopCleanup, LocalValue, LocalState, AllocId, Frame,
     Allocation, MemoryKind, ImmTy, Pointer, Memory, PlaceTy,
-    Operand as InterpOperand,
+    Operand as InterpOperand, intern_const_alloc_recursive,
 };
 use crate::const_eval::error_to_const_error;
 use crate::transform::{MirPass, MirSource};
@@ -85,7 +85,6 @@ fn run_pass(&self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut Body<'
                 body.basic_blocks().clone(),
                 Default::default(),
                 ClearCrossCrate::Clear,
-                None,
                 body.local_decls.clone(),
                 Default::default(),
                 body.arg_count,
@@ -647,9 +646,9 @@ fn replace_with_const(
     }
 
     fn should_const_prop(&mut self, op: OpTy<'tcx>) -> bool {
-        if self.tcx.sess.opts.debugging_opts.mir_opt_level >= 2 {
-            return true;
-        } else if self.tcx.sess.opts.debugging_opts.mir_opt_level == 0 {
+        let mir_opt_level = self.tcx.sess.opts.debugging_opts.mir_opt_level;
+
+        if mir_opt_level == 0 {
             return false;
         }
 
@@ -659,6 +658,14 @@ fn should_const_prop(&mut self, op: OpTy<'tcx>) -> bool {
             interpret::Operand::Immediate(Immediate::ScalarPair(ScalarMaybeUndef::Scalar(l),
                                                                 ScalarMaybeUndef::Scalar(r))) =>
                 l.is_bits() && r.is_bits(),
+            interpret::Operand::Indirect(_) if mir_opt_level >= 2 => {
+                intern_const_alloc_recursive(
+                    &mut self.ecx,
+                    None,
+                    op.assert_mem_place()
+                ).expect("failed to intern alloc");
+                true
+            },
             _ => false
         }
     }
index 524b6b087908ce4b7ac57ac5e5e0ba79cac3a6f8..a904c6a3ada0f644292b2c2546cad8c7ca316a58 100644 (file)
@@ -62,7 +62,6 @@
 use rustc_index::bit_set::{BitSet, BitMatrix};
 use std::borrow::Cow;
 use std::iter;
-use std::mem;
 use crate::transform::{MirPass, MirSource};
 use crate::transform::simplify;
 use crate::transform::no_landing_pads::no_landing_pads;
@@ -427,9 +426,7 @@ fn replace_result_variable<'tcx>(
         mutability: Mutability::Mut,
         ty: ret_ty,
         user_ty: UserTypeProjections::none(),
-        name: None,
         source_info,
-        visibility_scope: source_info.scope,
         internal: false,
         is_block_tail: None,
         local_info: LocalInfo::Other
@@ -788,18 +785,12 @@ fn compute_layout<'tcx>(
         }
     }
 
-    let dummy_local = LocalDecl::new_internal(tcx.mk_unit(), body.span);
-
-    // Gather live locals and their indices replacing values in body.local_decls
-    // with a dummy to avoid changing local indices.
+    // Gather live local types and their indices.
     let mut locals = IndexVec::<GeneratorSavedLocal, _>::new();
     let mut tys = IndexVec::<GeneratorSavedLocal, _>::new();
-    let mut decls = IndexVec::<GeneratorSavedLocal, _>::new();
     for (idx, local) in live_locals.iter().enumerate() {
-        let var = mem::replace(&mut body.local_decls[local], dummy_local.clone());
         locals.push(local);
-        tys.push(var.ty);
-        decls.push(var);
+        tys.push(body.local_decls[local].ty);
         debug!("generator saved local {:?} => {:?}", GeneratorSavedLocal::from(idx), local);
     }
 
@@ -831,7 +822,6 @@ fn compute_layout<'tcx>(
         field_tys: tys,
         variant_fields,
         storage_conflicts,
-        __local_debuginfo_codegen_only_do_not_use: decls,
     };
 
     (remap, layout, storage_liveness)
@@ -962,9 +952,7 @@ fn create_generator_drop_shim<'tcx>(
         mutability: Mutability::Mut,
         ty: tcx.mk_unit(),
         user_ty: UserTypeProjections::none(),
-        name: None,
         source_info,
-        visibility_scope: source_info.scope,
         internal: false,
         is_block_tail: None,
         local_info: LocalInfo::Other
@@ -980,9 +968,7 @@ fn create_generator_drop_shim<'tcx>(
             mutbl: hir::Mutability::Mutable,
         }),
         user_ty: UserTypeProjections::none(),
-        name: None,
         source_info,
-        visibility_scope: source_info.scope,
         internal: false,
         is_block_tail: None,
         local_info: LocalInfo::Other
index 5a34e3f471f666dc426f653029901cc7deb82d99..867673beb35ccd8e49003cf89a47b44e232d518d 100644 (file)
@@ -219,13 +219,6 @@ fn should_inline(&self,
         debug!("should_inline({:?})", callsite);
         let tcx = self.tcx;
 
-        // Don't inline closures that have capture debuginfo
-        // FIXME: Handle closures better
-        if callee_body.__upvar_debuginfo_codegen_only_do_not_use.len() > 0 {
-            debug!("    upvar debuginfo present - not inlining");
-            return false;
-        }
-
         // Cannot inline generators which haven't been transformed yet
         if callee_body.yield_ty.is_some() {
             debug!("    yield ty present - not inlining");
@@ -413,7 +406,6 @@ fn inline_call(&self,
                     local.source_info.scope =
                         scope_map[local.source_info.scope];
                     local.source_info.span = callsite.location.span;
-                    local.visibility_scope = scope_map[local.visibility_scope];
 
                     let idx = caller_body.local_decls.push(local);
                     local_map.push(idx);
@@ -484,6 +476,10 @@ fn dest_needs_borrow(place: &Place<'_>) -> bool {
                     tcx: self.tcx,
                 };
 
+                for mut var_debug_info in callee_body.var_debug_info.drain(..) {
+                    integrator.visit_var_debug_info(&mut var_debug_info);
+                    caller_body.var_debug_info.push(var_debug_info);
+                }
 
                 for (bb, mut block) in callee_body.basic_blocks_mut().drain_enumerated(..) {
                     integrator.visit_basic_block_data(bb, &mut block);
index 86ecfbb4fbea59af92f71b2bb0bf1ca70ba89b5d..c92c59dd2f79caed942c748b3af26070eae584c4 100644 (file)
@@ -1098,7 +1098,6 @@ pub fn promote_candidates<'tcx>(
                 // memory usage?
                 body.source_scopes.clone(),
                 body.source_scope_local_data.clone(),
-                None,
                 initial_locals,
                 IndexVec::new(),
                 0,
index 71f13c169d41eb12d278495f3a3581cc33864288..81f4c277f4d76746146b02db115dda17cef98ca7 100644 (file)
@@ -337,6 +337,9 @@ fn check_terminator(
             check_operand(tcx, discr, span, def_id, body)
         }
 
+        // FIXME(ecstaticmorse): We probably want to allow `Unreachable` unconditionally.
+        TerminatorKind::Unreachable if tcx.features().const_if_match => Ok(()),
+
         | TerminatorKind::Abort | TerminatorKind::Unreachable => {
             Err((span, "const fn with unreachable code is not stable".into()))
         }
index f6b09f20bab679976b7af399128144c01a3c6670..c9185d14148c129bd5fea8f409a3f194d6305acf 100644 (file)
@@ -32,7 +32,6 @@
 use rustc::ty::TyCtxt;
 use rustc::mir::*;
 use rustc::mir::visit::{MutVisitor, Visitor, PlaceContext, MutatingUseContext};
-use rustc::session::config::DebugInfo;
 use std::borrow::Cow;
 use crate::transform::{MirPass, MirSource};
 
@@ -307,13 +306,6 @@ fn run_pass(&self, tcx: TyCtxt<'tcx>, source: MirSource<'tcx>, body: &mut Body<'
                 marker.locals.insert(arg);
             }
 
-            // We may need to keep dead user variables live for debuginfo.
-            if tcx.sess.opts.debuginfo == DebugInfo::Full {
-                for local in body.vars_iter() {
-                    marker.locals.insert(local);
-                }
-            }
-
             marker.locals
         };
 
index e4c2f7d389b502d1a5f7f61cbcff7271ea47e634..28f68ac2de037dccadfcee9f33e62ced3987c333 100644 (file)
@@ -362,6 +362,7 @@ fn visit_local(&mut self,
         match context {
             PlaceContext::NonUse(NonUseContext::StorageLive) => local_use.alive = Some(location),
             PlaceContext::NonUse(NonUseContext::StorageDead) => local_use.dead = Some(location),
+            PlaceContext::NonUse(NonUseContext::VarDebugInfo) => {}
             _ => {
                 local_use.use_count += 1;
                 if local_use.first_use.is_none() {
index 725ec84ca62370682bac1276583acf0c7ce11bb6..1611caddad1a6fe5344c91a40a6c4d44fbf54c33 100644 (file)
@@ -1,6 +1,6 @@
 //! Def-use analysis.
 
-use rustc::mir::{Body, Local, Location, PlaceElem};
+use rustc::mir::{Body, Local, Location, PlaceElem, VarDebugInfo};
 use rustc::mir::visit::{PlaceContext, MutVisitor, Visitor};
 use rustc::ty::TyCtxt;
 use rustc_index::vec::IndexVec;
@@ -12,7 +12,9 @@ pub struct DefUseAnalysis {
 
 #[derive(Clone)]
 pub struct Info {
+    // FIXME(eddyb) use smallvec where possible.
     pub defs_and_uses: Vec<Use>,
+    var_debug_info_indices: Vec<usize>,
 }
 
 #[derive(Clone)]
@@ -33,6 +35,8 @@ pub fn analyze(&mut self, body: &Body<'_>) {
 
         let mut finder = DefUseFinder {
             info: mem::take(&mut self.info),
+            var_debug_info_index: 0,
+            in_var_debug_info: false,
         };
         finder.visit_body(body);
         self.info = finder.info
@@ -55,9 +59,14 @@ fn mutate_defs_and_uses(
         new_local: Local,
         tcx: TyCtxt<'tcx>,
     ) {
-        for place_use in &self.info[local].defs_and_uses {
-            MutateUseVisitor::new(local, new_local, body, tcx)
-                .visit_location(body, place_use.location)
+        let mut visitor = MutateUseVisitor::new(local, new_local, body, tcx);
+        let info = &self.info[local];
+        for place_use in &info.defs_and_uses {
+            visitor.visit_location(body, place_use.location)
+        }
+        // Update debuginfo as well, alongside defs/uses.
+        for &i in &info.var_debug_info_indices {
+            visitor.visit_var_debug_info(&mut body.var_debug_info[i]);
         }
     }
 
@@ -73,6 +82,8 @@ pub fn replace_all_defs_and_uses_with(&self,
 
 struct DefUseFinder {
     info: IndexVec<Local, Info>,
+    var_debug_info_index: usize,
+    in_var_debug_info: bool,
 }
 
 impl Visitor<'_> for DefUseFinder {
@@ -80,10 +91,22 @@ fn visit_local(&mut self,
                    &local: &Local,
                    context: PlaceContext,
                    location: Location) {
-        self.info[local].defs_and_uses.push(Use {
-            context,
-            location,
-        });
+        let info = &mut self.info[local];
+        if self.in_var_debug_info {
+            info.var_debug_info_indices.push(self.var_debug_info_index);
+        } else {
+            info.defs_and_uses.push(Use {
+                context,
+                location,
+            });
+        }
+    }
+    fn visit_var_debug_info(&mut self, var_debug_info: &VarDebugInfo<'tcx>) {
+        assert!(!self.in_var_debug_info);
+        self.in_var_debug_info = true;
+        self.super_var_debug_info(var_debug_info);
+        self.in_var_debug_info = false;
+        self.var_debug_info_index += 1;
     }
 }
 
@@ -91,11 +114,13 @@ impl Info {
     fn new() -> Info {
         Info {
             defs_and_uses: vec![],
+            var_debug_info_indices: vec![],
         }
     }
 
     fn clear(&mut self) {
         self.defs_and_uses.clear();
+        self.var_debug_info_indices.clear();
     }
 
     pub fn def_count(&self) -> usize {
index ff2946d3a690e1cdbbe56a118d354c5957b34b47..3a7ec9f038aa59023dbf8cfd42cf05329069d579 100644 (file)
@@ -197,13 +197,13 @@ fn write_graph_label<'tcx, W: Write>(
             write!(w, "mut ")?;
         }
 
-        if let Some(name) = decl.name {
-            write!(w, r#"{:?}: {}; // {}<br align="left"/>"#,
-                   Place::from(local), escape(&decl.ty), name)?;
-        } else {
-            write!(w, r#"{:?}: {};<br align="left"/>"#,
-                   Place::from(local), escape(&decl.ty))?;
-        }
+        write!(w, r#"{:?}: {};<br align="left"/>"#,
+               Place::from(local), escape(&decl.ty))?;
+    }
+
+    for var_debug_info in &body.var_debug_info {
+        write!(w, r#"debug {} => {};<br align="left"/>"#,
+               var_debug_info.name, escape(&var_debug_info.place))?;
     }
 
     writeln!(w, ">;")
index 9757f4ac392ec8d8e273f9417f6d99cb8f587b33..63e4af0a56a75c8cda085b11dd7955ca2caa10be 100644 (file)
@@ -183,6 +183,9 @@ pub fn categorize(context: PlaceContext) -> Option<DefUse> {
 
         PlaceContext::MutatingUse(MutatingUseContext::Drop) =>
             Some(DefUse::Drop),
+
+        // Debug info is neither def nor use.
+        PlaceContext::NonUse(NonUseContext::VarDebugInfo) => None,
     }
 }
 
index 89f298846d2f5ad6bc909384279d9d7922231d42..36194335a555a6098367417e112386dd9aff24ea 100644 (file)
@@ -463,6 +463,30 @@ fn write_scope_tree(
 ) -> io::Result<()> {
     let indent = depth * INDENT.len();
 
+    // Local variable debuginfo.
+    for var_debug_info in &body.var_debug_info {
+        if var_debug_info.source_info.scope != parent {
+            // Not declared in this scope.
+            continue;
+        }
+
+        let indented_debug_info = format!(
+            "{0:1$}debug {2} => {3:?};",
+            INDENT,
+            indent,
+            var_debug_info.name,
+            var_debug_info.place,
+        );
+
+        writeln!(
+            w,
+            "{0:1$} // in {2}",
+            indented_debug_info,
+            ALIGN,
+            comment(tcx, var_debug_info.source_info),
+        )?;
+    }
+
     // Local variable types (including the user's name in a comment).
     for (local, local_decl) in body.local_decls.iter_enumerated() {
         if (1..body.arg_count+1).contains(&local.index()) {
@@ -496,8 +520,6 @@ fn write_scope_tree(
 
         let local_name = if local == RETURN_PLACE {
             format!(" return place")
-        } else if let Some(name) = local_decl.name {
-            format!(" \"{}\"", name)
         } else {
             String::new()
         };
index 2c9d4004226c74b5c9a853850db244e2ee128add..c613d361d39a85d229748716b515a460f6f6e485 100644 (file)
@@ -7,7 +7,7 @@
 use syntax::ast::{ItemKind, ImplItem, ImplItemKind, TraitItem, TraitItemKind, UseTree, UseTreeKind};
 use syntax::ast::{PathSegment, IsAuto, Constness, IsAsync, Unsafety, Defaultness, Extern, StrLit};
 use syntax::ast::{Visibility, VisibilityKind, Mutability, FnHeader, ForeignItem, ForeignItemKind};
-use syntax::ast::{Ty, TyKind, Generics, TraitRef, EnumDef, VariantData, StructField};
+use syntax::ast::{Ty, TyKind, Generics, TraitRef, EnumDef, Variant, VariantData, StructField};
 use syntax::ast::{Mac, MacDelimiter, Block, BindingMode, FnDecl, FnSig, SelfKind, Param};
 use syntax::print::pprust;
 use syntax::ptr::P;
@@ -491,9 +491,12 @@ pub(super) fn is_async_fn(&self) -> bool {
     }
 
     /// Parses a macro invocation inside a `trait`, `impl` or `extern` block.
-    fn parse_assoc_macro_invoc(&mut self, item_kind: &str, vis: Option<&Visibility>,
-                               at_end: &mut bool) -> PResult<'a, Option<Mac>>
-    {
+    fn parse_assoc_macro_invoc(
+        &mut self,
+        item_kind: &str,
+        vis: Option<&Visibility>,
+        at_end: &mut bool,
+    ) -> PResult<'a, Option<Mac>> {
         if self.token.is_path_start() &&
                 !(self.is_async_fn() && self.token.span.rust_2015()) {
             let prev_span = self.prev_span;
@@ -532,9 +535,11 @@ fn parse_assoc_macro_invoc(&mut self, item_kind: &str, vis: Option<&Visibility>,
         }
     }
 
-    fn missing_assoc_item_kind_err(&self, item_type: &str, prev_span: Span)
-                                   -> DiagnosticBuilder<'a>
-    {
+    fn missing_assoc_item_kind_err(
+        &self,
+        item_type: &str,
+        prev_span: Span,
+    ) -> DiagnosticBuilder<'a> {
         let expected_kinds = if item_type == "extern" {
             "missing `fn`, `type`, or `static`"
         } else {
@@ -1324,85 +1329,65 @@ fn parse_item_enum(&mut self) -> PResult<'a, ItemInfo> {
         let id = self.parse_ident()?;
         let mut generics = self.parse_generics()?;
         generics.where_clause = self.parse_where_clause()?;
-        self.expect(&token::OpenDelim(token::Brace))?;
 
-        let enum_definition = self.parse_enum_def(&generics).map_err(|e| {
+        let (variants, _) = self.parse_delim_comma_seq(
+            token::Brace,
+            |p| p.parse_enum_item(),
+        ).map_err(|e| {
             self.recover_stmt();
-            self.eat(&token::CloseDelim(token::Brace));
             e
         })?;
+
+        let enum_definition = EnumDef {
+            variants: variants.into_iter().filter_map(|v| v).collect(),
+        };
         Ok((id, ItemKind::Enum(enum_definition, generics), None))
     }
 
-    /// Parses the part of an enum declaration following the `{`.
-    fn parse_enum_def(&mut self, _generics: &Generics) -> PResult<'a, EnumDef> {
-        let mut variants = Vec::new();
-        // FIXME: Consider using `parse_delim_comma_seq`.
-        // We could then remove eating comma in `recover_nested_adt_item`.
-        while self.token != token::CloseDelim(token::Brace) {
-            let variant_attrs = self.parse_outer_attributes()?;
-            let vlo = self.token.span;
-
-            let vis = self.parse_visibility(FollowedByType::No)?;
-            if !self.recover_nested_adt_item(kw::Enum)? {
-                // Item already parsed, we need to skip this variant.
-                continue
-            }
-            let ident = self.parse_ident()?;
+    fn parse_enum_item(&mut self) -> PResult<'a, Option<Variant>> {
+        let variant_attrs = self.parse_outer_attributes()?;
+        let vlo = self.token.span;
 
-            let struct_def = if self.check(&token::OpenDelim(token::Brace)) {
-                // Parse a struct variant.
-                let (fields, recovered) = self.parse_record_struct_body()?;
-                VariantData::Struct(fields, recovered)
-            } else if self.check(&token::OpenDelim(token::Paren)) {
-                VariantData::Tuple(
-                    self.parse_tuple_struct_body()?,
-                    DUMMY_NODE_ID,
-                )
-            } else {
-                VariantData::Unit(DUMMY_NODE_ID)
-            };
+        let vis = self.parse_visibility(FollowedByType::No)?;
+        if !self.recover_nested_adt_item(kw::Enum)? {
+            return Ok(None)
+        }
+        let ident = self.parse_ident()?;
 
-            let disr_expr = if self.eat(&token::Eq) {
-                Some(AnonConst {
-                    id: DUMMY_NODE_ID,
-                    value: self.parse_expr()?,
-                })
-            } else {
-                None
-            };
+        let struct_def = if self.check(&token::OpenDelim(token::Brace)) {
+            // Parse a struct variant.
+            let (fields, recovered) = self.parse_record_struct_body()?;
+            VariantData::Struct(fields, recovered)
+        } else if self.check(&token::OpenDelim(token::Paren)) {
+            VariantData::Tuple(
+                self.parse_tuple_struct_body()?,
+                DUMMY_NODE_ID,
+            )
+        } else {
+            VariantData::Unit(DUMMY_NODE_ID)
+        };
 
-            let vr = ast::Variant {
-                ident,
-                vis,
+        let disr_expr = if self.eat(&token::Eq) {
+            Some(AnonConst {
                 id: DUMMY_NODE_ID,
-                attrs: variant_attrs,
-                data: struct_def,
-                disr_expr,
-                span: vlo.to(self.prev_span),
-                is_placeholder: false,
-            };
-            variants.push(vr);
+                value: self.parse_expr()?,
+            })
+        } else {
+            None
+        };
 
-            if !self.eat(&token::Comma) {
-                if self.token.is_ident() && !self.token.is_reserved_ident() {
-                    let sp = self.sess.source_map().next_point(self.prev_span);
-                    self.struct_span_err(sp, "missing comma")
-                        .span_suggestion_short(
-                            sp,
-                            "missing comma",
-                            ",".to_owned(),
-                            Applicability::MaybeIncorrect,
-                        )
-                        .emit();
-                } else {
-                    break;
-                }
-            }
-        }
-        self.expect(&token::CloseDelim(token::Brace))?;
+        let vr = ast::Variant {
+            ident,
+            vis,
+            id: DUMMY_NODE_ID,
+            attrs: variant_attrs,
+            data: struct_def,
+            disr_expr,
+            span: vlo.to(self.prev_span),
+            is_placeholder: false,
+        };
 
-        Ok(ast::EnumDef { variants })
+        Ok(Some(vr))
     }
 
     /// Parses `struct Foo { ... }`.
@@ -1759,7 +1744,6 @@ fn recover_nested_adt_item(&mut self, keyword: Symbol) -> PResult<'a, bool> {
             let kw_token = self.token.clone();
             let kw_str = pprust::token_to_string(&kw_token);
             let item = self.parse_item()?;
-            self.eat(&token::Comma);
 
             self.struct_span_err(
                 kw_token.span,
index d810117662c655c0c60287f479957efd69e67181..ea7673767d07e811e76077eff81625edae754093 100644 (file)
@@ -805,21 +805,39 @@ fn parse_seq_to_before_tokens<T>(
                             recovered = true;
                             break;
                         }
-                        Err(mut e) => {
+                        Err(mut expect_err) => {
+                            let sp = self.sess.source_map().next_point(self.prev_span);
+                            let token_str = pprust::token_kind_to_string(t);
+
                             // Attempt to keep parsing if it was a similar separator.
                             if let Some(ref tokens) = t.similar_tokens() {
                                 if tokens.contains(&self.token.kind) {
                                     self.bump();
                                 }
                             }
-                            e.emit();
+
                             // Attempt to keep parsing if it was an omitted separator.
                             match f(self) {
                                 Ok(t) => {
+                                    // Parsed successfully, therefore most probably the code only
+                                    // misses a separator.
+                                    expect_err
+                                        .span_suggestion_short(
+                                            sp,
+                                            &format!("missing `{}`", token_str),
+                                            token_str,
+                                            Applicability::MaybeIncorrect,
+                                        )
+                                        .emit();
+
                                     v.push(t);
                                     continue;
                                 },
                                 Err(mut e) => {
+                                    // Parsing failed, therefore it must be something more serious
+                                    // than just a missing separator.
+                                    expect_err.emit();
+
                                     e.cancel();
                                     break;
                                 }
index 6140d0438d8a758dce6c65ea4e749c9c9557a250..50f0d66b5e3fd3bce91a784731d2ca75b643d53d 100644 (file)
@@ -144,8 +144,8 @@ fn visit_expr(&mut self, e: &'hir hir::Expr) {
                                             "`continue` pointing to a labeled block")
                                 .span_label(e.span,
                                             "labeled blocks cannot be `continue`'d")
-                                .span_note(block.span,
-                                            "labeled block the continue points to")
+                                .span_label(block.span,
+                                            "labeled block the `continue` points to")
                                 .emit();
                         }
                     }
index 5c8e79096312fc24daf21493ca6569181cdec791..3ad53737f49693f6888027c296cd8c0cfbe77fb5 100644 (file)
@@ -1160,8 +1160,10 @@ fn finalize_import(
                     .emit();
             } else {
                 let msg = format!("`{}` is private, and cannot be re-exported", ident);
-                let note_msg =
-                    format!("consider marking `{}` as `pub` in the imported module", ident);
+                let note_msg = format!(
+                    "consider marking `{}` as `pub` in the imported module",
+                    ident,
+                );
                 struct_span_err!(self.r.session, directive.span, E0364, "{}", &msg)
                     .span_note(directive.span, &note_msg)
                     .emit();
index 1aee381d604c3d186792fe536f0bef6360551b32..37dd9427ef4f242486b8a28467460c1f0d52293d 100644 (file)
@@ -4,6 +4,7 @@ pub fn target() -> TargetResult {
     let mut base = super::windows_msvc_base::opts();
     base.max_atomic_width = Some(64);
     base.has_elf_tls = true;
+    base.features = "+neon,+fp-armv8".to_string();
 
     // FIXME: this shouldn't be panic=abort, it should be panic=unwind
     base.panic_strategy = PanicStrategy::Abort;
diff --git a/src/librustc_target/spec/hermit_kernel_base.rs b/src/librustc_target/spec/hermit_kernel_base.rs
new file mode 100644 (file)
index 0000000..ad1027c
--- /dev/null
@@ -0,0 +1,27 @@
+use crate::spec::{LldFlavor, LinkArgs, LinkerFlavor, PanicStrategy, TargetOptions};
+use std::default::Default;
+
+pub fn opts() -> TargetOptions {
+    let mut pre_link_args = LinkArgs::new();
+    pre_link_args.insert(LinkerFlavor::Lld(LldFlavor::Ld), vec![
+        "--build-id".to_string(),
+        "--hash-style=gnu".to_string(),
+        "--Bstatic".to_string(),
+    ]);
+
+    TargetOptions {
+        disable_redzone: true,
+        linker: Some("rust-lld".to_owned()),
+        executables: true,
+        has_elf_tls: true,
+        linker_is_gnu: true,
+        pre_link_args,
+        no_default_libraries: true,
+        panic_strategy: PanicStrategy::Abort,
+        position_independent_executables: true,
+        relocation_model: "static".to_string(),
+        target_family: None,
+        tls_model: "initial-exec".to_string(),
+        .. Default::default()
+    }
+}
index 716aef056a35b6a79e9d18edc0d6a47f0d18f3ca..29076254584c0cac200db10112c25deabbe0d712 100644 (file)
@@ -54,6 +54,7 @@
 mod freebsd_base;
 mod haiku_base;
 mod hermit_base;
+mod hermit_kernel_base;
 mod linux_base;
 mod linux_kernel_base;
 mod linux_musl_base;
@@ -481,12 +482,14 @@ fn $module() {
 
     ("aarch64-unknown-hermit", aarch64_unknown_hermit),
     ("x86_64-unknown-hermit", x86_64_unknown_hermit),
+    ("x86_64-unknown-hermit-kernel", x86_64_unknown_hermit_kernel),
 
     ("riscv32i-unknown-none-elf", riscv32i_unknown_none_elf),
     ("riscv32imc-unknown-none-elf", riscv32imc_unknown_none_elf),
     ("riscv32imac-unknown-none-elf", riscv32imac_unknown_none_elf),
     ("riscv64imac-unknown-none-elf", riscv64imac_unknown_none_elf),
     ("riscv64gc-unknown-none-elf", riscv64gc_unknown_none_elf),
+    ("riscv64gc-unknown-linux-gnu", riscv64gc_unknown_linux_gnu),
 
     ("aarch64-unknown-none", aarch64_unknown_none),
     ("aarch64-unknown-none-softfloat", aarch64_unknown_none_softfloat),
diff --git a/src/librustc_target/spec/riscv64gc_unknown_linux_gnu.rs b/src/librustc_target/spec/riscv64gc_unknown_linux_gnu.rs
new file mode 100644 (file)
index 0000000..638e677
--- /dev/null
@@ -0,0 +1,25 @@
+use crate::spec::{LinkerFlavor, Target, TargetOptions, TargetResult};
+
+pub fn target() -> TargetResult {
+    Ok(Target {
+        llvm_target: "riscv64-unknown-linux-gnu".to_string(),
+        target_endian: "little".to_string(),
+        target_pointer_width: "64".to_string(),
+        target_c_int_width: "32".to_string(),
+        target_env: "gnu".to_string(),
+        data_layout: "e-m:e-p:64:64-i64:64-i128:128-n64-S128".to_string(),
+        arch: "riscv64".to_string(),
+        target_os: "linux".to_string(),
+        target_vendor: "unknown".to_string(),
+        linker_flavor: LinkerFlavor::Gcc,
+        options: TargetOptions {
+            abi_blacklist: super::riscv_base::abi_blacklist(),
+            code_model: Some("medium".to_string()),
+            cpu: "generic-rv64".to_string(),
+            features: "+m,+a,+f,+d,+c".to_string(),
+            llvm_abiname: "lp64d".to_string(),
+            max_atomic_width: Some(64),
+            ..super::linux_base::opts()
+        },
+    })
+}
diff --git a/src/librustc_target/spec/x86_64_unknown_hermit_kernel.rs b/src/librustc_target/spec/x86_64_unknown_hermit_kernel.rs
new file mode 100644 (file)
index 0000000..ebaada8
--- /dev/null
@@ -0,0 +1,25 @@
+use crate::spec::{LldFlavor, LinkerFlavor, Target, TargetResult};
+
+pub fn target() -> TargetResult {
+    let mut base = super::hermit_kernel_base::opts();
+    base.cpu = "x86-64".to_string();
+    base.max_atomic_width = Some(64);
+    base.features =
+        "-mmx,-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-3dnow,-3dnowa,-avx,-avx2,+soft-float"
+        .to_string();
+    base.stack_probes = true;
+
+    Ok(Target {
+        llvm_target: "x86_64-unknown-hermit".to_string(),
+        target_endian: "little".to_string(),
+        target_pointer_width: "64".to_string(),
+        target_c_int_width: "32".to_string(),
+        data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".to_string(),
+        arch: "x86_64".to_string(),
+        target_os: "hermit".to_string(),
+        target_env: String::new(),
+        target_vendor: "unknown".to_string(),
+        linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld),
+        options: base,
+    })
+}
index 688523dc05b0bd7797a1070375d18a8540be0ed2..930241262b0c17845347d48cc6c0fe46917f0c16 100644 (file)
@@ -3748,7 +3748,7 @@ fn check_argument_types(
             formal_tys.clone()
         };
 
-        let mut final_arg_types: Vec<(usize, Ty<'_>)> = vec![];
+        let mut final_arg_types: Vec<(usize, Ty<'_>, Ty<'_>)> = vec![];
 
         // Check the arguments.
         // We do this in a pretty awful way: first we type-check any arguments
@@ -3816,7 +3816,7 @@ fn check_argument_types(
                 // We're processing function arguments so we definitely want to use
                 // two-phase borrows.
                 self.demand_coerce(&arg, checked_ty, coerce_ty, AllowTwoPhase::Yes);
-                final_arg_types.push((i, coerce_ty));
+                final_arg_types.push((i, checked_ty, coerce_ty));
 
                 // 3. Relate the expected type and the formal one,
                 //    if the expected type was used for the coercion.
@@ -3863,14 +3863,16 @@ fn err_args(&self, len: usize) -> Vec<Ty<'tcx>> {
         vec![self.tcx.types.err; len]
     }
 
-    /// Given a vec of evaluated `FullfillmentError`s and an `fn` call argument expressions, we
-    /// walk the resolved types for each argument to see if any of the `FullfillmentError`s
-    /// reference a type argument. If they do, and there's only *one* argument that does, we point
-    /// at the corresponding argument's expression span instead of the `fn` call path span.
+    /// Given a vec of evaluated `FulfillmentError`s and an `fn` call argument expressions, we walk
+    /// the checked and coerced types for each argument to see if any of the `FulfillmentError`s
+    /// reference a type argument. The reason to walk also the checked type is that the coerced type
+    /// can be not easily comparable with predicate type (because of coercion). If the types match
+    /// for either checked or coerced type, and there's only *one* argument that does, we point at
+    /// the corresponding argument's expression span instead of the `fn` call path span.
     fn point_at_arg_instead_of_call_if_possible(
         &self,
         errors: &mut Vec<traits::FulfillmentError<'_>>,
-        final_arg_types: &[(usize, Ty<'tcx>)],
+        final_arg_types: &[(usize, Ty<'tcx>, Ty<'tcx>)],
         call_sp: Span,
         args: &'tcx [hir::Expr],
     ) {
@@ -3880,19 +3882,27 @@ fn point_at_arg_instead_of_call_if_possible(
             for error in errors {
                 if let ty::Predicate::Trait(predicate) = error.obligation.predicate {
                     // Collect the argument position for all arguments that could have caused this
-                    // `FullfillmentError`.
+                    // `FulfillmentError`.
                     let mut referenced_in = final_arg_types.iter()
+                        .map(|(i, checked_ty, _)| (i, checked_ty))
+                        .chain(final_arg_types.iter().map(|(i, _, coerced_ty)| (i, coerced_ty)))
                         .flat_map(|(i, ty)| {
                             let ty = self.resolve_vars_if_possible(ty);
                             // We walk the argument type because the argument's type could have
-                            // been `Option<T>`, but the `FullfillmentError` references `T`.
+                            // been `Option<T>`, but the `FulfillmentError` references `T`.
                             ty.walk()
                                 .filter(|&ty| ty == predicate.skip_binder().self_ty())
                                 .map(move |_| *i)
-                        });
-                    if let (Some(ref_in), None) = (referenced_in.next(), referenced_in.next()) {
+                        })
+                        .collect::<Vec<_>>();
+
+                    // Both checked and coerced types could have matched, thus we need to remove
+                    // duplicates.
+                    referenced_in.dedup();
+
+                    if let (Some(ref_in), None) = (referenced_in.pop(), referenced_in.pop()) {
                         // We make sure that only *one* argument matches the obligation failure
-                        // and thet the obligation's span to its expression's.
+                        // and we assign the obligation's span to its expression's.
                         error.obligation.cause.span = args[ref_in].span;
                         error.points_at_arg_span = true;
                     }
@@ -3901,8 +3911,8 @@ fn point_at_arg_instead_of_call_if_possible(
         }
     }
 
-    /// Given a vec of evaluated `FullfillmentError`s and an `fn` call expression, we walk the
-    /// `PathSegment`s and resolve their type parameters to see if any of the `FullfillmentError`s
+    /// Given a vec of evaluated `FulfillmentError`s and an `fn` call expression, we walk the
+    /// `PathSegment`s and resolve their type parameters to see if any of the `FulfillmentError`s
     /// were caused by them. If they were, we point at the corresponding type argument's span
     /// instead of the `fn` call path span.
     fn point_at_type_arg_instead_of_call_if_possible(
index 6508295b8edcafd241c2f4d0ee7d43bba9cab2ef..f25dfa733c4b85ab946d1c3b694e564400be78f2 100644 (file)
@@ -2,7 +2,7 @@
 use crate::constrained_generic_params::{identify_constrained_generic_params, Parameter};
 
 use crate::hir::def_id::DefId;
-use rustc::traits::{self, ObligationCauseCode};
+use rustc::traits::{self, ObligationCause, ObligationCauseCode};
 use rustc::ty::{self, Ty, TyCtxt, GenericParamDefKind, TypeFoldable, ToPredicate};
 use rustc::ty::subst::{Subst, InternalSubsts};
 use rustc::util::nodemap::{FxHashSet, FxHashMap};
@@ -895,6 +895,11 @@ fn receiver_is_valid<'fcx, 'tcx>(
     // The first type is `receiver_ty`, which we know its not equal to `self_ty`; skip it.
     autoderef.next();
 
+    let receiver_trait_def_id = fcx.tcx.require_lang_item(
+        lang_items::ReceiverTraitLangItem,
+        None,
+    );
+
     // Keep dereferencing `receiver_ty` until we get to `self_ty`.
     loop {
         if let Some((potential_self_ty, _)) = autoderef.next() {
@@ -911,6 +916,19 @@ fn receiver_is_valid<'fcx, 'tcx>(
                 }
 
                 break
+            } else {
+                // Without `feature(arbitrary_self_types)`, we require that each step in the
+                // deref chain implement `receiver`
+                if !arbitrary_self_types_enabled
+                    && !receiver_is_implemented(
+                        fcx,
+                        receiver_trait_def_id,
+                        cause.clone(),
+                        potential_self_ty,
+                    )
+                {
+                    return false
+                }
             }
         } else {
             debug!("receiver_is_valid: type `{:?}` does not deref to `{:?}`",
@@ -919,43 +937,42 @@ fn receiver_is_valid<'fcx, 'tcx>(
             // unecessary errors (#58712).
             return receiver_ty.references_error();
         }
-
-        // Without the `arbitrary_self_types` feature, `receiver_ty` must directly deref to
-        // `self_ty`. Enforce this by only doing one iteration of the loop.
-        if !arbitrary_self_types_enabled {
-            return false
-        }
     }
 
     // Without `feature(arbitrary_self_types)`, we require that `receiver_ty` implements `Receiver`.
-    if !arbitrary_self_types_enabled {
-        let trait_def_id = match fcx.tcx.lang_items().receiver_trait() {
-            Some(did) => did,
-            None => {
-                debug!("receiver_is_valid: missing Receiver trait");
-                return false
-            }
-        };
+    if !arbitrary_self_types_enabled
+        && !receiver_is_implemented(fcx, receiver_trait_def_id, cause.clone(), receiver_ty)
+    {
+        return false
+    }
 
-        let trait_ref = ty::TraitRef{
-            def_id: trait_def_id,
-            substs: fcx.tcx.mk_substs_trait(receiver_ty, &[]),
-        };
+    true
+}
+
+fn receiver_is_implemented(
+    fcx: &FnCtxt<'_, 'tcx>,
+    receiver_trait_def_id: DefId,
+    cause: ObligationCause<'tcx>,
+    receiver_ty: Ty<'tcx>,
+) -> bool {
+    let trait_ref = ty::TraitRef{
+        def_id: receiver_trait_def_id,
+        substs: fcx.tcx.mk_substs_trait(receiver_ty, &[]),
+    };
 
-        let obligation = traits::Obligation::new(
-            cause,
-            fcx.param_env,
-            trait_ref.to_predicate()
-        );
+    let obligation = traits::Obligation::new(
+        cause,
+        fcx.param_env,
+        trait_ref.to_predicate()
+    );
 
-        if !fcx.predicate_must_hold_modulo_regions(&obligation) {
-            debug!("receiver_is_valid: type `{:?}` does not implement `Receiver` trait",
-                receiver_ty);
-            return false
-        }
+    if fcx.predicate_must_hold_modulo_regions(&obligation) {
+        true
+    } else {
+        debug!("receiver_is_implemented: type `{:?}` does not implement `Receiver` trait",
+            receiver_ty);
+        false
     }
-
-    true
 }
 
 fn check_variances_for_type_defn<'tcx>(
index ab34f8daad7197bd1d64ba1573e8a3a68c76863f..d8f2dbca835d85a7f937865fc662446175dd709a 100644 (file)
@@ -38,6 +38,11 @@ pub fn collect_intra_doc_links(krate: Crate, cx: &DocContext<'_>) -> Crate {
     }
 }
 
+enum ErrorKind {
+    ResolutionFailure,
+    AnchorFailure(&'static str),
+}
+
 struct LinkCollector<'a, 'tcx> {
     cx: &'a DocContext<'tcx>,
     mod_ids: Vec<hir::HirId>,
@@ -51,15 +56,74 @@ fn new(cx: &'a DocContext<'tcx>) -> Self {
         }
     }
 
+    fn variant_field(
+        &self,
+        path_str: &str,
+        current_item: &Option<String>,
+        module_id: syntax::ast::NodeId,
+    ) -> Result<(Res, Option<String>), ErrorKind> {
+        let cx = self.cx;
+
+        let mut split = path_str.rsplitn(3, "::");
+        let variant_field_name = split
+            .next()
+            .map(|f| Symbol::intern(f))
+            .ok_or(ErrorKind::ResolutionFailure)?;
+        let variant_name = split
+            .next()
+            .map(|f| Symbol::intern(f))
+            .ok_or(ErrorKind::ResolutionFailure)?;
+        let path = split.next().map(|f| {
+            if f == "self" || f == "Self" {
+                if let Some(name) = current_item.as_ref() {
+                    return name.clone();
+                }
+            }
+            f.to_owned()
+        }).ok_or(ErrorKind::ResolutionFailure)?;
+        let (_, ty_res) = cx.enter_resolver(|resolver| {
+            resolver.resolve_str_path_error(DUMMY_SP, &path, TypeNS, module_id)
+        }).map_err(|_| ErrorKind::ResolutionFailure)?;
+        if let Res::Err = ty_res {
+            return Err(ErrorKind::ResolutionFailure);
+        }
+        let ty_res = ty_res.map_id(|_| panic!("unexpected node_id"));
+        match ty_res {
+            Res::Def(DefKind::Enum, did) => {
+                if cx.tcx.inherent_impls(did)
+                         .iter()
+                         .flat_map(|imp| cx.tcx.associated_items(*imp))
+                         .any(|item| item.ident.name == variant_name) {
+                    return Err(ErrorKind::ResolutionFailure);
+                }
+                match cx.tcx.type_of(did).kind {
+                    ty::Adt(def, _) if def.is_enum() => {
+                        if def.all_fields()
+                              .any(|item| item.ident.name == variant_field_name) {
+                            Ok((ty_res,
+                                Some(format!("variant.{}.field.{}",
+                                             variant_name, variant_field_name))))
+                        } else {
+                            Err(ErrorKind::ResolutionFailure)
+                        }
+                    }
+                    _ => Err(ErrorKind::ResolutionFailure),
+                }
+            }
+            _ => Err(ErrorKind::ResolutionFailure)
+        }
+    }
+
     /// Resolves a string as a path within a particular namespace. Also returns an optional
     /// URL fragment in the case of variants and methods.
-    fn resolve(&self,
-               path_str: &str,
-               ns: Namespace,
-               current_item: &Option<String>,
-               parent_id: Option<hir::HirId>)
-        -> Result<(Res, Option<String>), ()>
-    {
+    fn resolve(
+        &self,
+        path_str: &str,
+        ns: Namespace,
+        current_item: &Option<String>,
+        parent_id: Option<hir::HirId>,
+        extra_fragment: &Option<String>,
+    ) -> Result<(Res, Option<String>), ErrorKind> {
         let cx = self.cx;
 
         // In case we're in a module, try to resolve the relative path.
@@ -69,8 +133,8 @@ fn resolve(&self,
                 resolver.resolve_str_path_error(DUMMY_SP, &path_str, ns, module_id)
             });
             let result = match result {
-                Ok((_, Res::Err)) => Err(()),
-                _ => result,
+                Ok((_, Res::Err)) => Err(ErrorKind::ResolutionFailure),
+                _ => result.map_err(|_| ErrorKind::ResolutionFailure),
             };
 
             if let Ok((_, res)) = result {
@@ -80,47 +144,55 @@ fn resolve(&self,
                 let value = match res {
                     Res::Def(DefKind::Method, _) | Res::Def(DefKind::AssocConst, _) => true,
                     Res::Def(DefKind::AssocTy, _) => false,
-                    Res::Def(DefKind::Variant, _) => return handle_variant(cx, res),
+                    Res::Def(DefKind::Variant, _) => {
+                        return handle_variant(cx, res, extra_fragment);
+                    }
                     // Not a trait item; just return what we found.
-                    Res::PrimTy(..) => return Ok((res, Some(path_str.to_owned()))),
-                    _ => return Ok((res, None))
+                    Res::PrimTy(..) => {
+                        if extra_fragment.is_some() {
+                            return Err(
+                                ErrorKind::AnchorFailure(
+                                    "primitive types cannot be followed by anchors"));
+                        }
+                        return Ok((res, Some(path_str.to_owned())));
+                    }
+                    _ => return Ok((res, extra_fragment.clone()))
                 };
 
                 if value != (ns == ValueNS) {
-                    return Err(())
+                    return Err(ErrorKind::ResolutionFailure)
                 }
             } else if let Some(prim) = is_primitive(path_str, ns) {
+                if extra_fragment.is_some() {
+                    return Err(
+                        ErrorKind::AnchorFailure("primitive types cannot be followed by anchors"));
+                }
                 return Ok((prim, Some(path_str.to_owned())))
             } else {
                 // If resolution failed, it may still be a method
                 // because methods are not handled by the resolver
                 // If so, bail when we're not looking for a value.
                 if ns != ValueNS {
-                    return Err(())
+                    return Err(ErrorKind::ResolutionFailure)
                 }
             }
 
             // Try looking for methods and associated items.
             let mut split = path_str.rsplitn(2, "::");
-            let item_name = if let Some(first) = split.next() {
-                Symbol::intern(first)
-            } else {
-                return Err(())
-            };
-
-            let mut path = if let Some(second) = split.next() {
-                second.to_owned()
-            } else {
-                return Err(())
-            };
-
-            if path == "self" || path == "Self" {
-                if let Some(name) = current_item.as_ref() {
-                    path = name.clone();
+            let item_name = split.next()
+                .map(|f| Symbol::intern(f))
+                .ok_or(ErrorKind::ResolutionFailure)?;
+            let path = split.next().map(|f| {
+                if f == "self" || f == "Self" {
+                    if let Some(name) = current_item.as_ref() {
+                        return name.clone();
+                    }
                 }
-            }
+                f.to_owned()
+            }).ok_or(ErrorKind::ResolutionFailure)?;
+
             if let Some(prim) = is_primitive(&path, TypeNS) {
-                let did = primitive_impl(cx, &path).ok_or(())?;
+                let did = primitive_impl(cx, &path).ok_or(ErrorKind::ResolutionFailure)?;
                 return cx.tcx.associated_items(did)
                     .find(|item| item.ident.name == item_name)
                     .and_then(|item| match item.kind {
@@ -128,14 +200,14 @@ fn resolve(&self,
                         _ => None,
                     })
                     .map(|out| (prim, Some(format!("{}#{}.{}", path, out, item_name))))
-                    .ok_or(());
+                    .ok_or(ErrorKind::ResolutionFailure);
             }
 
             let (_, ty_res) = cx.enter_resolver(|resolver| {
                 resolver.resolve_str_path_error(DUMMY_SP, &path, TypeNS, module_id)
-            })?;
+            }).map_err(|_| ErrorKind::ResolutionFailure)?;
             if let Res::Err = ty_res {
-                return Err(());
+                return self.variant_field(path_str, current_item, module_id);
             }
             let ty_res = ty_res.map_id(|_| panic!("unexpected node_id"));
             match ty_res {
@@ -151,9 +223,18 @@ fn resolve(&self,
                         let out = match item.kind {
                             ty::AssocKind::Method if ns == ValueNS => "method",
                             ty::AssocKind::Const if ns == ValueNS => "associatedconstant",
-                            _ => return Err(())
+                            _ => return self.variant_field(path_str, current_item, module_id),
                         };
-                        Ok((ty_res, Some(format!("{}.{}", out, item_name))))
+                        if extra_fragment.is_some() {
+                            Err(ErrorKind::AnchorFailure(
+                                if item.kind == ty::AssocKind::Method {
+                                    "methods cannot be followed by anchors"
+                                } else {
+                                    "associated constants cannot be followed by anchors"
+                                }))
+                        } else {
+                            Ok((ty_res, Some(format!("{}.{}", out, item_name))))
+                        }
                     } else {
                         match cx.tcx.type_of(did).kind {
                             ty::Adt(def, _) => {
@@ -165,19 +246,28 @@ fn resolve(&self,
                                        .iter()
                                        .find(|item| item.ident.name == item_name)
                                 } {
-                                    Ok((ty_res,
-                                        Some(format!("{}.{}",
-                                                     if def.is_enum() {
-                                                         "variant"
-                                                     } else {
-                                                         "structfield"
-                                                     },
-                                                     item.ident))))
+                                    if extra_fragment.is_some() {
+                                        Err(ErrorKind::AnchorFailure(
+                                            if def.is_enum() {
+                                                "enum variants cannot be followed by anchors"
+                                            } else {
+                                                "struct fields cannot be followed by anchors"
+                                            }))
+                                    } else {
+                                        Ok((ty_res,
+                                            Some(format!("{}.{}",
+                                                         if def.is_enum() {
+                                                             "variant"
+                                                         } else {
+                                                             "structfield"
+                                                         },
+                                                         item.ident))))
+                                    }
                                 } else {
-                                    Err(())
+                                    self.variant_field(path_str, current_item, module_id)
                                 }
                             }
-                            _ => Err(()),
+                            _ => self.variant_field(path_str, current_item, module_id),
                         }
                     }
                 }
@@ -196,19 +286,30 @@ fn resolve(&self,
                                     "tymethod"
                                 }
                             }
-                            _ => return Err(())
+                            _ => return self.variant_field(path_str, current_item, module_id),
                         };
 
-                        Ok((ty_res, Some(format!("{}.{}", kind, item_name))))
+                        if extra_fragment.is_some() {
+                            Err(ErrorKind::AnchorFailure(
+                                if item.kind == ty::AssocKind::Const {
+                                    "associated constants cannot be followed by anchors"
+                                } else if item.kind == ty::AssocKind::Type {
+                                    "associated types cannot be followed by anchors"
+                                } else {
+                                    "methods cannot be followed by anchors"
+                                }))
+                        } else {
+                            Ok((ty_res, Some(format!("{}.{}", kind, item_name))))
+                        }
                     } else {
-                        Err(())
+                        self.variant_field(path_str, current_item, module_id)
                     }
                 }
-                _ => Err(())
+                _ => self.variant_field(path_str, current_item, module_id),
             }
         } else {
             debug!("attempting to resolve item without parent module: {}", path_str);
-            Err(())
+            Err(ErrorKind::ResolutionFailure)
         }
     }
 }
@@ -289,6 +390,22 @@ fn fold_item(&mut self, mut item: Item) -> Option<Item> {
             }
 
             let link = ori_link.replace("`", "");
+            let parts = link.split('#').collect::<Vec<_>>();
+            let (link, extra_fragment) = if parts.len() > 2 {
+                build_diagnostic(cx, &item, &link, &dox, link_range,
+                                 "has an issue with the link anchor.",
+                                 "only one `#` is allowed in a link",
+                                 None);
+                continue;
+            } else if parts.len() == 2 {
+                if parts[0].trim().is_empty() {
+                    // This is an anchor to an element of the current page, nothing to do in here!
+                    continue;
+                }
+                (parts[0].to_owned(), Some(parts[1].to_owned()))
+            } else {
+                (parts[0].to_owned(), None)
+            };
             let (res, fragment) = {
                 let mut kind = None;
                 let path_str = if let Some(prefix) =
@@ -341,42 +458,73 @@ fn fold_item(&mut self, mut item: Item) -> Option<Item> {
 
                 match kind {
                     Some(ns @ ValueNS) => {
-                        if let Ok(res) = self.resolve(path_str, ns, &current_item, base_node) {
-                            res
-                        } else {
-                            resolution_failure(cx, &item, path_str, &dox, link_range);
-                            // This could just be a normal link or a broken link
-                            // we could potentially check if something is
-                            // "intra-doc-link-like" and warn in that case.
-                            continue;
+                        match self.resolve(path_str, ns, &current_item, base_node,
+                                           &extra_fragment) {
+                            Ok(res) => res,
+                            Err(ErrorKind::ResolutionFailure) => {
+                                resolution_failure(cx, &item, path_str, &dox, link_range);
+                                // This could just be a normal link or a broken link
+                                // we could potentially check if something is
+                                // "intra-doc-link-like" and warn in that case.
+                                continue;
+                            }
+                            Err(ErrorKind::AnchorFailure(msg)) => {
+                                anchor_failure(cx, &item, &ori_link, &dox, link_range, msg);
+                                continue
+                            }
                         }
                     }
                     Some(ns @ TypeNS) => {
-                        if let Ok(res) = self.resolve(path_str, ns, &current_item, base_node) {
-                            res
-                        } else {
-                            resolution_failure(cx, &item, path_str, &dox, link_range);
-                            // This could just be a normal link.
-                            continue;
+                        match self.resolve(path_str, ns, &current_item, base_node,
+                                           &extra_fragment) {
+                            Ok(res) => res,
+                            Err(ErrorKind::ResolutionFailure) => {
+                                resolution_failure(cx, &item, path_str, &dox, link_range);
+                                // This could just be a normal link.
+                                continue;
+                            }
+                            Err(ErrorKind::AnchorFailure(msg)) => {
+                                anchor_failure(cx, &item, &ori_link, &dox, link_range, msg);
+                                continue
+                            }
                         }
                     }
                     None => {
                         // Try everything!
                         let candidates = PerNS {
-                            macro_ns: macro_resolve(cx, path_str).map(|res| (res, None)),
-                            type_ns: self
-                                .resolve(path_str, TypeNS, &current_item, base_node)
-                                .ok(),
-                            value_ns: self
-                                .resolve(path_str, ValueNS, &current_item, base_node)
-                                .ok()
-                                .and_then(|(res, fragment)| {
-                                    // Constructors are picked up in the type namespace.
-                                    match res {
-                                        Res::Def(DefKind::Ctor(..), _) | Res::SelfCtor(..) => None,
-                                        _ => Some((res, fragment))
-                                    }
-                                }),
+                            macro_ns: macro_resolve(cx, path_str)
+                                        .map(|res| (res, extra_fragment.clone())),
+                            type_ns: match self.resolve(path_str, TypeNS, &current_item, base_node,
+                                                        &extra_fragment) {
+                                Err(ErrorKind::AnchorFailure(msg)) => {
+                                    anchor_failure(cx, &item, &ori_link, &dox, link_range, msg);
+                                    continue;
+                                }
+                                x => x.ok(),
+                            },
+                            value_ns: match self.resolve(path_str, ValueNS, &current_item,
+                                                         base_node, &extra_fragment) {
+                                Err(ErrorKind::AnchorFailure(msg)) => {
+                                    anchor_failure(cx, &item, &ori_link, &dox, link_range, msg);
+                                    continue;
+                                }
+                                x => x.ok(),
+                            }
+                            .and_then(|(res, fragment)| {
+                                // Constructors are picked up in the type namespace.
+                                match res {
+                                    Res::Def(DefKind::Ctor(..), _) | Res::SelfCtor(..) => None,
+                                    _ => match (fragment, extra_fragment) {
+                                        (Some(fragment), Some(_)) => {
+                                            // Shouldn't happen but who knows?
+                                            Some((res, Some(fragment)))
+                                        }
+                                        (fragment, None) | (None, fragment) => {
+                                            Some((res, fragment))
+                                        }
+                                    },
+                                }
+                            }),
                         };
 
                         if candidates.is_empty() {
@@ -402,7 +550,7 @@ fn fold_item(&mut self, mut item: Item) -> Option<Item> {
                     }
                     Some(MacroNS) => {
                         if let Some(res) = macro_resolve(cx, path_str) {
-                            (res, None)
+                            (res, extra_fragment)
                         } else {
                             resolution_failure(cx, &item, path_str, &dox, link_range);
                             continue
@@ -462,17 +610,15 @@ fn macro_resolve(cx: &DocContext<'_>, path_str: &str) -> Option<Res> {
     })
 }
 
-/// Reports a resolution failure diagnostic.
-///
-/// If we cannot find the exact source span of the resolution failure, we use the span of the
-/// documentation attributes themselves. This is a little heavy-handed, so we display the markdown
-/// line containing the failure as a note as well.
-fn resolution_failure(
+fn build_diagnostic(
     cx: &DocContext<'_>,
     item: &Item,
     path_str: &str,
     dox: &str,
     link_range: Option<Range<usize>>,
+    err_msg: &str,
+    short_err_msg: &str,
+    help_msg: Option<&str>,
 ) {
     let hir_id = match cx.as_local_hir_id(item.def_id) {
         Some(hir_id) => hir_id,
@@ -488,12 +634,12 @@ fn resolution_failure(
         lint::builtin::INTRA_DOC_LINK_RESOLUTION_FAILURE,
         hir_id,
         sp,
-        &format!("`[{}]` cannot be resolved, ignoring it...", path_str),
+        &format!("`[{}]` {}", path_str, err_msg),
     );
     if let Some(link_range) = link_range {
         if let Some(sp) = super::source_span_for_markdown_range(cx, dox, &link_range, attrs) {
             diag.set_span(sp);
-            diag.span_label(sp, "cannot be resolved, ignoring");
+            diag.span_label(sp, short_err_msg);
         } else {
             // blah blah blah\nblah\nblah [blah] blah blah\nblah blah
             //                       ^     ~~~~
@@ -513,11 +659,44 @@ fn resolution_failure(
             ));
         }
     };
-    diag.help("to escape `[` and `]` characters, just add '\\' before them like \
-               `\\[` or `\\]`");
+    if let Some(help_msg) = help_msg {
+        diag.help(help_msg);
+    }
     diag.emit();
 }
 
+/// Reports a resolution failure diagnostic.
+///
+/// If we cannot find the exact source span of the resolution failure, we use the span of the
+/// documentation attributes themselves. This is a little heavy-handed, so we display the markdown
+/// line containing the failure as a note as well.
+fn resolution_failure(
+    cx: &DocContext<'_>,
+    item: &Item,
+    path_str: &str,
+    dox: &str,
+    link_range: Option<Range<usize>>,
+) {
+    build_diagnostic(cx, item, path_str, dox, link_range,
+         "cannot be resolved, ignoring it.",
+         "cannot be resolved, ignoring",
+         Some("to escape `[` and `]` characters, just add '\\' before them like `\\[` or `\\]`"));
+}
+
+fn anchor_failure(
+    cx: &DocContext<'_>,
+    item: &Item,
+    path_str: &str,
+    dox: &str,
+    link_range: Option<Range<usize>>,
+    msg: &str,
+) {
+    build_diagnostic(cx, item, path_str, dox, link_range,
+         "has an issue with the link anchor.",
+         msg,
+         None);
+}
+
 fn ambiguity_error(
     cx: &DocContext<'_>,
     item: &Item,
@@ -637,13 +816,20 @@ fn ambiguity_error(
 }
 
 /// Given an enum variant's res, return the res of its enum and the associated fragment.
-fn handle_variant(cx: &DocContext<'_>, res: Res) -> Result<(Res, Option<String>), ()> {
+fn handle_variant(
+    cx: &DocContext<'_>,
+    res: Res,
+    extra_fragment: &Option<String>,
+) -> Result<(Res, Option<String>), ErrorKind> {
     use rustc::ty::DefIdTree;
 
+    if extra_fragment.is_some() {
+        return Err(ErrorKind::AnchorFailure("variants cannot be followed by anchors"));
+    }
     let parent = if let Some(parent) = cx.tcx.parent(res.def_id()) {
         parent
     } else {
-        return Err(())
+        return Err(ErrorKind::ResolutionFailure)
     };
     let parent_def = Res::Def(DefKind::Enum, parent);
     let variant = cx.tcx.expect_variant_res(res);
index f6560218a78c82935454dd7b9d5fa88529b576b7..0a95d4209ac6a46dfcfb7aba12005fe433f2ebb6 100644 (file)
@@ -344,7 +344,7 @@ fn add_test(&mut self, _: String, _: LangString, _: usize) {
             lint::builtin::MISSING_DOC_CODE_EXAMPLES,
             hir_id,
             sp,
-            "Missing code example in this documentation");
+            "missing code example in this documentation");
         diag.emit();
     } else if check_missing_code == false &&
               tests.found_tests > 0 &&
@@ -353,7 +353,7 @@ fn add_test(&mut self, _: String, _: LangString, _: usize) {
             lint::builtin::PRIVATE_DOC_TESTS,
             hir_id,
             span_of_attrs(&item.attrs).unwrap_or(item.source.span()),
-            "Documentation test in private item");
+            "documentation test in private item");
         diag.emit();
     }
 }
@@ -367,7 +367,7 @@ fn add_test(&mut self, _: String, _: LangString, _: usize) {
     if start == DUMMY_SP {
         return None;
     }
-    let end = attrs.doc_strings.last().expect("No doc strings provided").span();
+    let end = attrs.doc_strings.last().expect("no doc strings provided").span();
     Some(start.to(end))
 }
 
index 5bf12c54c4a203b8f47796a10e723f21a282a299..512f43c86ca010cc55b52c38511eae0b6f526a22 100644 (file)
@@ -1718,6 +1718,18 @@ pub fn bit_width(&self) -> Option<usize> {
             IntTy::I128 => 128,
         })
     }
+
+    pub fn normalize(&self, target_width: u32) -> Self {
+        match self {
+            IntTy::Isize => match target_width {
+                16 => IntTy::I16,
+                32 => IntTy::I32,
+                64 => IntTy::I64,
+                _ => unreachable!(),
+            },
+            _ => *self,
+        }
+    }
 }
 
 #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable_Generic,
@@ -1768,6 +1780,18 @@ pub fn bit_width(&self) -> Option<usize> {
             UintTy::U128 => 128,
         })
     }
+
+    pub fn normalize(&self, target_width: u32) -> Self {
+        match self {
+            UintTy::Usize => match target_width {
+                16 => UintTy::U16,
+                32 => UintTy::U32,
+                64 => UintTy::U64,
+                _ => unreachable!(),
+            },
+            _ => *self,
+        }
+    }
 }
 
 /// A constraint on an associated type (e.g., `A = Bar` in `Foo<A = Bar>` or
index 846508bd0cd155a42a65da855f48172e9c21a1e9..ec0eaa568123ab42954528c1bdf0c7c5874e6744 100644 (file)
@@ -688,10 +688,9 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
                     crate_edition: Edition, allow_features: &Option<Vec<String>>) -> Features {
     fn feature_removed(span_handler: &Handler, span: Span, reason: Option<&str>) {
         let mut err = struct_span_err!(span_handler, span, E0557, "feature has been removed");
+        err.span_label(span, "feature has been removed");
         if let Some(reason) = reason {
-            err.span_note(span, reason);
-        } else {
-            err.span_label(span, "feature has been removed");
+            err.note(reason);
         }
         err.emit();
     }
index 25754ed42177fd5ed18c94d1f8ae3d88059284cb..837e04afd34016a1786e96f3a22f826205477218 100644 (file)
@@ -269,7 +269,8 @@ fn check_binders(
                 // for nested macro definitions.
                 sess.span_diagnostic
                     .struct_span_err(span, "duplicate matcher binding")
-                    .span_note(prev_info.span, "previous declaration was here")
+                    .span_label(span, "duplicate binding")
+                    .span_label(prev_info.span, "previous binding")
                     .emit();
                 *valid = false;
             } else {
index 25daca9237fd6aa6466d66d352643778e6d68b81..0a19d64200ce70dbb754b0c269b5570d5a23b7ea 100644 (file)
@@ -172,7 +172,8 @@ fn parse_args<'a>(
             let e = p.parse_expr()?;
             if let Some(prev) = names.get(&name) {
                 ecx.struct_span_err(e.span, &format!("duplicate argument named `{}`", name))
-                    .span_note(args[*prev].span, "previously here")
+                    .span_label(args[*prev].span, "previously here")
+                    .span_label(e.span, "duplicate argument")
                     .emit();
                 continue;
             }
index fbded7dc130eb3a6a72798e6c20295ac27b5af4e..604400c3cc2ff5562384c61bbfc84e5ea671d413 100644 (file)
@@ -270,7 +270,7 @@ fn visit_item(&mut self, item: &'a ast::Item) {
                     };
 
                     self.handler.struct_span_err(attr.span, &msg)
-                        .span_note(prev_attr.span, "previous attribute here")
+                        .span_label(prev_attr.span, "previous attribute here")
                         .emit();
 
                     return;
index 062a8265cc6b728fa38494d25e3139d5ff91c875..e2bb49699e97c4e6667d5ac11e540483dd7ec6a8 100644 (file)
@@ -580,7 +580,7 @@ LLVMRustWriteOutputFile(LLVMTargetMachineRef Target, LLVMPassManagerRef PMR,
   // Apparently `addPassesToEmitFile` adds a pointer to our on-the-stack output
   // stream (OS), so the only real safe place to delete this is here? Don't we
   // wish this was written in Rust?
-  delete PM;
+  LLVMDisposePassManager(PMR);
   return LLVMRustResult::Success;
 }
 
index 8e134ad14fc144e6f11bda977f768d8fb5c7c8c2..70820dfaea4a033de9c4b9b79f1fca0faace731c 100644 (file)
@@ -25,7 +25,7 @@ pub fn change_loop_body() {
 }
 
 #[cfg(not(cfail1))]
-#[rustc_clean(cfg="cfail2", except="HirBody, mir_built")]
+#[rustc_clean(cfg="cfail2", except="HirBody, mir_built, optimized_mir")]
 #[rustc_clean(cfg="cfail3")]
 pub fn change_loop_body() {
     let mut _x = 0;
index 4e8ba5a209df8d9e80bd4238264b9ef342826519..68545b7daaa5cafd70c25ab488f701743a85b611 100644 (file)
@@ -22,7 +22,7 @@ pub fn change_name() {
 
 #[cfg(not(cfail1))]
 #[rustc_clean(cfg="cfail2",
-    except="HirBody,mir_built")]
+    except="HirBody,mir_built,optimized_mir")]
 #[rustc_clean(cfg="cfail3")]
 pub fn change_name() {
     let _y = 2u64;
@@ -86,7 +86,7 @@ pub fn change_mutability_of_slot() {
 
 #[cfg(not(cfail1))]
 #[rustc_clean(cfg="cfail2",
-    except="HirBody,typeck_tables_of,mir_built")]
+    except="HirBody,typeck_tables_of,mir_built,optimized_mir")]
 #[rustc_clean(cfg="cfail3")]
 pub fn change_mutability_of_slot() {
     let _x: u64 = 0;
@@ -182,7 +182,7 @@ pub fn add_initializer() {
 
 #[cfg(not(cfail1))]
 #[rustc_clean(cfg="cfail2",
-    except="HirBody,typeck_tables_of,mir_built")]
+    except="HirBody,typeck_tables_of,mir_built,optimized_mir")]
 #[rustc_clean(cfg="cfail3")]
 pub fn add_initializer() {
     let _x: i16 = 3i16;
@@ -198,7 +198,7 @@ pub fn change_initializer() {
 
 #[cfg(not(cfail1))]
 #[rustc_clean(cfg="cfail2",
-    except="HirBody,mir_built")]
+    except="HirBody,mir_built,optimized_mir")]
 #[rustc_clean(cfg="cfail3")]
 pub fn change_initializer() {
     let _x = 5u16;
index ca85ee39e36715146df7724d3bff5470ec29bc99..a2222db4c59ad37a57c59ba3a4bad2525a67cee5 100644 (file)
@@ -25,7 +25,7 @@ pub fn change_loop_body() {
 }
 
 #[cfg(not(cfail1))]
-#[rustc_clean(cfg="cfail2", except="HirBody, mir_built")]
+#[rustc_clean(cfg="cfail2", except="HirBody, mir_built, optimized_mir")]
 #[rustc_clean(cfg="cfail3")]
 pub fn change_loop_body() {
     let mut _x = 0;
index 70d0f86c3d268eed931ff5f4983d3d013a5132c9..a427ffb96e33982c5c79ad67c80455734ef672ec 100644 (file)
@@ -25,7 +25,7 @@ pub fn change_loop_body() {
 }
 
 #[cfg(not(cfail1))]
-#[rustc_clean(cfg="cfail2", except="HirBody, mir_built")]
+#[rustc_clean(cfg="cfail2", except="HirBody, mir_built, optimized_mir")]
 #[rustc_clean(cfg="cfail3")]
 pub fn change_loop_body() {
     let mut _x = 0;
@@ -48,7 +48,7 @@ pub fn change_loop_condition() {
 }
 
 #[cfg(not(cfail1))]
-#[rustc_clean(cfg="cfail2", except="HirBody, mir_built")]
+#[rustc_clean(cfg="cfail2", except="HirBody, mir_built, optimized_mir")]
 #[rustc_clean(cfg="cfail3")]
 pub fn change_loop_condition() {
     let mut _x = 0;
index 8dc6b73edf6d473ecd804cdd314597fbdb86dcd9..fa1a291858becca149f0abe544f4be40434da9e4 100644 (file)
@@ -27,6 +27,7 @@ fn drop(&mut self) {
 //     let _3: ();
 //     let mut _4: std::boxed::Box<S>;
 //     scope 1 {
+//         debug x => _1;
 //     }
 //     bb0: {
 //         StorageLive(_1);
index 34d4a534ad9f1b23314ff581cb653d8cf0c3379d..3f82b81a47de5883a41b8572957721de8fd63e0e 100644 (file)
@@ -23,9 +23,9 @@ fn main() {
 // START rustc.main.ConstProp.after.mir
 //  bb0: {
 //      ...
-//      _4 = const Scalar(AllocId(1).0x0) : &i32;
-//      _3 = const Scalar(AllocId(1).0x0) : &i32;
-//      _2 = const Value(Scalar(AllocId(1).0x0)) : *const i32;
+//      _4 = const main::FOO;
+//      _3 = _4;
+//      _2 = move _3 as *const i32 (Misc);
 //      ...
 //      _1 = move _2 as usize (Misc);
 //      ...
index 2d04822c0e7898a453652aa21e8204bad75ee464..d45ffdc87753539fdbcdeab9e5d6f20694a32388 100644 (file)
@@ -14,7 +14,7 @@ fn main() {
 // START rustc.main.ConstProp.after.mir
 // bb0: {
 //     ...
-//     _2 = const Scalar(AllocId(0).0x0) : &i32;
+//     _2 = &(promoted[0]: i32);
 //     _1 = const 4i32;
 //     ...
 // }
index ad7f195676a68b194707837b52d1cef11c607725..4d6fe905b0c3546e01bce91235e731a592281d22 100644 (file)
@@ -16,7 +16,7 @@ fn main() {
 // START rustc.main.ConstProp.after.mir
 //  bb0: {
 //      ...
-//      _3 = const main;
+//      _3 = const main as fn() (Pointer(ReifyFnPointer));
 //      _2 = move _3 as usize (Misc);
 //      ...
 //      _1 = move _2 as *const fn() (Misc);
index 05595ce147c96f6b17472fda1e6b2325f2cb8f9a..d6ff76b34b9b5fb7de1a4249bf2cff203ea48d94 100644 (file)
@@ -24,8 +24,8 @@ fn main() {
 // START rustc.main.ConstProp.after.mir
 //  bb0: {
 //      ...
-//      _4 = const Scalar(AllocId(0).0x0) : &[u32; 3];
-//      _3 = const Scalar(AllocId(0).0x0) : &[u32; 3];
+//      _4 = &(promoted[0]: [u32; 3]);
+//      _3 = _4;
 //      _2 = move _3 as &[u32] (Pointer(Unsize));
 //      ...
 //      _6 = const 1usize;
index 109304d6d22ccdd4cb9368c12bbea673702e2f76..ecce0a08c7bf017eddb0269408493f27ca728d6f 100644 (file)
@@ -37,8 +37,10 @@ fn main() {
 // ...
 // let mut _9: Bar;
 // scope 1 {
+//     debug a => _2;
 //     let _3: Bar;
 //     scope 2 {
+//         debug b => _3;
 //     }
 // }
 // bb0: {
index 491130b7c5d32937d65bef3f58afa5ed1cd8f140..b5bfeef5e9c56ab41ad5865b920c494b5ee6c339 100644 (file)
@@ -17,23 +17,43 @@ fn foo<T: Copy>(_t: T, q: &i32) -> i32 {
 
 // END RUST SOURCE
 // START rustc.foo.Inline.after.mir
-// ...
-// bb0: {
-//     ...
-//     _3 = [closure@HirId { owner: DefIndex(4), local_id: 31 }];
-//     ...
-//     _4 = &_3;
-//     ...
-//     _6 = &(*_2);
-//     ...
-//     _7 = &(*_2);
-//     _5 = (move _6, move _7);
-//     _8 = move (_5.0: &i32);
-//     _9 = move (_5.1: &i32);
-//     ...
-//     _0 = (*_8);
-//     ...
-//     return;
+// fn foo(_1: T, _2: &i32) -> i32{
+//     debug _t => _1;
+//     debug q => _2;
+//     let mut _0: i32;
+//     let _3: [closure@HirId { owner: DefIndex(4), local_id: 31 }];
+//     let mut _4: &[closure@HirId { owner: DefIndex(4), local_id: 31 }];
+//     let mut _5: (&i32, &i32);
+//     let mut _6: &i32;
+//     let mut _7: &i32;
+//     let mut _8: &i32;
+//     let mut _9: &i32;
+//     scope 1 {
+//         debug x => _3;
+//         scope 2 {
+//             debug r => _8;
+//             debug _s => _9;
+//         }
+//     }
+//     scope 3 {
+//         debug variable => _8;
+//     }
+//     bb0: {
+//         ...
+//         _3 = [closure@HirId { owner: DefIndex(4), local_id: 31 }];
+//         ...
+//         _4 = &_3;
+//         ...
+//         _6 = &(*_2);
+//         ...
+//         _7 = &(*_2);
+//         _5 = (move _6, move _7);
+//         _8 = move (_5.0: &i32);
+//         _9 = move (_5.1: &i32);
+//         ...
+//         _0 = (*_8);
+//         ...
+//         return;
+//     }
 // }
-// ...
 // END rustc.foo.Inline.after.mir
diff --git a/src/test/mir-opt/inline-closure-captures.rs b/src/test/mir-opt/inline-closure-captures.rs
new file mode 100644 (file)
index 0000000..e73dbe4
--- /dev/null
@@ -0,0 +1,60 @@
+// compile-flags: -Z span_free_formats
+
+// Tests that MIR inliner can handle closure captures.
+
+fn main() {
+    println!("{:?}", foo(0, 14));
+}
+
+fn foo<T: Copy>(t: T, q: i32) -> (i32, T) {
+    let x = |_q| (q, t);
+    x(q)
+}
+
+// END RUST SOURCE
+// START rustc.foo.Inline.after.mir
+// fn foo(_1: T, _2: i32) -> (i32, T){
+//     debug t => _1;
+//     debug q => _2;
+//     let mut _0: (i32, T);
+//     let _3: [closure@HirId { owner: DefIndex(4), local_id: 15 } q:&i32, t:&T];
+//     let mut _4: &i32;
+//     let mut _5: &T;
+//     let mut _6: &[closure@HirId { owner: DefIndex(4), local_id: 15 } q:&i32, t:&T];
+//     let mut _7: (i32,);
+//     let mut _8: i32;
+//     let mut _11: i32;
+//     scope 1 {
+//         debug x => _3;
+//         scope 2 {
+//             debug _q => _11;
+//             debug q => (*((*_6).0: &i32));
+//             debug t => (*((*_6).1: &T));
+//             let mut _9: i32;
+//             let mut _10: T;
+//         }
+//     }
+//     bb0: {
+//         ...
+//         _4 = &_2;
+//         ...
+//         _5 = &_1;
+//         _3 = [closure@HirId { owner: DefIndex(4), local_id: 15 }] { q: move _4, t: move _5 };
+//         ...
+//         _6 = &_3;
+//         ...
+//         ...
+//         _8 = _2;
+//         _7 = (move _8,);
+//         _11 = move (_7.0: i32);
+//         ...
+//         _9 = (*((*_6).0: &i32));
+//         ...
+//         _10 = (*((*_6).1: &T));
+//         (_0.0: i32) = move _9;
+//         (_0.1: T) = move _10;
+//         ...
+//         return;
+//     }
+// }
+// END rustc.foo.Inline.after.mir
index 7c0259b643a630636e566afc2b4fe7dc2dc6a169..ddf027f4be38aac0acbf83731490b2a82f316009 100644 (file)
@@ -13,22 +13,38 @@ fn foo<T: Copy>(_t: T, q: i32) -> i32 {
 
 // END RUST SOURCE
 // START rustc.foo.Inline.after.mir
-// ...
-// bb0: {
-//     ...
-//     _3 = [closure@HirId { owner: DefIndex(4), local_id: 15 }];
-//     ...
-//     _4 = &_3;
-//     ...
-//     _6 = _2;
-//     ...
-//     _7 = _2;
-//     _5 = (move _6, move _7);
-//     _8 = move (_5.0: i32);
-//     _9 = move (_5.1: i32);
-//     _0 = _8;
-//     ...
-//     return;
-// }
-// ...
+// fn foo(_1: T, _2: i32) -> i32{
+//     debug _t => _1;
+//     debug q => _2;
+//     let mut _0: i32;
+//     let _3: [closure@HirId { owner: DefIndex(4), local_id: 15 }];
+//     let mut _4: &[closure@HirId { owner: DefIndex(4), local_id: 15 }];
+//     let mut _5: (i32, i32);
+//     let mut _6: i32;
+//     let mut _7: i32;
+//     let mut _8: i32;
+//     let mut _9: i32;
+//     scope 1 {
+//         debug x => _3;
+//         scope 2 {
+//             debug _t => _8;
+//             debug _q => _9;
+//         }
+//     }
+//     bb0: {
+//         ...
+//         _3 = [closure@HirId { owner: DefIndex(4), local_id: 15 }];
+//         ...
+//         _4 = &_3;
+//         ...
+//         _6 = _2;
+//         ...
+//         _7 = _2;
+//         _5 = (move _6, move _7);
+//         _8 = move (_5.0: i32);
+//         _9 = move (_5.1: i32);
+//         _0 = _8;
+//         ...
+//         return;
+//     }
 // END rustc.foo.Inline.after.mir
index e73390f52b5d552fc3287e923a0f52ac9a117c52..5ba54f98d00da7fcf15e559cda3569b594f4ea79 100644 (file)
@@ -35,6 +35,7 @@ fn other(self, s: Self) {}
 //    let mut _4: S;
 //    let mut _5: bool;
 //    scope 1 {
+//        debug x => _1;
 //    }
 //    ...
 //    bb0: {
@@ -47,7 +48,11 @@ fn other(self, s: Self) {}
 //    let mut _5: S;
 //    let mut _6: bool;
 //    ...
+//    debug u => _1;
+//    ...
 //    let mut _2: S;
 //    ...
+//    debug v => _2;
+//    ...
 //    bb0: {
 // END rustc.test.ElaborateDrops.after.mir
index 58f321d6df170321d02904055b59b5891742ff64..efe2b249d4a8653237651d337af3b2afb3987d50 100644 (file)
@@ -25,9 +25,11 @@ enum E {
 // fn main() -> () {
 //     let mut _0: ();
 //     scope 1 {
-//         let _1: E; // `e`
+//         let _1: E;
+//         debug e => _1;
 //         scope 2 {
 //             let _6: K;
+//             debug _k => _6;
 //         }
 //     }
 //     let mut _2: bool;
index d0dbcbd7515f838974806fde144eea1df778db63..54c89b85f42d7945062310d3065c64fbb6366c7c 100644 (file)
@@ -24,6 +24,7 @@ fn main() {
 //     let _5: ();
 //     let mut _6: &i32;
 //     scope 1 {
+//         debug beacon => _2;
 //     }
 //     bb0: {
 //         goto -> bb1;
index c898d3a6f168c8e86113ae83bf20369b8fa5d8fe..4412a16e74d5ea53593a7c0bfaf76e51a02cf107 100644 (file)
@@ -53,8 +53,14 @@ fn main() {
 // let _15: bool;                       // `b`
 // let _16: std::string::String;        // `t`
 // scope 1 {
+//     debug a => _5;
+//     debug a => _6;
+//     debug s => _7;
+//     debug s => _8;
 // }
 // scope 2 {
+//     debug b => _15;
+//     debug t => _16;
 // }
 // bb0: {
 //     FakeRead(ForMatchedPlace, _2);
index 8228d9740f0d3f6901ea35e9472f24d3792d6ca9..16e357fc162559e9cf9bc5c6b7eeb5f545577107 100644 (file)
@@ -29,8 +29,12 @@ fn main() {
 // START rustc.main.nll.0.mir
 // let _2: &'_#3r usize;
 // ...
+// debug p => _2;
+// ...
 // let _6: &'_#4r usize;
 // ...
+// debug q => _6;
+// ...
 // _2 = &'_#2r _1[_3];
 // ...
 // _6 = _2;
index da73cc96348f059e4c15e29ce839204b2b824ed4..113f81c441f7c7d08d200f74e76f8d6e483c4103 100644 (file)
@@ -25,6 +25,7 @@ fn drop(&mut self) {}
 //     let mut _5: Droppy;
 //     let mut _6: Aligned;
 //     scope 1 {
+//         debug x => _1;
 //     }
 //
 //     bb0: {
index 7911fbd0a984d5a93fa792840d871a1053a197d9..656b405ef340edbd20510947b5833f602a1a5e28 100644 (file)
@@ -10,6 +10,7 @@ fn main() {
 // END RUST SOURCE
 // START rustc.try_identity.SimplifyArmIdentity.before.mir
 // fn try_identity(_1: std::result::Result<u32, i32>) -> std::result::Result<u32, i32> {
+//     debug x => _1;
 //     let mut _0: std::result::Result<u32, i32>;
 //     let _2: u32;
 //     let mut _3: std::result::Result<u32, i32>;
@@ -22,21 +23,27 @@ fn main() {
 //     let _10: u32;
 //     let mut _11: u32;
 //     scope 1 {
+//         debug y => _10;
 //     }
 //     scope 2 {
+//         debug err => _6;
 //         scope 3 {
 //             scope 7 {
+//                 debug t => _6;
 //             }
 //             scope 8 {
+//                 debug v => _6;
 //                 let mut _12: i32;
 //             }
 //         }
 //     }
 //     scope 4 {
+//         debug val => _10;
 //         scope 5 {
 //         }
 //     }
 //     scope 6 {
+//         debug self => _1;
 //     }
 //     bb0: {
 //         _5 = discriminant(_1);
@@ -65,6 +72,7 @@ fn main() {
 
 // START rustc.try_identity.SimplifyArmIdentity.after.mir
 // fn try_identity(_1: std::result::Result<u32, i32>) -> std::result::Result<u32, i32> {
+//     debug x => _1;
 //     let mut _0: std::result::Result<u32, i32>;
 //     let _2: u32;
 //     let mut _3: std::result::Result<u32, i32>;
@@ -77,21 +85,27 @@ fn main() {
 //     let _10: u32;
 //     let mut _11: u32;
 //     scope 1 {
+//         debug y => _10;
 //     }
 //     scope 2 {
+//         debug err => _6;
 //         scope 3 {
 //             scope 7 {
+//                 debug t => _6;
 //             }
 //             scope 8 {
+//                 debug v => _6;
 //                 let mut _12: i32;
 //             }
 //         }
 //     }
 //     scope 4 {
+//         debug val => _10;
 //         scope 5 {
 //         }
 //     }
 //     scope 6 {
+//         debug self => _1;
 //     }
 //     bb0: {
 //         _5 = discriminant(_1);
@@ -120,6 +134,7 @@ fn main() {
 
 // START rustc.try_identity.SimplifyBranchSame.after.mir
 // fn try_identity(_1: std::result::Result<u32, i32>) -> std::result::Result<u32, i32> {
+//     debug x => _1;
 //     let mut _0: std::result::Result<u32, i32>;
 //     let _2: u32;
 //     let mut _3: std::result::Result<u32, i32>;
@@ -132,21 +147,27 @@ fn main() {
 //     let _10: u32;
 //     let mut _11: u32;
 //     scope 1 {
+//         debug y => _10;
 //     }
 //     scope 2 {
+//         debug err => _6;
 //         scope 3 {
 //             scope 7 {
+//                 debug t => _6;
 //             }
 //             scope 8 {
+//                 debug v => _6;
 //                 let mut _12: i32;
 //             }
 //         }
 //     }
 //     scope 4 {
+//         debug val => _10;
 //         scope 5 {
 //         }
 //     }
 //     scope 6 {
+//         debug self => _1;
 //     }
 //     bb0: {
 //         _5 = discriminant(_1);
@@ -166,23 +187,32 @@ fn main() {
 
 // START rustc.try_identity.SimplifyLocals.after.mir
 // fn try_identity(_1: std::result::Result<u32, i32>) -> std::result::Result<u32, i32> {
+//     debug x => _1;
 //     let mut _0: std::result::Result<u32, i32>;
 //     let mut _2: isize;
+//     let _3: i32;
+//     let _4: u32;
 //     scope 1 {
+//         debug y => _4;
 //     }
 //     scope 2 {
+//         debug err => _3;
 //         scope 3 {
 //             scope 7 {
+//                 debug t => _3;
 //             }
 //             scope 8 {
+//                 debug v => _3;
 //             }
 //         }
 //     }
 //     scope 4 {
+//         debug val => _4;
 //         scope 5 {
 //         }
 //     }
 //     scope 6 {
+//         debug self => _1;
 //     }
 //     bb0: {
 //         _2 = discriminant(_1);
index 1a120dcb18654c0c321f99dfa5adcd491a2d710a..b432bfbf20f5daefc28f82ce934fbef27bba6a0f 100644 (file)
@@ -1,4 +1,4 @@
-error: `[v2]` cannot be resolved, ignoring it...
+error: `[v2]` cannot be resolved, ignoring it.
   --> $DIR/deny-intra-link-resolution-failure.rs:3:6
    |
 LL | /// [v2]
index 4b2a91e9c812722f4a6f66beb1692e8ea56037a6..5ad8e8a826f053b5eff3576942d7b33c648970e6 100644 (file)
@@ -1,13 +1,13 @@
-#![deny(missing_doc_code_examples)] //~ ERROR Missing code example in this documentation
+#![deny(missing_doc_code_examples)] //~ ERROR missing code example in this documentation
 
 /// Some docs.
-//~^ ERROR Missing code example in this documentation
+//~^ ERROR missing code example in this documentation
 pub struct Foo;
 
 /// And then, the princess died.
-//~^ ERROR Missing code example in this documentation
+//~^ ERROR missing code example in this documentation
 pub mod foo {
     /// Or maybe not because she saved herself!
-    //~^ ERROR Missing code example in this documentation
+    //~^ ERROR missing code example in this documentation
     pub fn bar() {}
 }
index 23c07c4d32d64359d43a4a4ead40dbac4ba40050..bf65fcf19a0d6e56ab140df534b3297917730aeb 100644 (file)
@@ -1,4 +1,4 @@
-error: Missing code example in this documentation
+error: missing code example in this documentation
   --> $DIR/doc-without-codeblock.rs:1:1
    |
 LL | / #![deny(missing_doc_code_examples)]
@@ -16,19 +16,19 @@ note: lint level defined here
 LL | #![deny(missing_doc_code_examples)]
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^
 
-error: Missing code example in this documentation
+error: missing code example in this documentation
   --> $DIR/doc-without-codeblock.rs:3:1
    |
 LL | /// Some docs.
    | ^^^^^^^^^^^^^^
 
-error: Missing code example in this documentation
+error: missing code example in this documentation
   --> $DIR/doc-without-codeblock.rs:7:1
    |
 LL | /// And then, the princess died.
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
-error: Missing code example in this documentation
+error: missing code example in this documentation
   --> $DIR/doc-without-codeblock.rs:10:5
    |
 LL |     /// Or maybe not because she saved herself!
index cebb14cba7c11b96d70648c3e43dff35159ae02b..d4d3e5fea3e1aea009d2c2ce3f28424e8bfcd293 100644 (file)
@@ -1,4 +1,4 @@
-error: `[TypeAlias::hoge]` cannot be resolved, ignoring it...
+error: `[TypeAlias::hoge]` cannot be resolved, ignoring it.
   --> $DIR/intra-doc-alias-ice.rs:5:30
    |
 LL | /// [broken cross-reference](TypeAlias::hoge)
index c7a13bbf606cbe68d0db8bbfa9b87c05021e31e0..44997c90f59320465bbc7a6b063886aca329afe1 100644 (file)
@@ -7,7 +7,7 @@
 /// ## For example:
 ///
 /// (arr[i])
-//~^ ERROR `[i]` cannot be resolved, ignoring it...
+//~^ ERROR `[i]` cannot be resolved, ignoring it.
 pub fn test_ice() {
     unimplemented!();
 }
index 79702a1a546b7497fbebf082a0de0717bdf1e51a..edd5b8b92f2302c441b9be03a3404dbee89d630c 100644 (file)
@@ -1,4 +1,4 @@
-error: `[i]` cannot be resolved, ignoring it...
+error: `[i]` cannot be resolved, ignoring it.
   --> $DIR/intra-link-span-ice-55723.rs:9:10
    |
 LL | /// (arr[i])
diff --git a/src/test/rustdoc-ui/intra-links-anchors.rs b/src/test/rustdoc-ui/intra-links-anchors.rs
new file mode 100644 (file)
index 0000000..7f8a8dd
--- /dev/null
@@ -0,0 +1,45 @@
+#![deny(intra_doc_link_resolution_failure)]
+
+// A few tests on anchors.
+
+/// Hello people.
+///
+/// You can anchors? Here's one!
+///
+/// # hola
+///
+/// Isn't it amazing?
+pub struct Foo {
+    pub f: u8,
+}
+
+pub enum Enum {
+    A,
+    B,
+}
+
+/// Have you heard about stuff?
+///
+/// Like [Foo#hola].
+///
+/// Or maybe [Foo::f#hola].
+//~^ ERROR `[Foo::f#hola]` has an issue with the link anchor.
+pub fn foo() {}
+
+/// Empty.
+///
+/// Another anchor error: [hello#people#!].
+//~^ ERROR `[hello#people#!]` has an issue with the link anchor.
+pub fn bar() {}
+
+/// Empty?
+///
+/// Damn enum's variants: [Enum::A#whatever].
+//~^ ERROR `[Enum::A#whatever]` has an issue with the link anchor.
+pub fn enum_link() {}
+
+/// Primitives?
+///
+/// [u32#hello]
+//~^ ERROR `[u32#hello]` has an issue with the link anchor.
+pub fn x() {}
diff --git a/src/test/rustdoc-ui/intra-links-anchors.stderr b/src/test/rustdoc-ui/intra-links-anchors.stderr
new file mode 100644 (file)
index 0000000..5fead8e
--- /dev/null
@@ -0,0 +1,32 @@
+error: `[Foo::f#hola]` has an issue with the link anchor.
+  --> $DIR/intra-links-anchors.rs:25:15
+   |
+LL | /// Or maybe [Foo::f#hola].
+   |               ^^^^^^^^^^^ struct fields cannot be followed by anchors
+   |
+note: lint level defined here
+  --> $DIR/intra-links-anchors.rs:1:9
+   |
+LL | #![deny(intra_doc_link_resolution_failure)]
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: `[hello#people#!]` has an issue with the link anchor.
+  --> $DIR/intra-links-anchors.rs:31:28
+   |
+LL | /// Another anchor error: [hello#people#!].
+   |                            ^^^^^^^^^^^^^^ only one `#` is allowed in a link
+
+error: `[Enum::A#whatever]` has an issue with the link anchor.
+  --> $DIR/intra-links-anchors.rs:37:28
+   |
+LL | /// Damn enum's variants: [Enum::A#whatever].
+   |                            ^^^^^^^^^^^^^^^^ variants cannot be followed by anchors
+
+error: `[u32#hello]` has an issue with the link anchor.
+  --> $DIR/intra-links-anchors.rs:43:6
+   |
+LL | /// [u32#hello]
+   |      ^^^^^^^^^ primitive types cannot be followed by anchors
+
+error: aborting due to 4 previous errors
+
index b4e11c29ed5acc7d422a9c8371e6c2f6b75707e3..e4dd13cfa0195d0fd2c18e94981bbc44fb9970f0 100644 (file)
@@ -1,4 +1,4 @@
-warning: `[error]` cannot be resolved, ignoring it...
+warning: `[error]` cannot be resolved, ignoring it.
   --> $DIR/intra-links-warning-crlf.rs:7:6
    |
 LL | /// [error]
@@ -7,7 +7,7 @@ LL | /// [error]
    = note: `#[warn(intra_doc_link_resolution_failure)]` on by default
    = help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
 
-warning: `[error1]` cannot be resolved, ignoring it...
+warning: `[error1]` cannot be resolved, ignoring it.
   --> $DIR/intra-links-warning-crlf.rs:12:11
    |
 LL | /// docs [error1]
@@ -15,7 +15,7 @@ LL | /// docs [error1]
    |
    = help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
 
-warning: `[error2]` cannot be resolved, ignoring it...
+warning: `[error2]` cannot be resolved, ignoring it.
   --> $DIR/intra-links-warning-crlf.rs:15:11
    |
 LL | /// docs [error2]
@@ -23,7 +23,7 @@ LL | /// docs [error2]
    |
    = help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
 
-warning: `[error]` cannot be resolved, ignoring it...
+warning: `[error]` cannot be resolved, ignoring it.
   --> $DIR/intra-links-warning-crlf.rs:23:20
    |
 LL |  * It also has an [error].
index 27cc3aeb0810077be6d3642b55385129dc28609c..5f1c9cfbc367a752b5c9242449a1d17357a209bb 100644 (file)
@@ -1,4 +1,4 @@
-warning: `[Foo::baz]` cannot be resolved, ignoring it...
+warning: `[Foo::baz]` cannot be resolved, ignoring it.
   --> $DIR/intra-links-warning.rs:3:23
    |
 LL |        //! Test with [Foo::baz], [Bar::foo], ...
@@ -7,7 +7,7 @@ LL |        //! Test with [Foo::baz], [Bar::foo], ...
    = note: `#[warn(intra_doc_link_resolution_failure)]` on by default
    = help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
 
-warning: `[Bar::foo]` cannot be resolved, ignoring it...
+warning: `[Bar::foo]` cannot be resolved, ignoring it.
   --> $DIR/intra-links-warning.rs:3:35
    |
 LL |        //! Test with [Foo::baz], [Bar::foo], ...
@@ -15,7 +15,7 @@ LL |        //! Test with [Foo::baz], [Bar::foo], ...
    |
    = help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
 
-warning: `[Uniooon::X]` cannot be resolved, ignoring it...
+warning: `[Uniooon::X]` cannot be resolved, ignoring it.
   --> $DIR/intra-links-warning.rs:6:13
    |
 LL |      //! , [Uniooon::X] and [Qux::Z].
@@ -23,7 +23,7 @@ LL |      //! , [Uniooon::X] and [Qux::Z].
    |
    = help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
 
-warning: `[Qux::Z]` cannot be resolved, ignoring it...
+warning: `[Qux::Z]` cannot be resolved, ignoring it.
   --> $DIR/intra-links-warning.rs:6:30
    |
 LL |      //! , [Uniooon::X] and [Qux::Z].
@@ -31,7 +31,7 @@ LL |      //! , [Uniooon::X] and [Qux::Z].
    |
    = help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
 
-warning: `[Uniooon::X]` cannot be resolved, ignoring it...
+warning: `[Uniooon::X]` cannot be resolved, ignoring it.
   --> $DIR/intra-links-warning.rs:10:14
    |
 LL |       //! , [Uniooon::X] and [Qux::Z].
@@ -39,7 +39,7 @@ LL |       //! , [Uniooon::X] and [Qux::Z].
    |
    = help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
 
-warning: `[Qux::Z]` cannot be resolved, ignoring it...
+warning: `[Qux::Z]` cannot be resolved, ignoring it.
   --> $DIR/intra-links-warning.rs:10:31
    |
 LL |       //! , [Uniooon::X] and [Qux::Z].
@@ -47,7 +47,7 @@ LL |       //! , [Uniooon::X] and [Qux::Z].
    |
    = help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
 
-warning: `[Qux:Y]` cannot be resolved, ignoring it...
+warning: `[Qux:Y]` cannot be resolved, ignoring it.
   --> $DIR/intra-links-warning.rs:14:13
    |
 LL |        /// [Qux:Y]
@@ -55,7 +55,7 @@ LL |        /// [Qux:Y]
    |
    = help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
 
-warning: `[error]` cannot be resolved, ignoring it...
+warning: `[error]` cannot be resolved, ignoring it.
   --> $DIR/intra-links-warning.rs:58:30
    |
 LL |  * time to introduce a link [error]*/
@@ -63,7 +63,7 @@ LL |  * time to introduce a link [error]*/
    |
    = help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
 
-warning: `[error]` cannot be resolved, ignoring it...
+warning: `[error]` cannot be resolved, ignoring it.
   --> $DIR/intra-links-warning.rs:64:30
    |
 LL |  * time to introduce a link [error]
@@ -71,7 +71,7 @@ LL |  * time to introduce a link [error]
    |
    = help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
 
-warning: `[error]` cannot be resolved, ignoring it...
+warning: `[error]` cannot be resolved, ignoring it.
   --> $DIR/intra-links-warning.rs:68:1
    |
 LL | #[doc = "single line [error]"]
@@ -83,7 +83,7 @@ LL | #[doc = "single line [error]"]
                         ^^^^^
    = help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
 
-warning: `[error]` cannot be resolved, ignoring it...
+warning: `[error]` cannot be resolved, ignoring it.
   --> $DIR/intra-links-warning.rs:71:1
    |
 LL | #[doc = "single line with \"escaping\" [error]"]
@@ -95,7 +95,7 @@ LL | #[doc = "single line with \"escaping\" [error]"]
                                         ^^^^^
    = help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
 
-warning: `[error]` cannot be resolved, ignoring it...
+warning: `[error]` cannot be resolved, ignoring it.
   --> $DIR/intra-links-warning.rs:74:1
    |
 LL | / /// Item docs.
@@ -109,7 +109,7 @@ LL | | /// [error]
             ^^^^^
    = help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
 
-warning: `[error1]` cannot be resolved, ignoring it...
+warning: `[error1]` cannot be resolved, ignoring it.
   --> $DIR/intra-links-warning.rs:80:11
    |
 LL | /// docs [error1]
@@ -117,7 +117,7 @@ LL | /// docs [error1]
    |
    = help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
 
-warning: `[error2]` cannot be resolved, ignoring it...
+warning: `[error2]` cannot be resolved, ignoring it.
   --> $DIR/intra-links-warning.rs:82:11
    |
 LL | /// docs [error2]
@@ -125,7 +125,7 @@ LL | /// docs [error2]
    |
    = help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
 
-warning: `[BarA]` cannot be resolved, ignoring it...
+warning: `[BarA]` cannot be resolved, ignoring it.
   --> $DIR/intra-links-warning.rs:21:10
    |
 LL | /// bar [BarA] bar
@@ -133,7 +133,7 @@ LL | /// bar [BarA] bar
    |
    = help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
 
-warning: `[BarB]` cannot be resolved, ignoring it...
+warning: `[BarB]` cannot be resolved, ignoring it.
   --> $DIR/intra-links-warning.rs:27:9
    |
 LL |  * bar [BarB] bar
@@ -141,7 +141,7 @@ LL |  * bar [BarB] bar
    |
    = help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
 
-warning: `[BarC]` cannot be resolved, ignoring it...
+warning: `[BarC]` cannot be resolved, ignoring it.
   --> $DIR/intra-links-warning.rs:34:6
    |
 LL | bar [BarC] bar
@@ -149,7 +149,7 @@ LL | bar [BarC] bar
    |
    = help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
 
-warning: `[BarD]` cannot be resolved, ignoring it...
+warning: `[BarD]` cannot be resolved, ignoring it.
   --> $DIR/intra-links-warning.rs:45:1
    |
 LL | #[doc = "Foo\nbar [BarD] bar\nbaz"]
@@ -161,7 +161,7 @@ LL | #[doc = "Foo\nbar [BarD] bar\nbaz"]
                 ^^^^
    = help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
 
-warning: `[BarF]` cannot be resolved, ignoring it...
+warning: `[BarF]` cannot be resolved, ignoring it.
   --> $DIR/intra-links-warning.rs:50:9
    |
 LL |         #[doc = $f]
index 0e0ebd9ce70800c4db78272cd550c43e23959a42..06766db5335a1eeb4d3c2ec7da0f1db03cac6e7f 100644 (file)
 pub fn link_error() {} //~^^^^^ ERROR cannot be resolved, ignoring it
 
 /// wait, this doesn't have a doctest?
-pub fn no_doctest() {} //~^ ERROR Missing code example in this documentation
+pub fn no_doctest() {} //~^ ERROR missing code example in this documentation
 
 /// wait, this *does* have a doctest?
 ///
 /// ```
 /// println!("sup");
 /// ```
-fn private_doctest() {} //~^^^^^ ERROR Documentation test in private item
+fn private_doctest() {} //~^^^^^ ERROR documentation test in private item
index cd523b227deb18d24c067e84efca35ab82bc6f55..dca98cf58df317702bf4ebcb1f8cab4f02d27749 100644 (file)
@@ -1,4 +1,4 @@
-error: Documentation test in private item
+error: documentation test in private item
   --> $DIR/lint-group.rs:19:1
    |
 LL | / /// wait, this *does* have a doctest?
@@ -15,7 +15,7 @@ LL | #![deny(rustdoc)]
    |         ^^^^^^^
    = note: `#[deny(private_doc_tests)]` implied by `#[deny(rustdoc)]`
 
-error: `[error]` cannot be resolved, ignoring it...
+error: `[error]` cannot be resolved, ignoring it.
   --> $DIR/lint-group.rs:9:29
    |
 LL | /// what up, let's make an [error]
@@ -29,7 +29,7 @@ LL | #![deny(rustdoc)]
    = note: `#[deny(intra_doc_link_resolution_failure)]` implied by `#[deny(rustdoc)]`
    = help: to escape `[` and `]` characters, just add '\' before them like `\[` or `\]`
 
-error: Missing code example in this documentation
+error: missing code example in this documentation
   --> $DIR/lint-group.rs:16:1
    |
 LL | /// wait, this doesn't have a doctest?
index 97a52a13e3f652d5688bb7e58d66d9876b4ab265..179dba17c6d818f0413b3319e0a6d90e44d85582 100644 (file)
@@ -1,4 +1,4 @@
-error: Missing code example in this documentation
+error: missing code example in this documentation
   --> $DIR/lint-missing-doc-code-example.rs:19:1
    |
 LL | / mod module1 {
@@ -11,7 +11,7 @@ note: lint level defined here
 LL | #![deny(missing_doc_code_examples)]
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^
 
-error: Missing code example in this documentation
+error: missing code example in this documentation
   --> $DIR/lint-missing-doc-code-example.rs:37:3
    |
 LL |   /// doc
index 20ac292aeaf80fcea1ffd2e0b38713812be438cb..2f1bddc7c75ccdbc4754554838c4a9b12a4df923 100644 (file)
@@ -6,6 +6,6 @@ mod foo {
     /// ```
     /// assert!(false);
     /// ```
-    //~^^^^^ ERROR Documentation test in private item
+    //~^^^^^ ERROR documentation test in private item
     fn bar() {}
 }
index 20f3eb8b12025eb201e156f3522c9ea9312dd57c..8abbdb31ec91acedac122cd87677adf49883877d 100644 (file)
@@ -1,4 +1,4 @@
-error: Documentation test in private item
+error: documentation test in private item
   --> $DIR/private-item-doc-test.rs:4:5
    |
 LL | /     /// private doc test
diff --git a/src/test/rustdoc/intra-doc-link-enum-struct-field.rs b/src/test/rustdoc/intra-doc-link-enum-struct-field.rs
new file mode 100644 (file)
index 0000000..70bf343
--- /dev/null
@@ -0,0 +1,14 @@
+#![crate_name = "foo"]
+
+pub enum Foo {
+    X {
+        y: u8,
+    }
+}
+
+/// Hello
+///
+/// I want [Foo::X::y].
+pub fn foo() {}
+
+// @has foo/fn.foo.html '//a/@href' '../foo/enum.Foo.html#variant.X.field.y'
diff --git a/src/test/rustdoc/intra-links-anchors.rs b/src/test/rustdoc/intra-links-anchors.rs
new file mode 100644 (file)
index 0000000..f554e16
--- /dev/null
@@ -0,0 +1,12 @@
+/// I want...
+///
+/// # Anchor!
+pub struct Something;
+
+// @has intra_links_anchors/struct.SomeOtherType.html
+// @has - '//a/@href' '../intra_links_anchors/struct.Something.html#Anchor!'
+
+/// I want...
+///
+/// To link to [Something#Anchor!]
+pub struct SomeOtherType;
index ed0aa13eb8078e6bce1bace25afc41b5c8d7d210..35d9f0f42f00164fcbdd7f30fd4bcb5f6425687d 100644 (file)
@@ -1,14 +1,11 @@
 error: cannot define multiple global allocators
   --> $DIR/two-allocators.rs:6:1
    |
-LL | static B: System = System;
-   | ^^^^^^^^^^^^^^^^^^^^^^^^^^
-   |
-note: the previous global allocator is defined here
-  --> $DIR/two-allocators.rs:4:1
-   |
 LL | static A: System = System;
-   | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+   | -------------------------- previous global allocator is defined here
+LL | #[global_allocator]
+LL | static B: System = System;
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot define a new global allocator
 
 error: aborting due to previous error
 
index d56b9f562c932dfc5c51feb38a4916298a01ca1a..26de39101f2117e98f3f4a14c01ea9eee3e3cbeb 100644 (file)
@@ -10,15 +10,7 @@ LL |                   num2) => (),
 LL |         Foo::Foo2(num) => (),
    |                   --- ...and here
    |
-note: move occurs because these variables have types that don't implement the `Copy` trait
-  --> $DIR/borrowck-move-error-with-note.rs:12:19
-   |
-LL |         Foo::Foo1(num1,
-   |                   ^^^^
-LL |                   num2) => (),
-   |                   ^^^^
-LL |         Foo::Foo2(num) => (),
-   |                   ^^^
+   = note: move occurs because these variables have types that don't implement the `Copy` trait
 
 error[E0509]: cannot move out of type `S`, which implements the `Drop` trait
   --> $DIR/borrowck-move-error-with-note.rs:28:11
@@ -31,13 +23,7 @@ LL |             f: _s,
 LL |             g: _t
    |                -- ...and here
    |
-note: move occurs because these variables have types that don't implement the `Copy` trait
-  --> $DIR/borrowck-move-error-with-note.rs:31:16
-   |
-LL |             f: _s,
-   |                ^^
-LL |             g: _t
-   |                ^^
+   = note: move occurs because these variables have types that don't implement the `Copy` trait
 
 error[E0507]: cannot move out of `a.a` which is behind a shared reference
   --> $DIR/borrowck-move-error-with-note.rs:46:11
index 9f0670c6bc72d65943554ca4f5f58e16aebfa7c9..8fb4c062c0363772f5e529b179000cbad372f0e9 100644 (file)
@@ -9,13 +9,7 @@ LL |                 &[Foo { string: a },
 LL |                   Foo { string: b }] => {
    |                                 - ...and here
    |
-note: move occurs because these variables have types that don't implement the `Copy` trait
-  --> $DIR/borrowck-move-out-of-vec-tail.rs:21:33
-   |
-LL |                 &[Foo { string: a },
-   |                                 ^
-LL |                   Foo { string: b }] => {
-   |                                 ^
+   = note: move occurs because these variables have types that don't implement the `Copy` trait
 help: consider removing the `&`
    |
 LL |                 [Foo { string: a },
index a215305f684dd6aa16efafb0acca652a70a1f5f9..e274d105e05034f4e0fb2512cc98fa981dd60de9 100644 (file)
@@ -75,12 +75,12 @@ fn e() {
     match vec {
         //~^ ERROR cannot move out
         //~| NOTE cannot move out
+        //~| NOTE move occurs because these variables have types
         &mut [_a, _b, _c] => {}
         //~^ NOTE data moved here
         //~| NOTE and here
         //~| NOTE and here
         //~| HELP consider removing the `&mut`
-        //~| NOTE move occurs because these variables have types
         _ => {}
     }
     let a = vec[0]; //~ ERROR cannot move out
index ad5e206a9a1be1ccfaa4e4d4d9d82e2687f886d5..a3324f25d0bb5968c52f611958544f5a6366f395 100644 (file)
@@ -97,11 +97,7 @@ LL |         &mut [_a, _b, _c] => {}
    |         |     data moved here
    |         help: consider removing the `&mut`: `[_a, _b, _c]`
    |
-note: move occurs because these variables have types that don't implement the `Copy` trait
-  --> $DIR/borrowck-vec-pattern-nesting.rs:78:15
-   |
-LL |         &mut [_a, _b, _c] => {}
-   |               ^^  ^^  ^^
+   = note: move occurs because these variables have types that don't implement the `Copy` trait
 
 error[E0508]: cannot move out of type `[std::boxed::Box<isize>]`, a non-copy slice
   --> $DIR/borrowck-vec-pattern-nesting.rs:86:13
diff --git a/src/test/ui/consts/control-flow/exhaustive-c-like-enum-match.rs b/src/test/ui/consts/control-flow/exhaustive-c-like-enum-match.rs
new file mode 100644 (file)
index 0000000..9e22151
--- /dev/null
@@ -0,0 +1,21 @@
+// Test for <https://github.com/rust-lang/rust/issues/66756>
+
+// check-pass
+
+#![feature(const_if_match)]
+
+enum E {
+    A,
+    B,
+    C
+}
+
+const fn f(e: E) {
+    match e {
+        E::A => {}
+        E::B => {}
+        E::C => {}
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/consts/control-flow/single-arm-match-wild.rs b/src/test/ui/consts/control-flow/single-arm-match-wild.rs
new file mode 100644 (file)
index 0000000..fba6e35
--- /dev/null
@@ -0,0 +1,21 @@
+// check-pass
+
+#![feature(const_if_match)]
+
+enum E {
+    A,
+    B,
+    C
+}
+
+const fn f(e: E) -> usize {
+    match e {
+        _ => 0
+    }
+}
+
+fn main() {
+    const X: usize = f(E::C);
+    assert_eq!(X, 0);
+    assert_eq!(f(E::A), 0);
+}
diff --git a/src/test/ui/consts/issue-66345.rs b/src/test/ui/consts/issue-66345.rs
new file mode 100644 (file)
index 0000000..7d0de73
--- /dev/null
@@ -0,0 +1,24 @@
+// run-pass
+// compile-flags: -Z mir-opt-level=3
+
+// Checks that the compiler does not ICE when passing references to field of by-value struct
+// with -Z mir-opt-level=3
+
+fn do_nothing(_: &()) {}
+
+pub struct Foo {
+    bar: (),
+}
+
+pub fn by_value_1(foo: Foo) {
+    do_nothing(&foo.bar);
+}
+
+pub fn by_value_2<T>(foo: Foo) {
+    do_nothing(&foo.bar);
+}
+
+fn main() {
+    by_value_1(Foo { bar: () });
+    by_value_2::<()>(Foo { bar: () });
+}
index 07917c2a540d59594015b524c12a3db542a35dbd..c024094dd5610da186114734332eb165b6f2b31f 100644 (file)
@@ -138,13 +138,9 @@ error: duplicate argument named `foo`
   --> $DIR/ifmt-bad-arg.rs:40:33
    |
 LL |     format!("{foo}", foo=1, foo=2);
-   |                                 ^
-   |
-note: previously here
-  --> $DIR/ifmt-bad-arg.rs:40:26
-   |
-LL |     format!("{foo}", foo=1, foo=2);
-   |                          ^
+   |                          -      ^ duplicate argument
+   |                          |
+   |                          previously here
 
 error: positional arguments cannot follow named arguments
   --> $DIR/ifmt-bad-arg.rs:41:35
index 1de29dc8c6108c83facacc39d5fc625168184584..9d9a88f4f9b06353a1a0a73c1f600d281e712ed4 100644 (file)
@@ -10,14 +10,7 @@ LL |             => println!("one empty"),
 LL |         (&[hd1, ..], &[hd2, ..])
    |                        --- ...and here
    |
-note: move occurs because these variables have types that don't implement the `Copy` trait
-  --> $DIR/issue-12567.rs:8:17
-   |
-LL |         (&[], &[hd, ..]) | (&[hd, ..], &[])
-   |                 ^^
-LL |             => println!("one empty"),
-LL |         (&[hd1, ..], &[hd2, ..])
-   |                        ^^^
+   = note: move occurs because these variables have types that don't implement the `Copy` trait
 
 error[E0508]: cannot move out of type `[T]`, a non-copy slice
   --> $DIR/issue-12567.rs:4:11
@@ -31,14 +24,7 @@ LL |             => println!("one empty"),
 LL |         (&[hd1, ..], &[hd2, ..])
    |            --- ...and here
    |
-note: move occurs because these variables have types that don't implement the `Copy` trait
-  --> $DIR/issue-12567.rs:8:17
-   |
-LL |         (&[], &[hd, ..]) | (&[hd, ..], &[])
-   |                 ^^
-LL |             => println!("one empty"),
-LL |         (&[hd1, ..], &[hd2, ..])
-   |            ^^^
+   = note: move occurs because these variables have types that don't implement the `Copy` trait
 
 error: aborting due to 2 previous errors
 
index e547ec7e4754c5719aa60839ca8b641cea2d411d..d0a4097de6816fcb35321b63fca5900feaf80582 100644 (file)
@@ -7,11 +7,7 @@ LL |     let (a, b) = x[0];
    |          |  ...and here
    |          data moved here
    |
-note: move occurs because these variables have types that don't implement the `Copy` trait
-  --> $DIR/issue-40402-2.rs:5:10
-   |
-LL |     let (a, b) = x[0];
-   |          ^  ^
+   = note: move occurs because these variables have types that don't implement the `Copy` trait
 
 error: aborting due to previous error
 
index b3c0b421023ac0e5cf60956113962f9dbf2bd529..c5f79ed6333ee6f62242c33870cc670754b8bac7 100644 (file)
@@ -7,16 +7,11 @@ LL |         continue;
 error[E0696]: `continue` pointing to a labeled block
   --> $DIR/label_break_value_continue.rs:14:9
    |
-LL |         continue 'b;
-   |         ^^^^^^^^^^^ labeled blocks cannot be `continue`'d
-   |
-note: labeled block the continue points to
-  --> $DIR/label_break_value_continue.rs:13:5
-   |
 LL | /     'b: {
 LL | |         continue 'b;
+   | |         ^^^^^^^^^^^ labeled blocks cannot be `continue`'d
 LL | |     }
-   | |_____^
+   | |_____- labeled block the `continue` points to
 
 error[E0695]: unlabeled `continue` inside of a labeled block
   --> $DIR/label_break_value_continue.rs:22:13
index e20503a395c89b7df6d2c7d9da2cab88fc893275..a439a1f339aea6e6521600683dc947f522232cae 100644 (file)
@@ -65,6 +65,10 @@ pub fn zero_size_phantom_toplevel()
     pub fn transparent_i128(p: TransparentI128); //~ ERROR: uses type `i128`
     pub fn transparent_str(p: TransparentStr); //~ ERROR: uses type `str`
     pub fn transparent_fn(p: TransparentBadFn); //~ ERROR: uses type `std::boxed::Box<u32>`
+    pub fn raw_array(arr: [u8; 8]); //~ ERROR: uses type `[u8; 8]`
+
+    pub static static_u128_type: u128; //~ ERROR: uses type `u128`
+    pub static static_u128_array_type: [u128; 16]; //~ ERROR: uses type `u128`
 
     pub fn good3(fptr: Option<extern fn()>);
     pub fn good4(aptr: &[u8; 4 as usize]);
@@ -83,6 +87,9 @@ pub fn zero_size_phantom_toplevel()
     pub fn good17(p: TransparentCustomZst);
     #[allow(improper_ctypes)]
     pub fn good18(_: &String);
+    pub fn good20(arr: *const [u8; 8]);
+    pub static good21: [u8; 8];
+
 }
 
 #[allow(improper_ctypes)]
index e533a767b317f536c8f359cba1fd4fe335fa5346..e6bb49afb880f8d3cdf188b684189cc1aeae09cb 100644 (file)
@@ -197,5 +197,30 @@ LL |     pub fn transparent_fn(p: TransparentBadFn);
    = help: consider adding a `#[repr(C)]` or `#[repr(transparent)]` attribute to this struct
    = note: this struct has unspecified layout
 
-error: aborting due to 20 previous errors
+error: `extern` block uses type `[u8; 8]`, which is not FFI-safe
+  --> $DIR/lint-ctypes.rs:68:27
+   |
+LL |     pub fn raw_array(arr: [u8; 8]);
+   |                           ^^^^^^^ not FFI-safe
+   |
+   = help: consider passing a pointer to the array
+   = note: passing raw arrays by value is not FFI-safe
+
+error: `extern` block uses type `u128`, which is not FFI-safe
+  --> $DIR/lint-ctypes.rs:70:34
+   |
+LL |     pub static static_u128_type: u128;
+   |                                  ^^^^ not FFI-safe
+   |
+   = note: 128-bit integers don't currently have a known stable ABI
+
+error: `extern` block uses type `u128`, which is not FFI-safe
+  --> $DIR/lint-ctypes.rs:71:40
+   |
+LL |     pub static static_u128_array_type: [u128; 16];
+   |                                        ^^^^^^^^^^ not FFI-safe
+   |
+   = note: 128-bit integers don't currently have a known stable ABI
+
+error: aborting due to 23 previous errors
 
index 65362388d7de168a2e3c6ba414278fd068d90cc7..3ad1297ffb2f3961ab497030ad69d70e5b0a3171 100644 (file)
@@ -2,49 +2,33 @@ error: duplicate matcher binding
   --> $DIR/macro-multiple-matcher-bindings.rs:7:16
    |
 LL |     ($a:ident, $a:ident) => {};
-   |                ^^^^^^^^
-   |
-note: previous declaration was here
-  --> $DIR/macro-multiple-matcher-bindings.rs:7:6
-   |
-LL |     ($a:ident, $a:ident) => {};
-   |      ^^^^^^^^
+   |      --------  ^^^^^^^^ duplicate binding
+   |      |
+   |      previous binding
 
 error: duplicate matcher binding
   --> $DIR/macro-multiple-matcher-bindings.rs:8:16
    |
 LL |     ($a:ident, $a:path) => {};
-   |                ^^^^^^^
-   |
-note: previous declaration was here
-  --> $DIR/macro-multiple-matcher-bindings.rs:8:6
-   |
-LL |     ($a:ident, $a:path) => {};
-   |      ^^^^^^^^
+   |      --------  ^^^^^^^ duplicate binding
+   |      |
+   |      previous binding
 
 error: duplicate matcher binding
   --> $DIR/macro-multiple-matcher-bindings.rs:17:18
    |
 LL |     ($a:ident, $($a:ident),*) => {};
-   |                  ^^^^^^^^
-   |
-note: previous declaration was here
-  --> $DIR/macro-multiple-matcher-bindings.rs:17:6
-   |
-LL |     ($a:ident, $($a:ident),*) => {};
-   |      ^^^^^^^^
+   |      --------    ^^^^^^^^ duplicate binding
+   |      |
+   |      previous binding
 
 error: duplicate matcher binding
   --> $DIR/macro-multiple-matcher-bindings.rs:18:25
    |
 LL |     ($($a:ident)+ # $($($a:path),+);*) => {};
-   |                         ^^^^^^^
-   |
-note: previous declaration was here
-  --> $DIR/macro-multiple-matcher-bindings.rs:18:8
-   |
-LL |     ($($a:ident)+ # $($($a:path),+);*) => {};
-   |        ^^^^^^^^
+   |        --------         ^^^^^^^ duplicate binding
+   |        |
+   |        previous binding
 
 error: aborting due to 4 previous errors
 
index 4bec70850aff76dd34cf47302c0d0e45cd19fc33..475a586ddc083ed4da470db3523c92950fef0e31 100644 (file)
@@ -2,13 +2,9 @@ error[E0557]: feature has been removed
   --> $DIR/macro-reexport-removed.rs:3:12
    |
 LL | #![feature(macro_reexport)]
-   |            ^^^^^^^^^^^^^^
+   |            ^^^^^^^^^^^^^^ feature has been removed
    |
-note: subsumed by `pub use`
-  --> $DIR/macro-reexport-removed.rs:3:12
-   |
-LL | #![feature(macro_reexport)]
-   |            ^^^^^^^^^^^^^^
+   = note: subsumed by `pub use`
 
 error: cannot find attribute `macro_reexport` in this scope
   --> $DIR/macro-reexport-removed.rs:5:3
index 33b7b055b4e4b6d27d4fb37c69b6f818ce587f44..f1e828a46d8f239676483d09f429de6bdc6e108a 100644 (file)
@@ -7,8 +7,8 @@ LL | macro_rules! unknown { () => () }
 error: cannot find a built-in macro with name `line`
   --> <::core::macros::builtin::line macros>:1:1
    |
-LL | () => { }
-   | ^^^^^^^^^
+LL | () => { } ;
+   | ^^^^^^^^^^^
 
 error: aborting due to 2 previous errors
 
index 7139617a97a4fe8e0c3cf312ce67a0b035e1addd..d4a0e45648c25ea2653e9568bf4478119c3f592b 100644 (file)
@@ -83,13 +83,7 @@ LL |         B::U(d) => (),
 LL |         B::V(s) => (),
    |              - ...and here
    |
-note: move occurs because these variables have types that don't implement the `Copy` trait
-  --> $DIR/move-errors.rs:76:14
-   |
-LL |         B::U(d) => (),
-   |              ^
-LL |         B::V(s) => (),
-   |              ^
+   = note: move occurs because these variables have types that don't implement the `Copy` trait
 
 error[E0509]: cannot move out of type `D`, which implements the `Drop` trait
   --> $DIR/move-errors.rs:83:11
@@ -138,11 +132,7 @@ LL |         F(s, mut t) => (),
    |           |
    |           data moved here
    |
-note: move occurs because these variables have types that don't implement the `Copy` trait
-  --> $DIR/move-errors.rs:104:11
-   |
-LL |         F(s, mut t) => (),
-   |           ^  ^^^^^
+   = note: move occurs because these variables have types that don't implement the `Copy` trait
 
 error[E0507]: cannot move out of `x.0` which is behind a shared reference
   --> $DIR/move-errors.rs:110:11
index 738bf7c6c6ba0e60d70a78e25784d878c8f5dac3..2e1d484e05a5a4d8fa670382efda5fee6b1531a4 100644 (file)
@@ -2,7 +2,10 @@ error: expected one of `)` or `,`, found `label`
   --> $DIR/expected-comma-found-token.rs:9:5
    |
 LL |     message="the message"
-   |                          - expected one of `)` or `,`
+   |                          -
+   |                          |
+   |                          expected one of `)` or `,`
+   |                          help: missing `,`
 LL |     label="the label"
    |     ^^^^^ unexpected token
 
index cb8bf62a8fe0b4168f8e7b8495064bff7dc991a7..fe9603cb57f1f094905a57f57ec4179dece68ffb 100644 (file)
@@ -2,7 +2,10 @@ error: expected one of `)`, `,`, `@`, or `|`, found `[`
   --> $DIR/pat-lt-bracket-6.rs:5:19
    |
 LL |     let Test(&desc[..]) = x;
-   |                   ^ expected one of `)`, `,`, `@`, or `|`
+   |                   ^
+   |                   |
+   |                   expected one of `)`, `,`, `@`, or `|`
+   |                   help: missing `,`
 
 error[E0658]: subslice patterns are unstable
   --> $DIR/pat-lt-bracket-6.rs:5:20
index aa115659d47a4cc67123a7faff4e81c1768616e5..004dcfb2a7b2d0a9ce63225583cf611a968d4ecf 100644 (file)
@@ -2,7 +2,10 @@ error: expected one of `)`, `,`, `@`, or `|`, found `[`
   --> $DIR/pat-lt-bracket-7.rs:5:16
    |
 LL |     for Thing(x[]) in foo {}
-   |                ^ expected one of `)`, `,`, `@`, or `|`
+   |                ^
+   |                |
+   |                expected one of `)`, `,`, `@`, or `|`
+   |                help: missing `,`
 
 error[E0308]: mismatched types
   --> $DIR/pat-lt-bracket-7.rs:9:30
index 331bfff84f106a778f7f68cf6bfc5aa2d345b6c0..08dd939e2c023f7f3290a796d02f4bc9e005b1cb 100644 (file)
@@ -1,11 +1,11 @@
 fn main() {
     enum Test {
-        Very
-        //~^ ERROR missing comma
-        Bad(usize)
-        //~^ ERROR missing comma
-        Stuff { a: usize }
-        //~^ ERROR missing comma
+        Very //~ HELP missing `,`
+        Bad(usize) //~ HELP missing `,`
+        //~^ ERROR expected one of `(`, `,`, `=`, `{`, or `}`, found `Bad`
+        Stuff { a: usize } //~ HELP missing `,`
+        //~^ ERROR expected one of `,`, `=`, or `}`, found `Stuff`
         Here
+        //~^ ERROR expected one of `,`, `=`, or `}`, found `Here`
     }
 }
index 81c7ae337dbebe0c12e91256032adaaa52691634..a2b650e4f4eb7ca23d98d19a226fb8a8b90fd8ca 100644 (file)
@@ -1,20 +1,37 @@
-error: missing comma
-  --> $DIR/recover-enum.rs:3:13
+error: expected one of `(`, `,`, `=`, `{`, or `}`, found `Bad`
+  --> $DIR/recover-enum.rs:4:9
    |
 LL |         Very
-   |             ^ help: missing comma
+   |             -
+   |             |
+   |             expected one of `(`, `,`, `=`, `{`, or `}`
+   |             help: missing `,`
+LL |         Bad(usize)
+   |         ^^^ unexpected token
 
-error: missing comma
-  --> $DIR/recover-enum.rs:5:19
+error: expected one of `,`, `=`, or `}`, found `Stuff`
+  --> $DIR/recover-enum.rs:6:9
    |
 LL |         Bad(usize)
-   |                   ^ help: missing comma
+   |                   -
+   |                   |
+   |                   expected one of `,`, `=`, or `}`
+   |                   help: missing `,`
+LL |
+LL |         Stuff { a: usize }
+   |         ^^^^^ unexpected token
 
-error: missing comma
-  --> $DIR/recover-enum.rs:7:27
+error: expected one of `,`, `=`, or `}`, found `Here`
+  --> $DIR/recover-enum.rs:8:9
    |
 LL |         Stuff { a: usize }
-   |                           ^ help: missing comma
+   |                           -
+   |                           |
+   |                           expected one of `,`, `=`, or `}`
+   |                           help: missing `,`
+LL |
+LL |         Here
+   |         ^^^^ unexpected token
 
 error: aborting due to 3 previous errors
 
diff --git a/src/test/ui/rfc-2008-non-exhaustive/auxiliary/monovariants.rs b/src/test/ui/rfc-2008-non-exhaustive/auxiliary/monovariants.rs
new file mode 100644 (file)
index 0000000..5f86db8
--- /dev/null
@@ -0,0 +1,8 @@
+#[non_exhaustive]
+pub enum NonExhaustiveMonovariant {
+    Variant(u32),
+}
+
+pub enum ExhaustiveMonovariant {
+    Variant(u32),
+}
diff --git a/src/test/ui/rfc-2008-non-exhaustive/borrowck-exhaustive.rs b/src/test/ui/rfc-2008-non-exhaustive/borrowck-exhaustive.rs
new file mode 100644 (file)
index 0000000..be775b3
--- /dev/null
@@ -0,0 +1,42 @@
+// Test that the borrow checker doesn't consider checking an exhaustive pattern
+// as an access.
+
+// check-pass
+
+// aux-build:monovariants.rs
+extern crate monovariants;
+
+use monovariants::ExhaustiveMonovariant;
+
+enum Local {
+    Variant(u32),
+}
+
+#[non_exhaustive]
+enum LocalNonExhaustive {
+    Variant(u32),
+}
+
+fn main() {
+    let mut x = ExhaustiveMonovariant::Variant(1);
+    let y = &mut x;
+    match x {
+        ExhaustiveMonovariant::Variant(_) => {},
+        _ => {},
+    }
+    drop(y);
+    let mut x = Local::Variant(1);
+    let y = &mut x;
+    match x {
+        Local::Variant(_) => {},
+        _ => {},
+    }
+    drop(y);
+    let mut x = LocalNonExhaustive::Variant(1);
+    let y = &mut x;
+    match x {
+        LocalNonExhaustive::Variant(_) => {},
+        _ => {},
+    }
+    drop(y);
+}
diff --git a/src/test/ui/rfc-2008-non-exhaustive/borrowck-non-exhaustive.rs b/src/test/ui/rfc-2008-non-exhaustive/borrowck-non-exhaustive.rs
new file mode 100644 (file)
index 0000000..00dcf89
--- /dev/null
@@ -0,0 +1,18 @@
+// Test that the borrow checker considers `#[non_exhaustive]` when checking
+// whether a match contains a discriminant read.
+
+// aux-build:monovariants.rs
+extern crate monovariants;
+
+use monovariants::NonExhaustiveMonovariant;
+
+fn main() {
+    let mut x = NonExhaustiveMonovariant::Variant(1);
+    let y = &mut x;
+    match x {
+        NonExhaustiveMonovariant::Variant(_) => {},
+        //~^ ERROR cannot use `x` because it was mutably borrowed
+        _ => {},
+    }
+    drop(y);
+}
diff --git a/src/test/ui/rfc-2008-non-exhaustive/borrowck-non-exhaustive.stderr b/src/test/ui/rfc-2008-non-exhaustive/borrowck-non-exhaustive.stderr
new file mode 100644 (file)
index 0000000..9edfa84
--- /dev/null
@@ -0,0 +1,15 @@
+error[E0503]: cannot use `x` because it was mutably borrowed
+  --> $DIR/borrowck-non-exhaustive.rs:13:9
+   |
+LL |     let y = &mut x;
+   |             ------ borrow of `x` occurs here
+LL |     match x {
+LL |         NonExhaustiveMonovariant::Variant(_) => {},
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use of borrowed `x`
+...
+LL |     drop(y);
+   |          - borrow later used here
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0503`.
index cdffc1d86edfb965bde49898d41a014587c446a1..653ccb9db949aceed4a80d236a12d2bc75d6986e 100644 (file)
@@ -1,5 +1,5 @@
 error[E0038]: the trait `Foo` cannot be made into an object
-  --> $DIR/arbitrary-self-types-not-object-safe.rs:34:32
+  --> $DIR/arbitrary-self-types-not-object-safe.rs:33:32
    |
 LL |     fn foo(self: &Rc<Self>) -> usize;
    |        --- method `foo`'s `self` parameter cannot be dispatched on
@@ -8,7 +8,7 @@ LL |     let x = Rc::new(5usize) as Rc<dyn Foo>;
    |                                ^^^^^^^^^^^ the trait `Foo` cannot be made into an object
 
 error[E0038]: the trait `Foo` cannot be made into an object
-  --> $DIR/arbitrary-self-types-not-object-safe.rs:34:13
+  --> $DIR/arbitrary-self-types-not-object-safe.rs:33:13
    |
 LL |     fn foo(self: &Rc<Self>) -> usize;
    |        --- method `foo`'s `self` parameter cannot be dispatched on
index 725632a12126e5e6ab538030229646895f1056e4..33f1fa2e51be3545b548706a2c0f627c352075eb 100644 (file)
@@ -1,5 +1,5 @@
 error[E0038]: the trait `Foo` cannot be made into an object
-  --> $DIR/arbitrary-self-types-not-object-safe.rs:34:13
+  --> $DIR/arbitrary-self-types-not-object-safe.rs:33:13
    |
 LL |     fn foo(self: &Rc<Self>) -> usize;
    |        --- method `foo`'s `self` parameter cannot be dispatched on
index 2eeabad28db0202507f3706b2c15a411e9f8a276..40e8df3395f6e6294cf19f1c752c784f4529b86d 100644 (file)
@@ -1,7 +1,6 @@
 // revisions: curr object_safe_for_dispatch
 
 #![cfg_attr(object_safe_for_dispatch, feature(object_safe_for_dispatch))]
-#![feature(arbitrary_self_types)]
 
 use std::rc::Rc;
 
index e6eba377a9578c9178a282268ee3c866e92c556e..353da8fd20b22131a60f2ec2c8db5184d9a9ddc6 100644 (file)
@@ -1,5 +1,5 @@
 error[E0038]: the trait `Foo` cannot be made into an object
-  --> $DIR/arbitrary-self-types-not-object-safe.rs:31:32
+  --> $DIR/arbitrary-self-types-not-object-safe.rs:29:32
    |
 LL |     fn foo(self: &Rc<Self>) -> usize;
    |        --- method `foo`'s `self` parameter cannot be dispatched on
@@ -8,7 +8,7 @@ LL |     let x = Rc::new(5usize) as Rc<dyn Foo>;
    |                                ^^^^^^^^^^^ the trait `Foo` cannot be made into an object
 
 error[E0038]: the trait `Foo` cannot be made into an object
-  --> $DIR/arbitrary-self-types-not-object-safe.rs:31:13
+  --> $DIR/arbitrary-self-types-not-object-safe.rs:29:13
    |
 LL |     fn foo(self: &Rc<Self>) -> usize;
    |        --- method `foo`'s `self` parameter cannot be dispatched on
diff --git a/src/test/ui/self/arbitrary_self_types_nested.rs b/src/test/ui/self/arbitrary_self_types_nested.rs
new file mode 100644 (file)
index 0000000..680196f
--- /dev/null
@@ -0,0 +1,36 @@
+// run-pass
+
+use {
+    std::{
+        rc::Rc,
+        sync::Arc,
+    },
+};
+
+#[derive(Default)]
+struct Ty;
+
+trait Trait {
+    fn receive_trait(self: &Arc<Rc<Box<Self>>>) -> u32;
+}
+
+const TRAIT_MAGIC: u32 = 42;
+const INHERENT_MAGIC: u32 = 1995;
+
+impl Trait for Ty {
+    fn receive_trait(self: &Arc<Rc<Box<Self>>>) -> u32 {
+        TRAIT_MAGIC
+    }
+}
+
+impl Ty {
+    fn receive_inherent(self: &Arc<Rc<Box<Self>>>) -> u32 {
+        INHERENT_MAGIC
+    }
+}
+
+fn main() {
+    let ty = <Arc<Rc<Box<Ty>>>>::default();
+    assert_eq!(TRAIT_MAGIC, ty.receive_trait());
+    assert_eq!(INHERENT_MAGIC, ty.receive_inherent());
+}
index cf62cd3a4e6390fac13210baf8a26f7701b6c902..905ad83b659d4fafb3efd2b05f3ba10be1d2c97d 100644 (file)
@@ -1,5 +1,4 @@
 // run-pass
-#![feature(arbitrary_self_types)]
 
 use std::rc::Rc;
 
index fb06344df7ed04b5dab1eb7ffd66c8f55ba276db..973c7cae85a94a5168fc2a9f33dfcc850b848890 100644 (file)
@@ -1,5 +1,4 @@
 // run-pass
-#![feature(arbitrary_self_types)]
 
 use std::rc::Rc;
 
index b78223fd57cf680726fea7b5fd81e8298284c4cd..d43f3132890b5ead536e23122d48d4022185f2f2 100644 (file)
@@ -1,5 +1,4 @@
 // run-pass
-#![feature(arbitrary_self_types)]
 
 use std::rc::Rc;
 
index 9743c13909658b7fa8b4cc2645d1737b257423ba..7c0dd068623f358f5fb989f839316f221210a1d5 100644 (file)
@@ -1,7 +1,6 @@
 // check-pass
 // edition:2018
 
-#![feature(arbitrary_self_types)]
 #![allow(non_snake_case)]
 
 use std::rc::Rc;
index b5aacfaeec427355b0d59bc3c153270f42448e1a..0c801d7023212b0774a918d3a32be93307924a43 100644 (file)
@@ -1,6 +1,5 @@
 // check-pass
 
-#![feature(arbitrary_self_types)]
 #![allow(non_snake_case)]
 
 use std::rc::Rc;
index fa5968de5acc22db778ab62e4570bc9ee25e9dd3..363b7fc2aaeb23c20e43839592b945ef29c12fce 100644 (file)
@@ -1,7 +1,6 @@
 // check-pass
 // edition:2018
 
-#![feature(arbitrary_self_types)]
 #![allow(non_snake_case)]
 
 use std::rc::Rc;
index 163eb49383a877169f9e6ae0fd8bc69cab7f669a..fa39a2b478b1ef2c57cac95d92a853c9cbf37072 100644 (file)
@@ -1,6 +1,5 @@
 // check-pass
 
-#![feature(arbitrary_self_types)]
 #![allow(non_snake_case)]
 
 use std::rc::Rc;
index cc5badaaa6ef6836852eeb1736d38004f12b7d84..3a6f8471e66423622ad1c36bd1c83ee8bf11a876 100644 (file)
@@ -1,7 +1,6 @@
 // check-pass
 // edition:2018
 
-#![feature(arbitrary_self_types)]
 #![allow(non_snake_case)]
 
 use std::rc::Rc;
index df2300deda25fd3b40a989f45b0238a611620e63..bbba88e4e5bb9d7e9dbcfb8cd6e02e11d1d60e88 100644 (file)
@@ -1,6 +1,5 @@
 // check-pass
 
-#![feature(arbitrary_self_types)]
 #![allow(non_snake_case)]
 
 use std::rc::Rc;
index f060800e4da5214a0db9cfe3d7c018199a749a0f..0d3ff630d14e7f500e490a544318b6a322dfeaa5 100644 (file)
@@ -1,7 +1,6 @@
 // check-pass
 // edition:2018
 
-#![feature(arbitrary_self_types)]
 #![allow(non_snake_case)]
 
 use std::rc::Rc;
index 70573598fcb16b4cbd9d90c404e26740601c0378..8f3543135365c33ec1e2d37156f3292f0dbe504d 100644 (file)
@@ -1,6 +1,5 @@
 // check-pass
 
-#![feature(arbitrary_self_types)]
 #![allow(non_snake_case)]
 
 use std::rc::Rc;
index b4f8ff6001d60b8d4d0f5376dbbbf1de0ce97098..1288759703f69f4679a3b3f023c1f9afa6887e19 100644 (file)
@@ -1,5 +1,5 @@
 error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/lt-ref-self-async.rs:13:42
+  --> $DIR/lt-ref-self-async.rs:12:42
    |
 LL |     async fn ref_self(&self, f: &u32) -> &u32 {
    |                                          ^^^^
@@ -7,7 +7,7 @@ LL |     async fn ref_self(&self, f: &u32) -> &u32 {
    = note: hidden type `impl std::future::Future` captures lifetime '_#23r
 
 error: lifetime may not live long enough
-  --> $DIR/lt-ref-self-async.rs:14:9
+  --> $DIR/lt-ref-self-async.rs:13:9
    |
 LL |     async fn ref_self(&self, f: &u32) -> &u32 {
    |                       -
@@ -18,7 +18,7 @@ LL |         f
    |         ^ function was supposed to return data with lifetime `'_` but it is returning data with lifetime `'_`
 
 error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/lt-ref-self-async.rs:19:48
+  --> $DIR/lt-ref-self-async.rs:18:48
    |
 LL |     async fn ref_Self(self: &Self, f: &u32) -> &u32 {
    |                                                ^^^^
@@ -26,7 +26,7 @@ LL |     async fn ref_Self(self: &Self, f: &u32) -> &u32 {
    = note: hidden type `impl std::future::Future` captures lifetime '_#23r
 
 error: lifetime may not live long enough
-  --> $DIR/lt-ref-self-async.rs:20:9
+  --> $DIR/lt-ref-self-async.rs:19:9
    |
 LL |     async fn ref_Self(self: &Self, f: &u32) -> &u32 {
    |                             -
@@ -37,7 +37,7 @@ LL |         f
    |         ^ function was supposed to return data with lifetime `'_` but it is returning data with lifetime `'_`
 
 error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/lt-ref-self-async.rs:23:57
+  --> $DIR/lt-ref-self-async.rs:22:57
    |
 LL |     async fn box_ref_Self(self: Box<&Self>, f: &u32) -> &u32 {
    |                                                         ^^^^
@@ -45,7 +45,7 @@ LL |     async fn box_ref_Self(self: Box<&Self>, f: &u32) -> &u32 {
    = note: hidden type `impl std::future::Future` captures lifetime '_#23r
 
 error: lifetime may not live long enough
-  --> $DIR/lt-ref-self-async.rs:24:9
+  --> $DIR/lt-ref-self-async.rs:23:9
    |
 LL |     async fn box_ref_Self(self: Box<&Self>, f: &u32) -> &u32 {
    |                                     -
@@ -56,7 +56,7 @@ LL |         f
    |         ^ function was supposed to return data with lifetime `'_` but it is returning data with lifetime `'_`
 
 error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/lt-ref-self-async.rs:27:57
+  --> $DIR/lt-ref-self-async.rs:26:57
    |
 LL |     async fn pin_ref_Self(self: Pin<&Self>, f: &u32) -> &u32 {
    |                                                         ^^^^
@@ -64,7 +64,7 @@ LL |     async fn pin_ref_Self(self: Pin<&Self>, f: &u32) -> &u32 {
    = note: hidden type `impl std::future::Future` captures lifetime '_#23r
 
 error: lifetime may not live long enough
-  --> $DIR/lt-ref-self-async.rs:28:9
+  --> $DIR/lt-ref-self-async.rs:27:9
    |
 LL |     async fn pin_ref_Self(self: Pin<&Self>, f: &u32) -> &u32 {
    |                                     -
@@ -75,7 +75,7 @@ LL |         f
    |         ^ function was supposed to return data with lifetime `'_` but it is returning data with lifetime `'_`
 
 error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/lt-ref-self-async.rs:31:66
+  --> $DIR/lt-ref-self-async.rs:30:66
    |
 LL |     async fn box_box_ref_Self(self: Box<Box<&Self>>, f: &u32) -> &u32 {
    |                                                                  ^^^^
@@ -83,7 +83,7 @@ LL |     async fn box_box_ref_Self(self: Box<Box<&Self>>, f: &u32) -> &u32 {
    = note: hidden type `impl std::future::Future` captures lifetime '_#23r
 
 error: lifetime may not live long enough
-  --> $DIR/lt-ref-self-async.rs:32:9
+  --> $DIR/lt-ref-self-async.rs:31:9
    |
 LL |     async fn box_box_ref_Self(self: Box<Box<&Self>>, f: &u32) -> &u32 {
    |                                             -
@@ -94,7 +94,7 @@ LL |         f
    |         ^ function was supposed to return data with lifetime `'_` but it is returning data with lifetime `'_`
 
 error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/lt-ref-self-async.rs:35:62
+  --> $DIR/lt-ref-self-async.rs:34:62
    |
 LL |     async fn box_pin_Self(self: Box<Pin<&Self>>, f: &u32) -> &u32 {
    |                                                              ^^^^
@@ -102,7 +102,7 @@ LL |     async fn box_pin_Self(self: Box<Pin<&Self>>, f: &u32) -> &u32 {
    = note: hidden type `impl std::future::Future` captures lifetime '_#23r
 
 error: lifetime may not live long enough
-  --> $DIR/lt-ref-self-async.rs:36:9
+  --> $DIR/lt-ref-self-async.rs:35:9
    |
 LL |     async fn box_pin_Self(self: Box<Pin<&Self>>, f: &u32) -> &u32 {
    |                                         -
index 5aba7cfcf296e7c4add58e65122af7bd37d91073..ef6cbe7772c276cb7960840beda83782113b09f3 100644 (file)
@@ -1,6 +1,5 @@
 // edition:2018
 
-#![feature(arbitrary_self_types)]
 #![allow(non_snake_case)]
 
 use std::pin::Pin;
index 235b71ccab3a8be6643201ec9070d6ed191251e4..badd973c37f088f3437ae8f151dc7847acabaa6e 100644 (file)
@@ -1,5 +1,5 @@
 error[E0623]: lifetime mismatch
-  --> $DIR/lt-ref-self-async.rs:14:9
+  --> $DIR/lt-ref-self-async.rs:13:9
    |
 LL |     async fn ref_self(&self, f: &u32) -> &u32 {
    |                       -----              ----
@@ -9,7 +9,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/lt-ref-self-async.rs:20:9
+  --> $DIR/lt-ref-self-async.rs:19:9
    |
 LL |     async fn ref_Self(self: &Self, f: &u32) -> &u32 {
    |                             -----              ----
@@ -19,7 +19,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/lt-ref-self-async.rs:24:9
+  --> $DIR/lt-ref-self-async.rs:23:9
    |
 LL |     async fn box_ref_Self(self: Box<&Self>, f: &u32) -> &u32 {
    |                                     -----               ----
@@ -29,7 +29,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/lt-ref-self-async.rs:28:9
+  --> $DIR/lt-ref-self-async.rs:27:9
    |
 LL |     async fn pin_ref_Self(self: Pin<&Self>, f: &u32) -> &u32 {
    |                                     -----               ----
@@ -39,7 +39,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/lt-ref-self-async.rs:32:9
+  --> $DIR/lt-ref-self-async.rs:31:9
    |
 LL |     async fn box_box_ref_Self(self: Box<Box<&Self>>, f: &u32) -> &u32 {
    |                                             -----                ----
@@ -49,7 +49,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/lt-ref-self-async.rs:36:9
+  --> $DIR/lt-ref-self-async.rs:35:9
    |
 LL |     async fn box_pin_Self(self: Box<Pin<&Self>>, f: &u32) -> &u32 {
    |                                         -----                ----
index e97a01e746d4b8e5a52bb872a6d6e1ed6466c339..a0c56f2221850e50fd03b9316ae9f7edd5a21115 100644 (file)
@@ -1,5 +1,5 @@
 error: lifetime may not live long enough
-  --> $DIR/lt-ref-self.rs:12:9
+  --> $DIR/lt-ref-self.rs:11:9
    |
 LL |     fn ref_self(&self, f: &u32) -> &u32 {
    |                 -         - let's call the lifetime of this reference `'1`
@@ -9,7 +9,7 @@ LL |         f
    |         ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
 
 error: lifetime may not live long enough
-  --> $DIR/lt-ref-self.rs:18:9
+  --> $DIR/lt-ref-self.rs:17:9
    |
 LL |     fn ref_Self(self: &Self, f: &u32) -> &u32 {
    |                       -         - let's call the lifetime of this reference `'1`
@@ -19,7 +19,7 @@ LL |         f
    |         ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
 
 error: lifetime may not live long enough
-  --> $DIR/lt-ref-self.rs:22:9
+  --> $DIR/lt-ref-self.rs:21:9
    |
 LL |     fn box_ref_Self(self: Box<&Self>, f: &u32) -> &u32 {
    |                               -          - let's call the lifetime of this reference `'1`
@@ -29,7 +29,7 @@ LL |         f
    |         ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
 
 error: lifetime may not live long enough
-  --> $DIR/lt-ref-self.rs:26:9
+  --> $DIR/lt-ref-self.rs:25:9
    |
 LL |     fn pin_ref_Self(self: Pin<&Self>, f: &u32) -> &u32 {
    |                               -          - let's call the lifetime of this reference `'1`
@@ -39,7 +39,7 @@ LL |         f
    |         ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
 
 error: lifetime may not live long enough
-  --> $DIR/lt-ref-self.rs:30:9
+  --> $DIR/lt-ref-self.rs:29:9
    |
 LL |     fn box_box_ref_Self(self: Box<Box<&Self>>, f: &u32) -> &u32 {
    |                                       -           - let's call the lifetime of this reference `'1`
@@ -49,7 +49,7 @@ LL |         f
    |         ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
 
 error: lifetime may not live long enough
-  --> $DIR/lt-ref-self.rs:34:9
+  --> $DIR/lt-ref-self.rs:33:9
    |
 LL |     fn box_pin_Self(self: Box<Pin<&Self>>, f: &u32) -> &u32 {
    |                                   -           - let's call the lifetime of this reference `'1`
index 8abf2876a5c1b155136dd6fbe39fe872a7661aca..423c7d5822df7389ba8fbf39210a39672caa30d9 100644 (file)
@@ -1,4 +1,3 @@
-#![feature(arbitrary_self_types)]
 #![allow(non_snake_case)]
 
 use std::pin::Pin;
index afd07d38f2fe47ab198d3f2cfec61015f6a78acc..f392580d422097b18960616012efaa9fa5b7af5c 100644 (file)
@@ -1,5 +1,5 @@
 error[E0623]: lifetime mismatch
-  --> $DIR/lt-ref-self.rs:12:9
+  --> $DIR/lt-ref-self.rs:11:9
    |
 LL |     fn ref_self(&self, f: &u32) -> &u32 {
    |                           ----     ----
@@ -9,7 +9,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/lt-ref-self.rs:18:9
+  --> $DIR/lt-ref-self.rs:17:9
    |
 LL |     fn ref_Self(self: &Self, f: &u32) -> &u32 {
    |                                 ----     ----
@@ -19,7 +19,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/lt-ref-self.rs:22:9
+  --> $DIR/lt-ref-self.rs:21:9
    |
 LL |     fn box_ref_Self(self: Box<&Self>, f: &u32) -> &u32 {
    |                                          ----     ----
@@ -29,7 +29,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/lt-ref-self.rs:26:9
+  --> $DIR/lt-ref-self.rs:25:9
    |
 LL |     fn pin_ref_Self(self: Pin<&Self>, f: &u32) -> &u32 {
    |                                          ----     ----
@@ -39,7 +39,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/lt-ref-self.rs:30:9
+  --> $DIR/lt-ref-self.rs:29:9
    |
 LL |     fn box_box_ref_Self(self: Box<Box<&Self>>, f: &u32) -> &u32 {
    |                                                   ----     ----
@@ -49,7 +49,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/lt-ref-self.rs:34:9
+  --> $DIR/lt-ref-self.rs:33:9
    |
 LL |     fn box_pin_Self(self: Box<Pin<&Self>>, f: &u32) -> &u32 {
    |                                               ----     ----
index 42647b82ef8e73c7c8fac93128c14834ae276c5f..4cedaf79da3a3ede3b2058a4953f370ae0d0c176 100644 (file)
@@ -1,7 +1,6 @@
 // check-pass
 // edition:2018
 
-#![feature(arbitrary_self_types)]
 #![allow(non_snake_case)]
 
 use std::pin::Pin;
index 9b0ee5e42a51ade616bb70d5df839257c7943155..cf74f892b8fcec57164d201a6fdad9a0a29031cb 100644 (file)
@@ -1,6 +1,5 @@
 // check-pass
 
-#![feature(arbitrary_self_types)]
 #![allow(non_snake_case)]
 
 use std::pin::Pin;
index dc5a53b89d78622bd0e69f17e12484176f526237..abbee7fdfcb874e5ae3bf9a8167de4e3004f41ab 100644 (file)
@@ -1,7 +1,6 @@
 // check-pass
 // edition:2018
 
-#![feature(arbitrary_self_types)]
 #![allow(non_snake_case)]
 
 use std::rc::Rc;
index e41dfbbe0bf0d1265b61863cdb05dde49b12b6ec..799c6c079b34d6051c362e8b62a8b745782e9aa7 100644 (file)
@@ -1,6 +1,5 @@
 // check-pass
 
-#![feature(arbitrary_self_types)]
 #![allow(non_snake_case)]
 
 use std::rc::Rc;
index 4b02c2fd00c86fad81d11aad9dff88cb98f11be7..15f16525b6b1c078d693d4c217e14a5f6c662e87 100644 (file)
@@ -1,7 +1,6 @@
 // edition:2018
 // check-pass
 
-#![feature(arbitrary_self_types)]
 #![allow(non_snake_case)]
 
 use std::pin::Pin;
index d83ac612235e35766fc89c03863fd0b9ffbfb1b1..341f5b52df0adfdebec2e08258fe6c2ea9dd9fb6 100644 (file)
@@ -1,6 +1,5 @@
 // check-pass
 
-#![feature(arbitrary_self_types)]
 #![allow(non_snake_case)]
 
 use std::pin::Pin;
index 258e27b7cb3bc0fb3c27f81b984e7cfb60d75ed1..ad10d8ba4f4e2b61d3856b10138d66f55c65825b 100644 (file)
@@ -1,7 +1,6 @@
 // edition:2018
 // check-pass
 
-#![feature(arbitrary_self_types)]
 #![allow(non_snake_case)]
 
 use std::pin::Pin;
index f9354bc884710e42e21e1adb0d6b2f22d1ec3d25..2f02cb5f3c8af6dce4771b4bcc3717a62b411fc4 100644 (file)
@@ -1,6 +1,5 @@
 // check-pass
 
-#![feature(arbitrary_self_types)]
 #![allow(non_snake_case)]
 
 use std::pin::Pin;
index 5f9ccf3bc7f2bbcaa543d4bc9e97c8fb3a9ed0c5..2c3f971d26e8b134aec48083a34ce1d445c637b9 100644 (file)
@@ -1,7 +1,6 @@
 // edition:2018
 // check-pass
 
-#![feature(arbitrary_self_types)]
 #![allow(non_snake_case)]
 
 use std::pin::Pin;
index 395816f8f5d80f75aeaedd719bfd05663c8704d3..ce1ab3ffccaba2c7ad4e11c488f8afd42b4808f1 100644 (file)
@@ -1,6 +1,5 @@
 // check-pass
 
-#![feature(arbitrary_self_types)]
 #![allow(non_snake_case)]
 
 use std::pin::Pin;
index b6f2b63f093b193c3ccffbb77b7d0751fbc27fd9..24e3f7a098fb1e8966f4cb3bac4b2a73d8b3a97f 100644 (file)
@@ -1,5 +1,5 @@
 error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/ref-mut-self-async.rs:13:46
+  --> $DIR/ref-mut-self-async.rs:12:46
    |
 LL |     async fn ref_self(&mut self, f: &u32) -> &u32 {
    |                                              ^^^^
@@ -7,7 +7,7 @@ LL |     async fn ref_self(&mut self, f: &u32) -> &u32 {
    = note: hidden type `impl std::future::Future` captures lifetime '_#15r
 
 error: lifetime may not live long enough
-  --> $DIR/ref-mut-self-async.rs:14:9
+  --> $DIR/ref-mut-self-async.rs:13:9
    |
 LL |     async fn ref_self(&mut self, f: &u32) -> &u32 {
    |                       -
@@ -18,7 +18,7 @@ LL |         f
    |         ^ function was supposed to return data with lifetime `'_` but it is returning data with lifetime `'_`
 
 error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/ref-mut-self-async.rs:19:52
+  --> $DIR/ref-mut-self-async.rs:18:52
    |
 LL |     async fn ref_Self(self: &mut Self, f: &u32) -> &u32 {
    |                                                    ^^^^
@@ -26,7 +26,7 @@ LL |     async fn ref_Self(self: &mut Self, f: &u32) -> &u32 {
    = note: hidden type `impl std::future::Future` captures lifetime '_#15r
 
 error: lifetime may not live long enough
-  --> $DIR/ref-mut-self-async.rs:20:9
+  --> $DIR/ref-mut-self-async.rs:19:9
    |
 LL |     async fn ref_Self(self: &mut Self, f: &u32) -> &u32 {
    |                             -
@@ -37,7 +37,7 @@ LL |         f
    |         ^ function was supposed to return data with lifetime `'_` but it is returning data with lifetime `'_`
 
 error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/ref-mut-self-async.rs:23:61
+  --> $DIR/ref-mut-self-async.rs:22:61
    |
 LL |     async fn box_ref_Self(self: Box<&mut Self>, f: &u32) -> &u32 {
    |                                                             ^^^^
@@ -45,7 +45,7 @@ LL |     async fn box_ref_Self(self: Box<&mut Self>, f: &u32) -> &u32 {
    = note: hidden type `impl std::future::Future` captures lifetime '_#15r
 
 error: lifetime may not live long enough
-  --> $DIR/ref-mut-self-async.rs:24:9
+  --> $DIR/ref-mut-self-async.rs:23:9
    |
 LL |     async fn box_ref_Self(self: Box<&mut Self>, f: &u32) -> &u32 {
    |                                     -
@@ -56,7 +56,7 @@ LL |         f
    |         ^ function was supposed to return data with lifetime `'_` but it is returning data with lifetime `'_`
 
 error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/ref-mut-self-async.rs:27:61
+  --> $DIR/ref-mut-self-async.rs:26:61
    |
 LL |     async fn pin_ref_Self(self: Pin<&mut Self>, f: &u32) -> &u32 {
    |                                                             ^^^^
@@ -64,7 +64,7 @@ LL |     async fn pin_ref_Self(self: Pin<&mut Self>, f: &u32) -> &u32 {
    = note: hidden type `impl std::future::Future` captures lifetime '_#15r
 
 error: lifetime may not live long enough
-  --> $DIR/ref-mut-self-async.rs:28:9
+  --> $DIR/ref-mut-self-async.rs:27:9
    |
 LL |     async fn pin_ref_Self(self: Pin<&mut Self>, f: &u32) -> &u32 {
    |                                     -
@@ -75,7 +75,7 @@ LL |         f
    |         ^ function was supposed to return data with lifetime `'_` but it is returning data with lifetime `'_`
 
 error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/ref-mut-self-async.rs:31:70
+  --> $DIR/ref-mut-self-async.rs:30:70
    |
 LL |     async fn box_box_ref_Self(self: Box<Box<&mut Self>>, f: &u32) -> &u32 {
    |                                                                      ^^^^
@@ -83,7 +83,7 @@ LL |     async fn box_box_ref_Self(self: Box<Box<&mut Self>>, f: &u32) -> &u32 {
    = note: hidden type `impl std::future::Future` captures lifetime '_#15r
 
 error: lifetime may not live long enough
-  --> $DIR/ref-mut-self-async.rs:32:9
+  --> $DIR/ref-mut-self-async.rs:31:9
    |
 LL |     async fn box_box_ref_Self(self: Box<Box<&mut Self>>, f: &u32) -> &u32 {
    |                                             -
@@ -94,7 +94,7 @@ LL |         f
    |         ^ function was supposed to return data with lifetime `'_` but it is returning data with lifetime `'_`
 
 error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/ref-mut-self-async.rs:35:70
+  --> $DIR/ref-mut-self-async.rs:34:70
    |
 LL |     async fn box_pin_ref_Self(self: Box<Pin<&mut Self>>, f: &u32) -> &u32 {
    |                                                                      ^^^^
@@ -102,7 +102,7 @@ LL |     async fn box_pin_ref_Self(self: Box<Pin<&mut Self>>, f: &u32) -> &u32 {
    = note: hidden type `impl std::future::Future` captures lifetime '_#15r
 
 error: lifetime may not live long enough
-  --> $DIR/ref-mut-self-async.rs:36:9
+  --> $DIR/ref-mut-self-async.rs:35:9
    |
 LL |     async fn box_pin_ref_Self(self: Box<Pin<&mut Self>>, f: &u32) -> &u32 {
    |                                             -
index b8eb416d90432a2e702eafc34e2177983164bcd1..1e65605036d6f0b12ed49876184fc1886cbbb510 100644 (file)
@@ -1,6 +1,5 @@
 // edition:2018
 
-#![feature(arbitrary_self_types)]
 #![allow(non_snake_case)]
 
 use std::pin::Pin;
index a656808d46bc2bb965062beb5c587518ecf5038a..73d942a83f89ac32d419f399d8232aefda6619c6 100644 (file)
@@ -1,5 +1,5 @@
 error[E0623]: lifetime mismatch
-  --> $DIR/ref-mut-self-async.rs:14:9
+  --> $DIR/ref-mut-self-async.rs:13:9
    |
 LL |     async fn ref_self(&mut self, f: &u32) -> &u32 {
    |                       ---------              ----
@@ -9,7 +9,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/ref-mut-self-async.rs:20:9
+  --> $DIR/ref-mut-self-async.rs:19:9
    |
 LL |     async fn ref_Self(self: &mut Self, f: &u32) -> &u32 {
    |                             ---------              ----
@@ -19,7 +19,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/ref-mut-self-async.rs:24:9
+  --> $DIR/ref-mut-self-async.rs:23:9
    |
 LL |     async fn box_ref_Self(self: Box<&mut Self>, f: &u32) -> &u32 {
    |                                     ---------               ----
@@ -29,7 +29,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/ref-mut-self-async.rs:28:9
+  --> $DIR/ref-mut-self-async.rs:27:9
    |
 LL |     async fn pin_ref_Self(self: Pin<&mut Self>, f: &u32) -> &u32 {
    |                                     ---------               ----
@@ -39,7 +39,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/ref-mut-self-async.rs:32:9
+  --> $DIR/ref-mut-self-async.rs:31:9
    |
 LL |     async fn box_box_ref_Self(self: Box<Box<&mut Self>>, f: &u32) -> &u32 {
    |                                             ---------                ----
@@ -49,7 +49,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/ref-mut-self-async.rs:36:9
+  --> $DIR/ref-mut-self-async.rs:35:9
    |
 LL |     async fn box_pin_ref_Self(self: Box<Pin<&mut Self>>, f: &u32) -> &u32 {
    |                                             ---------                ----
index 3a8ae3fdcba8c0ff759472b613d5d56bb719fde6..4e7d7f521d2568045c25da8d5874ab0558babbf0 100644 (file)
@@ -1,5 +1,5 @@
 error: lifetime may not live long enough
-  --> $DIR/ref-mut-self.rs:12:9
+  --> $DIR/ref-mut-self.rs:11:9
    |
 LL |     fn ref_self(&mut self, f: &u32) -> &u32 {
    |                 -             - let's call the lifetime of this reference `'1`
@@ -9,7 +9,7 @@ LL |         f
    |         ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
 
 error: lifetime may not live long enough
-  --> $DIR/ref-mut-self.rs:18:9
+  --> $DIR/ref-mut-self.rs:17:9
    |
 LL |     fn ref_Self(self: &mut Self, f: &u32) -> &u32 {
    |                       -             - let's call the lifetime of this reference `'1`
@@ -19,7 +19,7 @@ LL |         f
    |         ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
 
 error: lifetime may not live long enough
-  --> $DIR/ref-mut-self.rs:22:9
+  --> $DIR/ref-mut-self.rs:21:9
    |
 LL |     fn box_ref_Self(self: Box<&mut Self>, f: &u32) -> &u32 {
    |                               -              - let's call the lifetime of this reference `'1`
@@ -29,7 +29,7 @@ LL |         f
    |         ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
 
 error: lifetime may not live long enough
-  --> $DIR/ref-mut-self.rs:26:9
+  --> $DIR/ref-mut-self.rs:25:9
    |
 LL |     fn pin_ref_Self(self: Pin<&mut Self>, f: &u32) -> &u32 {
    |                               -              - let's call the lifetime of this reference `'1`
@@ -39,7 +39,7 @@ LL |         f
    |         ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
 
 error: lifetime may not live long enough
-  --> $DIR/ref-mut-self.rs:30:9
+  --> $DIR/ref-mut-self.rs:29:9
    |
 LL |     fn box_box_ref_Self(self: Box<Box<&mut Self>>, f: &u32) -> &u32 {
    |                                       -               - let's call the lifetime of this reference `'1`
@@ -49,7 +49,7 @@ LL |         f
    |         ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
 
 error: lifetime may not live long enough
-  --> $DIR/ref-mut-self.rs:34:9
+  --> $DIR/ref-mut-self.rs:33:9
    |
 LL |     fn box_pin_ref_Self(self: Box<Pin<&mut Self>>, f: &u32) -> &u32 {
    |                                       -               - let's call the lifetime of this reference `'1`
index a7ea47bb7f6de87e037492dff3b737b6254ef465..8d9359dbd94b571c369a8cc34c20c1df2b514b67 100644 (file)
@@ -1,4 +1,3 @@
-#![feature(arbitrary_self_types)]
 #![allow(non_snake_case)]
 
 use std::pin::Pin;
index 3d6ae4b3dd388889206bcd39b6db4c9fb0b66398..46d849741ebe3d9fd863c386948de406b2cd31de 100644 (file)
@@ -1,5 +1,5 @@
 error[E0623]: lifetime mismatch
-  --> $DIR/ref-mut-self.rs:12:9
+  --> $DIR/ref-mut-self.rs:11:9
    |
 LL |     fn ref_self(&mut self, f: &u32) -> &u32 {
    |                               ----     ----
@@ -9,7 +9,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/ref-mut-self.rs:18:9
+  --> $DIR/ref-mut-self.rs:17:9
    |
 LL |     fn ref_Self(self: &mut Self, f: &u32) -> &u32 {
    |                                     ----     ----
@@ -19,7 +19,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/ref-mut-self.rs:22:9
+  --> $DIR/ref-mut-self.rs:21:9
    |
 LL |     fn box_ref_Self(self: Box<&mut Self>, f: &u32) -> &u32 {
    |                                              ----     ----
@@ -29,7 +29,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/ref-mut-self.rs:26:9
+  --> $DIR/ref-mut-self.rs:25:9
    |
 LL |     fn pin_ref_Self(self: Pin<&mut Self>, f: &u32) -> &u32 {
    |                                              ----     ----
@@ -39,7 +39,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/ref-mut-self.rs:30:9
+  --> $DIR/ref-mut-self.rs:29:9
    |
 LL |     fn box_box_ref_Self(self: Box<Box<&mut Self>>, f: &u32) -> &u32 {
    |                                                       ----     ----
@@ -49,7 +49,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/ref-mut-self.rs:34:9
+  --> $DIR/ref-mut-self.rs:33:9
    |
 LL |     fn box_pin_ref_Self(self: Box<Pin<&mut Self>>, f: &u32) -> &u32 {
    |                                                       ----     ----
index fa78543bd87ab14d7c3159da606e3d0a2124eea2..c0423d1d3e6691c94ee3d87d5a2569e6eb9c3d31 100644 (file)
@@ -1,5 +1,5 @@
 error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/ref-mut-struct-async.rs:13:56
+  --> $DIR/ref-mut-struct-async.rs:12:56
    |
 LL |     async fn ref_Struct(self: &mut Struct, f: &u32) -> &u32 {
    |                                                        ^^^^
@@ -7,7 +7,7 @@ LL |     async fn ref_Struct(self: &mut Struct, f: &u32) -> &u32 {
    = note: hidden type `impl std::future::Future` captures lifetime '_#15r
 
 error: lifetime may not live long enough
-  --> $DIR/ref-mut-struct-async.rs:14:9
+  --> $DIR/ref-mut-struct-async.rs:13:9
    |
 LL |     async fn ref_Struct(self: &mut Struct, f: &u32) -> &u32 {
    |                               -
@@ -18,7 +18,7 @@ LL |         f
    |         ^ function was supposed to return data with lifetime `'_` but it is returning data with lifetime `'_`
 
 error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/ref-mut-struct-async.rs:17:65
+  --> $DIR/ref-mut-struct-async.rs:16:65
    |
 LL |     async fn box_ref_Struct(self: Box<&mut Struct>, f: &u32) -> &u32 {
    |                                                                 ^^^^
@@ -26,7 +26,7 @@ LL |     async fn box_ref_Struct(self: Box<&mut Struct>, f: &u32) -> &u32 {
    = note: hidden type `impl std::future::Future` captures lifetime '_#15r
 
 error: lifetime may not live long enough
-  --> $DIR/ref-mut-struct-async.rs:18:9
+  --> $DIR/ref-mut-struct-async.rs:17:9
    |
 LL |     async fn box_ref_Struct(self: Box<&mut Struct>, f: &u32) -> &u32 {
    |                                       -
@@ -37,7 +37,7 @@ LL |         f
    |         ^ function was supposed to return data with lifetime `'_` but it is returning data with lifetime `'_`
 
 error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/ref-mut-struct-async.rs:21:65
+  --> $DIR/ref-mut-struct-async.rs:20:65
    |
 LL |     async fn pin_ref_Struct(self: Pin<&mut Struct>, f: &u32) -> &u32 {
    |                                                                 ^^^^
@@ -45,7 +45,7 @@ LL |     async fn pin_ref_Struct(self: Pin<&mut Struct>, f: &u32) -> &u32 {
    = note: hidden type `impl std::future::Future` captures lifetime '_#15r
 
 error: lifetime may not live long enough
-  --> $DIR/ref-mut-struct-async.rs:22:9
+  --> $DIR/ref-mut-struct-async.rs:21:9
    |
 LL |     async fn pin_ref_Struct(self: Pin<&mut Struct>, f: &u32) -> &u32 {
    |                                       -
@@ -56,7 +56,7 @@ LL |         f
    |         ^ function was supposed to return data with lifetime `'_` but it is returning data with lifetime `'_`
 
 error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/ref-mut-struct-async.rs:25:74
+  --> $DIR/ref-mut-struct-async.rs:24:74
    |
 LL |     async fn box_box_ref_Struct(self: Box<Box<&mut Struct>>, f: &u32) -> &u32 {
    |                                                                          ^^^^
@@ -64,7 +64,7 @@ LL |     async fn box_box_ref_Struct(self: Box<Box<&mut Struct>>, f: &u32) -> &u
    = note: hidden type `impl std::future::Future` captures lifetime '_#15r
 
 error: lifetime may not live long enough
-  --> $DIR/ref-mut-struct-async.rs:26:9
+  --> $DIR/ref-mut-struct-async.rs:25:9
    |
 LL |     async fn box_box_ref_Struct(self: Box<Box<&mut Struct>>, f: &u32) -> &u32 {
    |                                               -
@@ -75,7 +75,7 @@ LL |         f
    |         ^ function was supposed to return data with lifetime `'_` but it is returning data with lifetime `'_`
 
 error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/ref-mut-struct-async.rs:29:74
+  --> $DIR/ref-mut-struct-async.rs:28:74
    |
 LL |     async fn box_pin_ref_Struct(self: Box<Pin<&mut Struct>>, f: &u32) -> &u32 {
    |                                                                          ^^^^
@@ -83,7 +83,7 @@ LL |     async fn box_pin_ref_Struct(self: Box<Pin<&mut Struct>>, f: &u32) -> &u
    = note: hidden type `impl std::future::Future` captures lifetime '_#15r
 
 error: lifetime may not live long enough
-  --> $DIR/ref-mut-struct-async.rs:30:9
+  --> $DIR/ref-mut-struct-async.rs:29:9
    |
 LL |     async fn box_pin_ref_Struct(self: Box<Pin<&mut Struct>>, f: &u32) -> &u32 {
    |                                               -
index 1822a9a468b0ee32b54bf38590d3536834d724b1..990f485907f8ec70cc9b534e13463af17c7b810b 100644 (file)
@@ -1,6 +1,5 @@
 // edition:2018
 
-#![feature(arbitrary_self_types)]
 #![allow(non_snake_case)]
 
 use std::pin::Pin;
index 2dc8cdb7d28ecb48afeb5bec154482c4e7effc3d..7d613c574486ce2e03a48c8f7d29a7b33ef492ce 100644 (file)
@@ -1,5 +1,5 @@
 error[E0623]: lifetime mismatch
-  --> $DIR/ref-mut-struct-async.rs:14:9
+  --> $DIR/ref-mut-struct-async.rs:13:9
    |
 LL |     async fn ref_Struct(self: &mut Struct, f: &u32) -> &u32 {
    |                               -----------              ----
@@ -9,7 +9,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/ref-mut-struct-async.rs:18:9
+  --> $DIR/ref-mut-struct-async.rs:17:9
    |
 LL |     async fn box_ref_Struct(self: Box<&mut Struct>, f: &u32) -> &u32 {
    |                                       -----------               ----
@@ -19,7 +19,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/ref-mut-struct-async.rs:22:9
+  --> $DIR/ref-mut-struct-async.rs:21:9
    |
 LL |     async fn pin_ref_Struct(self: Pin<&mut Struct>, f: &u32) -> &u32 {
    |                                       -----------               ----
@@ -29,7 +29,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/ref-mut-struct-async.rs:26:9
+  --> $DIR/ref-mut-struct-async.rs:25:9
    |
 LL |     async fn box_box_ref_Struct(self: Box<Box<&mut Struct>>, f: &u32) -> &u32 {
    |                                               -----------                ----
@@ -39,7 +39,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/ref-mut-struct-async.rs:30:9
+  --> $DIR/ref-mut-struct-async.rs:29:9
    |
 LL |     async fn box_pin_ref_Struct(self: Box<Pin<&mut Struct>>, f: &u32) -> &u32 {
    |                                               -----------                ----
index 66152ba40a5f5bdf51eeeb82a93990c87d28cf3f..cec7034cd9f9d2668ed011d8ec347f1350300427 100644 (file)
@@ -1,5 +1,5 @@
 error: lifetime may not live long enough
-  --> $DIR/ref-mut-struct.rs:12:9
+  --> $DIR/ref-mut-struct.rs:11:9
    |
 LL |     fn ref_Struct(self: &mut Struct, f: &u32) -> &u32 {
    |                         -               - let's call the lifetime of this reference `'1`
@@ -9,7 +9,7 @@ LL |         f
    |         ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
 
 error: lifetime may not live long enough
-  --> $DIR/ref-mut-struct.rs:16:9
+  --> $DIR/ref-mut-struct.rs:15:9
    |
 LL |     fn box_ref_Struct(self: Box<&mut Struct>, f: &u32) -> &u32 {
    |                                 -                - let's call the lifetime of this reference `'1`
@@ -19,7 +19,7 @@ LL |         f
    |         ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
 
 error: lifetime may not live long enough
-  --> $DIR/ref-mut-struct.rs:20:9
+  --> $DIR/ref-mut-struct.rs:19:9
    |
 LL |     fn pin_ref_Struct(self: Pin<&mut Struct>, f: &u32) -> &u32 {
    |                                 -                - let's call the lifetime of this reference `'1`
@@ -29,7 +29,7 @@ LL |         f
    |         ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
 
 error: lifetime may not live long enough
-  --> $DIR/ref-mut-struct.rs:24:9
+  --> $DIR/ref-mut-struct.rs:23:9
    |
 LL |     fn box_box_ref_Struct(self: Box<Box<&mut Struct>>, f: &u32) -> &u32 {
    |                                         -                 - let's call the lifetime of this reference `'1`
@@ -39,7 +39,7 @@ LL |         f
    |         ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
 
 error: lifetime may not live long enough
-  --> $DIR/ref-mut-struct.rs:28:9
+  --> $DIR/ref-mut-struct.rs:27:9
    |
 LL |     fn box_pin_ref_Struct(self: Box<Pin<&mut Struct>>, f: &u32) -> &u32 {
    |                                         -                 - let's call the lifetime of this reference `'1`
index 795ddf8ac1354066681f475f85c027ca48c6b536..05e275b19e4c414d6cb422eed2a4db9ff9c769b6 100644 (file)
@@ -1,4 +1,3 @@
-#![feature(arbitrary_self_types)]
 #![allow(non_snake_case)]
 
 use std::pin::Pin;
index 3fec398bb9879c6b658cd7e061deee59ba95fa06..c824f2cac983ea79ac85d7c70e7b081e27fbb0b7 100644 (file)
@@ -1,5 +1,5 @@
 error[E0623]: lifetime mismatch
-  --> $DIR/ref-mut-struct.rs:12:9
+  --> $DIR/ref-mut-struct.rs:11:9
    |
 LL |     fn ref_Struct(self: &mut Struct, f: &u32) -> &u32 {
    |                                         ----     ----
@@ -9,7 +9,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/ref-mut-struct.rs:16:9
+  --> $DIR/ref-mut-struct.rs:15:9
    |
 LL |     fn box_ref_Struct(self: Box<&mut Struct>, f: &u32) -> &u32 {
    |                                                  ----     ----
@@ -19,7 +19,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/ref-mut-struct.rs:20:9
+  --> $DIR/ref-mut-struct.rs:19:9
    |
 LL |     fn pin_ref_Struct(self: Pin<&mut Struct>, f: &u32) -> &u32 {
    |                                                  ----     ----
@@ -29,7 +29,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/ref-mut-struct.rs:24:9
+  --> $DIR/ref-mut-struct.rs:23:9
    |
 LL |     fn box_box_ref_Struct(self: Box<Box<&mut Struct>>, f: &u32) -> &u32 {
    |                                                           ----     ----
@@ -39,7 +39,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/ref-mut-struct.rs:28:9
+  --> $DIR/ref-mut-struct.rs:27:9
    |
 LL |     fn box_pin_ref_Struct(self: Box<Pin<&mut Struct>>, f: &u32) -> &u32 {
    |                                                           ----     ----
index 88fd2101bc619b3bedede0e66bc45adf069cd311..46468b693ee980a964ce6421168686c445d45cb7 100644 (file)
-error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/ref-self-async.rs:22:42
-   |
-LL |     async fn ref_self(&self, f: &u32) -> &u32 {
-   |                                          ^^^^
-   |
-   = note: hidden type `impl std::future::Future` captures lifetime '_#15r
-
-error: lifetime may not live long enough
-  --> $DIR/ref-self-async.rs:23:9
-   |
-LL |     async fn ref_self(&self, f: &u32) -> &u32 {
-   |                       -
-   |                       |
-   |                       lifetime `'_` defined here
-   |                       lifetime `'_` defined here
-LL |         f
-   |         ^ function was supposed to return data with lifetime `'_` but it is returning data with lifetime `'_`
-
-error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/ref-self-async.rs:28:48
-   |
-LL |     async fn ref_Self(self: &Self, f: &u32) -> &u32 {
-   |                                                ^^^^
-   |
-   = note: hidden type `impl std::future::Future` captures lifetime '_#15r
-
-error: lifetime may not live long enough
-  --> $DIR/ref-self-async.rs:29:9
-   |
-LL |     async fn ref_Self(self: &Self, f: &u32) -> &u32 {
-   |                             -
-   |                             |
-   |                             lifetime `'_` defined here
-   |                             lifetime `'_` defined here
-LL |         f
-   |         ^ function was supposed to return data with lifetime `'_` but it is returning data with lifetime `'_`
-
-error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/ref-self-async.rs:32:57
-   |
-LL |     async fn box_ref_Self(self: Box<&Self>, f: &u32) -> &u32 {
-   |                                                         ^^^^
-   |
-   = note: hidden type `impl std::future::Future` captures lifetime '_#15r
-
-error: lifetime may not live long enough
-  --> $DIR/ref-self-async.rs:33:9
-   |
-LL |     async fn box_ref_Self(self: Box<&Self>, f: &u32) -> &u32 {
-   |                                     -
-   |                                     |
-   |                                     lifetime `'_` defined here
-   |                                     lifetime `'_` defined here
-LL |         f
-   |         ^ function was supposed to return data with lifetime `'_` but it is returning data with lifetime `'_`
-
-error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/ref-self-async.rs:36:57
-   |
-LL |     async fn pin_ref_Self(self: Pin<&Self>, f: &u32) -> &u32 {
-   |                                                         ^^^^
-   |
-   = note: hidden type `impl std::future::Future` captures lifetime '_#15r
-
-error: lifetime may not live long enough
-  --> $DIR/ref-self-async.rs:37:9
-   |
-LL |     async fn pin_ref_Self(self: Pin<&Self>, f: &u32) -> &u32 {
-   |                                     -
-   |                                     |
-   |                                     lifetime `'_` defined here
-   |                                     lifetime `'_` defined here
-LL |         f
-   |         ^ function was supposed to return data with lifetime `'_` but it is returning data with lifetime `'_`
-
-error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/ref-self-async.rs:40:66
-   |
-LL |     async fn box_box_ref_Self(self: Box<Box<&Self>>, f: &u32) -> &u32 {
-   |                                                                  ^^^^
-   |
-   = note: hidden type `impl std::future::Future` captures lifetime '_#15r
-
-error: lifetime may not live long enough
-  --> $DIR/ref-self-async.rs:41:9
-   |
-LL |     async fn box_box_ref_Self(self: Box<Box<&Self>>, f: &u32) -> &u32 {
-   |                                             -
-   |                                             |
-   |                                             lifetime `'_` defined here
-   |                                             lifetime `'_` defined here
-LL |         f
-   |         ^ function was supposed to return data with lifetime `'_` but it is returning data with lifetime `'_`
-
-error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/ref-self-async.rs:44:66
-   |
-LL |     async fn box_pin_ref_Self(self: Box<Pin<&Self>>, f: &u32) -> &u32 {
-   |                                                                  ^^^^
-   |
-   = note: hidden type `impl std::future::Future` captures lifetime '_#15r
-
-error: lifetime may not live long enough
-  --> $DIR/ref-self-async.rs:45:9
-   |
-LL |     async fn box_pin_ref_Self(self: Box<Pin<&Self>>, f: &u32) -> &u32 {
-   |                                             -
-   |                                             |
-   |                                             lifetime `'_` defined here
-   |                                             lifetime `'_` defined here
-LL |         f
-   |         ^ function was supposed to return data with lifetime `'_` but it is returning data with lifetime `'_`
-
-error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/ref-self-async.rs:48:69
+error[E0658]: `Wrap<&Struct, Struct>` cannot be used as the type of `self` without the `arbitrary_self_types` feature
+  --> $DIR/ref-self-async.rs:47:39
    |
 LL |     async fn wrap_ref_Self_Self(self: Wrap<&Self, Self>, f: &u8) -> &u8 {
-   |                                                                     ^^^
-   |
-   = note: hidden type `impl std::future::Future` captures lifetime '_#15r
-
-error: lifetime may not live long enough
-  --> $DIR/ref-self-async.rs:49:9
+   |                                       ^^^^^^^^^^^^^^^^^
    |
-LL |     async fn wrap_ref_Self_Self(self: Wrap<&Self, Self>, f: &u8) -> &u8 {
-   |                                            -
-   |                                            |
-   |                                            lifetime `'_` defined here
-   |                                            lifetime `'_` defined here
-LL |         f
-   |         ^ function was supposed to return data with lifetime `'_` but it is returning data with lifetime `'_`
+   = note: for more information, see https://github.com/rust-lang/rust/issues/44874
+   = help: add `#![feature(arbitrary_self_types)]` to the crate attributes to enable
+   = help: consider changing to `self`, `&self`, `&mut self`, `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, or `self: Pin<P>` (where P is one of the previous types except `Self`)
 
-error: aborting due to 14 previous errors
+error: aborting due to previous error
 
-For more information about this error, try `rustc --explain E0700`.
+For more information about this error, try `rustc --explain E0658`.
index 9425fbfca8f084e532d4073a1d01bbe52101f715..6a98b79cb3bbafeb08097042597104c997492fa2 100644 (file)
@@ -1,6 +1,5 @@
 // edition:2018
 
-#![feature(arbitrary_self_types)]
 #![allow(non_snake_case)]
 
 use std::marker::PhantomData;
index bda958241b67b6564df1b8d6e7b8ee6a02ab8c04..b73290b024f8f285f762e624de7f473cb533ed59 100644 (file)
@@ -1,5 +1,5 @@
 error[E0623]: lifetime mismatch
-  --> $DIR/ref-self-async.rs:23:9
+  --> $DIR/ref-self-async.rs:22:9
    |
 LL |     async fn ref_self(&self, f: &u32) -> &u32 {
    |                       -----              ----
@@ -9,7 +9,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/ref-self-async.rs:29:9
+  --> $DIR/ref-self-async.rs:28:9
    |
 LL |     async fn ref_Self(self: &Self, f: &u32) -> &u32 {
    |                             -----              ----
@@ -19,7 +19,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/ref-self-async.rs:33:9
+  --> $DIR/ref-self-async.rs:32:9
    |
 LL |     async fn box_ref_Self(self: Box<&Self>, f: &u32) -> &u32 {
    |                                     -----               ----
@@ -29,7 +29,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/ref-self-async.rs:37:9
+  --> $DIR/ref-self-async.rs:36:9
    |
 LL |     async fn pin_ref_Self(self: Pin<&Self>, f: &u32) -> &u32 {
    |                                     -----               ----
@@ -39,7 +39,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/ref-self-async.rs:41:9
+  --> $DIR/ref-self-async.rs:40:9
    |
 LL |     async fn box_box_ref_Self(self: Box<Box<&Self>>, f: &u32) -> &u32 {
    |                                             -----                ----
@@ -49,7 +49,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/ref-self-async.rs:45:9
+  --> $DIR/ref-self-async.rs:44:9
    |
 LL |     async fn box_pin_ref_Self(self: Box<Pin<&Self>>, f: &u32) -> &u32 {
    |                                             -----                ----
@@ -59,7 +59,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/ref-self-async.rs:49:9
+  --> $DIR/ref-self-async.rs:48:9
    |
 LL |     async fn wrap_ref_Self_Self(self: Wrap<&Self, Self>, f: &u8) -> &u8 {
    |                                            -----                    ---
index 93fec69ec343a2188327165dd9aea09352ed3b0d..6f413a7f49fb8db518ebbc46f1df1643a15d915a 100644 (file)
@@ -1,5 +1,5 @@
 error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/ref-struct-async.rs:13:52
+  --> $DIR/ref-struct-async.rs:12:52
    |
 LL |     async fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
    |                                                    ^^^^
@@ -7,7 +7,7 @@ LL |     async fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
    = note: hidden type `impl std::future::Future` captures lifetime '_#15r
 
 error: lifetime may not live long enough
-  --> $DIR/ref-struct-async.rs:14:9
+  --> $DIR/ref-struct-async.rs:13:9
    |
 LL |     async fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
    |                               -
@@ -18,7 +18,7 @@ LL |         f
    |         ^ function was supposed to return data with lifetime `'_` but it is returning data with lifetime `'_`
 
 error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/ref-struct-async.rs:17:61
+  --> $DIR/ref-struct-async.rs:16:61
    |
 LL |     async fn box_ref_Struct(self: Box<&Struct>, f: &u32) -> &u32 {
    |                                                             ^^^^
@@ -26,7 +26,7 @@ LL |     async fn box_ref_Struct(self: Box<&Struct>, f: &u32) -> &u32 {
    = note: hidden type `impl std::future::Future` captures lifetime '_#15r
 
 error: lifetime may not live long enough
-  --> $DIR/ref-struct-async.rs:18:9
+  --> $DIR/ref-struct-async.rs:17:9
    |
 LL |     async fn box_ref_Struct(self: Box<&Struct>, f: &u32) -> &u32 {
    |                                       -
@@ -37,7 +37,7 @@ LL |         f
    |         ^ function was supposed to return data with lifetime `'_` but it is returning data with lifetime `'_`
 
 error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/ref-struct-async.rs:21:61
+  --> $DIR/ref-struct-async.rs:20:61
    |
 LL |     async fn pin_ref_Struct(self: Pin<&Struct>, f: &u32) -> &u32 {
    |                                                             ^^^^
@@ -45,7 +45,7 @@ LL |     async fn pin_ref_Struct(self: Pin<&Struct>, f: &u32) -> &u32 {
    = note: hidden type `impl std::future::Future` captures lifetime '_#15r
 
 error: lifetime may not live long enough
-  --> $DIR/ref-struct-async.rs:22:9
+  --> $DIR/ref-struct-async.rs:21:9
    |
 LL |     async fn pin_ref_Struct(self: Pin<&Struct>, f: &u32) -> &u32 {
    |                                       -
@@ -56,7 +56,7 @@ LL |         f
    |         ^ function was supposed to return data with lifetime `'_` but it is returning data with lifetime `'_`
 
 error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/ref-struct-async.rs:25:70
+  --> $DIR/ref-struct-async.rs:24:70
    |
 LL |     async fn box_box_ref_Struct(self: Box<Box<&Struct>>, f: &u32) -> &u32 {
    |                                                                      ^^^^
@@ -64,7 +64,7 @@ LL |     async fn box_box_ref_Struct(self: Box<Box<&Struct>>, f: &u32) -> &u32 {
    = note: hidden type `impl std::future::Future` captures lifetime '_#15r
 
 error: lifetime may not live long enough
-  --> $DIR/ref-struct-async.rs:26:9
+  --> $DIR/ref-struct-async.rs:25:9
    |
 LL |     async fn box_box_ref_Struct(self: Box<Box<&Struct>>, f: &u32) -> &u32 {
    |                                               -
@@ -75,7 +75,7 @@ LL |         f
    |         ^ function was supposed to return data with lifetime `'_` but it is returning data with lifetime `'_`
 
 error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
-  --> $DIR/ref-struct-async.rs:29:66
+  --> $DIR/ref-struct-async.rs:28:66
    |
 LL |     async fn box_pin_Struct(self: Box<Pin<&Struct>>, f: &u32) -> &u32 {
    |                                                                  ^^^^
@@ -83,7 +83,7 @@ LL |     async fn box_pin_Struct(self: Box<Pin<&Struct>>, f: &u32) -> &u32 {
    = note: hidden type `impl std::future::Future` captures lifetime '_#15r
 
 error: lifetime may not live long enough
-  --> $DIR/ref-struct-async.rs:30:9
+  --> $DIR/ref-struct-async.rs:29:9
    |
 LL |     async fn box_pin_Struct(self: Box<Pin<&Struct>>, f: &u32) -> &u32 {
    |                                           -
index 64c84c4cd2eb9e209a83bdc99bbcb23162042692..e6bd5418c8d92b8b6986e41aecd277c12159ef22 100644 (file)
@@ -1,6 +1,5 @@
 // edition:2018
 
-#![feature(arbitrary_self_types)]
 #![allow(non_snake_case)]
 
 use std::pin::Pin;
index 49a2a00953d8793905d7af10746dd28814487565..fc85450c4a7cde14668aa951960dc0913e002543 100644 (file)
@@ -1,5 +1,5 @@
 error[E0623]: lifetime mismatch
-  --> $DIR/ref-struct-async.rs:14:9
+  --> $DIR/ref-struct-async.rs:13:9
    |
 LL |     async fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
    |                               -------              ----
@@ -9,7 +9,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/ref-struct-async.rs:18:9
+  --> $DIR/ref-struct-async.rs:17:9
    |
 LL |     async fn box_ref_Struct(self: Box<&Struct>, f: &u32) -> &u32 {
    |                                       -------               ----
@@ -19,7 +19,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/ref-struct-async.rs:22:9
+  --> $DIR/ref-struct-async.rs:21:9
    |
 LL |     async fn pin_ref_Struct(self: Pin<&Struct>, f: &u32) -> &u32 {
    |                                       -------               ----
@@ -29,7 +29,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/ref-struct-async.rs:26:9
+  --> $DIR/ref-struct-async.rs:25:9
    |
 LL |     async fn box_box_ref_Struct(self: Box<Box<&Struct>>, f: &u32) -> &u32 {
    |                                               -------                ----
@@ -39,7 +39,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/ref-struct-async.rs:30:9
+  --> $DIR/ref-struct-async.rs:29:9
    |
 LL |     async fn box_pin_Struct(self: Box<Pin<&Struct>>, f: &u32) -> &u32 {
    |                                           -------                ----
index a258bc9f7439038b5f6498418312edab3ae495c5..31bb9f49a6c4d5dea8f5438cf6a60ae4182c4c24 100644 (file)
@@ -1,5 +1,5 @@
 error: lifetime may not live long enough
-  --> $DIR/ref-struct.rs:12:9
+  --> $DIR/ref-struct.rs:11:9
    |
 LL |     fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
    |                         -           - let's call the lifetime of this reference `'1`
@@ -9,7 +9,7 @@ LL |         f
    |         ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
 
 error: lifetime may not live long enough
-  --> $DIR/ref-struct.rs:16:9
+  --> $DIR/ref-struct.rs:15:9
    |
 LL |     fn box_ref_Struct(self: Box<&Struct>, f: &u32) -> &u32 {
    |                                 -            - let's call the lifetime of this reference `'1`
@@ -19,7 +19,7 @@ LL |         f
    |         ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
 
 error: lifetime may not live long enough
-  --> $DIR/ref-struct.rs:20:9
+  --> $DIR/ref-struct.rs:19:9
    |
 LL |     fn pin_ref_Struct(self: Pin<&Struct>, f: &u32) -> &u32 {
    |                                 -            - let's call the lifetime of this reference `'1`
@@ -29,7 +29,7 @@ LL |         f
    |         ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
 
 error: lifetime may not live long enough
-  --> $DIR/ref-struct.rs:24:9
+  --> $DIR/ref-struct.rs:23:9
    |
 LL |     fn box_box_ref_Struct(self: Box<Box<&Struct>>, f: &u32) -> &u32 {
    |                                         -             - let's call the lifetime of this reference `'1`
@@ -39,7 +39,7 @@ LL |         f
    |         ^ function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1`
 
 error: lifetime may not live long enough
-  --> $DIR/ref-struct.rs:28:9
+  --> $DIR/ref-struct.rs:27:9
    |
 LL |     fn box_pin_Struct(self: Box<Pin<&Struct>>, f: &u32) -> &u32 {
    |                                     -             - let's call the lifetime of this reference `'1`
index 342d6d2b36357bffa93dc9d84a556e6f716637df..73711a7feead3a8dfab0e6c3968c0647063b94b4 100644 (file)
@@ -1,4 +1,3 @@
-#![feature(arbitrary_self_types)]
 #![allow(non_snake_case)]
 
 use std::pin::Pin;
index 5116488dd22bb3154d5ba67582418543973638f5..a69673091431c43a6921362a8a8810441eefc37c 100644 (file)
@@ -1,5 +1,5 @@
 error[E0623]: lifetime mismatch
-  --> $DIR/ref-struct.rs:12:9
+  --> $DIR/ref-struct.rs:11:9
    |
 LL |     fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
    |                                     ----     ----
@@ -9,7 +9,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/ref-struct.rs:16:9
+  --> $DIR/ref-struct.rs:15:9
    |
 LL |     fn box_ref_Struct(self: Box<&Struct>, f: &u32) -> &u32 {
    |                                              ----     ----
@@ -19,7 +19,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/ref-struct.rs:20:9
+  --> $DIR/ref-struct.rs:19:9
    |
 LL |     fn pin_ref_Struct(self: Pin<&Struct>, f: &u32) -> &u32 {
    |                                              ----     ----
@@ -29,7 +29,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/ref-struct.rs:24:9
+  --> $DIR/ref-struct.rs:23:9
    |
 LL |     fn box_box_ref_Struct(self: Box<Box<&Struct>>, f: &u32) -> &u32 {
    |                                                       ----     ----
@@ -39,7 +39,7 @@ LL |         f
    |         ^ ...but data from `f` is returned here
 
 error[E0623]: lifetime mismatch
-  --> $DIR/ref-struct.rs:28:9
+  --> $DIR/ref-struct.rs:27:9
    |
 LL |     fn box_pin_Struct(self: Box<Pin<&Struct>>, f: &u32) -> &u32 {
    |                                                   ----     ----
index e1379bfaf2e491faad3b29b14a2035e49c2fc755..eb01cfc9768e64d06dd77b5b295be53c2206efaf 100644 (file)
@@ -1,7 +1,6 @@
 // check-pass
 // edition:2018
 
-#![feature(arbitrary_self_types)]
 #![allow(non_snake_case)]
 
 use std::rc::Rc;
index dbcef71ba14fc451ad33cc33ecc860066ab287b2..574b7e7c9b3d66366053c771e44a52b20865c207 100644 (file)
@@ -1,6 +1,5 @@
 // check-pass
 
-#![feature(arbitrary_self_types)]
 #![allow(non_snake_case)]
 
 use std::rc::Rc;
index 4a38a2164c82a6181fe23fb375aae60b9328b88f..e018e0daf9620906d71d17dbd62c2e7bfb4a7930 100644 (file)
@@ -1,7 +1,6 @@
 // check-pass
 // edition:2018
 
-#![feature(arbitrary_self_types)]
 #![allow(non_snake_case)]
 
 use std::rc::Rc;
index 227e993bd3c61bff39d00748017868088d2ed9b4..d1ac99d13be7fa039fc6f0a0a4be9ce527427c69 100644 (file)
@@ -1,6 +1,5 @@
 // check-pass
 
-#![feature(arbitrary_self_types)]
 #![allow(non_snake_case)]
 
 use std::rc::Rc;
index d3d5b4a6d1e7db7cbbf1be02ed71d4da8213eb51..35a2fe79d5e66e380eaf1f833ae1465308058d28 100644 (file)
@@ -2,7 +2,10 @@ error: expected one of `,`, `::`, `as`, or `}`, found `.`
   --> $DIR/similar-tokens.rs:7:10
    |
 LL | use x::{A. B};
-   |          ^ expected one of `,`, `::`, `as`, or `}`
+   |          ^
+   |          |
+   |          expected one of `,`, `::`, `as`, or `}`
+   |          help: missing `,`
 
 error: aborting due to previous error
 
index c0b7a5a5b6250ad217aa4b689195d6c0b64a1a1c..1f1211aa198f8ea09a83ccb58a2a60f4b73229ff 100644 (file)
@@ -8,11 +8,7 @@ LL |     let &(X(_t), X(_u)) = &(x.clone(), x.clone());
    |         |   data moved here
    |         help: consider removing the `&`: `(X(_t), X(_u))`
    |
-note: move occurs because these variables have types that don't implement the `Copy` trait
-  --> $DIR/duplicate-suggestions.rs:39:13
-   |
-LL |     let &(X(_t), X(_u)) = &(x.clone(), x.clone());
-   |             ^^     ^^
+   = note: move occurs because these variables have types that don't implement the `Copy` trait
 
 error[E0507]: cannot move out of a shared reference
   --> $DIR/duplicate-suggestions.rs:43:50
@@ -24,11 +20,7 @@ LL |     if let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) {
    |            |             data moved here
    |            help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))`
    |
-note: move occurs because these variables have types that don't implement the `Copy` trait
-  --> $DIR/duplicate-suggestions.rs:43:26
-   |
-LL |     if let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { }
-   |                          ^^               ^^
+   = note: move occurs because these variables have types that don't implement the `Copy` trait
 
 error[E0507]: cannot move out of a shared reference
   --> $DIR/duplicate-suggestions.rs:47:53
@@ -40,11 +32,7 @@ LL |     while let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone())
    |               |             data moved here
    |               help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))`
    |
-note: move occurs because these variables have types that don't implement the `Copy` trait
-  --> $DIR/duplicate-suggestions.rs:47:29
-   |
-LL |     while let &(Either::One(_t), Either::Two(_u)) = &(e.clone(), e.clone()) { }
-   |                             ^^               ^^
+   = note: move occurs because these variables have types that don't implement the `Copy` trait
 
 error[E0507]: cannot move out of a shared reference
   --> $DIR/duplicate-suggestions.rs:51:11
@@ -60,14 +48,7 @@ LL |         &(Either::One(_t), Either::Two(_u)) => (),
 LL |         &(Either::Two(_t), Either::One(_u)) => (),
    |                       -- ...and here   -- ...and here
    |
-note: move occurs because these variables have types that don't implement the `Copy` trait
-  --> $DIR/duplicate-suggestions.rs:53:23
-   |
-LL |         &(Either::One(_t), Either::Two(_u)) => (),
-   |                       ^^               ^^
-...
-LL |         &(Either::Two(_t), Either::One(_u)) => (),
-   |                       ^^               ^^
+   = note: move occurs because these variables have types that don't implement the `Copy` trait
 help: consider removing the `&`
    |
 LL |         (Either::One(_t), Either::Two(_u)) => (),
@@ -90,11 +71,7 @@ LL |         &(Either::One(_t), Either::Two(_u))
    |         |             data moved here
    |         help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))`
    |
-note: move occurs because these variables have types that don't implement the `Copy` trait
-  --> $DIR/duplicate-suggestions.rs:63:23
-   |
-LL |         &(Either::One(_t), Either::Two(_u))
-   |                       ^^               ^^
+   = note: move occurs because these variables have types that don't implement the `Copy` trait
 
 error[E0507]: cannot move out of a shared reference
   --> $DIR/duplicate-suggestions.rs:70:11
@@ -109,11 +86,7 @@ LL |         &(Either::One(_t), Either::Two(_u)) => (),
    |         |             data moved here
    |         help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))`
    |
-note: move occurs because these variables have types that don't implement the `Copy` trait
-  --> $DIR/duplicate-suggestions.rs:72:23
-   |
-LL |         &(Either::One(_t), Either::Two(_u)) => (),
-   |                       ^^               ^^
+   = note: move occurs because these variables have types that don't implement the `Copy` trait
 
 error[E0507]: cannot move out of a shared reference
   --> $DIR/duplicate-suggestions.rs:78:11
@@ -128,11 +101,7 @@ LL |         &(Either::One(_t), Either::Two(_u)) => (),
    |         |             data moved here
    |         help: consider removing the `&`: `(Either::One(_t), Either::Two(_u))`
    |
-note: move occurs because these variables have types that don't implement the `Copy` trait
-  --> $DIR/duplicate-suggestions.rs:80:23
-   |
-LL |         &(Either::One(_t), Either::Two(_u)) => (),
-   |                       ^^               ^^
+   = note: move occurs because these variables have types that don't implement the `Copy` trait
 
 error[E0507]: cannot move out of a mutable reference
   --> $DIR/duplicate-suggestions.rs:91:31
@@ -144,11 +113,7 @@ LL |     let &mut (X(_t), X(_u)) = &mut (xm.clone(), xm.clone());
    |         |       data moved here
    |         help: consider removing the `&mut`: `(X(_t), X(_u))`
    |
-note: move occurs because these variables have types that don't implement the `Copy` trait
-  --> $DIR/duplicate-suggestions.rs:91:17
-   |
-LL |     let &mut (X(_t), X(_u)) = &mut (xm.clone(), xm.clone());
-   |                 ^^     ^^
+   = note: move occurs because these variables have types that don't implement the `Copy` trait
 
 error[E0507]: cannot move out of a mutable reference
   --> $DIR/duplicate-suggestions.rs:95:54
@@ -160,11 +125,7 @@ LL |     if let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.c
    |            |                 data moved here
    |            help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))`
    |
-note: move occurs because these variables have types that don't implement the `Copy` trait
-  --> $DIR/duplicate-suggestions.rs:95:30
-   |
-LL |     if let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { }
-   |                              ^^               ^^
+   = note: move occurs because these variables have types that don't implement the `Copy` trait
 
 error[E0507]: cannot move out of a mutable reference
   --> $DIR/duplicate-suggestions.rs:99:57
@@ -176,11 +137,7 @@ LL |     while let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), e
    |               |                 data moved here
    |               help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))`
    |
-note: move occurs because these variables have types that don't implement the `Copy` trait
-  --> $DIR/duplicate-suggestions.rs:99:33
-   |
-LL |     while let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { }
-   |                                 ^^               ^^
+   = note: move occurs because these variables have types that don't implement the `Copy` trait
 
 error[E0507]: cannot move out of a mutable reference
   --> $DIR/duplicate-suggestions.rs:103:11
@@ -196,14 +153,7 @@ LL |         &mut (Either::One(_t), Either::Two(_u)) => (),
 LL |         &mut (Either::Two(_t), Either::One(_u)) => (),
    |                           -- ...and here   -- ...and here
    |
-note: move occurs because these variables have types that don't implement the `Copy` trait
-  --> $DIR/duplicate-suggestions.rs:105:27
-   |
-LL |         &mut (Either::One(_t), Either::Two(_u)) => (),
-   |                           ^^               ^^
-...
-LL |         &mut (Either::Two(_t), Either::One(_u)) => (),
-   |                           ^^               ^^
+   = note: move occurs because these variables have types that don't implement the `Copy` trait
 help: consider removing the `&mut`
    |
 LL |         (Either::One(_t), Either::Two(_u)) => (),
@@ -226,11 +176,7 @@ LL |         &mut (Either::One(_t), Either::Two(_u))
    |         |                 data moved here
    |         help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))`
    |
-note: move occurs because these variables have types that don't implement the `Copy` trait
-  --> $DIR/duplicate-suggestions.rs:115:27
-   |
-LL |         &mut (Either::One(_t), Either::Two(_u))
-   |                           ^^               ^^
+   = note: move occurs because these variables have types that don't implement the `Copy` trait
 
 error[E0507]: cannot move out of a mutable reference
   --> $DIR/duplicate-suggestions.rs:122:11
@@ -245,11 +191,7 @@ LL |         &mut (Either::One(_t), Either::Two(_u)) => (),
    |         |                 data moved here
    |         help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))`
    |
-note: move occurs because these variables have types that don't implement the `Copy` trait
-  --> $DIR/duplicate-suggestions.rs:124:27
-   |
-LL |         &mut (Either::One(_t), Either::Two(_u)) => (),
-   |                           ^^               ^^
+   = note: move occurs because these variables have types that don't implement the `Copy` trait
 
 error[E0507]: cannot move out of a mutable reference
   --> $DIR/duplicate-suggestions.rs:130:11
@@ -264,11 +206,7 @@ LL |         &mut (Either::One(_t), Either::Two(_u)) => (),
    |         |                 data moved here
    |         help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))`
    |
-note: move occurs because these variables have types that don't implement the `Copy` trait
-  --> $DIR/duplicate-suggestions.rs:132:27
-   |
-LL |         &mut (Either::One(_t), Either::Two(_u)) => (),
-   |                           ^^               ^^
+   = note: move occurs because these variables have types that don't implement the `Copy` trait
 
 error[E0507]: cannot move out of a mutable reference
   --> $DIR/duplicate-suggestions.rs:138:11
@@ -283,11 +221,7 @@ LL |         &mut (Either::One(_t), Either::Two(_u)) => (),
    |         |                 data moved here
    |         help: consider removing the `&mut`: `(Either::One(_t), Either::Two(_u))`
    |
-note: move occurs because these variables have types that don't implement the `Copy` trait
-  --> $DIR/duplicate-suggestions.rs:140:27
-   |
-LL |         &mut (Either::One(_t), Either::Two(_u)) => (),
-   |                           ^^               ^^
+   = note: move occurs because these variables have types that don't implement the `Copy` trait
 
 error[E0507]: cannot move out of a shared reference
   --> $DIR/duplicate-suggestions.rs:86:11
@@ -299,11 +233,7 @@ LL |     fn f5(&(X(_t), X(_u)): &(X, X)) { }
    |           |   data moved here
    |           help: consider removing the `&`: `(X(_t), X(_u))`
    |
-note: move occurs because these variables have types that don't implement the `Copy` trait
-  --> $DIR/duplicate-suggestions.rs:86:15
-   |
-LL |     fn f5(&(X(_t), X(_u)): &(X, X)) { }
-   |               ^^     ^^
+   = note: move occurs because these variables have types that don't implement the `Copy` trait
 
 error[E0507]: cannot move out of a mutable reference
   --> $DIR/duplicate-suggestions.rs:146:11
@@ -315,11 +245,7 @@ LL |     fn f6(&mut (X(_t), X(_u)): &mut (X, X)) { }
    |           |       data moved here
    |           help: consider removing the `&mut`: `(X(_t), X(_u))`
    |
-note: move occurs because these variables have types that don't implement the `Copy` trait
-  --> $DIR/duplicate-suggestions.rs:146:19
-   |
-LL |     fn f6(&mut (X(_t), X(_u)): &mut (X, X)) { }
-   |                   ^^     ^^
+   = note: move occurs because these variables have types that don't implement the `Copy` trait
 
 error: aborting due to 17 previous errors
 
index cb3ce5991aeeeeca5e103c6c846e935994d1a544..ac91ac43736f95e7b301b640389d6756562fcddc 100644 (file)
@@ -337,14 +337,7 @@ LL |         &mut Either::One(_t) => (),
 LL |         &mut Either::Two(_t) => (),
    |                          -- ...and here
    |
-note: move occurs because these variables have types that don't implement the `Copy` trait
-  --> $DIR/simple.rs:221:26
-   |
-LL |         &mut Either::One(_t) => (),
-   |                          ^^
-...
-LL |         &mut Either::Two(_t) => (),
-   |                          ^^
+   = note: move occurs because these variables have types that don't implement the `Copy` trait
 help: consider removing the `&mut`
    |
 LL |         Either::One(_t) => (),
@@ -470,13 +463,7 @@ LL |         (&mut Either::One(_t),) => (),
 LL |         (&mut Either::Two(_t),) => (),
    |                           -- ...and here
    |
-note: move occurs because these variables have types that don't implement the `Copy` trait
-  --> $DIR/simple.rs:280:27
-   |
-LL |         (&mut Either::One(_t),) => (),
-   |                           ^^
-LL |         (&mut Either::Two(_t),) => (),
-   |                           ^^
+   = note: move occurs because these variables have types that don't implement the `Copy` trait
 
 error[E0507]: cannot move out of a shared reference
   --> $DIR/simple.rs:288:18
index 94f39f3b9f1dde107f44c14aeeb3d2004452de43..bfa0b32fd458ae0063871d32b819b2b02586343f 100644 (file)
@@ -2,7 +2,9 @@ error: expected one of `)` or `,`, found `(`
   --> $DIR/test.rs:4:26
    |
 LL |     struct S2(pub((foo)) ());
-   |                          ^ expected one of `)` or `,`
+   |                         -^ expected one of `)` or `,`
+   |                         |
+   |                         help: missing `,`
 
 error[E0412]: cannot find type `foo` in this scope
   --> $DIR/test.rs:4:20
index 9a64ed97ae1d4c6ee3755a8327cbc23e93b4c0d0..d924c351439bd91749108bc8634598674eee7789 100644 (file)
@@ -2,7 +2,9 @@ error: expected one of `)` or `,`, found `(`
   --> $DIR/test2.rs:5:26
    |
 LL |         struct S3(pub $t ());
-   |                          ^ expected one of `)` or `,`
+   |                         -^ expected one of `)` or `,`
+   |                         |
+   |                         help: missing `,`
 ...
 LL |     define_struct! { (foo) }
    |     ------------------------ in this macro invocation
index 89ae784882d4de97b3e6aa2c0d04f0eb065a1ec2..50cac6c179e31a29fa9f8fd22cbcac3e5f7262a3 100644 (file)
@@ -2,7 +2,9 @@ error: expected one of `)` or `,`, found `(`
   --> $DIR/test3.rs:5:27
    |
 LL |         struct S3(pub($t) ());
-   |                           ^ expected one of `)` or `,`
+   |                          -^ expected one of `)` or `,`
+   |                          |
+   |                          help: missing `,`
 ...
 LL |     define_struct! { foo }
    |     ---------------------- in this macro invocation
diff --git a/src/test/ui/type-alias-impl-trait/issue-63263-closure-return.rs b/src/test/ui/type-alias-impl-trait/issue-63263-closure-return.rs
new file mode 100644 (file)
index 0000000..7414611
--- /dev/null
@@ -0,0 +1,13 @@
+// Regression test for issue #63263.
+// Tests that we properly handle closures with an explicit return type
+// that return an opaque type.
+
+// check-pass
+
+#![feature(type_alias_impl_trait)]
+
+pub type Closure = impl FnOnce();
+
+fn main() {
+    || -> Closure { || () };
+}
index b1f9a28e16d5610f8accc06f1b05d4ae5b0a943e..eeda5460ac36acf03eb135fdf4867a3f057475ef 100644 (file)
@@ -15,11 +15,11 @@ fn main() {
         extern crate crate_a1 as a;
         a::try_foo(foo2);
         //~^ ERROR mismatched types
-        //~| Perhaps two different versions of crate `crate_a1`
+        //~| perhaps two different versions of crate `crate_a1`
         //~| expected struct `main::a::Foo`
         a::try_bar(bar2);
         //~^ ERROR mismatched types
-        //~| Perhaps two different versions of crate `crate_a1`
+        //~| perhaps two different versions of crate `crate_a1`
         //~| expected trait `main::a::Bar`
         //~| expected struct `std::boxed::Box<(dyn main::a::Bar + 'static)>`
         //~| found struct `std::boxed::Box<dyn main::a::Bar>`
index 91bbe9c1fbe2a2c6cb69261f2f898582c7ef337d..be5406696b7de790747dc7c79e1bad6a19214d4b 100644 (file)
@@ -4,11 +4,7 @@ error[E0308]: mismatched types
 LL |         a::try_foo(foo2);
    |                    ^^^^ expected struct `main::a::Foo`, found a different struct `main::a::Foo`
    |
-note: Perhaps two different versions of crate `crate_a1` are being used?
-  --> $DIR/type-mismatch-same-crate-name.rs:16:20
-   |
-LL |         a::try_foo(foo2);
-   |                    ^^^^
+   = note: perhaps two different versions of crate `crate_a1` are being used?
 
 error[E0308]: mismatched types
   --> $DIR/type-mismatch-same-crate-name.rs:20:20
@@ -18,11 +14,7 @@ LL |         a::try_bar(bar2);
    |
    = note: expected struct `std::boxed::Box<(dyn main::a::Bar + 'static)>`
               found struct `std::boxed::Box<dyn main::a::Bar>`
-note: Perhaps two different versions of crate `crate_a1` are being used?
-  --> $DIR/type-mismatch-same-crate-name.rs:20:20
-   |
-LL |         a::try_bar(bar2);
-   |                    ^^^^
+   = note: perhaps two different versions of crate `crate_a1` are being used?
 
 error: aborting due to 2 previous errors
 
diff --git a/src/test/ui/unsized/unsized-fn-param.rs b/src/test/ui/unsized/unsized-fn-param.rs
new file mode 100644 (file)
index 0000000..32efc7e
--- /dev/null
@@ -0,0 +1,20 @@
+use std::convert::AsRef;
+use std::path::Path;
+
+fn foo11(_bar: &dyn AsRef<Path>, _baz: &str) {}
+fn foo12(_bar: &str, _baz: &dyn AsRef<Path>) {}
+
+fn foo21(_bar: &dyn AsRef<str>, _baz: &str) {}
+fn foo22(_bar: &str, _baz: &dyn AsRef<str>) {}
+
+fn main() {
+    foo11("bar", &"baz"); //~ ERROR the size for values of type
+    foo11(&"bar", &"baz");
+    foo12(&"bar", "baz"); //~ ERROR the size for values of type
+    foo12(&"bar", &"baz");
+
+    foo21("bar", &"baz"); //~ ERROR the size for values of type
+    foo21(&"bar", &"baz");
+    foo22(&"bar", "baz"); //~ ERROR the size for values of type
+    foo22(&"bar", &"baz");
+}
diff --git a/src/test/ui/unsized/unsized-fn-param.stderr b/src/test/ui/unsized/unsized-fn-param.stderr
new file mode 100644 (file)
index 0000000..ed2c2e7
--- /dev/null
@@ -0,0 +1,43 @@
+error[E0277]: the size for values of type `str` cannot be known at compilation time
+  --> $DIR/unsized-fn-param.rs:11:11
+   |
+LL |     foo11("bar", &"baz");
+   |           ^^^^^ doesn't have a size known at compile-time
+   |
+   = help: the trait `std::marker::Sized` is not implemented for `str`
+   = note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
+   = note: required for the cast to the object type `dyn std::convert::AsRef<std::path::Path>`
+
+error[E0277]: the size for values of type `str` cannot be known at compilation time
+  --> $DIR/unsized-fn-param.rs:13:19
+   |
+LL |     foo12(&"bar", "baz");
+   |                   ^^^^^ doesn't have a size known at compile-time
+   |
+   = help: the trait `std::marker::Sized` is not implemented for `str`
+   = note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
+   = note: required for the cast to the object type `dyn std::convert::AsRef<std::path::Path>`
+
+error[E0277]: the size for values of type `str` cannot be known at compilation time
+  --> $DIR/unsized-fn-param.rs:16:11
+   |
+LL |     foo21("bar", &"baz");
+   |           ^^^^^ doesn't have a size known at compile-time
+   |
+   = help: the trait `std::marker::Sized` is not implemented for `str`
+   = note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
+   = note: required for the cast to the object type `dyn std::convert::AsRef<str>`
+
+error[E0277]: the size for values of type `str` cannot be known at compilation time
+  --> $DIR/unsized-fn-param.rs:18:19
+   |
+LL |     foo22(&"bar", "baz");
+   |                   ^^^^^ doesn't have a size known at compile-time
+   |
+   = help: the trait `std::marker::Sized` is not implemented for `str`
+   = note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
+   = note: required for the cast to the object type `dyn std::convert::AsRef<str>`
+
+error: aborting due to 4 previous errors
+
+For more information about this error, try `rustc --explain E0277`.
index a824546d436f7e64564472a3dbb51f3b981db48d..defe85ef46a231155b69a129f43990c44622c503 100644 (file)
@@ -397,7 +397,8 @@ fn map_lib_features(base_src_path: &Path,
         }
 
         let mut becoming_feature: Option<(&str, Feature)> = None;
-        for (i, line) in contents.lines().enumerate() {
+        let mut iter_lines = contents.lines().enumerate().peekable();
+        while let Some((i, line)) = iter_lines.next() {
             macro_rules! err {
                 ($msg:expr) => {{
                     mf(Err($msg), file, i + 1);
@@ -411,7 +412,7 @@ macro_rules! err {
                 }
                 if line.ends_with(']') {
                     mf(Ok((name, f.clone())), file, i + 1);
-                } else if !line.ends_with(',') && !line.ends_with('\\') {
+                } else if !line.ends_with(',') && !line.ends_with('\\') && !line.ends_with('"') {
                     // We need to bail here because we might have missed the
                     // end of a stability attribute above because the ']'
                     // might not have been at the end of the line.
@@ -450,7 +451,9 @@ macro_rules! err {
             } else {
                 continue;
             };
-            let feature_name = match find_attr_val(line, "feature") {
+            let feature_name = match find_attr_val(line, "feature")
+                .or_else(|| iter_lines.peek().and_then(|next| find_attr_val(next.1, "feature")))
+            {
                 Some(name) => name,
                 None => err!("malformed stability attribute: missing `feature` key"),
             };
index 5abe481368df53f2832947736942558a15e1fe23..20636c86e1e96fd70006c5622624f98bef68a34f 100644 (file)
@@ -141,17 +141,28 @@ pub fn check(path: &Path, bad: &mut bool) {
     super::walk(path, &mut super::filter_dirs, &mut |entry, contents| {
         let file = entry.path();
         let filename = file.file_name().unwrap().to_string_lossy();
-        let extensions = [".rs", ".py", ".js", ".sh", ".c", ".cpp", ".h"];
+        let extensions = [".rs", ".py", ".js", ".sh", ".c", ".cpp", ".h", ".md"];
         if extensions.iter().all(|e| !filename.ends_with(e)) ||
            filename.starts_with(".#") {
             return
         }
 
+        if filename.ends_with(".md") &&
+           file.parent()
+               .unwrap()
+               .file_name()
+               .unwrap()
+               .to_string_lossy() != "error_codes" {
+            // We don't want to check all ".md" files (almost of of them aren't compliant
+            // currently), just the long error code explanation ones.
+            return;
+        }
+
         if contents.is_empty() {
             tidy_error!(bad, "{}: empty file", file.display());
         }
 
-        let max_columns = if filename == "error_codes.rs" {
+        let max_columns = if filename == "error_codes.rs" || filename.ends_with(".md") {
             ERROR_CODE_COLS
         } else {
             COLS