Skip to content

Commit 71c7e14

Browse files
committed
Auto merge of #69004 - jonas-schievink:rollup-z2ymler, r=jonas-schievink
Rollup of 5 pull requests Successful merges: - #68738 (Derive Clone + Eq for std::string::FromUtf8Error) - #68742 (implement AsMut<str> for String) - #68881 (rustc_codegen_llvm: always set AlwaysPreserve on all debuginfo variables) - #68911 (Speed up the inherent impl overlap check) - #68913 (Pretty-print generic params and where clauses on associated types) Failed merges: r? @ghost
2 parents 1ad6b5e + da00582 commit 71c7e14

File tree

35 files changed

+194
-103
lines changed

35 files changed

+194
-103
lines changed

src/liballoc/string.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ pub struct String {
319319
/// assert_eq!(vec![0, 159], value.unwrap_err().into_bytes());
320320
/// ```
321321
#[stable(feature = "rust1", since = "1.0.0")]
322-
#[derive(Debug)]
322+
#[derive(Debug, Clone, PartialEq, Eq)]
323323
pub struct FromUtf8Error {
324324
bytes: Vec<u8>,
325325
error: Utf8Error,
@@ -2208,6 +2208,14 @@ impl AsRef<str> for String {
22082208
}
22092209
}
22102210

2211+
#[stable(feature = "string_as_mut", since = "1.43.0")]
2212+
impl AsMut<str> for String {
2213+
#[inline]
2214+
fn as_mut(&mut self) -> &mut str {
2215+
self
2216+
}
2217+
}
2218+
22112219
#[stable(feature = "rust1", since = "1.0.0")]
22122220
impl AsRef<[u8]> for String {
22132221
#[inline]

src/liballoc/tests/string.rs

+4
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ fn test_from_utf8() {
5050

5151
let xs = b"hello\xFF".to_vec();
5252
let err = String::from_utf8(xs).unwrap_err();
53+
assert_eq!(err.as_bytes(), b"hello\xff");
54+
let err_clone = err.clone();
55+
assert_eq!(err, err_clone);
5356
assert_eq!(err.into_bytes(), b"hello\xff".to_vec());
57+
assert_eq!(err_clone.utf8_error().valid_up_to(), 5);
5458
}
5559

5660
#[test]

src/librustc/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ rustc_queries! {
323323
query associated_item(_: DefId) -> ty::AssocItem {}
324324

325325
/// Collects the associated items defined on a trait or impl.
326-
query associated_items(key: DefId) -> ty::AssocItemsIterator<'tcx> {
326+
query associated_items(key: DefId) -> &'tcx [ty::AssocItem] {
327327
desc { |tcx| "collecting associated items of {}", tcx.def_path_str(key) }
328328
}
329329

src/librustc/traits/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,7 @@ fn vtable_methods<'tcx>(
541541
tcx.arena.alloc_from_iter(supertraits(tcx, trait_ref).flat_map(move |trait_ref| {
542542
let trait_methods = tcx
543543
.associated_items(trait_ref.def_id())
544+
.iter()
544545
.filter(|item| item.kind == ty::AssocKind::Method);
545546

546547
// Now list each method's DefId and InternalSubsts (for within its trait).

src/librustc/traits/object_safety.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ fn object_safety_violations_for_trait(
212212
// Check methods for violations.
213213
let mut violations: Vec<_> = tcx
214214
.associated_items(trait_def_id)
215+
.iter()
215216
.filter(|item| item.kind == ty::AssocKind::Method)
216217
.filter_map(|item| {
217218
object_safety_violation_for_method(tcx, trait_def_id, &item)
@@ -277,6 +278,7 @@ fn object_safety_violations_for_trait(
277278

278279
violations.extend(
279280
tcx.associated_items(trait_def_id)
281+
.iter()
280282
.filter(|item| item.kind == ty::AssocKind::Const)
281283
.map(|item| ObjectSafetyViolation::AssocConst(item.ident.name, item.ident.span)),
282284
);
@@ -632,7 +634,9 @@ fn object_ty_for_trait<'tcx>(
632634

633635
let mut associated_types = traits::supertraits(tcx, ty::Binder::dummy(trait_ref))
634636
.flat_map(|super_trait_ref| {
635-
tcx.associated_items(super_trait_ref.def_id()).map(move |item| (super_trait_ref, item))
637+
tcx.associated_items(super_trait_ref.def_id())
638+
.iter()
639+
.map(move |item| (super_trait_ref, item))
636640
})
637641
.filter(|(_, item)| item.kind == ty::AssocKind::Type)
638642
.collect::<Vec<_>>();

src/librustc/traits/project.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1473,7 +1473,7 @@ fn assoc_ty_def(
14731473
{
14741474
return specialization_graph::NodeItem {
14751475
node: specialization_graph::Node::Impl(impl_def_id),
1476-
item,
1476+
item: *item,
14771477
};
14781478
}
14791479
}

src/librustc/traits/types/specialization_graph.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl<'tcx> Node {
8181
}
8282

8383
/// Iterate over the items defined directly by the given (impl or trait) node.
84-
pub fn items(&self, tcx: TyCtxt<'tcx>) -> ty::AssocItemsIterator<'tcx> {
84+
pub fn items(&self, tcx: TyCtxt<'tcx>) -> &'tcx [ty::AssocItem] {
8585
tcx.associated_items(self.def_id())
8686
}
8787

@@ -98,8 +98,10 @@ impl<'tcx> Node {
9898
) -> Option<ty::AssocItem> {
9999
use crate::ty::AssocKind::*;
100100

101-
tcx.associated_items(self.def_id()).find(move |impl_item| {
102-
match (trait_item_kind, impl_item.kind) {
101+
tcx.associated_items(self.def_id())
102+
.iter()
103+
.find(move |impl_item| {
104+
match (trait_item_kind, impl_item.kind) {
103105
| (Const, Const)
104106
| (Method, Method)
105107
| (Type, Type)
@@ -112,7 +114,8 @@ impl<'tcx> Node {
112114
| (OpaqueTy, _)
113115
=> false,
114116
}
115-
})
117+
})
118+
.copied()
116119
}
117120

118121
pub fn def_id(&self) -> DefId {

src/librustc/traits/wf.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
166166
let extend_cause_with_original_assoc_item_obligation =
167167
|cause: &mut traits::ObligationCause<'_>,
168168
pred: &ty::Predicate<'_>,
169-
trait_assoc_items: ty::AssocItemsIterator<'_>| {
169+
trait_assoc_items: &[ty::AssocItem]| {
170170
let trait_item = tcx
171171
.hir()
172172
.as_local_hir_id(trait_ref.def_id)
@@ -283,6 +283,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
283283
) = (&proj.skip_binder().self_ty().kind, item.map(|i| &i.kind))
284284
{
285285
if let Some((impl_item, trait_assoc_item)) = trait_assoc_items
286+
.iter()
286287
.filter(|i| i.def_id == *item_def_id)
287288
.next()
288289
.and_then(|trait_assoc_item| {
@@ -325,7 +326,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
325326
extend_cause_with_original_assoc_item_obligation(
326327
&mut cause,
327328
&pred,
328-
trait_assoc_items.clone(),
329+
trait_assoc_items,
329330
);
330331
traits::Obligation::new(cause, param_env, pred)
331332
});

src/librustc/ty/adjustment.rs

+1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ impl<'tcx> OverloadedDeref<'tcx> {
122122
};
123123
let method_def_id = tcx
124124
.associated_items(trait_def_id.unwrap())
125+
.iter()
125126
.find(|m| m.kind == ty::AssocKind::Method)
126127
.unwrap()
127128
.def_id;

src/librustc/ty/instance.rs

+1
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ impl<'tcx> Instance<'tcx> {
376376
let fn_once = tcx.lang_items().fn_once_trait().unwrap();
377377
let call_once = tcx
378378
.associated_items(fn_once)
379+
.iter()
379380
.find(|it| it.kind == ty::AssocKind::Method)
380381
.unwrap()
381382
.def_id;

src/librustc/ty/mod.rs

+3-22
Original file line numberDiff line numberDiff line change
@@ -2705,14 +2705,14 @@ impl<'tcx> TyCtxt<'tcx> {
27052705
.for_each(|&body_id| f(self.hir().body_owner_def_id(body_id)));
27062706
}
27072707

2708-
pub fn provided_trait_methods(self, id: DefId) -> Vec<AssocItem> {
2708+
pub fn provided_trait_methods(self, id: DefId) -> impl Iterator<Item = &'tcx AssocItem> {
27092709
self.associated_items(id)
2710+
.iter()
27102711
.filter(|item| item.kind == AssocKind::Method && item.defaultness.has_value())
2711-
.collect()
27122712
}
27132713

27142714
pub fn trait_relevant_for_never(self, did: DefId) -> bool {
2715-
self.associated_items(did).any(|item| item.relevant_for_never())
2715+
self.associated_items(did).iter().any(|item| item.relevant_for_never())
27162716
}
27172717

27182718
pub fn opt_item_name(self, def_id: DefId) -> Option<Ident> {
@@ -2974,25 +2974,6 @@ impl<'tcx> TyCtxt<'tcx> {
29742974
}
29752975
}
29762976

2977-
#[derive(Copy, Clone, HashStable)]
2978-
pub struct AssocItemsIterator<'tcx> {
2979-
pub items: &'tcx [AssocItem],
2980-
}
2981-
2982-
impl<'tcx> Iterator for AssocItemsIterator<'tcx> {
2983-
type Item = AssocItem;
2984-
2985-
#[inline]
2986-
fn next(&mut self) -> Option<AssocItem> {
2987-
if let Some((first, rest)) = self.items.split_first() {
2988-
self.items = rest;
2989-
Some(*first)
2990-
} else {
2991-
None
2992-
}
2993-
}
2994-
}
2995-
29962977
#[derive(Clone, HashStable)]
29972978
pub struct AdtSizedConstraint<'tcx>(pub &'tcx [Ty<'tcx>]);
29982979

src/librustc/ty/sty.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,7 @@ impl<'tcx> ProjectionTy<'tcx> {
10661066
) -> ProjectionTy<'tcx> {
10671067
let item_def_id = tcx
10681068
.associated_items(trait_ref.def_id)
1069+
.iter()
10691070
.find(|item| {
10701071
item.kind == ty::AssocKind::Type
10711072
&& tcx.hygienic_eq(item_name, item.ident, trait_ref.def_id)

src/librustc/ty/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ impl<'tcx> TyCtxt<'tcx> {
355355
let mut dtor_did = None;
356356
let ty = self.type_of(adt_did);
357357
self.for_each_relevant_impl(drop_trait, ty, |impl_did| {
358-
if let Some(item) = self.associated_items(impl_did).next() {
358+
if let Some(item) = self.associated_items(impl_did).first() {
359359
if validate(self, impl_did).is_ok() {
360360
dtor_did = Some(item.def_id);
361361
}

src/librustc_ast_pretty/pprust.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1074,12 +1074,15 @@ impl<'a> State<'a> {
10741074
fn print_associated_type(
10751075
&mut self,
10761076
ident: ast::Ident,
1077+
generics: &ast::Generics,
10771078
bounds: &ast::GenericBounds,
10781079
ty: Option<&ast::Ty>,
10791080
) {
10801081
self.word_space("type");
10811082
self.print_ident(ident);
1083+
self.print_generic_params(&generics.params);
10821084
self.print_type_bounds(":", bounds);
1085+
self.print_where_clause(&generics.where_clause);
10831086
if let Some(ty) = ty {
10841087
self.s.space();
10851088
self.word_space("=");
@@ -1474,7 +1477,7 @@ impl<'a> State<'a> {
14741477
self.print_fn_full(sig, item.ident, &item.generics, &item.vis, body, &item.attrs);
14751478
}
14761479
ast::AssocItemKind::TyAlias(bounds, ty) => {
1477-
self.print_associated_type(item.ident, bounds, ty.as_deref());
1480+
self.print_associated_type(item.ident, &item.generics, bounds, ty.as_deref());
14781481
}
14791482
ast::AssocItemKind::Macro(mac) => {
14801483
self.print_mac(mac);

src/librustc_codegen_llvm/debuginfo/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
559559
file_metadata,
560560
loc.line as c_uint,
561561
type_metadata,
562-
self.sess().opts.optimize != config::OptLevel::No,
562+
true,
563563
DIFlags::FlagZero,
564564
argument_index,
565565
align.bytes() as u32,

src/librustc_hir/print.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -454,14 +454,17 @@ impl<'a> State<'a> {
454454
fn print_associated_type(
455455
&mut self,
456456
ident: ast::Ident,
457+
generics: &hir::Generics<'_>,
457458
bounds: Option<hir::GenericBounds<'_>>,
458459
ty: Option<&hir::Ty<'_>>,
459460
) {
460461
self.word_space("type");
461462
self.print_ident(ident);
463+
self.print_generic_params(&generics.params);
462464
if let Some(bounds) = bounds {
463465
self.print_bounds(":", bounds);
464466
}
467+
self.print_where_clause(&generics.where_clause);
465468
if let Some(ty) = ty {
466469
self.s.space();
467470
self.word_space("=");
@@ -902,6 +905,7 @@ impl<'a> State<'a> {
902905
hir::TraitItemKind::Type(ref bounds, ref default) => {
903906
self.print_associated_type(
904907
ti.ident,
908+
&ti.generics,
905909
Some(bounds),
906910
default.as_ref().map(|ty| &**ty),
907911
);
@@ -930,7 +934,7 @@ impl<'a> State<'a> {
930934
self.ann.nested(self, Nested::Body(body));
931935
}
932936
hir::ImplItemKind::TyAlias(ref ty) => {
933-
self.print_associated_type(ii.ident, None, Some(ty));
937+
self.print_associated_type(ii.ident, &ii.generics, None, Some(ty));
934938
}
935939
hir::ImplItemKind::OpaqueTy(bounds) => {
936940
self.word_space("type");

src/librustc_mir/shim.rs

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> &'tcx
6868
let fn_mut = tcx.lang_items().fn_mut_trait().unwrap();
6969
let call_mut = tcx
7070
.associated_items(fn_mut)
71+
.iter()
7172
.find(|it| it.kind == ty::AssocKind::Method)
7273
.unwrap()
7374
.def_id;

src/librustc_mir/util/elaborate_drops.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ where
539539
debug!("destructor_call_block({:?}, {:?})", self, succ);
540540
let tcx = self.tcx();
541541
let drop_trait = tcx.lang_items().drop_trait().unwrap();
542-
let drop_fn = tcx.associated_items(drop_trait).next().unwrap();
542+
let drop_fn = tcx.associated_items(drop_trait)[0];
543543
let ty = self.place_ty(self.place);
544544
let substs = tcx.mk_substs_trait(ty, &[]);
545545

src/librustc_passes/reachable.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,12 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, 'tcx
362362
return;
363363
}
364364

365-
let provided_trait_methods = self.tcx.provided_trait_methods(trait_def_id);
366-
self.worklist.reserve(provided_trait_methods.len());
367-
for default_method in provided_trait_methods {
368-
let hir_id = self.tcx.hir().as_local_hir_id(default_method.def_id).unwrap();
369-
self.worklist.push(hir_id);
370-
}
365+
// FIXME(#53488) remove `let`
366+
let tcx = self.tcx;
367+
self.worklist.extend(
368+
tcx.provided_trait_methods(trait_def_id)
369+
.map(|assoc| tcx.hir().as_local_hir_id(assoc.def_id).unwrap()),
370+
);
371371
}
372372
}
373373
}

src/librustc_passes/stability.rs

+1
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ impl Visitor<'tcx> for Checker<'tcx> {
468468
let trait_item_def_id = self
469469
.tcx
470470
.associated_items(trait_did)
471+
.iter()
471472
.find(|item| item.ident.name == impl_item.ident.name)
472473
.map(|item| item.def_id);
473474
if let Some(def_id) = trait_item_def_id {

src/librustc_save_analysis/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
423423
qualname.push_str(&self.tcx.def_path_str(def_id));
424424
self.tcx
425425
.associated_items(def_id)
426+
.iter()
426427
.find(|item| item.ident.name == ident.name)
427428
.map(|item| decl_id = Some(item.def_id));
428429
}
@@ -717,6 +718,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
717718
let ti = self.tcx.associated_item(decl_id);
718719
self.tcx
719720
.associated_items(ti.container.id())
721+
.iter()
720722
.find(|item| {
721723
item.ident.name == ti.ident.name && item.defaultness.has_value()
722724
})

src/librustc_ty/ty.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,10 @@ fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: DefId) -> &[DefId] {
206206
}
207207
}
208208

209-
fn associated_items<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> ty::AssocItemsIterator<'tcx> {
210-
ty::AssocItemsIterator {
211-
items: tcx.arena.alloc_from_iter(
212-
tcx.associated_item_def_ids(def_id).iter().map(|did| tcx.associated_item(*did)),
213-
),
214-
}
209+
fn associated_items<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx [ty::AssocItem] {
210+
tcx.arena.alloc_from_iter(
211+
tcx.associated_item_def_ids(def_id).iter().map(|did| tcx.associated_item(*did)),
212+
)
215213
}
216214

217215
fn def_span(tcx: TyCtxt<'_>, def_id: DefId) -> Span {

0 commit comments

Comments
 (0)