Commit graph

8487 commits

Author SHA1 Message Date
Lzu Tao
8db24840f7 Merge commit 'ff0993c5e9162ddaea78e83d0f0161e68bd4ea73' into clippy 2020-06-09 14:36:01 +00:00
Ralf Jung
161474b7f7 Rollup merge of #72508 - ecstatic-morse:poly-self-ty, r=nikomatsakis
Make `PolyTraitRef::self_ty` return `Binder<Ty>`

This came up during review of #71618. The current implementation is the same as a call to `skip_binder` but harder to audit. Make it preserve binding levels and add a call to `skip_binder` at all use sites so they can be audited as part of #72507.
2020-06-06 21:57:38 +02:00
bors
b059c0a2e6 Auto merge of #72927 - petrochenkov:rustc, r=Mark-Simulacrum
Rename all remaining compiler crates to use the `rustc_foo` pattern

libarena -> librustc_arena
libfmt_macros -> librustc_parse_format
libgraphviz -> librustc_graphviz
libserialize -> librustc_serialize

Closes https://github.com/rust-lang/rust/issues/71177 in particular.
2020-06-06 09:00:51 +00:00
Mark Rousskov
0c470b3339 Bump to 1.46 2020-06-03 15:27:51 -04:00
Vadim Petrochenkov
bd3fc11416 Update fulldeps tests and clippy 2020-06-03 00:18:57 +03:00
Vadim Petrochenkov
2b79413491 Rename the crates in source code 2020-06-02 20:42:54 +03:00
Dylan MacKenzie
ea06c72fdd Call skip_binder or no_bound_vars before self_ty 2020-06-01 12:18:57 -07:00
Yuki Okushi
9fd8e1088f Return early to avoid ICE 2020-05-30 18:48:54 +09:00
bors
fcc0e8f7d4 Auto merge of #72671 - flip1995:clippyup, r=Xanewok
Update Clippy, RLS, and rustfmt

r? @Dylan-DPC

This makes Clippy test-pass again: 3089c3b

Otherwise this includes bugfixes and a few new lints.

Fixes #72231
Fixes #72232
2020-05-29 11:16:45 +00:00
Dylan DPC
28c690e07e Rollup merge of #72466 - lzutao:stabilize_str-strip, r=dtolnay
Stabilize str_strip feature

This PR stabilizes these APIs:

```rust
impl str {
    /// Returns a string slice with the prefix removed.
    ///
    /// If the string starts with the pattern `prefix`, `Some` is returned with the substring where
    /// the prefix is removed. Unlike `trim_start_matches`, this method removes the prefix exactly
    /// once.
    pub fn strip_prefix<'a, P: Pattern<'a>>(&'a self, prefix: P) -> Option<&'a str>;

    /// Returns a string slice with the suffix removed.
    ///
    /// If the string ends with the pattern `suffix`, `Some` is returned with the substring where
    /// the suffix is removed. Unlike `trim_end_matches`, this method removes the suffix exactly
    /// once.
    pub fn strip_suffix<'a, P>(&'a self, suffix: P) -> Option<&'a str>
    where
        P: Pattern<'a>,
        <P as Pattern<'a>>::Searcher: ReverseSearcher<'a>;
}
```

Closes  #67302
2020-05-29 02:33:11 +02:00
flip1995
b6c58f0d72 Temp fix: don't run cargo lint tests in rustc test suite 2020-05-28 17:19:30 +02:00
flip1995
a0e9f9bd0d Merge commit '7ea7cd165ad6705603852771bf82cc2fd6560db5' into clippyup2 2020-05-28 15:45:24 +02:00
Bastian Kauschke
e820a03d1c iterate List by value 2020-05-23 12:24:19 +02:00
Dylan MacKenzie
b3a690f5a1 Use OnceCell instead of Once 2020-05-22 13:31:02 -07:00
Lzu Tao
221c482142 Stabilize str_strip feature 2020-05-22 15:29:47 +00:00
Bastian Kauschke
091239ee60 introduce newtype'd Predicate<'tcx> 2020-05-20 15:44:34 +02:00
Bastian Kauschke
2722522fac rename Predicate to PredicateKind, introduce alias 2020-05-20 15:38:03 +02:00
bors
6cb1f5972d Auto merge of #69171 - Amanieu:new-asm, r=nagisa,nikomatsakis
Implement new asm! syntax from RFC 2850

This PR implements the new `asm!` syntax proposed in https://github.com/rust-lang/rfcs/pull/2850.

# Design

A large part of this PR revolves around taking an `asm!` macro invocation and plumbing it through all of the compiler layers down to LLVM codegen. Throughout the various stages, an `InlineAsm` generally consists of 3 components:

