Skip to content

Commit

Permalink
Auto merge of rust-lang#76975 - RalfJung:rollup-s2wiuqr, r=RalfJung
Browse files Browse the repository at this point in the history
Rollup of 15 pull requests

Successful merges:

 - rust-lang#76732 (Add docs for `BasicBlock`)
 - rust-lang#76832 (Let backends define custom targets)
 - rust-lang#76866 (Remove unused feature gates from library/ crates)
 - rust-lang#76875 (Move to intra-doc links in library/alloc/src/collections/binary_heap.rs)
 - rust-lang#76876 (Move to intra-doc links in collections/btree/map.rs and collections/linked_list.rs)
 - rust-lang#76877 (Move to intra-doc links in collections/vec_deque.rs and collections/vec_deque/drain.rs)
 - rust-lang#76878 (Move the version number to a plaintext file)
 - rust-lang#76883 (README.md: Remove prompts from code blocks)
 - rust-lang#76887 (Add missing examples on HashSet iter types)
 - rust-lang#76890 (use matches!() macro for simple if let conditions)
 - rust-lang#76891 (don't take `TyCtxt` by reference)
 - rust-lang#76910 (transmute: use diagnostic item)
 - rust-lang#76924 (Add tracking issue for feature(unix_socket_peek))
 - rust-lang#76926 (BTreeMap: code readability tweaks)
 - rust-lang#76940 (Don't allow implementing trait directly on type-alias-impl-trait)

Failed merges:

r? `@ghost`
  • Loading branch information
bors committed Sep 20, 2020
2 parents b873fa6 + fc58224 commit 81e0270
Show file tree
Hide file tree
Showing 56 changed files with 359 additions and 213 deletions.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ by running `./x.py --help` or reading the [rustc dev guide][rustcguidebuild].
2. Clone the [source] with `git`:

```sh
$ git clone https://github.com/rust-lang/rust.git
$ cd rust
git clone https://github.com/rust-lang/rust.git
cd rust
```

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

```sh
$ cp config.toml.example config.toml
cp config.toml.example config.toml
```

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

```sh
$ ./x.py build && ./x.py install
./x.py build && ./x.py install
```

