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

Lines changed: 9 additions & 1 deletion
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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 5 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 7 additions & 4 deletions
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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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;

0 commit comments

Comments
 (0)