- The template string, which is stored as an array of `InlineAsmTemplatePiece`. Each piece represents either a literal or a placeholder for an operand (just like format strings).
```rust
pub enum InlineAsmTemplatePiece {
    String(String),
    Placeholder { operand_idx: usize, modifier: Option<char>, span: Span },
}
```

- The list of operands to the `asm!` (`in`, `[late]out`, `in[late]out`, `sym`, `const`). These are represented differently at each stage of lowering, but follow a common pattern:
  - `in`, `out` and `inout` all have an associated register class (`reg`) or explicit register (`"eax"`).
  - `inout` has 2 forms: one with a single expression that is both read from and written to, and one with two separate expressions for the input and output parts.
  - `out` and `inout` have a `late` flag (`lateout` / `inlateout`) to indicate that the register allocator is allowed to reuse an input register for this output.
  - `out` and the split variant of `inout` allow `_` to be specified for an output, which means that the output is discarded. This is used to allocate scratch registers for assembly code.
  - `sym` is a bit special since it only accepts a path expression, which must point to a `static` or a `fn`.

- The options set at the end of the `asm!` macro. The only one that is particularly of interest to rustc is `NORETURN` which makes `asm!` return `!` instead of `()`.
```rust
bitflags::bitflags! {
    pub struct InlineAsmOptions: u8 {
        const PURE = 1 << 0;
        const NOMEM = 1 << 1;
        const READONLY = 1 << 2;
        const PRESERVES_FLAGS = 1 << 3;
        const NORETURN = 1 << 4;
        const NOSTACK = 1 << 5;
    }
}
```

## AST

`InlineAsm` is represented as an expression in the AST:

```rust
pub struct InlineAsm {
    pub template: Vec<InlineAsmTemplatePiece>,
    pub operands: Vec<(InlineAsmOperand, Span)>,
    pub options: InlineAsmOptions,
}

pub enum InlineAsmRegOrRegClass {
    Reg(Symbol),
    RegClass(Symbol),
}

pub enum InlineAsmOperand {
    In {
        reg: InlineAsmRegOrRegClass,
        expr: P<Expr>,
    },
    Out {
        reg: InlineAsmRegOrRegClass,
        late: bool,
        expr: Option<P<Expr>>,
    },
    InOut {
        reg: InlineAsmRegOrRegClass,
        late: bool,
        expr: P<Expr>,
    },
    SplitInOut {
        reg: InlineAsmRegOrRegClass,
        late: bool,
        in_expr: P<Expr>,
        out_expr: Option<P<Expr>>,
    },
    Const {
        expr: P<Expr>,
    },
    Sym {
        expr: P<Expr>,
    },
}
```

The `asm!` macro is implemented in librustc_builtin_macros and outputs an `InlineAsm` AST node. The template string is parsed using libfmt_macros, positional and named operands are resolved to explicit operand indicies. Since target information is not available to macro invocations, validation of the registers and register classes is deferred to AST lowering.

## HIR

`InlineAsm` is represented as an expression in the HIR:

```rust
pub struct InlineAsm<'hir> {
    pub template: &'hir [InlineAsmTemplatePiece],
    pub operands: &'hir [InlineAsmOperand<'hir>],
    pub options: InlineAsmOptions,
}

pub enum InlineAsmRegOrRegClass {
    Reg(InlineAsmReg),
    RegClass(InlineAsmRegClass),
}

pub enum InlineAsmOperand<'hir> {
    In {
        reg: InlineAsmRegOrRegClass,
        expr: Expr<'hir>,
    },
    Out {
        reg: InlineAsmRegOrRegClass,
        late: bool,
        expr: Option<Expr<'hir>>,
    },
    InOut {
        reg: InlineAsmRegOrRegClass,
        late: bool,
        expr: Expr<'hir>,
    },
    SplitInOut {
        reg: InlineAsmRegOrRegClass,
        late: bool,
        in_expr: Expr<'hir>,
        out_expr: Option<Expr<'hir>>,
    },
    Const {
        expr: Expr<'hir>,
    },
    Sym {
        expr: Expr<'hir>,
    },
}
```

AST lowering is where `InlineAsmRegOrRegClass` is converted from `Symbol`s to an actual register or register class. If any modifiers are specified for a template string placeholder, these are validated against the set allowed for that operand type. Finally, explicit registers for inputs and outputs are checked for conflicts (same register used for different operands).

## Type checking

Each register class has a whitelist of types that it may be used with. After the types of all operands have been determined, the `intrinsicck` pass will check that these types are in the whitelist. It also checks that split `inout` operands have compatible types and that `const` operands are integers or floats. Suggestions are emitted where needed if a template modifier should be used for an operand based on the type that was passed into it.

## HAIR

`InlineAsm` is represented as an expression in the HAIR:

```rust
crate enum ExprKind<'tcx> {
    // [..]
    InlineAsm {
        template: &'tcx [InlineAsmTemplatePiece],
        operands: Vec<InlineAsmOperand<'tcx>>,
        options: InlineAsmOptions,
    },
}
crate enum InlineAsmOperand<'tcx> {
    In {
        reg: InlineAsmRegOrRegClass,
        expr: ExprRef<'tcx>,
    },
    Out {
        reg: InlineAsmRegOrRegClass,
        late: bool,
        expr: Option<ExprRef<'tcx>>,
    },
    InOut {
        reg: InlineAsmRegOrRegClass,
        late: bool,
        expr: ExprRef<'tcx>,
    },
    SplitInOut {
        reg: InlineAsmRegOrRegClass,
        late: bool,
        in_expr: ExprRef<'tcx>,
        out_expr: Option<ExprRef<'tcx>>,
    },
    Const {
        expr: ExprRef<'tcx>,
    },
    SymFn {
        expr: ExprRef<'tcx>,
    },
    SymStatic {
        expr: ExprRef<'tcx>,
    },
}
```

The only significant change compared to HIR is that `Sym` has been lowered to either a `SymFn` whose `expr` is a `Literal` ZST of the `fn`, or a `SymStatic` whose `expr` is a `StaticRef`.

## MIR

`InlineAsm` is represented as a `Terminator` in the MIR:

```rust
pub enum TerminatorKind<'tcx> {
    // [..]

    /// Block ends with an inline assembly block. This is a terminator since
    /// inline assembly is allowed to diverge.
    InlineAsm {
        /// The template for the inline assembly, with placeholders.
        template: &'tcx [InlineAsmTemplatePiece],

        /// The operands for the inline assembly, as `Operand`s or `Place`s.
        operands: Vec<InlineAsmOperand<'tcx>>,

        /// Miscellaneous options for the inline assembly.
        options: InlineAsmOptions,

        /// Destination block after the inline assembly returns, unless it is
        /// diverging (InlineAsmOptions::NORETURN).
        destination: Option<BasicBlock>,
    },
}

pub enum InlineAsmOperand<'tcx> {
    In {
        reg: InlineAsmRegOrRegClass,
        value: Operand<'tcx>,
    },
    Out {
        reg: InlineAsmRegOrRegClass,
        late: bool,
        place: Option<Place<'tcx>>,
    },
    InOut {
        reg: InlineAsmRegOrRegClass,
        late: bool,
        in_value: Operand<'tcx>,
        out_place: Option<Place<'tcx>>,
    },
    Const {
        value: Operand<'tcx>,
    },
    SymFn {
        value: Box<Constant<'tcx>>,
    },
    SymStatic {
        value: Box<Constant<'tcx>>,
    },
}
```

As part of HAIR lowering, `InOut` and `SplitInOut` operands are lowered to a split form with a separate `in_value` and `out_place`.

Semantically, the `InlineAsm` terminator is similar to the `Call` terminator except that it has multiple output places where a `Call` only has a single return place output.

The constant promotion pass is used to ensure that `const` operands are actually constants (using the same logic as `#[rustc_args_required_const]`).

## Codegen

Operands are lowered one more time before being passed to LLVM codegen:

```rust
pub enum InlineAsmOperandRef<'tcx, B: BackendTypes + ?Sized> {
    In {
        reg: InlineAsmRegOrRegClass,
        value: OperandRef<'tcx, B::Value>,
    },
    Out {
        reg: InlineAsmRegOrRegClass,
        late: bool,
        place: Option<PlaceRef<'tcx, B::Value>>,
    },
    InOut {
        reg: InlineAsmRegOrRegClass,
        late: bool,
        in_value: OperandRef<'tcx, B::Value>,
        out_place: Option<PlaceRef<'tcx, B::Value>>,
    },
    Const {
        string: String,
    },
    SymFn {
        instance: Instance<'tcx>,
    },
    SymStatic {
        def_id: DefId,
    },
}
```

The operands are lowered to LLVM operands and constraint codes as follow:
- `out` and the output part of `inout` operands are added first, as required by LLVM. Late output operands have a `=` prefix added to their constraint code, non-late output operands have a `=&` prefix added to their constraint code.
- `in` operands are added normally.
- `inout` operands are tied to the matching output operand.
- `sym` operands are passed as function pointers or pointers, using the `"s"` constraint.
- `const` operands are formatted to a string and directly inserted in the template string.

