Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2c74903

Browse files
committedMar 17, 2021
Auto merge of #83225 - JohnTitor:rollup-4hnuhb8, r=JohnTitor
Rollup of 8 pull requests Successful merges: - #82774 (Fix bad diagnostics for anon params with ref and/or qualified paths) - #82826 ((std::net::parser): Fix capitalization of IP version names) - #83092 (More precise spans for HIR paths) - #83124 (Do not insert impl_trait_in_bindings opaque definitions twice.) - #83202 (Show details in cfg version unstable book) - #83203 (Don't warn about old rustdoc lint names (temporarily)) - #83206 (Update books) - #83219 (Update cargo) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 0c34122 + 95bbcdb commit 2c74903

Some content is hidden

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

51 files changed

+353
-227
lines changed
 

‎compiler/rustc_ast/src/ast.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,17 @@ impl PathSegment {
149149
pub fn from_ident(ident: Ident) -> Self {
150150
PathSegment { ident, id: DUMMY_NODE_ID, args: None }
151151
}
152+
152153
pub fn path_root(span: Span) -> Self {
153154
PathSegment::from_ident(Ident::new(kw::PathRoot, span))
154155
}
156+
157+
pub fn span(&self) -> Span {
158+
match &self.args {
159+
Some(args) => self.ident.span.to(args.span()),
160+
None => self.ident.span,
161+
}
162+
}
155163
}
156164

157165
/// The arguments of a path segment.

‎compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 15 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -438,31 +438,6 @@ impl<'a> TokenStreamLowering<'a> {
438438
}
439439
}
440440

441-
struct ImplTraitTypeIdVisitor<'a> {
442-
ids: &'a mut SmallVec<[NodeId; 1]>,
443-
}
444-
445-
impl Visitor<'_> for ImplTraitTypeIdVisitor<'_> {
446-
fn visit_ty(&mut self, ty: &Ty) {
447-
match ty.kind {
448-
TyKind::Typeof(_) | TyKind::BareFn(_) => return,
449-
450-
TyKind::ImplTrait(id, _) => self.ids.push(id),
451-
_ => {}
452-
}
453-
visit::walk_ty(self, ty);
454-
}
455-
456-
fn visit_path_segment(&mut self, path_span: Span, path_segment: &PathSegment) {
457-
if let Some(ref p) = path_segment.args {
458-
if let GenericArgs::Parenthesized(_) = **p {
459-
return;
460-
}
461-
}
462-
visit::walk_path_segment(self, path_span, path_segment)
463-
}
464-
}
465-
466441
impl<'a, 'hir> LoweringContext<'a, 'hir> {
467442
fn lower_crate(mut self, c: &Crate) -> hir::Crate<'hir> {
468443
/// Full-crate AST visitor that inserts into a fresh
@@ -1789,14 +1764,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
17891764
)
17901765
}
17911766

1792-
fn lower_local(&mut self, l: &Local) -> (hir::Local<'hir>, SmallVec<[NodeId; 1]>) {
1793-
let mut ids = SmallVec::<[NodeId; 1]>::new();
1794-
if self.sess.features_untracked().impl_trait_in_bindings {
1795-
if let Some(ref ty) = l.ty {
1796-
let mut visitor = ImplTraitTypeIdVisitor { ids: &mut ids };
1797-
visitor.visit_ty(ty);
1798-
}
1799-
}
1767+
fn lower_local(&mut self, l: &Local) -> hir::Local<'hir> {
18001768
let ty = l.ty.as_ref().map(|t| {
18011769
let mut capturable_lifetimes;
18021770
self.lower_ty(
@@ -1815,17 +1783,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
18151783
let init = l.init.as_ref().map(|e| self.lower_expr(e));
18161784
let hir_id = self.lower_node_id(l.id);
18171785
self.lower_attrs(hir_id, &l.attrs);
1818-
(
1819-
hir::Local {
1820-
hir_id,
1821-
ty,
1822-
pat: self.lower_pat(&l.pat),
1823-
init,
1824-
span: l.span,
1825-
source: hir::LocalSource::Normal,
1826-
},
1827-
ids,
1828-
)
1786+
hir::Local {
1787+
hir_id,
1788+
ty,
1789+
pat: self.lower_pat(&l.pat),
1790+
init,
1791+
span: l.span,
1792+
source: hir::LocalSource::Normal,
1793+
}
18291794
}
18301795

18311796
fn lower_fn_params_to_names(&mut self, decl: &FnDecl) -> &'hir [Ident] {
@@ -2445,27 +2410,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
24452410
fn lower_stmt(&mut self, s: &Stmt) -> SmallVec<[hir::Stmt<'hir>; 1]> {
24462411
let (hir_id, kind) = match s.kind {
24472412
StmtKind::Local(ref l) => {
2448-
let (l, item_ids) = self.lower_local(l);
2449-
let mut ids: SmallVec<[hir::Stmt<'hir>; 1]> = item_ids
2450-
.into_iter()
2451-
.map(|item_id| {
2452-
let item_id = hir::ItemId {
2453-
// All the items that `lower_local` finds are `impl Trait` types.
2454-
def_id: self.lower_node_id(item_id).expect_owner(),
2455-
};
2456-
self.stmt(s.span, hir::StmtKind::Item(item_id))
2457-
})
2458-
.collect();
2413+
let l = self.lower_local(l);
24592414
let hir_id = self.lower_node_id(s.id);
24602415
self.alias_attrs(hir_id, l.hir_id);
2461-
ids.push({
2462-
hir::Stmt {
2463-
hir_id,
2464-
kind: hir::StmtKind::Local(self.arena.alloc(l)),
2465-
span: s.span,
2466-
}
2467-
});
2468-
return ids;
2416+
return smallvec![hir::Stmt {
2417+
hir_id,
2418+
kind: hir::StmtKind::Local(self.arena.alloc(l)),
2419+
span: s.span,
2420+
}];
24692421
}
24702422
StmtKind::Item(ref it) => {
24712423
// Can only use the ID once.

0 commit comments

Comments
 (0)
Please sign in to comment.