Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 5 pull requests #71302

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/liballoc/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ mod hack {
use crate::string::ToString;
use crate::vec::Vec;

// We shouldn't add inline attribute to this since this is used in
// `vec!` macro mostly and causes perf regression. See #71204 for
// discussion and perf results.
pub fn into_vec<T>(b: Box<[T]>) -> Vec<T> {
unsafe {
let len = b.len();
Expand Down
1 change: 0 additions & 1 deletion src/librustc_ast/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ pub mod util {
pub mod comments;
pub mod lev_distance;
pub mod literal;
pub mod map_in_place;
pub mod parser;
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_ast/mut_visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use crate::ast::*;
use crate::ptr::P;
use crate::token::{self, Token};
use crate::tokenstream::*;
use crate::util::map_in_place::MapInPlace;

use rustc_data_structures::map_in_place::MapInPlace;
use rustc_data_structures::sync::Lrc;
use rustc_span::source_map::{respan, Spanned};
use rustc_span::Span;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_builtin_macros/deriving/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ use std::vec;
use rustc_ast::ast::{self, BinOpKind, EnumDef, Expr, Generics, Ident, PatKind};
use rustc_ast::ast::{GenericArg, GenericParamKind, VariantData};
use rustc_ast::ptr::P;
use rustc_ast::util::map_in_place::MapInPlace;
use rustc_attr as attr;
use rustc_data_structures::map_in_place::MapInPlace;
use rustc_expand::base::{Annotatable, ExtCtxt};
use rustc_session::parse::ParseSess;
use rustc_span::source_map::respan;
Expand Down
1 change: 1 addition & 0 deletions src/librustc_data_structures/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub mod fx;
pub mod graph;
pub mod jobserver;
pub mod macros;
pub mod map_in_place;
pub mod obligation_forest;
pub mod owning_ref;
pub mod ptr_key;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// FIXME(Centril): Move to rustc_data_structures.

use smallvec::{Array, SmallVec};
use std::ptr;

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_expand/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use rustc_ast::ast::{self, AttrItem, Attribute, MetaItem};
use rustc_ast::attr::HasAttrs;
use rustc_ast::mut_visit::*;
use rustc_ast::ptr::P;
use rustc_ast::util::map_in_place::MapInPlace;
use rustc_attr as attr;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::map_in_place::MapInPlace;
use rustc_errors::{error_code, struct_span_err, Applicability, Handler};
use rustc_feature::{Feature, Features, State as FeatureState};
use rustc_feature::{
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_expand/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ use rustc_ast::mut_visit::*;
use rustc_ast::ptr::P;
use rustc_ast::token;
use rustc_ast::tokenstream::TokenStream;
use rustc_ast::util::map_in_place::MapInPlace;
use rustc_ast::visit::{self, AssocCtxt, Visitor};
use rustc_ast_pretty::pprust;
use rustc_attr::{self as attr, is_builtin_attr, HasAttrs};
use rustc_data_structures::map_in_place::MapInPlace;
use rustc_errors::{Applicability, PResult};
use rustc_feature::Features;
use rustc_parse::parser::Parser;
Expand Down
39 changes: 38 additions & 1 deletion src/librustc_hir/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ pub enum DefKind {

// Macro namespace
Macro(MacroKind),

// Not namespaced (or they are, but we don't treat them so)
ExternCrate,
Use,
ForeignMod,
AnonConst,
Field,
LifetimeParam,
GlobalAsm,
Impl,
Closure,
Generator,
}

impl DefKind {
Expand Down Expand Up @@ -113,6 +125,16 @@ impl DefKind {
DefKind::TyParam => "type parameter",
DefKind::ConstParam => "const parameter",
DefKind::Macro(macro_kind) => macro_kind.descr(),
DefKind::LifetimeParam => "lifetime parameter",
DefKind::Use => "import",
DefKind::ForeignMod => "foreign module",
DefKind::AnonConst => "constant expression",
DefKind::Field => "field",
DefKind::Impl => "implementation",
DefKind::Closure => "closure",
DefKind::Generator => "generator",
DefKind::ExternCrate => "extern crate",
DefKind::GlobalAsm => "global assembly block",
}
}

Expand All @@ -124,7 +146,10 @@ impl DefKind {
| DefKind::AssocOpaqueTy
| DefKind::AssocFn
| DefKind::Enum
| DefKind::OpaqueTy => "an",
| DefKind::OpaqueTy
| DefKind::Impl
| DefKind::Use
| DefKind::ExternCrate => "an",
DefKind::Macro(macro_kind) => macro_kind.article(),
_ => "a",
}
Expand Down Expand Up @@ -155,6 +180,18 @@ impl DefKind {
| DefKind::AssocConst => ns == Namespace::ValueNS,

DefKind::Macro(..) => ns == Namespace::MacroNS,

// Not namespaced.
DefKind::AnonConst
| DefKind::Field
| DefKind::LifetimeParam
| DefKind::ExternCrate
| DefKind::Closure
| DefKind::Generator
| DefKind::Use
| DefKind::ForeignMod
| DefKind::GlobalAsm
| DefKind::Impl => false,
}
}
}
Expand Down
31 changes: 0 additions & 31 deletions src/librustc_hir/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2452,27 +2452,6 @@ pub enum ItemKind<'hir> {
}

impl ItemKind<'_> {
pub fn descr(&self) -> &str {
match *self {
ItemKind::ExternCrate(..) => "extern crate",
ItemKind::Use(..) => "`use` import",
ItemKind::Static(..) => "static item",
ItemKind::Const(..) => "constant item",
ItemKind::Fn(..) => "function",
ItemKind::Mod(..) => "module",
ItemKind::ForeignMod(..) => "extern block",
ItemKind::GlobalAsm(..) => "global asm item",
ItemKind::TyAlias(..) => "type alias",
ItemKind::OpaqueTy(..) => "opaque type",
ItemKind::Enum(..) => "enum",
ItemKind::Struct(..) => "struct",
ItemKind::Union(..) => "union",
ItemKind::Trait(..) => "trait",
ItemKind::TraitAlias(..) => "trait alias",
ItemKind::Impl { .. } => "implementation",
}
}

pub fn generics(&self) -> Option<&Generics<'_>> {
Some(match *self {
ItemKind::Fn(_, ref generics, _)
Expand Down Expand Up @@ -2551,16 +2530,6 @@ pub enum ForeignItemKind<'hir> {
Type,
}

impl ForeignItemKind<'hir> {
pub fn descriptive_variant(&self) -> &str {
match *self {
ForeignItemKind::Fn(..) => "foreign function",
ForeignItemKind::Static(..) => "foreign static item",
ForeignItemKind::Type => "foreign type",
}
}
}

/// A variable captured by a closure.
#[derive(Debug, Copy, Clone, RustcEncodable, RustcDecodable, HashStable_Generic)]
pub struct Upvar {
Expand Down
7 changes: 1 addition & 6 deletions src/librustc_infer/infer/error_reporting/need_type_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
.get_opt_name()
.map(|parent_symbol| parent_symbol.to_string());

let type_parent_desc = self
.tcx
.def_kind(parent_def_id)
.map(|parent_def_kind| parent_def_kind.descr(parent_def_id));

(parent_name, type_parent_desc)
(parent_name, Some(self.tcx.def_kind(parent_def_id).descr(parent_def_id)))
} else {
(None, None)
};
Expand Down
4 changes: 3 additions & 1 deletion src/librustc_metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,9 @@ impl<'a> CrateLoader<'a> {
}

fn inject_profiler_runtime(&mut self) {
if self.sess.opts.debugging_opts.profile || self.sess.opts.cg.profile_generate.enabled() {
if (self.sess.opts.debugging_opts.profile || self.sess.opts.cg.profile_generate.enabled())
&& !self.sess.opts.debugging_opts.no_profiler_runtime
{
info!("loading profiler");

let name = Symbol::intern("profiler_builtins");
Expand Down
56 changes: 26 additions & 30 deletions src/librustc_metadata/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,8 @@ impl MetadataBlob {
}

impl EntryKind {
fn def_kind(&self) -> Option<DefKind> {
Some(match *self {
fn def_kind(&self) -> DefKind {
match *self {
EntryKind::Const(..) => DefKind::Const,
EntryKind::AssocConst(..) => DefKind::AssocConst,
EntryKind::ImmStatic
Expand All @@ -587,14 +587,13 @@ impl EntryKind {
EntryKind::Enum(..) => DefKind::Enum,
EntryKind::MacroDef(_) => DefKind::Macro(MacroKind::Bang),
EntryKind::ForeignType => DefKind::ForeignTy,

EntryKind::ForeignMod
| EntryKind::GlobalAsm
| EntryKind::Impl(_)
| EntryKind::Field
| EntryKind::Generator(_)
| EntryKind::Closure => return None,
})
EntryKind::Impl(_) => DefKind::Impl,
EntryKind::Closure => DefKind::Closure,
EntryKind::ForeignMod => DefKind::ForeignMod,
EntryKind::GlobalAsm => DefKind::GlobalAsm,
EntryKind::Field => DefKind::Field,
EntryKind::Generator(_) => DefKind::Generator,
}
}
}

Expand Down Expand Up @@ -679,11 +678,11 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
}
}

fn def_kind(&self, index: DefIndex) -> Option<DefKind> {
fn def_kind(&self, index: DefIndex) -> DefKind {
if !self.is_proc_macro(index) {
self.kind(index).def_kind()
} else {
Some(DefKind::Macro(macro_kind(self.raw_proc_macro(index))))
DefKind::Macro(macro_kind(self.raw_proc_macro(index)))
}
}

Expand Down Expand Up @@ -1009,20 +1008,19 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
.get(self, child_index)
.unwrap_or(Lazy::empty());
for child_index in child_children.decode((self, sess)) {
if let Some(kind) = self.def_kind(child_index) {
callback(Export {
res: Res::Def(kind, self.local_def_id(child_index)),
ident: self.item_ident(child_index, sess),
vis: self.get_visibility(child_index),
span: self
.root
.tables
.span
.get(self, child_index)
.unwrap()
.decode((self, sess)),
});
}
let kind = self.def_kind(child_index);
callback(Export {
res: Res::Def(kind, self.local_def_id(child_index)),
ident: self.item_ident(child_index, sess),
vis: self.get_visibility(child_index),
span: self
.root
.tables
.span
.get(self, child_index)
.unwrap()
.decode((self, sess)),
});
}
continue;
}
Expand All @@ -1033,10 +1031,8 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {

let def_key = self.def_key(child_index);
let span = self.get_span(child_index, sess);
if let (Some(kind), true) = (
self.def_kind(child_index),
def_key.disambiguated_data.data.get_opt_name().is_some(),
) {
if def_key.disambiguated_data.data.get_opt_name().is_some() {
let kind = self.def_kind(child_index);
let ident = self.item_ident(child_index, sess);
let vis = self.get_visibility(child_index);
let def_id = self.local_def_id(child_index);
Expand Down
Loading