Skip to content

Commit 9cd61f0

Browse files
committed
Auto merge of #59967 - Centril:rollup-bdqq7ux, r=Centril
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
2 parents d70c5a9 + c348bb6 commit 9cd61f0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+384
-148
lines changed

Cargo.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -1906,7 +1906,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
19061906

19071907
[[package]]
19081908
name = "polonius-engine"
1909-
version = "0.6.2"
1909+
version = "0.7.0"
19101910
source = "registry+https://github.com/rust-lang/crates.io-index"
19111911
dependencies = [
19121912
"datafrog 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2341,7 +2341,7 @@ dependencies = [
23412341
"measureme 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
23422342
"num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
23432343
"parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
2344-
"polonius-engine 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
2344+
"polonius-engine 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
23452345
"rustc-rayon 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
23462346
"rustc-rayon-core 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
23472347
"rustc_apfloat 0.0.0",
@@ -2841,7 +2841,7 @@ dependencies = [
28412841
"graphviz 0.0.0",
28422842
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
28432843
"log_settings 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
2844-
"polonius-engine 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
2844+
"polonius-engine 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
28452845
"rustc 0.0.0",
28462846
"rustc_apfloat 0.0.0",
28472847
"rustc_data_structures 0.0.0",
@@ -4164,7 +4164,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
41644164
"checksum phf_generator 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)" = "05a079dd052e7b674d21cb31cbb6c05efd56a2cd2827db7692e2f1a507ebd998"
41654165
"checksum phf_shared 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)" = "c2261d544c2bb6aa3b10022b0be371b9c7c64f762ef28c6f5d4f1ef6d97b5930"
41664166
"checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c"
4167-
"checksum polonius-engine 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2490c396085801abf88df91758bad806b0890354f0875d624e62ecf0579a8145"
4167+
"checksum polonius-engine 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8b24942fee141ea45628484a453762bb7e515099c3ec05fbeb76b7bf57b1aeed"
41684168
"checksum precomputed-hash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"
41694169
"checksum pretty_assertions 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3a029430f0d744bc3d15dd474d591bed2402b645d024583082b9f63bb936dac6"
41704170
"checksum pretty_env_logger 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "df8b3f4e0475def7d9c2e5de8e5a1306949849761e107b360d03e98eafaffd61"

src/libcore/pin.rs

+16-12
Original file line numberDiff line numberDiff line change
@@ -158,28 +158,32 @@
158158
//! is called *even if your type was previously pinned*! It is as if the
159159
//! compiler automatically called `get_unchecked_mut`.
160160
//!
161-
//! This can never cause a problem in safe code because implementing a type that relies on pinning
162-
//! requires unsafe code, but be aware that deciding to make use of pinning
163-
//! in your type (for example by implementing some operation on `Pin<&[mut] Self>`)
164-
//! has consequences for your `Drop` implementation as well: if an element
165-
//! of your type could have been pinned, you must treat Drop as implicitly taking
166-
//! `Pin<&mut Self>`.
161+
//! This can never cause a problem in safe code because implementing a type that
162+
//! relies on pinning requires unsafe code, but be aware that deciding to make
163+
//! use of pinning in your type (for example by implementing some operation on
164+
//! `Pin<&Self>` or `Pin<&mut Self>`) has consequences for your `Drop`
165+
//! implementation as well: if an element of your type could have been pinned,
166+
//! you must treat Drop as implicitly taking `Pin<&mut Self>`.
167167
//!
168168
//! In particular, if your type is `#[repr(packed)]`, the compiler will automatically
169169
//! move fields around to be able to drop them. As a consequence, you cannot use
170170
//! pinning with a `#[repr(packed)]` type.
171171
//!
172172
//! # Projections and Structural Pinning
173173
//!
174-
//! One interesting question arises when considering the interaction of pinning and
175-
//! the fields of a struct. When can a struct have a "pinning projection", i.e.,
176-
//! an operation with type `fn(Pin<&[mut] Struct>) -> Pin<&[mut] Field>`?
177-
//! In a similar vein, when can a generic wrapper type (such as `Vec<T>`, `Box<T>`, or `RefCell<T>`)
178-
//! have an operation with type `fn(Pin<&[mut] Wrapper<T>>) -> Pin<&[mut] T>`?
174+
//! One interesting question arises when considering the interaction of pinning
175+
//! and the fields of a struct. When can a struct have a "pinning projection",
176+
//! i.e., an operation with type `fn(Pin<&Struct>) -> Pin<&Field>`? In a
177+
//! similar vein, when can a generic wrapper type (such as `Vec<T>`, `Box<T>`,
178+
//! or `RefCell<T>`) have an operation with type `fn(Pin<&Wrapper<T>>) ->
179+
//! Pin<&T>`?
180+
//!
181+
//! Note: For the entirety of this discussion, the same applies for mutable references as it
182+
//! does for shared references.
179183
//!
180184
//! Having a pinning projection for some field means that pinning is "structural":
181185
//! when the wrapper is pinned, the field must be considered pinned, too.
182-
//! After all, the pinning projection lets us get a `Pin<&[mut] Field>`.
186+
//! After all, the pinning projection lets us get a `Pin<&Field>`.
183187
//!
184188
//! However, structural pinning comes with a few extra requirements, so not all
185189
//! wrappers can be structural and hence not all wrappers can offer pinning projections:

src/librustc/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ lazy_static = "1.0.0"
1919
num_cpus = "1.0"
2020
scoped-tls = "1.0"
2121
log = { version = "0.4", features = ["release_max_level_info", "std"] }
22-
polonius-engine = "0.6.2"
22+
polonius-engine = "0.7.0"
2323
rustc-rayon = "0.1.2"
2424
rustc-rayon-core = "0.1.2"
2525
rustc_apfloat = { path = "../librustc_apfloat" }

src/librustc/hir/def.rs

+67-12
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ use crate::hir::def_id::DefId;
22
use crate::util::nodemap::{NodeMap, DefIdMap};
33
use syntax::ast;
44
use syntax::ext::base::MacroKind;
5+
use syntax::ast::NodeId;
56
use syntax_pos::Span;
67
use rustc_macros::HashStable;
78
use crate::hir;
89
use crate::ty;
10+
use std::fmt::Debug;
911

1012
use self::Namespace::*;
1113

@@ -43,7 +45,7 @@ pub enum NonMacroAttrKind {
4345
}
4446

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

81-
Local(ast::NodeId),
82-
Upvar(ast::NodeId, // `NodeId` of closed over local
83+
Local(Id),
84+
Upvar(Id, // `HirId` of closed over local
8385
usize, // index in the `freevars` list of the closure
8486
ast::NodeId), // expr node that creates the closure
8587
Label(ast::NodeId),
@@ -108,22 +110,22 @@ pub enum Def {
108110
/// ```
109111
#[derive(Copy, Clone, Debug)]
110112
pub struct PathResolution {
111-
base_def: Def,
113+
base_def: Def<NodeId>,
112114
unresolved_segments: usize,
113115
}
114116

115117
impl PathResolution {
116-
pub fn new(def: Def) -> Self {
118+
pub fn new(def: Def<NodeId>) -> Self {
117119
PathResolution { base_def: def, unresolved_segments: 0 }
118120
}
119121

120-
pub fn with_unresolved_segments(def: Def, mut unresolved_segments: usize) -> Self {
122+
pub fn with_unresolved_segments(def: Def<NodeId>, mut unresolved_segments: usize) -> Self {
121123
if def == Def::Err { unresolved_segments = 0 }
122124
PathResolution { base_def: def, unresolved_segments: unresolved_segments }
123125
}
124126

125127
#[inline]
126-
pub fn base_def(&self) -> Def {
128+
pub fn base_def(&self) -> Def<NodeId> {
127129
self.base_def
128130
}
129131

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

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

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

224226
#[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable, HashStable)]
225-
pub struct Export {
227+
pub struct Export<Id> {
226228
/// The name of the target.
227229
pub ident: ast::Ident,
228230
/// The definition of the target.
229-
pub def: Def,
231+
pub def: Def<Id>,
230232
/// The span of the target definition.
231233
pub span: Span,
232234
/// The visibility of the export.
233235
/// We include non-`pub` exports for hygienic macros that get used from extern crates.
234236
pub vis: ty::Visibility,
235237
}
236238

239+
impl<Id> Export<Id> {
240+
pub fn map_id<R>(self, map: impl FnMut(Id) -> R) -> Export<R> {
241+
Export {
242+
ident: self.ident,
243+
def: self.def.map_id(map),
244+
span: self.span,
245+
vis: self.vis,
246+
}
247+
}
248+
}
249+
237250
impl CtorKind {
238251
pub fn from_ast(vdata: &ast::VariantData) -> CtorKind {
239252
match *vdata {
@@ -264,9 +277,12 @@ impl NonMacroAttrKind {
264277
}
265278
}
266279

267-
impl Def {
280+
impl<Id> Def<Id> {
268281
/// Return the `DefId` of this `Def` if it has an id, else panic.
269-
pub fn def_id(&self) -> DefId {
282+
pub fn def_id(&self) -> DefId
283+
where
284+
Id: Debug,
285+
{
270286
self.opt_def_id().unwrap_or_else(|| {
271287
bug!("attempted .def_id() on invalid def: {:?}", self)
272288
})
@@ -358,4 +374,43 @@ impl Def {
358374
_ => "a",
359375
}
360376
}
377+
378+
pub fn map_id<R>(self, mut map: impl FnMut(Id) -> R) -> Def<R> {
379+
match self {
380+
Def::Fn(id) => Def::Fn(id),
381+
Def::Mod(id) => Def::Mod(id),
382+
Def::Static(id, is_mutbl) => Def::Static(id, is_mutbl),
383+
Def::Enum(id) => Def::Enum(id),
384+
Def::Variant(id) => Def::Variant(id),
385+
Def::Ctor(a, b, c) => Def::Ctor(a, b, c),
386+
Def::Struct(id) => Def::Struct(id),
387+
Def::Existential(id) => Def::Existential(id),
388+
Def::TyAlias(id) => Def::TyAlias(id),
389+
Def::TraitAlias(id) => Def::TraitAlias(id),
390+
Def::AssociatedTy(id) => Def::AssociatedTy(id),
391+
Def::AssociatedExistential(id) => Def::AssociatedExistential(id),
392+
Def::SelfCtor(id) => Def::SelfCtor(id),
393+
Def::Union(id) => Def::Union(id),
394+
Def::Trait(id) => Def::Trait(id),
395+
Def::ForeignTy(id) => Def::ForeignTy(id),
396+
Def::Method(id) => Def::Method(id),
397+
Def::Const(id) => Def::Const(id),
398+
Def::AssociatedConst(id) => Def::AssociatedConst(id),
399+
Def::TyParam(id) => Def::TyParam(id),
400+
Def::ConstParam(id) => Def::ConstParam(id),
401+
Def::PrimTy(id) => Def::PrimTy(id),
402+
Def::Local(id) => Def::Local(map(id)),
403+
Def::Upvar(id, index, closure) => Def::Upvar(
404+
map(id),
405+
index,
406+
closure
407+
),
408+
Def::Label(id) => Def::Label(id),
409+
Def::SelfTy(a, b) => Def::SelfTy(a, b),
410+
Def::Macro(id, macro_kind) => Def::Macro(id, macro_kind),
411+
Def::ToolMod => Def::ToolMod,
412+
Def::NonMacroAttr(attr_kind) => Def::NonMacroAttr(attr_kind),
413+
Def::Err => Def::Err,
414+
}
415+
}
361416
}

0 commit comments

Comments
 (0)