Skip to content

Commit a5dfdc5

Browse files
committed
Auto merge of #59684 - Centril:rollup-n7pnare, r=Centril
Rollup of 6 pull requests Successful merges: - #59316 (Internal lints take 2) - #59663 (Be more direct about borrow contract) - #59664 (Updated the documentation of spin_loop and spin_loop_hint) - #59666 (Updated the environment description in rustc.) - #59669 (Reduce repetition in librustc(_lint) wrt. impl LintPass by using macros) - #59677 (rustfix coverage: Skip UI tests with non-json error-format) Failed merges: r? @ghost
2 parents 314a79c + 231bd48 commit a5dfdc5

File tree

72 files changed

+939
-716
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+939
-716
lines changed

src/bootstrap/bin/rustc.rs

+5
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,11 @@ fn main() {
316316
}
317317
}
318318

319+
// This is required for internal lints.
320+
if stage != "0" {
321+
cmd.arg("-Zunstable-options");
322+
}
323+
319324
// Force all crates compiled by this compiler to (a) be unstable and (b)
320325
// allow the `rustc_private` feature to link to other unstable crates
321326
// also in the sysroot. We also do this for host crates, since those

src/doc/man/rustc.1

+2-2
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ Optimize with possible levels 0\[en]3
265265

266266
.SH ENVIRONMENT
267267

268-
Some of these affect the output of the compiler, while others affect programs
269-
which link to the standard library.
268+
Some of these affect only test harness programs (generated via rustc --test);
269+
others affect all programs which link to the Rust standard library.
270270

271271
.TP
272272
\fBRUST_TEST_THREADS\fR

src/libarena/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
test(no_crate_inject, attr(deny(warnings))))]
1313

1414
#![deny(rust_2018_idioms)]
15+
#![cfg_attr(not(stage0), deny(internal))]
1516

1617
#![feature(alloc)]
1718
#![feature(core_intrinsics)]

src/libcore/borrow.rs

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
/// on the identical behavior of these additional trait implementations.
3333
/// These traits will likely appear as additional trait bounds.
3434
///
35+
/// In particular `Eq`, `Ord` and `Hash` must be equivalent for
36+
/// borrowed and owned values: `x.borrow() == y.borrow()` should give the
37+
/// same result as `x == y`.
38+
///
3539
/// If generic code merely needs to work for all types that can
3640
/// provide a reference to related type `T`, it is often better to use
3741
/// [`AsRef<T>`] as more types can safely implement it.

src/libcore/convert.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,13 @@ pub const fn identity<T>(x: T) -> T { x }
105105
/// `&T` or write a custom function.
106106
///
107107
///
108-
/// `AsRef` is very similar to, but serves a slightly different purpose than [`Borrow`]:
108+
/// `AsRef` has the same signature as [`Borrow`], but `Borrow` is different in few aspects:
109109
///
110-
/// - Use `AsRef` when the goal is to simply convert into a reference
111-
/// - Use `Borrow` when the goal is related to writing code that is agnostic to
112-
/// the type of borrow and whether it is a reference or value
110+
/// - Unlike `AsRef`, `Borrow` has a blanket impl for any `T`, and can be used to accept either
111+
/// a reference or a value.
112+
/// - `Borrow` also requires that `Hash`, `Eq` and `Ord` for borrowed value are
113+
/// equivalent to those of the owned value. For this reason, if you want to
114+
/// borrow only a single field of a struct you can implement `AsRef`, but not `Borrow`.
113115
///
114116
/// [`Borrow`]: ../../std/borrow/trait.Borrow.html
115117
///

src/libcore/hint.rs

+20-7
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,28 @@ pub unsafe fn unreachable_unchecked() -> ! {
5050
intrinsics::unreachable()
5151
}
5252

