Skip to content

Rollup of 7 pull requests #74810

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

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions src/etc/htmldocck.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@
from htmlentitydefs import name2codepoint

# "void elements" (no closing tag) from the HTML Standard section 12.1.2
VOID_ELEMENTS = set(['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen',
'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr'])
VOID_ELEMENTS = {'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'keygen',
'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr'}

# Python 2 -> 3 compatibility
try:
Expand All @@ -146,7 +146,7 @@ def __init__(self, target=None):
self.__builder = target or ET.TreeBuilder()

def handle_starttag(self, tag, attrs):
attrs = dict((k, v or '') for k, v in attrs)
attrs = {k: v or '' for k, v in attrs}
self.__builder.start(tag, attrs)
if tag in VOID_ELEMENTS:
self.__builder.end(tag)
Expand All @@ -155,7 +155,7 @@ def handle_endtag(self, tag):
self.__builder.end(tag)

def handle_startendtag(self, tag, attrs):
attrs = dict((k, v or '') for k, v in attrs)
attrs = {k: v or '' for k, v in attrs}
self.__builder.start(tag, attrs)
self.__builder.end(tag)

Expand Down
1 change: 1 addition & 0 deletions src/liballoc/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#![feature(map_first_last)]
#![feature(new_uninit)]
#![feature(pattern)]
#![feature(str_split_once)]
#![feature(trusted_len)]
#![feature(try_reserve)]
#![feature(unboxed_closures)]
Expand Down
24 changes: 24 additions & 0 deletions src/liballoc/tests/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1318,6 +1318,30 @@ fn test_rsplitn() {
assert_eq!(split, ["mb\n", "\nMäry häd ä little lämb\nLittle l"]);
}

#[test]
fn test_split_once() {
assert_eq!("".split_once("->"), None);
assert_eq!("-".split_once("->"), None);
assert_eq!("->".split_once("->"), Some(("", "")));
assert_eq!("a->".split_once("->"), Some(("a", "")));
assert_eq!("->b".split_once("->"), Some(("", "b")));
assert_eq!("a->b".split_once("->"), Some(("a", "b")));
assert_eq!("a->b->c".split_once("->"), Some(("a", "b->c")));
assert_eq!("---".split_once("--"), Some(("", "-")));
}

#[test]
fn test_rsplit_once() {
assert_eq!("".rsplit_once("->"), None);
assert_eq!("-".rsplit_once("->"), None);
assert_eq!("->".rsplit_once("->"), Some(("", "")));
assert_eq!("a->".rsplit_once("->"), Some(("a", "")));
assert_eq!("->b".rsplit_once("->"), Some(("", "b")));
assert_eq!("a->b".rsplit_once("->"), Some(("a", "b")));
assert_eq!("a->b->c".rsplit_once("->"), Some(("a->b", "c")));
assert_eq!("---".rsplit_once("--"), Some(("-", "")));
}

#[test]
fn test_split_whitespace() {
let data = "\n \tMäry häd\tä little lämb\nLittle lämb\n";
Expand Down
41 changes: 41 additions & 0 deletions src/libcore/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3610,6 +3610,47 @@ impl str {
RSplitN(self.splitn(n, pat).0)
}

/// Splits the string on the first occurrence of the specified delimiter and
/// returns prefix before delimiter and suffix after delimiter.
///
/// # Examples
///
/// ```
/// #![feature(str_split_once)]
///
/// assert_eq!("cfg".split_once('='), None);
/// assert_eq!("cfg=foo".split_once('='), Some(("cfg", "foo")));
/// assert_eq!("cfg=foo=bar".split_once('='), Some(("cfg", "foo=bar")));
/// ```
#[unstable(feature = "str_split_once", reason = "newly added", issue = "74773")]
#[inline]
pub fn split_once<'a, P: Pattern<'a>>(&'a self, delimiter: P) -> Option<(&'a str, &'a str)> {
let (start, end) = delimiter.into_searcher(self).next_match()?;
Some((&self[..start], &self[end..]))
}

/// Splits the string on the last occurrence of the specified delimiter and
/// returns prefix before delimiter and suffix after delimiter.
///
/// # Examples
///
/// ```
/// #![feature(str_split_once)]
///
/// assert_eq!("cfg".rsplit_once('='), None);
/// assert_eq!("cfg=foo".rsplit_once('='), Some(("cfg", "foo")));
/// assert_eq!("cfg=foo=bar".rsplit_once('='), Some(("cfg=foo", "bar")));
/// ```
#[unstable(feature = "str_split_once", reason = "newly added", issue = "74773")]
#[inline]
pub fn rsplit_once<'a, P>(&'a self, delimiter: P) -> Option<(&'a str, &'a str)>
where
P: Pattern<'a, Searcher: ReverseSearcher<'a>>,
{
let (start, end) = delimiter.into_searcher(self).next_match_back()?;
Some((&self[..start], &self[end..]))
}

