Skip to content

Commit

Permalink
Addressed points raised in review.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Regueiro committed Jun 5, 2019
1 parent 4310ba2 commit a71d557
Show file tree
Hide file tree
Showing 53 changed files with 793 additions and 319 deletions.
15 changes: 7 additions & 8 deletions src/librustc/hir/lowering.rs
Expand Up @@ -1382,12 +1382,12 @@ impl<'a> LoweringContext<'a> {
if existential_desugaring {
// Desugar `AssocTy: Bounds` into `AssocTy = impl Bounds`.

let impl_ty_node_id = self.sess.next_node_id();
let impl_trait_node_id = self.sess.next_node_id();
let parent_def_index = self.current_hir_id_owner.last().unwrap().0;
self.resolver.definitions().create_def_with_parent(
parent_def_index,
impl_ty_node_id,
DefPathData::Misc,
impl_trait_node_id,
DefPathData::ImplTrait,
DefIndexAddressSpace::High,
Mark::root(),
DUMMY_SP
Expand All @@ -1397,7 +1397,7 @@ impl<'a> LoweringContext<'a> {
this.lower_ty(
&Ty {
id: this.sess.next_node_id(),
node: TyKind::ImplTrait(impl_ty_node_id, bounds.clone()),
node: TyKind::ImplTrait(impl_trait_node_id, bounds.clone()),
span: DUMMY_SP,
},
itctx,
Expand All @@ -1410,9 +1410,8 @@ impl<'a> LoweringContext<'a> {
let bounds = self.lower_param_bounds(bounds, itctx);

let id = self.sess.next_node_id();
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(id);
P(hir::Ty {
hir_id,
hir_id: self.lower_node_id(id),
node: hir::TyKind::AssocTyExistential(bounds),
span: DUMMY_SP,
})
Expand All @@ -1423,7 +1422,7 @@ impl<'a> LoweringContext<'a> {
hir::TypeBinding {
hir_id: self.lower_node_id(c.id),
ident: c.ident,
ty
ty,
span: c.span,
}
}
Expand Down Expand Up @@ -1647,7 +1646,7 @@ impl<'a> LoweringContext<'a> {
// Not tracking it makes lints in rustc and clippy very fragile, as
// frequently opened issues show.
let exist_ty_span = self.mark_span_with_reason(
CompilerDesugaringKind::ExistentialReturnType,
CompilerDesugaringKind::ExistentialType,
span,
None,
);
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/hir/map/definitions.rs
Expand Up @@ -276,7 +276,7 @@ pub enum DefPathData {
// they are treated specially by the `def_path` function.
/// The crate root (marker)
CrateRoot,
// Catch-all for random DefId things like DUMMY_NODE_ID
// Catch-all for random DefId things like `DUMMY_NODE_ID`
Misc,
// Different kinds of items and item-like things:
/// An impl
Expand All @@ -298,9 +298,9 @@ pub enum DefPathData {
AnonConst,
/// An `impl Trait` type node
ImplTrait,
/// 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.
/// 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),
}

Expand Down
10 changes: 5 additions & 5 deletions src/librustc/hir/map/mod.rs
Expand Up @@ -842,7 +842,7 @@ impl<'hir> Map<'hir> {
}

/// Returns the nearest enclosing scope. A scope is roughly an item or block.
pub fn get_enclosing_scope(&self, id: HirId) -> Option<HirId> {
pub fn get_enclosing_scope(&self, hir_id: HirId) -> Option<HirId> {
self.walk_parent_nodes(hir_id, |node| match *node {
Node::Item(i) => {
match i.node {
Expand Down Expand Up @@ -880,14 +880,14 @@ impl<'hir> Map<'hir> {
}

/// Returns the defining scope for an existential type definition.
pub fn get_defining_scope(&self, id: NodeId) -> Option<NodeId> {
pub fn get_defining_scope(&self, id: HirId) -> Option<HirId> {
let mut scope = id;
loop {
scope = self.get_enclosing_scope(scope)?;
if scope == CRATE_NODE_ID {
return Some(CRATE_NODE_ID);
if scope == CRATE_HIR_ID {
return Some(CRATE_HIR_ID);
}
match self.get(scope) {
match self.get_by_hir_id(scope) {
Node::Item(i) => {
match i.node {
ItemKind::Existential(ExistTy { impl_trait_fn: None, .. }) => {}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/hir/mod.rs
Expand Up @@ -1780,7 +1780,7 @@ pub struct ImplItem {
pub span: Span,
}

/// Represents different contents within `impl`s
/// Represents different contents within `impl`s.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable)]
pub enum ImplItemKind {
/// An associated constant of the given type, set to the constant result
Expand All @@ -1794,7 +1794,7 @@ pub enum ImplItemKind {
Existential(GenericBounds),
}

// Bind a type to an associated type: `A=Foo`.
// Bind a type to an associated type (`A = Foo`).
#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable)]
pub struct TypeBinding {
pub hir_id: HirId,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ich/impls_syntax.rs
Expand Up @@ -408,7 +408,7 @@ impl_stable_hash_for!(enum ::syntax_pos::hygiene::CompilerDesugaringKind {
Async,
Await,
QuestionMark,
ExistentialReturnType,
ExistentialType,
ForLoop,
TryBlock
});
Expand Down
9 changes: 4 additions & 5 deletions src/librustc/infer/opaque_types/mod.rs
Expand Up @@ -953,14 +953,13 @@ pub fn may_define_existential_type(
);

// Named existential types can be defined by any siblings or children of siblings.
let scope_node_id = tcx.hir()
.get_defining_scope(tcx.hir().hir_to_node_id(opaque_hir_id))
let scope = tcx.hir()
.get_defining_scope(opaque_hir_id)
.expect("could not get defining scope");
let scope_id = tcx.hir().node_to_hir_id(scope_node_id);
// We walk up the node tree until we hit the root or the scope of the opaque type.
while hir_id != scope_id && hir_id != hir::CRATE_HIR_ID {
while hir_id != scope && hir_id != hir::CRATE_HIR_ID {
hir_id = tcx.hir().get_parent_item(hir_id);
}
// Syntactically, we are allowed to define the concrete type if:
hir_id == scope_id
hir_id == scope
}
21 changes: 6 additions & 15 deletions src/librustc_interface/util.rs
Expand Up @@ -716,23 +716,14 @@ impl<'a> ReplaceBodyWithLoop<'a> {
ast::GenericArg::Type(ty) => Some(ty),
_ => None,
});
let any_assoc_ty_bounds = data.constraints.iter().any(|c| {
if let ast::AssocTyConstraintKind::Bound { .. } = c.kind {
true
} else {
false
}
});
any_assoc_ty_bounds ||
any_involves_impl_trait(types.into_iter()) ||
any_involves_impl_trait(data.constraints.iter().filter_map(|c| {
if let ast::AssocTyConstraintKind::Equality { ref ty }
= c.kind {
Some(ty)
} else {
None
data.constraints.iter().any(|c| {
match c.kind {
ast::AssocTyConstraintKind::Bound { .. } => true,
ast::AssocTyConstraintKind::Equality { ref ty } =>
involves_impl_trait(ty),
}
}))
})
},
Some(&ast::GenericArgs::Parenthesized(ref data)) => {
any_involves_impl_trait(data.inputs.iter()) ||
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/lib.rs
Expand Up @@ -2533,7 +2533,7 @@ impl<'a> Resolver<'a> {
self.with_current_self_item(item, |this| {
this.with_generic_param_rib(HasGenericParams(generics, ItemRibKind), |this| {
let item_def_id = this.definitions.local_def_id(item.id);
this.with_self_rib(Def::SelfTy(Some(item_def_id), None), |this| {
this.with_self_rib(Res::SelfTy(Some(item_def_id), None), |this| {
visit::walk_item(this, item)
})
})
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_typeck/astconv.rs
Expand Up @@ -764,7 +764,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
let mut dup_bindings = FxHashMap::default();
for binding in &assoc_bindings {
// Specify type to assert that error was already reported in `Err` case.
let _ =
let _: Result<_, ErrorReported> =
self.add_predicates_for_ast_type_binding(
trait_ref.hir_ref_id,
poly_trait_ref,
Expand Down Expand Up @@ -933,8 +933,8 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
}

/// Translates the AST's notion of ty param bounds (which are an enum consisting of a newtyped
/// `Ty` or a region) to ty's notion of ty param bounds, which can either be user-defined traits
/// or the built-in trait `Send`.
/// `Ty` or a region) to ty's notion of ty param bounds (which can either be user-defined traits
/// or the built-in trait `Sized`).
pub fn compute_bounds(&self,
param_ty: Ty<'tcx>,
ast_bounds: &[hir::GenericBound],
Expand Down
15 changes: 7 additions & 8 deletions src/librustc_typeck/collect.rs
Expand Up @@ -1650,24 +1650,23 @@ fn find_existential_constraints<'a, 'tcx>(
}
}

let node_id = tcx.hir().as_local_node_id(def_id).unwrap();
let scope_node_id = tcx.hir()
.get_defining_scope(node_id)
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
let scope = tcx.hir()
.get_defining_scope(hir_id)
.expect("could not get defining scope");
let scope_id = tcx.hir().node_to_hir_id(scope_node_id);
let mut locator = ConstraintLocator {
def_id,
tcx,
found: None,
};

debug!("find_existential_constraints: scope_id={:?}", scope_id);
debug!("find_existential_constraints: scope={:?}", scope);

if scope_id == hir::CRATE_HIR_ID {
if scope == hir::CRATE_HIR_ID {
intravisit::walk_crate(&mut locator, tcx.hir().krate());
} else {
debug!("find_existential_constraints: scope={:?}", tcx.hir().get_by_hir_id(scope_id));
match tcx.hir().get_by_hir_id(scope_id) {
debug!("find_existential_constraints: scope={:?}", tcx.hir().get_by_hir_id(scope));
match tcx.hir().get_by_hir_id(scope) {
Node::Item(ref it) => intravisit::walk_item(&mut locator, it),
Node::ImplItem(ref it) => intravisit::walk_impl_item(&mut locator, it),
Node::TraitItem(ref it) => intravisit::walk_trait_item(&mut locator, it),
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/mod.rs
Expand Up @@ -2445,7 +2445,7 @@ pub struct PolyTrait {

/// A representation of a type suitable for hyperlinking purposes. Ideally, one can get the original
/// type out of the AST/`TyCtxt` given one of these, if more information is needed. Most
/// importanntly, it does not preserve mutability or boxes.
/// importantly, it does not preserve mutability or boxes.
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)]
pub enum Type {
/// Structs/enums/traits (most that would be an `hir::TyKind::Path`).
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax_pos/hygiene.rs
Expand Up @@ -714,7 +714,7 @@ pub enum CompilerDesugaringKind {
/// Desugaring of an `impl Trait` in return type position
/// to an `existential type Foo: Trait;` and replacing the
/// `impl Trait` with `Foo`.
ExistentialReturnType,
ExistentialType,
Async,
Await,
ForLoop,
Expand All @@ -728,7 +728,7 @@ impl CompilerDesugaringKind {
CompilerDesugaringKind::Await => "await",
CompilerDesugaringKind::QuestionMark => "?",
CompilerDesugaringKind::TryBlock => "try block",
CompilerDesugaringKind::ExistentialReturnType => "existential type",
CompilerDesugaringKind::ExistentialType => "existential type",
CompilerDesugaringKind::ForLoop => "for loop",
})
}
Expand Down
Expand Up @@ -6,4 +6,3 @@ LL | for<'a> <_2 as Iterator>::Item: for<'b> Lam<&'a &'b u8, App = _0>,

error: aborting due to previous error

For more information about this error, try `rustc --explain E0316`.
Expand Up @@ -49,7 +49,7 @@ error[E0308]: mismatched types
|
LL | let _: i32 = f2(2i32);
| ^^^^^^^^ expected i32, found u32
help: you can convert an `u32` to `i32` and panic if the converted value wouldn't fit
help: you can convert an `u32` to `i32` or panic if it the converted value wouldn't fit
|
LL | let _: i32 = f2(2i32).try_into().unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down

0 comments on commit a71d557

Please sign in to comment.