When complete, `./x.py install` will place several programs into
Expand Down Expand Up @@ -106,15 +106,15 @@ build.
```sh
# Update package mirrors (may be needed if you have a fresh install of MSYS2)
$ pacman -Sy pacman-mirrors
pacman -Sy pacman-mirrors
# Install build tools needed for Rust. If you're building a 32-bit compiler,
# then replace "x86_64" below with "i686". If you've already got git, python,
# or CMake installed and in PATH you can remove them from this list. Note
# that it is important that you do **not** use the 'python2', 'cmake' and 'ninja'
# packages from the 'msys2' subsystem. The build has historically been known
# to fail with these packages.
$ pacman -S git \
pacman -S git \
make \
diffutils \
tar \
Expand All @@ -127,7 +127,7 @@ build.
4. Navigate to Rust's source code (or clone it), then build it:
```sh
$ ./x.py build && ./x.py install
./x.py build && ./x.py install
```
#### MSVC
Expand All @@ -145,7 +145,7 @@ With these dependencies installed, you can build the compiler in a `cmd.exe`
shell with:
```sh
> python x.py build
python x.py build
```
Currently, building Rust only works with some known versions of Visual Studio. If
Expand All @@ -154,8 +154,8 @@ you may need to force rustbuild to use an older version. This can be done
by manually calling the appropriate vcvars file before running the bootstrap.
```batch
> CALL "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat"
> python x.py build
CALL "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat"
python x.py build
```
#### Specifying an ABI
Expand All @@ -181,8 +181,8 @@ While it's not the recommended build system, this project also provides a
configure script and makefile (the latter of which just invokes `x.py`).
```sh
$ ./configure
$ make && sudo make install
./configure
make && sudo make install
```
When using the configure script, the generated `config.mk` file may override the
Expand All @@ -194,7 +194,7 @@ When using the configure script, the generated `config.mk` file may override the
If you’d like to build the documentation, it’s almost the same:
```sh
$ ./x.py doc
./x.py doc
```
The generated documentation will appear under `doc` in the `build` directory for
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1931,7 +1931,7 @@ pub enum TyKind {

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

pub fn is_unit(&self) -> bool {
Expand Down Expand Up @@ -2227,7 +2227,7 @@ pub enum Async {

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

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

impl VisibilityKind {
pub fn is_pub(&self) -> bool {
if let VisibilityKind::Public = *self { true } else { false }
matches!(self, VisibilityKind::Public)
}
}

Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -868,10 +868,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
.emit();
}

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

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_attr/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ pub enum StabilityLevel {

impl StabilityLevel {
pub fn is_unstable(&self) -> bool {
if let StabilityLevel::Unstable { .. } = *self { true } else { false }
matches!(self, StabilityLevel::Unstable { .. })
}
pub fn is_stable(&self) -> bool {
if let StabilityLevel::Stable { .. } = *self { true } else { false }
matches!(self, StabilityLevel::Stable { .. })
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1529,7 +1529,7 @@ impl<'a> TraitDef<'a> {
}
}

let is_tuple = if let ast::VariantData::Tuple(..) = struct_def { true } else { false };
let is_tuple = matches!(struct_def, ast::VariantData::Tuple(..));
match (just_spans.is_empty(), named_idents.is_empty()) {
(false, false) => cx.span_bug(
self.span,
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_codegen_ssa/src/traits/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use rustc_session::{
};
use rustc_span::symbol::Symbol;
use rustc_target::abi::LayoutOf;
use rustc_target::spec::Target;

pub use rustc_data_structures::sync::MetadataRef;

Expand Down Expand Up @@ -54,6 +55,12 @@ pub trait CodegenBackend {
fn print_passes(&self) {}
fn print_version(&self) {}

/// If this plugin provides additional builtin targets, provide the one enabled by the options here.
/// Be careful: this is called *before* init() is called.
fn target_override(&self, _opts: &config::Options) -> Option<Target> {
None
}

fn metadata_loader(&self) -> Box<MetadataLoaderDyn>;
fn provide(&self, _providers: &mut Providers);
fn provide_extern(&self, _providers: &mut Providers);
Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_errors/src/snippet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,15 @@ pub struct Annotation {
impl Annotation {
/// Whether this annotation is a vertical line placeholder.
pub fn is_line(&self) -> bool {
if let AnnotationType::MultilineLine(_) = self.annotation_type { true } else { false }
matches!(self.annotation_type, AnnotationType::MultilineLine(_))
}

pub fn is_multiline(&self) -> bool {
match self.annotation_type {
matches!(self.annotation_type,
AnnotationType::Multiline(_)
| AnnotationType::MultilineStart(_)
| AnnotationType::MultilineLine(_)
| AnnotationType::MultilineEnd(_) => true,
_ => false,
}
| AnnotationType::MultilineEnd(_))
}

pub fn len(&self) -> usize {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ fn mk_session(matches: getopts::Matches) -> (Session, CfgSpecs) {
DiagnosticOutput::Default,
Default::default(),
None,
None,
);
(sess, cfg)
}
Expand Down
15 changes: 9 additions & 6 deletions compiler/rustc_interface/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,21 @@ pub fn create_session(
lint_caps: FxHashMap<lint::LintId, lint::Level>,
descriptions: Registry,
) -> (Lrc<Session>, Lrc<Box<dyn CodegenBackend>>) {
let codegen_backend = get_codegen_backend(&sopts);
// target_override is documented to be called before init(), so this is okay
let target_override = codegen_backend.target_override(&sopts);

let mut sess = session::build_session(
sopts,
input_path,
descriptions,
diagnostic_output,
lint_caps,
file_loader,
target_override,
);

let codegen_backend = get_codegen_backend(&sess);
codegen_backend.init(&sess);

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

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

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

INIT.call_once(|| {
let codegen_name = sess.opts.debugging_opts.codegen_backend.as_deref().unwrap_or("llvm");
let codegen_name = sopts.debugging_opts.codegen_backend.as_deref().unwrap_or("llvm");
let backend = match codegen_name {
filename if filename.contains('.') => load_backend_from_dylib(filename.as_ref()),
codegen_name => get_builtin_codegen_backend(codegen_name),
Expand All @@ -235,9 +240,7 @@ pub fn get_codegen_backend(sess: &Session) -> Box<dyn CodegenBackend> {
LOAD = backend;
}
});
let backend = unsafe { LOAD() };
backend.init(sess);
backend
unsafe { LOAD() }
}

// This is used for rustdoc, but it uses similar machinery to codegen backend
Expand Down
22 changes: 8 additions & 14 deletions compiler/rustc_lint/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1984,9 +1984,9 @@ impl ExplicitOutlivesRequirements {
.filter_map(|(i, bound)| {
if let hir::GenericBound::Outlives(lifetime) = bound {
let is_inferred = match tcx.named_region(lifetime.hir_id) {
Some(Region::Static) if infer_static => inferred_outlives
.iter()
.any(|r| if let ty::ReStatic = r { true } else { false }),
Some(Region::Static) if infer_static => {
inferred_outlives.iter().any(|r| matches!(r, ty::ReStatic))
}
Some(Region::EarlyBound(index, ..)) => inferred_outlives.iter().any(|r| {
if let ty::ReEarlyBound(ebr) = r { ebr.index == index } else { false }
}),
Expand Down Expand Up @@ -2078,9 +2078,10 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
let mut lint_spans = Vec::new();

for param in hir_generics.params {
let has_lifetime_bounds = param.bounds.iter().any(|bound| {
if let hir::GenericBound::Outlives(_) = bound { true } else { false }
});
let has_lifetime_bounds = param
.bounds
.iter()
.any(|bound| matches!(bound, hir::GenericBound::Outlives(_)));
if !has_lifetime_bounds {
continue;
}
Expand Down Expand Up @@ -2349,13 +2350,6 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {

/// Determine if this expression is a "dangerous initialization".
fn is_dangerous_init(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> Option<InitKind> {
// `transmute` is inside an anonymous module (the `extern` block?);
// `Invalid` represents the empty string and matches that.
// FIXME(#66075): use diagnostic items. Somehow, that does not seem to work
// on intrinsics right now.
const TRANSMUTE_PATH: &[Symbol] =
&[sym::core, sym::intrinsics, kw::Invalid, sym::transmute];

if let hir::ExprKind::Call(ref path_expr, ref args) = expr.kind {
// Find calls to `mem::{uninitialized,zeroed}` methods.
if let hir::ExprKind::Path(ref qpath) = path_expr.kind {
Expand All @@ -2365,7 +2359,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
return Some(InitKind::Zeroed);
} else if cx.tcx.is_diagnostic_item(sym::mem_uninitialized, def_id) {
return Some(InitKind::Uninit);
} else if cx.match_def_path(def_id, TRANSMUTE_PATH) {
} else if cx.tcx.is_diagnostic_item(sym::transmute, def_id) {
if is_zero(&args[0]) {
return Some(InitKind::Zeroed);
}
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,10 @@ impl<'tcx> LateContext<'tcx> {
/// Anonymous scopes such as `extern` imports are matched with `kw::Invalid`;
/// inherent `impl` blocks are matched with the name of the type.
///
/// Instead of using this method, it is often preferable to instead use
/// `rustc_diagnostic_item` or a `lang_item`. This is less prone to errors
/// as paths get invalidated if the target definition moves.
///
/// # Examples
///
/// ```rust,ignore (no context or def id available)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/middle/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub enum LibSource {

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

pub fn option(&self) -> Option<PathBuf> {
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/middle/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use rustc_target::spec::PanicStrategy;
impl<'tcx> TyCtxt<'tcx> {
/// Returns the `DefId` for a given `LangItem`.
/// If not found, fatally aborts compilation.
pub fn require_lang_item(&self, lang_item: LangItem, span: Option<Span>) -> DefId {
pub fn require_lang_item(self, lang_item: LangItem, span: Option<Span>) -> DefId {
self.lang_items().require(lang_item).unwrap_or_else(|msg| {
if let Some(span) = span {
self.sess.span_fatal(span, &msg)
Expand All @@ -27,7 +27,7 @@ impl<'tcx> TyCtxt<'tcx> {
})
}

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

pub fn is_weak_lang_item(&self, item_def_id: DefId) -> bool {
pub fn is_weak_lang_item(self, item_def_id: DefId) -> bool {
self.lang_items().is_weak_lang_item(item_def_id)
}
}
Expand Down
Loading

0 comments on commit 81e0270

Please sign in to comment.