Commit Graph

22 Commits

Author SHA1 Message Date
Vadim Petrochenkov dbdbd30bf2 expand/resolve: Turn `#[derive]` into a regular macro attribute 2021-02-07 20:08:45 +03:00
Cameron Steffen fba747a06e Refactor out PrimitiveTypeTable 2021-02-03 08:32:23 -06:00
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
Vadim Petrochenkov 7f9a2cfa1b resolve: Reject ambiguity built-in attr vs different built-in attr 2021-01-17 01:48:17 +03:00
Yuki Okushi fd02c83bfe
Rollup merge of #80870 - petrochenkov:bmactable, r=oli-obk
resolve: Simplify built-in macro table

We don't use full `SyntaxExtension`s from the table, only `SyntaxExtensionKind`s, and `Ident` in `register_builtin_macro` always had dummy span. This PR removes unnecessary data from the table and related function signatures.

Noticed when reviewing #80850.
2021-01-12 07:59:13 +09:00
bors 26d451f4b3 Auto merge of #80782 - petrochenkov:viscopes, r=matthewjasper
resolve: Scope visiting doesn't need an `Ident`

Resolution scope visitor (`fn visit_scopes`) currently takes an `Ident` parameter, but it doesn't need a full identifier, or even its span, it only needs the `SyntaxContext` part.
The `SyntaxContext` part is necessary because scope visitor has to jump to macro definition sites, so it has to be directed by macro expansion information somehow.

I think it's clearer to pass only the necessary part.
Yes, usually visiting happens as a part of an identifier resolution, but in cases like collecting traits in scope (#80765) or collecting typo suggestions that's not the case.

r? `@matthewjasper`
2021-01-10 23:36:33 +00:00
Vadim Petrochenkov f9b5859173 resolve: Simplify built-in macro table 2021-01-10 14:48:47 +03:00
Mara Bos d651fa78ce Allow #[rustc_builtin_macro = "name"].
This makes it possible to have both std::panic and core::panic as a
builtin macro, by using different builtin macro names for each.

Also removes SyntaxExtension::is_derive_copy, as the macro name (e.g.
sym::Copy) is now tracked and provides that information directly.
2021-01-09 19:50:06 +01:00
Vadim Petrochenkov 3ff866ed7c resolve: Scope visiting doesn't need an `Ident` 2021-01-07 16:09:47 +03:00
Camelid ff75da89b1 Rename to `nearest_parent_mod`
* Rename `ModuleData.normal_ancestor_id` to `nearest_parent_mod`

`normal_ancestor_id` is a very confusing name if you don't already
understand what it means. Adding docs helps, but using a clearer and
more obvious name is also important.

* Rename `Resolver::nearest_mod_parent` to `nearest_parent_mod`

* Add more docs
2021-01-06 12:55:44 -08:00
Joshua Nelson edeac1778c Rename kw::Invalid -> kw::Empty
See https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Is.20there.20a.20symbol.20for.20the.20empty.20string.3F/near/220054471
for context.
2020-12-30 09:50:02 -05:00
Vadim Petrochenkov 993bb072ff rustc_expand: Mark inner `#![test]` attributes as soft-unstable 2020-11-20 19:35:03 +03:00
Vadim Petrochenkov dfb690eaa9 resolve/expand: Misc cleanup 2020-11-19 19:25:20 +03:00
Vadim Petrochenkov 68f94e94ed resolve: Centralize some error reporting for unexpected macro resolutions 2020-11-19 19:25:20 +03:00
Vadim Petrochenkov 69894ce9ac resolve: Introduce a separate `NonMacroAttrKind` for legacy derive helpers 2020-11-19 19:25:20 +03:00
Mara Bos 92dcf6d733
Rollup merge of #78999 - petrochenkov:deprid, r=eddyb
stability: More precise location for deprecation lint on macros

One missing piece of https://github.com/rust-lang/rust/pull/73178.
2020-11-18 15:46:25 +01:00
Vadim Petrochenkov ac4c1f58b9 rustc_resolve: Make `macro_rules` scope chain compression lazy 2020-11-14 00:35:56 +03:00
Vadim Petrochenkov 909c8945b1 stability: More precise location for deprecation lint on macros 2020-11-12 22:53:42 +03:00
Vadim Petrochenkov 922107919d resolve: Collapse `macro_rules` scope chains on the fly 2020-11-07 02:18:29 +03:00
Vadim Petrochenkov ef09ed2002 resolve: Relax macro resolution consistency check to account for any errors 2020-10-24 21:26:08 +03:00
Joshua Nelson be2947d0b7 Give a better error message for duplicate built-in macros
Previously, this would say no such macro existed, but this was
misleading, since the macro _did_ exist, it was just already seen.

- Say where the macro was previously defined
- Add long-form error message
2020-09-01 08:34:17 -04:00
mark 9e5f7d5631 mv compiler to compiler/ 2020-08-30 18:45:07 +03:00