Skip to content

Commit 81e0270

Browse files
committed
Auto merge of #76975 - RalfJung:rollup-s2wiuqr, r=RalfJung
Rollup of 15 pull requests Successful merges: - #76732 (Add docs for `BasicBlock`) - #76832 (Let backends define custom targets) - #76866 (Remove unused feature gates from library/ crates) - #76875 (Move to intra-doc links in library/alloc/src/collections/binary_heap.rs) - #76876 (Move to intra-doc links in collections/btree/map.rs and collections/linked_list.rs) - #76877 (Move to intra-doc links in collections/vec_deque.rs and collections/vec_deque/drain.rs) - #76878 (Move the version number to a plaintext file) - #76883 (README.md: Remove prompts from code blocks) - #76887 (Add missing examples on HashSet iter types) - #76890 (use matches!() macro for simple if let conditions) - #76891 (don't take `TyCtxt` by reference) - #76910 (transmute: use diagnostic item) - #76924 (Add tracking issue for feature(unix_socket_peek)) - #76926 (BTreeMap: code readability tweaks) - #76940 (Don't allow implementing trait directly on type-alias-impl-trait) Failed merges: r? `@ghost`
2 parents b873fa6 + fc58224 commit 81e0270

File tree

56 files changed

+359
-213
lines changed

Some content is hidden

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

56 files changed

+359
-213
lines changed

README.md

+13-13
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ by running `./x.py --help` or reading the [rustc dev guide][rustcguidebuild].
4444
2. Clone the [source] with `git`:
4545

4646
```sh
47-
$ git clone https://github.com/rust-lang/rust.git
48-
$ cd rust
47+
git clone https://github.com/rust-lang/rust.git
48+
cd rust
4949
```
5050

5151
[source]: https://github.com/rust-lang/rust
@@ -57,7 +57,7 @@ by running `./x.py --help` or reading the [rustc dev guide][rustcguidebuild].
5757
Copy the default `config.toml.example` to `config.toml` to get started.
5858

5959
```sh
60-
$ cp config.toml.example config.toml
60+
cp config.toml.example config.toml
6161
```
6262

6363
If you plan to use `x.py install` to create an installation, it is recommended
@@ -68,7 +68,7 @@ by running `./x.py --help` or reading the [rustc dev guide][rustcguidebuild].
6868
4. Build and install:
6969

7070
```sh
71-
$ ./x.py build && ./x.py install
71+
./x.py build && ./x.py install
7272
```
7373

