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

Aggregation of cosmetic changes made during work on REPL PRs: librustc #64227

Merged
merged 2 commits into from
Sep 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/librustc/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ impl<T: Copy> ArenaAllocatable for T {}

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

Expand Down
7 changes: 3 additions & 4 deletions src/librustc/hir/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
//! conflicts between multiple such attributes attached to the same
//! item.


use crate::ty::TyCtxt;
use crate::ty::query::Providers;

use crate::hir;
use crate::hir::def_id::DefId;
use crate::hir::intravisit::{self, Visitor, NestedVisitorMap};
use crate::ty::TyCtxt;
use crate::ty::query::Providers;

use std::fmt::{self, Display};
use syntax::symbol::sym;
use syntax_pos::Span;
Expand Down
22 changes: 14 additions & 8 deletions src/librustc/hir/def.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
use self::Namespace::*;

use crate::hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
use crate::hir;
use crate::ty;
use crate::util::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::*;
use std::fmt::Debug;

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

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

// Type namespace

PrimTy(hir::PrimTy),
SelfTy(Option<DefId> /* trait */, Option<DefId> /* impl */),
ToolMod, // e.g., `rustfmt` in `#[rustfmt::skip]`

// Value namespace

SelfCtor(DefId /* impl */), // `DefId` refers to the impl
Local(Id),

// Macro namespace

NonMacroAttr(NonMacroAttrKind), // e.g., `#[inline]` or `#[rustfmt::skip]`

// All namespaces

Err,
}

Expand Down Expand Up @@ -330,7 +336,7 @@ impl NonMacroAttrKind {
}

impl<Id> Res<Id> {
/// Return the `DefId` of this `Def` if it has an id, else panic.
/// Return the `DefId` of this `Def` if it has an ID, else panic.
pub fn def_id(&self) -> DefId
where
Id: Debug,
Expand All @@ -340,7 +346,7 @@ impl<Id> Res<Id> {
})
}

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

/// An English article for the res.
/// Gets an English article for the `Res`.
pub fn article(&self) -> &'static str {
match *self {
Res::Def(kind, _) => kind.article(),
Expand Down
7 changes: 3 additions & 4 deletions src/librustc/hir/def_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ newtype_index! {

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

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


impl Idx for CrateNum {
#[inline]
fn new(value: usize) -> Self {
Expand Down
20 changes: 11 additions & 9 deletions src/librustc/hir/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@
//! This order consistency is required in a few places in rustc, for
//! example generator inference, and possibly also HIR borrowck.

use syntax::ast::{Ident, Name, Attribute};
use syntax_pos::Span;
use super::itemlikevisit::DeepVisitor;

use crate::hir::*;
use crate::hir::map::Map;
use super::itemlikevisit::DeepVisitor;

use syntax::ast::{Ident, Name, Attribute};
use syntax_pos::Span;

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

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

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

/// Invoked to visit the body of a function, method or closure. Like
/// visit_nested_item, does nothing by default unless you override
/// `nested_visit_map` to return `Some(_)`, in which case it will walk the
/// body.
/// `nested_visit_map` to return other htan `None`, in which case it will walk
/// the body.
fn visit_nested_body(&mut self, id: BodyId) {
let opt_body = self.nested_visit_map().intra().map(|map| map.body(id));
if let Some(body) = opt_body {
Expand Down Expand Up @@ -603,7 +605,7 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) {
visitor.visit_lifetime(lifetime);
visitor.visit_ty(&mutable_type.ty)
}
TyKind::Never => {},
TyKind::Never => {}
TyKind::Tup(ref tuple_element_types) => {
walk_list!(visitor, visit_ty, tuple_element_types);
}
Expand Down
21 changes: 10 additions & 11 deletions src/librustc/hir/itemlikevisit.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{Item, ImplItem, TraitItem};
use super::intravisit::Visitor;

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

/// A parallel variant of ItemLikeVisitor
/// A parallel variant of `ItemLikeVisitor`.
pub trait ParItemLikeVisitor<'hir> {
fn visit_item(&self, item: &'hir Item);
fn visit_trait_item(&self, trait_item: &'hir TraitItem);
Expand Down
18 changes: 9 additions & 9 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const HIR_ID_COUNTER_LOCKED: u32 = 0xFFFFFFFF;
pub struct LoweringContext<'a> {
crate_root: Option<Symbol>,

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

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

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

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

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

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

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

hir::Path {
span,
res: res.map_id(|_| panic!("unexpected node_id")),
res: res.map_id(|_| panic!("unexpected `NodeId`")),
segments: segments.into(),
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/hir/lowering/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ impl LoweringContext<'_> {
AnonymousLifetimeMode::PassThrough,
|this, _| {
(
// Disallow impl Trait in foreign items
// Disallow `impl Trait` in foreign items.
this.lower_fn_decl(fdec, None, false, None),
this.lower_fn_params_to_names(fdec),
)
Expand All @@ -732,7 +732,7 @@ impl LoweringContext<'_> {
self.lower_ty(t, ImplTraitContext::disallowed()), self.lower_mutability(m))
}
ForeignItemKind::Ty => hir::ForeignItemKind::Type,
ForeignItemKind::Macro(_) => panic!("shouldn't exist here"),
ForeignItemKind::Macro(_) => panic!("macro shouldn't exist here"),
},
vis: self.lower_visibility(&i.vis, None),
span: i.span,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/map/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
/// their outer items.

fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'hir> {
panic!("visit_nested_xxx must be manually implemented in this visitor")
panic!("`visit_nested_xxx` must be manually implemented in this visitor");
}

fn visit_nested_item(&mut self, item: ItemId) {
Expand Down
Loading