Commit Graph

202 Commits

Author SHA1 Message Date
Guillaume Gomez 039b1b62ac
Rollup merge of #82456 - klensy:or-else, r=estebank
Replaced some unwrap_or and map_or with lazy variants

Replaced some `unwrap_or` and `map_or` with `unwrap_or_else` and `map_or_else`.
2021-02-26 15:52:31 +01:00
bors 98f8cce6db Auto merge of #82447 - Amanieu:legacy_const_generics, r=oli-obk
Add #[rustc_legacy_const_generics]

This is the first step towards removing `#[rustc_args_required_const]`: a new attribute is added which rewrites function calls of the form `func(a, b, c)` to `func::<{b}>(a, c)`. This allows previously stabilized functions in `stdarch` which use `rustc_args_required_const` to use const generics instead.

This new attribute is not intended to ever be stabilized, it is only intended for use in `stdarch` as a replacement for `#[rustc_args_required_const]`.

```rust
#[rustc_legacy_const_generics(1)]
pub fn foo<const Y: usize>(x: usize, z: usize) -> [usize; 3] {
    [x, Y, z]
}

fn main() {
    assert_eq!(foo(0 + 0, 1 + 1, 2 + 2), [0, 2, 4]);
    assert_eq!(foo::<{1 + 1}>(0 + 0, 2 + 2), [0, 2, 4]);
}
```

r? `@oli-obk`
2021-02-25 18:14:50 +00:00
Dylan DPC 568ae3aee7
Rollup merge of #82087 - estebank:abolish-ice, r=oli-obk
Fix ICE caused by suggestion with no code substitutions

Change suggestion logic to filter and checking _before_ creating
specific resolution suggestion.

Assert earlier that suggestions contain code substitions to make it
easier in the future to debug invalid uses. If we find this becomes too
noisy in the wild, we can always make the emitter resilient to these
cases and remove the assertions.

Fix #78651.
2021-02-25 14:33:56 +01:00
klensy 08b1e8004b fix review 2021-02-25 04:21:12 +03:00
Amanieu d'Antras 22184a0f5d Add a cache for rustc_legacy_const_generics 2021-02-25 00:37:56 +00:00
Amanieu d'Antras 2451f124c9 Address review comments 2021-02-25 00:09:33 +00:00
Amanieu d'Antras 00eca69bff Properly reject non-const arguments 2021-02-24 06:46:30 +00:00
klensy c75c4a579b replaced some map_or with map_or_else 2021-02-24 02:43:35 +03:00
Amanieu d'Antras d87eec1bf6 Add #[rustc_legacy_const_generics] 2021-02-23 17:25:55 +00:00
Dylan DPC e2561c58a4
Rollup merge of #82296 - spastorino:pubrules, r=nikomatsakis
Support `pub` on `macro_rules`

This rebases and updates `since` version of #78166 from ``@petrochenkov``

r? ``@nikomatsakis``
2021-02-23 16:10:23 +01:00
Vadim Petrochenkov 0fddc2f780
Support `pub` on `macro_rules` 2021-02-19 13:52:57 -03:00
Dylan DPC cc01bbe8f0
Rollup merge of #82259 - osa1:issue82156, r=petrochenkov
Fix popping singleton paths in when generating E0433

Fixes #82156

---

This was introduced with #72923, so pinging `@Patryk27` for reviews.
2021-02-19 02:49:11 +01:00
Ömer Sinan Ağacan 9889e44470 Fix popping singleton paths in when generating E0433
Fixes #82156
2021-02-18 19:13:40 +03:00
Vadim Petrochenkov 4a88165124 ast: Keep expansion status for out-of-line module items
Also remove `ast::Mod` which is mostly redundant now
2021-02-18 13:07:49 +03:00
Vadim Petrochenkov eb65f15c78 ast: Stop using `Mod` in `Crate`
Crate root is sufficiently different from `mod` items, at least at syntactic level.

Also remove customization point for "`mod` item or crate root" from AST visitors.
2021-02-18 13:07:49 +03:00
bors 8fe989dd76 Auto merge of #81611 - cjgillot:meowner, r=estebank
Only store a LocalDefId in some HIR nodes

