Skip to content

Rollup of 11 pull requests #86160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Jun 9, 2021
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7234141
Fix documentation style inconsistencies
CDirkx May 25, 2021
25e5a71
Document `From` impls in string.rs
fee1-dead May 26, 2021
7f27b29
Add `Ipv6Addr::is_unicast`
CDirkx May 31, 2021
187b415
Use `is_unicast` instead of ``!is_multicast`
CDirkx May 31, 2021
6dff51f
rustdoc- Show defaults on const generics
BoxyUwU Jun 3, 2021
3bd7de9
add test
BoxyUwU Jun 3, 2021
f7117f8
format version
BoxyUwU Jun 7, 2021
ed8a775
Forwarding implementation for Seek trait's stream_position method
myshylin-msft Jun 7, 2021
aba85ff
Enable rustdoc to document safe wasm intrinsics
alexcrichton Jun 4, 2021
822f800
Include macro name in 'local ambiguity' error
Aaron1011 Jun 8, 2021
1c0ecd4
Refactor: Extract render_summary from render_impl.
jsha Jun 8, 2021
58e0889
Simplify proc_macro code using Bound::cloned().
m-ou-se Jun 8, 2021
7c08d5e
Update books
ehuss Jun 9, 2021
38c6d6c
Update cargo
ehuss Jun 9, 2021
e6763c9
Rollup merge of #85676 - CDirkx:ip-style, r=JohnTitor
JohnTitor Jun 9, 2021
58f4c0f
Rollup merge of #85715 - fee1-dead:document-string, r=JohnTitor
JohnTitor Jun 9, 2021
3bc8221
Rollup merge of #85791 - CDirkx:is_unicast, r=joshtriplett
JohnTitor Jun 9, 2021
606feba
Rollup merge of #85957 - BoxyUwU:rustdoc-const-generic-defaults, r=ol…
JohnTitor Jun 9, 2021
da1a449
Rollup merge of #85982 - alexcrichton:doc-safe-wasm, r=jyn514
JohnTitor Jun 9, 2021
c961a0f
Rollup merge of #86121 - nickshiling:forwarding_impl_for_seek_trait_s…
JohnTitor Jun 9, 2021
d7186a8
Rollup merge of #86124 - Aaron1011:ambig-macro-name, r=varkor
JohnTitor Jun 9, 2021
e163e3c
Rollup merge of #86128 - jsha:render-impl-into-mod, r=GuillaumeGomez
JohnTitor Jun 9, 2021
3a9609b
Rollup merge of #86142 - m-ou-se:proc-macro-subspan-bound-cloned-clea…
JohnTitor Jun 9, 2021
e8c1cc8
Rollup merge of #86158 - ehuss:update-books, r=ehuss
JohnTitor Jun 9, 2021
d8376f4
Rollup merge of #86159 - ehuss:update-cargo, r=ehuss
JohnTitor Jun 9, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_expand/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![feature(crate_visibility_modifier)]
#![feature(decl_macro)]
#![feature(destructuring_assignment)]
#![feature(format_args_capture)]
#![feature(iter_zip)]
#![feature(proc_macro_diagnostic)]
#![feature(proc_macro_internals)]
9 changes: 7 additions & 2 deletions compiler/rustc_expand/src/mbe/macro_parser.rs
Original file line number Diff line number Diff line change
@@ -85,6 +85,7 @@ use smallvec::{smallvec, SmallVec};

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

/// Use the given sequence of token trees (`ms`) as a matcher. Match the token
/// stream from the given `parser` against it and return the match.
pub(super) fn parse_tt(parser: &mut Cow<'_, Parser<'_>>, ms: &[TokenTree]) -> NamedParseResult {
pub(super) fn parse_tt(
parser: &mut Cow<'_, Parser<'_>>,
ms: &[TokenTree],
macro_name: Ident,
) -> NamedParseResult {
// A queue of possible matcher positions. We initialize it with the matcher position in which
// the "dot" is before the first token of the first token tree in `ms`. `inner_parse_loop` then
// 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
return Error(
parser.token.span,
format!(
"local ambiguity: multiple parsing options: {}",
"local ambiguity when calling macro `{macro_name}`: multiple parsing options: {}",
match next_items.len() {
0 => format!("built-in NTs {}.", nts),
1 => format!("built-in NTs {} or 1 other option.", nts),
6 changes: 3 additions & 3 deletions compiler/rustc_expand/src/mbe/macro_rules.rs
Original file line number Diff line number Diff line change
@@ -245,7 +245,7 @@ fn generic_extension<'cx>(
// are not recorded. On the first `Success(..)`ful matcher, the spans are merged.
let mut gated_spans_snapshot = mem::take(&mut *sess.gated_spans.spans.borrow_mut());

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

let parser = Parser::new(&sess.parse_sess, body, true, rustc_parse::MACRO_ARGUMENTS);
let argument_map = match parse_tt(&mut Cow::Borrowed(&parser), &argument_gram) {
let argument_map = match parse_tt(&mut Cow::Borrowed(&parser), &argument_gram, def.ident) {
Success(m) => m,
Failure(token, msg) => {
let s = parse_failure_msg(&token);
6 changes: 5 additions & 1 deletion compiler/rustc_typeck/src/collect.rs
Original file line number Diff line number Diff line change
@@ -2771,7 +2771,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
}
} else if tcx.sess.check_name(attr, sym::target_feature) {
if !tcx.is_closure(id) && tcx.fn_sig(id).unsafety() == hir::Unsafety::Normal {
if tcx.sess.target.is_like_wasm {
if tcx.sess.target.is_like_wasm || tcx.sess.opts.actually_rustdoc {
// The `#[target_feature]` attribute is allowed on
// WebAssembly targets on all functions, including safe
// ones. Other targets require that `#[target_feature]` is
@@ -2785,6 +2785,10 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
// deterministic trap. There is no undefined behavior when
// executing WebAssembly so `#[target_feature]` is allowed
// on safe functions (but again, only for WebAssembly)
//
// Note that this is also allowed if `actually_rustdoc` so
// if a target is documenting some wasm-specific code then
// it's not spuriously denied.
} else if !tcx.features().target_feature_11 {
let mut err = feature_err(
&tcx.sess.parse_sess,
50 changes: 43 additions & 7 deletions library/alloc/src/string.rs
Original file line number Diff line number Diff line change
@@ -2491,6 +2491,9 @@ impl AsRef<[u8]> for String {
#[cfg(not(no_global_oom_handling))]
#[stable(feature = "rust1", since = "1.0.0")]
impl From<&str> for String {
/// Converts a `&str` into a [`String`].
///
/// The result is allocated on the heap.
#[inline]
fn from(s: &str) -> String {
s.to_owned()
@@ -2500,7 +2503,7 @@ impl From<&str> for String {
#[cfg(not(no_global_oom_handling))]
#[stable(feature = "from_mut_str_for_string", since = "1.44.0")]
impl From<&mut str> for String {
/// Converts a `&mut str` into a `String`.
/// Converts a `&mut str` into a [`String`].
///
/// The result is allocated on the heap.
#[inline]
@@ -2512,6 +2515,9 @@ impl From<&mut str> for String {
#[cfg(not(no_global_oom_handling))]
#[stable(feature = "from_ref_string", since = "1.35.0")]
impl From<&String> for String {
/// Converts a `&String` into a [`String`].
///
/// This clones `s` and returns the clone.
#[inline]
fn from(s: &String) -> String {
s.clone()
@@ -2522,7 +2528,7 @@ impl From<&String> for String {
#[cfg(not(test))]
#[stable(feature = "string_from_box", since = "1.18.0")]
impl From<Box<str>> for String {
/// Converts the given boxed `str` slice to a `String`.
/// Converts the given boxed `str` slice to a [`String`].
/// It is notable that the `str` slice is owned.
///
/// # Examples
@@ -2544,7 +2550,7 @@ impl From<Box<str>> for String {
#[cfg(not(no_global_oom_handling))]
#[stable(feature = "box_from_str", since = "1.20.0")]
impl From<String> for Box<str> {
/// Converts the given `String` to a boxed `str` slice that is owned.
/// Converts the given [`String`] to a boxed `str` slice that is owned.
///
/// # Examples
///
@@ -2565,6 +2571,22 @@ impl From<String> for Box<str> {
#[cfg(not(no_global_oom_handling))]
#[stable(feature = "string_from_cow_str", since = "1.14.0")]
impl<'a> From<Cow<'a, str>> for String {
/// Converts a clone-on-write string to an owned
/// instance of [`String`].
///
/// This extracts the owned string,
/// clones the string if it is not already owned.
///
/// # Example
///
/// ```
/// # use std::borrow::Cow;
/// // If the string is not owned...
/// let cow: Cow<str> = Cow::Borrowed("eggplant");
/// // It will allocate on the heap and copy the string.
/// let owned: String = String::from(cow);
/// assert_eq!(&owned[..], "eggplant");
/// ```
fn from(s: Cow<'a, str>) -> String {
s.into_owned()
}
@@ -2573,7 +2595,7 @@ impl<'a> From<Cow<'a, str>> for String {
#[cfg(not(no_global_oom_handling))]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> From<&'a str> for Cow<'a, str> {
/// Converts a string slice into a Borrowed variant.
/// Converts a string slice into a [`Borrowed`] variant.
/// No heap allocation is performed, and the string
/// is not copied.
///
@@ -2583,6 +2605,8 @@ impl<'a> From<&'a str> for Cow<'a, str> {
/// # use std::borrow::Cow;
/// assert_eq!(Cow::from("eggplant"), Cow::Borrowed("eggplant"));
/// ```
///
/// [`Borrowed`]: crate::borrow::Cow::Borrowed
#[inline]
fn from(s: &'a str) -> Cow<'a, str> {
Cow::Borrowed(s)
@@ -2592,7 +2616,7 @@ impl<'a> From<&'a str> for Cow<'a, str> {
#[cfg(not(no_global_oom_handling))]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> From<String> for Cow<'a, str> {
/// Converts a String into an Owned variant.
/// Converts a [`String`] into an [`Owned`] variant.
/// No heap allocation is performed, and the string
/// is not copied.
///
@@ -2604,6 +2628,8 @@ impl<'a> From<String> for Cow<'a, str> {
/// let s2 = "eggplant".to_string();
/// assert_eq!(Cow::from(s), Cow::<'static, str>::Owned(s2));
/// ```
///
/// [`Owned`]: crate::borrow::Cow::Owned
#[inline]
fn from(s: String) -> Cow<'a, str> {
Cow::Owned(s)
@@ -2613,7 +2639,7 @@ impl<'a> From<String> for Cow<'a, str> {
#[cfg(not(no_global_oom_handling))]
#[stable(feature = "cow_from_string_ref", since = "1.28.0")]
impl<'a> From<&'a String> for Cow<'a, str> {
/// Converts a String reference into a Borrowed variant.
/// Converts a [`String`] reference into a [`Borrowed`] variant.
/// No heap allocation is performed, and the string
/// is not copied.
///
@@ -2624,6 +2650,8 @@ impl<'a> From<&'a String> for Cow<'a, str> {
/// let s = "eggplant".to_string();
/// assert_eq!(Cow::from(&s), Cow::Borrowed("eggplant"));
/// ```
///
/// [`Borrowed`]: crate::borrow::Cow::Borrowed
#[inline]
fn from(s: &'a String) -> Cow<'a, str> {
Cow::Borrowed(s.as_str())
@@ -2656,7 +2684,7 @@ impl<'a> FromIterator<String> for Cow<'a, str> {

#[stable(feature = "from_string_for_vec_u8", since = "1.14.0")]
impl From<String> for Vec<u8> {
/// Converts the given `String` to a vector `Vec` that holds values of type `u8`.
/// Converts the given [`String`] to a vector [`Vec`] that holds values of type [`u8`].
///
/// # Examples
///
@@ -2802,6 +2830,14 @@ impl FusedIterator for Drain<'_> {}
#[cfg(not(no_global_oom_handling))]
#[stable(feature = "from_char_for_string", since = "1.46.0")]
impl From<char> for String {
/// Allocates an owned [`String`] from a single character.
///
/// # Example
/// ```rust
/// let c: char = 'a';
/// let s: String = String::from(c);
/// assert_eq!("a", &s[..]);
/// ```
#[inline]
fn from(c: char) -> Self {
c.to_string()
14 changes: 3 additions & 11 deletions library/proc_macro/src/lib.rs
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@
#![feature(restricted_std)]
#![feature(rustc_attrs)]
#![feature(min_specialization)]
#![feature(bound_cloned)]
#![recursion_limit = "256"]

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

use std::cmp::Ordering;
use std::ops::{Bound, RangeBounds};
use std::ops::RangeBounds;
use std::path::PathBuf;
use std::str::FromStr;
use std::{error, fmt, iter, mem};
@@ -1162,16 +1163,7 @@ impl Literal {
// was 'c' or whether it was '\u{63}'.
#[unstable(feature = "proc_macro_span", issue = "54725")]
pub fn subspan<R: RangeBounds<usize>>(&self, range: R) -> Option<Span> {
// HACK(eddyb) something akin to `Option::cloned`, but for `Bound<&T>`.
fn cloned_bound<T: Clone>(bound: Bound<&T>) -> Bound<T> {
match bound {
Bound::Included(x) => Bound::Included(x.clone()),
Bound::Excluded(x) => Bound::Excluded(x.clone()),
Bound::Unbounded => Bound::Unbounded,
}
}

self.0.subspan(cloned_bound(range.start_bound()), cloned_bound(range.end_bound())).map(Span)
self.0.subspan(range.start_bound().cloned(), range.end_bound().cloned()).map(Span)
}
}

10 changes: 10 additions & 0 deletions library/std/src/io/impls.rs
Original file line number Diff line number Diff line change
@@ -87,6 +87,11 @@ impl<S: Seek + ?Sized> Seek for &mut S {
fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
(**self).seek(pos)
}

#[inline]
fn stream_position(&mut self) -> io::Result<u64> {
(**self).stream_position()
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<B: BufRead + ?Sized> BufRead for &mut B {
@@ -186,6 +191,11 @@ impl<S: Seek + ?Sized> Seek for Box<S> {
fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
(**self).seek(pos)
}

#[inline]
fn stream_position(&mut self) -> io::Result<u64> {
(**self).stream_position()
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<B: BufRead + ?Sized> BufRead for Box<B> {
Loading