1. 01 8月, 2020 1 次提交
  2. 30 7月, 2020 20 次提交
  3. 29 7月, 2020 19 次提交
    • B
      Auto merge of #72488 - KodrAus:stabilize/const_type_id, r=nikomatsakis · 6fd4c3f2
      bors 提交于
      Stabilize const_type_id feature
      
      The tracking issue for `const_type_id` points to the ill-fated #41875. So I'm re-energizing `TypeId` shenanigans by opening this one up to see if there's anything blocking us from stabilizing the constification of type ids.
      
      Will wait for CI before pinging teams/groups.
      
      -----
      
      This PR stabilizes the `const_type_id` feature, which allows `TypeId::of` (and the underlying unstable intrinsic) to be called in constant contexts.
      
      There are some [sanity tests](https://github.com/rust-lang/rust/blob/master/src/test/ui/consts/const-typeid-of-rpass.rs) that demonstrate its usage, but I’ve included some more below.
      
      As a simple example, you could create a constant item that contains some type ids:
      
      ```rust
      use std::any::TypeId;
      
      const TYPE_IDS: [TypeId; 2] = [
          TypeId::of::<u32>(),
          TypeId::of::<i32>(),
      ];
      
      assert_eq!(TypeId::of::<u32>(), TYPE_IDS[0]);
      ```
      
      Type ids can also now appear in associated constants. You could create a trait that associates each type with its constant type id:
      
      ```rust
      trait Any where Self: 'static {
          const TYPE_ID: TypeId = TypeId::of::<Self>();
      }
      
      impl<T: 'static> Any for T { }
      
      assert_eq!(TypeId::of::<usize>(), usize::TYPE_ID);
      ```
      
      `TypeId::of` is generic, which we saw above in the way the generic `Self` argument was used. This has some implications for const evaluation. It means we can make trait impls evaluate differently depending on information that wasn't directly passed through the trait system. This violates the _parametricity_ property, which requires all instances of a generic function to behave the same way with respect to its generic parameters. That's not unique to `TypeId::of`, other generic const functions based on compiler intrinsics like `mem::align_of` can also violate parametricity. In practice Rust doesn't really have type parametricity anyway since it monomorphizes generics into concrete functions, so violating it using type ids isn’t new.
      
      As an example of how impls can behave differently, you could combine constant type ids with the `const_if_match` feature to dispatch calls based on the type id of the generic `Self`, rather than based on information about `Self` that was threaded through trait bounds. It's like a rough-and-ready form of specialization:
      
      ```rust
      #![feature(const_if_match)]
      
      trait Specialized where Self: 'static {
          // An associated constant that determines the function to call
          // at compile-time based on `TypeId::of::<Self>`.
          const CALL: fn(&Self) = {
              const USIZE: TypeId = TypeId::of::<usize>();
      
              match TypeId::of::<Self>() {
                  // Use a closure for `usize` that transmutes the generic `Self` to
                  // a concrete `usize` and dispatches to `Self::usize`.
                  USIZE => |x| Self::usize(unsafe { &*(x as *const Self as *const usize) }),
                  // For other types, dispatch to the generic `Self::default`.
                  _ => Self::default,
              }
          };
      
          fn call(&self) {
              // Call the function we determined at compile-time
              (Self::CALL)(self)
          }
      
          fn default(x: &Self);
          fn usize(x: &usize);
      }
      
      // Implement our `Specialized` trait for any `Debug` type.
      impl<T: fmt::Debug + 'static> Specialized for T {
          fn default(x: &Self) {
              println!("default: {:?}", x);
          }
      
          fn usize(x: &usize) {
              println!("usize: {:?}", x);
          }
      }
      
      // Will print "usize: 42"
      Specialized::call(&42usize);
      
      // Will print "default: ()"
      Specialized::call(&());
      ```
      
      Type ids have some edges that this stabilization exposes to more contexts. It's possible for type ids to collide (but this is a bug). Since they can change between compiler versions, it's never valid to cast a type id to its underlying value.
      6fd4c3f2
    • X
      Move mir-opt tests to toplevel · f07607f4
      Xavier Denis 提交于
      f07607f4
    • R
      Moved structs/enums with repr(C) to LLVM types into ffi.rs crates · 5b2e2b25
      Rich Kadel 提交于
      Some were in librustc_codegen_llvm, but others are not tied to LLVM, so
      I put them in a new crate: librustc_codegen_ssa/coverageinfo/ffi.rs
      5b2e2b25
    • T
      Fix broken link in unstable book `plugin` · ab166cff
      Takayuki Nakata 提交于
      ab166cff
    • B
      Auto merge of #72049 - mati865:mingw-lld, r=petrochenkov · 584e83dd
      bors 提交于
      MinGW: enable dllexport/dllimport
      
      Fixes (only when using LLD) https://github.com/rust-lang/rust/issues/50176
      Fixes https://github.com/rust-lang/rust/issues/72319
      
      This makes `windows-gnu` on pair with `windows-msvc` when it comes to symbol exporting.
      For MinGW it means both good things like correctly working dllimport/dllexport, ability to link with LLD and bad things like https://github.com/rust-lang/rust/issues/27438.
      
      Not sure but maybe this should land behind unstable compiler option (`-Z`) or environment variable?
      584e83dd
    • R
      fence docs: fix example Mutex · 897149a8
      Ralf Jung 提交于
      897149a8
    • M
      Add test for #50176 · 87abd656
      Mateusz Mikuła 提交于
      87abd656
    • M
      MinGW: emit dllexport/dllimport by rustc · db9a84a1
      Mateusz Mikuła 提交于
      This fixes various cases where LD could not guess dllexport correctly and greatly improves compatibility with LLD which is not going to support linker scripts anytime soon
      db9a84a1
    • X
      add crate name to mir dumps · 86be22eb
      Xavier Denis 提交于
      86be22eb
    • B
      Auto merge of #74900 - tmiasko:doc-open, r=Mark-Simulacrum · 06e7b93f
      bors 提交于
      Fix opening docs for std crates with ./x.py doc --open library/*
      
      The directories for core, alloc, std, proc_macro, and test crates now
      correspond directly to the crate name, and stripping the "lib" prefix is
      no longer necessary.
      06e7b93f
    • T
      Fix opening docs for std crates with ./x.py doc --open library/* · 6b4c739f
      Tomasz Miąsko 提交于
      The directories for core, alloc, std, proc_macro, and test crates now
      correspond directly to the crate name and stripping the "lib" prefix is
      no longer necessary.
      6b4c739f
    • J
      82766cb7
    • O
      Address review comments · b81d164f
      Oliver Scherer 提交于
      b81d164f
    • S
    • B
      Auto merge of #74896 - imbolc:patch-1, r=kennytm · 0dd362ec
      bors 提交于
      Update `fs::remove_file` docs
      
      Mention that absence of file causes an error
      0dd362ec
    • T
      Link to syntax section when referencing it · 1b4a6a51
      Tomasz Miąsko 提交于
      1b4a6a51
    • L
      Explain why inline default ToString impl · 27e1b063
      Lzu Tao 提交于
      27e1b063
    • I
      Update `fs::remove_file` docs · c4e44d73
      Imbolc 提交于
      Mention that absence of file causes an error
      c4e44d73
    • B
      Auto merge of #74887 - Mark-Simulacrum:cache-non-exhaustive, r=petrochenkov · 10c37570
      bors 提交于
      Cache non-exhaustive separately from attributes
      
      This prevents cross-crate attribute loading from metadata just for non_exhaustive checking; cross-crate attribute loading implies disk reading and is relatively slow.
      10c37570