Skip to content

Commit a501e66

Browse files
committed
Auto merge of #103125 - matthiaskrgr:rollup-82xttcl, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - #103087 (Documentation BTreeMap::append's behavior for already existing keys) - #103089 (Mark derived StructuralEq as automatically derived.) - #103102 (Clarify the possible return values of `len_utf16`) - #103109 (PhantomData: inline a macro that is used only once) - #103120 (rustdoc: Do not expect `doc(primitive)` modules to always exist) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents b8b5cae + db30a25 commit a501e66

File tree

9 files changed

+156
-97
lines changed

9 files changed

+156
-97
lines changed

compiler/rustc_builtin_macros/src/deriving/mod.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -131,23 +131,27 @@ fn inject_impl_of_structural_trait(
131131
// Create generics param list for where clauses and impl headers
132132
let mut generics = generics.clone();
133133

134+
let ctxt = span.ctxt();
135+
134136
// Create the type of `self`.
135137
//
136138
// in addition, remove defaults from generic params (impls cannot have them).
137139
let self_params: Vec<_> = generics
138140
.params
139141
.iter_mut()
140142
.map(|param| match &mut param.kind {
141-
ast::GenericParamKind::Lifetime => {
142-
ast::GenericArg::Lifetime(cx.lifetime(span, param.ident))
143-
}
143+
ast::GenericParamKind::Lifetime => ast::GenericArg::Lifetime(
144+
cx.lifetime(param.ident.span.with_ctxt(ctxt), param.ident),
145+
),
144146
ast::GenericParamKind::Type { default } => {
145147
*default = None;
146-
ast::GenericArg::Type(cx.ty_ident(span, param.ident))
148+
ast::GenericArg::Type(cx.ty_ident(param.ident.span.with_ctxt(ctxt), param.ident))
147149
}
148150
ast::GenericParamKind::Const { ty: _, kw_span: _, default } => {
149151
*default = None;
150-
ast::GenericArg::Const(cx.const_ident(span, param.ident))
152+
ast::GenericArg::Const(
153+
cx.const_ident(param.ident.span.with_ctxt(ctxt), param.ident),
154+
)
151155
}
152156
})
153157
.collect();
@@ -174,6 +178,8 @@ fn inject_impl_of_structural_trait(
174178
})
175179
.cloned(),
176180
);
181+
// Mark as `automatically_derived` to avoid some silly lints.
182+
attrs.push(cx.attribute(cx.meta_word(span, sym::automatically_derived)));
177183

