Skip to content

Commit

Permalink
Cosmetic improvements and fixes to stderr files
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Regueiro committed Jan 3, 2019
1 parent a8e7baa commit d246b2c
Show file tree
Hide file tree
Showing 35 changed files with 232 additions and 421 deletions.
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
18 changes: 9 additions & 9 deletions src/librustc/hir/map/definitions.rs
Original file line number Diff line number Diff line change
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 @@ -659,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
33 changes: 24 additions & 9 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 @@ -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 @@ -2053,6 +2054,20 @@ pub struct TraitRef {
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>`.
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/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
17 changes: 5 additions & 12 deletions src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,10 @@ declare_lint! {
}

declare_lint! {
pub DUPLICATE_AUTO_TRAITS_IN_TRAIT_OBJECTS,
Warn,
"duplicate auto traits in trait object bounds"
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`.
Expand All @@ -367,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 @@ -436,9 +430,8 @@ impl LintPass for HardwiredLints {
PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
MACRO_USE_EXTERN_CRATE,
MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
DUPLICATE_AUTO_TRAITS_IN_TRAIT_OBJECTS,
parser::QUESTION_MARK_MACRO_SEP,
DEPRECATED_IN_FUTURE,
parser::QUESTION_MARK_MACRO_SEP,
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ pub fn fully_normalize<'a, 'gcx, 'tcx, T>(
param_env: ty::ParamEnv<'tcx>,
value: &T)
-> Result<T, Vec<FulfillmentError<'tcx>>>
where T : TypeFoldable<'tcx>
where T: TypeFoldable<'tcx>
{
debug!("fully_normalize_with_fulfillcx(value={:?})", value);
let selcx = &mut SelectionContext::new(infcx);
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/traits/object_safety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
predicates
.predicates
.iter()
.map(|(predicate, _)| predicate.subst_supertrait(self, &trait_ref))
.any(|predicate| {
match predicate {
.map(|(pred, _)| pred.subst_supertrait(self, &trait_ref))
.any(|pred| {
match pred {
ty::Predicate::Trait(ref data) => {
// In the case of a trait predicate, we can skip the "self" type.
data.skip_binder().input_types().skip(1).any(|t| t.has_self_ty())
Expand Down
26 changes: 13 additions & 13 deletions src/librustc/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ pub type ProjectionTyObligation<'tcx> =
/// When attempting to resolve `<T as TraitRef>::Name` ...
#[derive(Debug)]
pub enum ProjectionTyError<'tcx> {
/// ...we found multiple sources of information and couldn't resolve the ambiguity.
/// ... we found multiple sources of information and couldn't resolve the ambiguity.
TooManyCandidates,

/// ...an error occurred matching `T : TraitRef`
/// ... an error occurred matching `T: TraitRef`.
TraitSelectionError(SelectionError<'tcx>),
}

Expand All @@ -92,13 +92,13 @@ pub struct MismatchedProjectionTypes<'tcx> {

#[derive(PartialEq, Eq, Debug)]
enum ProjectionTyCandidate<'tcx> {
// from a where-clause in the env or object type
// From a where-clause in the env or object type.
ParamEnv(ty::PolyProjectionPredicate<'tcx>),

// from the definition of `Trait` when you have something like <<A as Trait>::B as Trait2>::C
// From the definition of `Trait` when you have something like `<<A as Trait>::B as Trait2>::C`.
TraitDef(ty::PolyProjectionPredicate<'tcx>),

// from a "impl" (or a "pseudo-impl" returned by select)
// From a "impl" (or a "pseudo-impl" returned by select).
Select(Selection<'tcx>),
}

Expand Down Expand Up @@ -270,7 +270,7 @@ pub fn normalize<'a, 'b, 'gcx, 'tcx, T>(selcx: &'a mut SelectionContext<'b, 'gcx
cause: ObligationCause<'tcx>,
value: &T)
-> Normalized<'tcx, T>
where T : TypeFoldable<'tcx>
where T: TypeFoldable<'tcx>
{
normalize_with_depth(selcx, param_env, cause, 0, value)
}
Expand All @@ -284,7 +284,7 @@ pub fn normalize_with_depth<'a, 'b, 'gcx, 'tcx, T>(
value: &T)
-> Normalized<'tcx, T>

where T : TypeFoldable<'tcx>
where T: TypeFoldable<'tcx>
{
debug!("normalize_with_depth(depth={}, value={:?})", depth, value);
let mut normalizer = AssociatedTypeNormalizer::new(selcx, param_env, cause, depth);
Expand Down Expand Up @@ -386,7 +386,7 @@ impl<'a, 'b, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for AssociatedTypeNormalizer<'a,
// handle normalization within binders because
// otherwise we wind up a need to normalize when doing
// trait matching (since you can have a trait
// obligation like `for<'a> T::B : Fn(&'a int)`), but
// obligation like `for<'a> T::B: Fn(&'a int)`), but
// we can't normalize with bound regions in scope. So
// far now we just ignore binders but only normalize
// if all bound regions are gone (and then we still
Expand Down Expand Up @@ -948,7 +948,7 @@ fn assemble_candidates_from_param_env<'cx, 'gcx, 'tcx>(
///
/// ```
/// trait Foo {
/// type FooT : Bar<BarT=i32>
/// type FooT: Bar<BarT = i32>
/// }
/// ```
///
Expand Down Expand Up @@ -1139,8 +1139,8 @@ fn assemble_candidates_from_impls<'cx, 'gcx, 'tcx>(
// fn foo<T:SomeTrait>(...) { }
// ```
//
// If the user writes `<T as SomeTrait>::Foo`, then the `T
// : SomeTrait` binding does not help us decide what the
// If the user writes `<T as SomeTrait>::Foo`, then the
// `T: SomeTrait` binding does not help us decide what the
// type `Foo` is (at least, not more specifically than
// what we already knew).
//
Expand All @@ -1150,10 +1150,10 @@ fn assemble_candidates_from_impls<'cx, 'gcx, 'tcx>(
// fn bar<T:SomeTrait<Foo=usize>>(...) { ... }
// ```
//
// Doesn't the `T : Sometrait<Foo=usize>` predicate help
// Doesn't the `T: Sometrait<Foo = usize>` predicate help
// resolve `T::Foo`? And of course it does, but in fact
// that single predicate is desugared into two predicates
// in the compiler: a trait predicate (`T : SomeTrait`) and a
// in the compiler: a trait predicate (`T: SomeTrait`) and a
// projection. And the projection where clause is handled
// in `assemble_candidates_from_param_env`.
false
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3812,19 +3812,19 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
let mut predicates: Vec<_> = predicates
.predicates
.iter()
.flat_map(|(predicate, _)| {
let predicate = normalize_with_depth(
.flat_map(|(pred, _)| {
let pred = normalize_with_depth(
self,
param_env,
cause.clone(),
recursion_depth,
&predicate.subst(tcx, substs),
&pred.subst(tcx, substs),
);
predicate.obligations.into_iter().chain(Some(Obligation {
pred.obligations.into_iter().chain(Some(Obligation {
cause: cause.clone(),
recursion_depth,
param_env,
predicate: predicate.value,
predicate: pred.value,
}))
})
.collect();
Expand Down
7 changes: 3 additions & 4 deletions src/librustc/ty/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ pub fn encode_predicates<'tcx, E, C>(encoder: &mut E,
}

pub trait TyDecoder<'a, 'tcx: 'a>: Decoder {

fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx>;

fn peek_byte(&self) -> u8;
Expand Down Expand Up @@ -168,8 +167,8 @@ pub fn decode_predicates<'a, 'tcx, D>(decoder: &mut D)
Ok(ty::GenericPredicates {
parent: Decodable::decode(decoder)?,
predicates: (0..decoder.read_usize()?).map(|_| {
// Handle shorthands first, if we have an usize > 0x80.
let predicate = if decoder.positioned_at_shorthand() {
// Handle shorthands first, if we have an usize greater than `0x80`.
let pred = if decoder.positioned_at_shorthand() {
let pos = decoder.read_usize()?;
assert!(pos >= SHORTHAND_OFFSET);
let shorthand = pos - SHORTHAND_OFFSET;
Expand All @@ -178,7 +177,7 @@ pub fn decode_predicates<'a, 'tcx, D>(decoder: &mut D)
} else {
ty::Predicate::decode(decoder)
}?;
Ok((predicate, Decodable::decode(decoder)?))
Ok((pred, Decodable::decode(decoder)?))
})
.collect::<Result<Vec<_>, _>>()?,
})
Expand Down
7 changes: 3 additions & 4 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ use lint::{self, Lint};
use ich::{StableHashingContext, NodeIdHashingMode};
use infer::canonical::{Canonical, CanonicalVarInfo, CanonicalVarInfos};
use infer::outlives::free_region_map::FreeRegionMap;
use middle::cstore::CrateStoreDyn;
use middle::cstore::EncodedMetadata;
use middle::cstore::{CrateStoreDyn, EncodedMetadata};
use middle::lang_items;
use middle::resolve_lifetime::{self, ObjectLifetimeDefault};
use middle::stability;
Expand Down Expand Up @@ -1366,7 +1365,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {

pub fn def_path_debug_str(self, def_id: DefId) -> String {
// We are explicitly not going through queries here in order to get
// crate name and disambiguator since this code is called from debug!()
// crate name and disambiguator since this code is called from `debug!()`
// statements within the query system and we'd run into endless
// recursion otherwise.
let (crate_name, crate_disambiguator) = if def_id.is_local() {
Expand All @@ -1390,7 +1389,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
}

// Note that this is *untracked* and should only be used within the query
// system if the result is otherwise tracked through queries
// system if the result is otherwise tracked through queries.
pub fn crate_data_as_rc_any(self, cnum: CrateNum) -> Lrc<dyn Any> {
self.cstore.crate_data_as_rc_any(cnum)
}
Expand Down
Loading

0 comments on commit d246b2c

Please sign in to comment.