Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 7 pull requests #59964

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c440c0a
update polonius-engine
Apr 2, 2019
fd4c6e9
Remove duplicated redundant spans
estebank Apr 11, 2019
94a5c3b
Remove [mut] syntax in pin docs
czipperz Apr 12, 2019
ac5e755
Make BufWriter use get_mut instead of manipulating inner in Write imp…
czipperz Apr 12, 2019
e9c9d1c
Add comment that field projectin also works with mutable fields
czipperz Apr 12, 2019
ca5a9ce
Add test and fix dedup
estebank Apr 12, 2019
b754b8f
Expand note on mutable references
czipperz Apr 13, 2019
37d325e
Use a proc macro to declare preallocated symbols
Zoxc Apr 3, 2019
d1fcdd9
Make check_name generic
Zoxc Apr 5, 2019
a55de31
Ensure the symbols are pure strings
Zoxc Apr 9, 2019
fe4a390
Move modules outside the proc macro
Zoxc Apr 9, 2019
d66975c
Use colon for keyword defs
Zoxc Apr 9, 2019
3b99a48
HirIdify hir::Def
ljedrz Apr 3, 2019
b5d43fc
Update tests
Zoxc Apr 11, 2019
8f3fd85
Add missing backtick to Symbol documentation.
krk Apr 14, 2019
31d5364
Rollup merge of #59655 - Zoxc:symbols, r=petrochenkov
Centril Apr 14, 2019
cee4567
Rollup merge of #59856 - albins:update-polonius, r=nikomatsakis
Centril Apr 14, 2019
6c5777e
Rollup merge of #59877 - Zoxc:hiridify_def_id, r=eddyb
Centril Apr 14, 2019
443925c
Rollup merge of #59896 - estebank:dedup-spans, r=davidtwco
Centril Apr 14, 2019
c25ae85
Rollup merge of #59900 - czipperz:remove-bracket-mut-syntax-in-pin-do…
Centril Apr 14, 2019
f6dec88
Rollup merge of #59906 - czipperz:bufwriter-use-getmut, r=kennytm
Centril Apr 14, 2019
02b02cf
Rollup merge of #59957 - krk:fix-doctypo-symbol, r=jonas-schievink
Centril Apr 14, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1904,7 +1904,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 @@ -2339,7 +2339,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 @@ -2839,7 +2839,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 @@ -3385,6 +3385,7 @@ dependencies = [
"arena 0.0.0",
"cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc_data_structures 0.0.0",
"rustc_macros 0.1.0",
"scoped-tls 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serialize 0.0.0",
"unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
Expand Down Expand Up @@ -4162,7 +4163,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