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

Various fixes to trait alias feature #55994

Closed
wants to merge 12 commits into from
8 changes: 4 additions & 4 deletions src/liballoc/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ pub use core::slice::{RChunks, RChunksMut, RChunksExact, RChunksExactMut};
////////////////////////////////////////////////////////////////////////////////

// HACK(japaric) needed for the implementation of `vec!` macro during testing
// NB see the hack module in this file for more details
// N.B., see the `hack` module in this file for more details.
#[cfg(test)]
pub use self::hack::into_vec;

// HACK(japaric) needed for the implementation of `Vec::clone` during testing
// NB see the hack module in this file for more details
// N.B., see the `hack` module in this file for more details.
#[cfg(test)]
pub use self::hack::to_vec;

Expand Down Expand Up @@ -373,7 +373,7 @@ impl<T> [T] {
pub fn to_vec(&self) -> Vec<T>
where T: Clone
{
// NB see hack module in this file
// N.B., see the `hack` module in this file for more details.
hack::to_vec(self)
}

Expand All @@ -394,7 +394,7 @@ impl<T> [T] {
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn into_vec(self: Box<Self>) -> Vec<T> {
// NB see hack module in this file
// N.B., see the `hack` module in this file for more details.
hack::into_vec(self)
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ pub enum Def {
Enum(DefId),
Variant(DefId),
Trait(DefId),
TraitAlias(DefId),
/// `existential type Foo: Bar;`
Existential(DefId),
/// `type Foo = Bar;`
TyAlias(DefId),
ForeignTy(DefId),
TraitAlias(DefId),
AssociatedTy(DefId),
/// `existential type Foo: Bar;`
AssociatedExistential(DefId),
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 @@ -14,7 +14,7 @@ use syntax_pos::Span;
use ich::StableHashingContext;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableHasherResult};

/// A Visitor that walks over the HIR and collects Nodes into a HIR map
/// A visitor that walks over the HIR and collects `Node`s into a HIR map.
pub(super) struct NodeCollector<'a, 'hir> {
/// The crate
krate: &'hir Crate,
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/hir/map/def_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
debug!("visit_item: {:?}", i);

// Pick the def data. This need not be unique, but the more
// information we encapsulate into, the better
// information we encapsulate into, the better.
let def_data = match i.node {
ItemKind::Impl(..) => DefPathData::Impl,
ItemKind::Trait(..) => DefPathData::Trait(i.ident.as_interned_str()),
ItemKind::TraitAlias(..) => DefPathData::TraitAlias(i.ident.as_interned_str()),
ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) |
ItemKind::TraitAlias(..) | ItemKind::Existential(..) |
ItemKind::ExternCrate(..) | ItemKind::ForeignMod(..) | ItemKind::Ty(..) =>
DefPathData::TypeNs(i.ident.as_interned_str()),
ItemKind::Existential(..) | ItemKind::ExternCrate(..) | ItemKind::ForeignMod(..) |
ItemKind::Ty(..) => DefPathData::TypeNs(i.ident.as_interned_str()),
ItemKind::Mod(..) if i.ident == keywords::Invalid.ident() => {
return visit::walk_item(self, i);
}
Expand Down
28 changes: 16 additions & 12 deletions src/librustc/hir/map/definitions.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! For each definition, we track the following data. A definition
//! For each definition, we track the following data. A definition
//! here is defined somewhat circularly as "something with a def-id",
//! but it generally corresponds to things like structs, enums, etc.
//! There are also some rather random cases (like const initializer
Expand Down Expand Up @@ -114,7 +114,7 @@ impl Encodable for DefPathTable {
self.index_to_key[DefIndexAddressSpace::Low.index()].encode(s)?;
self.index_to_key[DefIndexAddressSpace::High.index()].encode(s)?;

// DefPath hashes
// `DefPath` hashes
self.def_path_hashes[DefIndexAddressSpace::Low.index()].encode(s)?;
self.def_path_hashes[DefIndexAddressSpace::High.index()].encode(s)?;

Expand Down Expand Up @@ -260,9 +260,9 @@ impl DefPath {
DefPath { data: data, krate: krate }
}

/// Returns a string representation of the DefPath without
/// Returns a string representation of the `DefPath` without
/// the crate-prefix. This method is useful if you don't have
/// a TyCtxt available.
/// a `TyCtxt` available.
pub fn to_string_no_crate(&self) -> String {
let mut s = String::with_capacity(self.data.len() * 16);

Expand All @@ -271,13 +271,13 @@ impl DefPath {
"::{}[{}]",
component.data.as_interned_str(),
component.disambiguator)
.unwrap();
.unwrap();
}

s
}

/// Return filename friendly string of the DefPah with the
/// Returns filename-friendly string of the `DefPath` with the
/// crate-prefix.
pub fn to_string_friendly<F>(&self, crate_imported_name: F) -> String
where F: FnOnce(CrateNum) -> Symbol
Expand All @@ -295,16 +295,16 @@ impl DefPath {
"{}[{}]",
component.data.as_interned_str(),
component.disambiguator)
.unwrap();
.unwrap();
}
}

s
}

/// Return filename friendly string of the DefPah without
/// Returns filename-friendly string of the `DefPath` without
/// the crate-prefix. This method is useful if you don't have
/// a TyCtxt available.
/// a `TyCtxt` available.
pub fn to_filename_friendly_no_crate(&self) -> String {
let mut s = String::with_capacity(self.data.len() * 16);

Expand All @@ -319,7 +319,7 @@ impl DefPath {
"{}[{}]",
component.data.as_interned_str(),
component.disambiguator)
.unwrap();
.unwrap();
}
}
s
Expand Down Expand Up @@ -373,7 +373,9 @@ pub enum DefPathData {
/// GlobalMetaData identifies a piece of crate metadata that is global to
/// a whole crate (as opposed to just one item). GlobalMetaData components
/// are only supposed to show up right below the crate root.
GlobalMetaData(InternedString)
GlobalMetaData(InternedString),
/// A trait alias.
TraitAlias(InternedString),
}

