Skip to content

Commit f412fb5

Browse files
committed
Auto merge of #80708 - JohnTitor:rollup-6esk027, r=JohnTitor
Rollup of 12 pull requests Successful merges: - #80442 (Mention Arc::make_mut and Rc::make_mut in the documentation of Cow) - #80533 (bootstrap: clippy fixes) - #80538 (Add check for `[T;N]`/`usize` mismatch in astconv) - #80612 (Remove reverted change from relnotes) - #80627 (Builder: Warn if test file does not exist) - #80637 (Use Option::filter instead of open-coding it) - #80643 (Move variable into the only branch where it is relevant) - #80656 (Fixed documentation error for `std::hint::spin_loop`) - #80666 (Fix missing link for "fully qualified syntax") - #80672 (./x.py clippy: allow the most noisy lints) - #80677 (doc -- list edit for consistency) - #80696 (make sure that promoteds which fail to evaluate in dead const code behave correctly) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9919ad6 + 9daac58 commit f412fb5

File tree

23 files changed

+173
-88
lines changed

23 files changed

+173
-88
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -3745,6 +3745,7 @@ version = "0.0.0"
37453745
dependencies = [
37463746
"rustc_ast",
37473747
"rustc_data_structures",
3748+
"rustc_feature",
37483749
"rustc_index",
37493750
"rustc_macros",
37503751
"rustc_serialize",

RELEASES.md

-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ Libraries
4545

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

5049
Stabilized APIs
5150
---------------
@@ -110,7 +109,6 @@ related tools.
110109
[76199]: https://github.com/rust-lang/rust/pull/76199
111110
[76119]: https://github.com/rust-lang/rust/pull/76119
112111
[75914]: https://github.com/rust-lang/rust/pull/75914
113-
[74989]: https://github.com/rust-lang/rust/pull/74989
114112
[79004]: https://github.com/rust-lang/rust/pull/79004
115113
[78676]: https://github.com/rust-lang/rust/pull/78676
116114
[79904]: https://github.com/rust-lang/rust/issues/79904

compiler/rustc_hir/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ doctest = false
99

1010
[dependencies]
1111
rustc_target = { path = "../rustc_target" }
12+
rustc_feature = { path = "../rustc_feature" }
1213
rustc_macros = { path = "../rustc_macros" }
1314
rustc_data_structures = { path = "../rustc_data_structures" }
1415
rustc_index = { path = "../rustc_index" }

compiler/rustc_hir/src/hir.rs

+8
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,14 @@ impl GenericArg<'_> {
290290
GenericArg::Const(_) => "const",
291291
}
292292
}
293+
294+
pub fn to_ord(&self, feats: &rustc_feature::Features) -> ast::ParamKindOrd {
295+
match self {
296+
GenericArg::Lifetime(_) => ast::ParamKindOrd::Lifetime,
297+
GenericArg::Type(_) => ast::ParamKindOrd::Type,
298+
GenericArg::Const(_) => ast::ParamKindOrd::Const { unordered: feats.const_generics },
299+
}
300+
}
293301
}
294302

295303
#[derive(Debug, HashStable_Generic)]

compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

+9-19
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,18 @@ impl<'a, 'tcx> FindHirNodeVisitor<'a, 'tcx> {
4343
}
4444

4545
fn node_ty_contains_target(&mut self, hir_id: HirId) -> Option<Ty<'tcx>> {
46-
let ty_opt = self
47-
.infcx
46+
self.infcx
4847
.in_progress_typeck_results
49-
.and_then(|typeck_results| typeck_results.borrow().node_type_opt(hir_id));
50-
match ty_opt {
51-
Some(ty) => {
52-
let ty = self.infcx.resolve_vars_if_possible(ty);
53-
if ty.walk().any(|inner| {
48+
.and_then(|typeck_results| typeck_results.borrow().node_type_opt(hir_id))
49+
.map(|ty| self.infcx.resolve_vars_if_possible(ty))
50+
.filter(|ty| {
51+
ty.walk().any(|inner| {
5452
inner == self.target
5553
|| match (inner.unpack(), self.target.unpack()) {
5654
(GenericArgKind::Type(inner_ty), GenericArgKind::Type(target_ty)) => {
55+
use ty::{Infer, TyVar};
5756
match (inner_ty.kind(), target_ty.kind()) {
58-
(
59-
&ty::Infer(ty::TyVar(a_vid)),
60-
&ty::Infer(ty::TyVar(b_vid)),
61-
) => self
57+
(&Infer(TyVar(a_vid)), &Infer(TyVar(b_vid))) => self
6258
.infcx
6359
.inner
6460
.borrow_mut()
@@ -69,14 +65,8 @@ impl<'a, 'tcx> FindHirNodeVisitor<'a, 'tcx> {
6965
}
7066
_ => false,
7167
}
72-
}) {
73-
Some(ty)
74-
} else {
75-
None
76-
}
77-
}
78-
None => None,
79-
}
68+
})
69+
})
8070
}
8171
}
8272

