about summary refs log tree commit diff
path: root/compiler/rustc_hir_analysis/src/astconv
AgeCommit message (Collapse)AuthorLines
2023-12-23Give `DiagnosticBuilder` a default type.Nicholas Nethercote-1/+1
`IntoDiagnostic` defaults to `ErrorGuaranteed`, because errors are the most common diagnostic level. It makes sense to do likewise for the closely-related (and much more widely used) `DiagnosticBuilder` type, letting us write `DiagnosticBuilder<'a, ErrorGuaranteed>` as just `DiagnosticBuilder<'a>`. This cuts over 200 lines of code due to many multi-line things becoming single line things.
2023-12-19effects: fix commentLeón Orell Valerian Liehr-1/+1
2023-12-15Rollup merge of #118727 - compiler-errors:lint-decorate, r=WaffleLapkinJubilee-4/+1
Don't pass lint back out of lint decorator Change the decorator function in the signature of the `emit_lint`/`span_lint`/etc family of methods from `impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>) -> &'b mut DiagnosticBuilder<'a, ()>` to `impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>)`. I consider it easier to read this way, especially when there's control flow involved. r? nnethercote though feel free to reassign
2023-12-15Rollup merge of #118396 - compiler-errors:ast-lang-items, r=cjgillotJubilee-121/+35
Collect lang items from AST, get rid of `GenericBound::LangItemTrait` r? `@cjgillot` cc #115178 Looking forward, the work to remove `QPath::LangItem` will also be significantly more difficult, but I plan on doing it as well. Specifically, we have to change: 1. A lot of `rustc_ast_lowering` for things like expr `..` 2. A lot of astconv, since we actually instantiate lang and non-lang paths quite differently. 3. A ton of diagnostics and clippy lints that are special-cased via `QPath::LangItem` Meanwhile, it was pretty easy to remove `GenericBound::LangItemTrait`, so I just did that here.
2023-12-15Simplify instantiate_poly_trait_refMichael Goulet-75/+35
2023-12-15banish hir::GenericBound::LangItemTraitMichael Goulet-47/+1
2023-12-15Don't pass lint back out of lint decoratorMichael Goulet-4/+1
2023-12-15Annotate some bugsMichael Goulet-5/+19
2023-12-12Move some methods from `tcx.hir()` to `tcx`zetanumbers-2/+2
Renamings: - find -> opt_hir_node - get -> hir_node - find_by_def_id -> opt_hir_node_by_def_id - get_by_def_id -> hir_node_by_def_id Fix rebase changes using removed methods Use `tcx.hir_node_by_def_id()` whenever possible in compiler Fix clippy errors Fix compiler Apply suggestions from code review Co-authored-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com> Add FIXME for `tcx.hir()` returned type about its removal Simplify with with `tcx.hir_node_by_def_id`
2023-12-07Resolve assoc item bindings by namespaceLeón Orell Valerian Liehr-295/+264
If a const is expected, resolve a const. If a type is expected, resolve a type. Don't try to resolve a type first falling back to consts.
2023-12-06Auto merge of #117661 - TheLazyDutchman:point_out_shadowed_associated_types, ↵bors-4/+58
r=petrochenkov Added shadowed hint for overlapping associated types Previously, when you tried to set an associated type that is shadowed by an associated type in a subtrait, like this: ```rust trait A { type X; } trait B: A { type X; // note: this is legal } impl<Y> Clone for Box<dyn B<X=Y, X=Y>> { fn clone(&self) -> Self { todo!() } } you got a confusing error message, that says nothing about the shadowing: error[E0719]: the value of the associated type `X` (from trait `B`) is already specified --> test.rs:9:34 | 9 | impl<Y> Clone for Box<dyn B<X=Y, X=Y>> { | --- ^^^ re-bound here | | | `X` bound here first error[E0191]: the value of the associated type `X` (from trait `A`) must be specified --> test.rs:9:27 | 2 | type X; | ------ `X` defined here ... 9 | impl<Y> Clone for Box<dyn B<X=Y, X=Y>> { | ^^^^^^^^^^^ help: specify the associated type: `B<X=Y, X=Y, X = Type>` error: aborting due to 2 previous errors Some errors have detailed explanations: E0191, E0719. For more information about an error, try `rustc --explain E0191`. ``` Now instead, the error shows that the associated type is shadowed, and suggests renaming as a potential fix. ```rust error[E0719]: the value of the associated type `X` in trait `B` is already specified --> test.rs:9:34 | 9 | impl<Y> Clone for Box<dyn B<X=Y, X=Y>> { | --- ^^^ re-bound here | | | `X` bound here first error[E0191]: the value of the associated type `X` in `A` must be specified --> test.rs:9:27 | 2 | type X; | ------ `A::X` defined here ... 6 | type X; // note: this is legal | ------ `A::X` shadowed here ... 9 | impl<Y> Clone for Box<dyn B<X=Y, X=Y>> { | ^^^^^^^^^^^ associated type `X` must be specified | help: consider renaming this associated type --> test.rs:2:5 | 2 | type X; | ^^^^^^ help: consider renaming this associated type --> test.rs:6:5 | 6 | type X; // note: this is legal | ^^^^^^ ``` error: aborting due to 2 previous errors Some errors have detailed explanations: E0191, E0719. For more information about an error, try `rustc --explain E0191`. The rename help message is only emitted when the trait is local. This is true both for the supertrait as for the subtrait. There might be cases where you can use the fully qualified path (for instance, in a where clause), but this PR currently does not deal with that. fixes #100109 (continues from #117642, because I didn't know renaming the branch would close the PR)
2023-12-06Point out shadowed associated typesTheLazyDutchman-4/+58
Shadowing the associated type of a supertrait is allowed. This however makes it impossible to set the associated type of the supertrait in a dyn object. This PR makes the error message for that case clearer, like adding a note that shadowing is happening, as well as suggesting renaming of one of the associated types. r=petrochenckov
2023-12-05Rollup merge of #118268 - compiler-errors:pretty-print, r=estebankMichael Goulet-4/+2
Pretty print `Fn<(..., ...)>` trait refs with parentheses (almost) always It's almost always better, at least in diagnostics, to print `Fn(i32, u32)` instead of `Fn<(i32, u32)>`. Related to but doesn't fix #118225. That needs a separate fix.
2023-12-05Add print_trait_sugaredMichael Goulet-4/+2
2023-12-04Use default params until effects in desugaringDeadbeef-0/+25
2023-12-02Rename `HandlerInner::delay_span_bug` as `HandlerInner::span_delayed_bug`.Nicholas Nethercote-6/+7
Because the corresponding `Level` is `DelayedBug` and `span_delayed_bug` follows the pattern used everywhere else: `span_err`, `span_warning`, etc.
2023-11-27Auto merge of #118118 - spastorino:do-not-erase-late-bound-regions-on-iat, ↵bors-115/+92
r=compiler-errors Do not erase late bound regions when selecting inherent associated types In the fix for #97156 we would want the following code: ```rust #![feature(inherent_associated_types)] #![allow(incomplete_features)] struct Foo<T>(T); impl Foo<fn(&'static ())> { type Assoc = u32; } trait Other {} impl Other for u32 {} // FIXME(inherent_associated_types): Avoid emitting two diagnostics (they only differ in span). // FIXME(inherent_associated_types): Enhancement: Spruce up the diagnostic by saying something like // "implementation is not general enough" as is done for traits via // `try_report_trait_placeholder_mismatch`. fn bar(_: Foo<for<'a> fn(&'a ())>::Assoc) {} //~^ ERROR mismatched types //~| ERROR mismatched types fn main() {} ``` to fail with ... ``` error[E0220]: associated type `Assoc` not found for `Foo<for<'a> fn(&'a ())>` in the current scope --> tests/ui/associated-inherent-types/issue-109789.rs:18:36 | 4 | struct Foo<T>(T); | ------------- associated item `Assoc` not found for this struct ... 18 | fn bar(_: Foo<for<'a> fn(&'a ())>::Assoc) {} | ^^^^^ associated item not found in `Foo<for<'a> fn(&'a ())>` | = note: the associated type was found for - `Foo<fn(&'static ())>` error: aborting due to previous error For more information about this error, try `rustc --explain E0220`. ``` This PR fixes the ICE we are currently getting "was a subtype of Foo<Binder(fn(&ReStatic ()), [])> during selection but now it is not" Also fixes #112631 r? `@lcnr`
2023-11-26rustc: `hir().local_def_id_to_hir_id()` -> `tcx.local_def_id_to_hir_id()` ↵Vadim Petrochenkov-3/+3
cleanup
2023-11-25Get rid of infer vars in inherent assoc types selection by using probeSantiago Pastorino-47/+34
2023-11-25Extract select_inherent_assoc_type_candidatesSantiago Pastorino-79/+95
2023-11-25Do not erase late bound regions, replace them with placeholdersSantiago Pastorino-114/+88
2023-11-25Remove HirId from QPath::LangItemMichael Goulet-1/+1
2023-11-24We should call eq instead of sup as we're relating Ty directly and not ↵Santiago Pastorino-4/+1
Binder<TraitRef>
2023-11-21Fix `clippy::needless_borrow` in the compilerNilstrieb-5/+5
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`. Then I had to remove a few unnecessary parens and muts that were exposed now.
2023-11-19Rollup merge of #117828 - Nilstrieb:astconv-hashmaps, r=petrochenkovMichael Goulet-10/+6
Avoid iterating over hashmaps in astconv
2023-11-19Don't sort `span_suggestions`, leave that to callerEsteban Küber-1/+5
2023-11-19Avoid iterating over hashmaps in astconvNilstrieb-10/+6
2023-11-15Re-format code with new rustfmtMark Rousskov-17/+13
2023-11-14finish `RegionKind` renamelcnr-2/+2
- `ReFree` -> `ReLateParam` - `ReEarlyBound` -> `ReEarlyParam`
2023-11-13Auto merge of #117881 - TaKO8Ki:rollup-n7jtmgj, r=TaKO8Kibors-2/+1
Rollup of 5 pull requests Successful merges: - #117737 (Remove `-Zkeep-hygiene-data`.) - #117830 (Small improvements in object lifetime default code) - #117858 (Compute layout with spans for better cycle errors in coroutines) - #117863 (Remove some unused stuff from `rustc_index`) - #117872 (Cranelift isn't available on non-nightly channels) r? `@ghost` `@rustbot` modify labels: rollup
2023-11-13rename `ReLateBound` to `ReBound`lcnr-3/+5
other changes: - `Region::new_late_bound` -> `Region::new_bound` - `Region::is_late_bound` -> `Region::is_bound`
2023-11-12Small improvements in object lifetime default codeNilstrieb-2/+1
I found those while trying to understand how the code works.
2023-10-30Auto merge of #116405 - estebank:issue-103155, r=davidtwcobors-9/+40
Detect object safety errors when assoc type is missing When an associated type with GATs isn't specified in a `dyn Trait`, emit an object safety error instead of only complaining about the missing associated type, as it will lead the user down a path of three different errors before letting them know that what they were trying to do is impossible to begin with. Fix #103155.
2023-10-30Sort errorsEsteban Küber-4/+6
2023-10-30Detect object safety errors when assoc type is missingEsteban Küber-10/+39
When an associated type with GATs isn't specified in a `dyn Trait`, emit an object safety error instead of only complaining about the missing associated type, as it will lead the user down a path of three different errors before letting them know that what they were trying to do is impossible to begin with. Fix #103155.
2023-10-30Improve some diagnostics around `?Trait` boundsOli Scherer-26/+31
2023-10-26Deny providing explicit effect paramsDeadbeef-3/+13
2023-10-18AliasTy::new instead of tcx methodlcnr-4/+4
2023-10-17Unify suggestion wordingEsteban Küber-2/+2
2023-10-17Auto merge of #116756 - fee1-dead-contrib:dupe-those-bounds, r=oli-obkbors-1/+33
Duplicate `~const` bounds with a non-const one in effects desugaring This should unblock #116058. r? `@oli-obk`
2023-10-16Rollup merge of #116257 - estebank:issue-101351, r=b-naberMatthias Krüger-15/+63
Suggest trait bounds for used associated type on type param Fix #101351. When an associated type on a type parameter is used, and the type parameter isn't constrained by the correct trait, suggest the appropriate trait bound: ``` error[E0220]: associated type `Associated` not found for `T` --> file.rs:6:15 | 6 | field: T::Associated, | ^^^^^^^^^^ there is a similarly named associated type `Associated` in the trait `Foo` | help: consider restricting type parameter `T` | 5 | struct Generic<T: Foo> { | +++++ ``` When an associated type on a type parameter has a typo, suggest fixing it: ``` error[E0220]: associated type `Baa` not found for `T` --> $DIR/issue-55673.rs:9:8 | LL | T::Baa: std::fmt::Debug, | ^^^ there is a similarly named associated type `Bar` in the trait `Foo` | help: change the associated type name to use `Bar` from `Foo` | LL | T::Bar: std::fmt::Debug, | ~~~ ```
2023-10-15Duplicate `~const` bounds with a non-const one in effects desugaringDeadbeef-1/+33
2023-10-13Tweak wordingEsteban Küber-1/+2
2023-10-13Suggest trait bounds for used associated type on type paramEsteban Küber-15/+62
Fix #101351. When an associated type on a type parameter is used, and the type parameter isn't constrained by the correct trait, suggest the appropriate trait bound: ``` error[E0220]: associated type `Associated` not found for `T` --> file.rs:6:15 | 6 | field: T::Associated, | ^^^^^^^^^^ there is a similarly named associated type `Associated` in the trait `Foo` | help: consider restricting type parameter `T` | 5 | struct Generic<T: Foo> { | +++++ ``` When an associated type on a type parameter has a typo, suggest fixing it: ``` error[E0220]: associated type `Baa` not found for `T` --> $DIR/issue-55673.rs:9:8 | LL | T::Baa: std::fmt::Debug, | ^^^ there is a similarly named associated type `Bar` in the trait `Foo` | help: change the associated type name to use `Bar` from `Foo` | LL | T::Bar: std::fmt::Debug, | ~~~ ```
2023-10-13Format all the let chains in compilerMichael Goulet-22/+41
2023-10-09Fix suggestion span involving wrongly placed generic arg on enum variantsGurinder Singh-3/+5
When the variant and the (wrongly placed) args are at separate source locations such as being in different macos or one in a macro and the other somwhere outside of it, the arg spans we computed spanned the entire distance between such locations and were hence invalid. .
2023-09-27Auto merge of #116163 - compiler-errors:lazyness, r=oli-obkbors-12/+5
Don't store lazyness in `DefKind::TyAlias` 1. Don't store lazyness of a type alias in its `DefKind`, but instead via a query. 2. This allows us to treat type aliases as lazy if `#[feature(lazy_type_alias)]` *OR* if the alias contains a TAIT, rather than having checks for both in separate parts of the codebase. r? `@oli-obk` cc `@fmease`
2023-09-26subst -> instantiatelcnr-11/+12
2023-09-26Don't store lazyness in DefKindMichael Goulet-12/+5
2023-09-24Remove span from BrAnon.Camille GILLOT-2/+2