7474
When complete, `./x.py install` will place several programs into
@@ -106,15 +106,15 @@ build.
106106
107107
```sh
108108
# Update package mirrors (may be needed if you have a fresh install of MSYS2)
109-
$ pacman -Sy pacman-mirrors
109+
pacman -Sy pacman-mirrors
110110
111111
# Install build tools needed for Rust. If you're building a 32-bit compiler,
112112
# then replace "x86_64" below with "i686". If you've already got git, python,
113113
# or CMake installed and in PATH you can remove them from this list. Note
114114
# that it is important that you do **not** use the 'python2', 'cmake' and 'ninja'
115115
# packages from the 'msys2' subsystem. The build has historically been known
116116
# to fail with these packages.
117-
$ pacman -S git \
117+
pacman -S git \
118118
make \
119119
diffutils \
120120
tar \
@@ -127,7 +127,7 @@ build.
127127
4. Navigate to Rust's source code (or clone it), then build it:
128128
129129
```sh
130-
$ ./x.py build && ./x.py install
130+
./x.py build && ./x.py install
131131
```
132132
133133
#### MSVC
@@ -145,7 +145,7 @@ With these dependencies installed, you can build the compiler in a `cmd.exe`
145145
shell with:
146146
147147
```sh
148-
> python x.py build
148+
python x.py build
149149
```
150150
151151
Currently, building Rust only works with some known versions of Visual Studio. If
@@ -154,8 +154,8 @@ you may need to force rustbuild to use an older version. This can be done
154154
by manually calling the appropriate vcvars file before running the bootstrap.
155155
156156
```batch
157-
> CALL "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat"
158-
> python x.py build
157+
CALL "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat"
158+
python x.py build
159159
```
160160
161161
#### Specifying an ABI
@@ -181,8 +181,8 @@ While it's not the recommended build system, this project also provides a
181181
configure script and makefile (the latter of which just invokes `x.py`).
182182
183183
```sh
184-
$ ./configure
185-
$ make && sudo make install
184+
./configure
185+
make && sudo make install
186186
```
187187
188188
When using the configure script, the generated `config.mk` file may override the
@@ -194,7 +194,7 @@ When using the configure script, the generated `config.mk` file may override the
194194
If you’d like to build the documentation, it’s almost the same:
195195
196196
```sh
197-
$ ./x.py doc
197+
./x.py doc
198198
```
199199
200200
The generated documentation will appear under `doc` in the `build` directory for

compiler/rustc_ast/src/ast.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1931,7 +1931,7 @@ pub enum TyKind {
19311931

19321932
impl TyKind {
19331933
pub fn is_implicit_self(&self) -> bool {
1934-
if let TyKind::ImplicitSelf = *self { true } else { false }
1934+
matches!(self, TyKind::ImplicitSelf)
19351935
}
19361936

19371937
pub fn is_unit(&self) -> bool {
@@ -2227,7 +2227,7 @@ pub enum Async {
22272227

22282228
impl Async {
22292229
pub fn is_async(self) -> bool {
2230-
if let Async::Yes { .. } = self { true } else { false }
2230+
matches!(self, Async::Yes { .. })
22312231
}
22322232

22332233
/// In this case this is an `async` return, the `NodeId` for the generated `impl Trait` item.
@@ -2508,7 +2508,7 @@ pub enum VisibilityKind {
25082508

25092509
impl VisibilityKind {
25102510
pub fn is_pub(&self) -> bool {
2511-
if let VisibilityKind::Public = *self { true } else { false }
2511+
matches!(self, VisibilityKind::Public)
25122512
}
25132513
}
25142514

compiler/rustc_ast_passes/src/ast_validation.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -868,10 +868,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
868868
.emit();
869869
}
870870

871-
if !bounds
872-
.iter()
873-
.any(|b| if let GenericBound::Trait(..) = *b { true } else { false })
874-
{
871+
if !bounds.iter().any(|b| matches!(b, GenericBound::Trait(..))) {
875872
self.err_handler().span_err(ty.span, "at least one trait must be specified");
876873
}
877874

compiler/rustc_attr/src/builtin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,10 @@ pub enum StabilityLevel {
160160

161161
impl StabilityLevel {
162162
pub fn is_unstable(&self) -> bool {
163-
if let StabilityLevel::Unstable { .. } = *self { true } else { false }
163+
matches!(self, StabilityLevel::Unstable { .. })
164164
}
165165
pub fn is_stable(&self) -> bool {
166-
if let StabilityLevel::Stable { .. } = *self { true } else { false }
166+
matches!(self, StabilityLevel::Stable { .. })
167167
}
168168
}
169169

compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1529,7 +1529,7 @@ impl<'a> TraitDef<'a> {
15291529
}
15301530
}
15311531

1532-
let is_tuple = if let ast::VariantData::Tuple(..) = struct_def { true } else { false };
1532+
let is_tuple = matches!(struct_def, ast::VariantData::Tuple(..));
15331533
match (just_spans.is_empty(), named_idents.is_empty()) {
15341534
(false, false) => cx.span_bug(
15351535
self.span,

compiler/rustc_codegen_ssa/src/traits/backend.rs

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rustc_session::{
1515
};
1616
use rustc_span::symbol::Symbol;
1717
use rustc_target::abi::LayoutOf;
18+
use rustc_target::spec::Target;
1819

1920
pub use rustc_data_structures::sync::MetadataRef;
2021

@@ -54,6 +55,12 @@ pub trait CodegenBackend {
5455
fn print_passes(&self) {}
5556
fn print_version(&self) {}
5657

58+
/// If this plugin provides additional builtin targets, provide the one enabled by the options here.
59+
/// Be careful: this is called *before* init() is called.
60+
fn target_override(&self, _opts: &config::Options) -> Option<Target> {
61+
None
62+
}
63+
5764
fn metadata_loader(&self) -> Box<MetadataLoaderDyn>;
5865
fn provide(&self, _providers: &mut Providers);
5966
fn provide_extern(&self, _providers: &mut Providers);

compiler/rustc_errors/src/snippet.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,15 @@ pub struct Annotation {
118118
impl Annotation {
119119
/// Whether this annotation is a vertical line placeholder.
120120
pub fn is_line(&self) -> bool {
121-
if let AnnotationType::MultilineLine(_) = self.annotation_type { true } else { false }
121+
matches!(self.annotation_type, AnnotationType::MultilineLine(_))
122122
}
123123

124124
pub fn is_multiline(&self) -> bool {
125-
match self.annotation_type {
125+
matches!(self.annotation_type,
126126
AnnotationType::Multiline(_)
127127
| AnnotationType::MultilineStart(_)
128128
| AnnotationType::MultilineLine(_)
129-
| AnnotationType::MultilineEnd(_) => true,
130-
_ => false,
131-
}
129+
| AnnotationType::MultilineEnd(_))
132130
}
133131

134132
pub fn len(&self) -> usize {

compiler/rustc_interface/src/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ fn mk_session(matches: getopts::Matches) -> (Session, CfgSpecs) {
4040
DiagnosticOutput::Default,
4141
Default::default(),
4242
None,
43+
None,
4344
);
4445
(sess, cfg)
4546
}

compiler/rustc_interface/src/util.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,21 @@ pub fn create_session(
6565
lint_caps: FxHashMap<lint::LintId, lint::Level>,
6666
descriptions: Registry,
6767
) -> (Lrc<Session>, Lrc<Box<dyn CodegenBackend>>) {
68+
let codegen_backend = get_codegen_backend(&sopts);
69+
// target_override is documented to be called before init(), so this is okay
70+
let target_override = codegen_backend.target_override(&sopts);
71+
6872
let mut sess = session::build_session(
6973
sopts,
7074
input_path,
7175
descriptions,
7276
diagnostic_output,
7377
lint_caps,
7478
file_loader,
79+
target_override,
7580
);
7681

77-
let codegen_backend = get_codegen_backend(&sess);
82+
codegen_backend.init(&sess);
7883

7984
let mut cfg = config::build_configuration(&sess, config::to_crate_config(cfg));
8085
add_configuration(&mut cfg, &mut sess, &*codegen_backend);
@@ -219,13 +224,13 @@ fn load_backend_from_dylib(path: &Path) -> fn() -> Box<dyn CodegenBackend> {
219224
}
220225
}
221226

222-
pub fn get_codegen_backend(sess: &Session) -> Box<dyn CodegenBackend> {
227+
pub fn get_codegen_backend(sopts: &config::Options) -> Box<dyn CodegenBackend> {
223228
static INIT: Once = Once::new();
224229

225230
static mut LOAD: fn() -> Box<dyn CodegenBackend> = || unreachable!();
226231

227232
INIT.call_once(|| {
228-
let codegen_name = sess.opts.debugging_opts.codegen_backend.as_deref().unwrap_or("llvm");
233+
let codegen_name = sopts.debugging_opts.codegen_backend.as_deref().unwrap_or("llvm");
229234
let backend = match codegen_name {
230235
filename if filename.contains('.') => load_backend_from_dylib(filename.as_ref()),
231236
codegen_name => get_builtin_codegen_backend(codegen_name),
@@ -235,9 +240,7 @@ pub fn get_codegen_backend(sess: &Session) -> Box<dyn CodegenBackend> {
235240
LOAD = backend;
236241
}
237242
});
238-
let backend = unsafe { LOAD() };
239-
backend.init(sess);
240-
backend
243+
unsafe { LOAD() }
241244
}
242245

243246
// This is used for rustdoc, but it uses similar machinery to codegen backend

compiler/rustc_lint/src/builtin.rs

+8-14
Original file line numberDiff line numberDiff line change
@@ -1984,9 +1984,9 @@ impl ExplicitOutlivesRequirements {
19841984
.filter_map(|(i, bound)| {
19851985
if let hir::GenericBound::Outlives(lifetime) = bound {
19861986
let is_inferred = match tcx.named_region(lifetime.hir_id) {
1987-
Some(Region::Static) if infer_static => inferred_outlives
1988-
.iter()
1989-
.any(|r| if let ty::ReStatic = r { true } else { false }),
1987+
Some(Region::Static) if infer_static => {
1988+
inferred_outlives.iter().any(|r| matches!(r, ty::ReStatic))
1989+
}
19901990
Some(Region::EarlyBound(index, ..)) => inferred_outlives.iter().any(|r| {
19911991
if let ty::ReEarlyBound(ebr) = r { ebr.index == index } else { false }
19921992
}),
@@ -2078,9 +2078,10 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
20782078
let mut lint_spans = Vec::new();
20792079

20802080
for param in hir_generics.params {
2081-
let has_lifetime_bounds = param.bounds.iter().any(|bound| {
2082-
if let hir::GenericBound::Outlives(_) = bound { true } else { false }
2083-
});
2081+
let has_lifetime_bounds = param
2082+
.bounds
2083+
.iter()
2084+
.any(|bound| matches!(bound, hir::GenericBound::Outlives(_)));
20842085
if !has_lifetime_bounds {
20852086
continue;
20862087
}
@@ -2349,13 +2350,6 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
23492350

23502351
/// Determine if this expression is a "dangerous initialization".
23512352
fn is_dangerous_init(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> Option<InitKind> {
2352-
// `transmute` is inside an anonymous module (the `extern` block?);
2353-
// `Invalid` represents the empty string and matches that.
2354-
// FIXME(#66075): use diagnostic items. Somehow, that does not seem to work
2355-
// on intrinsics right now.
2356-
const TRANSMUTE_PATH: &[Symbol] =
2357-
&[sym::core, sym::intrinsics, kw::Invalid, sym::transmute];
2358-
23592353
if let hir::ExprKind::Call(ref path_expr, ref args) = expr.kind {
23602354
// Find calls to `mem::{uninitialized,zeroed}` methods.
23612355
if let hir::ExprKind::Path(ref qpath) = path_expr.kind {
@@ -2365,7 +2359,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
23652359
return Some(InitKind::Zeroed);
23662360
} else if cx.tcx.is_diagnostic_item(sym::mem_uninitialized, def_id) {
23672361
return Some(InitKind::Uninit);
2368-
} else if cx.match_def_path(def_id, TRANSMUTE_PATH) {
2362+
} else if cx.tcx.is_diagnostic_item(sym::transmute, def_id) {
23692363
if is_zero(&args[0]) {
23702364
return Some(InitKind::Zeroed);
23712365
}

compiler/rustc_lint/src/context.rs

+4
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,10 @@ impl<'tcx> LateContext<'tcx> {
720720
/// Anonymous scopes such as `extern` imports are matched with `kw::Invalid`;
721721
/// inherent `impl` blocks are matched with the name of the type.
722722
///
723+
/// Instead of using this method, it is often preferable to instead use
724+
/// `rustc_diagnostic_item` or a `lang_item`. This is less prone to errors
725+
/// as paths get invalidated if the target definition moves.
726+
///
723727
/// # Examples
724728
///
725729
/// ```rust,ignore (no context or def id available)

