Skip to content

Commit c1d29ee

Browse files
author
Alexander Regueiro
committed
Aggregation of cosmetic changes made during work on REPL PRs: librustc
1 parent ef54f57 commit c1d29ee

Some content is hidden

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

50 files changed

+1028
-996
lines changed

src/librustc/arena.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ impl<T: Copy> ArenaAllocatable for T {}
187187

188188
unsafe trait ArenaField<'tcx>: Sized {
189189
/// Returns a specific arena to allocate from.
190-
/// If None is returned, the DropArena will be used.
190+
/// If `None` is returned, the `DropArena` will be used.
191191
fn arena<'a>(arena: &'a Arena<'tcx>) -> Option<&'a TypedArena<Self>>;
192192
}
193193

src/librustc/hir/check_attr.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
//! conflicts between multiple such attributes attached to the same
55
//! item.
66
7-
8-
use crate::ty::TyCtxt;
9-
use crate::ty::query::Providers;
10-
117
use crate::hir;
128
use crate::hir::def_id::DefId;
139
use crate::hir::intravisit::{self, Visitor, NestedVisitorMap};
10+
use crate::ty::TyCtxt;
11+
use crate::ty::query::Providers;
12+
1413
use std::fmt::{self, Display};
1514
use syntax::symbol::sym;
1615
use syntax_pos::Span;

src/librustc/hir/def.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1+
use self::Namespace::*;
2+
13
use crate::hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
4+
use crate::hir;
5+
use crate::ty;
26
use crate::util::nodemap::DefIdMap;
7+
38
use syntax::ast;
49
use syntax::ext::base::MacroKind;
510
use syntax::ast::NodeId;
611
use syntax_pos::Span;
712
use rustc_macros::HashStable;
8-
use crate::hir;
9-
use crate::ty;
10-
use std::fmt::Debug;
1113

12-
use self::Namespace::*;
14+
use std::fmt::Debug;
1315

1416
/// Encodes if a `DefKind::Ctor` is the constructor of an enum variant or a struct.
1517
#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, HashStable)]
@@ -115,7 +117,7 @@ impl DefKind {
115117
}
116118
}
117119

118-
/// An English article for the def.
120+
/// Gets an English article for the definition.
119121
pub fn article(&self) -> &'static str {
120122
match *self {
121123
DefKind::AssocTy
@@ -134,18 +136,22 @@ pub enum Res<Id = hir::HirId> {
134136
Def(DefKind, DefId),
135137

136138
// Type namespace
139+
137140
PrimTy(hir::PrimTy),
138141
SelfTy(Option<DefId> /* trait */, Option<DefId> /* impl */),
139142
ToolMod, // e.g., `rustfmt` in `#[rustfmt::skip]`
140143

141144
// Value namespace
145+
142146
SelfCtor(DefId /* impl */), // `DefId` refers to the impl
143147
Local(Id),
144148

145149
// Macro namespace
150+
146151
NonMacroAttr(NonMacroAttrKind), // e.g., `#[inline]` or `#[rustfmt::skip]`
147152

148153
// All namespaces
154+
149155
Err,
150156
}
151157

@@ -330,7 +336,7 @@ impl NonMacroAttrKind {
330336
}
331337

332338
impl<Id> Res<Id> {
333-
/// Return the `DefId` of this `Def` if it has an id, else panic.
339+
/// Return the `DefId` of this `Def` if it has an ID, else panic.
334340
pub fn def_id(&self) -> DefId
335341
where
336342
Id: Debug,
@@ -340,7 +346,7 @@ impl<Id> Res<Id> {
340346
})
341347
}
342348

