Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
4 changes: 2 additions & 2 deletions src/liballoc/collections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl<K: Clone, V: Clone> Clone for BTreeMap<K, V> {
(root, length)
};

out_node.push(k, v, subroot.unwrap_or_else(|| node::Root::new_leaf()));
out_node.push(k, v, subroot.unwrap_or_else(node::Root::new_leaf));
out_tree.length += 1 + sublength;
}
}
Expand Down Expand Up @@ -2147,7 +2147,7 @@ impl<K, V> BTreeMap<K, V> {
/// If the root node is the empty (non-allocated) root node, allocate our
/// own node.
fn ensure_root_is_owned(&mut self) -> &mut node::Root<K, V> {
self.root.get_or_insert_with(|| node::Root::new_leaf())
self.root.get_or_insert_with(node::Root::new_leaf)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/dep_graph/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ impl DepGraph {
C: DepGraphSafe + StableHashingContextProvider<'a>,
{
if let Some(ref data) = self.data {
let task_deps = create_task(key).map(|deps| Lock::new(deps));
let task_deps = create_task(key).map(Lock::new);

// In incremental mode, hash the result of the task. We don't
// do anything with the hash yet, but we are computing it
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/mir/interpret/allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ impl UndefMask {
}

// FIXME(oli-obk): optimize this for allocations larger than a block.
let idx = (start.bytes()..end.bytes()).map(|i| Size::from_bytes(i)).find(|&i| !self.get(i));
let idx = (start.bytes()..end.bytes()).map(Size::from_bytes).find(|&i| !self.get(i));

match idx {
Some(idx) => Err(idx),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_ast/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ impl ParenthesizedArgs {
pub fn as_angle_bracketed_args(&self) -> AngleBracketedArgs {
AngleBracketedArgs {
span: self.span,
args: self.inputs.iter().cloned().map(|input| GenericArg::Type(input)).collect(),
args: self.inputs.iter().cloned().map(GenericArg::Type).collect(),
constraints: vec![],
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_ast_lowering/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
if !generic_args.parenthesized && !has_lifetimes {
generic_args.args = self
.elided_path_lifetimes(path_span, expected_lifetimes)
.map(|lt| GenericArg::Lifetime(lt))
.map(GenericArg::Lifetime)
.chain(generic_args.args.into_iter())
.collect();
if expected_lifetimes > 0 && param_mode == ParamMode::Explicit {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_builtin_macros/deriving/generic/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ impl<'a> Path<'a> {
self.params.iter().map(|t| t.to_ty(cx, span, self_ty, self_generics)).collect();
let params = lt
.into_iter()
.map(|lt| GenericArg::Lifetime(lt))
.chain(tys.into_iter().map(|ty| GenericArg::Type(ty)))
.map(GenericArg::Lifetime)
.chain(tys.into_iter().map(GenericArg::Type))
.collect();

match self.kind {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_builtin_macros/source_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rustc_ast_pretty::pprust;
use rustc_expand::base::{self, *};
use rustc_expand::module::DirectoryOwnership;
use rustc_expand::panictry;
use rustc_parse::{self, new_sub_parser_from_file, parser::Parser};
use rustc_parse::{self, new_parser_from_file, parser::Parser};
use rustc_session::lint::builtin::INCOMPLETE_INCLUDE;
use rustc_span::symbol::Symbol;
use rustc_span::{self, Pos, Span};
Expand Down Expand Up @@ -110,7 +110,7 @@ pub fn expand_include<'cx>(
return DummyResult::any(sp);
}
};
let p = new_sub_parser_from_file(cx.parse_sess(), &file, None, sp);
let p = new_parser_from_file(cx.parse_sess(), &file, Some(sp));

// If in the included file we have e.g., `mod bar;`,
// then the path of `bar.rs` should be relative to the directory of `file`.
Expand Down
43 changes: 19 additions & 24 deletions src/librustc_codegen_ssa/mir/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,31 +40,26 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
&mut self,
constant: &mir::Constant<'tcx>,
) -> Result<ConstValue<'tcx>, ErrorHandled> {
match constant.literal.val {
ty::ConstKind::Unevaluated(def_id, substs, promoted) => {
let substs = self.monomorphize(&substs);
self.cx
.tcx()
.const_eval_resolve(ty::ParamEnv::reveal_all(), def_id, substs, promoted, None)
.map_err(|err| {
if promoted.is_none() {
self.cx
.tcx()
.sess
.span_err(constant.span, "erroneous constant encountered");
}
err
})
}
match self.monomorphize(&constant.literal).val {
ty::ConstKind::Unevaluated(def_id, substs, promoted) => self
.cx
.tcx()
.const_eval_resolve(ty::ParamEnv::reveal_all(), def_id, substs, promoted, None)
.map_err(|err| {
if promoted.is_none() {
self.cx
.tcx()
.sess
.span_err(constant.span, "erroneous constant encountered");
}
err
}),
ty::ConstKind::Value(value) => Ok(value),
_ => {
let const_ = self.monomorphize(&constant.literal);
if let ty::ConstKind::Value(value) = const_.val {
Ok(value)
} else {
span_bug!(constant.span, "encountered bad ConstKind in codegen: {:?}", const_);
}
}
err => span_bug!(
constant.span,
"encountered bad ConstKind after monomorphizing: {:?}",
err
),
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_data_structures/sharded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct Sharded<T> {
impl<T: Default> Default for Sharded<T> {
#[inline]
fn default() -> Self {
Self::new(|| T::default())
Self::new(T::default)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_errors/diagnostic_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl<'a> DiagnosticBuilder<'a> {
message: &str,
span: Option<S>,
) -> &mut Self {
let span = span.map(|s| s.into()).unwrap_or_else(|| MultiSpan::new());
let span = span.map(|s| s.into()).unwrap_or_else(MultiSpan::new);
self.0.diagnostic.sub(level, message, span, None);
self
}
Expand Down
2 changes: 0 additions & 2 deletions src/librustc_expand/mbe/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,6 @@ fn generic_extension<'cx>(
}

let mut p = Parser::new(sess, tts, false, None);
p.root_module_name =
cx.current_expansion.module.mod_path.last().map(|id| id.to_string());
p.last_type_ascription = cx.current_expansion.prior_type_ascription;

// Let the context choose how to interpret the result.
Expand Down
7 changes: 3 additions & 4 deletions src/librustc_expand/module.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rustc_ast::ast::{self, Attribute, Ident, Mod};
use rustc_ast::{attr, token};
use rustc_errors::{struct_span_err, PResult};
use rustc_parse::new_sub_parser_from_file;
use rustc_parse::new_parser_from_file;
use rustc_session::parse::ParseSess;
use rustc_span::source_map::{FileName, Span};
use rustc_span::symbol::sym;
Expand Down Expand Up @@ -59,9 +59,8 @@ crate fn parse_external_mod(
*pop_mod_stack = true; // We have pushed, so notify caller.
drop(included_mod_stack);

// Actually parse the external file as amodule.
let mut p0 = new_sub_parser_from_file(sess, &mp.path, Some(id.to_string()), span);
let mut module = p0.parse_mod(&token::Eof)?;
// Actually parse the external file as a module.
let mut module = new_parser_from_file(sess, &mp.path, Some(span)).parse_mod(&token::Eof)?;
module.0.inline = false;
module
};
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_feature/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub struct Feature {

impl Feature {
fn issue(&self) -> Option<NonZeroU32> {
self.issue.and_then(|i| NonZeroU32::new(i))
self.issue.and_then(NonZeroU32::new)
}
}

Expand Down
17 changes: 6 additions & 11 deletions src/librustc_infer/infer/error_reporting/need_type_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::infer::InferCtxt;
use rustc::hir::map::Map;
use rustc::ty::print::Print;
use rustc::ty::{self, DefIdTree, Infer, Ty, TyVar};
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder};
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder};
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Namespace};
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
Expand Down Expand Up @@ -462,24 +462,19 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
e: &Expr<'_>,
err: &mut DiagnosticBuilder<'_>,
) {
if let (Ok(snippet), Some(tables), None) = (
self.tcx.sess.source_map().span_to_snippet(segment.ident.span),
self.in_progress_tables,
&segment.args,
) {
if let (Some(tables), None) = (self.in_progress_tables, &segment.args) {
let borrow = tables.borrow();
if let Some((DefKind::AssocFn, did)) = borrow.type_dependent_def(e.hir_id) {
let generics = self.tcx.generics_of(did);
if !generics.params.is_empty() {
err.span_suggestion(
segment.ident.span,
err.span_suggestion_verbose(
segment.ident.span.shrink_to_hi(),
&format!(
"consider specifying the type argument{} in the method call",
if generics.params.len() > 1 { "s" } else { "" },
pluralize!(generics.params.len()),
),
format!(
"{}::<{}>",
snippet,
"::<{}>",
generics
.params
.iter()
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_interface/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ impl<'tcx> QueryContext<'tcx> {
where
F: FnOnce(TyCtxt<'tcx>) -> R,
{
ty::tls::enter_global(self.0, |tcx| f(tcx))
ty::tls::enter_global(self.0, f)
}

pub fn print_stats(&mut self) {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_metadata/locator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ impl<'a> CrateLocator<'a> {
.into_iter()
.filter_map(|entry| entry.files())
.flatten()
.map(|location| PathBuf::from(location))
.map(PathBuf::from)
.collect()
} else {
// SVH being specified means this is a transitive dependency,
Expand Down
56 changes: 31 additions & 25 deletions src/librustc_metadata/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,14 +509,6 @@ impl<'a, 'tcx> SpecializedDecoder<Span> for DecodeContext<'a, 'tcx> {
}
}

impl SpecializedDecoder<Ident> for DecodeContext<'_, '_> {
fn specialized_decode(&mut self) -> Result<Ident, Self::Error> {
// FIXME(jseyfried): intercrate hygiene

Ok(Ident::with_dummy_span(Symbol::decode(self)?))
}
}

impl<'a, 'tcx> SpecializedDecoder<Fingerprint> for DecodeContext<'a, 'tcx> {
fn specialized_decode(&mut self) -> Result<Fingerprint, Self::Error> {
Fingerprint::decode_opaque(&mut self.opaque)
Expand Down Expand Up @@ -663,15 +655,27 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
&self.raw_proc_macros.unwrap()[pos]
}

fn item_name(&self, item_index: DefIndex) -> Symbol {
fn item_ident(&self, item_index: DefIndex, sess: &Session) -> Ident {
if !self.is_proc_macro(item_index) {
self.def_key(item_index)
let name = self
.def_key(item_index)
.disambiguated_data
.data
.get_opt_name()
.expect("no name in item_name")
.expect("no name in item_ident");
let span = self
.root
.per_def
.ident_span
.get(self, item_index)
.map(|data| data.decode((self, sess)))
.unwrap_or_else(|| panic!("Missing ident span for {:?} ({:?})", name, item_index));
Ident::new(name, span)
} else {
Symbol::intern(self.raw_proc_macro(item_index).name())
Ident::new(
Symbol::intern(self.raw_proc_macro(item_index).name()),
self.get_span(item_index, sess),
)
}
}

Expand Down Expand Up @@ -750,6 +754,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
kind: &EntryKind,
index: DefIndex,
parent_did: DefId,
sess: &Session,
) -> ty::VariantDef {
let data = match kind {
EntryKind::Variant(data) | EntryKind::Struct(data, _) | EntryKind::Union(data, _) => {
Expand All @@ -771,7 +776,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {

ty::VariantDef::new(
tcx,
Ident::with_dummy_span(self.item_name(index)),
self.item_ident(index, sess),
variant_did,
ctor_did,
data.discr,
Expand All @@ -783,7 +788,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
.decode(self)
.map(|index| ty::FieldDef {
did: self.local_def_id(index),
ident: Ident::with_dummy_span(self.item_name(index)),
ident: self.item_ident(index, sess),
vis: self.get_visibility(index),
})
.collect(),
Expand Down Expand Up @@ -812,10 +817,10 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
.get(self, item_id)
.unwrap_or(Lazy::empty())
.decode(self)
.map(|index| self.get_variant(tcx, &self.kind(index), index, did))
.map(|index| self.get_variant(tcx, &self.kind(index), index, did, tcx.sess))
.collect()
} else {
std::iter::once(self.get_variant(tcx, &kind, item_id, did)).collect()
std::iter::once(self.get_variant(tcx, &kind, item_id, did, tcx.sess)).collect()
};

tcx.alloc_adt_def(did, adt_kind, variants, repr)
Expand Down Expand Up @@ -1007,7 +1012,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
if let Some(kind) = self.def_kind(child_index) {
callback(Export {
res: Res::Def(kind, self.local_def_id(child_index)),
ident: Ident::with_dummy_span(self.item_name(child_index)),
ident: self.item_ident(child_index, sess),
vis: self.get_visibility(child_index),
span: self
.root
Expand All @@ -1028,10 +1033,11 @@ 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), Some(name)) =
(self.def_kind(child_index), def_key.disambiguated_data.data.get_opt_name())
{
let ident = Ident::with_dummy_span(name);
if let (Some(kind), true) = (
self.def_kind(child_index),
def_key.disambiguated_data.data.get_opt_name().is_some(),
) {
let ident = self.item_ident(child_index, sess);
let vis = self.get_visibility(child_index);
let def_id = self.local_def_id(child_index);
let res = Res::Def(kind, def_id);
Expand Down Expand Up @@ -1138,10 +1144,10 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
}
}

fn get_associated_item(&self, id: DefIndex) -> ty::AssocItem {
fn get_associated_item(&self, id: DefIndex, sess: &Session) -> ty::AssocItem {
let def_key = self.def_key(id);
let parent = self.local_def_id(def_key.parent.unwrap());
let name = def_key.disambiguated_data.data.get_opt_name().unwrap();
let ident = self.item_ident(id, sess);

let (kind, container, has_self) = match self.kind(id) {
EntryKind::AssocConst(container, _, _) => (ty::AssocKind::Const, container, false),
Expand All @@ -1155,7 +1161,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
};

ty::AssocItem {
ident: Ident::with_dummy_span(name),
ident,
kind,
vis: self.get_visibility(id),
defaultness: container.defaultness(),
Expand Down Expand Up @@ -1219,7 +1225,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
.get(self, id)
.unwrap_or(Lazy::empty())
.decode(self)
.map(|index| respan(self.get_span(index, sess), self.item_name(index)))
.map(|index| respan(self.get_span(index, sess), self.item_ident(index, sess).name))
.collect()
}

Expand Down
Loading