Skip to content

Commit

Permalink
Auto merge of #69796 - Centril:rollup-xg85jmx, r=Centril
Browse files Browse the repository at this point in the history
Rollup of 9 pull requests

Successful merges:

 - #67741 (When encountering an Item in a pat context, point at the item def)
 - #68985 (Parse & reject postfix operators after casts)
 - #69656 (Use .next() instead of .nth(0) on iterators.)
 - #69680 (rustc_expand: Factor out `Annotatable::into_tokens` to a separate method)
 - #69690 (test(pattern): add tests for combinations of pattern features)
 - #69706 (Use subslice patterns in slice methods)
 - #69727 (Avoid using `unwrap()` in suggestions)
 - #69754 (Update deprecation version to 1.42 for Error::description)
 - #69782 (Don't redundantly repeat field names (clippy::redundant_field_names))

Failed merges:

r? @ghost
  • Loading branch information
bors committed Mar 7, 2020
2 parents 2890b37 + 709325a commit a039217
Show file tree
Hide file tree
Showing 102 changed files with 1,311 additions and 215 deletions.
2 changes: 1 addition & 1 deletion src/liballoc/collections/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,7 @@ impl<T> LinkedList<T> {
let it = self.head;
let old_len = self.len;

DrainFilter { list: self, it: it, pred: filter, idx: 0, old_len: old_len }
DrainFilter { list: self, it, pred: filter, idx: 0, old_len }
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1659,7 +1659,7 @@ struct SetLenOnDrop<'a> {
impl<'a> SetLenOnDrop<'a> {
#[inline]
fn new(len: &'a mut usize) -> Self {
SetLenOnDrop { local_len: *len, len: len }
SetLenOnDrop { local_len: *len, len }
}

#[inline]
Expand Down
30 changes: 8 additions & 22 deletions src/libcore/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl<T> [T] {
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn first(&self) -> Option<&T> {
self.get(0)
if let [first, ..] = self { Some(first) } else { None }
}

/// Returns a mutable pointer to the first element of the slice, or `None` if it is empty.
Expand All @@ -121,7 +121,7 @@ impl<T> [T] {
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn first_mut(&mut self) -> Option<&mut T> {
self.get_mut(0)
if let [first, ..] = self { Some(first) } else { None }
}

/// Returns the first and all the rest of the elements of the slice, or `None` if it is empty.
Expand All @@ -139,7 +139,7 @@ impl<T> [T] {
#[stable(feature = "slice_splits", since = "1.5.0")]
#[inline]
pub fn split_first(&self) -> Option<(&T, &[T])> {
if self.is_empty() { None } else { Some((&self[0], &self[1..])) }
if let [first, tail @ ..] = self { Some((first, tail)) } else { None }
}

/// Returns the first and all the rest of the elements of the slice, or `None` if it is empty.
Expand All @@ -159,12 +159,7 @@ impl<T> [T] {
#[stable(feature = "slice_splits", since = "1.5.0")]
#[inline]
pub fn split_first_mut(&mut self) -> Option<(&mut T, &mut [T])> {
if self.is_empty() {
None
} else {
let split = self.split_at_mut(1);
Some((&mut split.0[0], split.1))
}
if let [first, tail @ ..] = self { Some((first, tail)) } else { None }
}

/// Returns the last and all the rest of the elements of the slice, or `None` if it is empty.
Expand All @@ -182,8 +177,7 @@ impl<T> [T] {
#[stable(feature = "slice_splits", since = "1.5.0")]
#[inline]
pub fn split_last(&self) -> Option<(&T, &[T])> {
let len = self.len();
if len == 0 { None } else { Some((&self[len - 1], &self[..(len - 1)])) }
if let [init @ .., last] = self { Some((last, init)) } else { None }
}

/// Returns the last and all the rest of the elements of the slice, or `None` if it is empty.
Expand All @@ -203,13 +197,7 @@ impl<T> [T] {
#[stable(feature = "slice_splits", since = "1.5.0")]
#[inline]
pub fn split_last_mut(&mut self) -> Option<(&mut T, &mut [T])> {
let len = self.len();
if len == 0 {
None
} else {
let split = self.split_at_mut(len - 1);
Some((&mut split.1[0], split.0))
}
if let [init @ .., last] = self { Some((last, init)) } else { None }
}

/// Returns the last element of the slice, or `None` if it is empty.
Expand All @@ -226,8 +214,7 @@ impl<T> [T] {
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn last(&self) -> Option<&T> {
let last_idx = self.len().checked_sub(1)?;
self.get(last_idx)
if let [.., last] = self { Some(last) } else { None }
}

/// Returns a mutable pointer to the last item in the slice.
Expand All @@ -245,8 +232,7 @@ impl<T> [T] {
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn last_mut(&mut self) -> Option<&mut T> {
let last_idx = self.len().checked_sub(1)?;
self.get_mut(last_idx)
if let [.., last] = self { Some(last) } else { None }
}

/// Returns a reference to an element or subslice depending on the type of
Expand Down
17 changes: 7 additions & 10 deletions src/libproc_macro/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@ pub struct Diagnostic {
}

macro_rules! diagnostic_child_methods {
($spanned:ident, $regular:ident, $level:expr) => (
($spanned:ident, $regular:ident, $level:expr) => {
/// Adds a new child diagnostic message to `self` with the level
/// identified by this method's name with the given `spans` and
/// `message`.
#[unstable(feature = "proc_macro_diagnostic", issue = "54140")]
pub fn $spanned<S, T>(mut self, spans: S, message: T) -> Diagnostic
where S: MultiSpan, T: Into<String>
where
S: MultiSpan,
T: Into<String>,
{
self.children.push(Diagnostic::spanned(spans, $level, message));
self
Expand All @@ -74,7 +76,7 @@ macro_rules! diagnostic_child_methods {
self.children.push(Diagnostic::new($level, message));
self
}
)
};
}

/// Iterator over the children diagnostics of a `Diagnostic`.
Expand All @@ -96,7 +98,7 @@ impl Diagnostic {
/// Creates a new diagnostic with the given `level` and `message`.
#[unstable(feature = "proc_macro_diagnostic", issue = "54140")]
pub fn new<T: Into<String>>(level: Level, message: T) -> Diagnostic {
Diagnostic { level: level, message: message.into(), spans: vec![], children: vec![] }
Diagnostic { level, message: message.into(), spans: vec![], children: vec![] }
}

/// Creates a new diagnostic with the given `level` and `message` pointing to
Expand All @@ -107,12 +109,7 @@ impl Diagnostic {
S: MultiSpan,
T: Into<String>,
{
Diagnostic {
level: level,
message: message.into(),
spans: spans.into_spans(),
children: vec![],
}
Diagnostic { level, message: message.into(), spans: spans.into_spans(), children: vec![] }
}

diagnostic_child_methods!(span_error, error, Level::Error);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/map/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ impl DefPath {
}
}
data.reverse();
DefPath { data: data, krate: krate }
DefPath { data, krate }
}

/// Returns a string representation of the `DefPath` without
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1446,7 +1446,7 @@ impl<'tcx> Debug for TerminatorKind<'tcx> {
match successor_count {
0 => Ok(()),

1 => write!(fmt, " -> {:?}", self.successors().nth(0).unwrap()),
1 => write!(fmt, " -> {:?}", self.successors().next().unwrap()),

_ => {
write!(fmt, " -> [")?;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/mir/mono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ pub enum Visibility {

impl<'tcx> CodegenUnit<'tcx> {
pub fn new(name: Symbol) -> CodegenUnit<'tcx> {
CodegenUnit { name: name, items: Default::default(), size_estimate: None }
CodegenUnit { name, items: Default::default(), size_estimate: None }
}

pub fn name(&self) -> Symbol {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/traits/structural_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,9 +532,9 @@ impl<'a, 'tcx> Lift<'tcx> for traits::Vtable<'a, ()> {
nested,
}) => tcx.lift(&substs).map(|substs| {
traits::VtableGenerator(traits::VtableGeneratorData {
generator_def_id: generator_def_id,
substs: substs,
nested: nested,
generator_def_id,
substs,
nested,
})
}),
traits::VtableClosure(traits::VtableClosureData { closure_def_id, substs, nested }) => {
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2256,22 +2256,22 @@ impl<'tcx> TyCtxt<'tcx> {

#[inline]
pub fn mk_mut_ref(self, r: Region<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
self.mk_ref(r, TypeAndMut { ty: ty, mutbl: hir::Mutability::Mut })
self.mk_ref(r, TypeAndMut { ty, mutbl: hir::Mutability::Mut })
}

#[inline]
pub fn mk_imm_ref(self, r: Region<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> {
self.mk_ref(r, TypeAndMut { ty: ty, mutbl: hir::Mutability::Not })
self.mk_ref(r, TypeAndMut { ty, mutbl: hir::Mutability::Not })
}

#[inline]
pub fn mk_mut_ptr(self, ty: Ty<'tcx>) -> Ty<'tcx> {
self.mk_ptr(TypeAndMut { ty: ty, mutbl: hir::Mutability::Mut })
self.mk_ptr(TypeAndMut { ty, mutbl: hir::Mutability::Mut })
}

#[inline]
pub fn mk_imm_ptr(self, ty: Ty<'tcx>) -> Ty<'tcx> {
self.mk_ptr(TypeAndMut { ty: ty, mutbl: hir::Mutability::Not })
self.mk_ptr(TypeAndMut { ty, mutbl: hir::Mutability::Not })
}

#[inline]
Expand Down Expand Up @@ -2393,7 +2393,7 @@ impl<'tcx> TyCtxt<'tcx> {

#[inline]
pub fn mk_ty_param(self, index: u32, name: Symbol) -> Ty<'tcx> {
self.mk_ty(Param(ParamTy { index, name: name }))
self.mk_ty(Param(ParamTy { index, name }))
}

#[inline]
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ impl<'tcx> Instance<'tcx> {
def_id,
substs
);
Instance { def: InstanceDef::Item(def_id), substs: substs }
Instance { def: InstanceDef::Item(def_id), substs }
}

pub fn mono(tcx: TyCtxt<'tcx>, def_id: DefId) -> Instance<'tcx> {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ pub trait DefIdTree: Copy {

impl<'tcx> DefIdTree for TyCtxt<'tcx> {
fn parent(self, id: DefId) -> Option<DefId> {
self.def_key(id).parent.map(|index| DefId { index: index, ..id })
self.def_key(id).parent.map(|index| DefId { index, ..id })
}
}

Expand Down Expand Up @@ -2227,7 +2227,7 @@ impl ReprOptions {
if !tcx.consider_optimizing(|| format!("Reorder fields of {:?}", tcx.def_path_str(did))) {
flags.insert(ReprFlags::IS_LINEAR);
}
ReprOptions { int: size, align: max_align, pack: min_pack, flags: flags }
ReprOptions { int: size, align: max_align, pack: min_pack, flags }
}

#[inline]
Expand Down
5 changes: 1 addition & 4 deletions src/librustc/ty/normalize_erasing_regions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ impl<'tcx> TyCtxt<'tcx> {
if !value.has_projections() {
value
} else {
value.fold_with(&mut NormalizeAfterErasingRegionsFolder {
tcx: self,
param_env: param_env,
})
value.fold_with(&mut NormalizeAfterErasingRegionsFolder { tcx: self, param_env })
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/relate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ impl<'tcx> Relate<'tcx> for ty::TraitRef<'tcx> {
Err(TypeError::Traits(expected_found(relation, &a.def_id, &b.def_id)))
} else {
let substs = relate_substs(relation, None, a.substs, b.substs)?;
Ok(ty::TraitRef { def_id: a.def_id, substs: substs })
Ok(ty::TraitRef { def_id: a.def_id, substs })
}
}
}
Expand All @@ -303,7 +303,7 @@ impl<'tcx> Relate<'tcx> for ty::ExistentialTraitRef<'tcx> {
Err(TypeError::Traits(expected_found(relation, &a.def_id, &b.def_id)))
} else {
let substs = relate_substs(relation, None, a.substs, b.substs)?;
Ok(ty::ExistentialTraitRef { def_id: a.def_id, substs: substs })
Ok(ty::ExistentialTraitRef { def_id: a.def_id, substs })
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,7 @@ pub struct ParamTy {

impl<'tcx> ParamTy {
pub fn new(index: u32, name: Symbol) -> ParamTy {
ParamTy { index, name: name }
ParamTy { index, name }
}

pub fn for_self() -> ParamTy {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ impl<'tcx> TyCtxt<'tcx> {
let mut dtor_did = None;
let ty = self.type_of(adt_did);
self.for_each_relevant_impl(drop_trait, ty, |impl_did| {
if let Some(item) = self.associated_items(impl_did).in_definition_order().nth(0) {
if let Some(item) = self.associated_items(impl_did).in_definition_order().next() {
if validate(self, impl_did).is_ok() {
dtor_did = Some(item.def_id);
}
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 @@ -482,7 +482,7 @@ impl<'a> TraitDef<'a> {
})
.cloned(),
);
push(Annotatable::Item(P(ast::Item { attrs: attrs, ..(*newitem).clone() })))
push(Annotatable::Item(P(ast::Item { attrs, ..(*newitem).clone() })))
}
_ => {
// Non-Item derive is an error, but it should have been
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl LlvmType for CastTarget {
.prefix
.iter()
.flat_map(|option_kind| {
option_kind.map(|kind| Reg { kind: kind, size: self.prefix_chunk }.llvm_type(cx))
option_kind.map(|kind| Reg { kind, size: self.prefix_chunk }.llvm_type(cx))
})
.chain((0..rest_count).map(|_| rest_ll_unit))
.collect();
Expand Down
27 changes: 26 additions & 1 deletion src/librustc_expand/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rustc_ast::ast::{self, Attribute, Name, NodeId, PatKind};
use rustc_ast::mut_visit::{self, MutVisitor};
use rustc_ast::ptr::P;
use rustc_ast::token;
use rustc_ast::tokenstream::{self, TokenStream};
use rustc_ast::tokenstream::{self, TokenStream, TokenTree};
use rustc_ast::visit::{AssocCtxt, Visitor};
use rustc_attr::{self as attr, Deprecation, HasAttrs, Stability};
use rustc_data_structures::fx::FxHashMap;
Expand Down Expand Up @@ -118,6 +118,31 @@ impl Annotatable {
}
}

crate fn into_tokens(self) -> TokenStream {
// `Annotatable` can be converted into tokens directly, but we
// are packing it into a nonterminal as a piece of AST to make
// the produced token stream look nicer in pretty-printed form.
let nt = match self {
Annotatable::Item(item) => token::NtItem(item),
Annotatable::TraitItem(item) | Annotatable::ImplItem(item) => {
token::NtItem(P(item.and_then(ast::AssocItem::into_item)))
}
Annotatable::ForeignItem(item) => {
token::NtItem(P(item.and_then(ast::ForeignItem::into_item)))
}
Annotatable::Stmt(stmt) => token::NtStmt(stmt.into_inner()),
Annotatable::Expr(expr) => token::NtExpr(expr),
Annotatable::Arm(..)
| Annotatable::Field(..)
| Annotatable::FieldPat(..)
| Annotatable::GenericParam(..)
| Annotatable::Param(..)
| Annotatable::StructField(..)
| Annotatable::Variant(..) => panic!("unexpected annotatable"),
};
TokenTree::token(token::Interpolated(Lrc::new(nt)), DUMMY_SP).into()
}

pub fn expect_item(self) -> P<ast::Item> {
match self {
Annotatable::Item(i) => i,
Expand Down
Loading

0 comments on commit a039217

Please sign in to comment.