343-
/// Return `Some(..)` with the `DefId` of this `Res` if it has a id, else `None`.
349+
/// Return `Some(..)` with the `DefId` of this `Res` if it has a ID, else `None`.
344350
pub fn opt_def_id(&self) -> Option<DefId> {
345351
match *self {
346352
Res::Def(_, id) => Some(id),
@@ -379,7 +385,7 @@ impl<Id> Res<Id> {
379385
}
380386
}
381387

382-
/// An English article for the res.
388+
/// Gets an English article for the `Res`.
383389
pub fn article(&self) -> &'static str {
384390
match *self {
385391
Res::Def(kind, _) => kind.article(),

src/librustc/hir/def_id.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ newtype_index! {
1111

1212
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
1313
pub enum CrateNum {
14-
/// A special CrateNum that we use for the tcx.rcache when decoding from
14+
/// A special `CrateNum` that we use for the `tcx.rcache` when decoding from
1515
/// the incr. comp. cache.
1616
ReservedForIncrCompCache,
1717
Index(CrateId),
@@ -26,11 +26,10 @@ impl ::std::fmt::Debug for CrateNum {
2626
}
2727
}
2828

29-
/// Item definitions in the currently-compiled crate would have the CrateNum
30-
/// LOCAL_CRATE in their DefId.
29+
/// Item definitions in the currently-compiled crate would have the `CrateNum`
30+
/// `LOCAL_CRATE` in their `DefId`.
3131
pub const LOCAL_CRATE: CrateNum = CrateNum::Index(CrateId::from_u32_const(0));
3232

33-
3433
impl Idx for CrateNum {
3534
#[inline]
3635
fn new(value: usize) -> Self {

src/librustc/hir/intravisit.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@
3131
//! This order consistency is required in a few places in rustc, for
3232
//! example generator inference, and possibly also HIR borrowck.
3333
34-
use syntax::ast::{Ident, Name, Attribute};
35-
use syntax_pos::Span;
34+
use super::itemlikevisit::DeepVisitor;
35+
3636
use crate::hir::*;
3737
use crate::hir::map::Map;
38-
use super::itemlikevisit::DeepVisitor;
38+
39+
use syntax::ast::{Ident, Name, Attribute};
40+
use syntax_pos::Span;
3941

4042
#[derive(Copy, Clone)]
4143
pub enum FnKind<'a> {
@@ -139,7 +141,7 @@ impl<'this, 'tcx> NestedVisitorMap<'this, 'tcx> {
139141
/// explicitly, you need to override each method. (And you also need
140142
/// to monitor future changes to `Visitor` in case a new method with a
141143
/// new default implementation gets introduced.)
142-
pub trait Visitor<'v> : Sized {
144+
pub trait Visitor<'v>: Sized {
143145
///////////////////////////////////////////////////////////////////////////
144146
// Nested items.
145147

@@ -162,8 +164,8 @@ pub trait Visitor<'v> : Sized {
162164
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'v>;
163165

164166
/// Invoked when a nested item is encountered. By default does
165-
/// nothing unless you override `nested_visit_map` to return
166-
/// `Some(_)`, in which case it will walk the item. **You probably
167+
/// nothing unless you override `nested_visit_map` to return other than
168+
/// `None`, in which case it will walk the item. **You probably
167169
/// don't want to override this method** -- instead, override
168170
/// `nested_visit_map` or use the "shallow" or "deep" visit
169171
/// patterns described on `itemlikevisit::ItemLikeVisitor`. The only
@@ -201,8 +203,8 @@ pub trait Visitor<'v> : Sized {
201203

202204
/// Invoked to visit the body of a function, method or closure. Like
203205
/// visit_nested_item, does nothing by default unless you override
204-
/// `nested_visit_map` to return `Some(_)`, in which case it will walk the
205-
/// body.
206+
/// `nested_visit_map` to return other htan `None`, in which case it will walk
207+
/// the body.
206208
fn visit_nested_body(&mut self, id: BodyId) {
207209
let opt_body = self.nested_visit_map().intra().map(|map| map.body(id));
208210
if let Some(body) = opt_body {
@@ -603,7 +605,7 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {
603605
visitor.visit_lifetime(lifetime);
604606
visitor.visit_ty(&mutable_type.ty)
605607
}
606-
TyKind::Never => {},
608+
TyKind::Never => {}
607609
TyKind::Tup(ref tuple_element_types) => {
608610
walk_list!(visitor, visit_ty, tuple_element_types);
609611
}

src/librustc/hir/itemlikevisit.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::{Item, ImplItem, TraitItem};
22
use super::intravisit::Visitor;
33

4-
/// The "item-like visitor" visitor defines only the top-level methods
4+
/// The "item-like visitor" defines only the top-level methods
55
/// that can be invoked by `Crate::visit_all_item_likes()`. Whether
66
/// this trait is the right one to implement will depend on the
77
/// overall pattern you need. Here are the three available patterns,
@@ -18,22 +18,21 @@ use super::intravisit::Visitor;
1818
/// an item, but don't care about how item-like things are nested
1919
/// within one another.
2020
/// - Example: Examine each expression to look for its type and do some check or other.
21-
/// - How: Implement `intravisit::Visitor` and use
22-
/// `tcx.hir().krate().visit_all_item_likes(visitor.as_deep_visitor())`. Within
23-
/// your `intravisit::Visitor` impl, implement methods like
24-
/// `visit_expr()`; don't forget to invoke
25-
/// `intravisit::walk_visit_expr()` to keep walking the subparts.
21+
/// - How: Implement `intravisit::Visitor` and override the `nested_visit_map()` method
22+
/// to return `NestedVisitorMap::OnlyBodies` and use
23+
/// `tcx.hir().krate().visit_all_item_likes(&mut visitor.as_deep_visitor())`. Within
24+
/// your `intravisit::Visitor` impl, implement methods like `visit_expr()` (don't forget
25+
/// to invoke `intravisit::walk_expr()` to keep walking the subparts).
2626
/// - Pro: Visitor methods for any kind of HIR node, not just item-like things.
2727
/// - Pro: Integrates well into dependency tracking.
2828
/// - Con: Don't get information about nesting between items
2929
/// 3. **Nested visit**: Want to visit the whole HIR and you care about the nesting between
3030
/// item-like things.
3131
/// - Example: Lifetime resolution, which wants to bring lifetimes declared on the
3232
/// impl into scope while visiting the impl-items, and then back out again.
33-
/// - How: Implement `intravisit::Visitor` and override the
34-
/// `nested_visit_map()` methods to return
35-
/// `NestedVisitorMap::All`. Walk your crate with
36-
/// `intravisit::walk_crate()` invoked on `tcx.hir().krate()`.
33+
/// - How: Implement `intravisit::Visitor` and override the `nested_visit_map()` method
34+
/// to return `NestedVisitorMap::All`. Walk your crate with `intravisit::walk_crate()`
35+
/// invoked on `tcx.hir().krate()`.
3736
/// - Pro: Visitor methods for any kind of HIR node, not just item-like things.
3837
/// - Pro: Preserves nesting information
3938
/// - Con: Does not integrate well into dependency tracking.
@@ -79,7 +78,7 @@ impl<'v, 'hir, V> ItemLikeVisitor<'hir> for DeepVisitor<'v, V>
7978
}
8079
}
8180

82-
/// A parallel variant of ItemLikeVisitor
81+
/// A parallel variant of `ItemLikeVisitor`.
8382
pub trait ParItemLikeVisitor<'hir> {
8483
fn visit_item(&self, item: &'hir Item);
8584
fn visit_trait_item(&self, trait_item: &'hir TraitItem);

src/librustc/hir/lowering.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const HIR_ID_COUNTER_LOCKED: u32 = 0xFFFFFFFF;
7979
pub struct LoweringContext<'a> {
8080
crate_root: Option<Symbol>,
8181

82-
/// Used to assign ids to HIR nodes that do not directly correspond to an AST node.
82+
/// Used to assign IDs to HIR nodes that do not directly correspond to AST nodes.
8383
sess: &'a Session,
8484

8585
cstore: &'a dyn CrateStore,
@@ -126,7 +126,7 @@ pub struct LoweringContext<'a> {
126126
/// lifetime definitions in the corresponding impl or function generics.
127127
lifetimes_to_define: Vec<(Span, ParamName)>,
128128

129-
/// Whether or not in-band lifetimes are being collected. This is used to
129+
/// `true` ifs in-band lifetimes are being collected. This is used to
130130
/// indicate whether or not we're in a place where new lifetimes will result
131131
/// in in-band lifetime definitions, such a function or an impl header,
132132
/// including implicit lifetimes from `impl_header_lifetime_elision`.
@@ -154,13 +154,13 @@ pub struct LoweringContext<'a> {
154154
}
155155

156156
pub trait Resolver {
157-
/// Obtain resolution for a `NodeId` with a single resolution.
157+
/// Obtains resolution for a `NodeId` with a single resolution.
158158
fn get_partial_res(&mut self, id: NodeId) -> Option<PartialRes>;
159159

160-
/// Obtain per-namespace resolutions for `use` statement with the given `NoedId`.
160+
/// Obtains per-namespace resolutions for `use` statement with the given `NodeId`.
161161
fn get_import_res(&mut self, id: NodeId) -> PerNS<Option<Res<NodeId>>>;
162162

163-
/// Obtain resolution for a label with the given `NodeId`.
163+
/// Obtains resolution for a label with the given `NodeId`.
164164
fn get_label_res(&mut self, id: NodeId) -> Option<NodeId>;
165165

166166
/// We must keep the set of definitions up to date as we add nodes that weren't in the AST.
@@ -699,7 +699,7 @@ impl<'a> LoweringContext<'a> {
699699
fn lower_res(&mut self, res: Res<NodeId>) -> Res {
700700
res.map_id(|id| {
701701
self.lower_node_id_generic(id, |_| {
702-
panic!("expected node_id to be lowered already for res {:#?}", res)
702+
panic!("expected `NodeId` to be lowered already for res {:#?}", res);
703703
})
704704
})
705705
}
@@ -1364,7 +1364,7 @@ impl<'a> LoweringContext<'a> {
13641364
}
13651365
}
13661366
}
1367-
TyKind::Mac(_) => bug!("`TyMac` should have been expanded by now."),
1367+
TyKind::Mac(_) => bug!("`TyMac` should have been expanded by now"),
13681368
TyKind::CVarArgs => {
13691369
// Create the implicit lifetime of the "spoofed" `VaListImpl`.
13701370
let span = self.sess.source_map().next_point(t.span.shrink_to_lo());
@@ -2999,7 +2999,7 @@ impl<'a> LoweringContext<'a> {
29992999
}
30003000
StmtKind::Expr(ref e) => hir::StmtKind::Expr(P(self.lower_expr(e))),
30013001
StmtKind::Semi(ref e) => hir::StmtKind::Semi(P(self.lower_expr(e))),
3002-
StmtKind::Mac(..) => panic!("Shouldn't exist here"),
3002+
StmtKind::Mac(..) => panic!("shouldn't exist here"),
30033003
};
30043004
smallvec![hir::Stmt {
30053005
hir_id: self.lower_node_id(s.id),
@@ -3187,7 +3187,7 @@ impl<'a> LoweringContext<'a> {
31873187

31883188
hir::Path {
31893189
span,
3190-
res: res.map_id(|_| panic!("unexpected node_id")),
3190+
res: res.map_id(|_| panic!("unexpected `NodeId`")),
31913191
segments: segments.into(),
31923192
}
31933193
}

src/librustc/hir/lowering/item.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ impl LoweringContext<'_> {
718718
AnonymousLifetimeMode::PassThrough,
719719
|this, _| {
720720
(
721-
// Disallow impl Trait in foreign items
721+
// Disallow `impl Trait` in foreign items.
722722
this.lower_fn_decl(fdec, None, false, None),
723723
this.lower_fn_params_to_names(fdec),
724724
)
@@ -732,7 +732,7 @@ impl LoweringContext<'_> {
732732
self.lower_ty(t, ImplTraitContext::disallowed()), self.lower_mutability(m))
733733
}
734734
ForeignItemKind::Ty => hir::ForeignItemKind::Type,
735-
ForeignItemKind::Macro(_) => panic!("shouldn't exist here"),
735+
ForeignItemKind::Macro(_) => panic!("macro shouldn't exist here"),
736736
},
737737
vis: self.lower_visibility(&i.vis, None),
738738
span: i.span,

src/librustc/hir/map/collector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
340340
/// their outer items.
341341
342342
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'hir> {
343-
panic!("visit_nested_xxx must be manually implemented in this visitor")
343+
panic!("`visit_nested_xxx` must be manually implemented in this visitor");
344344
}
345345

346346
fn visit_nested_item(&mut self, item: ItemId) {

0 commit comments

Comments
 (0)