Some HIR nodes are guaranteed to be HIR owners: Item, TraitItem, ImplItem, ForeignItem and MacroDef.
As a consequence, we do not need to store the `HirId`'s `local_id`, and we can directly store a `LocalDefId`.

This allows to avoid a bit of the dance with `tcx.hir().local_def_id` and `tcx.hir().local_def_id_to_hir_id` mappings.
2021-02-16 22:14:32 +00:00
Matthias Krüger 4390a61b64 avoid full-slicing slices
If we already have a slice, there is no need to get another full-range slice from that, just use the original.
clippy::redundant_slicing
2021-02-16 00:31:11 +01:00
Camille GILLOT 7878fa70d6 Fix E0657. 2021-02-15 19:32:29 +01:00
Camille GILLOT 786a80e9ea Only store a LocalDefId in hir::ImplItem. 2021-02-15 19:32:29 +01:00
Camille GILLOT a871a0f111 Only store a LocalDefId in hir::TraitItem. 2021-02-15 19:32:28 +01:00
Camille GILLOT cebbba081e Only store a LocalDefId in hir::Item.
Items are guaranteed to be HIR owner.
2021-02-15 19:32:10 +01:00
Camille GILLOT c676e358a5 Use ItemId as a strongly typed index. 2021-02-15 19:24:58 +01:00
klensy 93c8ebe022 bumped smallvec deps 2021-02-14 18:03:11 +03:00
Esteban Küber 04c2454b1e Fix ICE caused by suggestion with no code substitutions
Change suggestion logic to filter and checking _before_ creating
specific resolution suggestion.

Assert earlier that suggestions contain code substitions to make it
easier in the future to debug invalid uses. If we find this becomes too
noisy in the wild, we can always make the emitter resilient to these
cases and remove the assertions.

Fix #78651.
2021-02-13 19:52:12 -08:00
Vadim Petrochenkov 8e74842089 resolve: Remove visibility hacks for enum variants and trait items
Special treatment like this was necessary before `pub(restricted)` had been implemented and only two visibilities existed - `pub` and non-`pub`.
Now it's no longer necessary and the desired behavior follows from `pub(restricted)`-style visibilities naturally assigned to enum variants and trait items.
2021-02-10 22:46:44 +03:00
Vadim Petrochenkov b4b6b62e70 resolve: Cleanup visibility resolution in enums and traits 2021-02-10 22:46:44 +03:00
Vadim Petrochenkov f6caae52c1 Feature gate macro attributes in `#[derive]` output 2021-02-07 20:08:45 +03:00
Vadim Petrochenkov dbdbd30bf2 expand/resolve: Turn `#[derive]` into a regular macro attribute 2021-02-07 20:08:45 +03:00
Jonas Schievink 85fb5cdf26
Rollup merge of #81680 - camsteffen:primty, r=oli-obk
Refactor `PrimitiveTypeTable` for Clippy

I removed `PrimitiveTypeTable` and added `PrimTy::ALL` and `PrimTy::from_name` in its place. This allows Clippy to use `PrimTy::from_name` for the `builtin_type_shadow` lint, and a `const` list of primitive types is deleted from Clippy code (the goal). All changes should be a little faster, if anything.
2021-02-06 17:01:45 +01:00
Cameron Steffen c89b9d97e2 Small refactor with Iterator::reduce 2021-02-05 09:34:40 -06:00
Cameron Steffen fba747a06e Refactor out PrimitiveTypeTable 2021-02-03 08:32:23 -06:00
Jack Huey 86e23cc9f1
Rollup merge of #81636 - LingMan:slice_not_vec, r=petrochenkov
Directly use `Option<&[T]>` instead of converting from `Option<&Vec<T>>` later on

```@rustbot``` modify labels +C-cleanup +T-compiler
2021-02-02 16:01:45 -05:00
bors 3182375e06 Auto merge of #81405 - bugadani:ast, r=cjgillot
Box the biggest ast::ItemKind variants

This PR is a different approach on https://github.com/rust-lang/rust/pull/81400, aiming to save memory in humongous ASTs.

The three affected item kind enums are:
 - `ast::ItemKind` (208 -> 112 bytes)
 - `ast::AssocItemKind` (176 -> 72 bytes)
 - `ast::ForeignItemKind` (176 -> 72 bytes)
