Commit Graph

202 Commits

Author SHA1 Message Date
Mara Bos ffcbeefd64
Rollup merge of #80765 - petrochenkov:traitsinscope, r=matthewjasper
resolve: Simplify collection of traits in scope

"Traits in scope" for a given location are collected by walking all scopes in type namespace, collecting traits in them and pruning traits that don't have an associated item with the given name and namespace.

Previously we tried to prune traits using some kind of hygienic resolution for associated items, but that was complex and likely incorrect, e.g. in #80762 correction to visibilites of trait items caused some traits to not be in scope anymore.
I previously had some comments and concerns about this in https://github.com/rust-lang/rust/pull/65351.

In this PR we are doing some much simpler pruning based on `Symbol` and `Namespace` comparisons, it should be enough to throw away 99.9% of unnecessary traits.
It is not necessary for pruning to be precise because for trait aliases, for example, we don't do any pruning at all, and precise hygienic resolution for associated items needs to be done in typeck anyway.

The somewhat unexpected effect is that trait imports introduced by macros 2.0 now bring traits into scope due to the removed hygienic check on associated item names.
I'm not sure whether it is desirable or not, but I think it's acceptable for now.
The old check was certainly incorrect because macros 2.0 did bring trait aliases into scope.
If doing this is not desirable, then we should come up with some other way to avoid bringing traits from macros 2.0 into scope, that would accommodate for trait aliases as well.

---

The PR also contains a couple of pure refactorings
- Scope walk is done by using `visit_scopes` instead of a hand-rolled version.
- Code is restructured to accomodate for rustdoc that also wants to query traits in scope, but doesn't want to filter them by associated items at all.

r? ```@matthewjasper```
2021-01-17 12:24:47 +00:00
Mara Bos 3d5e7e0f47
Rollup merge of #80031 - petrochenkov:builtina, r=estebank
resolve: Reject ambiguity built-in attr vs different built-in attr

Fixes https://github.com/rust-lang/rust/issues/79798.

Resolution ensures that inert attributes cannot be used through imports like this, but built-in attributes don't go through initial resolution (only through resolution validation), so we have to keep some extra data (the built-in attribute name) to prevent it from happening.
2021-01-17 12:24:41 +00:00
LingMan 0a74e17211 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-17 02:07:37 +01:00
Vadim Petrochenkov 7f9a2cfa1b resolve: Reject ambiguity built-in attr vs different built-in attr 2021-01-17 01:48:17 +03:00
Bastian Kauschke 15f0921d0c correctly deal with late-bound lifetimes in anon consts 2021-01-16 19:27:42 +01:00
Yuki Okushi a584d87417
Rollup merge of #80944 - LingMan:map_or, r=nagisa
Use Option::map_or instead of `.map(..).unwrap_or(..)`

``@rustbot`` modify labels +C-cleanup +T-compiler
2021-01-15 18:26:14 +09:00
LingMan a56bffb4f9 Use Option::map_or instead of `.map(..).unwrap_or(..)` 2021-01-14 19:23:59 +01:00
bors 4275ef6c9d Auto merge of #79689 - Vooblin:patch1, r=tmandry
Update tests of "unused_lifetimes" lint for async functions and corresponding source code

Before this PR the following code would cause an error:
```
#![deny(unused_lifetimes)]
async fn f<'a>(_: &'a i32) {}
fn main() {}
```
It was happening because of the desugaring of return type in async functions. As a result of the desugaring, the return type contains all lifetimes involved in the function signature. And these lifetimes were interpreted separately from the same in the function scope => so they are unused.

Now, all lifetimes from the return type are interpreted as used. It is also not perfect, but at least this lint doesn't cause wrong errors now.

