Skip to content

Commit

Permalink
Auto merge of rust-lang#80708 - JohnTitor:rollup-6esk027, r=JohnTitor
Browse files Browse the repository at this point in the history
Rollup of 12 pull requests

Successful merges:

 - rust-lang#80442 (Mention Arc::make_mut and Rc::make_mut in the documentation of Cow)
 - rust-lang#80533 (bootstrap: clippy fixes)
 - rust-lang#80538 (Add check for `[T;N]`/`usize` mismatch in astconv)
 - rust-lang#80612 (Remove reverted change from relnotes)
 - rust-lang#80627 (Builder: Warn if test file does not exist)
 - rust-lang#80637 (Use Option::filter instead of open-coding it)
 - rust-lang#80643 (Move variable into the only branch where it is relevant)
 - rust-lang#80656 (Fixed documentation error for `std::hint::spin_loop`)
 - rust-lang#80666 (Fix missing link for "fully qualified syntax")
 - rust-lang#80672 (./x.py clippy: allow the most noisy lints)
 - rust-lang#80677 (doc -- list edit for consistency)
 - rust-lang#80696 (make sure that promoteds which fail to evaluate in dead const code behave correctly)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Jan 5, 2021
2 parents 9919ad6 + 9daac58 commit f412fb5
Show file tree
Hide file tree
Showing 23 changed files with 173 additions and 88 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Expand Up @@ -3745,6 +3745,7 @@ version = "0.0.0"
dependencies = [
"rustc_ast",
"rustc_data_structures",
"rustc_feature",
"rustc_index",
"rustc_macros",
"rustc_serialize",
Expand Down
2 changes: 0 additions & 2 deletions RELEASES.md
Expand Up @@ -45,7 +45,6 @@ Libraries

- [`RangeInclusive` now checks for exhaustion when calling `contains` and indexing.][78109]
- [`ToString::to_string` now no longer shrinks the internal buffer in the default implementation.][77997]
- [`ops::{Index, IndexMut}` are now implemented for fixed sized arrays of any length.][74989]

Stabilized APIs
---------------
Expand Down Expand Up @@ -110,7 +109,6 @@ related tools.
[76199]: https://github.com/rust-lang/rust/pull/76199
[76119]: https://github.com/rust-lang/rust/pull/76119
[75914]: https://github.com/rust-lang/rust/pull/75914
[74989]: https://github.com/rust-lang/rust/pull/74989
[79004]: https://github.com/rust-lang/rust/pull/79004
[78676]: https://github.com/rust-lang/rust/pull/78676
[79904]: https://github.com/rust-lang/rust/issues/79904
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir/Cargo.toml
Expand Up @@ -9,6 +9,7 @@ doctest = false

[dependencies]
rustc_target = { path = "../rustc_target" }
rustc_feature = { path = "../rustc_feature" }
rustc_macros = { path = "../rustc_macros" }
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_index = { path = "../rustc_index" }
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_hir/src/hir.rs
Expand Up @@ -290,6 +290,14 @@ impl GenericArg<'_> {
GenericArg::Const(_) => "const",
}
}

pub fn to_ord(&self, feats: &rustc_feature::Features) -> ast::ParamKindOrd {
match self {
GenericArg::Lifetime(_) => ast::ParamKindOrd::Lifetime,
GenericArg::Type(_) => ast::ParamKindOrd::Type,
GenericArg::Const(_) => ast::ParamKindOrd::Const { unordered: feats.const_generics },
}
}
}

#[derive(Debug, HashStable_Generic)]
Expand Down
28 changes: 9 additions & 19 deletions compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs
Expand Up @@ -43,22 +43,18 @@ impl<'a, 'tcx> FindHirNodeVisitor<'a, 'tcx> {
}

