Skip to content
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

Rollup of 12 pull requests #80708

Merged
merged 24 commits into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
303203f
Mention Arc::make_mut and Rc::make_mut in the documentation of Cow
steffahn Dec 28, 2020
87423fb
bootstrap: clippy fixes
matthiaskrgr Dec 30, 2020
a2f2778
Remove reverted change from relnotes
XAMPPRocky Jan 2, 2021
203d502
Use Option::filter instead of open-coding it
LingMan Jan 3, 2021
af7134e
Move variable into the only branch where it is relevant
LingMan Jan 3, 2021
514b0ce
Fixed documentation error
booleancoercion Jan 3, 2021
6d45d05
Fix missing link for "fully qualified syntax"
jjlin Jan 3, 2021
6a4b24e
./x.py clippy: allow the most noisy lints
matthiaskrgr Jan 4, 2021
e152582
doc -- list edit for consistency
Jan 4, 2021
54883e0
Add check for array/usize mismatch in astconv
JulianKnodt Dec 30, 2020
6002e78
Builder: Warn if test file does not exist
bugadani Jan 4, 2021
92d1b39
make sure that promoteds which fail to evaluate in dead const code be…
RalfJung Jan 4, 2021
bdf8bbd
Rollup merge of #80442 - steffahn:mention_arc_in_cow, r=Mark-Simulacrum
JohnTitor Jan 5, 2021
4c4e8e7
Rollup merge of #80533 - matthiaskrgr:bootstrap_clppy, r=Mark-Simulacrum
JohnTitor Jan 5, 2021
be2a3f8
Rollup merge of #80538 - JulianKnodt:err_usize, r=lcnr
JohnTitor Jan 5, 2021
d85c2fe
Rollup merge of #80612 - rust-lang:XAMPPRocky-patch-1, r=Mark-Simulacrum
JohnTitor Jan 5, 2021
1c6593c
Rollup merge of #80627 - bugadani:warn, r=Mark-Simulacrum
JohnTitor Jan 5, 2021
faf8bed
Rollup merge of #80637 - LingMan:filter, r=oli-obk
JohnTitor Jan 5, 2021
598d189
Rollup merge of #80643 - LingMan:unwrap, r=oli-obk
JohnTitor Jan 5, 2021
cbdc241
Rollup merge of #80656 - booleancoercion:master, r=sfackler
JohnTitor Jan 5, 2021
cda26a6
Rollup merge of #80666 - jjlin:master, r=Dylan-DPC
JohnTitor Jan 5, 2021
cb43373
Rollup merge of #80672 - matthiaskrgr:xpy_clippy_less_noise, r=Mark-S…
JohnTitor Jan 5, 2021
ee94d9d
Rollup merge of #80677 - kw-fn:patch-2, r=jyn514
JohnTitor Jan 5, 2021
9daac58
Rollup merge of #80696 - RalfJung:failing-promoteds, r=oli-obk
JohnTitor Jan 5, 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 Cargo.lock
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading