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: libsyntax #64226

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
52 changes: 26 additions & 26 deletions src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,11 @@ impl WherePredicate {
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct WhereBoundPredicate {
pub span: Span,
/// Any generics from a `for` binding
/// Any generics from a `for` binding.
pub bound_generic_params: Vec<GenericParam>,
/// The type being bounded
/// The type being bounded.
pub bounded_ty: P<Ty>,
/// Trait and lifetime bounds (`Clone+Send+'static`)
/// Trait and lifetime bounds (`Clone + Send + 'static`).
pub bounds: GenericBounds,
}

Expand Down Expand Up @@ -495,15 +495,15 @@ pub enum MetaItemKind {
NameValue(Lit),
}

/// A Block (`{ .. }`).
/// A block (`{ .. }`).
///
/// E.g., `{ .. }` as in `fn foo() { .. }`.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct Block {
/// Statements in a block
/// The statements in the block.
pub stmts: Vec<Stmt>,
pub id: NodeId,
/// Distinguishes between `unsafe { ... }` and `{ ... }`
/// Distinguishes between `unsafe { ... }` and `{ ... }`.
pub rules: BlockCheckMode,
pub span: Span,
}
Expand Down Expand Up @@ -908,11 +908,11 @@ pub enum MacStmtStyle {
/// Local represents a `let` statement, e.g., `let <pat>:<ty> = <expr>;`.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct Local {
pub id: NodeId,
pub pat: P<Pat>,
pub ty: Option<P<Ty>>,
/// Initializer expression to set the value, if any.
pub init: Option<P<Expr>>,
pub id: NodeId,
pub span: Span,
pub attrs: ThinVec<Attribute>,
}
Expand Down Expand Up @@ -970,7 +970,7 @@ pub struct AnonConst {
pub value: P<Expr>,
}

