about summary refs log tree commit diff
path: root/compiler/rustc_resolve/src
AgeCommit message (Collapse)AuthorLines
2020-11-13Auto merge of #78826 - petrochenkov:mrscopes2, r=eddybbors-29/+69
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-12stability: More precise location for deprecation lint on macrosVadim Petrochenkov-0/+1
2020-11-11Implement destructuring assignment for structs and slicesFabian Zaiser-3/+1
Co-authored-by: varkor <github@varkor.com>
2020-11-08Rollup merge of #78860 - petrochenkov:resolvefmt, r=Mark-SimulacrumMara Bos-38/+13
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-08rustc_resolve: Use `#![feature(format_args_capture)]`Vadim Petrochenkov-38/+13
2020-11-07Allow making `RUSTC_BOOTSTRAP` conditional on the crate nameJoshua Nelson-3/+2
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-07resolve: Collapse `macro_rules` scope chains on the flyVadim Petrochenkov-29/+69
2020-11-06Revert "Revert "resolve: Avoid "self-confirming" import resolutions in one ↵Mark Rousskov-2/+11
more case"" This reverts commit b20bce8ce54ea9d47c2e3eb0b17cbb6baf916ae2. It retains the test added in that commit as a check-pass test, intended to prevent future (unintentional) regressions.
2020-11-04fix a couple of clippy warnings:Matthias Krüger-3/+2
filter_next manual_strip redundant_static_lifetimes single_char_pattern unnecessary_cast unused_unit op_ref redundant_closure useless_conversion
2020-11-03Expand `NtExpr` tokens only in key-value attributesVadim Petrochenkov-22/+0
2020-11-01Auto merge of #78420 - estebank:suggest-assoc-fn, r=petrochenkovbors-27/+55
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-30Add back missing commentsJoshua Nelson-0/+1
2020-10-30Fix even more clippy warningsJoshua Nelson-169/+91
2020-10-29Auto merge of #78508 - wesleywiser:optimize_visit_scopes, r=petrochenkovbors-4/+3
[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-29Rollup merge of #78224 - lcnr:repeat-expr, r=varkorYuki Okushi-18/+70
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-28[resolve] Use `unwrap_or_else` instead of `unwrap_or` in a hot pathWesley Wiser-4/+3
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-26Suggest calling associated `fn` inside `trait`sEsteban Küber-27/+55
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-26resolve: private fields in tuple struct ctor diagDavid Wood-44/+61
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-25Rollup merge of #77984 - Aaron1011:fix/macro-mod-weird-parent, r=petrochenkovYuki Okushi-7/+41
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-25Auto merge of #77546 - lcnr:impl-trait-closure, r=eddybbors-4/+4
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-24Compute proper module parent during resolutionAaron Hill-7/+41
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-24resolve: Relax macro resolution consistency check to account for any errorsVadim Petrochenkov-4/+4
2020-10-22min_const_generics: allow ty param in repeat exprBastian Kauschke-18/+70
2020-10-22Auto merge of #78134 - bugadani:arena-nodrop, r=lcnrbors-7/+5
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-20Resolve: Use dropless arena for types that don't need dropDániel Buga-7/+5
2020-10-19Calculate visibilities once in resolveVadim Petrochenkov-81/+131
Then use them through a query based on resolver outputs
2020-10-18Rollup merge of #78048 - blyxxyz:e0424-improve-self-placement, r=lcnrYuki Okushi-3/+5
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-17Suggest correct place to add `self` parameter when inside closureJan Verbeek-3/+5
It would incorrectly suggest adding it as a parameter to the closure instead of the containing function.
2020-10-17resolve: Do not put nonexistent crate `meta` into preludeVadim Petrochenkov-3/+0
2020-10-17Rollup merge of #77855 - ↵Yuki Okushi-62/+88
davidtwco:pr-77341-follow-up-non-constructable-variants, r=estebank resolve: further improvements to "try using the enum's variant" diagnostic Follow-up on https://github.com/rust-lang/rust/pull/77341#issuecomment-702738281. This PR improves the diagnostic modified in #77341 to suggest not only those variants which do not have fields, but those with fields (by suggesting with placeholders). In addition, the wording of the tuple-variant-only case is improved slightly. I've not made further changes to the tuple-variant-only case (e.g. to only suggest variants with the correct number of fields) because I don't think I have enough information to do so reliably (e.g. in the case where there is an attempt to construct a tuple variant, I have no information on how many fields were provided; and in the case of pattern matching, I only have a slice of spans and would need to check for things like `..` in those spans, which doesn't seem worth it). r? @estebank
2020-10-17Rollup merge of #75209 - Hirrolot:suggest-macro-imports, r=estebankYuki Okushi-0/+11
Suggest imports of unresolved macros Closes https://github.com/rust-lang/rust/issues/75191.
2020-10-15resolve: improve "try using tuple struct" messageDavid Wood-11/+11
This commit improves the tuple struct case added in rust-lang/rust#77341 so that the context is mentioned in more of the message. Signed-off-by: David Wood <david@davidtw.co>
2020-10-15resolve: suggest variants with placeholdersDavid Wood-60/+86
This commit improves the diagnostic modified in rust-lang/rust#77341 to suggest not only those variants which do not have fields, but those with fields (by suggesting with placeholders). Signed-off-by: David Wood <david@davidtw.co>
2020-10-14Rollup merge of #77825 - ethanboxx:min_const_generics_diagnostic, r=lcnrYuki Okushi-15/+8
`min_const_generics` diagnostics improvements As disscussed in [zulip/project-const-generics/non-trivial anonymous constant](https://rust-lang.zulipchat.com/#narrow/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants). This is my first PR on the compiler. @lcnr is mentoring me on this PR. Related to #60551.
2020-10-12A little rewordingEthan Brierley-1/+1
Co-authored-by: varkor <github@varkor.com>
2020-10-12Remove a little jargon from errorEthan Brierley-1/+1
Co-authored-by: varkor <github@varkor.com>
2020-10-12Make error help clearerEthan Brierley-1/+1
Co-authored-by: varkor <github@varkor.com>
2020-10-11`min_const_generics` diagnostics improvementsEthan Brierley-15/+8
2 3
2020-10-09address review commentsEsteban Küber-8/+16
2020-10-09Add docstringEsteban Küber-0/+2
2020-10-09Given `<T as Trait>::A: Ty` suggest `T: Trait<A = Ty>`Esteban Küber-0/+129
Fix #75829
2020-10-09Suggest removing bounds even when potential typoEsteban Küber-15/+21
2020-10-09Tweak output and add test casesEsteban Küber-5/+51
2020-10-09Point out why a trait is expected on `Struct + 'lt`Esteban Küber-1/+17
2020-10-07Auto merge of #77341 - davidtwco:issue-73427-you-might-have-meant-variant, ↵bors-21/+124
r=estebank resolve: improve "try using the enum's variant" Fixes #73427. This PR improves the "try using the enum's variant" suggestion: - Variants in suggestions would not result in more errors (e.g. use of a struct variant is only suggested if the suggestion can trivially construct that variant). Therefore, suggestions are only emitted for variants that have no fields (since the suggestion can't know what value fields would have). - Suggestions include the syntax for constructing the variant. If a struct or tuple variant is suggested, then it is constructed in the suggestion - unless in pattern-matching or when arguments are already provided. - A help message is added which mentions the variants which are no longer suggested. All of the diagnostic logic introduced by this PR is separated from the normal code path for a successful compilation. r? `@estebank`
2020-10-07fix def collector for impl traitBastian Kauschke-4/+4
2020-10-05Rollup merge of #77439 - varkor:min_const_generics-tests, r=lcnr,estebankDylan DPC-2/+2
Fix missing diagnostic span for `impl Trait` with const generics, and add various tests for `min_const_generics` and `const_generics` Closes https://github.com/rust-lang/rust/issues/61410. Adds `min_const_generics` tests for: - https://github.com/rust-lang/rust/issues/73727 - https://github.com/rust-lang/rust/issues/72293 - https://github.com/rust-lang/rust/issues/67375 - https://github.com/rust-lang/rust/issues/75153 - https://github.com/rust-lang/rust/issues/71922 - https://github.com/rust-lang/rust/issues/69913 - https://github.com/rust-lang/rust/issues/67945 - https://github.com/rust-lang/rust/issues/69239 Adds `const_generics` tests for: - https://github.com/rust-lang/rust/issues/67375 - https://github.com/rust-lang/rust/issues/75153 - https://github.com/rust-lang/rust/issues/71922 - https://github.com/rust-lang/rust/issues/69913 - https://github.com/rust-lang/rust/issues/67945 - https://github.com/rust-lang/rust/issues/69239 (I only added separate `min_const_generics` and `const_generics` tests if they were handled differently by the two features.) We need to figure out how to deduplicate when `const_generics` is stabilised, but we can discuss that later. For now, we should be checking neither feature breaks, so require regression tests for both. I've given them identical names when I've added both, which should make it easier to spot them later. r? @lcnr
2020-10-03Replace "non trivial" with "non-trivial"varkor-2/+2
2020-10-03Rollup merge of #77421 - petrochenkov:globtravel, r=nagisaJonas Schievink-11/+2
Revert "resolve: Avoid "self-confirming" import resolutions in one more case" And remove the assert that https://github.com/rust-lang/rust/pull/70236 tried to avoid instead. Closes https://github.com/rust-lang/rust/issues/74556.
2020-10-02resolve: prohibit anon const non-static lifetimesDavid Wood-0/+33
This commit modifies name resolution to emit an error when non-static lifetimes are used in anonymous constants when the `min_const_generics` feature is enabled. Signed-off-by: David Wood <david@davidtw.co>