fn node_ty_contains_target(&mut self, hir_id: HirId) -> Option<Ty<'tcx>> {
let ty_opt = self
.infcx
self.infcx
.in_progress_typeck_results
.and_then(|typeck_results| typeck_results.borrow().node_type_opt(hir_id));
match ty_opt {
Some(ty) => {
let ty = self.infcx.resolve_vars_if_possible(ty);
if ty.walk().any(|inner| {
.and_then(|typeck_results| typeck_results.borrow().node_type_opt(hir_id))
.map(|ty| self.infcx.resolve_vars_if_possible(ty))
.filter(|ty| {
ty.walk().any(|inner| {
inner == self.target
|| match (inner.unpack(), self.target.unpack()) {
(GenericArgKind::Type(inner_ty), GenericArgKind::Type(target_ty)) => {
use ty::{Infer, TyVar};
match (inner_ty.kind(), target_ty.kind()) {
(
&ty::Infer(ty::TyVar(a_vid)),
&ty::Infer(ty::TyVar(b_vid)),
) => self
(&Infer(TyVar(a_vid)), &Infer(TyVar(b_vid))) => self
.infcx
.inner
.borrow_mut()
Expand All @@ -69,14 +65,8 @@ impl<'a, 'tcx> FindHirNodeVisitor<'a, 'tcx> {
}
_ => false,
}
}) {
Some(ty)
} else {
None
}
}
None => None,
}
})
})
}
}

Expand Down
15 changes: 7 additions & 8 deletions compiler/rustc_metadata/src/rmeta/decoder.rs
Expand Up @@ -1341,15 +1341,14 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
return &[];
}