This PR connected to issues #78522, #77217
2021-01-14 17:27:15 +00:00
bors a62a76047e Auto merge of #77524 - Patryk27:fixes/66228, r=estebank
Rework diagnostics for wrong number of generic args (fixes #66228 and #71924)

This PR reworks the `wrong number of {} arguments` message, so that it provides more details and contextual hints.
2021-01-13 20:35:58 +00:00
bors 150d1fee04 Auto merge of #79322 - jyn514:refactor-impl, r=estebank
Separate out a `hir::Impl` struct

This makes it possible to pass the `Impl` directly to functions, instead
of having to pass each of the many fields one at a time. It also
simplifies matches in many cases.

See `rustc_save_analysis::dump_visitor::process_impl` or `rustdoc::clean::clean_impl` for a good example of how this makes `impl`s easier to work with.

r? `@petrochenkov` maybe?
2021-01-13 01:40:41 +00:00
Joshua Nelson a8ff647deb Separate out a `hir::Impl` struct
This makes it possible to pass the `Impl` directly to functions, instead
of having to pass each of the many fields one at a time. It also
simplifies matches in many cases.
2021-01-12 20:32:33 -05:00
Yuki Okushi 8c342da22e
Rollup merge of #80927 - LingMan:matches, r=estebank
Replace a simple `if let` with the `matches` macro

`@rustbot` modify labels +C-cleanup +T-compiler
2021-01-12 16:13:33 +09:00
LingMan 6bd661ef17 Replace a simple `if let` with the `matches` macro 2021-01-12 01:49:36 +01: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
Vadim Petrochenkov b7071b2353 resolve: Simplify collection of traits in scope 2021-01-11 23:49:47 +03: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
Patryk Wychowaniec d2f8e398f1
Rework diagnostics for wrong number of generic args 2021-01-10 13:07:40 +01:00
Vadim Petrochenkov f9b5859173 resolve: Simplify built-in macro table 2021-01-10 14:48:47 +03:00
Yuki Okushi 3e735c6e93
Rollup merge of #80850 - m-ou-se:rustc-builtin-macro-name, r=petrochenkov
Allow #[rustc_builtin_macro = "name"]

This adds the option of specifying the name of a builtin macro in the `#[rustc_builtin_macro]` attribute: `#[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. This is needed to implement the edition-specific behaviour of the panic macros of RFC 3007.

Also removes `SyntaxExtension::is_derive_copy`, as the macro name (e.g. `sym::Copy`) is now tracked and provides that information directly.

r? ``@petrochenkov``
2021-01-10 16:56:05 +09:00
Yuki Okushi 700f3f23d8
Rollup merge of #80801 - estebank:correct-binding-sugg-span, r=petrochenkov
Use correct span for structured suggestion

On structured suggestion for `let` -> `const`  and `const` -> `let`, use
a proper `Span` and update tests to check the correct application.

Follow up to #80012.
2021-01-10 16:55:59 +09: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 d81c1946c6 resolve/expand: Improve attribute expansion on macro definitions and calls 2021-01-09 18:43:01 +03:00
Esteban Küber 9a5dcaab67 Use correct span for structured suggestion
On structured suggestion for `let` -> `const`  and `const` -> `let`, use
a proper `Span` and update tests to check the correct application.

Follow up to #80012.
2021-01-07 16:52:44 -08:00
Yuki Okushi bb229b8f6c
Rollup merge of #80012 - sasurau4:feature/point-constant-identifier-E0435, r=petrochenkov
Add pointing const identifier when emitting E0435

Fix #79919
2021-01-08 02:05:58 +09:00
Vadim Petrochenkov 3ff866ed7c resolve: Scope visiting doesn't need an `Ident` 2021-01-07 16:09:47 +03:00
Daiki Ihara f03907b33f Add pointing const identifier when emitting E0435 2021-01-07 20:20:58 +09: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
Camelid 06931988c0 Document `ModuleData`
* Convert comments on fields to doc comments so they're visible in API
  docs
* Add new documentation
* Get rid of "normal module" terminology
2021-01-06 12:51:36 -08:00
Rémy Rakic 1fc3c4c16d adjust const generics defaults FIXMEs to the new feature gate 2021-01-01 11:01:01 +01:00
Julian Knodt 61f33bfd29 first pass at default values for const generics
- Adds optional default values to const generic parameters in the AST
  and HIR
- Parses these optional default values
- Adds a `const_generics_defaults` feature gate
2021-01-01 10:55:10 +01:00
Mara Bos c574ded57d Consistently call editions "Rust 20xx" in messages. 2020-12-31 19:06:09 +01:00
Mara Bos 9e8edc8c22
Rollup merge of #80495 - jyn514:rename-empty, r=petrochenkov
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.

r? `@petrochenkov`
2020-12-30 20:56:58 +00: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
Yuki Okushi 41fa0dba27
Rollup merge of #80509 - matthiaskrgr:ptr_arg, r=varkor
where possible, pass slices instead of &Vec or &String (clippy::ptr_arg)
2020-12-30 22:49:26 +09:00
Matthias Krüger e5ead5fc58 remove unused return types such as empty Results or Options that would always be Some(..)
remove unused return type of dropck::check_drop_obligations()
don't wrap return type in Option in get_macro_by_def_id() since we would always return Some(..)
remove redundant return type of back::write::optimize()
don't Option-wrap return type of compute_type_parameters() since we always return Some(..)
don't return empty Result in assemble_generator_candidates()
don't return empty Result in assemble_closure_candidates()
don't return empty result in assemble_fn_pointer_candidates()
don't return empty result in assemble_candidates_from_impls()
don't return empty result in assemble_candidates_from_auto_impls()
don't return emtpy result in assemble_candidates_for_trait_alias()
don't return empty result in assemble_builtin_bound_candidates()
don't return empty results in assemble_extension_candidates_for_traits_in_scope() and assemble_extension_candidates_for_trait()
remove redundant wrapping of return type of StripItem::strip() since it always returns Some(..)
remove unused return type of assemble_extension_candidates_for_all_traits()
2020-12-30 13:15:40 +01:00
Matthias Krüger bdc9291ed9 where possible, pass slices instead of &Vec or &String (clippy::ptr_arg) 2020-12-30 13:11:52 +01:00
Vadim Petrochenkov 4d2d0bad4e Remove `compile-fail` test suite 2020-12-29 23:39:56 +03:00
Dylan DPC 80934aba15
Rollup merge of #80411 - petrochenkov:nosymwith, r=matthewjasper
rustc_span: Remove `Symbol::with`

A subset of https://github.com/rust-lang/rust/pull/79425 that is a pure refactoring.
2020-12-28 14:13:21 +01:00
Dylan DPC c51172f38a
Rollup merge of #80344 - matthiaskrgr:matches, r=Dylan-DPC
use matches!() macro in more places
2020-12-28 14:13:12 +01:00
Vadim Petrochenkov 0ae998e122 rustc_span: Remove `Symbol::with` 2020-12-27 18:10:58 +03:00
Bastian Kauschke 06cc9c26da stabilize min_const_generics 2020-12-26 18:24:10 +01:00
Matthias Krüger d12a358673 use matches!() macro in more places 2020-12-24 13:35:12 +01:00
Dániel Buga 6d71cc6750 Move std_path construction into condition 2020-12-20 23:55:03 +01:00
Dániel Buga 66c2872901 Inline a single-use closure 2020-12-20 23:17:56 +01:00
Dániel Buga f499601dd8 Create closure outside of the loop 2020-12-20 22:49:53 +01:00
Dániel Buga 89bc399d56 Add missing semicolon 2020-12-20 21:41:35 +01:00
Dániel Buga 91ea623f49 Remove unnecessary cloned 2020-12-20 21:41:15 +01:00
Dániel Buga 62f593bda9 Precompute vector length in smart_resolve_path_fragment 2020-12-20 21:38:41 +01:00
Dániel Buga 93d5a8025d Clean up with_generic_param_rib, avoid double hashing 2020-12-20 21:08:55 +01:00
Daiki Ihara 7b9ee11a4c Enhance error message when misspelled label to value in break expression
Apply suggestions from code review

Co-authored-by: lcnr <bastian_kauschke@hotmail.de>
2020-12-17 20:22:22 +09:00
Camelid 5ce3f4c166 Resolve enum field visibility correctly
Previously, this code treated enum fields' visibility as if they were
struct fields. However, that's not correct because the visibility of a
struct field with `ast::VisibilityKind::Inherited` is private to the
module it's defined in, whereas the visibility of an *enum* field with
`ast::VisibilityKind::Inherited` is the visibility of the enum it
belongs to.
2020-12-12 14:04:59 -08:00
Dmitry Murygin 64f11b9639 Update tests of "unused_lifetimes" lint for async functions and corresponding source code 2020-12-04 08:25:59 +03:00
Yuki Okushi cdcce11504 Tweak diagnostics on shadowing lifetimes/labels 2020-12-02 11:39:42 +09:00
Camille GILLOT 032f68d625 Remove ForeignMod struct. 2020-11-26 21:32:27 +01:00
Arlie Davis 5481c1bd6d Move lev_distance to rustc_ast, make non-generic
rustc_ast currently has a few dependencies on rustc_lexer. Ideally, an AST
would not have any dependency its lexer, for minimizing unnecessarily
design-time dependencies. Breaking this dependency would also have practical
benefits, since modifying rustc_lexer would not trigger a rebuild of rustc_ast.

This commit does not remove the rustc_ast --> rustc_lexer dependency,
but it does remove one of the sources of this dependency, which is the
code that handles fuzzy matching between symbol names for making suggestions
in diagnostics. Since that code depends only on Symbol, it is easy to move
it to rustc_span. It might even be best to move it to a separate crate,
since other tools such as Cargo use the same algorithm, and have simply
contain a duplicate of the code.

This changes the signature of find_best_match_for_name so that it is no
longer generic over its input. I checked the optimized binaries, and this
function was duplicated at nearly every call site, because most call sites
used short-lived iterator chains, generic over Map and such. But there's
no good reason for a function like this to be generic, since all it does
is immediately convert the generic input (the Iterator impl) to a concrete
Vec<Symbol>. This has all of the costs of generics (duplicated method bodies)
with no benefit.

Changing find_best_match_for_name to be non-generic removed about 10KB of
code from the optimized binary. I know it's a drop in the bucket, but we have
to start reducing binary size, and beginning to tame over-use of generics
is part of that.
2020-11-24 16:12:23 -08:00
Jonas Schievink f049b0be96
Rollup merge of #79374 - mendess:const-param-expr-diagnostic, r=lcnr
Add note to use nightly when using expr in const generics

As recommended by `@Icnr` in #73899 and in zulip, I've added a note saying that const expressions can be used in nightly.

```
error: generic parameters may not be used in const operations
  --> $DIR/issue-61935.rs:10:23
   |
 6 |         Self:FooImpl<{N==0}>
   |                       ^ cannot perform const operation using `N`
   |
   = help: const parameters may only be used as standalone arguments, i.e. `N`
   = note: use feature(const_generics) and feature(const_evaluatable_checked) to enable this

error: aborting due to previous error
```

I hope the note is well written 😅
2020-11-24 13:17:51 +01:00
mendess 888055eb4c Swap note for help 2020-11-24 11:05:55 +00:00
mendess af978e3b63 Requested changes 2020-11-24 10:28:18 +00:00
mendess b7593e5070 Add note to use nightly when using expr in const generics 2020-11-24 09:35:08 +00:00
bors 6331023708 Auto merge of #79294 - petrochenkov:determ, r=varkor
resolve: Do not put macros into `module.unexpanded_invocations` unless necessary

Macro invocations in modules <sup>(*)</sup> need to be tracked because they can produce named items when expanded.
We cannot give definite answer to queries like "does this module declare name `n`?" until all macro calls in that module are expanded.

Previously we marked too many macros as potentially producing named items.
E.g. in this example
```rust
mod m {
    const C: u32 = line!();
}
```
`line!()` cannot emit any items into module `m`, but it was still marked.
This PR fixes that and marks macro calls as "unexpanded in module" only if they can actually emit named items into that module.

Diagnostics in UI test outputs have different order now because this change affects macro expansion order.

<sup>*</sup> Any containers for named items are called modules in resolve (that includes blocks, traits and enums in addition to `mod` items).
2020-11-24 09:17:33 +00:00
Jonas Schievink c58c245e2c
Rollup merge of #79236 - lcnr:mcg-resolve-dsb, r=eddyb
const_generics: assert resolve hack causes an error

prevent the min_const_generics `HACK`s in resolve from triggering a fallback path which successfully compiles so that we don't have to worry about future compat issues when removing it

r? `@eddyb` cc `@varkor`
2020-11-23 15:25:42 +01:00
Vadim Petrochenkov 27af650a0d resolve: Do not put macros into `module.unexpanded_invocations` unless necessary 2020-11-22 14:42:29 +03:00
Bastian Kauschke c85af74fcd update bug message for cg 2020-11-20 23:31:36 +01:00
Bastian Kauschke 34ea5d02dd const_generics: assert resolve hack causes an error 2020-11-20 23:29:54 +01: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
Jonas Schievink b0178f4cc7
Rollup merge of #79034 - petrochenkov:mrscopes3, r=eddyb
rustc_resolve: Make `macro_rules` scope chain compression lazy

As suggested in https://github.com/rust-lang/rust/pull/78826#issuecomment-723420664.
2020-11-15 13:39:57 +01:00
Jonas Schievink 8825942e86
Rollup merge of #77802 - jyn514:bootstrap-specific, r=nikomatsakis
Allow making `RUSTC_BOOTSTRAP` conditional on the crate name

Motivation: This came up in the [Zulip stream](https://rust-lang.zulipchat.com/#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/Require.20users.20to.20confirm.20they.20know.20RUSTC_.E2.80.A6.20compiler-team.23350/near/208403962) for https://github.com/rust-lang/compiler-team/issues/350.
See also https://github.com/rust-lang/cargo/pull/6608#issuecomment-458546258; this implements https://github.com/rust-lang/cargo/issues/6627.
The goal is for this to eventually allow prohibiting setting `RUSTC_BOOTSTRAP` in build.rs (https://github.com/rust-lang/cargo/issues/7088).

## User-facing changes

- `RUSTC_BOOTSTRAP=1` still works; there is no current plan to remove this.
- Things like `RUSTC_BOOTSTRAP=0` no longer activate nightly features. In practice this shouldn't be a big deal, since `RUSTC_BOOTSTRAP` is the opposite of stable and everyone uses `RUSTC_BOOTSTRAP=1` anyway.
- `RUSTC_BOOTSTRAP=x` will enable nightly features only for crate `x`.
- `RUSTC_BOOTSTRAP=x,y` will enable nightly features only for crates `x` and `y`.

## Implementation changes

The main change is that `UnstableOptions::from_environment` now requires
an (optional) crate name. If the crate name is unknown (`None`), then the new feature is not available and you still have to use `RUSTC_BOOTSTRAP=1`. In practice this means the feature is only available for `--crate-name`, not for `#![crate_name]`; I'm interested in supporting the second but I'm not sure how.

Other major changes:

- Added `Session::is_nightly_build()`, which uses the `crate_name` of
the session
- Added `nightly_options::match_is_nightly_build`, a convenience method
for looking up `--crate-name` from CLI arguments.
`Session::is_nightly_build()`should be preferred where possible, since
it will take into account `#![crate_name]` (I think).
- Added `unstable_features` to `rustdoc::RenderOptions`

I'm not sure whether this counts as T-compiler or T-lang; _technically_ RUSTC_BOOTSTRAP is an implementation detail, but it's been used so much it seems like this counts as a language change too.

r? `@joshtriplett`
cc `@Mark-Simulacrum` `@hsivonen`
2020-11-15 13:39:43 +01:00
Vadim Petrochenkov ac4c1f58b9 rustc_resolve: Make `macro_rules` scope chain compression lazy 2020-11-14 00:35:56 +03:00
bors a38f8fb674 Auto merge of #78826 - petrochenkov:mrscopes2, r=eddyb
resolve: Collapse `macro_rules` scope chains on the fly

Otherwise they grow too long and you have to endlessly walk through them when resolving macros or imports.
Addresses https://rust-lang.zulipchat.com/#narrow/stream/247081-t-compiler.2Fperformance/topic/Slow.20Builtin.20Derives/near/215750815
2020-11-13 05:40:37 +00:00
Vadim Petrochenkov 909c8945b1 stability: More precise location for deprecation lint on macros 2020-11-12 22:53:42 +03:00
Fabian Zaiser de84ad95b4 Implement destructuring assignment for structs and slices
Co-authored-by: varkor <github@varkor.com>
2020-11-11 12:10:52 +00:00
Mara Bos 829e88032a
Rollup merge of #78860 - petrochenkov:resolvefmt, r=Mark-Simulacrum
rustc_resolve: Use `#![feature(format_args_capture)]`

This is the best new sugar for quite some time.

(I only changed places that already used named arguments.)
2020-11-08 13:36:30 +01:00
Vadim Petrochenkov 907b87fafa rustc_resolve: Use `#![feature(format_args_capture)]` 2020-11-08 01:38:11 +03:00
Joshua Nelson 622c48e4f1 Allow making `RUSTC_BOOTSTRAP` conditional on the crate name
The main change is that `UnstableOptions::from_environment` now requires
an (optional) crate name. If the crate name is unknown (`None`), then the new feature is not available and you still have to use `RUSTC_BOOTSTRAP=1`. In practice this means the feature is only available for `--crate-name`, not for `#![crate_name]`; I'm interested in supporting the second but I'm not sure how.

Other major changes:

- Added `Session::is_nightly_build()`, which uses the `crate_name` of
the session
- Added `nightly_options::match_is_nightly_build`, a convenience method
for looking up `--crate-name` from CLI arguments.
`Session::is_nightly_build()`should be preferred where possible, since
it will take into account `#![crate_name]` (I think).
- Added `unstable_features` to `rustdoc::RenderOptions`

  There is a user-facing change here: things like `RUSTC_BOOTSTRAP=0` no
  longer active nightly features. In practice this shouldn't be a big
  deal, since `RUSTC_BOOTSTRAP` is the opposite of stable and everyone
  uses `RUSTC_BOOTSTRAP=1` anyway.

- Add tests

  Check against `Cheat`, not whether nightly features are allowed.
  Nightly features are always allowed on the nightly channel.

- Only call `is_nightly_build()` once within a function

- Use booleans consistently for rustc_incremental

  Sessions can't be passed through threads, so `read_file` couldn't take a
  session. To be consistent, also take a boolean in `write_file_header`.
2020-11-07 13:45:11 -05:00
Vadim Petrochenkov 922107919d resolve: Collapse `macro_rules` scope chains on the fly 2020-11-07 02:18:29 +03:00
Mark Rousskov ae4f80b4be Revert "Revert "resolve: Avoid "self-confirming" import resolutions in one more case""
This reverts commit b20bce8ce5.

It retains the test added in that commit as a check-pass test, intended to
prevent future (unintentional) regressions.
2020-11-06 11:22:13 -05:00
Matthias Krüger bcd2f2df67 fix a couple of clippy warnings:
filter_next
manual_strip
redundant_static_lifetimes
single_char_pattern
unnecessary_cast
unused_unit
op_ref
redundant_closure
useless_conversion
2020-11-04 13:48:50 +01:00
Vadim Petrochenkov 19dbb02a89 Expand `NtExpr` tokens only in key-value attributes 2020-11-03 00:53:43 +03:00
bors 1d5b7c3c96 Auto merge of #78420 - estebank:suggest-assoc-fn, r=petrochenkov
Suggest calling associated `fn` inside `trait`s

When calling a function that doesn't exist inside of a trait's
associated `fn`, and another associated `fn` in that trait has that
name, suggest calling it with the appropriate fully-qualified path.

Expand the label to be more descriptive.

Prompted by the following user experience:
https://users.rust-lang.org/t/cannot-find-function/50663
2020-11-01 06:49:16 +00:00
Joshua Nelson 5339bd1ebe Add back missing comments 2020-10-30 10:13:41 -04:00
Joshua Nelson 57c6ed0c07 Fix even more clippy warnings 2020-10-30 10:13:39 -04:00
bors 6bdae9edd0 Auto merge of #78508 - wesleywiser:optimize_visit_scopes, r=petrochenkov
[resolve] Use `unwrap_or_else` instead of `unwrap_or` in a hot path

This improves the performance of the `resolve_crate` function by 30% for
a very large single file crate with auto-generated C bindings.

cc `@rylev`
2020-10-29 18:34:59 +00:00
Yuki Okushi 270d2e0c2e
Rollup merge of #78224 - lcnr:repeat-expr, r=varkor
min_const_generics: allow ty param in repeat expr

implements https://rust-lang.zulipchat.com/#narrow/stream/260443-project-const-generics/topic/repeat.20expressions

Even with `min_const_generics` active, now keeps resulting in future compat warnings instead of hard errors.
Const parameters, for example `[0; N + 1]`, still result in hard errors during resolve.
```rust
#![allow(dead_code)]

fn foo<T>() {
    [0; std::mem::size_of::<*mut T>()];
}

struct Foo<T>(T);

impl<T> Foo<T> {
    const ASSOC: usize = 4;

    fn test() {
        [0; Self::ASSOC];
    }
}
```

r? @varkor cc @petrochenkov
2020-10-29 12:08:40 +09:00
Wesley Wiser 1c1c591c81 [resolve] Use `unwrap_or_else` instead of `unwrap_or` in a hot path
This improves the performance of the `resolve_crate` function by 30% for
a very large single file crate with auto-generated C bindings.
2020-10-28 21:53:25 -04:00
Esteban Küber 9e16213610 Suggest calling associated `fn` inside `trait`s
When calling a function that doesn't exist inside of a trait's
associated `fn`, and another associated `fn` in that trait has that
name, suggest calling it with the appropriate fully-qualified path.

Expand the label to be more descriptive.

Prompted by the following user experience:
https://users.rust-lang.org/t/cannot-find-function/50663
2020-10-26 16:31:11 -07:00
David Wood 27bb27f71c
resolve: private fields in tuple struct ctor diag
This commit improves the diagnostic emitted when a tuple struct is being
constructed which has private fields so that private fields are
labelled and the message is improved.

Signed-off-by: David Wood <david@davidtw.co>
2020-10-26 14:56:27 +00:00
Yuki Okushi 569d29d55c
Rollup merge of #77984 - Aaron1011:fix/macro-mod-weird-parent, r=petrochenkov
Compute proper module parent during resolution

Fixes #75982

The direct parent of a module may not be a module
(e.g. `const _: () =  { #[path = "foo.rs"] mod foo; };`).

To find the parent of a module for purposes of resolution, we need to
walk up the tree until we hit a module or a crate root.
2020-10-25 18:43:37 +09:00
bors 3e0dd24a6c Auto merge of #77546 - lcnr:impl-trait-closure, r=eddyb
fix def collector for impl trait

fixes #77329

We now consistently make `impl Trait` a hir owner, requiring some special casing for synthetic generic params.

r? `@eddyb`
2020-10-25 07:03:58 +00:00
Aaron Hill 283053a742
Compute proper module parent during resolution
Fixes #75982

The direct parent of a module may not be a module
(e.g. `const _: () =  { #[path = "foo.rs"] mod foo; };`).

To find the parent of a module for purposes of resolution, we need to
walk up the tree until we hit a module or a crate root.
2020-10-24 14:28:13 -04:00
Vadim Petrochenkov ef09ed2002 resolve: Relax macro resolution consistency check to account for any errors 2020-10-24 21:26:08 +03:00
Bastian Kauschke 4a15a25662 min_const_generics: allow ty param in repeat expr 2020-10-22 10:43:28 +02:00
bors 6b9fbf212a Auto merge of #78134 - bugadani:arena-nodrop, r=lcnr
Use `DroplessArena` where we know the type doesn't need drop

This PR uses a single `DroplessArena` in resolve instead of three separate `TypedArena`s.

`DroplessArena` checks that the type indeed doesn't need drop, so in case the types change, this will result in visible failures.
2020-10-22 07:05:21 +00:00
Dániel Buga d07ce65d56 Resolve: Use dropless arena for types that don't need drop 2020-10-20 10:37:56 +02:00
Vadim Petrochenkov cee5521a03 Calculate visibilities once in resolve
Then use them through a query based on resolver outputs
2020-10-19 11:57:50 +03:00
Yuki Okushi 57e38dd4fb
Rollup merge of #78048 - blyxxyz:e0424-improve-self-placement, r=lcnr
Suggest correct place to add `self` parameter when inside closure

It would incorrectly suggest adding it as a parameter to the closure instead of the containing function.

[For example](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=1936bcd1e5f981573386e0cee985c3c0):
```
help: add a `self` receiver parameter to make the associated `fn` a method
  |
5 |         let _ = || self&self;
  |                        ^^^^^
```

`DiagnosticMetadata.current_function` is only used for these messages so tweaking its behavior should be ok.
2020-10-18 04:11:11 +09:00
Jan Verbeek e701ae376a Suggest correct place to add `self` parameter when inside closure
It would incorrectly suggest adding it as a parameter to the closure instead of the
containing function.
2020-10-17 13:36:59 +02:00