Skip to content

Commit c838138

Browse files
committed
Auto merge of rust-lang#86160 - JohnTitor:rollup-8ark9x7, r=JohnTitor
Rollup of 11 pull requests Successful merges: - rust-lang#85676 (Fix documentation style inconsistencies for IP addresses) - rust-lang#85715 (Document `From` impls in string.rs) - rust-lang#85791 (Add `Ipv6Addr::is_unicast`) - rust-lang#85957 (Display defaults on const params- rustdoc ) - rust-lang#85982 (Enable rustdoc to document safe wasm intrinsics) - rust-lang#86121 (Forwarding implementation for Seek trait's stream_position method) - rust-lang#86124 (Include macro name in 'local ambiguity' error) - rust-lang#86128 (Refactor: Extract render_summary from render_impl.) - rust-lang#86142 (Simplify proc_macro code using Bound::cloned().) - rust-lang#86158 (Update books) - rust-lang#86159 (Update cargo) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents ed597e7 + d8376f4 commit c838138

File tree

22 files changed

+264
-144
lines changed

22 files changed

+264
-144
lines changed

compiler/rustc_expand/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![feature(crate_visibility_modifier)]
22
#![feature(decl_macro)]
33
#![feature(destructuring_assignment)]
4+
#![feature(format_args_capture)]
45
#![feature(iter_zip)]
56
#![feature(proc_macro_diagnostic)]
67
#![feature(proc_macro_internals)]

compiler/rustc_expand/src/mbe/macro_parser.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ use smallvec::{smallvec, SmallVec};
8585

