Skip to content

Rollup of 9 pull requests #69796

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

Merged
merged 32 commits into from
Mar 7, 2020
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
940f657
Parse & reject postfix operators after casts
daboross Feb 9, 2020
5ce9b80
Refactor out error case & apply suggestions.
daboross Feb 16, 2020
4fc0532
Type ascription outputs a Type, not Cast
daboross Feb 16, 2020
0cf2049
Keep better fix suggestion if type ascription is likely unintended
daboross Feb 16, 2020
f82ca8b
Add more error cases to issue 35813 tests
daboross Feb 16, 2020
5dd6464
Fix related type ascription tests.
daboross Feb 16, 2020
e3eefe2
Remove extra debug print in unreachable!
daboross Feb 16, 2020
c2d7ffb
Remove trailing whitespace
daboross Feb 16, 2020
8ef3da0
Fix test stderr after rebasing on master.
daboross Feb 16, 2020
fa1f547
Add more double cast + method call tests
daboross Feb 22, 2020
f434c6e
Use multipart suggestion
daboross Feb 22, 2020
453c505
Replace ptr hashing with ptr casting
daboross Feb 25, 2020
d3e5177
Use .next() instead of .nth(0) on iterators.
matthiaskrgr Mar 3, 2020
5456114
test(pattern): add tests for combinations of pattern features
thekuom Mar 4, 2020
b4788a7
test(pattern): harden tests for or-patterns with slice-patterns
thekuom Mar 4, 2020
ea7b3c3
fix tidy error
thekuom Mar 4, 2020
53be0cc
Use subslice patterns in slice methods
cuviper Mar 4, 2020
9afbf28
Update deprecation version to 1.42 for Error::description
dylnuge Mar 6, 2020
2d0c5b4
rustc_expand: Factor out `Annotatable::into_tokens` to a separate method
petrochenkov Mar 3, 2020
83980ac
Don't redundantly repeat field names (clippy::redundant_field_names)
matthiaskrgr Mar 6, 2020
1631b4d
Avoid using `unwrap()` in suggestions
JohnTitor Mar 5, 2020
3d67649
Add a regression test
JohnTitor Mar 6, 2020
125159f
When encountering an Item in a pat context, point at the item def
estebank Dec 30, 2019
e8bb6c0
Rollup merge of #67741 - estebank:point-at-pat-def, r=Centril
Centril Mar 7, 2020
111724f
Rollup merge of #68985 - daboross:fix-35813, r=Centril
Centril Mar 7, 2020
5d1433b
Rollup merge of #69656 - matthiaskrgr:iter_nth_zero, r=oli-obk
Centril Mar 7, 2020
e9c3ddc
Rollup merge of #69680 - petrochenkov:nont4, r=Centril
Centril Mar 7, 2020
ba1f6cb
Rollup merge of #69690 - thekuom:test/67311-extend-bindings-after-at-…
Centril Mar 7, 2020
b25fb9e
Rollup merge of #69706 - cuviper:subslice-methods, r=Centril
Centril Mar 7, 2020
93a57cf
Rollup merge of #69727 - JohnTitor:sugg-unwrap, r=estebank
Centril Mar 7, 2020
ca90c3d
Rollup merge of #69754 - Dylnuge:dylnuge/dep-version, r=Mark-Simulacrum
Centril Mar 7, 2020
709325a
Rollup merge of #69782 - matthiaskrgr:redundant_field_name_rep, r=cra…
Centril Mar 7, 2020
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
2 changes: 1 addition & 1 deletion src/liballoc/collections/linked_list.rs
Original file line number Diff line number Diff line change
@@ -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 }
}
}

2 changes: 1 addition & 1 deletion src/liballoc/vec.rs
Original file line number Diff line number Diff line change
@@ -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]
30 changes: 8 additions & 22 deletions src/libcore/slice/mod.rs
Original file line number Diff line number Diff line change
@@ -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.
@@ -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.
@@ -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.
@@ -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.
@@ -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.
@@ -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.
@@ -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.
@@ -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
17 changes: 7 additions & 10 deletions src/libproc_macro/diagnostic.rs
Original file line number Diff line number Diff line change
@@ -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
@@ -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`.
@@ -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
@@ -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);
2 changes: 1 addition & 1 deletion src/librustc/hir/map/definitions.rs
Original file line number Diff line number Diff line change
@@ -192,7 +192,7 @@ impl DefPath {
}
}
data.reverse();
DefPath { data: data, krate: krate }
DefPath { data, krate }
}

/// Returns a string representation of the `DefPath` without
2 changes: 1 addition & 1 deletion src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
@@ -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, " -> [")?;
2 changes: 1 addition & 1 deletion src/librustc/mir/mono.rs
Original file line number Diff line number Diff line change
@@ -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 {
6 changes: 3 additions & 3 deletions src/librustc/traits/structural_impls.rs
Original file line number Diff line number Diff line change
@@ -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 }) => {
10 changes: 5 additions & 5 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
@@ -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]
@@ -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]
2 changes: 1 addition & 1 deletion src/librustc/ty/instance.rs
Original file line number Diff line number Diff line change
@@ -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> {
4 changes: 2 additions & 2 deletions src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
@@ -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 })
}
}

@@ -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]
5 changes: 1 addition & 4 deletions src/librustc/ty/normalize_erasing_regions.rs
Original file line number Diff line number Diff line change
@@ -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 })
}
}

4 changes: 2 additions & 2 deletions src/librustc/ty/relate.rs
Original file line number Diff line number Diff line change
@@ -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 })
}
}
}
@@ -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 })
}
}
}
2 changes: 1 addition & 1 deletion src/librustc/ty/sty.rs
Original file line number Diff line number Diff line change
@@ -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 {
2 changes: 1 addition & 1 deletion src/librustc/ty/util.rs
Original file line number Diff line number Diff line change
@@ -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);
}
2 changes: 1 addition & 1 deletion src/librustc_builtin_macros/deriving/generic/mod.rs
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/abi.rs
Original file line number Diff line number Diff line change
@@ -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();
27 changes: 26 additions & 1 deletion src/librustc_expand/base.rs
Original file line number Diff line number Diff line change
@@ -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;
@@ -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,
Loading