summary refs log tree commit diff
path: root/tests/ui/parser
AgeCommit message (Collapse)AuthorLines
2024-06-07Rollup merge of #125572 - mu001999-contrib:dead/enhance, r=pnkfelixMatthias Krüger-7/+9
Detect pub structs never constructed and unused associated constants <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r​? <reviewer name> --> Lints never constructed public structs. If we don't provide public methods to construct public structs with private fields, and don't construct them in the local crate. They would be never constructed. So that we can detect such public structs. --- Update: Also lints unused associated constants in traits.
2024-06-06Revert "Rollup merge of #124099 - voidc:disallow-ambiguous-expr-attrs, ↵Rémy Rakic-76/+0
r=davidtwco" This reverts commit 57dad1d75e562ff73051c1c43b07eaf65c7dbd74, reversing changes made to 36316df9fe6c3e246153fe6e78967643cf08c148.
2024-06-06Auto merge of #124482 - spastorino:unsafe-extern-blocks, r=oli-obkbors-49/+50
Unsafe extern blocks This implements RFC 3484. Tracking issue #123743 and RFC https://github.com/rust-lang/rfcs/pull/3484 This is better reviewed commit by commit.
2024-06-05Detect pub structs never constructed and unused associated constants in traitsr0cky-7/+9
2024-06-05Add unsafe_extern_blocks feature flagSantiago Pastorino-4/+29
2024-06-04Fail when using safe/unsafe items inside unadorned extern blocksSantiago Pastorino-3/+32
2024-06-04Handle safety keyword for extern block inner itemsSantiago Pastorino-28/+28
2024-06-04Allow using unsafe on functions inside extern blocksSantiago Pastorino-44/+6
2024-06-04Allow unsafe extern on all editionsSantiago Pastorino-23/+8
2024-06-04Auto merge of #123536 - compiler-errors:simplify-int-float, r=lcnrbors-9/+0
Simplify `IntVarValue`/`FloatVarValue` r? `@ghost`
2024-06-04Rollup merge of #125667 - oli-obk:taintify, r=TaKO8KiMichael Goulet-3/+15
Silence follow-up errors directly based on error types and regions During type_of, we used to just return an error type if there were any errors encountered. This is problematic, because it means a struct declared as `struct Foo<'static>` will end up not finding any inherent or trait impls because those impl blocks' `Self` type will be `{type error}` instead of `Foo<'re_error>`. Now it's the latter, silencing nonsensical follow-up errors about `Foo` not having any methods. Unfortunately that now allows for new follow-up errors, because borrowck treats `'re_error` as `'static`, causing nonsensical errors about non-error lifetimes not outliving `'static`. So what I also did was to just strip all outlives bounds that borrowck found, thus never letting it check them. There are probably more nuanced ways to do this, but I worried there would be other nonsensical errors if some outlives bounds were missing. Also from the test changes, it looked like an improvement everywhere.
2024-06-01Auto merge of #125863 - fmease:rej-CVarArgs-in-parse_ty_for_where_clause, ↵bors-2/+23
r=compiler-errors Reject `CVarArgs` in `parse_ty_for_where_clause` Fixes #125847. This regressed in #77035 where the `parse_ty` inside `parse_ty_where_predicate` was replaced with the at the time new `parse_ty_for_where_clause` which incorrectly stated it would permit CVarArgs (maybe a copy/paste error). r? parser
2024-06-01Reject CVarArgs in parse_ty_for_where_clauseLeón Orell Valerian Liehr-2/+23
2024-06-01Simplify IntVarValue/FloatVarValueMichael Goulet-9/+0
2024-05-28Allow type_of to return partially non-error types if the type was already ↵Oli Scherer-3/+15
tainted
2024-05-26Rollup merge of #124048 - veera-sivarajan:bugfix-123773-c23-variadics, ↵Jubilee-85/+35
r=compiler-errors Support C23's Variadics Without a Named Parameter Fixes #123773 This PR removes the static check that disallowed extern functions with ellipsis (varargs) as the only parameter since this is now valid in C23. This will not break any existing code as mentioned in the proposal document: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2975.pdf. Also, adds a doc comment for `check_decl_cvariadic_pos()` and fixes the name of the function (`varadic` -> `variadic`).
2024-04-16Update TestsVeera-85/+35
2024-04-12Rollup merge of #123847 - eggyal:issue-123844, r=fmeaseMatthias Krüger-36/+0
Suppress `let else` suggestion for uninitialized refutable `let`s Fixes #123844 r? `@CAD97`
2024-04-12Suppress erroneous suggestionAlan Egerton-36/+0
The suggestion to use `let else` with an uninitialized refutable `let` statement was erroneous: `let else` cannot be used with deferred initialization.
2024-04-12Rollup merge of #123841 - Kohei316:remove_qualifier_sugg, r=wesleywiserMatthias Krüger-6/+6
Improve diagnostic by suggesting to remove visibility qualifier Resolves #123529 This PR improve diagnostic by suggesting to remove visibility qualifier.
2024-04-12Improve diagnostic by suggesting to remove visibility qualifiermorine0122-6/+6
2024-04-07Remove useless configs in testsUrgau-30/+0
Since they are never set and don't have impact on the test. Or for the cfg-panic tests are already tested with check-cfg.
2024-04-07Unify all the always-false cfgs under the `FALSE` cfgUrgau-9/+9
2024-04-04Fix diagnostic for qualifier in extern blockArthur Carcano-55/+55
Closes: https://github.com/rust-lang/rust/issues/123306
2024-03-26Rollup merge of #122120 - fmease:sugg-assoc-ty-bound-on-eq-bound, ↵Matthias Krüger-7/+12
r=compiler-errors Suggest associated type bounds on problematic associated equality bounds Fixes #105056. TL;DR: Suggest `Trait<Ty: Bound>` on `Trait<Ty = Bound>` in Rust >=2021. ~~Blocked on #122055 (stabilization of `associated_type_bounds`), I'd say.~~ (merged)
2024-03-25Rollup merge of #122910 - compiler-errors:unit-struct-in-path-pat-only, ↵Matthias Krüger-6/+7
r=petrochenkov Validate that we're only matching on unit struct for path pattern Resolution doesn't validate that we only really take `CtorKind::Unit` in path patterns, since all it sees is `Res::SelfCtor(def_id)`. Check this instead during pattern typeck. r? petrochenkov Fixes #122809
2024-03-24Rollup merge of #122217 - estebank:issue-119685, r=fmeaseMatthias Krüger-12/+12
Handle str literals written with `'` lexed as lifetime Given `'hello world'` and `'1 str', provide a structured suggestion for a valid string literal: ``` error[E0762]: unterminated character literal --> $DIR/lex-bad-str-literal-as-char-3.rs:2:26 | LL | println!('hello world'); | ^^^^ | help: if you meant to write a `str` literal, use double quotes | LL | println!("hello world"); | ~ ~ ``` ``` error[E0762]: unterminated character literal --> $DIR/lex-bad-str-literal-as-char-1.rs:2:20 | LL | println!('1 + 1'); | ^^^^ | help: if you meant to write a `str` literal, use double quotes | LL | println!("1 + 1"); | ~ ~ ``` Fix #119685.
2024-03-22Validate that we're only matching on unit struct for path patternMichael Goulet-6/+7
2024-03-23Suggest assoc ty bound on lifetime in eq constraintLeón Orell Valerian Liehr-7/+12
2024-03-22add test for #105210 assertion failure self.lines.iter().all(|r| ↵Matthias Krüger-0/+44
!r.iter().any(|sc| sc.chr == \'\\t\')) with edition 2021 Fixes #105210
2024-03-21Rewrite `parse_meta_item`.Nicholas Nethercote-0/+37
It can't use `maybe_whole`, but it can match `maybe_whole` more closely. Also add a test for a case that wasn't previously covered.
2024-03-19Rollup merge of #122717 - ↵Matthias Krüger-0/+4907
workingjubilee:handle-call-call-call-call-calling-me-maybe, r=compiler-errors Ensure stack before parsing dot-or-call There are many cases where, due to codegen or a massively unruly codebase, a deeply nested `call(call(call(call(call(call(call(call(call(f())))))))))` can happen. This is a spot where it would be good to grow our stack, so that we can survive to tell the programmer their code is dubiously written. Closes https://github.com/rust-lang/rust/issues/122715
2024-03-18Ensure stack before parsing dot-or-callJubilee Young-0/+4907
There are many cases where, due to codegen or a massively unruly codebase, a deeply nested call(call(call(call(call(call(call(call(call(f()))))))))) can happen. This is a spot where it would be good to grow our stack, so that we can survive to tell the programmer their code is dubiously written.
2024-03-19Auto merge of #122055 - compiler-errors:stabilize-atb, r=oli-obkbors-30/+0
Stabilize associated type bounds (RFC 2289) This PR stabilizes associated type bounds, which were laid out in [RFC 2289]. This gives us a shorthand to express nested type bounds that would otherwise need to be expressed with nested `impl Trait` or broken into several `where` clauses. ### What are we stabilizing? We're stabilizing the associated item bounds syntax, which allows us to put bounds in associated type position within other bounds, i.e. `T: Trait<Assoc: Bounds...>`. See [RFC 2289] for motivation. In all position, the associated type bound syntax expands into a set of two (or more) bounds, and never anything else (see "How does this differ[...]" section for more info). Associated type bounds are stabilized in four positions: * **`where` clauses (and APIT)** - This is equivalent to breaking up the bound into two (or more) `where` clauses. For example, `where T: Trait<Assoc: Bound>` is equivalent to `where T: Trait, <T as Trait>::Assoc: Bound`. * **Supertraits** - Similar to above, `trait CopyIterator: Iterator<Item: Copy> {}`. This is almost equivalent to breaking up the bound into two (or more) `where` clauses; however, the bound on the associated item is implied whenever the trait is used. See #112573/#112629. * **Associated type item bounds** - This allows constraining the *nested* rigid projections that are associated with a trait's associated types. e.g. `trait Trait { type Assoc: Trait2<Assoc2: Copy>; }`. * **opaque item bounds (RPIT, TAIT)** - This allows constraining associated types that are associated with the opaque without having to *name* the opaque. For example, `impl Iterator<Item: Copy>` defines an iterator whose item is `Copy` without having to actually name that item bound. The latter three are not expressible in surface Rust (though for associated type item bounds, this will change in #120752, which I don't believe should block this PR), so this does represent a slight expansion of what can be expressed in trait bounds. ### How does this differ from the RFC? Compared to the RFC, the current implementation *always* desugars associated type bounds to sets of `ty::Clause`s internally. Specifically, it does *not* introduce a position-dependent desugaring as laid out in [RFC 2289], and in particular: * It does *not* desugar to anonymous associated items in associated type item bounds. * It does *not* desugar to nested RPITs in RPIT bounds, nor nested TAITs in TAIT bounds. This position-dependent desugaring laid out in the RFC existed simply to side-step limitations of the trait solver, which have mostly been fixed in #120584. The desugaring laid out in the RFC also added unnecessary complication to the design of the feature, and introduces its own limitations to, for example: * Conditionally lowering to nested `impl Trait` in certain positions such as RPIT and TAIT means that we inherit the limitations of RPIT/TAIT, namely lack of support for higher-ranked opaque inference. See this code example: https://github.com/rust-lang/rust/pull/120752#issuecomment-1979412531. * Introducing anonymous associated types makes traits no longer object safe, since anonymous associated types are not nameable, and all associated types must be named in `dyn` types. This last point motivates why this PR is *not* stabilizing support for associated type bounds in `dyn` types, e.g, `dyn Assoc<Item: Bound>`. Why? Because `dyn` types need to have *concrete* types for all associated items, this would necessitate a distinct lowering for associated type bounds, which seems both complicated and unnecessary compared to just requiring the user to write `impl Trait` themselves. See #120719. ### Implementation history: Limited to the significant behavioral changes and fixes and relevant PRs, ping me if I left something out-- * #57428 * #108063 * #110512 * #112629 * #120719 * #120584 Closes #52662 [RFC 2289]: https://rust-lang.github.io/rfcs/2289-associated-type-bounds.html
2024-03-18Provide structured suggestion for `#![feature(foo)]`Esteban Küber-3/+12
``` error: `S2<'_>` is forbidden as the type of a const generic parameter --> $DIR/lifetime-in-const-param.rs:5:23 | LL | struct S<'a, const N: S2>(&'a ()); | ^^ | = note: the only supported types are integers, `bool` and `char` help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types | LL + #![feature(adt_const_params)] | ``` Fix #55941.
2024-03-17review comment: `str` -> string in messagesEsteban Küber-8/+8
2024-03-17Use shorter span for existing `'` -> `"` structured suggestionEsteban Küber-4/+4
2024-03-14Remove unneeded `f16` and `f128` parser testsTrevor Gross-104/+0
Superceded by feature gate tests.
2024-03-12Fix ICE in diagnostics for parenthesized type argumentsDaniel Sedlak-0/+23
2024-03-11Rollup merge of #122152 - wutchzone:120892, r=fmeaseJubilee-0/+76
Improve diagnostics for parenthesized type arguments Fixes #120892 r? fmease
2024-03-09Improve diagnostics for parenthesized type argumentsDaniel Sedlak-0/+76
2024-03-09Rollup merge of #122160 - jieyouxu:eager-translate-help-use-latest-edition, ↵Matthias Krüger-0/+26
r=cjgillot Eagerly translate `HelpUseLatestEdition` in parser diagnostics Fixes #122130. This makes me suspicious of these other two usage of `add_to_diagnostic()`. Would they *also* crash? I haven't attempted to construct test cases for them. ``` compiler/rustc_parse/src/parser/expr.rs 3453: errors::HelpUseLatestEdition::new().add_to_diagnostic(e); compiler/rustc_hir_typeck/src/expr.rs 2603: HelpUseLatestEdition::new().add_to_diagnostic(&mut err); ``` This also seems like a footgun?
2024-03-08Stabilize associated type boundsMichael Goulet-30/+0
2024-03-07Eagerly translate HelpUseLatestEdition in parser diagnostics许杰友 Jieyou Xu (Joe)-0/+26
2024-03-07Rollup merge of #122004 - fmease:astvalidator-min-fix, r=compiler-errorsGuillaume Gomez-0/+72
AST validation: Improve handling of inherent impls nested within functions and anon consts Minimal fix for issue #121607 extracted from PR #120698 for ease of backporting and since I'd like to improve PR #120698 in such a way that it makes AST validator truly robust against such sort of regressions (AST validator is generally *beyond* footgun-y atm). The current version of PR #120698 sort of does that already but there's still room for improvement. Fixes #89342. Fixes [after beta-backport] #121607. Partially addresses #119924 (#120698 aims to fully fix it). --- ### Explainer The last commit of PR #119505 regressed issue #121607. Previously we would reject visibilities on associated items with `visibility_not_permitted` if we were in a trait (by checking the parameter `ctxt` of `visit_assoc_item` which was 100% accurate) or if we were in a trait impl (by checking a flag called `in_trait_impl` tracked in `AstValidator` which was/is only accurate if the visitor methods correctly updated it which isn't actually the case giving rise to the old open issue #89342). In PR #119505, I moved even more state into the `AstValidator` by generalizing the flag `in_trait_impl` to `trait_or_trait_impl` to be able to report more precise diagnostics (modeling *Trait | TraitImpl*). However since we/I didn't update `trait_or_trait_impl` in all places to reflect reality (similar to us not updating `in_trait_impl` before), this lead to https://github.com/rust-lang/rust/issues/121607#issuecomment-1963084636 getting wrongfully rejected. Since PR #119505 we reject visibilities if the “globally tracked” (wrt. to `AstValidator`) `outer_trait_or_trait_impl` is `Some`. Crucially, when visiting an inherent impl, I never reset `outer_trait_or_trait_impl` back to `None` leading us to believe that `bar` in the stack [`trait Foo` > `fn foo` > `impl Bar` > `pub fn bar`] (from the MCVE) was an inherent associated item (we saw `trait Foo` but not `impl Bar` before it). The old open issue #89342 is caused by the aforementioned issue of us never updating `in_trait_impl` prior to my PR #119505 / `outer_trait_or_trait` after my PR. Stack: [`impl Default for Foo` > `{` > `impl Foo` > `pub const X`] (we only saw `impl Default for Foo` but not the `impl Foo` before it). --- This PR is only meant to be a *hot fix*. I plan on completely *rewriting* `AstValidator` from the ground up to not rely on “globally tracked” state like this or at least make it close to impossible to forget updating it when descending into nested items (etc.). Other visitors do a way better job at that (e.g. AST lowering). I actually plan on experimenting with moving more and more logic from `AstValidator` into the AST lowering pass/stage/visitor to follow the [Parse, don't validate](https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/) “pattern”. --- r? `@compiler-errors`
2024-03-07Rollup merge of #122115 - clubby789:cancel-recoverr, r=compiler-errorsGuillaume Gomez-2/+17
Cancel parsing ever made during recovery Fixes #122112 It would be nice if diagnostics from recovery were automatically cancelled... 🤔
2024-03-07Merge `check_mod_impl_wf` and `check_mod_type_wf`Oli Scherer-9/+9
2024-03-06Cancel parsing ever made during recoveryclubby789-2/+17
2024-03-05AST validation: Improve handling of inherent impls nested within functions ↵León Orell Valerian Liehr-0/+72
and anon consts
2024-03-02Auto merge of #121657 - estebank:issue-119665, r=davidtwcobors-21/+37
Detect more cases of `=` to `:` typo When a `Local` is fully parsed, but not followed by a `;`, keep the `:` span arround and mention it. If the type could continue being parsed as an expression, suggest replacing the `:` with a `=`. ``` error: expected one of `!`, `+`, `->`, `::`, `;`, or `=`, found `.` --> file.rs:2:32 | 2 | let _: std::env::temp_dir().join("foo"); | - ^ expected one of `!`, `+`, `->`, `::`, `;`, or `=` | | | while parsing the type for `_` | help: use `=` if you meant to assign ``` Fix #119665.