Skip to content

Commit a039217

Browse files
committed
Auto merge of #69796 - Centril:rollup-xg85jmx, r=Centril
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
2 parents 2890b37 + 709325a commit a039217

File tree

102 files changed

+1311
-215
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+1311
-215
lines changed

src/liballoc/collections/linked_list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,7 @@ impl<T> LinkedList<T> {
959959
let it = self.head;
960960
let old_len = self.len;
961961

962-
DrainFilter { list: self, it: it, pred: filter, idx: 0, old_len: old_len }
962+
DrainFilter { list: self, it, pred: filter, idx: 0, old_len }
963963
}
964964
}
965965

src/liballoc/vec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1659,7 +1659,7 @@ struct SetLenOnDrop<'a> {
16591659
impl<'a> SetLenOnDrop<'a> {
16601660
#[inline]
16611661
fn new(len: &'a mut usize) -> Self {
1662-
SetLenOnDrop { local_len: *len, len: len }
1662+
SetLenOnDrop { local_len: *len, len }
16631663
}
16641664

16651665
#[inline]

src/libcore/slice/mod.rs

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ impl<T> [T] {
103103
#[stable(feature = "rust1", since = "1.0.0")]
104104
#[inline]
105105
pub fn first(&self) -> Option<&T> {
106-
self.get(0)
106+
if let [first, ..] = self { Some(first) } else { None }
107107
}
108108

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

127127
/// 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] {
139139
#[stable(feature = "slice_splits", since = "1.5.0")]
140140
#[inline]
141141
pub fn split_first(&self) -> Option<(&T, &[T])> {
142-
if self.is_empty() { None } else { Some((&self[0], &self[1..])) }
142+
if let [first, tail @ ..] = self { Some((first, tail)) } else { None }
143143
}
144144

145145
/// 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] {
159159
#[stable(feature = "slice_splits", since = "1.5.0")]
160160
#[inline]
161161
pub fn split_first_mut(&mut self) -> Option<(&mut T, &mut [T])> {
162-
if self.is_empty() {
163-
None
164-
} else {
165-
let split = self.split_at_mut(1);
166-
Some((&mut split.0[0], split.1))
167-
}
162+
if let [first, tail @ ..] = self { Some((first, tail)) } else { None }
168163
}
169164

170165
/// 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] {
182177
#[stable(feature = "slice_splits", since = "1.5.0")]
183178
#[inline]
184179
pub fn split_last(&self) -> Option<(&T, &[T])> {
185-
let len = self.len();
186-
if len == 0 { None } else { Some((&self[len - 1], &self[..(len - 1)])) }
180+
if let [init @ .., last] = self { Some((last, init)) } else { None }
187181
}
188182

189183
/// 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] {
203197
#[stable(feature = "slice_splits", since = "1.5.0")]
204198
#[inline]
205199
pub fn split_last_mut(&mut self) -> Option<(&mut T, &mut [T])> {
206-
let len = self.len();
207-
if len == 0 {
208-
None
209-
} else {
210-
let split = self.split_at_mut(len - 1);
211-
Some((&mut split.1[0], split.0))
212-
}
200+
if let [init @ .., last] = self { Some((last, init)) } else { None }
213201
}
214202

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

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

252238
/// Returns a reference to an element or subslice depending on the type of

src/libproc_macro/diagnostic.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,15 @@ pub struct Diagnostic {
5555
}
5656

5757
macro_rules! diagnostic_child_methods {
58-
($spanned:ident, $regular:ident, $level:expr) => (
58+
($spanned:ident, $regular:ident, $level:expr) => {
5959
/// Adds a new child diagnostic message to `self` with the level
6060
/// identified by this method's name with the given `spans` and
6161
/// `message`.
6262
#[unstable(feature = "proc_macro_diagnostic", issue = "54140")]
6363
pub fn $spanned<S, T>(mut self, spans: S, message: T) -> Diagnostic
64-
where S: MultiSpan, T: Into<String>
64+
where
65+
S: MultiSpan,
66+
T: Into<String>,
6567
{
6668
self.children.push(Diagnostic::spanned(spans, $level, message));
6769
self
@@ -74,7 +76,7 @@ macro_rules! diagnostic_child_methods {
7476
self.children.push(Diagnostic::new($level, message));
7577
self
7678
}
77-
)
79+
};
7880
}
7981

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

102104
/// Creates a new diagnostic with the given `level` and `message` pointing to
@@ -107,12 +109,7 @@ impl Diagnostic {
107109
S: MultiSpan,
108110
T: Into<String>,
109111
{
110-
Diagnostic {
111-
level: level,
112-
message: message.into(),
113-
spans: spans.into_spans(),
114-
children: vec![],
115-
}
112+
Diagnostic { level, message: message.into(), spans: spans.into_spans(), children: vec![] }
116113
}
117114

118115
diagnostic_child_methods!(span_error, error, Level::Error);

src/librustc/hir/map/definitions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ impl DefPath {
192192
}
193193
}
194194
data.reverse();
195-
DefPath { data: data, krate: krate }
195+
DefPath { data, krate }
196196
}
197197

198198
/// Returns a string representation of the `DefPath` without

src/librustc/mir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1446,7 +1446,7 @@ impl<'tcx> Debug for TerminatorKind<'tcx> {
14461446
match successor_count {
14471447
0 => Ok(()),
14481448

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

14511451
_ => {
14521452
write!(fmt, " -> [")?;

src/librustc/mir/mono.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ pub enum Visibility {
258258

259259
impl<'tcx> CodegenUnit<'tcx> {
260260
pub fn new(name: Symbol) -> CodegenUnit<'tcx> {
261-
CodegenUnit { name: name, items: Default::default(), size_estimate: None }
261+
CodegenUnit { name, items: Default::default(), size_estimate: None }
262262
}
263263

264264
pub fn name(&self) -> Symbol {

src/librustc/traits/structural_impls.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -532,9 +532,9 @@ impl<'a, 'tcx> Lift<'tcx> for traits::Vtable<'a, ()> {
532532
nested,
533533
}) => tcx.lift(&substs).map(|substs| {
534534
traits::VtableGenerator(traits::VtableGeneratorData {
535-
generator_def_id: generator_def_id,
536-
substs: substs,
537-
nested: nested,
535+
generator_def_id,
536+
substs,
537+
nested,
538538
})
539539
}),
540540
traits::VtableClosure(traits::VtableClosureData { closure_def_id, substs, nested }) => {

src/librustc/ty/context.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2256,22 +2256,22 @@ impl<'tcx> TyCtxt<'tcx> {
22562256

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

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

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

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

22772277
#[inline]
@@ -2393,7 +2393,7 @@ impl<'tcx> TyCtxt<'tcx> {
23932393

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

23992399
#[inline]

src/librustc/ty/instance.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ impl<'tcx> Instance<'tcx> {
241241
def_id,
242242
substs
243243
);
244-
Instance { def: InstanceDef::Item(def_id), substs: substs }
244+
Instance { def: InstanceDef::Item(def_id), substs }
245245
}
246246

247247
pub fn mono(tcx: TyCtxt<'tcx>, def_id: DefId) -> Instance<'tcx> {

0 commit comments

Comments
 (0)