53-
/// Save power or switch hyperthreads in a busy-wait spin-loop.
53+
/// Signals the processor that it is entering a busy-wait spin-loop.
5454
///
55-
/// This function is deliberately more primitive than
56-
/// [`std::thread::yield_now`](../../std/thread/fn.yield_now.html) and
57-
/// does not directly yield to the system's scheduler.
58-
/// In some cases it might be useful to use a combination of both functions.
59-
/// Careful benchmarking is advised.
55+
/// Upon receiving spin-loop signal the processor can optimize its behavior by, for example, saving
56+
/// power or switching hyper-threads.
6057
///
61-
/// On some platforms this function may not do anything at all.
58+
/// This function is different than [`std::thread::yield_now`] which directly yields to the
59+
/// system's scheduler, whereas `spin_loop` only signals the processor that it is entering a
60+
/// busy-wait spin-loop without yielding control to the system's scheduler.
61+
///
62+
/// Using a busy-wait spin-loop with `spin_loop` is ideally used in situations where a
63+
/// contended lock is held by another thread executed on a different CPU and where the waiting
64+
/// times are relatively small. Because entering busy-wait spin-loop does not trigger the system's
65+
/// scheduler, no overhead for switching threads occurs. However, if the thread holding the
66+
/// contended lock is running on the same CPU, the spin-loop is likely to occupy an entire CPU slice
67+
/// before switching to the thread that holds the lock. If the contending lock is held by a thread
68+
/// on the same CPU or if the waiting times for acquiring the lock are longer, it is often better to
69+
/// use [`std::thread::yield_now`].
70+
///
71+
/// **Note**: On platforms that do not support receiving spin-loop hints this function does not
72+
/// do anything at all.
73+
///
74+
/// [`std::thread::yield_now`]: ../../std/thread/fn.yield_now.html
6275
#[inline]
6376
#[unstable(feature = "renamed_spin_loop", issue = "55002")]
6477
pub fn spin_loop() {

src/libcore/sync/atomic.rs

+20-7
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,28 @@ use fmt;
124124

125125
use hint::spin_loop;
126126

127-
/// Save power or switch hyperthreads in a busy-wait spin-loop.
127+
/// Signals the processor that it is entering a busy-wait spin-loop.
128128
///
129-
/// This function is deliberately more primitive than
130-
/// [`std::thread::yield_now`](../../../std/thread/fn.yield_now.html) and
131-
/// does not directly yield to the system's scheduler.
132-
/// In some cases it might be useful to use a combination of both functions.
133-
/// Careful benchmarking is advised.
129+
/// Upon receiving spin-loop signal the processor can optimize its behavior by, for example, saving
130+
/// power or switching hyper-threads.
134131
///
135-
/// On some platforms this function may not do anything at all.
132+
/// This function is different than [`std::thread::yield_now`] which directly yields to the
133+
/// system's scheduler, whereas `spin_loop_hint` only signals the processor that it is entering a
134+
/// busy-wait spin-loop without yielding control to the system's scheduler.
135+
///
136+
/// Using a busy-wait spin-loop with `spin_loop_hint` is ideally used in situations where a
137+
/// contended lock is held by another thread executed on a different CPU and where the waiting
138+
/// times are relatively small. Because entering busy-wait spin-loop does not trigger the system's
139+
/// scheduler, no overhead for switching threads occurs. However, if the thread holding the
140+
/// contended lock is running on the same CPU, the spin-loop is likely to occupy an entire CPU slice
141+
/// before switching to the thread that holds the lock. If the contending lock is held by a thread
142+
/// on the same CPU or if the waiting times for acquiring the lock are longer, it is often better to
143+
/// use [`std::thread::yield_now`].
144+
///
145+
/// **Note**: On platforms that do not support receiving spin-loop hints this function does not
146+
/// do anything at all.
147+
///
148+
/// [`std::thread::yield_now`]: ../../../std/thread/fn.yield_now.html
136149
#[inline]
137150
#[stable(feature = "spin_loop_hint", since = "1.24.0")]
138151
pub fn spin_loop_hint() {

src/libfmt_macros/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
test(attr(deny(warnings))))]
1010

1111
#![deny(rust_2018_idioms)]
12+
#![cfg_attr(not(stage0), deny(internal))]
1213

1314
#![feature(nll)]
1415
#![feature(rustc_private)]

src/librustc/hir/def_id.rs

+104-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use crate::ty;
2-
use crate::ty::TyCtxt;
3-
use crate::hir::map::definitions::FIRST_FREE_HIGH_DEF_INDEX;
1+
use crate::ty::{self, print::Printer, subst::Kind, Ty, TyCtxt};
2+
use crate::hir::map::definitions::{DisambiguatedDefPathData, FIRST_FREE_HIGH_DEF_INDEX};
43
use rustc_data_structures::indexed_vec::Idx;
54
use serialize;
65
use std::fmt;
76
use std::u32;
7+
use syntax::symbol::{LocalInternedString, Symbol};
88