compiler/rustc_metadata/src/rmeta/decoder.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -1341,15 +1341,14 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
13411341
return &[];
13421342
}
13431343

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

1352-
if let Some(filter) = filter {
13531352
if let Some(impls) = self.trait_impls.get(&filter) {
13541353
tcx.arena.alloc_from_iter(
13551354
impls.decode(self).map(|(idx, simplified_self_ty)| {

compiler/rustc_middle/src/ty/mod.rs

+9
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,15 @@ impl GenericParamDefKind {
801801
GenericParamDefKind::Const => "constant",
802802
}
803803
}
804+
pub fn to_ord(&self, tcx: TyCtxt<'_>) -> ast::ParamKindOrd {
805+
match self {
806+
GenericParamDefKind::Lifetime => ast::ParamKindOrd::Lifetime,
807+
GenericParamDefKind::Type { .. } => ast::ParamKindOrd::Type,
808+
GenericParamDefKind::Const => {
809+
ast::ParamKindOrd::Const { unordered: tcx.features().const_generics }
810+
}
811+
}
812+
}
804813
}
805814

806815
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable)]

compiler/rustc_typeck/src/astconv/generics.rs

+51-41
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_hir::GenericArg;
1111
use rustc_middle::ty::{
1212
self, subst, subst::SubstsRef, GenericParamDef, GenericParamDefKind, Ty, TyCtxt,
1313
};
14-
use rustc_session::{lint::builtin::LATE_BOUND_LIFETIME_ARGUMENTS, Session};
14+
use rustc_session::lint::builtin::LATE_BOUND_LIFETIME_ARGUMENTS;
1515
use rustc_span::{symbol::kw, MultiSpan, Span};
1616

1717
use smallvec::SmallVec;
@@ -20,62 +20,72 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
2020
/// Report an error that a generic argument did not match the generic parameter that was
2121
/// expected.
2222
fn generic_arg_mismatch_err(
23-
sess: &Session,
23+
tcx: TyCtxt<'_>,
2424
arg: &GenericArg<'_>,
25-
kind: &'static str,
25+
param: &GenericParamDef,
2626
possible_ordering_error: bool,
2727
help: Option<&str>,
2828
) {
29+
let sess = tcx.sess;
2930
let mut err = struct_span_err!(
3031
sess,
3132
arg.span(),
3233
E0747,
3334
"{} provided when a {} was expected",
3435
arg.descr(),
35-
kind,
36+
param.kind.descr(),
3637
);
3738

38-
let unordered = sess.features_untracked().const_generics;
39-
let kind_ord = match kind {
40-
"lifetime" => ParamKindOrd::Lifetime,
41-
"type" => ParamKindOrd::Type,
42-
"constant" => ParamKindOrd::Const { unordered },
43-
// It's more concise to match on the string representation, though it means
44-
// the match is non-exhaustive.
45-
_ => bug!("invalid generic parameter kind {}", kind),
46-
};
47-
48-
if let ParamKindOrd::Const { .. } = kind_ord {
39+
if let GenericParamDefKind::Const { .. } = param.kind {
4940
if let GenericArg::Type(hir::Ty { kind: hir::TyKind::Infer, .. }) = arg {
5041
err.help("const arguments cannot yet be inferred with `_`");
5142
}
5243
}
5344

54-
let arg_ord = match arg {
55-
GenericArg::Lifetime(_) => ParamKindOrd::Lifetime,
56-
GenericArg::Type(_) => ParamKindOrd::Type,
57-
GenericArg::Const(_) => ParamKindOrd::Const { unordered },
58-
};
59-
60-
if matches!(arg, GenericArg::Type(hir::Ty { kind: hir::TyKind::Path { .. }, .. }))
61-
&& matches!(kind_ord, ParamKindOrd::Const { .. })
62-
{
63-
let suggestions = vec![
64-
(arg.span().shrink_to_lo(), String::from("{ ")),
65-
(arg.span().shrink_to_hi(), String::from(" }")),
66-
];
67-
err.multipart_suggestion(
68-
"if this generic argument was intended as a const parameter, \
45+
// Specific suggestion set for diagnostics
46+
match (arg, &param.kind) {
47+
(
48+
GenericArg::Type(hir::Ty { kind: hir::TyKind::Path { .. }, .. }),
49+
GenericParamDefKind::Const { .. },
50+
) => {
51+
let suggestions = vec![
52+
(arg.span().shrink_to_lo(), String::from("{ ")),
53+
(arg.span().shrink_to_hi(), String::from(" }")),
54+
];
55+
err.multipart_suggestion(
56+
"if this generic argument was intended as a const parameter, \
6957
try surrounding it with braces:",
70-
suggestions,
71-
Applicability::MaybeIncorrect,
72-
);
58+
suggestions,
59+
Applicability::MaybeIncorrect,
60+
);
61+
}
62+
(
63+
GenericArg::Type(hir::Ty { kind: hir::TyKind::Array(_, len), .. }),
64+
GenericParamDefKind::Const { .. },
65+
) if tcx.type_of(param.def_id) == tcx.types.usize => {
66+
let snippet = sess.source_map().span_to_snippet(tcx.hir().span(len.hir_id));
67+
if let Ok(snippet) = snippet {
68+
err.span_suggestion(
69+
arg.span(),
70+
"array type provided where a `usize` was expected, try",
71+
format!("{{ {} }}", snippet),
72+
Applicability::MaybeIncorrect,
73+
);
74+
}
75+
}
76+
_ => {}
7377
}
7478

79+
let kind_ord = param.kind.to_ord(tcx);
80+
let arg_ord = arg.to_ord(&tcx.features());
81+
7582
// This note is only true when generic parameters are strictly ordered by their kind.
7683
if possible_ordering_error && kind_ord.cmp(&arg_ord) != core::cmp::Ordering::Equal {
77-
let (first, last) =
78-
if kind_ord < arg_ord { (kind, arg.descr()) } else { (arg.descr(), kind) };
84+
let (first, last) = if kind_ord < arg_ord {
85+
(param.kind.descr(), arg.descr())
86+
} else {
87+
(arg.descr(), param.kind.descr())
88+
};
7989
err.note(&format!("{} arguments must be provided before {} arguments", first, last));
8090
if let Some(help) = help {
8191
err.help(help);
@@ -203,7 +213,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
203213
// We expected a lifetime argument, but got a type or const
204214
// argument. That means we're inferring the lifetimes.
205215
substs.push(ctx.inferred_kind(None, param, infer_args));
206-
force_infer_lt = Some(arg);
216+
force_infer_lt = Some((arg, param));
207217
params.next();
208218
}
209219
(GenericArg::Lifetime(_), _, ExplicitLateBound::Yes) => {
@@ -213,7 +223,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
213223
// ignore it.
214224
args.next();
215225
}
216-
(_, kind, _) => {
226+
(_, _, _) => {
217227
// We expected one kind of parameter, but the user provided
218228
// another. This is an error. However, if we already know that
219229
// the arguments don't match up with the parameters, we won't issue
@@ -256,9 +266,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
256266
param_types_present.dedup();
257267

258268
Self::generic_arg_mismatch_err(
259-
tcx.sess,
269+
tcx,
260270
arg,
261-
kind.descr(),
271+
param,
262272
!args_iter.clone().is_sorted_by_key(|arg| match arg {
263273
GenericArg::Lifetime(_) => ParamKindOrd::Lifetime,
264274
GenericArg::Type(_) => ParamKindOrd::Type,
@@ -315,9 +325,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
315325
{
316326
let kind = arg.descr();
317327
assert_eq!(kind, "lifetime");
318-
let provided =
328+
let (provided_arg, param) =
319329
force_infer_lt.expect("lifetimes ought to have been inferred");
320-
Self::generic_arg_mismatch_err(tcx.sess, provided, kind, false, None);
330+
Self::generic_arg_mismatch_err(tcx, provided_arg, param, false, None);
321331
}
322332

323333
break;

library/alloc/src/borrow.rs

+5
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ where
103103
/// is desired, `to_mut` will obtain a mutable reference to an owned
104104
/// value, cloning if necessary.
105105
///
106+
/// If you need reference-counting pointers, note that
107+
/// [`Rc::make_mut`][crate::rc::Rc::make_mut] and
108+
/// [`Arc::make_mut`][crate::sync::Arc::make_mut] can provide clone-on-write
109+
/// functionality as well.
110+
///
106111
/// # Examples
107112
///
108113
/// ```

library/alloc/src/rc.rs

+1
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@
238238
//! [downgrade]: Rc::downgrade
239239
//! [upgrade]: Weak::upgrade
240240
//! [mutability]: core::cell#introducing-mutability-inside-of-something-immutable
241+
//! [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
241242
242243
#![stable(feature = "rust1", since = "1.0.0")]
243244

library/core/src/hint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub const unsafe fn unreachable_unchecked() -> ! {
9191
/// };
9292
///
9393
/// // Back on our current thread, we wait for the value to be set
94-
/// while live.load(Ordering::Acquire) {
94+
/// while !live.load(Ordering::Acquire) {
9595
/// // The spin loop is a hint to the CPU that we're waiting, but probably
9696
/// // not for very long
9797
/// hint::spin_loop();

library/core/src/iter/adapters/zip.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ impl<A: Debug + TrustedRandomAccess, B: Debug + TrustedRandomAccess> ZipFmt<A, B
397397
/// only be called at most `self.size() - idx - 1` times.
398398
/// 4. After `get_unchecked` is called, then only the following methods will be
399399
/// called on `self`:
400-
/// * `std::clone::Clone::clone`
400+
/// * `std::clone::Clone::clone()`
401401
/// * `std::iter::Iterator::size_hint()`
402402
/// * `std::iter::Iterator::next_back()`
403403
/// * `std::iter::Iterator::__iterator_get_unchecked()`

src/bootstrap/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1534,7 +1534,7 @@ impl Rustflags {
15341534
fn arg(&mut self, arg: &str) -> &mut Self {
15351535
assert_eq!(arg.split(' ').count(), 1);
15361536
if !self.0.is_empty() {
1537-
self.0.push_str(" ");
1537+
self.0.push(' ');
15381538
}
15391539
self.0.push_str(arg);
15401540
self

src/bootstrap/channel.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ impl GitInfo {
7474
if let Some(ref inner) = self.inner {
7575
version.push_str(" (");
7676
version.push_str(&inner.short_sha);
77-
version.push_str(" ");
77+
version.push(' ');
7878
version.push_str(&inner.commit_date);
79-
version.push_str(")");
79+
version.push(')');
8080
}
8181
version
8282
}

src/bootstrap/check.rs

+11
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ fn args(builder: &Builder<'_>) -> Vec<String> {
2121
}
2222

2323
if let Subcommand::Clippy { fix, .. } = builder.config.cmd {
24+
// disable the most spammy clippy lints
25+
let ignored_lints = vec![
26+
"many_single_char_names", // there are a lot in stdarch
27+
"collapsible_if",
28+
"type_complexity",
29+
"missing_safety_doc", // almost 3K warnings
30+
"too_many_arguments",
31+
"needless_lifetimes", // people want to keep the lifetimes
32+
"wrong_self_convention",
33+
];
2434
let mut args = vec![];
2535
if fix {
2636
#[rustfmt::skip]
@@ -33,6 +43,7 @@ fn args(builder: &Builder<'_>) -> Vec<String> {
3343
]));
3444
}
3545
args.extend(strings(&["--", "--cap-lints", "warn"]));
46+
args.extend(ignored_lints.iter().map(|lint| format!("-Aclippy::{}", lint)));
3647
args
3748
} else {
3849
vec![]

src/bootstrap/dist.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1326,17 +1326,17 @@ impl Step for Extended {
13261326
license += &builder.read(&builder.src.join("COPYRIGHT"));
13271327
license += &builder.read(&builder.src.join("LICENSE-APACHE"));
13281328
license += &builder.read(&builder.src.join("LICENSE-MIT"));
1329-
license.push_str("\n");
1330-
license.push_str("\n");
1329+
license.push('\n');
1330+
license.push('\n');
13311331

13321332
let rtf = r"{\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset0 Arial;}}\nowwrap\fs18";
13331333
let mut rtf = rtf.to_string();
1334-
rtf.push_str("\n");
1334+
rtf.push('\n');
13351335
for line in license.lines() {
13361336
rtf.push_str(line);
13371337
rtf.push_str("\\line ");
13381338
}
1339-
rtf.push_str("}");
1339+
rtf.push('}');
13401340

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

0 commit comments

Comments
 (0)