Skip to content

Commit 82d87f2

Browse files
committed
Auto merge of rust-lang#75815 - jyn514:ambiguous-primitives, r=guillaumegomez
Report an ambiguity if both modules and primitives are in scope for intra-doc links Closes rust-lang#75381 - Add a new `prim@` disambiguator, since both modules and primitives are in the same namespace - Refactor `report_ambiguity` into a closure Additionally, I noticed that rustdoc would previously allow `[struct@char]` if `char` resolved to a primitive (not if it had a DefId). I fixed that and added a test case. I also need to update libstd to use `prim@char` instead of `type@char`. If possible I would also like to refactor `ambiguity_error` to use `Disambiguator` instead of its own hand-rolled match - that ran into issues with `prim@` (I updated one and not the other) and it would be better for them to be in sync.
2 parents 8ad886d + 219c776 commit 82d87f2

File tree

6 files changed

+50
-11
lines changed

6 files changed

+50
-11
lines changed

alloc/src/string.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,8 @@ use crate::vec::Vec;
268268
///
269269
/// Here, there's no need to allocate more memory inside the loop.
270270
///
271-
/// [`str`]: type@str
272-
/// [`&str`]: type@str
271+
/// [`str`]: prim@str
272+
/// [`&str`]: prim@str
273273
/// [`Deref`]: core::ops::Deref
274274
/// [`as_str()`]: String::as_str
275275
#[derive(PartialOrd, Eq, Ord)]
@@ -296,7 +296,7 @@ pub struct String {
296296
///
297297
/// [`Utf8Error`]: core::str::Utf8Error
298298
/// [`std::str`]: core::str
299-
/// [`&str`]: str
299+
/// [`&str`]: prim@str
300300
/// [`utf8_error`]: Self::utf8_error
301301
///
302302
/// # Examples
@@ -472,7 +472,7 @@ impl String {
472472
///
473473
/// [`from_utf8_unchecked`]: String::from_utf8_unchecked
474474
/// [`Vec<u8>`]: crate::vec::Vec
475-
/// [`&str`]: str
475+
/// [`&str`]: prim@str
476476
/// [`into_bytes`]: String::into_bytes
477477
#[inline]
478478
#[stable(feature = "rust1", since = "1.0.0")]
@@ -1576,6 +1576,8 @@ impl String {
15761576
///
15771577
/// This will drop any excess capacity.
15781578
///
1579+
/// [`str`]: prim@str
1580+
///
15791581
/// # Examples
15801582
///
15811583
/// Basic usage:
@@ -1644,7 +1646,7 @@ impl FromUtf8Error {
16441646
/// on using it.
16451647
///
16461648
/// [`std::str`]: core::str
1647-
/// [`&str`]: str
1649+
/// [`&str`]: prim@str
16481650
///
16491651
/// # Examples
16501652
///

core/src/str/mod.rs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ Section: Iterators
476476
/// This struct is created by the [`chars`] method on [`str`].
477477
/// See its documentation for more.
478478
///
479+
/// [`char`]: prim@char
479480
/// [`chars`]: str::chars
480481
#[derive(Clone)]
481482
#[stable(feature = "rust1", since = "1.0.0")]
@@ -673,6 +674,7 @@ impl<'a> Chars<'a> {
673674
/// This struct is created by the [`char_indices`] method on [`str`].
674675
/// See its documentation for more.
675676
///
677+
/// [`char`]: prim@char
676678
/// [`char_indices`]: str::char_indices
677679
#[derive(Clone, Debug)]
678680
#[stable(feature = "rust1", since = "1.0.0")]
@@ -2270,6 +2272,8 @@ impl str {
22702272
/// This length is in bytes, not [`char`]s or graphemes. In other words,
22712273
/// it may not be what a human considers the length of the string.
22722274
///
2275+
/// [`char`]: prim@char
2276+
///
22732277
/// # Examples
22742278
///
22752279
/// Basic usage:
@@ -2791,7 +2795,9 @@ impl str {
27912795
/// assert_eq!(None, chars.next());
27922796
/// ```
27932797
///
2794-
/// Remember, [`char`]s may not match your human intuition about characters:
2798+
/// Remember, [`char`]s may not match your intuition about characters:
2799+
///
2800+
/// [`char`]: prim@char
27952801
///
27962802
/// ```
27972803
/// let y = "y̆";
@@ -2842,7 +2848,9 @@ impl str {
28422848
/// assert_eq!(None, char_indices.next());
28432849
/// ```
28442850
///
2845-
/// Remember, [`char`]s may not match your human intuition about characters:
2851+
/// Remember, [`char`]s may not match your intuition about characters:
2852+
///
2853+
/// [`char`]: prim@char
28462854
///
28472855
/// ```
28482856
/// let yes = "y̆es";
@@ -3053,6 +3061,7 @@ impl str {
30533061
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
30543062
/// function or closure that determines if a character matches.
30553063
///
3064+
/// [`char`]: prim@char
30563065
/// [pattern]: self::pattern
30573066
///
30583067
/// # Examples
@@ -3079,6 +3088,7 @@ impl str {
30793088
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
30803089
/// function or closure that determines if a character matches.
30813090
///
3091+
/// [`char`]: prim@char
30823092
/// [pattern]: self::pattern
30833093
///
30843094
/// # Examples
@@ -3104,6 +3114,7 @@ impl str {
31043114
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
31053115
/// function or closure that determines if a character matches.
31063116
///
3117+
/// [`char`]: prim@char
31073118
/// [pattern]: self::pattern
31083119
///
31093120
/// # Examples
@@ -3132,6 +3143,7 @@ impl str {
31323143
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
31333144
/// function or closure that determines if a character matches.
31343145
///
3146+
/// [`char`]: prim@char
31353147
/// [pattern]: self::pattern
31363148
///
31373149
/// # Examples
@@ -3179,6 +3191,7 @@ impl str {
31793191
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
31803192
/// function or closure that determines if a character matches.
31813193
///
3194+
/// [`char`]: prim@char
31823195
/// [pattern]: self::pattern
31833196
///
31843197
/// # Examples
@@ -3225,6 +3238,7 @@ impl str {
32253238
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
32263239
/// function or closure that determines if a character matches.
32273240
///
3241+
/// [`char`]: prim@char
32283242
/// [pattern]: self::pattern
32293243
///
32303244
/// # Iterator behavior
@@ -3344,6 +3358,7 @@ impl str {
33443358
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
33453359
/// function or closure that determines if a character matches.
33463360
///
3361+
/// [`char`]: prim@char
33473362
/// [pattern]: self::pattern
33483363
///
33493364
/// # Examples
@@ -3383,6 +3398,7 @@ impl str {
33833398
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
33843399
/// function or closure that determines if a character matches.
33853400
///
3401+
/// [`char`]: prim@char
33863402
/// [pattern]: self::pattern
33873403
///
33883404
/// # Iterator behavior
@@ -3434,6 +3450,7 @@ impl str {
34343450
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
34353451
/// function or closure that determines if a character matches.
34363452
///
3453+
/// [`char`]: prim@char
34373454
/// [pattern]: self::pattern
34383455
///
34393456
/// Equivalent to [`split`], except that the trailing substring
@@ -3478,6 +3495,7 @@ impl str {
34783495
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
34793496
/// function or closure that determines if a character matches.
34803497
///
3498+
/// [`char`]: prim@char
34813499
/// [pattern]: self::pattern
34823500
///
34833501
/// Equivalent to [`split`], except that the trailing substring is
@@ -3526,6 +3544,7 @@ impl str {
35263544
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
35273545
/// function or closure that determines if a character matches.
35283546
///
3547+
/// [`char`]: prim@char
35293548
/// [pattern]: self::pattern
35303549
///
35313550
/// # Iterator behavior
@@ -3578,6 +3597,7 @@ impl str {
35783597
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
35793598
/// function or closure that determines if a character matches.
35803599
///
3600+
/// [`char`]: prim@char
35813601
/// [pattern]: self::pattern
35823602
///
35833603
/// # Iterator behavior
@@ -3666,6 +3686,7 @@ impl str {
36663686
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
36673687
/// function or closure that determines if a character matches.
36683688
///
3689+
/// [`char`]: prim@char
36693690
/// [pattern]: self::pattern
36703691
///
36713692
/// # Iterator behavior
@@ -3702,6 +3723,7 @@ impl str {
37023723
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
37033724
/// function or closure that determines if a character matches.
37043725
///
3726+
/// [`char`]: prim@char
37053727
/// [pattern]: self::pattern
37063728
///
37073729
/// # Iterator behavior
@@ -3743,6 +3765,7 @@ impl str {
37433765
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
37443766
/// function or closure that determines if a character matches.
37453767
///
3768+
/// [`char`]: prim@char
37463769
/// [pattern]: self::pattern
37473770
///
37483771
/// # Iterator behavior
@@ -3785,6 +3808,7 @@ impl str {
37853808
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
37863809
/// function or closure that determines if a character matches.
37873810
///
3811+
/// [`char`]: prim@char
37883812
/// [pattern]: self::pattern
37893813
///
37903814
/// # Iterator behavior
@@ -4003,6 +4027,7 @@ impl str {
40034027
/// The [pattern] can be a [`char`], a slice of [`char`]s, or a function
40044028
/// or closure that determines if a character matches.
40054029
///
4030+
/// [`char`]: prim@char
40064031
/// [pattern]: self::pattern
40074032
///
40084033
/// # Examples
@@ -4050,6 +4075,7 @@ impl str {
40504075
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
40514076
/// function or closure that determines if a character matches.
40524077
///
4078+
/// [`char`]: prim@char
40534079
/// [pattern]: self::pattern
40544080
///
40554081
/// # Text directionality
@@ -4094,6 +4120,7 @@ impl str {
40944120
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
40954121
/// function or closure that determines if a character matches.
40964122
///
4123+
/// [`char`]: prim@char
40974124
/// [pattern]: self::pattern
40984125
///
40994126
/// # Examples
@@ -4121,6 +4148,7 @@ impl str {
41214148
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
41224149
/// function or closure that determines if a character matches.
41234150
///
4151+
/// [`char`]: prim@char
41244152
/// [pattern]: self::pattern
41254153
///
41264154
/// # Examples
@@ -4147,6 +4175,7 @@ impl str {
41474175
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
41484176
/// function or closure that determines if a character matches.
41494177
///
4178+
/// [`char`]: prim@char
41504179
/// [pattern]: self::pattern
41514180
///
41524181
/// # Text directionality
@@ -4195,6 +4224,7 @@ impl str {
41954224
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
41964225
/// function or closure that determines if a character matches.
41974226
///
4227+
/// [`char`]: prim@char
41984228
/// [pattern]: self::pattern
41994229
///
42004230
/// # Text directionality
@@ -4231,6 +4261,7 @@ impl str {
42314261
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
42324262
/// function or closure that determines if a character matches.
42334263
///
4264+
/// [`char`]: prim@char
42344265
/// [pattern]: self::pattern
42354266
///
42364267
/// # Text directionality

std/src/error.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,8 @@ impl From<String> for Box<dyn Error> {
296296
impl<'a> From<&str> for Box<dyn Error + Send + Sync + 'a> {
297297
/// Converts a [`str`] into a box of dyn [`Error`] + [`Send`] + [`Sync`].
298298
///
299+
/// [`str`]: prim@str
300+
///
299301
/// # Examples
300302
///
301303
/// ```
@@ -317,6 +319,8 @@ impl<'a> From<&str> for Box<dyn Error + Send + Sync + 'a> {
317319
impl From<&str> for Box<dyn Error> {
318320
/// Converts a [`str`] into a box of dyn [`Error`].
319321
///
322+
/// [`str`]: prim@str
323+
///
320324
/// # Examples
321325
///
322326
/// ```

std/src/ffi/c_str.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ use crate::sys;
6969
/// extern functions. See the documentation for that function for a
7070
/// discussion on ensuring the lifetime of the raw pointer.
7171
///
72-
/// [`&str`]: str
72+
/// [`&str`]: prim@str
7373
/// [slice.as_ptr]: ../primitive.slice.html#method.as_ptr
7474
/// [slice.len]: ../primitive.slice.html#method.len
7575
/// [`Deref`]: ops::Deref
@@ -180,7 +180,7 @@ pub struct CString {
180180
/// println!("string: {}", my_string_safe());
181181
/// ```
182182
///
183-
/// [`&str`]: str
183+
/// [`&str`]: prim@str
184184
#[derive(Hash)]
185185
#[stable(feature = "rust1", since = "1.0.0")]
186186
// FIXME:
@@ -1351,7 +1351,7 @@ impl CStr {
13511351
/// function will return the corresponding [`&str`] slice. Otherwise,
13521352
/// it will return an error with details of where UTF-8 validation failed.
13531353
///
1354-
/// [`&str`]: str
1354+
/// [`&str`]: prim@str
13551355
///
13561356
/// # Examples
13571357
///
@@ -1379,6 +1379,7 @@ impl CStr {
13791379
/// [`U+FFFD REPLACEMENT CHARACTER`][U+FFFD] and return a
13801380
/// [`Cow`]`::`[`Owned`]`(`[`String`]`)` with the result.
13811381
///
1382+
/// [`str`]: prim@str
13821383
/// [`Borrowed`]: Cow::Borrowed
13831384
/// [`Owned`]: Cow::Owned
13841385
/// [U+FFFD]: crate::char::REPLACEMENT_CHARACTER

std/src/io/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ where
480480
/// ```
481481
///
482482
/// [`read()`]: Read::read
483-
/// [`&str`]: str
483+
/// [`&str`]: prim@str
484484
/// [`std::io`]: self
485485
/// [`File`]: crate::fs::File
486486
/// [slice]: ../../std/primitive.slice.html

std/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@
172172
//! [`Vec<T>`]: vec::Vec
173173
//! [`atomic`]: sync::atomic
174174
//! [`for`]: ../book/ch03-05-control-flow.html#looping-through-a-collection-with-for
175+
//! [`str`]: prim@str
175176
//! [`mpsc`]: sync::mpsc
176177
//! [`std::cmp`]: cmp
177178
//! [`std::slice`]: slice

0 commit comments

Comments
 (0)