about summary refs log tree commit diff
path: root/tests/ui/trait-bounds
AgeCommit message (Collapse)AuthorLines
2025-09-13Rollup merge of #145896 - Oneirical:uncountable-integer-10, r=jieyouxuJacob Pratt-0/+16
Rehome 30 `tests/ui/issues/` tests to other subdirectories under `tests/ui/` [#3 of Batch #2] Part of rust-lang/rust#133895 Methodology: 1. Refer to the previously written `tests/ui/SUMMARY.md` 2. Find an appropriate category for the test, using the original issue thread and the test contents. 3. Add the issue URL at the bottom (not at the top, as that would mess up stderr line numbers) 4. Rename the tests to make their purpose clearer Inspired by the methodology that `@Kivooeo` was using. r? `@jieyouxu`
2025-09-12Add test batch 3Oneirical-0/+16
2025-09-10Permit `more_maybe_bounds` in supertraits and trait objects onlyBryanskiy-1/+45
2025-08-22On E0277, point at type that doesn't implement boundEsteban Küber-1/+6
When encountering an unmet trait bound, point at local type that doesn't implement the trait: ``` error[E0277]: the trait bound `Bar<T>: Foo` is not satisfied --> $DIR/issue-64855.rs:9:19 | LL | pub struct Bar<T>(<Self as Foo>::Type) where Self: ; | ^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound | help: the trait `Foo` is not implemented for `Bar<T>` --> $DIR/issue-64855.rs:9:1 | LL | pub struct Bar<T>(<Self as Foo>::Type) where Self: ; | ^^^^^^^^^^^^^^^^^ ```
2025-08-21Rollup merge of #145642 - xizheyin:145611, r=lcnrJacob Pratt-0/+31
Do not use effective_visibilities query for Adt types of a local trait while proving a where-clause Partially fix rust-lang/rust#145611, but we should do something make cycle in this situation ICE. Instead of using a query, call `&tcx.resolutions(()).effective_visibilities`. r? `````@lcnr````` cc `````@compiler-errors`````
2025-08-20Do not use effective_visibilities query for Adt types of a local trait while ↵xizheyin-0/+31
proving a where-clause Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-08-17Rehome tests/ui/issues/ tests [5/?]Oneirical-0/+68
2025-08-11Rollup merge of #135331 - fmease:ban-assoc-ty-unbounds, r=lcnrStuart Cook-5/+9
Reject relaxed bounds inside associated type bounds (ATB) **Reject** relaxed bounds — most notably `?Sized` — inside associated type bounds `TraitRef<AssocTy: …>`. This was previously accepted without warning despite being incorrect: ATBs are *not* a place where we perform *sized elaboration*, meaning `TraitRef<AssocTy: …>` does *not* elaborate to `TraitRef<AssocTy: Sized + …>` if `…` doesn't contain `?Sized`. Therefore `?Sized` is meaningless. In no other (stable) place do we (intentionally) allow relaxed bounds where we don't also perform sized elab, this is highly inconsistent and confusing! Another point of comparison: For the desugared `$SelfTy: TraitRef, $SelfTy::AssocTy: …` we don't do sized elab either (and thus also don't allow relaxed bounds). Moreover — as I've alluded to back in https://github.com/rust-lang/rust/pull/135841#pullrequestreview-2619462717 — some later validation steps only happen during sized elaboration during HIR ty lowering[^1]. Namely, rejecting duplicates (e.g., `?Trait + ?Trait`) and ensuring that `Trait` in `?Trait` is equal to `Sized`[^2]. As you can probably guess, on stable/master we don't run these checks for ATBs (so we allow even more nonsensical bounds like `Iterator<Item: ?Copy>` despite T-types's ruling established in the FCP'ed rust-lang/rust#135841). This PR rectifies all of this. I cratered this back in 2025-01-10 with (allegedly) no regressions found ([report](https://github.com/rust-lang/rust/pull/135331#issuecomment-2585330783), [its analysis](https://github.com/rust-lang/rust/pull/135331#issuecomment-2585356422)). [However a contributor manually found two occurrences](https://github.com/rust-lang/rust/issues/135229#issuecomment-2581832852) of `TraitRef<AssocTy: ?Sized>` in small hobby projects (presumably via GH code search). I immediately sent downstream PRs: https://github.com/Gui-Yom/turbo-metrics/pull/14, https://github.com/ireina7/summon/pull/1 (however, the owners have showed no reaction so far). I'm leaning towards banning these forms **without a FCW** because a FCW isn't worth the maintenance cost[^3]. Note that associated type bounds were stabilized in 1.79.0 (released 2024-06-13 which is 13 months ago), so the proliferation of ATBs shouldn't be that high yet. If you think we should do another crater run since the last one was 6 months ago, I'm fine with that. Fixes rust-lang/rust#135229. [^1]: I consider this a flaw in the implementation and [I've already added a huge FIXME](https://github.com/rust-lang/rust/blob/82a02aefe07092c737c852daccebf49ca25507e3/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs#L195-L207). [^2]: To be more precise, if the internal flag `-Zexperimental-default-bounds` is provided other "default traits" (needs internal feature `lang_items`) are permitted as well (cc closely related internal feature: `more_maybe_bounds`). [^3]: Having to track this and adding an entire lint whose remnants would remain in the code base forever (we never *fully* remove lints).
2025-08-08Rollup merge of #144400 - Kivooeo:issue3, r=jieyouxuStuart Cook-0/+11
`tests/ui/issues/`: The Issues Strike Back [3/N] Some `tests/ui/issues/` housekeeping, to trim down number of tests directly under `tests/ui/issues/`. Part of https://github.com/rust-lang/rust/issues/133895. r? ```@jieyouxu```
2025-08-05commentsKivooeo-0/+2
2025-08-05moved 35 tests to organized locationsKivooeo-0/+9
2025-08-04Rehome tests/ui/issues/ tests [3/?]Oneirical-0/+29
2025-07-24Rehome tests/ui/issues/ tests [1/?]Oneirical-0/+16
2025-07-20Reject relaxed bounds inside associated type boundsLeón Orell Valerian Liehr-5/+9
2025-07-18Don't reject *multiple* relaxed bounds, reject *duplicate* ones.León Orell Valerian Liehr-34/+102
Having multiple relaxed bounds like `?Sized + ?Iterator` is actually *fine*. We actually want to reject *duplicate* relaxed bounds like `?Sized + ?Sized` because these most certainly represent a user error. Note that this doesn't mean that we accept more code because a bound like `?Iterator` is still invalid as it's not relaxing a *default* trait and the only way to define / use more default bounds is under the experimental and internal feature `more_maybe_bounds` plus `lang_items` plus unstable flag `-Zexperimental-default-bounds` (historical context: for the longest time, bounds like `?Iterator` were actually allowed and lead to a hard warning). Ultimately, this simply *reframes* the diagnostic. The scope of `more_maybe_bounds` / `-Zexperimental-default-bounds` remains unchanged as well.
2025-07-18Reword diagnostic about relaxing non-`Sized` boundLeón Orell Valerian Liehr-6/+55
* The phrasing "only does something for" made sense back when this diagnostic was a (hard) warning. Now however, it's simply a hard error and thus completely rules out "doing something". * The primary message was way too long * The new wording more closely mirrors the wording we use for applying other bound modifiers (like `const` and `async`) to incompatible traits. * "all other traits are not bound by default" is no longer accurate under Sized Hierarchy. E.g., traits and assoc tys are (currently) bounded by `MetaSized` by default but can't be relaxed using `?MetaSized` (instead, you relax it by adding `PointeeSized`). * I've decided against adding any diagnositic notes or suggestions for now like "trait `Trait` can't be relaxed as it's not bound by default" which would be incorrect for `MetaSized` and assoc tys as mentioned above) or "consider changing `?MetaSized` to `PointeeSized`" as the Sized Hierarchy impl is still WIP)
2025-07-07Point to correct argument in Func Call when Self type fails trait boundxizheyin-4/+4
When a trait bound fails due to the Self type parameter, adjust_fulfillment_errors now correctly points to the corresponding function argument instead of incorrectly pointing to other arguments. Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-07-07Add test tests/ui/trait-bounds/false-span-in-trait-bound-label.rsxizheyin-0/+27
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-06-05Add more missing 2015 edition directivesLukas Wirth-1/+3
2025-05-07Better error message for late/early lifetime param mismatchMichael Goulet-13/+40
2025-04-08Improve presentation of closure signature mismatch from Fn trait goalMichael Goulet-4/+4
2025-03-03Tweak error code for sized checks of const/staticMichael Goulet-0/+1
2025-02-11Reject `impl Trait` bounds in various places where we unconditionally warned ↵Oli Scherer-8/+8
since 1.0
2025-02-10Show diff suggestion format on verbose replacementEsteban Küber-2/+3
``` error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> $DIR/attempted-access-non-fatal.rs:7:15 | LL | let _ = 2.l; | ^ | help: if intended to be a floating point literal, consider adding a `0` after the period and a `f64` suffix | LL - let _ = 2.l; LL + let _ = 2.0f64; | ```
2025-02-05Rollup merge of #136536 - DuskyElf:master, r=jieyouxu许杰友 Jieyou Xu (Joe)-0/+72
Rename and Move some UI tests to more suitable subdirs ## Affected Tests - tests/ui/issues/issue-48838.rs -> tests/ui/enum/closure-in-enum-issue-48838.rs https://github.com/rust-lang/rust/issues/48838 - tests/ui/issues/issue-40350.rs -> tests/ui/enum/enum-inside-enum-issue-40350.rs https://github.com/rust-lang/rust/issues/40350 - tests/ui/issues/issue-41272.rs -> tests/ui/expr/if/if-let-no-match-guards-issue-41272.rs https://github.com/rust-lang/rust/issues/41272 - tests/ui/issues/issue-40408.rs -> tests/ui/lexer/floating-point-0e10-issue-40408.rs https://github.com/rust-lang/rust/issues/40408 - tests/ui/issues/issue-40136.rs -> tests/ui/macros/const-expr-invocations-issue-40136.rs https://github.com/rust-lang/rust/issues/40136 - tests/ui/issues/issue-40845.rs -> tests/ui/macros/macros-in-trait-positions-issue-40845.rs https://github.com/rust-lang/rust/issues/40845 - tests/ui/issues/issue-41213.rs -> tests/ui/match/enum-and-break-in-match-issue-41213.rs https://github.com/rust-lang/rust/issues/41213 - tests/ui/issues/issue-40782.rs -> tests/ui/suggestions/for-loop-missing-in.rs https://github.com/rust-lang/rust/issues/40782 - tests/ui/issues/issue-40827.rs -> tests/ui/trait-bounds/deep-level-Send-bound-check-issue-40827.rs https://github.com/rust-lang/rust/issues/40827 - tests/ui/issues/issue-40610.rs -> tests/ui/typeck/coercion-check-for-addition-issue-40610.rs https://github.com/rust-lang/rust/issues/40610 - tests/ui/issues/issue-40883.rs -> tests/ui/codegen/StackColoring-not-blowup-stack-issue-40883.rs https://github.com/rust-lang/rust/issues/40883 - tests/ui/issues/issue-40861.rs -> tests/ui/typeck/coercion-check-for-indexing-expression-issue-40861.rs https://github.com/rust-lang/rust/issues/40861 - tests/ui/issues/issue-41139.rs -> tests/ui/typeck/unsized-rvalue-issue-41139.rs https://github.com/rust-lang/rust/issues/41139 - tests/ui/issues/issue-40749.rs -> tests/ui/wf/range-expr-root-of-constant-issue-40749.rs https://github.com/rust-lang/rust/issues/40749 - tests/ui/issues/issue-40235.rs -> tests/ui/while/while-let-scope-issue-40235.rs https://github.com/rust-lang/rust/issues/40235
2025-02-04Rename and Move some UI tests to more suitable subdirsDuskyElf-0/+72
2025-02-03Check Sizedness of return type in WFMichael Goulet-13/+3
2024-12-07Tweak wordingEsteban Küber-1/+1
2024-12-07Do not talk about "trait `<Foo = Bar>`"Esteban Küber-1/+1
Pass in an appropriate `Option<DefId>` in more cases from hir ty lowering.
2024-12-07Use trait name instead of full constraint in suggestion messageEsteban Küber-1/+1
``` help: consider restricting type parameter `T` with traits `Copy` and `Trait` | LL | fn duplicate_custom<T: Copy + Trait>(t: S<T>) -> (S<T>, S<T>) { | ++++++++++++++ ``` ``` help: consider restricting type parameter `V` with trait `Copy` | LL | fn index<'a, K, V: std::marker::Copy>(map: &'a HashMap<K, V>, k: K) -> &'a V { | +++++++++++++++++++ ```
2024-12-07Add test for lack of suggestion in stableEsteban Küber-4/+21
This test will break when `Step` gets stabilized, but punt until then.
2024-12-07reword trait bound suggestion message to include the boundsEsteban Küber-3/+3
2024-12-07Don't suggest restricting bound with unstable traits on stableEsteban Küber-0/+36
On nightly, we mention the trait is unstable ``` error[E0277]: the trait bound `T: Unstable` is not satisfied --> $DIR/unstable-trait-suggestion.rs:13:9 | LL | foo(t) | --- ^ the trait `Unstable` is not implemented for `T` | | | required by a bound introduced by this call | note: required by a bound in `foo` --> $DIR/unstable-trait-suggestion.rs:9:11 | LL | fn foo<T: Unstable>(_: T) {} | ^^^^^^^^ required by this bound in `foo` help: consider restricting type parameter `T` but it is an `unstable` trait | LL | pub fn demo<T: Unstable>(t: T) { | ++++++++++ ``` On stable, we don't suggest the trait at all ``` error[E0277]: the trait bound `T: Unstable` is not satisfied --> $DIR/unstable-trait-suggestion.rs:13:9 | LL | foo(t) | --- ^ the trait `Unstable` is not implemented for `T` | | | required by a bound introduced by this call | note: required by a bound in `foo` --> $DIR/unstable-trait-suggestion.rs:9:11 | LL | fn foo<T: Unstable>(_: T) {} | ^^^^^^^^ required by this bound in `foo` ```
2024-11-20Store resolution for self and crate root module segmentsMichael Goulet-3/+3
2024-10-31Validate associated type bounds on ?Michael Goulet-0/+33
2024-10-30Actually do validation for poly trait refs with ? modifierMichael Goulet-0/+39
2024-10-29Remove detail from label/note that is already available in other noteEsteban Küber-2/+2
Remove the "which is required by `{root_obligation}`" post-script in "the trait `X` is not implemented for `Y`" explanation in E0277. This information is already conveyed in the notes explaining requirements, making it redundant while making the text (particularly in labels) harder to read. ``` error[E0277]: the trait bound `NotCopy: Copy` is not satisfied --> $DIR/wf-static-type.rs:10:13 | LL | static FOO: IsCopy<Option<NotCopy>> = IsCopy { t: None }; | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `NotCopy` | = note: required for `Option<NotCopy>` to implement `Copy` note: required by a bound in `IsCopy` --> $DIR/wf-static-type.rs:7:17 | LL | struct IsCopy<T:Copy> { t: T } | ^^^^ required by this bound in `IsCopy` ``` vs the prior ``` error[E0277]: the trait bound `NotCopy: Copy` is not satisfied --> $DIR/wf-static-type.rs:10:13 | LL | static FOO: IsCopy<Option<NotCopy>> = IsCopy { t: None }; | ^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `NotCopy`, which is required by `Option<NotCopy>: Copy` | = note: required for `Option<NotCopy>` to implement `Copy` note: required by a bound in `IsCopy` --> $DIR/wf-static-type.rs:7:17 | LL | struct IsCopy<T:Copy> { t: T } | ^^^^ required by this bound in `IsCopy` ```
2024-09-27On implicit `Sized` bound on fn argument, point at type instead of patternEsteban Küber-32/+38
Instead of ``` error[E0277]: the size for values of type `(dyn ThriftService<(), AssocType = _> + 'static)` cannot be known at compilation time --> $DIR/issue-59324.rs:23:20 | LL | fn with_factory<H>(factory: dyn ThriftService<()>) {} | ^^^^^^^ doesn't have a size known at compile-time ``` output ``` error[E0277]: the size for values of type `(dyn ThriftService<(), AssocType = _> + 'static)` cannot be known at compilation time --> $DIR/issue-59324.rs:23:29 | LL | fn with_factory<H>(factory: dyn ThriftService<()>) {} | ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time ```
2024-07-14Fix malformed suggestion for repeated maybe unsized boundsGurinder Singh-0/+231
2024-03-22Rollup merge of #122195 - jieyouxu:impl-return-note, r=fmeaseMatthias Krüger-0/+1
Note that the caller chooses a type for type param ``` error[E0308]: mismatched types --> $DIR/return-impl-trait.rs:23:5 | LL | fn other_bounds<T>() -> T | - - | | | | | expected `T` because of return type | | help: consider using an impl return type: `impl Trait` | expected this type parameter ... LL | () | ^^ expected type parameter `T`, found `()` | = note: expected type parameter `T` found unit type `()` = note: the caller chooses the type of T which can be different from () ``` Tried to see if "expected this type parameter" can be replaced, but that goes all the way to `rustc_infer` so seems not worth the effort and can affect other diagnostics. Revives #112088 and #104755.
2024-03-18Provide structured suggestion for `#![feature(foo)]`Esteban Küber-1/+4
``` 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-16Note that type param is chosen by caller when suggesting return impl Trait许杰友 Jieyou Xu (Joe)-0/+1
2024-03-09Add missing regression testsGurinder Singh-0/+109
for a couple of issues
2024-03-08Auto merge of #122078 - gurry:121443-ice-layout-is-sized-alt, r=oli-obkbors-0/+61
Check that return type is WF in typeck Ensures that non-WF types do not pass typeck and then later ICE in MIR/const eval Fixes #121443
2024-03-06Check that return type is WF in typeckGurinder Singh-0/+61
Without it non-WF types could pass typeck and then later fail in MIR/const eval
2024-03-04address review feedbackLukas Markeffsky-1/+45
2024-03-04suppress fulfillment errors for super projectionsLukas Markeffsky-117/+9
2024-03-04adjust obligation spans for super projectionsLukas Markeffsky-9/+9
2024-03-04add test for assoc type mismatch in supertraitLukas Markeffsky-0/+229
2024-02-18Rollup merge of #121100 - estebank:issue-71252, r=compiler-errorsLeón Orell Valerian Liehr-0/+38
Detect when method call on argument could be removed to fulfill failed trait bound When encountering ```rust struct Foo; struct Bar; impl From<Bar> for Foo { fn from(_: Bar) -> Self { Foo } } fn qux(_: impl From<Bar>) {} fn main() { qux(Bar.into()); } ``` Suggest removing `.into()`: ``` error[E0283]: type annotations needed --> f100.rs:8:13 | 8 | qux(Bar.into()); | --- ^^^^ | | | required by a bound introduced by this call | = note: cannot satisfy `_: From<Bar>` note: required by a bound in `qux` --> f100.rs:6:16 | 6 | fn qux(_: impl From<Bar>) {} | ^^^^^^^^^ required by this bound in `qux` help: try using a fully qualified path to specify the expected types | 8 | qux(<Bar as Into<T>>::into(Bar)); | +++++++++++++++++++++++ ~ help: consider removing this method call, as the receiver has type `Bar` and `Bar: From<Bar>` trivially holds | 8 - qux(Bar.into()); 8 + qux(Bar); | ``` Fix #71252