/// An iterator over the disjoint matches of a pattern within the given string
/// slice.
///
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ pub trait LintContext: Sized {
}
}
BuiltinLintDiagnostics::DeprecatedMacro(suggestion, span) => {
stability::deprecation_suggestion(&mut db, suggestion, span)
stability::deprecation_suggestion(&mut db, "macro", suggestion, span)
}
BuiltinLintDiagnostics::UnusedDocComment(span) => {
db.span_label(span, "rustdoc does not generate documentation for macro invocations");
Expand Down
20 changes: 13 additions & 7 deletions src/librustc_middle/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,29 +166,31 @@ pub fn deprecation_in_effect(is_since_rustc_version: bool, since: Option<&str>)

pub fn deprecation_suggestion(
diag: &mut DiagnosticBuilder<'_>,
kind: &str,
suggestion: Option<Symbol>,
span: Span,
) {
if let Some(suggestion) = suggestion {
diag.span_suggestion(
span,
"replace the use of the deprecated item",
&format!("replace the use of the deprecated {}", kind),
suggestion.to_string(),
Applicability::MachineApplicable,
);
}
}

pub fn deprecation_message(depr: &Deprecation, path: &str) -> (String, &'static Lint) {
pub fn deprecation_message(depr: &Deprecation, kind: &str, path: &str) -> (String, &'static Lint) {
let (message, lint) = if deprecation_in_effect(
depr.is_since_rustc_version,
depr.since.map(Symbol::as_str).as_deref(),
) {
(format!("use of deprecated item '{}'", path), DEPRECATED)
(format!("use of deprecated {} `{}`", kind, path), DEPRECATED)
} else {
(
format!(
"use of item '{}' that will be deprecated in future version {}",
"use of {} `{}` that will be deprecated in future version {}",
kind,
path,
depr.since.unwrap()
),
Expand Down Expand Up @@ -224,6 +226,7 @@ fn late_report_deprecation(
lint: &'static Lint,
span: Span,
hir_id: HirId,
def_id: DefId,
) {
if span.in_derive_expansion() {
return;
Expand All @@ -232,7 +235,8 @@ fn late_report_deprecation(
tcx.struct_span_lint_hir(lint, hir_id, span, |lint| {
let mut diag = lint.build(message);
if let hir::Node::Expr(_) = tcx.hir().get(hir_id) {
deprecation_suggestion(&mut diag, suggestion, span);
let kind = tcx.def_kind(def_id).descr(def_id);
deprecation_suggestion(&mut diag, kind, suggestion, span);
}
diag.emit()
});
Expand Down Expand Up @@ -304,15 +308,17 @@ impl<'tcx> TyCtxt<'tcx> {
// #[rustc_deprecated] however wants to emit down the whole
// hierarchy.
if !skip || depr_entry.attr.is_since_rustc_version {
let (message, lint) =
deprecation_message(&depr_entry.attr, &self.def_path_str(def_id));
let path = &self.def_path_str(def_id);
let kind = self.def_kind(def_id).descr(def_id);
let (message, lint) = deprecation_message(&depr_entry.attr, kind, path);
late_report_deprecation(
self,
&message,
depr_entry.attr.suggestion,
lint,
span,
id,
def_id,
);
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,7 @@ impl<'a> Resolver<'a> {
}
if let Some(depr) = &ext.deprecation {
let path = pprust::path_to_string(&path);
let (message, lint) = stability::deprecation_message(depr, &path);
let (message, lint) = stability::deprecation_message(depr, "macro", &path);
stability::early_report_deprecation(
&mut self.lint_buffer,
&message,
Expand Down
86 changes: 45 additions & 41 deletions src/librustc_typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1483,36 +1483,25 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
tcx.collect_referenced_late_bound_regions(&ty::Binder::bind(ty));
debug!("late_bound_in_trait_ref = {:?}", late_bound_in_trait_ref);
debug!("late_bound_in_ty = {:?}", late_bound_in_ty);
for br in late_bound_in_ty.difference(&late_bound_in_trait_ref) {
let br_name = match *br {
ty::BrNamed(_, name) => format!("lifetime `{}`", name),
_ => "an anonymous lifetime".to_string(),
};
// FIXME: point at the type params that don't have appropriate lifetimes:
// struct S1<F: for<'a> Fn(&i32, &i32) -> &'a i32>(F);
// ---- ---- ^^^^^^^
let mut err = struct_span_err!(
tcx.sess,
binding.span,
E0582,
"binding for associated type `{}` references {}, \
which does not appear in the trait input types",
binding.item_name,
br_name
);

if let ty::BrAnon(_) = *br {
// The only way for an anonymous lifetime to wind up
// in the return type but **also** be unconstrained is
// if it only appears in "associated types" in the
// input. See #62200 for an example. In this case,
// though we can easily give a hint that ought to be
// relevant.
err.note("lifetimes appearing in an associated type are not considered constrained");
}

err.emit();
}
// FIXME: point at the type params that don't have appropriate lifetimes:
// struct S1<F: for<'a> Fn(&i32, &i32) -> &'a i32>(F);
// ---- ---- ^^^^^^^
self.validate_late_bound_regions(
late_bound_in_trait_ref,
late_bound_in_ty,
|br_name| {
struct_span_err!(
tcx.sess,
binding.span,
E0582,
"binding for associated type `{}` references {}, \
which does not appear in the trait input types",
binding.item_name,
br_name
)
},
);
}
}

Expand Down Expand Up @@ -3085,33 +3074,48 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
tcx.collect_constrained_late_bound_regions(&inputs.map_bound(|i| i.to_owned()));
let output = bare_fn_ty.output();
let late_bound_in_ret = tcx.collect_referenced_late_bound_regions(&output);
for br in late_bound_in_ret.difference(&late_bound_in_args) {
let lifetime_name = match *br {
ty::BrNamed(_, name) => format!("lifetime `{}`,", name),
ty::BrAnon(_) | ty::BrEnv => "an anonymous lifetime".to_string(),
};
let mut err = struct_span_err!(

self.validate_late_bound_regions(late_bound_in_args, late_bound_in_ret, |br_name| {
struct_span_err!(
tcx.sess,
decl.output.span(),
E0581,
"return type references {} which is not constrained by the fn input types",
lifetime_name
);
"return type references {}, which is not constrained by the fn input types",
br_name
)
});

bare_fn_ty
}

fn validate_late_bound_regions(
&self,
constrained_regions: FxHashSet<ty::BoundRegion>,
referenced_regions: FxHashSet<ty::BoundRegion>,
generate_err: impl Fn(&str) -> rustc_errors::DiagnosticBuilder<'tcx>,
) {
for br in referenced_regions.difference(&constrained_regions) {
let br_name = match *br {
ty::BrNamed(_, name) => format!("lifetime `{}`", name),
ty::BrAnon(_) | ty::BrEnv => "an anonymous lifetime".to_string(),
};

let mut err = generate_err(&br_name);

if let ty::BrAnon(_) = *br {
// The only way for an anonymous lifetime to wind up
// in the return type but **also** be unconstrained is
// if it only appears in "associated types" in the
// input. See #47511 for an example. In this case,
// input. See #47511 and #62200 for examples. In this case,
// though we can easily give a hint that ought to be
// relevant.
err.note(
"lifetimes appearing in an associated type are not considered constrained",
);
}

err.emit();
}

bare_fn_ty
}

/// Given the bounds on an object, determines what single region bound (if any) we can
Expand Down
1 change: 0 additions & 1 deletion src/librustdoc/html/static/themes/ayu.css
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ pre {

pre.rust .comment, pre.rust .doccomment {
color: #788797;
font-style: italic;
}

nav:not(.sidebar) {
Expand Down
7 changes: 5 additions & 2 deletions src/libstd/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@

use crate::cmp;
use crate::fmt;
use crate::mem;
use crate::memchr;
use crate::ops::{Deref, DerefMut};
use crate::ptr;
Expand Down Expand Up @@ -1435,12 +1434,15 @@ pub trait Write {
/// ```
#[unstable(feature = "write_all_vectored", issue = "70436")]
fn write_all_vectored(&mut self, mut bufs: &mut [IoSlice<'_>]) -> Result<()> {
// Guarantee that bufs is empty if it contains no data,
// to avoid calling write_vectored if there is no data to be written.
bufs = IoSlice::advance(bufs, 0);
while !bufs.is_empty() {
match self.write_vectored(bufs) {
Ok(0) => {
return Err(Error::new(ErrorKind::WriteZero, "failed to write whole buffer"));
}
Ok(n) => bufs = IoSlice::advance(mem::take(&mut bufs), n),
Ok(n) => bufs = IoSlice::advance(bufs, n),
Err(ref e) if e.kind() == ErrorKind::Interrupted => {}
Err(e) => return Err(e),
}
Expand Down Expand Up @@ -2958,6 +2960,7 @@ mod tests {
#[rustfmt::skip] // Becomes unreadable otherwise.
let tests: Vec<(_, &'static [u8])> = vec![
(vec![], &[]),
(vec![IoSlice::new(&[]), IoSlice::new(&[])], &[]),
(vec![IoSlice::new(&[1])], &[1]),
(vec![IoSlice::new(&[1, 2])], &[1, 2]),
(vec![IoSlice::new(&[1, 2, 3])], &[1, 2, 3]),
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/binding/func-arg-ref-pattern.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// run-pass
// exec-env:RUST_POISON_ON_FREE=1

// Test argument patterns where we create refs to the inside of
// boxes. Make sure that we don't free the box as we match the
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/conditional-compilation/cfg-attr-multi-true.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
#[cfg_attr(all(), deprecated, must_use)]
struct MustUseDeprecated {}

impl MustUseDeprecated { //~ warning: use of deprecated item
fn new() -> MustUseDeprecated { //~ warning: use of deprecated item
MustUseDeprecated {} //~ warning: use of deprecated item
impl MustUseDeprecated { //~ warning: use of deprecated
fn new() -> MustUseDeprecated { //~ warning: use of deprecated
MustUseDeprecated {} //~ warning: use of deprecated
}
}

fn main() {
MustUseDeprecated::new(); //~ warning: use of deprecated item
MustUseDeprecated::new(); //~ warning: use of deprecated
//~| warning: unused `MustUseDeprecated` that must be used
}
Loading