compiler/rustc_middle/src/middle/cstore.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub enum LibSource {
6969

7070
impl LibSource {
7171
pub fn is_some(&self) -> bool {
72-
if let LibSource::Some(_) = *self { true } else { false }
72+
matches!(self, LibSource::Some(_))
7373
}
7474

7575
pub fn option(&self) -> Option<PathBuf> {

compiler/rustc_middle/src/middle/lang_items.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_target::spec::PanicStrategy;
1717
impl<'tcx> TyCtxt<'tcx> {
1818
/// Returns the `DefId` for a given `LangItem`.
1919
/// If not found, fatally aborts compilation.
20-
pub fn require_lang_item(&self, lang_item: LangItem, span: Option<Span>) -> DefId {
20+
pub fn require_lang_item(self, lang_item: LangItem, span: Option<Span>) -> DefId {
2121
self.lang_items().require(lang_item).unwrap_or_else(|msg| {
2222
if let Some(span) = span {
2323
self.sess.span_fatal(span, &msg)
@@ -27,7 +27,7 @@ impl<'tcx> TyCtxt<'tcx> {
2727
})
2828
}
2929

30-
pub fn fn_trait_kind_from_lang_item(&self, id: DefId) -> Option<ty::ClosureKind> {
30+
pub fn fn_trait_kind_from_lang_item(self, id: DefId) -> Option<ty::ClosureKind> {
3131
let items = self.lang_items();
3232
match Some(id) {
3333
x if x == items.fn_trait() => Some(ty::ClosureKind::Fn),
@@ -37,7 +37,7 @@ impl<'tcx> TyCtxt<'tcx> {
3737
}
3838
}
3939

40-
pub fn is_weak_lang_item(&self, item_def_id: DefId) -> bool {
40+
pub fn is_weak_lang_item(self, item_def_id: DefId) -> bool {
4141
self.lang_items().is_weak_lang_item(item_def_id)
4242
}
4343
}

0 commit comments

Comments
 (0)