99
newtype_index! {
1010
pub struct CrateId {
@@ -252,6 +252,107 @@ impl DefId {
252252
format!("module `{}`", tcx.def_path_str(*self))
253253
}
254254
}
255+
256+
/// Check if a `DefId`'s path matches the given absolute type path usage.
257+
// Uplifted from rust-lang/rust-clippy
258+
pub fn match_path<'a, 'tcx>(self, tcx: TyCtxt<'a, 'tcx, 'tcx>, path: &[&str]) -> bool {
259+
pub struct AbsolutePathPrinter<'a, 'tcx> {
260+
pub tcx: TyCtxt<'a, 'tcx, 'tcx>,
261+
}
262+
263+
impl<'tcx> Printer<'tcx, 'tcx> for AbsolutePathPrinter<'_, 'tcx> {
264+
type Error = !;
265+
266+
type Path = Vec<LocalInternedString>;
267+
type Region = ();
268+
type Type = ();
269+
type DynExistential = ();
270+
271+
fn tcx<'a>(&'a self) -> TyCtxt<'a, 'tcx, 'tcx> {
272+
self.tcx
273+
}
274+
275+
fn print_region(self, _region: ty::Region<'_>) -> Result<Self::Region, Self::Error> {
276+
Ok(())
277+
}
278+
279+
fn print_type(self, _ty: Ty<'tcx>) -> Result<Self::Type, Self::Error> {
280+
Ok(())
281+
}
282+
283+
fn print_dyn_existential(
284+
self,
285+
_predicates: &'tcx ty::List<ty::ExistentialPredicate<'tcx>>,
286+
) -> Result<Self::DynExistential, Self::Error> {
287+
Ok(())
288+
}
289+
290+
fn path_crate(self, cnum: CrateNum) -> Result<Self::Path, Self::Error> {
291+
Ok(vec![self.tcx.original_crate_name(cnum).as_str()])
292+
}
293+
294+
fn path_qualified(
295+
self,
296+
self_ty: Ty<'tcx>,
297+
trait_ref: Option<ty::TraitRef<'tcx>>,
298+
) -> Result<Self::Path, Self::Error> {
299+
if trait_ref.is_none() {
300+
if let ty::Adt(def, substs) = self_ty.sty {
301+
return self.print_def_path(def.did, substs);
302+
}
303+
}
304+
305+
// This shouldn't ever be needed, but just in case:
306+
Ok(vec![match trait_ref {
307+
Some(trait_ref) => Symbol::intern(&format!("{:?}", trait_ref)).as_str(),
308+
None => Symbol::intern(&format!("<{}>", self_ty)).as_str(),
309+
}])
310+
}
311+
312+
fn path_append_impl(
313+
self,
314+
print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
315+
_disambiguated_data: &DisambiguatedDefPathData,
316+
self_ty: Ty<'tcx>,
317+
trait_ref: Option<ty::TraitRef<'tcx>>,
318+
) -> Result<Self::Path, Self::Error> {
319+
let mut path = print_prefix(self)?;
320+
321+
// This shouldn't ever be needed, but just in case:
322+
path.push(match trait_ref {
323+
Some(trait_ref) => {
324+
Symbol::intern(&format!("<impl {} for {}>", trait_ref, self_ty)).as_str()
325+
},
326+
None => Symbol::intern(&format!("<impl {}>", self_ty)).as_str(),
327+
});
328+
329+
Ok(path)
330+
}
331+
332+
fn path_append(
333+
self,
334+
print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
335+
disambiguated_data: &DisambiguatedDefPathData,
336+
) -> Result<Self::Path, Self::Error> {
337+
let mut path = print_prefix(self)?;
338+
path.push(disambiguated_data.data.as_interned_str().as_str());
339+
Ok(path)
340+
}
341+
342+
fn path_generic_args(
343+
self,
344+
print_prefix: impl FnOnce(Self) -> Result<Self::Path, Self::Error>,
345+
_args: &[Kind<'tcx>],
346+
) -> Result<Self::Path, Self::Error> {
347+
print_prefix(self)
348+
}
349+
}
350+
351+
let names = AbsolutePathPrinter { tcx }.print_def_path(self, &[]).unwrap();
352+
353+
names.len() == path.len()
354+
&& names.into_iter().zip(path.iter()).all(|(a, &b)| *a == *b)
355+
}
255356
}
256357

257358
impl serialize::UseSpecializedEncodable for DefId {}

src/librustc/ich/hcx.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use crate::session::Session;
99

1010
use std::cmp::Ord;
1111
use std::hash as std_hash;
12-
use std::collections::HashMap;
1312
use std::cell::RefCell;
1413

