1
Fork 0

rustc_ast_lowering: Stop lowering imports into multiple items

Lower them into a single item with multiple resolutions instead.
This also allows to remove additional `NodId`s and `DefId`s related to those additional items.
This commit is contained in:
Vadim Petrochenkov 2022-12-01 18:51:20 +03:00
parent 1f259ae679
commit b32a4edb20
25 changed files with 79 additions and 198 deletions

View file

@ -2517,10 +2517,7 @@ pub struct Variant {
#[derive(Clone, Encodable, Decodable, Debug)] #[derive(Clone, Encodable, Decodable, Debug)]
pub enum UseTreeKind { pub enum UseTreeKind {
/// `use prefix` or `use prefix as rename` /// `use prefix` or `use prefix as rename`
/// Simple(Option<Ident>),
/// The extra `NodeId`s are for HIR lowering, when additional statements are created for each
/// namespace.
Simple(Option<Ident>, NodeId, NodeId),
/// `use prefix::{...}` /// `use prefix::{...}`
Nested(Vec<(UseTree, NodeId)>), Nested(Vec<(UseTree, NodeId)>),
/// `use prefix::*` /// `use prefix::*`
@ -2539,8 +2536,8 @@ pub struct UseTree {
impl UseTree { impl UseTree {
pub fn ident(&self) -> Ident { pub fn ident(&self) -> Ident {
match self.kind { match self.kind {
UseTreeKind::Simple(Some(rename), ..) => rename, UseTreeKind::Simple(Some(rename)) => rename,
UseTreeKind::Simple(None, ..) => { UseTreeKind::Simple(None) => {
self.prefix.segments.last().expect("empty prefix in a simple import").ident self.prefix.segments.last().expect("empty prefix in a simple import").ident
} }
_ => panic!("`UseTree::ident` can only be used on a simple import"), _ => panic!("`UseTree::ident` can only be used on a simple import"),

View file

@ -410,11 +410,7 @@ pub fn noop_visit_use_tree<T: MutVisitor>(use_tree: &mut UseTree, vis: &mut T) {
let UseTree { prefix, kind, span } = use_tree; let UseTree { prefix, kind, span } = use_tree;
vis.visit_path(prefix); vis.visit_path(prefix);
match kind { match kind {
UseTreeKind::Simple(rename, id1, id2) => { UseTreeKind::Simple(rename) => visit_opt(rename, |rename| vis.visit_ident(rename)),
visit_opt(rename, |rename| vis.visit_ident(rename));
vis.visit_id(id1);
vis.visit_id(id2);
}
UseTreeKind::Nested(items) => { UseTreeKind::Nested(items) => {
for (tree, id) in items { for (tree, id) in items {
vis.visit_use_tree(tree); vis.visit_use_tree(tree);

View file

@ -439,7 +439,7 @@ pub fn walk_path<'a, V: Visitor<'a>>(visitor: &mut V, path: &'a Path) {
pub fn walk_use_tree<'a, V: Visitor<'a>>(visitor: &mut V, use_tree: &'a UseTree, id: NodeId) { pub fn walk_use_tree<'a, V: Visitor<'a>>(visitor: &mut V, use_tree: &'a UseTree, id: NodeId) {
visitor.visit_path(&use_tree.prefix, id); visitor.visit_path(&use_tree.prefix, id);
match &use_tree.kind { match &use_tree.kind {
UseTreeKind::Simple(rename, ..) => { UseTreeKind::Simple(rename) => {
// The extra IDs are handled during HIR lowering. // The extra IDs are handled during HIR lowering.
if let &Some(rename) = rename { if let &Some(rename) = rename {
visitor.visit_ident(rename); visitor.visit_ident(rename);

View file

@ -19,7 +19,6 @@ use rustc_span::symbol::{kw, sym, Ident};
use rustc_span::{Span, Symbol}; use rustc_span::{Span, Symbol};
use rustc_target::spec::abi; use rustc_target::spec::abi;
use smallvec::{smallvec, SmallVec}; use smallvec::{smallvec, SmallVec};
use std::iter;
use thin_vec::ThinVec; use thin_vec::ThinVec;
pub(super) struct ItemLowerer<'a, 'hir> { pub(super) struct ItemLowerer<'a, 'hir> {
@ -179,36 +178,22 @@ impl<'hir> LoweringContext<'_, 'hir> {
let mut node_ids = let mut node_ids =
smallvec![hir::ItemId { owner_id: hir::OwnerId { def_id: self.local_def_id(i.id) } }]; smallvec![hir::ItemId { owner_id: hir::OwnerId { def_id: self.local_def_id(i.id) } }];
if let ItemKind::Use(use_tree) = &i.kind { if let ItemKind::Use(use_tree) = &i.kind {
self.lower_item_id_use_tree(use_tree, i.id, &mut node_ids); self.lower_item_id_use_tree(use_tree, &mut node_ids);
} }
node_ids node_ids
} }
fn lower_item_id_use_tree( fn lower_item_id_use_tree(&mut self, tree: &UseTree, vec: &mut SmallVec<[hir::ItemId; 1]>) {
&mut self,
tree: &UseTree,
base_id: NodeId,
vec: &mut SmallVec<[hir::ItemId; 1]>,
) {
match &tree.kind { match &tree.kind {
UseTreeKind::Nested(nested_vec) => { UseTreeKind::Nested(nested_vec) => {
for &(ref nested, id) in nested_vec { for &(ref nested, id) in nested_vec {
vec.push(hir::ItemId { vec.push(hir::ItemId {
owner_id: hir::OwnerId { def_id: self.local_def_id(id) }, owner_id: hir::OwnerId { def_id: self.local_def_id(id) },
}); });
self.lower_item_id_use_tree(nested, id, vec); self.lower_item_id_use_tree(nested, vec);
}
}
UseTreeKind::Glob => {}
UseTreeKind::Simple(_, id1, id2) => {
for (_, id) in
iter::zip(self.expect_full_res_from_use(base_id).skip(1), [*id1, *id2])
{
vec.push(hir::ItemId {
owner_id: hir::OwnerId { def_id: self.local_def_id(id) },
});
} }
} }
UseTreeKind::Simple(..) | UseTreeKind::Glob => {}
} }
} }
@ -489,7 +474,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let segments = prefix.segments.iter().chain(path.segments.iter()).cloned().collect(); let segments = prefix.segments.iter().chain(path.segments.iter()).cloned().collect();
match tree.kind { match tree.kind {
UseTreeKind::Simple(rename, id1, id2) => { UseTreeKind::Simple(rename) => {
*ident = tree.ident(); *ident = tree.ident();
// First, apply the prefix to the path. // First, apply the prefix to the path.
@ -505,58 +490,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
} }
} }
let mut resolutions = self.expect_full_res_from_use(id).fuse(); let res =
// We want to return *something* from this function, so hold onto the first item self.expect_full_res_from_use(id).map(|res| self.lower_res(res)).collect();
// for later. let path = self.lower_use_path(res, &path, ParamMode::Explicit);
let ret_res = smallvec![self.lower_res(resolutions.next().unwrap_or(Res::Err))];
// Here, we are looping over namespaces, if they exist for the definition
// being imported. We only handle type and value namespaces because we
// won't be dealing with macros in the rest of the compiler.
// Essentially a single `use` which imports two names is desugared into
// two imports.
for new_node_id in [id1, id2] {
let new_id = self.local_def_id(new_node_id);
let Some(res) = resolutions.next() else {
debug_assert!(self.children.iter().find(|(id, _)| id == &new_id).is_none());
// Associate an HirId to both ids even if there is no resolution.
self.children.push((
new_id,
hir::MaybeOwner::NonOwner(hir::HirId::make_owner(new_id))),
);
continue;
};
let ident = *ident;
let mut path = path.clone();
for seg in &mut path.segments {
// Give the cloned segment the same resolution information
// as the old one (this is needed for stability checking).
let new_id = self.next_node_id();
self.resolver.clone_res(seg.id, new_id);
seg.id = new_id;
}
let span = path.span;
self.with_hir_id_owner(new_node_id, |this| {
let res = smallvec![this.lower_res(res)];
let path = this.lower_use_path(res, &path, ParamMode::Explicit);
let kind = hir::ItemKind::Use(path, hir::UseKind::Single);
if let Some(attrs) = attrs {
this.attrs.insert(hir::ItemLocalId::new(0), attrs);
}
let item = hir::Item {
owner_id: hir::OwnerId { def_id: new_id },
ident: this.lower_ident(ident),
kind,
vis_span,
span: this.lower_span(span),
};
hir::OwnerNode::Item(this.arena.alloc(item))
});
}
let path = self.lower_use_path(ret_res, &path, ParamMode::Explicit);
hir::ItemKind::Use(path, hir::UseKind::Single) hir::ItemKind::Use(path, hir::UseKind::Single)
} }
UseTreeKind::Glob => { UseTreeKind::Glob => {
@ -633,8 +569,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
}); });
} }
let res = self.expect_full_res_from_use(id).next().unwrap_or(Res::Err); let res =
let res = smallvec![self.lower_res(res)]; self.expect_full_res_from_use(id).map(|res| self.lower_res(res)).collect();
let path = self.lower_use_path(res, &prefix, ParamMode::Explicit); let path = self.lower_use_path(res, &prefix, ParamMode::Explicit);
hir::ItemKind::Use(path, hir::UseKind::ListStem) hir::ItemKind::Use(path, hir::UseKind::ListStem)
} }

View file

@ -663,7 +663,7 @@ impl<'a> State<'a> {
fn print_use_tree(&mut self, tree: &ast::UseTree) { fn print_use_tree(&mut self, tree: &ast::UseTree) {
match &tree.kind { match &tree.kind {
ast::UseTreeKind::Simple(rename, ..) => { ast::UseTreeKind::Simple(rename) => {
self.print_path(&tree.prefix, false, 0); self.print_path(&tree.prefix, false, 0);
if let &Some(rename) = rename { if let &Some(rename) = rename {
self.nbsp(); self.nbsp();

View file

@ -106,7 +106,7 @@ impl<'cx, 'a> Context<'cx, 'a> {
( (
UseTree { UseTree {
prefix: this.cx.path(this.span, vec![Ident::with_dummy_span(sym)]), prefix: this.cx.path(this.span, vec![Ident::with_dummy_span(sym)]),
kind: UseTreeKind::Simple(None, DUMMY_NODE_ID, DUMMY_NODE_ID), kind: UseTreeKind::Simple(None),
span: this.span, span: this.span,
}, },
DUMMY_NODE_ID, DUMMY_NODE_ID,

View file

@ -1264,7 +1264,7 @@ impl UnusedImportBraces {
// Trigger the lint if the nested item is a non-self single item // Trigger the lint if the nested item is a non-self single item
let node_name = match items[0].0.kind { let node_name = match items[0].0.kind {
ast::UseTreeKind::Simple(rename, ..) => { ast::UseTreeKind::Simple(rename) => {
let orig_ident = items[0].0.prefix.segments.last().unwrap().ident; let orig_ident = items[0].0.prefix.segments.last().unwrap().ident;
if orig_ident.name == kw::SelfLower { if orig_ident.name == kw::SelfLower {
return; return;

View file

@ -1012,7 +1012,7 @@ impl<'a> Parser<'a> {
prefix.span = lo.to(self.prev_token.span); prefix.span = lo.to(self.prev_token.span);
} }
UseTreeKind::Simple(self.parse_rename()?, DUMMY_NODE_ID, DUMMY_NODE_ID) UseTreeKind::Simple(self.parse_rename()?)
} }
}; };

View file

@ -445,19 +445,13 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
prefix.is_empty() || prefix.len() == 1 && prefix[0].ident.name == kw::PathRoot prefix.is_empty() || prefix.len() == 1 && prefix[0].ident.name == kw::PathRoot
}; };
match use_tree.kind { match use_tree.kind {
ast::UseTreeKind::Simple(rename, id1, id2) => { ast::UseTreeKind::Simple(rename) => {
let mut ident = use_tree.ident(); let mut ident = use_tree.ident();
let mut module_path = prefix; let mut module_path = prefix;
let mut source = module_path.pop().unwrap(); let mut source = module_path.pop().unwrap();
let mut type_ns_only = false; let mut type_ns_only = false;
self.r.visibilities.insert(self.r.local_def_id(id), vis); self.r.visibilities.insert(self.r.local_def_id(id), vis);
if id1 != ast::DUMMY_NODE_ID {
self.r.visibilities.insert(self.r.local_def_id(id1), vis);
}
if id2 != ast::DUMMY_NODE_ID {
self.r.visibilities.insert(self.r.local_def_id(id2), vis);
}
if nested { if nested {
// Correctly handle `self` // Correctly handle `self`
@ -565,7 +559,6 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
type_ns_only, type_ns_only,
nested, nested,
id, id,
additional_ids: (id1, id2),
}; };
self.add_import(module_path, kind, use_tree.span, item, root_span, item.id, vis); self.add_import(module_path, kind, use_tree.span, item, root_span, item.id, vis);
@ -621,11 +614,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
let new_span = prefix[prefix.len() - 1].ident.span; let new_span = prefix[prefix.len() - 1].ident.span;
let tree = ast::UseTree { let tree = ast::UseTree {
prefix: ast::Path::from_ident(Ident::new(kw::SelfLower, new_span)), prefix: ast::Path::from_ident(Ident::new(kw::SelfLower, new_span)),
kind: ast::UseTreeKind::Simple( kind: ast::UseTreeKind::Simple(Some(Ident::new(kw::Underscore, new_span))),
Some(Ident::new(kw::Underscore, new_span)),
ast::DUMMY_NODE_ID,
ast::DUMMY_NODE_ID,
),
span: use_tree.span, span: use_tree.span,
}; };
self.build_reduced_graph_for_use_tree( self.build_reduced_graph_for_use_tree(

View file

@ -158,14 +158,6 @@ impl<'a, 'b> visit::Visitor<'a> for DefCollector<'a, 'b> {
fn visit_use_tree(&mut self, use_tree: &'a UseTree, id: NodeId, _nested: bool) { fn visit_use_tree(&mut self, use_tree: &'a UseTree, id: NodeId, _nested: bool) {
self.create_def(id, DefPathData::Use, use_tree.span); self.create_def(id, DefPathData::Use, use_tree.span);
match use_tree.kind {
UseTreeKind::Simple(_, id1, id2) => {
self.create_def(id1, DefPathData::Use, use_tree.prefix.span);
self.create_def(id2, DefPathData::Use, use_tree.prefix.span);
}
UseTreeKind::Glob => (),
UseTreeKind::Nested(..) => {}
}
visit::walk_use_tree(self, use_tree, id); visit::walk_use_tree(self, use_tree, id);
} }

View file

@ -1,4 +1,4 @@
use crate::{ImportKind, NameBinding, NameBindingKind, Resolver, ResolverTree}; use crate::{NameBinding, NameBindingKind, Resolver, ResolverTree};
use rustc_ast::ast; use rustc_ast::ast;
use rustc_ast::visit; use rustc_ast::visit;
use rustc_ast::visit::Visitor; use rustc_ast::visit::Visitor;
@ -104,28 +104,11 @@ impl<'r, 'a> EffectiveVisibilitiesVisitor<'r, 'a> {
for (binding, eff_vis) in visitor.import_effective_visibilities.iter() { for (binding, eff_vis) in visitor.import_effective_visibilities.iter() {
let NameBindingKind::Import { import, .. } = binding.kind else { unreachable!() }; let NameBindingKind::Import { import, .. } = binding.kind else { unreachable!() };
if let Some(node_id) = import.id() { if let Some(node_id) = import.id() {
let mut update = |node_id| { r.effective_visibilities.update_eff_vis(
r.effective_visibilities.update_eff_vis( r.local_def_id(node_id),
r.local_def_id(node_id), eff_vis,
eff_vis, ResolverTree(&r.definitions, &r.crate_loader),
ResolverTree(&r.definitions, &r.crate_loader), )
)
};
update(node_id);
if let ImportKind::Single { additional_ids: (id1, id2), .. } = import.kind {
// In theory all the single import IDs have individual visibilities and
// effective visibilities, but in practice these IDs go straight to HIR
// where all their few uses assume that their (effective) visibility
// applies to the whole syntactic `use` item. So they all get the same
// value which is the maximum of all bindings. Maybe HIR for imports
// shouldn't use three IDs at all.
if id1 != ast::DUMMY_NODE_ID {
update(id1);
}
if id2 != ast::DUMMY_NODE_ID {
update(id2);
}
}
} }
} }

View file

@ -56,9 +56,6 @@ pub enum ImportKind<'a> {
/// If this is the import for `foo::bar::a`, we would have the ID of the `UseTree` /// If this is the import for `foo::bar::a`, we would have the ID of the `UseTree`
/// for `a` in this field. /// for `a` in this field.
id: NodeId, id: NodeId,
/// Additional `NodeId`s allocated to a `ast::UseTree` for automatically generated `use` statement
/// (eg. implicit struct constructors)
additional_ids: (NodeId, NodeId),
}, },
Glob { Glob {
is_prelude: bool, is_prelude: bool,
@ -88,7 +85,6 @@ impl<'a> std::fmt::Debug for ImportKind<'a> {
ref type_ns_only, ref type_ns_only,
ref nested, ref nested,
ref id, ref id,
ref additional_ids,
// Ignore the following to avoid an infinite loop while printing. // Ignore the following to avoid an infinite loop while printing.
source_bindings: _, source_bindings: _,
target_bindings: _, target_bindings: _,
@ -99,7 +95,6 @@ impl<'a> std::fmt::Debug for ImportKind<'a> {
.field("type_ns_only", type_ns_only) .field("type_ns_only", type_ns_only)
.field("nested", nested) .field("nested", nested)
.field("id", id) .field("id", id)
.field("additional_ids", additional_ids)
.finish_non_exhaustive(), .finish_non_exhaustive(),
Glob { ref is_prelude, ref max_vis, ref id } => f Glob { ref is_prelude, ref max_vis, ref id } => f
.debug_struct("Glob") .debug_struct("Glob")

View file

@ -225,10 +225,10 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
types::ItemEnum::Function(_) types::ItemEnum::Function(_)
| types::ItemEnum::Module(_) | types::ItemEnum::Module(_)
| types::ItemEnum::Import(_)
| types::ItemEnum::AssocConst { .. } | types::ItemEnum::AssocConst { .. }
| types::ItemEnum::AssocType { .. } => true, | types::ItemEnum::AssocType { .. } => true,
types::ItemEnum::ExternCrate { .. } types::ItemEnum::ExternCrate { .. }
| types::ItemEnum::Import(_)
| types::ItemEnum::StructField(_) | types::ItemEnum::StructField(_)
| types::ItemEnum::Variant(_) | types::ItemEnum::Variant(_)
| types::ItemEnum::TraitAlias(_) | types::ItemEnum::TraitAlias(_)

View file

@ -2,13 +2,13 @@ error[E0080]: could not evaluate static initializer
--> $DIR/tls.rs:11:25 --> $DIR/tls.rs:11:25
| |
LL | unsafe { let _val = A; } LL | unsafe { let _val = A; }
| ^ cannot access thread local static (DefId(0:6 ~ tls[78b0]::A)) | ^ cannot access thread local static (DefId(0:4 ~ tls[78b0]::A))
error[E0080]: could not evaluate static initializer error[E0080]: could not evaluate static initializer
--> $DIR/tls.rs:18:26 --> $DIR/tls.rs:18:26
| |
LL | unsafe { let _val = &A; } LL | unsafe { let _val = &A; }
| ^ cannot access thread local static (DefId(0:6 ~ tls[78b0]::A)) | ^ cannot access thread local static (DefId(0:4 ~ tls[78b0]::A))
warning: skipping const checks warning: skipping const checks
| |

View file

@ -9,7 +9,7 @@ note: generator is not `Send` as this value is used across a yield
--> $DIR/generator-print-verbose-1.rs:35:9 --> $DIR/generator-print-verbose-1.rs:35:9
| |
LL | let _non_send_gen = make_non_send_generator(); LL | let _non_send_gen = make_non_send_generator();
| ------------- has type `Opaque(DefId(0:44 ~ generator_print_verbose_1[749a]::make_non_send_generator::{opaque#0}), [])` which is not `Send` | ------------- has type `Opaque(DefId(0:34 ~ generator_print_verbose_1[749a]::make_non_send_generator::{opaque#0}), [])` which is not `Send`
LL | yield; LL | yield;
| ^^^^^ yield occurs here, with `_non_send_gen` maybe used later | ^^^^^ yield occurs here, with `_non_send_gen` maybe used later
LL | }; LL | };
@ -35,17 +35,17 @@ note: required because it's used within this generator
| |
LL | || { LL | || {
| ^^ | ^^
note: required because it appears within the type `Opaque(DefId(0:45 ~ generator_print_verbose_1[749a]::make_gen2::{opaque#0}), [std::sync::Arc<std::cell::RefCell<i32>>])` note: required because it appears within the type `Opaque(DefId(0:35 ~ generator_print_verbose_1[749a]::make_gen2::{opaque#0}), [std::sync::Arc<std::cell::RefCell<i32>>])`
--> $DIR/generator-print-verbose-1.rs:41:30 --> $DIR/generator-print-verbose-1.rs:41:30
| |
LL | pub fn make_gen2<T>(t: T) -> impl Generator<Return = T> { LL | pub fn make_gen2<T>(t: T) -> impl Generator<Return = T> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
note: required because it appears within the type `Opaque(DefId(0:46 ~ generator_print_verbose_1[749a]::make_non_send_generator2::{opaque#0}), [])` note: required because it appears within the type `Opaque(DefId(0:36 ~ generator_print_verbose_1[749a]::make_non_send_generator2::{opaque#0}), [])`
--> $DIR/generator-print-verbose-1.rs:47:34 --> $DIR/generator-print-verbose-1.rs:47:34
| |
LL | fn make_non_send_generator2() -> impl Generator<Return = Arc<RefCell<i32>>> { LL | fn make_non_send_generator2() -> impl Generator<Return = Arc<RefCell<i32>>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: required because it captures the following types: `Opaque(DefId(0:46 ~ generator_print_verbose_1[749a]::make_non_send_generator2::{opaque#0}), [])`, `()` = note: required because it captures the following types: `Opaque(DefId(0:36 ~ generator_print_verbose_1[749a]::make_non_send_generator2::{opaque#0}), [])`, `()`
note: required because it's used within this generator note: required because it's used within this generator
--> $DIR/generator-print-verbose-1.rs:52:20 --> $DIR/generator-print-verbose-1.rs:52:20
| |

View file

@ -108,17 +108,6 @@ LL | type Bar<'b>;
= note: this bound is currently required to ensure that impls have maximum flexibility = note: this bound is currently required to ensure that impls have maximum flexibility
= note: we are soliciting feedback, see issue #87479 <https://github.com/rust-lang/rust/issues/87479> for more information = note: we are soliciting feedback, see issue #87479 <https://github.com/rust-lang/rust/issues/87479> for more information
error: missing required bound on `Item`
--> $DIR/self-outlives-lint.rs:140:5
|
LL | type Item<'a>;
| ^^^^^^^^^^^^^-
| |
| help: add the required where clause: `where Self: 'a`
|
= note: this bound is currently required to ensure that impls have maximum flexibility
= note: we are soliciting feedback, see issue #87479 <https://github.com/rust-lang/rust/issues/87479> for more information
error: missing required bound on `Iterator` error: missing required bound on `Iterator`
--> $DIR/self-outlives-lint.rs:142:5 --> $DIR/self-outlives-lint.rs:142:5
| |
@ -130,6 +119,17 @@ LL | type Iterator<'a>: Iterator<Item = Self::Item<'a>>;
= note: this bound is currently required to ensure that impls have maximum flexibility = note: this bound is currently required to ensure that impls have maximum flexibility
= note: we are soliciting feedback, see issue #87479 <https://github.com/rust-lang/rust/issues/87479> for more information = note: we are soliciting feedback, see issue #87479 <https://github.com/rust-lang/rust/issues/87479> for more information
error: missing required bound on `Item`
--> $DIR/self-outlives-lint.rs:140:5
|
LL | type Item<'a>;
| ^^^^^^^^^^^^^-
| |
| help: add the required where clause: `where Self: 'a`
|
= note: this bound is currently required to ensure that impls have maximum flexibility
= note: we are soliciting feedback, see issue #87479 <https://github.com/rust-lang/rust/issues/87479> for more information
error: missing required bound on `Item` error: missing required bound on `Item`
--> $DIR/self-outlives-lint.rs:148:5 --> $DIR/self-outlives-lint.rs:148:5
| |

View file

@ -72,6 +72,5 @@ mod half_public_import {
#[rustc_effective_visibility] #[rustc_effective_visibility]
pub use half_public_import::HalfPublicImport; //~ ERROR Direct: pub, Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub pub use half_public_import::HalfPublicImport; //~ ERROR Direct: pub, Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
//~^ ERROR Direct: pub, Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
fn main() {} fn main() {}

View file

@ -124,12 +124,6 @@ error: Direct: pub, Reexported: pub, Reachable: pub, ReachableThroughImplTrait:
LL | pub use half_public_import::HalfPublicImport; LL | pub use half_public_import::HalfPublicImport;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: Direct: pub, Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
--> $DIR/effective_visibilities.rs:74:9
|
LL | pub use half_public_import::HalfPublicImport;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImplTrait: pub
--> $DIR/effective_visibilities.rs:14:13 --> $DIR/effective_visibilities.rs:14:13
| |
@ -142,5 +136,5 @@ error: Direct: pub(crate), Reexported: pub, Reachable: pub, ReachableThroughImpl
LL | type B; LL | type B;
| ^^^^^^ | ^^^^^^
error: aborting due to 24 previous errors error: aborting due to 23 previous errors

View file

@ -120,59 +120,59 @@ hir-stats Name Accumulated Size Count Item Size
hir-stats ---------------------------------------------------------------- hir-stats ----------------------------------------------------------------
hir-stats ForeignItemRef 24 ( 0.3%) 1 24 hir-stats ForeignItemRef 24 ( 0.3%) 1 24
hir-stats Lifetime 24 ( 0.3%) 1 24 hir-stats Lifetime 24 ( 0.3%) 1 24
hir-stats Mod 32 ( 0.3%) 1 32 hir-stats Mod 32 ( 0.4%) 1 32
hir-stats ExprField 40 ( 0.4%) 1 40 hir-stats ExprField 40 ( 0.4%) 1 40
hir-stats TraitItemRef 56 ( 0.6%) 2 28 hir-stats TraitItemRef 56 ( 0.6%) 2 28
hir-stats Local 64 ( 0.7%) 1 64 hir-stats Local 64 ( 0.7%) 1 64
hir-stats Param 64 ( 0.7%) 2 32 hir-stats Param 64 ( 0.7%) 2 32
hir-stats InlineAsm 72 ( 0.8%) 1 72 hir-stats InlineAsm 72 ( 0.8%) 1 72
hir-stats ImplItemRef 72 ( 0.8%) 2 36 hir-stats ImplItemRef 72 ( 0.8%) 2 36
hir-stats Body 96 ( 1.0%) 3 32 hir-stats Body 96 ( 1.1%) 3 32
hir-stats FieldDef 96 ( 1.0%) 2 48 hir-stats FieldDef 96 ( 1.1%) 2 48
hir-stats Arm 96 ( 1.0%) 2 48 hir-stats Arm 96 ( 1.1%) 2 48
hir-stats Stmt 96 ( 1.0%) 3 32 hir-stats Stmt 96 ( 1.1%) 3 32
hir-stats - Local 32 ( 0.3%) 1 hir-stats - Local 32 ( 0.4%) 1
hir-stats - Semi 32 ( 0.3%) 1 hir-stats - Semi 32 ( 0.4%) 1
hir-stats - Expr 32 ( 0.3%) 1 hir-stats - Expr 32 ( 0.4%) 1
hir-stats FnDecl 120 ( 1.3%) 3 40 hir-stats FnDecl 120 ( 1.3%) 3 40
hir-stats Attribute 128 ( 1.4%) 4 32 hir-stats Attribute 128 ( 1.4%) 4 32
hir-stats GenericArg 128 ( 1.4%) 4 32 hir-stats GenericArg 128 ( 1.4%) 4 32
hir-stats - Type 32 ( 0.3%) 1 hir-stats - Type 32 ( 0.4%) 1
hir-stats - Lifetime 96 ( 1.0%) 3 hir-stats - Lifetime 96 ( 1.1%) 3
hir-stats GenericArgs 144 ( 1.6%) 3 48 hir-stats GenericArgs 144 ( 1.6%) 3 48
hir-stats Variant 176 ( 1.9%) 2 88 hir-stats Variant 176 ( 1.9%) 2 88
hir-stats GenericBound 192 ( 2.1%) 4 48 hir-stats GenericBound 192 ( 2.1%) 4 48
hir-stats - Trait 192 ( 2.1%) 4 hir-stats - Trait 192 ( 2.1%) 4
hir-stats WherePredicate 192 ( 2.1%) 3 64 hir-stats WherePredicate 192 ( 2.1%) 3 64
hir-stats - BoundPredicate 192 ( 2.1%) 3 hir-stats - BoundPredicate 192 ( 2.1%) 3
hir-stats Block 288 ( 3.1%) 6 48 hir-stats Block 288 ( 3.2%) 6 48
hir-stats Pat 360 ( 3.9%) 5 72 hir-stats Pat 360 ( 4.0%) 5 72
hir-stats - Wild 72 ( 0.8%) 1 hir-stats - Wild 72 ( 0.8%) 1
hir-stats - Struct 72 ( 0.8%) 1 hir-stats - Struct 72 ( 0.8%) 1
hir-stats - Binding 216 ( 2.4%) 3 hir-stats - Binding 216 ( 2.4%) 3
hir-stats GenericParam 400 ( 4.4%) 5 80 hir-stats GenericParam 400 ( 4.4%) 5 80
hir-stats Generics 560 ( 6.1%) 10 56 hir-stats Generics 560 ( 6.2%) 10 56
hir-stats Ty 720 ( 7.9%) 15 48 hir-stats Ty 720 ( 8.0%) 15 48
hir-stats - Ptr 48 ( 0.5%) 1 hir-stats - Ptr 48 ( 0.5%) 1
hir-stats - Rptr 48 ( 0.5%) 1 hir-stats - Rptr 48 ( 0.5%) 1
hir-stats - Path 624 ( 6.8%) 13 hir-stats - Path 624 ( 6.9%) 13
hir-stats Expr 768 ( 8.4%) 12 64 hir-stats Expr 768 ( 8.5%) 12 64
hir-stats - Path 64 ( 0.7%) 1 hir-stats - Path 64 ( 0.7%) 1
hir-stats - Struct 64 ( 0.7%) 1 hir-stats - Struct 64 ( 0.7%) 1
hir-stats - Match 64 ( 0.7%) 1 hir-stats - Match 64 ( 0.7%) 1
hir-stats - InlineAsm 64 ( 0.7%) 1 hir-stats - InlineAsm 64 ( 0.7%) 1
hir-stats - Lit 128 ( 1.4%) 2 hir-stats - Lit 128 ( 1.4%) 2
hir-stats - Block 384 ( 4.2%) 6 hir-stats - Block 384 ( 4.2%) 6
hir-stats Item 960 (10.5%) 12 80 hir-stats Item 880 ( 9.7%) 11 80
hir-stats - Trait 80 ( 0.9%) 1 hir-stats - Trait 80 ( 0.9%) 1
hir-stats - Enum 80 ( 0.9%) 1 hir-stats - Enum 80 ( 0.9%) 1
hir-stats - ExternCrate 80 ( 0.9%) 1 hir-stats - ExternCrate 80 ( 0.9%) 1
hir-stats - ForeignMod 80 ( 0.9%) 1 hir-stats - ForeignMod 80 ( 0.9%) 1
hir-stats - Impl 80 ( 0.9%) 1 hir-stats - Impl 80 ( 0.9%) 1
hir-stats - Fn 160 ( 1.7%) 2 hir-stats - Fn 160 ( 1.8%) 2
hir-stats - Use 400 ( 4.4%) 5 hir-stats - Use 320 ( 3.5%) 4
hir-stats Path 1_280 (14.0%) 32 40 hir-stats Path 1_240 (13.7%) 31 40
hir-stats PathSegment 1_920 (20.9%) 40 48 hir-stats PathSegment 1_920 (21.2%) 40 48
hir-stats ---------------------------------------------------------------- hir-stats ----------------------------------------------------------------
hir-stats Total 9_168 hir-stats Total 9_048
hir-stats hir-stats

View file

@ -149,7 +149,7 @@ impl SingleComponentPathImports {
// keep track of `use some_module;` usages // keep track of `use some_module;` usages
if segments.len() == 1 { if segments.len() == 1 {
if let UseTreeKind::Simple(None, _, _) = use_tree.kind { if let UseTreeKind::Simple(None) = use_tree.kind {
let name = segments[0].ident.name; let name = segments[0].ident.name;
if !macros.contains(&name) { if !macros.contains(&name) {
single_use_usages.push(SingleUse { single_use_usages.push(SingleUse {
@ -169,7 +169,7 @@ impl SingleComponentPathImports {
for tree in trees { for tree in trees {
let segments = &tree.0.prefix.segments; let segments = &tree.0.prefix.segments;
if segments.len() == 1 { if segments.len() == 1 {
if let UseTreeKind::Simple(None, _, _) = tree.0.kind { if let UseTreeKind::Simple(None) = tree.0.kind {
let name = segments[0].ident.name; let name = segments[0].ident.name;
if !macros.contains(&name) { if !macros.contains(&name) {
single_use_usages.push(SingleUse { single_use_usages.push(SingleUse {

View file

@ -57,7 +57,7 @@ impl EarlyLintPass for UnnecessarySelfImports {
format!( format!(
"{}{};", "{}{};",
last_segment.ident, last_segment.ident,
if let UseTreeKind::Simple(Some(alias), ..) = self_tree.kind { format!(" as {alias}") } else { String::new() }, if let UseTreeKind::Simple(Some(alias)) = self_tree.kind { format!(" as {alias}") } else { String::new() },
), ),
Applicability::MaybeIncorrect, Applicability::MaybeIncorrect,
); );

View file

@ -39,7 +39,7 @@ impl EarlyLintPass for UnsafeNameRemoval {
fn check_use_tree(use_tree: &UseTree, cx: &EarlyContext<'_>, span: Span) { fn check_use_tree(use_tree: &UseTree, cx: &EarlyContext<'_>, span: Span) {
match use_tree.kind { match use_tree.kind {
UseTreeKind::Simple(Some(new_name), ..) => { UseTreeKind::Simple(Some(new_name)) => {
let old_name = use_tree let old_name = use_tree
.prefix .prefix
.segments .segments
@ -48,7 +48,7 @@ fn check_use_tree(use_tree: &UseTree, cx: &EarlyContext<'_>, span: Span) {
.ident; .ident;
unsafe_to_safe_check(old_name, new_name, cx, span); unsafe_to_safe_check(old_name, new_name, cx, span);
}, },
UseTreeKind::Simple(None, ..) | UseTreeKind::Glob => {}, UseTreeKind::Simple(None) | UseTreeKind::Glob => {},
UseTreeKind::Nested(ref nested_use_tree) => { UseTreeKind::Nested(ref nested_use_tree) => {
for (use_tree, _) in nested_use_tree { for (use_tree, _) in nested_use_tree {
check_use_tree(use_tree, cx, span); check_use_tree(use_tree, cx, span);

View file

@ -566,7 +566,7 @@ pub fn eq_use_tree_kind(l: &UseTreeKind, r: &UseTreeKind) -> bool {
use UseTreeKind::*; use UseTreeKind::*;
match (l, r) { match (l, r) {
(Glob, Glob) => true, (Glob, Glob) => true,
(Simple(l, _, _), Simple(r, _, _)) => both(l, r, |l, r| eq_id(*l, *r)), (Simple(l), Simple(r)) => both(l, r, |l, r| eq_id(*l, *r)),
(Nested(l), Nested(r)) => over(l, r, |(l, _), (r, _)| eq_use_tree(l, r)), (Nested(l), Nested(r)) => over(l, r, |(l, _), (r, _)| eq_use_tree(l, r)),
_ => false, _ => false,
} }

View file

@ -1,8 +1,8 @@
error: `macro_use` attributes are no longer needed in the Rust 2018 edition error: `macro_use` attributes are no longer needed in the Rust 2018 edition
--> $DIR/macro_use_imports.rs:23:5 --> $DIR/macro_use_imports.rs:25:5
| |
LL | #[macro_use] LL | #[macro_use]
| ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{inner::foofoo, inner::try_err};` | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::inner::nested::string_add;`
| |
= note: `-D clippy::macro-use-imports` implied by `-D warnings` = note: `-D clippy::macro-use-imports` implied by `-D warnings`
@ -13,10 +13,10 @@ LL | #[macro_use]
| ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mini_mac::ClippyMiniMacroTest;` | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mini_mac::ClippyMiniMacroTest;`
error: `macro_use` attributes are no longer needed in the Rust 2018 edition error: `macro_use` attributes are no longer needed in the Rust 2018 edition
--> $DIR/macro_use_imports.rs:25:5 --> $DIR/macro_use_imports.rs:23:5
| |
LL | #[macro_use] LL | #[macro_use]
| ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::inner::nested::string_add;` | ^^^^^^^^^^^^ help: remove the attribute and import the macro directly, try: `use mac::{inner::foofoo, inner::try_err};`
error: `macro_use` attributes are no longer needed in the Rust 2018 edition error: `macro_use` attributes are no longer needed in the Rust 2018 edition
--> $DIR/macro_use_imports.rs:19:5 --> $DIR/macro_use_imports.rs:19:5

View file

@ -490,7 +490,7 @@ impl UseTree {
); );
result.path.push(UseSegment { kind, version }); result.path.push(UseSegment { kind, version });
} }
UseTreeKind::Simple(ref rename, ..) => { UseTreeKind::Simple(ref rename) => {
// If the path has leading double colons and is composed of only 2 segments, then we // If the path has leading double colons and is composed of only 2 segments, then we
// bypass the call to path_to_imported_ident which would get only the ident and // bypass the call to path_to_imported_ident which would get only the ident and
// lose the path root, e.g., `that` in `::that`. // lose the path root, e.g., `that` in `::that`.