8686
use rustc_data_structures::fx::FxHashMap;
8787
use rustc_data_structures::sync::Lrc;
88+
use rustc_span::symbol::Ident;
8889
use std::borrow::Cow;
8990
use std::collections::hash_map::Entry::{Occupied, Vacant};
9091
use std::mem;
@@ -615,7 +616,11 @@ fn inner_parse_loop<'root, 'tt>(
615616

616617
/// Use the given sequence of token trees (`ms`) as a matcher. Match the token
617618
/// stream from the given `parser` against it and return the match.
618-
pub(super) fn parse_tt(parser: &mut Cow<'_, Parser<'_>>, ms: &[TokenTree]) -> NamedParseResult {
619+
pub(super) fn parse_tt(
620+
parser: &mut Cow<'_, Parser<'_>>,
621+
ms: &[TokenTree],
622+
macro_name: Ident,
623+
) -> NamedParseResult {
619624
// A queue of possible matcher positions. We initialize it with the matcher position in which
620625
// the "dot" is before the first token of the first token tree in `ms`. `inner_parse_loop` then
621626
// processes all of these possible matcher positions and produces possible next positions into
@@ -711,7 +716,7 @@ pub(super) fn parse_tt(parser: &mut Cow<'_, Parser<'_>>, ms: &[TokenTree]) -> Na
711716
return Error(
712717
parser.token.span,
713718
format!(
714-
"local ambiguity: multiple parsing options: {}",
719+
"local ambiguity when calling macro `{macro_name}`: multiple parsing options: {}",
715720
match next_items.len() {
716721
0 => format!("built-in NTs {}.", nts),
717722
1 => format!("built-in NTs {} or 1 other option.", nts),

compiler/rustc_expand/src/mbe/macro_rules.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ fn generic_extension<'cx>(
245245
// are not recorded. On the first `Success(..)`ful matcher, the spans are merged.
246246
let mut gated_spans_snapshot = mem::take(&mut *sess.gated_spans.spans.borrow_mut());
247247

248-
match parse_tt(&mut Cow::Borrowed(&parser), lhs_tt) {
248+
match parse_tt(&mut Cow::Borrowed(&parser), lhs_tt, name) {
249249
Success(named_matches) => {
250250
// The matcher was `Success(..)`ful.
251251
// Merge the gated spans from parsing the matcher with the pre-existing ones.
@@ -338,7 +338,7 @@ fn generic_extension<'cx>(
338338
_ => continue,
339339
};
340340
if let Success(_) =
341-
parse_tt(&mut Cow::Borrowed(&parser_from_cx(sess, arg.clone())), lhs_tt)
341+
parse_tt(&mut Cow::Borrowed(&parser_from_cx(sess, arg.clone())), lhs_tt, name)
342342
{
343343
if comma_span.is_dummy() {
344344
err.note("you might be missing a comma");
@@ -432,7 +432,7 @@ pub fn compile_declarative_macro(
432432
];
433433

434434
let parser = Parser::new(&sess.parse_sess, body, true, rustc_parse::MACRO_ARGUMENTS);
435-
let argument_map = match parse_tt(&mut Cow::Borrowed(&parser), &argument_gram) {
435+
let argument_map = match parse_tt(&mut Cow::Borrowed(&parser), &argument_gram, def.ident) {
436436
Success(m) => m,
437437
Failure(token, msg) => {
438438
let s = parse_failure_msg(&token);

compiler/rustc_typeck/src/collect.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -2771,7 +2771,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
27712771
}
27722772
} else if tcx.sess.check_name(attr, sym::target_feature) {
27732773
if !tcx.is_closure(id) && tcx.fn_sig(id).unsafety() == hir::Unsafety::Normal {
2774-
if tcx.sess.target.is_like_wasm {
2774+
if tcx.sess.target.is_like_wasm || tcx.sess.opts.actually_rustdoc {
27752775
// The `#[target_feature]` attribute is allowed on
27762776
// WebAssembly targets on all functions, including safe
27772777
// ones. Other targets require that `#[target_feature]` is
@@ -2785,6 +2785,10 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
27852785
// deterministic trap. There is no undefined behavior when
27862786
// executing WebAssembly so `#[target_feature]` is allowed
27872787
// on safe functions (but again, only for WebAssembly)
2788+
//
2789+
// Note that this is also allowed if `actually_rustdoc` so
2790+
// if a target is documenting some wasm-specific code then
2791+
// it's not spuriously denied.
27882792
} else if !tcx.features().target_feature_11 {
27892793
let mut err = feature_err(
27902794
&tcx.sess.parse_sess,

library/alloc/src/string.rs

+43-7
Original file line numberDiff line numberDiff line change
@@ -2491,6 +2491,9 @@ impl AsRef<[u8]> for String {
24912491
#[cfg(not(no_global_oom_handling))]
24922492
#[stable(feature = "rust1", since = "1.0.0")]
24932493
impl From<&str> for String {
2494+
/// Converts a `&str` into a [`String`].
2495+
///
2496+
/// The result is allocated on the heap.
24942497
#[inline]
24952498
fn from(s: &str) -> String {
24962499
s.to_owned()
@@ -2500,7 +2503,7 @@ impl From<&str> for String {
25002503
#[cfg(not(no_global_oom_handling))]
25012504
#[stable(feature = "from_mut_str_for_string", since = "1.44.0")]
25022505
impl From<&mut str> for String {
2503-
/// Converts a `&mut str` into a `String`.
2506+
/// Converts a `&mut str` into a [`String`].
25042507
///
25052508
/// The result is allocated on the heap.
25062509
#[inline]
@@ -2512,6 +2515,9 @@ impl From<&mut str> for String {
25122515
#[cfg(not(no_global_oom_handling))]
25132516
#[stable(feature = "from_ref_string", since = "1.35.0")]
25142517
impl From<&String> for String {
2518+
/// Converts a `&String` into a [`String`].
2519+
///
2520+
/// This clones `s` and returns the clone.
25152521
#[inline]
25162522
fn from(s: &String) -> String {
25172523
s.clone()
@@ -2522,7 +2528,7 @@ impl From<&String> for String {
25222528
#[cfg(not(test))]
25232529
#[stable(feature = "string_from_box", since = "1.18.0")]
25242530
impl From<Box<str>> for String {
2525-
/// Converts the given boxed `str` slice to a `String`.
2531+
/// Converts the given boxed `str` slice to a [`String`].
25262532
/// It is notable that the `str` slice is owned.
25272533
///
25282534
/// # Examples
@@ -2544,7 +2550,7 @@ impl From<Box<str>> for String {
25442550
#[cfg(not(no_global_oom_handling))]
25452551
#[stable(feature = "box_from_str", since = "1.20.0")]
25462552
impl From<String> for Box<str> {
2547-
/// Converts the given `String` to a boxed `str` slice that is owned.
2553+
/// Converts the given [`String`] to a boxed `str` slice that is owned.
25482554
///
25492555
/// # Examples
25502556
///
@@ -2565,6 +2571,22 @@ impl From<String> for Box<str> {
25652571
#[cfg(not(no_global_oom_handling))]
25662572
#[stable(feature = "string_from_cow_str", since = "1.14.0")]
25672573
impl<'a> From<Cow<'a, str>> for String {
2574+
/// Converts a clone-on-write string to an owned
2575+
/// instance of [`String`].
2576+
///
2577+
/// This extracts the owned string,
2578+
/// clones the string if it is not already owned.
2579+
///
2580+
/// # Example
2581+
///
2582+
/// ```
2583+
/// # use std::borrow::Cow;
2584+
/// // If the string is not owned...
2585+
/// let cow: Cow<str> = Cow::Borrowed("eggplant");
2586+
/// // It will allocate on the heap and copy the string.
2587+
/// let owned: String = String::from(cow);
2588+
/// assert_eq!(&owned[..], "eggplant");
2589+
/// ```
25682590
fn from(s: Cow<'a, str>) -> String {
25692591
s.into_owned()
25702592
}
@@ -2573,7 +2595,7 @@ impl<'a> From<Cow<'a, str>> for String {
25732595
#[cfg(not(no_global_oom_handling))]
25742596
#[stable(feature = "rust1", since = "1.0.0")]
25752597
impl<'a> From<&'a str> for Cow<'a, str> {
2576-
/// Converts a string slice into a Borrowed variant.
2598+
/// Converts a string slice into a [`Borrowed`] variant.
25772599
/// No heap allocation is performed, and the string
25782600
/// is not copied.
25792601
///
@@ -2583,6 +2605,8 @@ impl<'a> From<&'a str> for Cow<'a, str> {
25832605
/// # use std::borrow::Cow;
25842606
/// assert_eq!(Cow::from("eggplant"), Cow::Borrowed("eggplant"));
25852607
/// ```
2608+
///
2609+
/// [`Borrowed`]: crate::borrow::Cow::Borrowed
25862610
#[inline]
25872611
fn from(s: &'a str) -> Cow<'a, str> {
25882612
Cow::Borrowed(s)
@@ -2592,7 +2616,7 @@ impl<'a> From<&'a str> for Cow<'a, str> {
25922616
#[cfg(not(no_global_oom_handling))]
25932617
#[stable(feature = "rust1", since = "1.0.0")]
25942618
impl<'a> From<String> for Cow<'a, str> {
2595-
/// Converts a String into an Owned variant.
2619+
/// Converts a [`String`] into an [`Owned`] variant.
25962620
/// No heap allocation is performed, and the string
25972621
/// is not copied.
25982622
///
@@ -2604,6 +2628,8 @@ impl<'a> From<String> for Cow<'a, str> {
26042628
/// let s2 = "eggplant".to_string();
26052629
/// assert_eq!(Cow::from(s), Cow::<'static, str>::Owned(s2));
26062630
/// ```
2631+
///
2632+
/// [`Owned`]: crate::borrow::Cow::Owned
26072633
#[inline]
26082634
fn from(s: String) -> Cow<'a, str> {
26092635
Cow::Owned(s)
@@ -2613,7 +2639,7 @@ impl<'a> From<String> for Cow<'a, str> {
26132639
#[cfg(not(no_global_oom_handling))]
26142640
#[stable(feature = "cow_from_string_ref", since = "1.28.0")]
26152641
impl<'a> From<&'a String> for Cow<'a, str> {
2616-
/// Converts a String reference into a Borrowed variant.
2642+
/// Converts a [`String`] reference into a [`Borrowed`] variant.
26172643
/// No heap allocation is performed, and the string
26182644
/// is not copied.
26192645
///
@@ -2624,6 +2650,8 @@ impl<'a> From<&'a String> for Cow<'a, str> {
26242650
/// let s = "eggplant".to_string();
26252651
/// assert_eq!(Cow::from(&s), Cow::Borrowed("eggplant"));
26262652
/// ```
2653+
///
2654+
/// [`Borrowed`]: crate::borrow::Cow::Borrowed
26272655
#[inline]
26282656
fn from(s: &'a String) -> Cow<'a, str> {
26292657
Cow::Borrowed(s.as_str())
@@ -2656,7 +2684,7 @@ impl<'a> FromIterator<String> for Cow<'a, str> {
26562684

26572685
#[stable(feature = "from_string_for_vec_u8", since = "1.14.0")]
26582686
impl From<String> for Vec<u8> {
2659-
/// Converts the given `String` to a vector `Vec` that holds values of type `u8`.
2687+
/// Converts the given [`String`] to a vector [`Vec`] that holds values of type [`u8`].
26602688
///
26612689
/// # Examples
26622690
///
@@ -2802,6 +2830,14 @@ impl FusedIterator for Drain<'_> {}
28022830
#[cfg(not(no_global_oom_handling))]
28032831
#[stable(feature = "from_char_for_string", since = "1.46.0")]
28042832
impl From<char> for String {
2833+
/// Allocates an owned [`String`] from a single character.
2834+
///
2835+
/// # Example
2836+
/// ```rust
2837+
/// let c: char = 'a';
2838+
/// let s: String = String::from(c);
2839+
/// assert_eq!("a", &s[..]);
2840+
/// ```
28052841
#[inline]
28062842
fn from(c: char) -> Self {
28072843
c.to_string()

library/proc_macro/src/lib.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#![feature(restricted_std)]
3232
#![feature(rustc_attrs)]
3333
#![feature(min_specialization)]
34+
#![feature(bound_cloned)]
3435
#![recursion_limit = "256"]
3536

3637
#[unstable(feature = "proc_macro_internals", issue = "27812")]
@@ -43,7 +44,7 @@ mod diagnostic;
4344
pub use diagnostic::{Diagnostic, Level, MultiSpan};
4445

4546
use std::cmp::Ordering;
46-
use std::ops::{Bound, RangeBounds};
47+
use std::ops::RangeBounds;
4748
use std::path::PathBuf;
4849
use std::str::FromStr;
4950
use std::{error, fmt, iter, mem};
@@ -1162,16 +1163,7 @@ impl Literal {
11621163
// was 'c' or whether it was '\u{63}'.
11631164
#[unstable(feature = "proc_macro_span", issue = "54725")]
11641165
pub fn subspan<R: RangeBounds<usize>>(&self, range: R) -> Option<Span> {
1165-
// HACK(eddyb) something akin to `Option::cloned`, but for `Bound<&T>`.
1166-
fn cloned_bound<T: Clone>(bound: Bound<&T>) -> Bound<T> {
1167-
match bound {
1168-
Bound::Included(x) => Bound::Included(x.clone()),
1169-
Bound::Excluded(x) => Bound::Excluded(x.clone()),
1170-
Bound::Unbounded => Bound::Unbounded,
1171-
}
1172-
}
1173-
1174-
self.0.subspan(cloned_bound(range.start_bound()), cloned_bound(range.end_bound())).map(Span)
1166+
self.0.subspan(range.start_bound().cloned(), range.end_bound().cloned()).map(Span)
11751167
}
11761168
}
11771169

library/std/src/io/impls.rs

+10
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ impl<S: Seek + ?Sized> Seek for &mut S {
8787
fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
8888
(**self).seek(pos)
8989
}
90+
91+
#[inline]
92+
fn stream_position(&mut self) -> io::Result<u64> {
93+
(**self).stream_position()
94+
}
9095
}
9196
#[stable(feature = "rust1", since = "1.0.0")]
9297
impl<B: BufRead + ?Sized> BufRead for &mut B {
@@ -186,6 +191,11 @@ impl<S: Seek + ?Sized> Seek for Box<S> {
186191
fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
187192
(**self).seek(pos)
188193
}
194+
195+
#[inline]
196+
fn stream_position(&mut self) -> io::Result<u64> {
197+
(**self).stream_position()
198+
}
189199
}
190200
#[stable(feature = "rust1", since = "1.0.0")]
191201
impl<B: BufRead + ?Sized> BufRead for Box<B> {

0 commit comments

Comments
 (0)