Skip to content

Commit 0913800

Browse files
committed
Auto merge of #59760 - Centril:rollup-4b9x7ue, r=Centril
Rollup of 5 pull requests Successful merges: - #59738 (Move match_path from DefId to lint::LateContext) - #59740 (Use for_each to extend collections) - #59751 (Tiny docs fix) - #59754 (Update books) - #59755 (Update miri) Failed merges: r? @ghost
2 parents 8159f38 + 4601ff0 commit 0913800

File tree

16 files changed

+129
-134
lines changed

16 files changed

+129
-134
lines changed

src/doc/nomicon

src/doc/reference

src/liballoc/collections/binary_heap.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1177,9 +1177,7 @@ impl<T: Ord> BinaryHeap<T> {
11771177

11781178
self.reserve(lower);
11791179

1180-
for elem in iterator {
1181-
self.push(elem);
1182-
}
1180+
iterator.for_each(move |elem| self.push(elem));
11831181
}
11841182
}
11851183

src/liballoc/collections/btree/map.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1727,9 +1727,9 @@ impl<K: Ord, V> FromIterator<(K, V)> for BTreeMap<K, V> {
17271727
impl<K: Ord, V> Extend<(K, V)> for BTreeMap<K, V> {
17281728
#[inline]
17291729
fn extend<T: IntoIterator<Item = (K, V)>>(&mut self, iter: T) {
1730-
for (k, v) in iter {
1730+
iter.into_iter().for_each(move |(k, v)| {
17311731
self.insert(k, v);
1732-
}
1732+
});
17331733
}
17341734
}
17351735

src/liballoc/collections/btree/set.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -883,9 +883,9 @@ impl<'a, T> IntoIterator for &'a BTreeSet<T> {
883883
impl<T: Ord> Extend<T> for BTreeSet<T> {
884884
#[inline]
885885
fn extend<Iter: IntoIterator<Item = T>>(&mut self, iter: Iter) {
886-
for elem in iter {
886+
iter.into_iter().for_each(move |elem| {
887887
self.insert(elem);
888-
}
888+
});
889889
}
890890
}
891891

src/liballoc/collections/linked_list.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1107,9 +1107,7 @@ impl<T> Extend<T> for LinkedList<T> {
11071107

11081108
impl<I: IntoIterator> SpecExtend<I> for LinkedList<I::Item> {
11091109
default fn spec_extend(&mut self, iter: I) {
1110-
for elt in iter {
1111-
self.push_back(elt);
1112-
}
1110+
iter.into_iter().for_each(move |elt| self.push_back(elt));
11131111
}
11141112
}
11151113

src/liballoc/collections/vec_deque.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -2677,9 +2677,7 @@ impl<'a, T> IntoIterator for &'a mut VecDeque<T> {
26772677
#[stable(feature = "rust1", since = "1.0.0")]
26782678
impl<A> Extend<A> for VecDeque<A> {
26792679
fn extend<T: IntoIterator<Item = A>>(&mut self, iter: T) {
2680-
for elt in iter {
2681-
self.push_back(elt);
2682-
}
2680+
iter.into_iter().for_each(move |elt| self.push_back(elt));
26832681
}
26842682
}
26852683

src/libcore/benches/ascii.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// after wrap-adding 0x1F:
33
//
44
// b'a' + 0x1F == 0x80 == 0b1000_0000
5-
// b'z' + 0x1F == 0x98 == 0b10011000
5+
// b'z' + 0x1F == 0x98 == 0b1001_1000
66
//
77
// Lower-case ASCII 'z' is the last byte that has its highest bit unset
88
// after wrap-adding 0x05:

src/libproc_macro/lib.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,7 @@ impl iter::FromIterator<TokenTree> for TokenStream {
160160
impl iter::FromIterator<TokenStream> for TokenStream {
161161
fn from_iter<I: IntoIterator<Item = TokenStream>>(streams: I) -> Self {
162162
let mut builder = bridge::client::TokenStreamBuilder::new();
163-
for stream in streams {
164-
builder.push(stream.0);
165-
}
163+
streams.into_iter().for_each(|stream| builder.push(stream.0));
166164
TokenStream(builder.build())
167165
}
168166
}

src/librustc/hir/def_id.rs

+2-104
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
use crate::ty::{self, print::Printer, subst::Kind, Ty, TyCtxt};
2-
use crate::hir::map::definitions::{DisambiguatedDefPathData, FIRST_FREE_HIGH_DEF_INDEX};
1+
use crate::ty::{self, TyCtxt};
2+
use crate::hir::map::definitions::FIRST_FREE_HIGH_DEF_INDEX;
33
use rustc_data_structures::indexed_vec::Idx;
44
use serialize;
55
use std::fmt;
66
use std::u32;
7-
use syntax::symbol::{LocalInternedString, Symbol};
87

98
newtype_index! {
109
pub struct CrateId {
@@ -252,107 +251,6 @@ impl DefId {
252251
format!("module `{}`", tcx.def_path_str(*self))
253252
}
254253
}
255-
256-
/// Check if a `DefId`'s path matches the given absolute type path usage.
257-
// Uplifted from rust-lang/rust-clippy
258-
pub fn match_path<'a, 'tcx>(self, tcx: TyCtxt<'a, 'tcx, 'tcx>, path: &[&str]) -> bool {
259-
pub struct AbsolutePathPrinter<'a, 'tcx> {
260-
pub tcx: TyCtxt<'a, 'tcx, 'tcx>,
261-
}
262-
263-
impl<'tcx> Printer<'tcx, 'tcx> for AbsolutePathPrinter<'_, 'tcx> {
264-
type Error = !;
265-
266-
type Path = Vec<LocalInternedString>;
267-
type Region = ();
268-
type Type = ();
269-
type DynExistential = ();
270-
271-
fn tcx<'a>(&'a self) -> TyCtxt<'a, 'tcx, 'tcx> {
272-
self.tcx
273-
}
274-
275-
fn print_region(self, _region: ty::Region<'_>) -> Result<Self::Region, Self::Error> {
276-
Ok(())
277-
}
278-
279-
fn print_type(self, _ty: Ty<'tcx>) -> Result<Self::Type, Self::Error> {
280-
Ok(())
281-
}
282-
283-
fn print_dyn_existential(
284-
self,
285-
_predicates: &'tcx ty::List<ty::ExistentialPredicate<'tcx>>,
286-
) -> Result<Self::DynExistential, Self::Error> {
287-
Ok(())
288-
}
289-
290-
fn path_crate(self, cnum: CrateNum) -> Result<Self::Path, Self::Error> {
291-
Ok(vec![self.tcx.original_crate_name(cnum).as_str()])
292-
}
293-
294-
fn path_qualified(
295-
self,
296-
self_ty: Ty<'tcx>,
297-
trait_ref: Option<ty::TraitRef<'tcx>>,
298-
) -> Result<Self::Path, Self::Error> {
299-
if trait_ref.is_none() {
300-
if let ty::Adt(def, substs) = self_ty.sty {
301-
return self.print_def_path(def.did, substs);
302-
}
303-
}
304-
305-
// This shouldn't ever be needed, but just in case:
306-
Ok(vec![match trait_ref {
307-
Some(trait_ref) => Symbol::intern(&format!("{:?}", trait_ref)).as_str(),
308-
None => Symbol::intern(&format!("<{}>", self_ty)).as_str(),
309-
}])
310-
}
311-
312-
fn path_append_impl(
313-
self,
314-
print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
315-
_disambiguated_data: &DisambiguatedDefPathData,
316-
self_ty: Ty<'tcx>,
317-
trait_ref: Option<ty::TraitRef<'tcx>>,
318-
) -> Result<Self::Path, Self::Error> {
319-
let mut path = print_prefix(self)?;
320-
321-
// This shouldn't ever be needed, but just in case:
322-
path.push(match trait_ref {
323-
Some(trait_ref) => {
324-
Symbol::intern(&format!("<impl {} for {}>", trait_ref, self_ty)).as_str()
325-
},
326-
None => Symbol::intern(&format!("<impl {}>", self_ty)).as_str(),
327-
});
328-
329-
Ok(path)
330-
}
331-
332-
fn path_append(
333-
self,
334-
print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
335-
disambiguated_data: &DisambiguatedDefPathData,
336-
) -> Result<Self::Path, Self::Error> {
337-
let mut path = print_prefix(self)?;
338-
path.push(disambiguated_data.data.as_interned_str().as_str());
339-
Ok(path)
340-
}
341-
342-
fn path_generic_args(
343-
self,
344-
print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
345-
_args: &[Kind<'tcx>],
346-
) -> Result<Self::Path, Self::Error> {
347-
print_prefix(self)
348-
}
349-
}
350-
351-
let names = AbsolutePathPrinter { tcx }.print_def_path(self, &[]).unwrap();
352-
353-
names.len() == path.len()
354-
&& names.into_iter().zip(path.iter()).all(|(a, &b)| *a == *b)
355-
}
356254
}
357255

358256
impl serialize::UseSpecializedEncodable for DefId {}

src/librustc/lint/context.rs

+111-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::lint::levels::{LintLevelSets, LintLevelsBuilder};
2525
use crate::middle::privacy::AccessLevels;
2626
use crate::rustc_serialize::{Decoder, Decodable, Encoder, Encodable};
2727
use crate::session::{config, early_error, Session};
28-
use crate::ty::{self, TyCtxt, Ty};
28+
use crate::ty::{self, print::Printer, subst::Kind, TyCtxt, Ty};
2929
use crate::ty::layout::{LayoutError, LayoutOf, TyLayout};
3030
use crate::util::nodemap::FxHashMap;
3131
use crate::util::common::time;
@@ -36,9 +36,10 @@ use syntax::edition;
3636
use syntax_pos::{MultiSpan, Span, symbol::{LocalInternedString, Symbol}};
3737
use errors::DiagnosticBuilder;
3838
use crate::hir;
39-
use crate::hir::def_id::{DefId, LOCAL_CRATE};
39+
use crate::hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
4040
use crate::hir::intravisit as hir_visit;
4141
use crate::hir::intravisit::Visitor;
42+
use crate::hir::map::{definitions::DisambiguatedDefPathData, DefPathData};
4243
use syntax::util::lev_distance::find_best_match_for_name;
4344
use syntax::visit as ast_visit;
4445

@@ -752,6 +753,114 @@ impl<'a, 'tcx> LateContext<'a, 'tcx> {
752753
pub fn current_lint_root(&self) -> hir::HirId {
753754
self.last_node_with_lint_attrs
754755
}
756+
757+
/// Check if a `DefId`'s path matches the given absolute type path usage.
758+
// Uplifted from rust-lang/rust-clippy
759+
pub fn match_path(&self, def_id: DefId, path: &[&str]) -> bool {
760+
pub struct AbsolutePathPrinter<'a, 'tcx> {
761+
pub tcx: TyCtxt<'a, 'tcx, 'tcx>,
762+
}
763+
764+
impl<'tcx> Printer<'tcx, 'tcx> for AbsolutePathPrinter<'_, 'tcx> {
765+
type Error = !;
766+
767+
type Path = Vec<LocalInternedString>;
768+
type Region = ();
769+
type Type = ();
770+
type DynExistential = ();
771+
772+
fn tcx<'a>(&'a self) -> TyCtxt<'a, 'tcx, 'tcx> {
773+
self.tcx
774+
}
775+
776+
fn print_region(self, _region: ty::Region<'_>) -> Result<Self::Region, Self::Error> {
777+
Ok(())
778+
}
779+
780+
fn print_type(self, _ty: Ty<'tcx>) -> Result<Self::Type, Self::Error> {
781+
Ok(())
782+
}
783+
784+
fn print_dyn_existential(
785+
self,
786+
_predicates: &'tcx ty::List<ty::ExistentialPredicate<'tcx>>,
787+
) -> Result<Self::DynExistential, Self::Error> {
788+
Ok(())
789+
}
790+
791+
fn path_crate(self, cnum: CrateNum) -> Result<Self::Path, Self::Error> {
792+
Ok(vec![self.tcx.original_crate_name(cnum).as_str()])
793+
}
794+
795+
fn path_qualified(
796+
self,
797+
self_ty: Ty<'tcx>,
798+
trait_ref: Option<ty::TraitRef<'tcx>>,
799+
) -> Result<Self::Path, Self::Error> {
800+
if trait_ref.is_none() {
801+
if let ty::Adt(def, substs) = self_ty.sty {
802+
return self.print_def_path(def.did, substs);
803+
}
804+
}
805+
806+
// This shouldn't ever be needed, but just in case:
807+
Ok(vec![match trait_ref {
808+
Some(trait_ref) => Symbol::intern(&format!("{:?}", trait_ref)).as_str(),
809+
None => Symbol::intern(&format!("<{}>", self_ty)).as_str(),
810+
}])
811+
}
812+
813+
fn path_append_impl(
814+
self,
815+
print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
816+
_disambiguated_data: &DisambiguatedDefPathData,
817+
self_ty: Ty<'tcx>,
818+
trait_ref: Option<ty::TraitRef<'tcx>>,
819+
) -> Result<Self::Path, Self::Error> {
820+
let mut path = print_prefix(self)?;
821+
822+
// This shouldn't ever be needed, but just in case:
823+
path.push(match trait_ref {
824+
Some(trait_ref) => {
825+
Symbol::intern(&format!("<impl {} for {}>", trait_ref, self_ty)).as_str()
826+
},
827+
None => Symbol::intern(&format!("<impl {}>", self_ty)).as_str(),
828+
});
829+
830+
Ok(path)
831+
}
832+
833+
fn path_append(
834+
self,
835+
print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
836+
disambiguated_data: &DisambiguatedDefPathData,
837+
) -> Result<Self::Path, Self::Error> {
838+
let mut path = print_prefix(self)?;
839+
840+
// Skip `::{{constructor}}` on tuple/unit structs.
841+
match disambiguated_data.data {
842+
DefPathData::Ctor => return Ok(path),
843+
_ => {}
844+
}
845+
846+
path.push(disambiguated_data.data.as_interned_str().as_str());
847+
Ok(path)
848+
}
849+
850+
fn path_generic_args(
851+
self,
852+
print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
853+
_args: &[Kind<'tcx>],
854+
) -> Result<Self::Path, Self::Error> {
855+
print_prefix(self)
856+
}
857+
}
858+
859+
let names = AbsolutePathPrinter { tcx: self.tcx }.print_def_path(def_id, &[]).unwrap();
860+
861+
names.len() == path.len()
862+
&& names.into_iter().zip(path.iter()).all(|(a, &b)| *a == *b)
863+
}
755864
}
756865

757866
impl<'a, 'tcx> LayoutOf for LateContext<'a, 'tcx> {

src/librustc/lint/internal.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ fn lint_ty_kind_usage(cx: &LateContext<'_, '_>, segment: &PathSegment) -> bool {
100100
if segment.ident.as_str() == "TyKind" {
101101
if let Some(def) = segment.def {
102102
if let Some(did) = def.opt_def_id() {
103-
return did.match_path(cx.tcx, &["rustc", "ty", "sty", "TyKind"]);
103+
return cx.match_path(did, &["rustc", "ty", "sty", "TyKind"]);
104104
}
105105
}
106106
}

src/libstd/path.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1551,9 +1551,7 @@ impl<P: AsRef<Path>> iter::FromIterator<P> for PathBuf {
15511551
#[stable(feature = "rust1", since = "1.0.0")]
15521552
impl<P: AsRef<Path>> iter::Extend<P> for PathBuf {
15531553
fn extend<I: IntoIterator<Item = P>>(&mut self, iter: I) {
1554-
for p in iter {
1555-
self.push(p.as_ref())
1556-
}
1554+
iter.into_iter().for_each(move |p| self.push(p.as_ref()));
15571555
}
15581556
}
15591557

src/libstd/sys_common/wtf8.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,7 @@ impl Extend<CodePoint> for Wtf8Buf {
388388
let (low, _high) = iterator.size_hint();
389389
// Lower bound of one byte per code point (ASCII only)
390390
self.bytes.reserve(low);
391-
for code_point in iterator {
392-
self.push(code_point);
393-
}
391+
iterator.for_each(move |code_point| self.push(code_point));
394392
}
395393
}
396394

0 commit comments

Comments
 (0)