2021-02-02 17:34:08 +00:00
bors b81f5811f9 Auto merge of #80843 - Mark-Simulacrum:fmt-bump, r=petrochenkov
Bump rustfmt version
2021-02-02 14:52:53 +00:00
Mark Rousskov d5b760ba62 Bump rustfmt version
Also switches on formatting of the mir build module
2021-02-02 09:09:52 -05:00
LingMan b35d601ab7 Directly use `Option<&[T]>` instead of converting from `Option<&Vec<T>>` later on 2021-02-01 19:51:24 +01:00
LingMan 8e34522309 Remove unneeded `mut` variable
`arg_elide` gets initialized, immediately cloned, and only written to after that.
The last reading access was removed back in
7704762604
2021-02-01 15:37:46 +01:00
Dániel Buga b87e1ecdf0 Box the biggest ast::ItemKind variants 2021-02-01 09:23:39 +01:00
Yuki Okushi ba40cea487
Rollup merge of #81505 - henryboisdequin:cold_path-not-pub, r=sanxiyn
`fn cold_path` doesn't need to be pub

Fixes #81429

Note: this PR also fixes a small typo that I found
2021-01-30 13:36:58 +09:00
Henry Boisdequin fd5fb86f05 fix typo 2021-01-29 16:08:49 +05:30
Aaron Hill f9025512e7
Add `SEMICOLON_IN_EXPRESSIONS_FROM_MACROS` lint
cc #79813

This PR adds an allow-by-default future-compatibility lint
`SEMICOLON_IN_EXPRESSIONS_FROM_MACROS`. It fires when a trailing semicolon in a
macro body is ignored due to the macro being used in expression
position:

```rust
macro_rules! foo {
    () => {
        true; // WARN
    }
}

fn main() {
    let val = match true {
        true => false,
        _ => foo!()
    };
}
```

The lint takes its level from the macro call site, and
can be allowed for a particular macro by adding
`#[allow(semicolon_in_expressions_from_macros)]`.

The lint is set to warn for all internal rustc crates (when being built
by a stage1 compiler). After the next beta bump, we can enable
the lint for the bootstrap compiler as well.
2021-01-28 08:51:43 -05:00
Jonas Schievink 7038bb1eb2
Rollup merge of #81252 - jyn514:resolve-timing, r=petrochenkov
Add more self-profile info to rustc_resolve

The idea is to help me find out where the time is being spent in compiling the docs for `windows-rs`: https://github.com/microsoft/windows-rs/issues/420#issuecomment-764991646
2021-01-23 20:16:09 +01:00
Esteban Küber 7698807770 Fix clippy and comment 2021-01-21 21:43:28 -08:00
Esteban Küber 74ddaf000c Avoid emitting redundant "unused label" lint 2021-01-21 21:41:46 -08:00
Esteban Küber 060dba67b7 Add loop head span to hir 2021-01-21 21:41:46 -08:00
Esteban Küber a701ff981d Suggest `'a` when given `a` only when appropriate
When encountering a name `a` that isn't resolved, but a label `'a` is
found in the current ribs, only suggest `'a` if this name is the value
expression of a `break` statement.

Solve FIXME.
2021-01-21 21:41:46 -08:00
Joshua Nelson 5f74ab4969 Add more self-profile info to rustc_resolve 2021-01-21 18:15:17 -05:00
Yuki Okushi a77c1d836a
Rollup merge of #81046 - rylev:unknown-external-crate, r=estebank
Improve unknown external crate error

This improves error messages when unknown items in the crate root are encountered.

Fixes #63799

r? ```@estebank```
2021-01-21 20:04:45 +09:00
Ashley Mannix b4defec768
Rollup merge of #81105 - LingMan:init_directly, r=nagisa
Initialize a few variables directly

Currently they are declared as `mut`, get initialized to a default value, and
then possibly overwritten.

By initializing to the final value directly, they don't need to be `mut` and
it's clear that they don't get mutated elsewhere later on.
2021-01-18 21:53:28 +10:00
Ryan Levick d829e40c7b Improve unknown external crate error 2021-01-18 12:05:07 +01:00