Skip to content

Commit a71d557

Browse files
author
Alexander Regueiro
committed
Addressed points raised in review.
1 parent 4310ba2 commit a71d557

File tree

53 files changed

+793
-319
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+793
-319
lines changed

src/librustc/hir/lowering.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,12 +1382,12 @@ impl<'a> LoweringContext<'a> {
13821382
if existential_desugaring {
13831383
// Desugar `AssocTy: Bounds` into `AssocTy = impl Bounds`.
13841384

1385-
let impl_ty_node_id = self.sess.next_node_id();
1385+
let impl_trait_node_id = self.sess.next_node_id();
13861386
let parent_def_index = self.current_hir_id_owner.last().unwrap().0;
13871387
self.resolver.definitions().create_def_with_parent(
13881388
parent_def_index,
1389-
impl_ty_node_id,
1390-
DefPathData::Misc,
1389+
impl_trait_node_id,
1390+
DefPathData::ImplTrait,
13911391
DefIndexAddressSpace::High,
13921392
Mark::root(),
13931393
DUMMY_SP
@@ -1397,7 +1397,7 @@ impl<'a> LoweringContext<'a> {
13971397
this.lower_ty(
13981398
&Ty {
13991399
id: this.sess.next_node_id(),
1400-
node: TyKind::ImplTrait(impl_ty_node_id, bounds.clone()),
1400+
node: TyKind::ImplTrait(impl_trait_node_id, bounds.clone()),
14011401
span: DUMMY_SP,
14021402
},
14031403
itctx,
@@ -1410,9 +1410,8 @@ impl<'a> LoweringContext<'a> {
14101410
let bounds = self.lower_param_bounds(bounds, itctx);
14111411

14121412
let id = self.sess.next_node_id();
1413-
let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(id);
14141413
P(hir::Ty {
1415-
hir_id,
1414+
hir_id: self.lower_node_id(id),
14161415
node: hir::TyKind::AssocTyExistential(bounds),
14171416
span: DUMMY_SP,
14181417
})
@@ -1423,7 +1422,7 @@ impl<'a> LoweringContext<'a> {
14231422
hir::TypeBinding {
14241423
hir_id: self.lower_node_id(c.id),
14251424
ident: c.ident,
1426-
ty
1425+
ty,
14271426
span: c.span,
14281427
}
14291428
}
@@ -1647,7 +1646,7 @@ impl<'a> LoweringContext<'a> {
16471646
// Not tracking it makes lints in rustc and clippy very fragile, as
16481647
// frequently opened issues show.
16491648
let exist_ty_span = self.mark_span_with_reason(
1650-
CompilerDesugaringKind::ExistentialReturnType,
1649+
CompilerDesugaringKind::ExistentialType,
16511650
span,
16521651
None,
16531652
);

src/librustc/hir/map/definitions.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ pub enum DefPathData {
276276
// they are treated specially by the `def_path` function.
277277
/// The crate root (marker)
278278
CrateRoot,
279-
// Catch-all for random DefId things like DUMMY_NODE_ID
279+
// Catch-all for random DefId things like `DUMMY_NODE_ID`
280280
Misc,
281281
// Different kinds of items and item-like things:
282282
/// An impl
@@ -298,9 +298,9 @@ pub enum DefPathData {
298298
AnonConst,
299299
/// An `impl Trait` type node
300300
ImplTrait,
301-
/// GlobalMetaData identifies a piece of crate metadata that is global to
302-
/// a whole crate (as opposed to just one item). GlobalMetaData components
303-
/// are only supposed to show up right below the crate root.
301+
/// Identifies a piece of crate metadata that is global to a whole crate
302+
/// (as opposed to just one item). `GlobalMetaData` components are only
303+
/// supposed to show up right below the crate root.
304304
GlobalMetaData(InternedString),
305305
}
306306

src/librustc/hir/map/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ impl<'hir> Map<'hir> {
842842
}
843843

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

882882
/// Returns the defining scope for an existential type definition.
883-
pub fn get_defining_scope(&self, id: NodeId) -> Option<NodeId> {
883+
pub fn get_defining_scope(&self, id: HirId) -> Option<HirId> {
884884
let mut scope = id;
885885
loop {
886886
scope = self.get_enclosing_scope(scope)?;
887-
if scope == CRATE_NODE_ID {
888-
return Some(CRATE_NODE_ID);
887+
if scope == CRATE_HIR_ID {
888+
return Some(CRATE_HIR_ID);
889889
}
890-
match self.get(scope) {
890+
match self.get_by_hir_id(scope) {
891891
Node::Item(i) => {
892892
match i.node {
893893
ItemKind::Existential(ExistTy { impl_trait_fn: None, .. }) => {}

src/librustc/hir/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,7 +1780,7 @@ pub struct ImplItem {
17801780
pub span: Span,
17811781
}
17821782

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

1797-
// Bind a type to an associated type: `A=Foo`.
1797+
// Bind a type to an associated type (`A = Foo`).
17981798
#[derive(Clone, RustcEncodable, RustcDecodable, Debug, HashStable)]
17991799
pub struct TypeBinding {
18001800
pub hir_id: HirId,

src/librustc/ich/impls_syntax.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ impl_stable_hash_for!(enum ::syntax_pos::hygiene::CompilerDesugaringKind {
408408
Async,
409409
Await,
410410
QuestionMark,
411-
ExistentialReturnType,
411+
ExistentialType,
412412
ForLoop,
413413
TryBlock
414414
});

src/librustc/infer/opaque_types/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -953,14 +953,13 @@ pub fn may_define_existential_type(
953953
);
954954

955955
// Named existential types can be defined by any siblings or children of siblings.
956-
let scope_node_id = tcx.hir()
957-
.get_defining_scope(tcx.hir().hir_to_node_id(opaque_hir_id))
956+
let scope = tcx.hir()
957+
.get_defining_scope(opaque_hir_id)
958958
.expect("could not get defining scope");
959-
let scope_id = tcx.hir().node_to_hir_id(scope_node_id);
960959
// We walk up the node tree until we hit the root or the scope of the opaque type.
961-
while hir_id != scope_id && hir_id != hir::CRATE_HIR_ID {
960+
while hir_id != scope && hir_id != hir::CRATE_HIR_ID {
962961
hir_id = tcx.hir().get_parent_item(hir_id);
963962
}
964963
// Syntactically, we are allowed to define the concrete type if:
965-
hir_id == scope_id
964+
hir_id == scope
966965
}

src/librustc_interface/util.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -716,23 +716,14 @@ impl<'a> ReplaceBodyWithLoop<'a> {
716716
ast::GenericArg::Type(ty) => Some(ty),
717717
_ => None,
718718
});
719-
let any_assoc_ty_bounds = data.constraints.iter().any(|c| {
720-
if let ast::AssocTyConstraintKind::Bound { .. } = c.kind {
721-
true
722-
} else {
723-
false
724-
}
725-
});
726-
any_assoc_ty_bounds ||
727719
any_involves_impl_trait(types.into_iter()) ||
728-
any_involves_impl_trait(data.constraints.iter().filter_map(|c| {
729-
if let ast::AssocTyConstraintKind::Equality { ref ty }
730-
= c.kind {
731-
Some(ty)
732-
} else {
733-
None
720+
data.constraints.iter().any(|c| {
721+
match c.kind {
722+
ast::AssocTyConstraintKind::Bound { .. } => true,
723+
ast::AssocTyConstraintKind::Equality { ref ty } =>
724+
involves_impl_trait(ty),
734725
}
735-
}))
726+
})
736727
},
737728
Some(&ast::GenericArgs::Parenthesized(ref data)) => {
738729
any_involves_impl_trait(data.inputs.iter()) ||

src/librustc_resolve/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2533,7 +2533,7 @@ impl<'a> Resolver<'a> {
25332533
self.with_current_self_item(item, |this| {
25342534
this.with_generic_param_rib(HasGenericParams(generics, ItemRibKind), |this| {
25352535
let item_def_id = this.definitions.local_def_id(item.id);
2536-
this.with_self_rib(Def::SelfTy(Some(item_def_id), None), |this| {
2536+
this.with_self_rib(Res::SelfTy(Some(item_def_id), None), |this| {
25372537
visit::walk_item(this, item)
25382538
})
25392539
})

src/librustc_typeck/astconv.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
764764
let mut dup_bindings = FxHashMap::default();
765765
for binding in &assoc_bindings {
766766
// Specify type to assert that error was already reported in `Err` case.
767-
let _ =
767+
let _: Result<_, ErrorReported> =
768768
self.add_predicates_for_ast_type_binding(
769769
trait_ref.hir_ref_id,
770770
poly_trait_ref,
@@ -933,8 +933,8 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o {
933933
}
934934

935935
/// Translates the AST's notion of ty param bounds (which are an enum consisting of a newtyped
936-
/// `Ty` or a region) to ty's notion of ty param bounds, which can either be user-defined traits
937-
/// or the built-in trait `Send`.
936+
/// `Ty` or a region) to ty's notion of ty param bounds (which can either be user-defined traits
937+
/// or the built-in trait `Sized`).
938938
pub fn compute_bounds(&self,
939939
param_ty: Ty<'tcx>,
940940
ast_bounds: &[hir::GenericBound],

src/librustc_typeck/collect.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,24 +1650,23 @@ fn find_existential_constraints<'a, 'tcx>(
16501650
}
16511651
}
16521652

1653-
let node_id = tcx.hir().as_local_node_id(def_id).unwrap();
1654-
let scope_node_id = tcx.hir()
1655-
.get_defining_scope(node_id)
1653+
let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap();
1654+
let scope = tcx.hir()
1655+
.get_defining_scope(hir_id)
16561656
.expect("could not get defining scope");
1657-
let scope_id = tcx.hir().node_to_hir_id(scope_node_id);
16581657
let mut locator = ConstraintLocator {
16591658
def_id,
16601659
tcx,
16611660
found: None,
16621661
};
16631662

1664-
debug!("find_existential_constraints: scope_id={:?}", scope_id);
1663+
debug!("find_existential_constraints: scope={:?}", scope);
16651664

1666-
if scope_id == hir::CRATE_HIR_ID {
1665+
if scope == hir::CRATE_HIR_ID {
16671666
intravisit::walk_crate(&mut locator, tcx.hir().krate());
16681667
} else {
1669-
debug!("find_existential_constraints: scope={:?}", tcx.hir().get_by_hir_id(scope_id));
1670-
match tcx.hir().get_by_hir_id(scope_id) {
1668+
debug!("find_existential_constraints: scope={:?}", tcx.hir().get_by_hir_id(scope));
1669+
match tcx.hir().get_by_hir_id(scope) {
16711670
Node::Item(ref it) => intravisit::walk_item(&mut locator, it),
16721671
Node::ImplItem(ref it) => intravisit::walk_impl_item(&mut locator, it),
16731672
Node::TraitItem(ref it) => intravisit::walk_trait_item(&mut locator, it),

src/librustdoc/clean/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2445,7 +2445,7 @@ pub struct PolyTrait {
24452445

24462446
/// A representation of a type suitable for hyperlinking purposes. Ideally, one can get the original
24472447
/// type out of the AST/`TyCtxt` given one of these, if more information is needed. Most
2448-
/// importanntly, it does not preserve mutability or boxes.
2448+
/// importantly, it does not preserve mutability or boxes.
24492449
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)]
24502450
pub enum Type {
24512451
/// Structs/enums/traits (most that would be an `hir::TyKind::Path`).

src/libsyntax_pos/hygiene.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ pub enum CompilerDesugaringKind {
714714
/// Desugaring of an `impl Trait` in return type position
715715
/// to an `existential type Foo: Trait;` and replacing the
716716
/// `impl Trait` with `Foo`.
717-
ExistentialReturnType,
717+
ExistentialType,
718718
Async,
719719
Await,
720720
ForLoop,
@@ -728,7 +728,7 @@ impl CompilerDesugaringKind {
728728
CompilerDesugaringKind::Await => "await",
729729
CompilerDesugaringKind::QuestionMark => "?",
730730
CompilerDesugaringKind::TryBlock => "try block",
731-
CompilerDesugaringKind::ExistentialReturnType => "existential type",
731+
CompilerDesugaringKind::ExistentialType => "existential type",
732732
CompilerDesugaringKind::ForLoop => "for loop",
733733
})
734734
}

src/test/ui/associated-type-bounds/nested-lifetime-bounds.stderr

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@ LL | for<'a> <_2 as Iterator>::Item: for<'b> Lam<&'a &'b u8, App = _0>,
66

77
error: aborting due to previous error
88

9-
For more information about this error, try `rustc --explain E0316`.

src/test/ui/associated-types/associated-types-path-2.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ error[E0308]: mismatched types
4949
|
5050
LL | let _: i32 = f2(2i32);
5151
| ^^^^^^^^ expected i32, found u32
52-
help: you can convert an `u32` to `i32` and panic if the converted value wouldn't fit
52+
help: you can convert an `u32` to `i32` or panic if it the converted value wouldn't fit
5353
|
5454
LL | let _: i32 = f2(2i32).try_into().unwrap();
5555
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)