The template string is converted to LLVM form:
- `$` characters are escaped as `$$`.
- `const` operands are converted to strings and inserted directly.
- Placeholders are formatted as `${X:M}` where `X` is the operand index and `M` is the modifier character. Modifiers are converted from the Rust form to the LLVM form.

The various options are converted to clobber constraints or LLVM attributes, refer to the [RFC](https://github.com/Amanieu/rfcs/blob/inline-asm/text/0000-inline-asm.md#mapping-to-llvm-ir) for more details.

Note that LLVM is sometimes rather picky about what types it accepts for certain constraint codes so we sometimes need to insert conversions to/from a supported type. See the target-specific ISelLowering.cpp files in LLVM for details.

# Adding support for new architectures

Adding inline assembly support to an architecture is mostly a matter of defining the registers and register classes for that architecture. All the definitions for register classes are located in `src/librustc_target/asm/`.

Additionally you will need to implement lowering of these register classes to LLVM constraint codes in `src/librustc_codegen_llvm/asm.rs`.
2020-05-19 18:32:40 +00:00
bors
8164832c4b Auto merge of #68717 - petrochenkov:stabexpat, r=varkor
Stabilize fn-like proc macros in expression, pattern and statement positions

I.e. all the positions in which stable `macro_rules` macros are supported.

Depends on https://github.com/rust-lang/rust/pull/68716 ("Stabilize `Span::mixed_site`").

cc https://github.com/rust-lang/rust/issues/54727
cc https://github.com/rust-lang/rust/issues/54727#issuecomment-580647446

Stabilization report: https://github.com/rust-lang/rust/pull/68717#issuecomment-623197503.
2020-05-19 03:11:32 +00:00
Amanieu d'Antras
d25b25610b Handle InlineAsm in clippy 2020-05-18 14:41:33 +01:00
flip1995
f1d3086492 Merge commit 'e214ea82ad0a751563acf67e1cd9279cf302db3a' into clippyup 2020-05-17 17:36:26 +02:00
Ralf Jung
8bba1b7589 Rollup merge of #72047 - Julian-Wollersberger:literal_error_reporting_cleanup, r=petrochenkov
Literal error reporting cleanup

While doing some performance work, I noticed some code duplication in `librustc_parser/lexer/mod.rs`, so I cleaned it up.

This PR is probably best reviewed commit by commit.

I'm not sure what the API stability practices for `librustc_lexer` are. Four public methods in `unescape.rs` can be removed, but two are used by clippy, so I left them in for now.
I could open a PR for Rust-Analyzer when this one lands.

But how do I open a PR for clippy? (Git submodules are frustrating to work with)
2020-05-16 19:46:31 +02:00
Dylan DPC
b381ea8abb Rollup merge of #72090 - RalfJung:rustc_driver-exit-code, r=oli-obk
rustc_driver: factor out computing the exit code

In a recent Miri PR I [added a convenience wrapper](https://github.com/rust-lang/miri/pull/1405/files#diff-c3d602c5c8035a16699ce9c015bfeceaR125) around `catch_fatal_errors` and `run_compiler` that @oli-obk suggested I could upstream. However, after seeing what could be shared between `rustc_driver::main`, clippy and Miri, really the only thing I found is computing the exit code -- so that's what this PR does.

What prevents using the Miri convenience function in `rustc_driver::main` and clippy is that they do extra work inside `catch_fatal_errors`, and while I could abstract that away, clippy actually *computes the callbacks* inside there, and I fond no good way to abstract that and thus gave up. Maybe the clippy thing could be moved out, I am not sure if it ever can actually raise a `FatalErrorMarker` -- someone more knowledgeable in clippy would have to do that.
2020-05-16 02:37:23 +02:00
Dylan DPC
b0490cc80d Rollup merge of #71948 - csmoe:issue-61076, r=oli-obk
Suggest to await future before ? operator

Closes https://github.com/rust-lang/rust/issues/71811
cc #61076
2020-05-16 02:37:21 +02:00
csmoe
0a86335cd4 implement type_implments_trait query 2020-05-15 15:37:11 +08:00
Julian Wollersberger
ff9a9ed37c Replace some usages of the old unescape_ functions in AST, clippy and tests. 2020-05-13 10:05:04 +02:00
flip1995
d13d8987b0 Merge commit '43a1777b89cf6791f9e20878b4e5e3ae907867a5' into clippyup 2020-05-11 20:23:47 +02:00
Ralf Jung
30822733f0 rustc_driver: factor out computing the exit code 2020-05-10 23:36:41 +02:00
Ralf Jung
51158cc71f Rollup merge of #71555 - cjgillot:nameless, r=matthewjasper
Remove ast::{Ident, Name} reexports.

The reexport of `Symbol` into `Name` confused me.
2020-05-09 13:36:39 +02:00
Camille GILLOT
31c84e5077 Fix clippy. 2020-05-08 13:57:01 +02:00
Jack Huey
0e2f5c9862 Fix nit and cargo.lock 2020-05-07 17:46:31 -04:00
Dylan MacKenzie
41fe5c1ca7 Update clippy lint 2020-05-03 11:41:03 -07:00
Vadim Petrochenkov
2d10babb71 Stabilize fn-like proc macros in expression, pattern and statement positions 2020-05-03 19:24:41 +03:00
bors
d2708873ef Auto merge of #5548 - matthiaskrgr:traget_os, r=flip1995
mismatched_target_os: link to respective section in rust reference

changelog: none
2020-05-01 16:33:14 +00:00
Matthias Krüger
b7800e1ac3 mismatched_target_os: link to respective section in rust reference 2020-05-01 01:21:24 +02:00
bors
0a53ed2d8e Auto merge of #5547 - CrazyRoka:fix-clone-double-ref-suggestion, r=flip1995
Fixed incorrect suggestion of `clone_double_ref` lint

- Added `<_>` to suggestion
- Changed help message
- Added new tests
Closes #5494

changelog: Improve suggestion of [`clone_double_ref`]
2020-04-29 20:05:18 +00:00
CrazyRoka
20c069beec Fixed incorrect suggestion of clone_double_ref lint
- Added `<_>` to suggestion
- Changed help message
2020-04-29 22:40:57 +03:00
bors
28197b6226 Auto merge of #5545 - flip1995:rustup, r=flip1995
Rustup to rust-lang/rust#71518

changelog: none
2020-04-29 13:59:30 +00:00
flip1995
cd3480991a
Rustup to rust-lang/rust#71518 2020-04-29 15:48:43 +02:00
bors
9a3b0a0588 Auto merge of #5543 - matthiaskrgr:rustup_45, r=flip1995
rustup https://github.com/rust-lang/rust/pull/71292/

cc https://github.com/rust-lang/rust/issues/71608

---

changelog: none
2020-04-28 18:30:01 +00:00
Matthias Krüger
bdc9528e7c rustup https://github.com/rust-lang/rust/pull/71292/ 2020-04-28 15:05:56 +02:00
bors
2c4d566113 Auto merge of #5535 - ebroto:issue_5360, r=phansch
used_underscore_binding: do not lint on `await` desugaring

changelog: used_underscore_binding: do not lint on `await` desugaring

Fixes #5360
2020-04-28 05:36:30 +00:00
Eduardo Broto
fc5fc6378c Test that we lint the awaited expression 2020-04-27 21:29:31 +02:00
Eduardo Broto
3a96f548d1 used_underscore_binding: do not lint on await desugaring 2020-04-27 21:20:08 +02:00
bors
f2486b3d35 Auto merge of #5538 - csmoe:rustup, r=phansch
rustup: rust-lang/rust#71628

cc https://github.com/rust-lang/rust/issues/71608

changelog: none
2020-04-27 16:58:24 +00:00
csmoe
305177d9cc rustup: rust-lang/rust#71628 2020-04-27 22:40:56 +08:00
bors
d13ffbe3fe Auto merge of #5522 - CrazyRoka:match_vec_item, r=phansch
New  lint `match_vec_item`

Added new lint to warn a match on index item which can panic. It's always better to use `get(..)` instead.
Closes #5500
changelog: New lint `match_on_vec_items`
2020-04-27 06:02:05 +00:00
bors
5d8a3e8724 Auto merge of #5506 - ebroto:mismatched_target_os, r=flip1995
Implement mismatched_target_os lint

I've extended the check suggested in the issue to all the currently supported operating systems instead of limiting it to `linux` and `macos`, let me know if we want to do this.

Also, I've restored the text `There are over XXX lints ...` in the README as it was matched against by `cargo dev new_lint`.

changelog: Added `mismatched_target_os` lint to warn when an operating system is used in target family position in a #[cfg] attribute

Closes #3949
2020-04-27 02:29:49 +00:00
Eduardo Broto
303e7d1af8 Split tests in unix/non-unix 2020-04-26 21:27:29 +02:00
Eduardo Broto
4a405c9977 Remove some OSes from the test to comply with stderr line limit 2020-04-26 21:27:29 +02:00