Skip to content

Commit

Permalink
Auto merge of #57755 - Centril:rollup, r=Centril
Browse files Browse the repository at this point in the history
Rollup of 7 pull requests

Successful merges:

 - #57486 (Simplify `TokenStream` some more)
 - #57502 (make trait-aliases work across crates)
 - #57598 (Add missing unpretty option help message)
 - #57649 (privacy: Account for associated existential types)
 - #57659 (Fix release manifest generation)
 - #57699 (add applicability to remaining suggestions)
 - #57719 (Tweak `expand_node`)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Jan 19, 2019
2 parents 286ac62 + 92fecfb commit 9323499
Show file tree
Hide file tree
Showing 44 changed files with 477 additions and 308 deletions.
6 changes: 3 additions & 3 deletions src/librustc/hir/map/def_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
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
6 changes: 5 additions & 1 deletion src/librustc/hir/map/definitions.rs
Original file line number Diff line number Diff line change
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 Down
15 changes: 15 additions & 0 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 @@ -2055,6 +2056,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
2 changes: 1 addition & 1 deletion src/librustc/ich/impls_syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ for tokenstream::TokenTree {
tokenstream::TokenTree::Delimited(span, delim, ref tts) => {
span.hash_stable(hcx, hasher);
std_hash::Hash::hash(&delim, hasher);
for sub_tt in tts.stream().trees() {
for sub_tt in tts.trees() {
sub_tt.hash_stable(hcx, hasher);
}
}
Expand Down
36 changes: 20 additions & 16 deletions src/librustc/infer/lexical_region_resolve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,34 +186,39 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> {
}

fn expansion(&self, var_values: &mut LexicalRegionResolutions<'tcx>) {
self.iterate_until_fixed_point("Expansion", |constraint, origin| {
debug!("expansion: constraint={:?} origin={:?}", constraint, origin);
match *constraint {
self.iterate_until_fixed_point("Expansion", |constraint| {
debug!("expansion: constraint={:?}", constraint);
let (a_region, b_vid, b_data, retain) = match *constraint {
Constraint::RegSubVar(a_region, b_vid) => {
let b_data = var_values.value_mut(b_vid);
(self.expand_node(a_region, b_vid, b_data), false)
(a_region, b_vid, b_data, false)
}
Constraint::VarSubVar(a_vid, b_vid) => match *var_values.value(a_vid) {
VarValue::ErrorValue => (false, false),
VarValue::ErrorValue => return (false, false),
VarValue::Value(a_region) => {
let b_node = var_values.value_mut(b_vid);
let changed = self.expand_node(a_region, b_vid, b_node);
let retain = match *b_node {
let b_data = var_values.value_mut(b_vid);
let retain = match *b_data {
VarValue::Value(ReStatic) | VarValue::ErrorValue => false,
_ => true
};
(changed, retain)
(a_region, b_vid, b_data, retain)
}
},
Constraint::RegSubReg(..) | Constraint::VarSubReg(..) => {
// These constraints are checked after expansion
// is done, in `collect_errors`.
(false, false)
return (false, false)
}
}
};

let changed = self.expand_node(a_region, b_vid, b_data);
(changed, retain)
})
}

// This function is very hot in some workloads. There's a single callsite
// so always inlining is ok even though it's large.
#[inline(always)]
fn expand_node(
&self,
a_region: Region<'tcx>,
Expand Down Expand Up @@ -722,18 +727,17 @@ impl<'cx, 'gcx, 'tcx> LexicalResolver<'cx, 'gcx, 'tcx> {
}

fn iterate_until_fixed_point<F>(&self, tag: &str, mut body: F)
where
F: FnMut(&Constraint<'tcx>, &SubregionOrigin<'tcx>) -> (bool, bool),
where F: FnMut(&Constraint<'tcx>) -> (bool, bool),
{
let mut constraints: SmallVec<[_; 16]> = self.data.constraints.iter().collect();
let mut constraints: SmallVec<[_; 16]> = self.data.constraints.keys().collect();
let mut iteration = 0;
let mut changed = true;
while changed {
changed = false;
iteration += 1;
debug!("---- {} Iteration {}{}", "#", tag, iteration);
constraints.retain(|(constraint, origin)| {
let (edge_changed, retain) = body(constraint, origin);
constraints.retain(|constraint| {
let (edge_changed, retain) = body(constraint);
if edge_changed {
debug!("Updated due to constraint {:?}", constraint);
changed = true;
Expand Down
9 changes: 7 additions & 2 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1353,10 +1353,15 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
unpretty: Option<String> = (None, parse_unpretty, [UNTRACKED],
"Present the input source, unstable (and less-pretty) variants;
valid types are any of the types for `--pretty`, as well as:
`expanded`, `expanded,identified`,
`expanded,hygiene` (with internal representations),
`flowgraph=<nodeid>` (graphviz formatted flowgraph for node),
`flowgraph,unlabelled=<nodeid>` (unlabelled graphviz formatted flowgraph for node),
`everybody_loops` (all function bodies replaced with `loop {}`),
`hir` (the HIR), `hir,identified`, or
`hir,typed` (HIR with types for each node)."),
`hir` (the HIR), `hir,identified`,
`hir,typed` (HIR with types for each node),
`hir-tree` (dump the raw HIR),
`mir` (the MIR), or `mir-cfg` (graphviz formatted MIR)"),
run_dsymutil: Option<bool> = (None, parse_opt_bool, [TRACKED],
"run `dsymutil` and delete intermediate object files"),
ui_testing: bool = (false, parse_bool, [UNTRACKED],
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2198,7 +2198,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {

let def_id = obligation.predicate.def_id();

if ty::is_trait_alias(self.tcx(), def_id) {
if self.tcx().is_trait_alias(def_id) {
candidates.vec.push(TraitAliasCandidate(def_id.clone()));
}

Expand Down
1 change: 1 addition & 0 deletions src/librustc/ty/item_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
data @ DefPathData::Misc |
data @ DefPathData::TypeNs(..) |
data @ DefPathData::Trait(..) |
data @ DefPathData::TraitAlias(..) |
data @ DefPathData::AssocTypeInTrait(..) |
data @ DefPathData::AssocTypeInImpl(..) |
data @ DefPathData::AssocExistentialInImpl(..) |
Expand Down
12 changes: 0 additions & 12 deletions src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3170,18 +3170,6 @@ pub fn is_impl_trait_defn(tcx: TyCtxt<'_, '_, '_>, def_id: DefId) -> Option<DefI
None
}

/// Returns `true` if `def_id` is a trait alias.
pub fn is_trait_alias(tcx: TyCtxt<'_, '_, '_>, def_id: DefId) -> bool {
if let Some(node_id) = tcx.hir().as_local_node_id(def_id) {
if let Node::Item(item) = tcx.hir().get(node_id) {
if let hir::ItemKind::TraitAlias(..) = item.node {
return true;
}
}
}
false
}

/// See `ParamEnv` struct definition for details.
fn param_env<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
def_id: DefId)
Expand Down
9 changes: 9 additions & 0 deletions src/librustc/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,15 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
}
}

/// True if `def_id` refers to a trait alias (i.e., `trait Foo = ...;`).
pub fn is_trait_alias(self, def_id: DefId) -> bool {
if let DefPathData::TraitAlias(_) = self.def_key(def_id).disambiguated_data.data {
true
} else {
false
}
}

/// True if this def-id refers to the implicit constructor for
/// a tuple struct like `struct Foo(u32)`.
pub fn is_struct_constructor(self, def_id: DefId) -> bool {
Expand Down
1 change: 1 addition & 0 deletions src/librustc/util/ppaux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ impl PrintContext {
DefPathData::AssocTypeInImpl(_) |
DefPathData::AssocExistentialInImpl(_) |
DefPathData::Trait(_) |
DefPathData::TraitAlias(_) |
DefPathData::Impl |
DefPathData::TypeNs(_) => {
break;
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_driver/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ pub fn parse_pretty(sess: &Session,
sess.fatal(&format!("argument to `unpretty` must be one of `normal`, \
`expanded`, `flowgraph[,unlabelled]=<nodeid>`, \
`identified`, `expanded,identified`, `everybody_loops`, \
`hir`, `hir,identified`, `hir,typed`, or `mir`; got {}",
`hir`, `hir,identified`, `hir,typed`, `hir-tree`, \
`mir` or `mir-cfg`; got {}",
name));
} else {
sess.fatal(&format!("argument to `pretty` must be one of `normal`, `expanded`, \
Expand Down
90 changes: 56 additions & 34 deletions src/librustc_errors/diagnostic_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ pub struct DiagnosticBuilder<'a> {
/// it easy to declare such methods on the builder.
macro_rules! forward {
// Forward pattern for &self -> &Self
(pub fn $n:ident(&self, $($name:ident: $ty:ty),* $(,)*) -> &Self) => {
(
$(#[$attrs:meta])*
pub fn $n:ident(&self, $($name:ident: $ty:ty),* $(,)*) -> &Self
) => {
$(#[$attrs])*
pub fn $n(&self, $($name: $ty),*) -> &Self {
#[allow(deprecated)]
self.diagnostic.$n($($name),*);
Expand All @@ -42,7 +46,11 @@ macro_rules! forward {
};

// Forward pattern for &mut self -> &mut Self
(pub fn $n:ident(&mut self, $($name:ident: $ty:ty),* $(,)*) -> &mut Self) => {
(
$(#[$attrs:meta])*
pub fn $n:ident(&mut self, $($name:ident: $ty:ty),* $(,)*) -> &mut Self
) => {
$(#[$attrs])*
pub fn $n(&mut self, $($name: $ty),*) -> &mut Self {
#[allow(deprecated)]
self.diagnostic.$n($($name),*);
Expand All @@ -52,10 +60,15 @@ macro_rules! forward {

// Forward pattern for &mut self -> &mut Self, with S: Into<MultiSpan>
// type parameter. No obvious way to make this more generic.
(pub fn $n:ident<S: Into<MultiSpan>>(
&mut self,
$($name:ident: $ty:ty),*
$(,)*) -> &mut Self) => {
(
$(#[$attrs:meta])*
pub fn $n:ident<S: Into<MultiSpan>>(
&mut self,
$($name:ident: $ty:ty),*
$(,)*
) -> &mut Self
) => {
$(#[$attrs])*
pub fn $n<S: Into<MultiSpan>>(&mut self, $($name: $ty),*) -> &mut Self {
#[allow(deprecated)]
self.diagnostic.$n($($name),*);
Expand Down Expand Up @@ -177,34 +190,43 @@ impl<'a> DiagnosticBuilder<'a> {
msg: &str,
) -> &mut Self);

#[deprecated(note = "Use `span_suggestion_short_with_applicability`")]
forward!(pub fn span_suggestion_short(
&mut self,
sp: Span,
msg: &str,
suggestion: String,
) -> &mut Self);

#[deprecated(note = "Use `multipart_suggestion_with_applicability`")]
forward!(pub fn multipart_suggestion(
&mut self,
msg: &str,
suggestion: Vec<(Span, String)>,
) -> &mut Self);

#[deprecated(note = "Use `span_suggestion_with_applicability`")]
forward!(pub fn span_suggestion(&mut self,
sp: Span,
msg: &str,
suggestion: String,
) -> &mut Self);

#[deprecated(note = "Use `span_suggestions_with_applicability`")]
forward!(pub fn span_suggestions(&mut self,
sp: Span,
msg: &str,
suggestions: Vec<String>,
) -> &mut Self);
forward!(
#[deprecated(note = "Use `span_suggestion_short_with_applicability`")]
pub fn span_suggestion_short(
&mut self,
sp: Span,
msg: &str,
suggestion: String,
) -> &mut Self
);

forward!(
#[deprecated(note = "Use `multipart_suggestion_with_applicability`")]
pub fn multipart_suggestion(
&mut self,
msg: &str,
suggestion: Vec<(Span, String)>,
) -> &mut Self
);

forward!(
#[deprecated(note = "Use `span_suggestion_with_applicability`")]
pub fn span_suggestion(
&mut self,
sp: Span,
msg: &str,
suggestion: String,
) -> &mut Self
);

forward!(
#[deprecated(note = "Use `span_suggestions_with_applicability`")]
pub fn span_suggestions(&mut self,
sp: Span,
msg: &str,
suggestions: Vec<String>,
) -> &mut Self
);

pub fn multipart_suggestion_with_applicability(&mut self,
msg: &str,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1474,7 +1474,7 @@ impl KeywordIdents {
_ => {},
}
TokenTree::Delimited(_, _, tts) => {
self.check_tokens(cx, tts.stream())
self.check_tokens(cx, tts)
},
}
}
Expand Down
Loading

0 comments on commit 9323499

Please sign in to comment.