summary refs log tree commit diff
path: root/compiler/rustc_resolve/src/lib.rs
AgeCommit message (Collapse)AuthorLines
2021-07-17Use LocalExpnId where possible.Camille GILLOT-21/+25
2021-07-14Change type param -> generic paramEllen-2/+2
2021-07-13Cache expansion hash.Camille GILLOT-2/+42
2021-07-10rustc_span: Revert addition of `proc_macro` field to `ExpnKind::Macro`Vadim Petrochenkov-5/+3
The flag has a vague meaning and is used for a single diagnostic change that is low benefit and appears only under `-Z macro_backtrace`.
2021-07-06Revert "Revert "Merge CrateDisambiguator into StableCrateId""bjorn3-1/+1
This reverts commit 8176ab8bc18fdd7d3c2cf7f720c51166364c33a3.
2021-06-24Auto merge of #85427 - ehuss:fix-use-placement, r=jackh726bors-8/+8
Fix use placement for suggestions near main. This fixes an edge case for the suggestion to add a `use`. When running with `--test`, the `main` function will be annotated with an `#[allow(dead_code)]` attribute. The `UsePlacementFinder` would end up using the dummy span of that synthetic attribute. If there are top-level inner attributes, this would place the `use` in the wrong position. The solution here is to ignore attributes with dummy spans. In the process of working on this, I discovered that the `use_suggestion_placement` test was broken. `UsePlacementFinder` is unaware of active attributes. Attributes like `#[derive]` don't exist in the AST since they are removed. Fixing that is difficult, since the AST does not retain enough information. I considered trying to place the `use` towards the top of the module after any `extern crate` items, but I couldn't find a way to get a span for the start of a module block (the `mod` span starts at the `mod` keyword, and it seems tricky to find the spot just after the opening bracket and past inner attributes). For now, I just put some comments about the issue. This appears to have been a known issue in #44215 where the test for it was introduced, and the fix seemed to be deferred to later.
2021-06-15Rollup merge of #85608 - scottmcm:stabilize-control-flow-enum-basics, r=m-ou-seYuki Okushi-1/+0
Stabilize `ops::ControlFlow` (just the type) Tracking issue: https://github.com/rust-lang/rust/issues/75744 (which also tracks items *not* closed by this PR). With the new `?` desugar implemented, [it's no longer possible to mix `Result` and `ControlFlow`](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=13feec97f5c96a9d791d97f7de2d49a6). (At the time of making this PR, godbolt was still on the 2021-05-01 nightly, where you can see that [the mixing example compiled](https://rust.godbolt.org/z/13Ke54j16).) That resolves the only blocker I know of, so I'd like to propose that `ControlFlow` be considered for stabilization. Its basic existence was part of https://github.com/rust-lang/rfcs/pull/3058, where it got a bunch of positive comments (examples [1](https://github.com/rust-lang/rfcs/pull/3058#issuecomment-758277325) [2](https://github.com/rust-lang/rfcs/pull/3058#pullrequestreview-592106494) [3](https://github.com/rust-lang/rfcs/pull/3058#issuecomment-784444155) [4](https://github.com/rust-lang/rfcs/pull/3058#issuecomment-797031584)). Its use in the compiler has been well received (https://github.com/rust-lang/rust/pull/78182#issuecomment-713695594), and there are ecosystem updates interested in using it (https://github.com/rust-itertools/itertools/issues/469#issuecomment-677729589, https://github.com/jonhoo/rust-imap/issues/194). As this will need an FCP, picking a libs member manually: r? `@m-ou-se` ## Stabilized APIs ```rust #[derive(Debug, Clone, Copy, PartialEq)] pub enum ControlFlow<B, C = ()> { /// Exit the operation without running subsequent phases. Break(B), /// Move on to the next phase of the operation as normal. Continue(C), } ``` As well as using `?` on a `ControlFlow<B, _>` in a function returning `ControlFlow<B, _>`. (Note, in particular, that there's no `From::from`-conversion on the `Break` value, the way there is for `Err`s.) ## Existing APIs *not* stabilized here All the associated methods and constants: `break_value`, `is_continue`, `map_break`, [`CONTINUE`](https://doc.rust-lang.org/nightly/std/ops/enum.ControlFlow.html#associatedconstant.CONTINUE), etc. Some of the existing methods in nightly seem reasonable, some seem like they should be removed, and some need more discussion to decide. But none of them are *essential*, so [as in the RFC](https://rust-lang.github.io/rfcs/3058-try-trait-v2.html#methods-on-controlflow), they're all omitted from this PR. They can be considered separately later, as further usage demonstrates which are important.
2021-06-08Store boxed metadata loader in CrateLoaderbjorn3-1/+1
2021-06-07Revert "Merge CrateDisambiguator into StableCrateId"bjorn3-1/+1
This reverts commit d0ec85d3fb6d322496cb8f4bc1c21e19f23284ad.
2021-06-03Rollup merge of #85896 - BoxyUwU:remove-fixme-fwd-declared-const-default, ↵Yuki Okushi-2/+2
r=petrochenkov Add test for forward declared const param defaults
2021-06-01Make trait_map an Option.Camille GILLOT-12/+3
2021-06-01Rename take_trait_map.Camille GILLOT-1/+1
2021-06-01Check that trait_map is not moved twice.Camille GILLOT-0/+9
2021-06-01Only compute the trait_map once.Camille GILLOT-2/+2
2021-06-01Add test for forward declared const param defaultsEllen-2/+2
2021-06-01Revert "Reduce the amount of untracked state in TyCtxt"Camille Gillot-11/+2
2021-05-30Rename take_trait_map.Camille GILLOT-1/+1
2021-05-30Check that trait_map is not moved twice.Camille GILLOT-0/+9
2021-05-30Only compute the trait_map once.Camille GILLOT-2/+2
2021-05-30Merge CrateDisambiguator into StableCrateIdbjorn3-1/+1
2021-05-26Rollup merge of #85478 - FabianWolff:issue-85348, r=petrochenkovDylan DPC-1/+8
Disallow shadowing const parameters This pull request fixes #85348. Trying to shadow a `const` parameter as follows: ```rust fn foo<const N: i32>() { let N @ _ = 0; } ``` currently causes an ICE. With my changes, I get: ``` error[E0530]: let bindings cannot shadow const parameters --> test.rs:2:9 | 1 | fn foo<const N: i32>() { | - the const parameter `N` is defined here 2 | let N @ _ = 0; | ^ cannot be named the same as a const parameter error: aborting due to previous error ``` This is the same error you get when trying to shadow a constant: ```rust const N: i32 = 0; let N @ _ = 0; ``` ``` error[E0530]: let bindings cannot shadow constants --> src/lib.rs:3:5 | 2 | const N: i32 = 0; | ----------------- the constant `N` is defined here 3 | let N @ _ = 0; | ^ cannot be named the same as a constant error: aborting due to previous error ``` The reason for disallowing shadowing in both cases is described [here](https://github.com/rust-lang/rust/issues/33118#issuecomment-233962221) (the comment there only talks about constants, but the same reasoning applies to `const` parameters).
2021-05-24remove cfg(bootstrap)Pietro Albini-1/+0
2021-05-23Stabilize ops::ControlFlow (just the type)Scott McMurray-1/+0
2021-05-19Disallow shadowing const parametersFabian Wolff-1/+8
2021-05-18Fix use placement for suggestions near main.Eric Huss-8/+8
2021-05-12Implement span quoting for proc-macrosAaron Hill-3/+5
This PR implements span quoting, allowing proc-macros to produce spans pointing *into their own crate*. This is used by the unstable `proc_macro::quote!` macro, allowing us to get error messages like this: ``` error[E0412]: cannot find type `MissingType` in this scope --> $DIR/auxiliary/span-from-proc-macro.rs:37:20 | LL | pub fn error_from_attribute(_args: TokenStream, _input: TokenStream) -> TokenStream { | ----------------------------------------------------------------------------------- in this expansion of procedural macro `#[error_from_attribute]` ... LL | field: MissingType | ^^^^^^^^^^^ not found in this scope | ::: $DIR/span-from-proc-macro.rs:8:1 | LL | #[error_from_attribute] | ----------------------- in this macro invocation ``` Here, `MissingType` occurs inside the implementation of the proc-macro `#[error_from_attribute]`. Previosuly, this would always result in a span pointing at `#[error_from_attribute]` This will make many proc-macro-related error message much more useful - when a proc-macro generates code containing an error, users will get an error message pointing directly at that code (within the macro definition), instead of always getting a span pointing at the macro invocation site. This is implemented as follows: * When a proc-macro crate is being *compiled*, it causes the `quote!` macro to get run. This saves all of the sapns in the input to `quote!` into the metadata of *the proc-macro-crate* (which we are currently compiling). The `quote!` macro then expands to a call to `proc_macro::Span::recover_proc_macro_span(id)`, where `id` is an opaque identifier for the span in the crate metadata. * When the same proc-macro crate is *run* (e.g. it is loaded from disk and invoked by some consumer crate), the call to `proc_macro::Span::recover_proc_macro_span` causes us to load the span from the proc-macro crate's metadata. The proc-macro then produces a `TokenStream` containing a `Span` pointing into the proc-macro crate itself. The recursive nature of 'quote!' can be difficult to understand at first. The file `src/test/ui/proc-macro/quote-debug.stdout` shows the output of the `quote!` macro, which should make this eaier to understand. This PR also supports custom quoting spans in custom quote macros (e.g. the `quote` crate). All span quoting goes through the `proc_macro::quote_span` method, which can be called by a custom quote macro to perform span quoting. An example of this usage is provided in `src/test/ui/proc-macro/auxiliary/custom-quote.rs` Custom quoting currently has a few limitations: In order to quote a span, we need to generate a call to `proc_macro::Span::recover_proc_macro_span`. However, proc-macros support renaming the `proc_macro` crate, so we can't simply hardcode this path. Previously, the `quote_span` method used the path `crate::Span` - however, this only works when it is called by the builtin `quote!` macro in the same crate. To support being called from arbitrary crates, we need access to the name of the `proc_macro` crate to generate a path. This PR adds an additional argument to `quote_span` to specify the name of the `proc_macro` crate. Howver, this feels kind of hacky, and we may want to change this before stabilizing anything quote-related. Additionally, using `quote_span` currently requires enabling the `proc_macro_internals` feature. The builtin `quote!` macro has an `#[allow_internal_unstable]` attribute, but this won't work for custom quote implementations. This will likely require some additional tricks to apply `allow_internal_unstable` to the span of `proc_macro::Span::recover_proc_macro_span`.
2021-04-29Implement RFC 1260 with feature_name `imported_main`.Charles Lew-1/+34
2021-04-21fix name resolution for param defaultslcnr-50/+8
2021-04-12Rollup merge of #83669 - kwj2104:issue-81508-fix, r=varkorDylan DPC-2/+63
Issue 81508 fix Fix #81508 **Problem**: When variable name is used incorrectly as path, error and warning point to undeclared/unused name, when in fact the name is used, just incorrectly (should be used as a variable, not part of a path). **Summary for fix**: When path resolution errs, diagnostics checks for variables in ```ValueNS``` that have the same name (e.g., variable rather than path named Foo), and adds additional suggestion that user may actually intend to use the variable name rather than a path. The fix does not suppress or otherwise change the *warning* that results. I did not find a straightforward way in the code to modify this, but would love to make changes here as well with any guidance.
2021-04-08Fix outdated crate names in compiler docspierwill-1/+1
Changes `librustc_X` to `rustc_X`, only in documentation comments. Plain code comments are left unchanged. Also fix incorrect file paths.
2021-04-07Added additional comments and minor editsK-43/+61
2021-04-05Use more appropriate return type for `resolve_associated_item`Joshua Nelson-0/+1
Previously, the types looked like this: - None means this is not an associated item (but may be a variant field) - Some(Err) means this is known to be an error. I think the only way that can happen is if it resolved and but you had your own anchor. - Some(Ok(_, None)) was impossible. Now, this returns a nested Option and does the error handling and fiddling with the side channel in the caller. As a side-effect, it also removes duplicate error handling. This has one small change in behavior, which is that `resolve_primitive_associated_item` now goes through `variant_field` if it fails to resolve something. This is not ideal, but since it will be quickly rejected anyway, I think the performance hit is worth the cleanup. This also fixes a bug where struct fields would forget to set the side channel, adds a test for the bug, and ignores `private_intra_doc_links` in rustc_resolve (since it's always documented with --document-private-items).
2021-04-04resolve: Stable order for derive helper attributesVadim Petrochenkov-1/+1
2021-04-04resolve/expand: Cache intermediate results of `#[derive]` expansionVadim Petrochenkov-4/+11
2021-04-01Fixed diagnostic and added test for issue 81508Kevin Jiang-13/+56
2021-03-27Auto merge of #83103 - petrochenkov:unilex, r=Aaron1011bors-131/+63
resolve: Partially unify early and late scope-relative identifier resolution Reuse `early_resolve_ident_in_lexical_scope` instead of a chunk of code in `resolve_ident_in_lexical_scope` doing the same job. `early_resolve_ident_in_lexical_scope`/`visit_scopes` had to be slightly extended to be able to 1) start from a specific module instead of the current parent scope and 2) report one deprecation lint. `early_resolve_ident_in_lexical_scope` still doesn't support walking through "ribs", that part is left in `resolve_ident_in_lexical_scope` (moreover, I'm pretty sure it's buggy, but that's a separate issue, cc https://github.com/rust-lang/rust/issues/52389 at least).
2021-03-27resolve: Partially unify early and late scope-relative ident resolutionVadim Petrochenkov-131/+63
2021-03-26Use iter::zip in compiler/Josh Stone-0/+1
2021-03-23progress, stuff compiles nowlcnr-2/+2
2021-03-23Some refactoringvarkor-5/+9
2021-03-19stabilize or_patternsmark-1/+1
2021-03-12Make def_key and HIR parenting consistent.Camille GILLOT-3/+10
2021-03-07diagnostics: Don't mention external crates when hitting import errors on ↵Manish Goregaokar-1/+3
crate imports in 2018
2021-03-07diagnostics: Differentiate between edition meanings of ::foo in resolve ↵Manish Goregaokar-4/+10
diagnostics (for bare `::foo`)
2021-03-02use outer_expn_data() instead of outer_expn().expn_data()klensy-1/+1
2021-02-25Add a cache for rustc_legacy_const_genericsAmanieu d'Antras-14/+29
2021-02-25Address review commentsAmanieu d'Antras-2/+46
2021-02-23Add #[rustc_legacy_const_generics]Amanieu d'Antras-0/+4
2021-02-18ast: Keep expansion status for out-of-line module itemsVadim Petrochenkov-3/+3
Also remove `ast::Mod` which is mostly redundant now
2021-02-18ast: Stop using `Mod` in `Crate`Vadim Petrochenkov-15/+23
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.