178184
let newitem = cx.item(
179185
span,

library/alloc/src/collections/btree/map.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,9 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
10931093

10941094
/// Moves all elements from `other` into `self`, leaving `other` empty.
10951095
///
1096+
/// If a key from `other` is already present in `self`, the respective
1097+
/// value from `self` will be overwritten with the respective value from `other`.
1098+
///
10961099
/// # Examples
10971100
///
10981101
/// ```
@@ -1101,10 +1104,10 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
11011104
/// let mut a = BTreeMap::new();
11021105
/// a.insert(1, "a");
11031106
/// a.insert(2, "b");
1104-
/// a.insert(3, "c");
1107+
/// a.insert(3, "c"); // Note: Key (3) also present in b.
11051108
///
11061109
/// let mut b = BTreeMap::new();
1107-
/// b.insert(3, "d");
1110+
/// b.insert(3, "d"); // Note: Key (3) also present in a.
11081111
/// b.insert(4, "e");
11091112
/// b.insert(5, "f");
11101113
///
@@ -1115,7 +1118,7 @@ impl<K, V, A: Allocator + Clone> BTreeMap<K, V, A> {
11151118
///
11161119
/// assert_eq!(a[&1], "a");
11171120
/// assert_eq!(a[&2], "b");
1118-
/// assert_eq!(a[&3], "d");
1121+
/// assert_eq!(a[&3], "d"); // Note: "c" has been overwritten.
11191122
/// assert_eq!(a[&4], "e");
11201123
/// assert_eq!(a[&5], "f");
11211124
/// ```

library/core/src/char/methods.rs

+5
Original file line numberDiff line numberDiff line change
@@ -597,9 +597,14 @@ impl char {
597597
/// Returns the number of 16-bit code units this `char` would need if
598598
/// encoded in UTF-16.
599599
///
600+
/// That number of code units is always either 1 or 2, for unicode scalar values in
601+
/// the [basic multilingual plane] or [supplementary planes] respectively.
602+
///
600603
/// See the documentation for [`len_utf8()`] for more explanation of this
601604
/// concept. This function is a mirror, but for UTF-16 instead of UTF-8.
602605
///
606+
/// [basic multilingual plane]: http://www.unicode.org/glossary/#basic_multilingual_plane
607+
/// [supplementary planes]: http://www.unicode.org/glossary/#supplementary_planes
603608
/// [`len_utf8()`]: #method.len_utf8
604609
///
605610
/// # Examples

library/core/src/marker.rs

+53-59
Original file line numberDiff line numberDiff line change
@@ -483,64 +483,6 @@ impl<T: ?Sized> !Sync for *const T {}
483483
#[stable(feature = "rust1", since = "1.0.0")]
484484
impl<T: ?Sized> !Sync for *mut T {}
485485

486-
macro_rules! impls {
487-
($t: ident) => {
488-
#[stable(feature = "rust1", since = "1.0.0")]
489-
impl<T: ?Sized> Hash for $t<T> {
490-
#[inline]
491-
fn hash<H: Hasher>(&self, _: &mut H) {}
492-
}
493-
494-
#[stable(feature = "rust1", since = "1.0.0")]
495-
impl<T: ?Sized> cmp::PartialEq for $t<T> {
496-
fn eq(&self, _other: &$t<T>) -> bool {
497-
true
498-
}
499-
}
500-
501-
#[stable(feature = "rust1", since = "1.0.0")]
502-
impl<T: ?Sized> cmp::Eq for $t<T> {}
503-
504-
#[stable(feature = "rust1", since = "1.0.0")]
505-
impl<T: ?Sized> cmp::PartialOrd for $t<T> {
506-
fn partial_cmp(&self, _other: &$t<T>) -> Option<cmp::Ordering> {
507-
Option::Some(cmp::Ordering::Equal)
508-
}
509-
}
510-
511-
#[stable(feature = "rust1", since = "1.0.0")]
512-
impl<T: ?Sized> cmp::Ord for $t<T> {
513-
fn cmp(&self, _other: &$t<T>) -> cmp::Ordering {
514-
cmp::Ordering::Equal
515-
}
516-
}
517-
518-
#[stable(feature = "rust1", since = "1.0.0")]
519-
impl<T: ?Sized> Copy for $t<T> {}
520-
521-
#[stable(feature = "rust1", since = "1.0.0")]
522-
impl<T: ?Sized> Clone for $t<T> {
523-
fn clone(&self) -> Self {
524-
Self
525-
}
526-
}
527-
528-
#[stable(feature = "rust1", since = "1.0.0")]
529-
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
530-
impl<T: ?Sized> const Default for $t<T> {
531-
fn default() -> Self {
532-
Self
533-
}
534-
}
535-
536-
#[unstable(feature = "structural_match", issue = "31434")]
537-
impl<T: ?Sized> StructuralPartialEq for $t<T> {}
538-
539-
#[unstable(feature = "structural_match", issue = "31434")]
540-
impl<T: ?Sized> StructuralEq for $t<T> {}
541-
};
542-
}
543-
544486
/// Zero-sized type used to mark things that "act like" they own a `T`.
545487
///
546488
/// Adding a `PhantomData<T>` field to your type tells the compiler that your
@@ -678,7 +620,59 @@ macro_rules! impls {
678620
#[stable(feature = "rust1", since = "1.0.0")]
679621
pub struct PhantomData<T: ?Sized>;
680622

681-
impls! { PhantomData }
623+
#[stable(feature = "rust1", since = "1.0.0")]
624+
impl<T: ?Sized> Hash for PhantomData<T> {
625+
#[inline]
626+
fn hash<H: Hasher>(&self, _: &mut H) {}
627+
}
628+
629+
#[stable(feature = "rust1", since = "1.0.0")]
630+
impl<T: ?Sized> cmp::PartialEq for PhantomData<T> {
631+
fn eq(&self, _other: &PhantomData<T>) -> bool {
632+
true
633+
}
634+
}
635+
636+
#[stable(feature = "rust1", since = "1.0.0")]
637+
impl<T: ?Sized> cmp::Eq for PhantomData<T> {}
638+
639+
#[stable(feature = "rust1", since = "1.0.0")]
640+
impl<T: ?Sized> cmp::PartialOrd for PhantomData<T> {
641+
fn partial_cmp(&self, _other: &PhantomData<T>) -> Option<cmp::Ordering> {
642+
Option::Some(cmp::Ordering::Equal)
643+
}
644+
}
645+
646+
#[stable(feature = "rust1", since = "1.0.0")]
647+
impl<T: ?Sized> cmp::Ord for PhantomData<T> {
648+
fn cmp(&self, _other: &PhantomData<T>) -> cmp::Ordering {
649+
cmp::Ordering::Equal
650+
}
651+
}
652+
653+
#[stable(feature = "rust1", since = "1.0.0")]
654+
impl<T: ?Sized> Copy for PhantomData<T> {}
655+
656+
#[stable(feature = "rust1", since = "1.0.0")]
657+
impl<T: ?Sized> Clone for PhantomData<T> {
658+
fn clone(&self) -> Self {
659+
Self
660+
}
661+
}
662+
663+
#[stable(feature = "rust1", since = "1.0.0")]
664+
#[rustc_const_unstable(feature = "const_default_impls", issue = "87864")]
665+
impl<T: ?Sized> const Default for PhantomData<T> {
666+
fn default() -> Self {
667+
Self
668+
}
669+
}
670+
671+
#[unstable(feature = "structural_match", issue = "31434")]
672+
impl<T: ?Sized> StructuralPartialEq for PhantomData<T> {}
673+
674+
#[unstable(feature = "structural_match", issue = "31434")]
675+
impl<T: ?Sized> StructuralEq for PhantomData<T> {}
682676

683677
mod impls {
684678
#[stable(feature = "rust1", since = "1.0.0")]

src/librustdoc/passes/collect_intra_doc_links.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ impl Res {
8080
}
8181
}
8282

83-
fn def_id(self, tcx: TyCtxt<'_>) -> DefId {
83+
fn def_id(self, tcx: TyCtxt<'_>) -> Option<DefId> {
8484
match self {
85-
Res::Def(_, id) => id,
86-
Res::Primitive(prim) => *PrimitiveType::primitive_locations(tcx).get(&prim).unwrap(),
85+
Res::Def(_, id) => Some(id),
86+
Res::Primitive(prim) => PrimitiveType::primitive_locations(tcx).get(&prim).copied(),
8787
}
8888
}
8989

@@ -1127,10 +1127,10 @@ impl LinkCollector<'_, '_> {
11271127
}
11281128
}
11291129

1130-
Some(ItemLink {
1130+
res.def_id(self.cx.tcx).map(|page_id| ItemLink {
11311131
link: ori_link.link.clone(),
11321132
link_text: link_text.clone(),
1133-
page_id: res.def_id(self.cx.tcx),
1133+
page_id,
11341134
fragment,
11351135
})
11361136
}

src/librustdoc/passes/collect_intra_doc_links/early.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ pub(crate) fn early_resolve_intra_doc_links(
4848
link_resolver.resolve_doc_links_local(&krate.attrs);
4949
link_resolver.process_module_children_or_reexports(CRATE_DEF_ID.to_def_id());
5050
visit::walk_crate(&mut link_resolver, krate);
51-
link_resolver.process_extern_impls();
5251

5352
// FIXME: somehow rustdoc is still missing crates even though we loaded all
5453
// the known necessary crates. Load them all unconditionally until we find a way to fix this.
@@ -58,6 +57,8 @@ pub(crate) fn early_resolve_intra_doc_links(
5857
link_resolver.resolver.resolve_rustdoc_path(extern_name, TypeNS, parent_scope);
5958
}
6059

60+
link_resolver.process_extern_impls();
61+
6162
ResolverCaches {
6263
markdown_links: Some(link_resolver.markdown_links),
6364
doc_link_resolutions: link_resolver.doc_link_resolutions,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Crate tree without a `doc(primitive)` module for primitive type linked to by a doc link.
2+
3+
#![deny(rustdoc::broken_intra_doc_links)]
4+
#![feature(no_core, lang_items, rustc_attrs)]
5+
#![no_core]
6+
#![rustc_coherence_is_core]
7+
#![crate_type = "rlib"]
8+
9+
// @has no_doc_primitive/index.html
10+
//! A [`char`] and its [`char::len_utf8`].
11+
impl char {
12+
pub fn len_utf8(self) -> usize {
13+
42
14+
}
15+
}

0 commit comments

Comments
 (0)