Skip to content

Commit

Permalink
Auto merge of #59967 - Centril:rollup-bdqq7ux, r=Centril
Browse files Browse the repository at this point in the history
Rollup of 7 pull requests

Successful merges:

 - #59856 (update polonius-engine)
 - #59877 (HirIdify hir::Def)
 - #59896 (Remove duplicated redundant spans)
 - #59900 (Remove [mut] syntax in pin docs)
 - #59906 (Make BufWriter use get_mut instead of manipulating inner in Write implementation)
 - #59936 (Fix cross-crate visibility of fictive variant constructors)
 - #59957 (Add missing backtick to Symbol documentation.)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Apr 14, 2019
2 parents d70c5a9 + c348bb6 commit 9cd61f0
Show file tree
Hide file tree
Showing 44 changed files with 384 additions and 148 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1906,7 +1906,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "polonius-engine"
version = "0.6.2"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"datafrog 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
Expand Down Expand Up @@ -2341,7 +2341,7 @@ dependencies = [
"measureme 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
"polonius-engine 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
"polonius-engine 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-rayon 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-rayon-core 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc_apfloat 0.0.0",
Expand Down Expand Up @@ -2841,7 +2841,7 @@ dependencies = [
"graphviz 0.0.0",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"log_settings 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"polonius-engine 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
"polonius-engine 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc 0.0.0",
"rustc_apfloat 0.0.0",
"rustc_data_structures 0.0.0",
Expand Down Expand Up @@ -4164,7 +4164,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum phf_generator 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)" = "05a079dd052e7b674d21cb31cbb6c05efd56a2cd2827db7692e2f1a507ebd998"
"checksum phf_shared 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)" = "c2261d544c2bb6aa3b10022b0be371b9c7c64f762ef28c6f5d4f1ef6d97b5930"
"checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c"
"checksum polonius-engine 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2490c396085801abf88df91758bad806b0890354f0875d624e62ecf0579a8145"
"checksum polonius-engine 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8b24942fee141ea45628484a453762bb7e515099c3ec05fbeb76b7bf57b1aeed"
"checksum precomputed-hash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"
"checksum pretty_assertions 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3a029430f0d744bc3d15dd474d591bed2402b645d024583082b9f63bb936dac6"
"checksum pretty_env_logger 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "df8b3f4e0475def7d9c2e5de8e5a1306949849761e107b360d03e98eafaffd61"
Expand Down
28 changes: 16 additions & 12 deletions src/libcore/pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,28 +158,32 @@
//! is called *even if your type was previously pinned*! It is as if the
//! compiler automatically called `get_unchecked_mut`.
//!
//! This can never cause a problem in safe code because implementing a type that relies on pinning
//! requires unsafe code, but be aware that deciding to make use of pinning
//! in your type (for example by implementing some operation on `Pin<&[mut] Self>`)
//! has consequences for your `Drop` implementation as well: if an element
//! of your type could have been pinned, you must treat Drop as implicitly taking
//! `Pin<&mut Self>`.
//! This can never cause a problem in safe code because implementing a type that
//! relies on pinning requires unsafe code, but be aware that deciding to make
//! use of pinning in your type (for example by implementing some operation on
//! `Pin<&Self>` or `Pin<&mut Self>`) has consequences for your `Drop`
//! implementation as well: if an element of your type could have been pinned,
//! you must treat Drop as implicitly taking `Pin<&mut Self>`.
//!
//! In particular, if your type is `#[repr(packed)]`, the compiler will automatically
//! move fields around to be able to drop them. As a consequence, you cannot use
//! pinning with a `#[repr(packed)]` type.
//!
//! # Projections and Structural Pinning
//!
//! One interesting question arises when considering the interaction of pinning and
//! the fields of a struct. When can a struct have a "pinning projection", i.e.,
//! an operation with type `fn(Pin<&[mut] Struct>) -> Pin<&[mut] Field>`?
//! In a similar vein, when can a generic wrapper type (such as `Vec<T>`, `Box<T>`, or `RefCell<T>`)
//! have an operation with type `fn(Pin<&[mut] Wrapper<T>>) -> Pin<&[mut] T>`?
//! One interesting question arises when considering the interaction of pinning
//! and the fields of a struct. When can a struct have a "pinning projection",
//! i.e., an operation with type `fn(Pin<&Struct>) -> Pin<&Field>`? In a
//! similar vein, when can a generic wrapper type (such as `Vec<T>`, `Box<T>`,
//! or `RefCell<T>`) have an operation with type `fn(Pin<&Wrapper<T>>) ->
//! Pin<&T>`?
//!
//! Note: For the entirety of this discussion, the same applies for mutable references as it
//! does for shared references.
//!
//! Having a pinning projection for some field means that pinning is "structural":
//! when the wrapper is pinned, the field must be considered pinned, too.
//! After all, the pinning projection lets us get a `Pin<&[mut] Field>`.
//! After all, the pinning projection lets us get a `Pin<&Field>`.
//!
//! However, structural pinning comes with a few extra requirements, so not all
//! wrappers can be structural and hence not all wrappers can offer pinning projections:
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ lazy_static = "1.0.0"
num_cpus = "1.0"
scoped-tls = "1.0"
log = { version = "0.4", features = ["release_max_level_info", "std"] }
polonius-engine = "0.6.2"
polonius-engine = "0.7.0"
rustc-rayon = "0.1.2"
rustc-rayon-core = "0.1.2"
rustc_apfloat = { path = "../librustc_apfloat" }
Expand Down
79 changes: 67 additions & 12 deletions src/librustc/hir/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ use crate::hir::def_id::DefId;
use crate::util::nodemap::{NodeMap, DefIdMap};
use syntax::ast;
use syntax::ext::base::MacroKind;
use syntax::ast::NodeId;
use syntax_pos::Span;
use rustc_macros::HashStable;
use crate::hir;
use crate::ty;
use std::fmt::Debug;

use self::Namespace::*;

Expand Down Expand Up @@ -43,7 +45,7 @@ pub enum NonMacroAttrKind {
}

#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, HashStable)]
pub enum Def {
pub enum Def<Id = hir::HirId> {
// Type namespace
Mod(DefId),
/// `DefId` refers to the struct itself, `Def::Ctor` refers to its constructor if it exists.
Expand Down Expand Up @@ -78,8 +80,8 @@ pub enum Def {
Method(DefId),
AssociatedConst(DefId),

Local(ast::NodeId),
Upvar(ast::NodeId, // `NodeId` of closed over local
Local(Id),
Upvar(Id, // `HirId` of closed over local
usize, // index in the `freevars` list of the closure
ast::NodeId), // expr node that creates the closure
Label(ast::NodeId),
Expand Down Expand Up @@ -108,22 +110,22 @@ pub enum Def {
/// ```
#[derive(Copy, Clone, Debug)]
pub struct PathResolution {
base_def: Def,
base_def: Def<NodeId>,
unresolved_segments: usize,
}

impl PathResolution {
pub fn new(def: Def) -> Self {
pub fn new(def: Def<NodeId>) -> Self {
PathResolution { base_def: def, unresolved_segments: 0 }
}

pub fn with_unresolved_segments(def: Def, mut unresolved_segments: usize) -> Self {
pub fn with_unresolved_segments(def: Def<NodeId>, mut unresolved_segments: usize) -> Self {
if def == Def::Err { unresolved_segments = 0 }
PathResolution { base_def: def, unresolved_segments: unresolved_segments }
}

#[inline]
pub fn base_def(&self) -> Def {
pub fn base_def(&self) -> Def<NodeId> {
self.base_def
}

Expand Down Expand Up @@ -215,25 +217,36 @@ pub type DefMap = NodeMap<PathResolution>;

/// This is the replacement export map. It maps a module to all of the exports
/// within.
pub type ExportMap = DefIdMap<Vec<Export>>;
pub type ExportMap<Id> = DefIdMap<Vec<Export<Id>>>;

/// Map used to track the `use` statements within a scope, matching it with all the items in every
/// namespace.
pub type ImportMap = NodeMap<PerNS<Option<PathResolution>>>;

#[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable, HashStable)]
pub struct Export {
pub struct Export<Id> {
/// The name of the target.
pub ident: ast::Ident,
/// The definition of the target.
pub def: Def,
pub def: Def<Id>,
/// The span of the target definition.
pub span: Span,
/// The visibility of the export.
/// We include non-`pub` exports for hygienic macros that get used from extern crates.
pub vis: ty::Visibility,
}

impl<Id> Export<Id> {
pub fn map_id<R>(self, map: impl FnMut(Id) -> R) -> Export<R> {
Export {
ident: self.ident,
def: self.def.map_id(map),
span: self.span,
vis: self.vis,
}
}
}

impl CtorKind {
pub fn from_ast(vdata: &ast::VariantData) -> CtorKind {
match *vdata {
Expand Down Expand Up @@ -264,9 +277,12 @@ impl NonMacroAttrKind {
}
}

impl Def {
impl<Id> Def<Id> {
/// Return the `DefId` of this `Def` if it has an id, else panic.
pub fn def_id(&self) -> DefId {
pub fn def_id(&self) -> DefId
where
Id: Debug,
{
self.opt_def_id().unwrap_or_else(|| {
bug!("attempted .def_id() on invalid def: {:?}", self)
})
Expand Down Expand Up @@ -358,4 +374,43 @@ impl Def {
_ => "a",
}
}

pub fn map_id<R>(self, mut map: impl FnMut(Id) -> R) -> Def<R> {
match self {
Def::Fn(id) => Def::Fn(id),
Def::Mod(id) => Def::Mod(id),
Def::Static(id, is_mutbl) => Def::Static(id, is_mutbl),
Def::Enum(id) => Def::Enum(id),
Def::Variant(id) => Def::Variant(id),
Def::Ctor(a, b, c) => Def::Ctor(a, b, c),
Def::Struct(id) => Def::Struct(id),
Def::Existential(id) => Def::Existential(id),
Def::TyAlias(id) => Def::TyAlias(id),
Def::TraitAlias(id) => Def::TraitAlias(id),
Def::AssociatedTy(id) => Def::AssociatedTy(id),
Def::AssociatedExistential(id) => Def::AssociatedExistential(id),
Def::SelfCtor(id) => Def::SelfCtor(id),
Def::Union(id) => Def::Union(id),
Def::Trait(id) => Def::Trait(id),
Def::ForeignTy(id) => Def::ForeignTy(id),
Def::Method(id) => Def::Method(id),
Def::Const(id) => Def::Const(id),
Def::AssociatedConst(id) => Def::AssociatedConst(id),
Def::TyParam(id) => Def::TyParam(id),
Def::ConstParam(id) => Def::ConstParam(id),
Def::PrimTy(id) => Def::PrimTy(id),
Def::Local(id) => Def::Local(map(id)),
Def::Upvar(id, index, closure) => Def::Upvar(
map(id),
index,
closure
),
Def::Label(id) => Def::Label(id),
Def::SelfTy(a, b) => Def::SelfTy(a, b),
Def::Macro(id, macro_kind) => Def::Macro(id, macro_kind),
Def::ToolMod => Def::ToolMod,
Def::NonMacroAttr(attr_kind) => Def::NonMacroAttr(attr_kind),
Def::Err => Def::Err,
}
}
}
Loading

0 comments on commit 9cd61f0

Please sign in to comment.