// Do a reverse lookup beforehand to avoid touching the crate_num
// hash map in the loop below.
let filter = match filter.map(|def_id| self.reverse_translate_def_id(def_id)) {
Some(Some(def_id)) => Some((def_id.krate.as_u32(), def_id.index)),
Some(None) => return &[],
None => None,
};
if let Some(def_id) = filter {
// Do a reverse lookup beforehand to avoid touching the crate_num
// hash map in the loop below.
let filter = match self.reverse_translate_def_id(def_id) {
Some(def_id) => (def_id.krate.as_u32(), def_id.index),
None => return &[],
};

if let Some(filter) = filter {
if let Some(impls) = self.trait_impls.get(&filter) {
tcx.arena.alloc_from_iter(
impls.decode(self).map(|(idx, simplified_self_ty)| {
Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_middle/src/ty/mod.rs
Expand Up @@ -801,6 +801,15 @@ impl GenericParamDefKind {
GenericParamDefKind::Const => "constant",
}
}
pub fn to_ord(&self, tcx: TyCtxt<'_>) -> ast::ParamKindOrd {
match self {
GenericParamDefKind::Lifetime => ast::ParamKindOrd::Lifetime,
GenericParamDefKind::Type { .. } => ast::ParamKindOrd::Type,
GenericParamDefKind::Const => {
ast::ParamKindOrd::Const { unordered: tcx.features().const_generics }
}
}
}
}

#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable)]
Expand Down
92 changes: 51 additions & 41 deletions compiler/rustc_typeck/src/astconv/generics.rs
Expand Up @@ -11,7 +11,7 @@ use rustc_hir::GenericArg;
use rustc_middle::ty::{
self, subst, subst::SubstsRef, GenericParamDef, GenericParamDefKind, Ty, TyCtxt,
};
use rustc_session::{lint::builtin::LATE_BOUND_LIFETIME_ARGUMENTS, Session};
use rustc_session::lint::builtin::LATE_BOUND_LIFETIME_ARGUMENTS;
use rustc_span::{symbol::kw, MultiSpan, Span};

use smallvec::SmallVec;
Expand All @@ -20,62 +20,72 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
/// Report an error that a generic argument did not match the generic parameter that was
/// expected.
fn generic_arg_mismatch_err(
sess: &Session,
tcx: TyCtxt<'_>,
arg: &GenericArg<'_>,
kind: &'static str,
param: &GenericParamDef,
possible_ordering_error: bool,
help: Option<&str>,
) {
let sess = tcx.sess;
let mut err = struct_span_err!(
sess,
arg.span(),
E0747,
"{} provided when a {} was expected",
arg.descr(),
kind,
param.kind.descr(),
);

let unordered = sess.features_untracked().const_generics;
let kind_ord = match kind {
"lifetime" => ParamKindOrd::Lifetime,
"type" => ParamKindOrd::Type,
"constant" => ParamKindOrd::Const { unordered },
// It's more concise to match on the string representation, though it means
// the match is non-exhaustive.
_ => bug!("invalid generic parameter kind {}", kind),
};

if let ParamKindOrd::Const { .. } = kind_ord {
if let GenericParamDefKind::Const { .. } = param.kind {
if let GenericArg::Type(hir::Ty { kind: hir::TyKind::Infer, .. }) = arg {
err.help("const arguments cannot yet be inferred with `_`");
}
}

let arg_ord = match arg {
GenericArg::Lifetime(_) => ParamKindOrd::Lifetime,
GenericArg::Type(_) => ParamKindOrd::Type,
GenericArg::Const(_) => ParamKindOrd::Const { unordered },
};

if matches!(arg, GenericArg::Type(hir::Ty { kind: hir::TyKind::Path { .. }, .. }))
&& matches!(kind_ord, ParamKindOrd::Const { .. })
{
let suggestions = vec![
(arg.span().shrink_to_lo(), String::from("{ ")),
(arg.span().shrink_to_hi(), String::from(" }")),
];
err.multipart_suggestion(
"if this generic argument was intended as a const parameter, \
// Specific suggestion set for diagnostics
match (arg, &param.kind) {
(
GenericArg::Type(hir::Ty { kind: hir::TyKind::Path { .. }, .. }),
GenericParamDefKind::Const { .. },
) => {
let suggestions = vec![
(arg.span().shrink_to_lo(), String::from("{ ")),
(arg.span().shrink_to_hi(), String::from(" }")),
];
err.multipart_suggestion(
"if this generic argument was intended as a const parameter, \
try surrounding it with braces:",
suggestions,
Applicability::MaybeIncorrect,
);
suggestions,
Applicability::MaybeIncorrect,
);
}
(
GenericArg::Type(hir::Ty { kind: hir::TyKind::Array(_, len), .. }),
GenericParamDefKind::Const { .. },
) if tcx.type_of(param.def_id) == tcx.types.usize => {
let snippet = sess.source_map().span_to_snippet(tcx.hir().span(len.hir_id));
if let Ok(snippet) = snippet {
err.span_suggestion(
arg.span(),
"array type provided where a `usize` was expected, try",
format!("{{ {} }}", snippet),
Applicability::MaybeIncorrect,
);
}
}
_ => {}
}

let kind_ord = param.kind.to_ord(tcx);
let arg_ord = arg.to_ord(&tcx.features());

// This note is only true when generic parameters are strictly ordered by their kind.
if possible_ordering_error && kind_ord.cmp(&arg_ord) != core::cmp::Ordering::Equal {
let (first, last) =
if kind_ord < arg_ord { (kind, arg.descr()) } else { (arg.descr(), kind) };
let (first, last) = if kind_ord < arg_ord {
(param.kind.descr(), arg.descr())
} else {
(arg.descr(), param.kind.descr())
};
err.note(&format!("{} arguments must be provided before {} arguments", first, last));
if let Some(help) = help {
err.help(help);
Expand Down Expand Up @@ -203,7 +213,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// We expected a lifetime argument, but got a type or const
// argument. That means we're inferring the lifetimes.
substs.push(ctx.inferred_kind(None, param, infer_args));
force_infer_lt = Some(arg);
force_infer_lt = Some((arg, param));
params.next();
}
(GenericArg::Lifetime(_), _, ExplicitLateBound::Yes) => {
Expand All @@ -213,7 +223,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// ignore it.
args.next();
}
(_, kind, _) => {
(_, _, _) => {
// We expected one kind of parameter, but the user provided
// another. This is an error. However, if we already know that
// the arguments don't match up with the parameters, we won't issue
Expand Down Expand Up @@ -256,9 +266,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
param_types_present.dedup();

Self::generic_arg_mismatch_err(
tcx.sess,
tcx,
arg,
kind.descr(),
param,
!args_iter.clone().is_sorted_by_key(|arg| match arg {
GenericArg::Lifetime(_) => ParamKindOrd::Lifetime,
GenericArg::Type(_) => ParamKindOrd::Type,
Expand Down Expand Up @@ -315,9 +325,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
{
let kind = arg.descr();
assert_eq!(kind, "lifetime");
let provided =
let (provided_arg, param) =
force_infer_lt.expect("lifetimes ought to have been inferred");
Self::generic_arg_mismatch_err(tcx.sess, provided, kind, false, None);
Self::generic_arg_mismatch_err(tcx, provided_arg, param, false, None);
}

break;
Expand Down
5 changes: 5 additions & 0 deletions library/alloc/src/borrow.rs
Expand Up @@ -103,6 +103,11 @@ where
/// is desired, `to_mut` will obtain a mutable reference to an owned
/// value, cloning if necessary.
///
/// If you need reference-counting pointers, note that
/// [`Rc::make_mut`][crate::rc::Rc::make_mut] and
/// [`Arc::make_mut`][crate::sync::Arc::make_mut] can provide clone-on-write
/// functionality as well.
///
/// # Examples
///
/// ```
Expand Down
1 change: 1 addition & 0 deletions library/alloc/src/rc.rs
Expand Up @@ -238,6 +238,7 @@
//! [downgrade]: Rc::downgrade
//! [upgrade]: Weak::upgrade
//! [mutability]: core::cell#introducing-mutability-inside-of-something-immutable
//! [fully qualified syntax]: https://doc.rust-lang.org/book/ch19-03-advanced-traits.html#fully-qualified-syntax-for-disambiguation-calling-methods-with-the-same-name

#![stable(feature = "rust1", since = "1.0.0")]

Expand Down
2 changes: 1 addition & 1 deletion library/core/src/hint.rs
Expand Up @@ -91,7 +91,7 @@ pub const unsafe fn unreachable_unchecked() -> ! {
/// };
///
/// // Back on our current thread, we wait for the value to be set
/// while live.load(Ordering::Acquire) {
/// while !live.load(Ordering::Acquire) {
/// // The spin loop is a hint to the CPU that we're waiting, but probably
/// // not for very long
/// hint::spin_loop();
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/iter/adapters/zip.rs
Expand Up @@ -397,7 +397,7 @@ impl<A: Debug + TrustedRandomAccess, B: Debug + TrustedRandomAccess> ZipFmt<A, B
/// only be called at most `self.size() - idx - 1` times.
/// 4. After `get_unchecked` is called, then only the following methods will be
/// called on `self`:
/// * `std::clone::Clone::clone`
/// * `std::clone::Clone::clone()`
/// * `std::iter::Iterator::size_hint()`
/// * `std::iter::Iterator::next_back()`
/// * `std::iter::Iterator::__iterator_get_unchecked()`
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/builder.rs
Expand Up @@ -1534,7 +1534,7 @@ impl Rustflags {
fn arg(&mut self, arg: &str) -> &mut Self {
assert_eq!(arg.split(' ').count(), 1);
if !self.0.is_empty() {
self.0.push_str(" ");
self.0.push(' ');
}
self.0.push_str(arg);
self
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/channel.rs
Expand Up @@ -74,9 +74,9 @@ impl GitInfo {
if let Some(ref inner) = self.inner {
version.push_str(" (");
version.push_str(&inner.short_sha);
version.push_str(" ");
version.push(' ');
version.push_str(&inner.commit_date);
version.push_str(")");
version.push(')');
}
version
}
Expand Down
11 changes: 11 additions & 0 deletions src/bootstrap/check.rs
Expand Up @@ -21,6 +21,16 @@ fn args(builder: &Builder<'_>) -> Vec<String> {
}

if let Subcommand::Clippy { fix, .. } = builder.config.cmd {
// disable the most spammy clippy lints
let ignored_lints = vec![
"many_single_char_names", // there are a lot in stdarch
"collapsible_if",
"type_complexity",
"missing_safety_doc", // almost 3K warnings
"too_many_arguments",
"needless_lifetimes", // people want to keep the lifetimes
"wrong_self_convention",
];
let mut args = vec![];
if fix {
#[rustfmt::skip]
Expand All @@ -33,6 +43,7 @@ fn args(builder: &Builder<'_>) -> Vec<String> {
]));
}
args.extend(strings(&["--", "--cap-lints", "warn"]));
args.extend(ignored_lints.iter().map(|lint| format!("-Aclippy::{}", lint)));
args
} else {
vec![]
Expand Down
8 changes: 4 additions & 4 deletions src/bootstrap/dist.rs
Expand Up @@ -1326,17 +1326,17 @@ impl Step for Extended {
license += &builder.read(&builder.src.join("COPYRIGHT"));
license += &builder.read(&builder.src.join("LICENSE-APACHE"));
license += &builder.read(&builder.src.join("LICENSE-MIT"));
license.push_str("\n");
license.push_str("\n");
license.push('\n');
license.push('\n');

let rtf = r"{\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset0 Arial;}}\nowwrap\fs18";
let mut rtf = rtf.to_string();
rtf.push_str("\n");
rtf.push('\n');
for line in license.lines() {
rtf.push_str(line);
rtf.push_str("\\line ");
}
rtf.push_str("}");
rtf.push('}');

fn filter(contents: &str, marker: &str) -> String {
let start = format!("tool-{}-start", marker);
Expand Down

0 comments on commit f412fb5

Please sign in to comment.