/// An expression
/// An expression.
#[derive(Clone, RustcEncodable, RustcDecodable)]
pub struct Expr {
pub id: NodeId,
Expand All @@ -984,26 +984,26 @@ pub struct Expr {
static_assert_size!(Expr, 96);

impl Expr {
/// Whether this expression would be valid somewhere that expects a value; for example, an `if`
/// condition.
/// Returns `true` if this expression would be valid somewhere that expects a value;
/// for example, an `if` condition.
pub fn returns(&self) -> bool {
if let ExprKind::Block(ref block, _) = self.node {
match block.stmts.last().map(|last_stmt| &last_stmt.node) {
// implicit return
// Implicit return
Some(&StmtKind::Expr(_)) => true,
Some(&StmtKind::Semi(ref expr)) => {
if let ExprKind::Ret(_) = expr.node {
// last statement is explicit return
// Last statement is explicit return.
true
} else {
false
}
}
// This is a block that doesn't end in either an implicit or explicit return
// This is a block that doesn't end in either an implicit or explicit return.
_ => false,
}
} else {
// This is not a block, it is a value
// This is not a block, it is a value.
true
}
}
Expand Down Expand Up @@ -2307,57 +2307,57 @@ impl Default for FnHeader {

#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub enum ItemKind {
/// An `extern crate` item, with optional *original* crate name if the crate was renamed.
/// An `extern crate` item, with the optional *original* crate name if the crate was renamed.
///
/// E.g., `extern crate foo` or `extern crate foo_bar as foo`.
ExternCrate(Option<Name>),
/// A use declaration (`use` or `pub use`) item.
/// A use declaration item (`use`).
///
/// E.g., `use foo;`, `use foo::bar;` or `use foo::bar as FooBar;`.
Use(P<UseTree>),
/// A static item (`static` or `pub static`).
/// A static item (`static`).
///
/// E.g., `static FOO: i32 = 42;` or `static FOO: &'static str = "bar";`.
Static(P<Ty>, Mutability, P<Expr>),
/// A constant item (`const` or `pub const`).
/// A constant item (`const`).
///
/// E.g., `const FOO: i32 = 42;`.
Const(P<Ty>, P<Expr>),
/// A function declaration (`fn` or `pub fn`).
/// A function declaration (`fn`).
///
/// E.g., `fn foo(bar: usize) -> usize { .. }`.
Fn(P<FnDecl>, FnHeader, Generics, P<Block>),
/// A module declaration (`mod` or `pub mod`).
/// A module declaration (`mod`).
///
/// E.g., `mod foo;` or `mod foo { .. }`.
Mod(Mod),
/// An external module (`extern` or `pub extern`).
/// An external module (`extern`).
///
/// E.g., `extern {}` or `extern "C" {}`.
ForeignMod(ForeignMod),
/// Module-level inline assembly (from `global_asm!()`).
GlobalAsm(P<GlobalAsm>),
/// A type alias (`type` or `pub type`).
/// A type alias (`type`).
///
/// E.g., `type Foo = Bar<u8>;`.
TyAlias(P<Ty>, Generics),
/// An opaque `impl Trait` type alias.
///
/// E.g., `type Foo = impl Bar + Boo;`.
OpaqueTy(GenericBounds, Generics),
/// An enum definition (`enum` or `pub enum`).
/// An enum definition (`enum`).
///
/// E.g., `enum Foo<A, B> { C<A>, D<B> }`.
Enum(EnumDef, Generics),
/// A struct definition (`struct` or `pub struct`).
/// A struct definition (`struct`).
///
/// E.g., `struct Foo<A> { x: A }`.
Struct(VariantData, Generics),
/// A union definition (`union` or `pub union`).
/// A union definition (`union`).
///
/// E.g., `union Foo<A, B> { x: A, y: B }`.
Union(VariantData, Generics),
/// A Trait declaration (`trait` or `pub trait`).
/// A trait declaration (`trait`).
///
/// E.g., `trait Foo { .. }`, `trait Foo<T> { .. }` or `auto trait Foo {}`.
Trait(IsAuto, Unsafety, Generics, GenericBounds, Vec<TraitItem>),
Expand Down
43 changes: 22 additions & 21 deletions src/libsyntax/attr/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Functions dealing with attributes and meta items
//! Functions dealing with attributes and meta items.

mod builtin;

Expand Down Expand Up @@ -61,15 +61,15 @@ pub fn is_known_lint_tool(m_item: Ident) -> bool {
}

impl NestedMetaItem {
/// Returns the MetaItem if self is a NestedMetaItem::MetaItem.
/// Returns the `MetaItem` if `self` is a `NestedMetaItem::MetaItem`.
pub fn meta_item(&self) -> Option<&MetaItem> {
match *self {
NestedMetaItem::MetaItem(ref item) => Some(item),
_ => None
}
}

/// Returns the Lit if self is a NestedMetaItem::Literal.
/// Returns the `Lit` if `self` is a `NestedMetaItem::Literal`s.
pub fn literal(&self) -> Option<&Lit> {
match *self {
NestedMetaItem::Literal(ref lit) => Some(lit),
Expand All @@ -82,21 +82,21 @@ impl NestedMetaItem {
self.meta_item().map_or(false, |meta_item| meta_item.check_name(name))
}

/// For a single-segment meta-item returns its name, otherwise returns `None`.
/// For a single-segment meta item, returns its name; otherwise, returns `None`.
pub fn ident(&self) -> Option<Ident> {
self.meta_item().and_then(|meta_item| meta_item.ident())
}
pub fn name_or_empty(&self) -> Symbol {
self.ident().unwrap_or(Ident::invalid()).name
}

/// Gets the string value if self is a MetaItem and the MetaItem is a
/// MetaItemKind::NameValue variant containing a string, otherwise None.
/// Gets the string value if `self` is a `MetaItem` and the `MetaItem` is a
/// `MetaItemKind::NameValue` variant containing a string, otherwise `None`.
pub fn value_str(&self) -> Option<Symbol> {
self.meta_item().and_then(|meta_item| meta_item.value_str())
}

/// Returns a name and single literal value tuple of the MetaItem.
/// Returns a name and single literal value tuple of the `MetaItem`.
pub fn name_value_literal(&self) -> Option<(Name, &Lit)> {
self.meta_item().and_then(
|meta_item| meta_item.meta_item_list().and_then(
Expand All @@ -112,32 +112,32 @@ impl NestedMetaItem {
}))
}

/// Gets a list of inner meta items from a list MetaItem type.
/// Gets a list of inner meta items from a list `MetaItem` type.
pub fn meta_item_list(&self) -> Option<&[NestedMetaItem]> {
self.meta_item().and_then(|meta_item| meta_item.meta_item_list())
}

/// Returns `true` if the variant is MetaItem.
/// Returns `true` if the variant is `MetaItem`.
pub fn is_meta_item(&self) -> bool {
self.meta_item().is_some()
}

/// Returns `true` if the variant is Literal.
/// Returns `true` if the variant is `Literal`.
pub fn is_literal(&self) -> bool {
self.literal().is_some()
}

/// Returns `true` if self is a MetaItem and the meta item is a word.
/// Returns `true` if `self` is a `MetaItem` and the meta item is a word.
pub fn is_word(&self) -> bool {
self.meta_item().map_or(false, |meta_item| meta_item.is_word())
}

/// Returns `true` if self is a MetaItem and the meta item is a ValueString.
/// Returns `true` if `self` is a `MetaItem` and the meta item is a `ValueString`.
pub fn is_value_str(&self) -> bool {
self.value_str().is_some()
}

/// Returns `true` if self is a MetaItem and the meta item is a list.
/// Returns `true` if `self` is a `MetaItem` and the meta item is a list.
pub fn is_meta_item_list(&self) -> bool {
self.meta_item_list().is_some()
}
Expand All @@ -156,7 +156,7 @@ impl Attribute {
matches
}

/// For a single-segment attribute returns its name, otherwise returns `None`.
/// For a single-segment attribute, returns its name; otherwise, returns `None`.
pub fn ident(&self) -> Option<Ident> {
if self.path.segments.len() == 1 {
Some(self.path.segments[0].ident)
Expand Down Expand Up @@ -187,14 +187,14 @@ impl Attribute {
self.meta_item_list().is_some()
}

/// Indicates if the attribute is a Value String.
/// Indicates if the attribute is a `ValueString`.
pub fn is_value_str(&self) -> bool {
self.value_str().is_some()
}
}

impl MetaItem {
/// For a single-segment meta-item returns its name, otherwise returns `None`.
/// For a single-segment meta item, returns its name; otherwise, returns `None`.
pub fn ident(&self) -> Option<Ident> {
if self.path.segments.len() == 1 {
Some(self.path.segments[0].ident)
Expand All @@ -206,8 +206,9 @@ impl MetaItem {
self.ident().unwrap_or(Ident::invalid()).name
}

// #[attribute(name = "value")]
// ^^^^^^^^^^^^^^
// Example:
// #[attribute(name = "value")]
// ^^^^^^^^^^^^^^
pub fn name_value_literal(&self) -> Option<&Lit> {
match &self.node {
MetaItemKind::NameValue(v) => Some(v),
Expand Down Expand Up @@ -255,7 +256,7 @@ impl MetaItem {
}

impl Attribute {
/// Extracts the MetaItem from inside this Attribute.
/// Extracts the `MetaItem` from inside this `Attribute`.
pub fn meta(&self) -> Option<MetaItem> {
let mut tokens = self.tokens.trees().peekable();
Some(MetaItem {
Expand Down Expand Up @@ -318,8 +319,8 @@ impl Attribute {
})
}

/// Converts self to a normal #[doc="foo"] comment, if it is a
/// comment like `///` or `/** */`. (Returns self unchanged for
/// Converts `self` to a normal `#[doc="foo"]` comment, if it is a
/// comment like `///` or `/** */`. (Returns `self` unchanged for
/// non-sugared doc attributes.)
pub fn with_desugared_doc<T, F>(&self, f: F) -> T where
F: FnOnce(&Attribute) -> T,
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ impl<'a> ExtCtxt<'a> {
self.resolver.check_unused_macros();
}

/// Resolve a path mentioned inside Rust code.
/// Resolves a path mentioned inside Rust code.
///
/// This unifies the logic used for resolving `include_X!`, and `#[doc(include)]` file paths.
///
Expand Down
18 changes: 10 additions & 8 deletions src/libsyntax/feature_gate/active.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//! List of the active feature gates.

use super::{State, Feature};

use crate::edition::Edition;
use crate::symbol::{Symbol, sym};

use syntax_pos::Span;
use super::{State, Feature};

macro_rules! set {
($field: ident) => {{
Expand Down Expand Up @@ -37,9 +39,9 @@ macro_rules! declare_features {
/// A set of features to be used by later passes.
#[derive(Clone)]
pub struct Features {
/// `#![feature]` attrs for language features, for error reporting
/// `#![feature]` attrs for language features, for error reporting.
pub declared_lang_features: Vec<(Symbol, Span, Option<Symbol>)>,
/// `#![feature]` attrs for non-language (library) features
/// `#![feature]` attrs for non-language (library) features.
pub declared_lib_features: Vec<(Symbol, Span)>,
$(
$(#[doc = $doc])*
Expand All @@ -66,11 +68,11 @@ macro_rules! declare_features {
}

impl Feature {
/// Set this feature in `Features`. Panics if called on a non-active feature.
/// Sets this feature in `Features`. Panics if called on a non-active feature.
pub fn set(&self, features: &mut Features, span: Span) {
match self.state {
State::Active { set } => set(features, span),
_ => panic!("Called `set` on feature `{}` which is not `active`", self.name)
_ => panic!("called `set` on feature `{}` which is not `active`", self.name)
}
}
}
Expand Down Expand Up @@ -478,7 +480,7 @@ declare_features! (
(active, precise_pointer_size_matching, "1.32.0", Some(56354), None),

/// Allows relaxing the coherence rules such that
/// `impl<T> ForeignTrait<LocalType> for ForeignType<T> is permitted.
/// `impl<T> ForeignTrait<LocalType> for ForeignType<T>` is permitted.
(active, re_rebalance_coherence, "1.32.0", Some(55437), None),

/// Allows using `#[ffi_returns_twice]` on foreign functions.
Expand Down Expand Up @@ -520,7 +522,7 @@ declare_features! (
/// Allows `async || body` closures.
(active, async_closure, "1.37.0", Some(62290), None),

/// Allows the use of `#[cfg(doctest)]`, set when rustdoc is collecting doctests
/// Allows the use of `#[cfg(doctest)]`; set when rustdoc is collecting doctests.
(active, cfg_doctest, "1.37.0", Some(62210), None),

/// Allows `[x; N]` where `x` is a constant (RFC 2203).
Expand All @@ -529,7 +531,7 @@ declare_features! (
/// Allows `impl Trait` to be used inside type aliases (RFC 2515).
(active, type_alias_impl_trait, "1.38.0", Some(63063), None),

/// Allows the use of or-patterns, e.g. `0 | 1`.
/// Allows the use of or-patterns (e.g., `0 | 1`).
(active, or_patterns, "1.38.0", Some(54883), None),

// -------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/feature_gate/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ const INTERAL_UNSTABLE: &str = "this is an internal attribute that will never be

pub type BuiltinAttribute = (Symbol, AttributeType, AttributeTemplate, AttributeGate);

/// Attributes that have a special meaning to rustc or rustdoc
/// Attributes that have a special meaning to rustc or rustdoc.
pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
// ==========================================================================
// Stable attributes:
Expand Down
Loading