#[derive(Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Debug,
Expand Down Expand Up @@ -615,6 +617,7 @@ impl DefPathData {
match *self {
TypeNs(name) |
Trait(name) |
TraitAlias(name) |
AssocTypeInTrait(name) |
AssocTypeInImpl(name) |
AssocExistentialInImpl(name) |
Expand Down Expand Up @@ -642,6 +645,7 @@ impl DefPathData {
let s = match *self {
TypeNs(name) |
Trait(name) |
TraitAlias(name) |
AssocTypeInTrait(name) |
AssocTypeInImpl(name) |
AssocExistentialInImpl(name) |
Expand All @@ -655,7 +659,7 @@ impl DefPathData {
GlobalMetaData(name) => {
return name
}
// note that this does not show up in user printouts
// Note that this does not show up in user print-outs.
CrateRoot => "{{root}}",
Impl => "{{impl}}",
Misc => "{{?}}",
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ impl<'hir> Map<'hir> {
}
}

/// Returns the name associated with the given NodeId's AST.
/// Returns the name associated with the given `NodeId`'s AST.
pub fn name(&self, id: NodeId) -> Name {
match self.get(id) {
Node::Item(i) => i.ident.name,
Expand Down
49 changes: 32 additions & 17 deletions src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub use self::PrimTy::*;
pub use self::UnOp::*;
pub use self::UnsafeSource::*;

use errors::FatalError;
use hir::def::Def;
use hir::def_id::{DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX};
use util::nodemap::{NodeMap, FxHashSet};
Expand Down Expand Up @@ -289,7 +290,7 @@ impl Lifetime {
}
}

/// A "Path" is essentially Rust's notion of a name; for instance:
/// A `Path` is essentially Rust's notion of a name; for instance:
/// `std::cmp::PartialEq`. It's represented as a sequence of identifiers,
/// along with a bunch of supporting information.
#[derive(Clone, RustcEncodable, RustcDecodable)]
Expand Down Expand Up @@ -607,7 +608,7 @@ pub enum SyntheticTyParamKind {
ImplTrait
}

/// A `where` clause in a definition
/// A `where` clause in a definition.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct WhereClause {
pub id: NodeId,
Expand All @@ -626,7 +627,7 @@ impl WhereClause {
}
}

/// A single predicate in a `where` clause
/// A single predicate in a `where` clause.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub enum WherePredicate {
/// A type binding (e.g., `for<'c> Foo: Send + Clone + 'c`).
Expand Down Expand Up @@ -2040,25 +2041,39 @@ pub enum UseKind {
ListStem,
}

/// TraitRef's appear in impls.
/// `TraitRef` are references to traits in impls.
///
/// resolve maps each TraitRef's ref_id to its defining trait; that's all
/// that the ref_id is for. Note that ref_id's value is not the NodeId of the
/// trait being referred to but just a unique NodeId that serves as a key
/// within the DefMap.
/// `resolve` maps each `TraitRef`'s `ref_id` to its defining trait; that's all
/// that the `ref_id` is for. Note that `ref_id`'s value is not the `NodeId` of the
/// trait being referred to but just a unique `NodeId` that serves as a key
/// within the `DefMap`.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct TraitRef {
pub path: Path,
pub ref_id: NodeId,
pub hir_ref_id: HirId,
}

impl TraitRef {
/// Get the `DefId` of the referenced trait. It _must_ actually be a trait or trait alias.
pub fn trait_def_id(&self) -> DefId {
match self.path.def {
Def::Trait(did) => did,
Def::TraitAlias(did) => did,
Def::Err => {
FatalError.raise();
}
_ => unreachable!(),
}
}
}

#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct PolyTraitRef {
/// The `'a` in `<'a> Foo<&'a T>`
/// The `'a` in `<'a> Foo<&'a T>`.
pub bound_generic_params: HirVec<GenericParam>,

/// The `Foo<&'a T>` in `<'a> Foo<&'a T>`
/// The `Foo<&'a T>` in `<'a> Foo<&'a T>`.
pub trait_ref: TraitRef,

pub span: Span,
Expand Down Expand Up @@ -2484,25 +2499,25 @@ impl CodegenFnAttrs {
}
}

/// True if `#[inline]` or `#[inline(always)]` is present.
/// Returns whether `#[inline]` or `#[inline(always)]` is present.
pub fn requests_inline(&self) -> bool {
match self.inline {
InlineAttr::Hint | InlineAttr::Always => true,
InlineAttr::None | InlineAttr::Never => false,
}
}

/// True if it looks like this symbol needs to be exported, for example:
/// Returns whether it looks like this symbol needs to be exported, for example:
///
/// * `#[no_mangle]` is present
/// * `#[export_name(...)]` is present
/// * `#[linkage]` is present
/// * `#[no_mangle]` is present.
/// * `#[export_name(...)]` is present.
/// * `#[linkage]` is present.
pub fn contains_extern_indicator(&self) -> bool {
self.flags.contains(CodegenFnAttrFlags::NO_MANGLE) ||
self.export_name.is_some() ||
match self.linkage {
// these are private, make sure we don't try to consider
// them external
// These are private, so make sure we don't try to consider
// them external.
None |
Some(Linkage::Internal) |
Some(Linkage::Private) => false,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/nll_relate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ where
}

fn trait_object_mode(&self) -> relate::TraitObjectMode {
// squashing should only be done in coherence, not NLL
// Squashing should only be done in coherence, not in NLL.
assert_eq!(self.infcx.trait_object_mode(),
relate::TraitObjectMode::NoSquash);
relate::TraitObjectMode::NoSquash
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/infer/outlives/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ impl<'cx, 'gcx, 'tcx> VerifyBoundCx<'cx, 'gcx, 'tcx> {
}

fn recursive_type_bound(&self, ty: Ty<'tcx>) -> VerifyBound<'tcx> {
let mut bounds = ty.walk_shallow()
let mut bounds: Vec<_> = ty.walk_shallow()
.map(|subty| self.type_bound(subty))
.collect::<Vec<_>>();
.collect();

let mut regions = smallvec![];
ty.push_regions(&mut regions);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl<'a, 'gcx, 'tcx> TypeVisitor<'tcx> for UnresolvedTypeFinder<'a, 'gcx, 'tcx>
/// then an `Err` result is returned.
pub fn fully_resolve<'a, 'gcx, 'tcx, T>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
value: &T) -> FixupResult<T>
where T : TypeFoldable<'tcx>
where T: TypeFoldable<'tcx>
{
let mut full_resolver = FullTypeResolver { infcx: infcx, err: None };
let result = value.fold_with(&mut full_resolver);
Expand Down
16 changes: 8 additions & 8 deletions src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,13 @@ declare_lint! {
"outlives requirements can be inferred"
}

declare_lint! {
pub DEPRECATED_IN_FUTURE,
Allow,
"detects use of items that will be deprecated in a future version",
report_in_external_macro: true
}

/// Some lints that are buffered from `libsyntax`. See `syntax::early_buffered_lints`.
pub mod parser {
declare_lint! {
Expand All @@ -361,13 +368,6 @@ pub mod parser {
}
}

declare_lint! {
pub DEPRECATED_IN_FUTURE,
Allow,
"detects use of items that will be deprecated in a future version",
report_in_external_macro: true
}

/// Does nothing as a lint pass, but registers some `Lint`s
/// that are used by other parts of the compiler.
#[derive(Copy, Clone)]
Expand Down Expand Up @@ -430,8 +430,8 @@ impl LintPass for HardwiredLints {
PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
MACRO_USE_EXTERN_CRATE,
MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
parser::QUESTION_MARK_MACRO_SEP,
DEPRECATED_IN_FUTURE,
parser::QUESTION_MARK_MACRO_SEP,
)
}
}
Expand Down
Loading