1514
use syntax::ast;
@@ -394,13 +393,12 @@ impl<'a> HashStable<StableHashingContext<'a>> for DelimSpan {
394393
}
395394
}
396395

397-
pub fn hash_stable_trait_impls<'a, 'gcx, W, R>(
396+
pub fn hash_stable_trait_impls<'a, 'gcx, W>(
398397
hcx: &mut StableHashingContext<'a>,
399398
hasher: &mut StableHasher<W>,
400399
blanket_impls: &[DefId],
401-
non_blanket_impls: &HashMap<fast_reject::SimplifiedType, Vec<DefId>, R>)
402-
where W: StableHasherResult,
403-
R: std_hash::BuildHasher,
400+
non_blanket_impls: &FxHashMap<fast_reject::SimplifiedType, Vec<DefId>>)
401+
where W: StableHasherResult
404402
{
405403
{
406404
let mut blanket_impls: SmallVec<[_; 8]> = blanket_impls

src/librustc/infer/error_reporting/mod.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ use crate::hir::Node;
5656
use crate::middle::region;
5757
use crate::traits::{ObligationCause, ObligationCauseCode};
5858
use crate::ty::error::TypeError;
59-
use crate::ty::{self, subst::{Subst, SubstsRef}, Region, Ty, TyCtxt, TyKind, TypeFoldable};
59+
use crate::ty::{self, subst::{Subst, SubstsRef}, Region, Ty, TyCtxt, TypeFoldable};
6060
use errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString};
6161
use std::{cmp, fmt};
6262
use syntax_pos::{Pos, Span};
@@ -1094,14 +1094,14 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10941094
(_, false, _) => {
10951095
if let Some(exp_found) = exp_found {
10961096
let (def_id, ret_ty) = match exp_found.found.sty {
1097-
TyKind::FnDef(def, _) => {
1097+
ty::FnDef(def, _) => {
10981098
(Some(def), Some(self.tcx.fn_sig(def).output()))
10991099
}
11001100
_ => (None, None),
11011101
};
11021102

11031103
let exp_is_struct = match exp_found.expected.sty {
1104-
TyKind::Adt(def, _) => def.is_struct(),
1104+
ty::Adt(def, _) => def.is_struct(),
11051105
_ => false,
11061106
};
11071107

@@ -1140,8 +1140,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
11401140
diag: &mut DiagnosticBuilder<'tcx>,
11411141
) {
11421142
match (&exp_found.expected.sty, &exp_found.found.sty) {
1143-
(TyKind::Adt(exp_def, exp_substs), TyKind::Ref(_, found_ty, _)) => {
1144-
if let TyKind::Adt(found_def, found_substs) = found_ty.sty {
1143+
(ty::Adt(exp_def, exp_substs), ty::Ref(_, found_ty, _)) => {
1144+
if let ty::Adt(found_def, found_substs) = found_ty.sty {
11451145
let path_str = format!("{:?}", exp_def);
11461146
if exp_def == &found_def {
11471147
let opt_msg = "you can convert from `&Option<T>` to `Option<&T>` using \
@@ -1164,17 +1164,17 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
11641164
let mut show_suggestion = true;
11651165
for (exp_ty, found_ty) in exp_substs.types().zip(found_substs.types()) {
11661166
match exp_ty.sty {
1167-
TyKind::Ref(_, exp_ty, _) => {
1167+
ty::Ref(_, exp_ty, _) => {
11681168
match (&exp_ty.sty, &found_ty.sty) {
1169-
(_, TyKind::Param(_)) |
1170-
(_, TyKind::Infer(_)) |
1171-
(TyKind::Param(_), _) |
1172-
(TyKind::Infer(_), _) => {}
1169+
(_, ty::Param(_)) |
1170+
(_, ty::Infer(_)) |
1171+
(ty::Param(_), _) |
1172+
(ty::Infer(_), _) => {}
11731173
_ if ty::TyS::same_type(exp_ty, found_ty) => {}
11741174
_ => show_suggestion = false,
11751175
};
11761176
}
1177-
TyKind::Param(_) | TyKind::Infer(_) => {}
1177+
ty::Param(_) | ty::Infer(_) => {}
11781178
_ => show_suggestion = false,
11791179
}
11801180
}

src/librustc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
3030

3131
#![deny(rust_2018_idioms)]
32+
#![cfg_attr(not(stage0), deny(internal))]
3233
#![allow(explicit_outlives_requirements)]
3334

3435
#![feature(arbitrary_self_types)]

0 commit comments

Comments
 (0)