summary refs log tree commit diff
path: root/src/test/ui/traits
AgeCommit message (Collapse)AuthorLines
2022-10-28Rollup merge of #103283 - nbarrios1337:unsafe-impl-suggestions, r=cjgillotMatthias Krüger-0/+18
Add suggestions for unsafe impl error codes Adds suggestions for users to add `unsafe` to trait impls that should be `unsafe`, and remove `unsafe` from trait impls that do not require `unsafe` With the folllowing code: ```rust struct Foo {} struct Bar {} trait Safe {} unsafe trait Unsafe {} impl Safe for Foo {} // ok impl Unsafe for Foo {} // E0200 unsafe impl Safe for Bar {} // E0199 unsafe impl Unsafe for Bar {} // ok // omitted empty main fn ``` The current rustc output is: ``` error[E0199]: implementing the trait `Safe` is not unsafe --> e0200.rs:13:1 | 13 | unsafe impl Safe for Bar {} // E0199 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0200]: the trait `Unsafe` requires an `unsafe impl` declaration --> e0200.rs:11:1 | 11 | impl Unsafe for Foo {} // E0200 | ^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 2 previous errors Some errors have detailed explanations: E0199, E0200. For more information about an error, try `rustc --explain E0199`. ``` With this PR, the future rustc output would be: ``` error[E0199]: implementing the trait `Safe` is not unsafe --> ../../temp/e0200.rs:13:1 | 13 | unsafe impl Safe for Bar {} // E0199 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | help: remove `unsafe` from this trait implementation | 13 - unsafe impl Safe for Bar {} // E0199 13 + impl Safe for Bar {} // E0199 | error[E0200]: the trait `Unsafe` requires an `unsafe impl` declaration --> ../../temp/e0200.rs:11:1 | 11 | impl Unsafe for Foo {} // E0200 | ^^^^^^^^^^^^^^^^^^^^^^ | = note: the trait `Unsafe` enforces invariants that the compiler can't check. Review the trait documentation and make sure this implementation upholds those invariants before adding the `unsafe` keyword help: add `unsafe` to this trait implementation | 11 | unsafe impl Unsafe for Foo {} // E0200 | ++++++ error: aborting due to 2 previous errors Some errors have detailed explanations: E0199, E0200. For more information about an error, try `rustc --explain E0199`. ``` ``@rustbot`` label +T-compiler +A-diagnostics +A-suggestion-diagnostics
2022-10-22Rollup merge of #103339 - Rageking8:fix-some-typos, r=fee1-deadMatthias Krüger-1/+1
Fix some typos
2022-10-21fix some typosRageking8-1/+1
2022-10-20Add fix suggestions for E0199, E0200, and E0569Nicolas Barrios-0/+18
2022-10-17`order_dependent_trait_objects` to `ReportNow`lcnr-0/+70
2022-10-15remove no_core featureTakayuki Maeda-28/+12
2022-10-14normalize stderrTakayuki Maeda-9/+10
2022-10-14check if the self type is `ty::Float` before getting second substsTakayuki Maeda-0/+90
2022-10-11Rollup merge of #100387 - cjgillot:hygiene-trait-impl, r=petrochenkovMatthias Krüger-2/+5
Check uniqueness of impl items by trait item when applicable. When checking uniqueness of item names in impl blocks, we currently use the same definition of hygiene as for toplevel items. This means that a plain item and one generated by a macro 2.0 do not collide. This hygiene rule does not match with how impl items resolve to associated trait items. As a consequence, we misdiagnose the trait impls. This PR proposes to consider that trait impl items are uses of the corresponding trait items during resolution, instead of checking for duplicates later. An error is emitted when a trait impl item is used twice. There should be no stable breakage, since macros 2.0 are still unstable. r? ``@petrochenkov`` cc ``@RalfJung`` Fixes https://github.com/rust-lang/rust/issues/71614.
2022-10-11Report duplicate definitions in trait impls during resolution.Camille GILLOT-2/+5
2022-10-10Rollup merge of #102055 - c410-f3r:moar-errors, r=petrochenkovDylan DPC-0/+29
Move some tests to more reasonable directories r? ``@petrochenkov``
2022-10-04follow-up fix about 101866 to print the self type.Yiming Lei-2/+2
modified: compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs modified: src/test/ui/error-codes/E0283.stderr modified: src/test/ui/error-codes/E0790.stderr modified: src/test/ui/traits/static-method-generic-inference.stderr modified: src/test/ui/type/issue-101866.stderr
2022-10-01bless ui testsMaybe Waffle-12/+12
2022-09-26Rollup merge of #101996 - b-naber:binder-print, r=lcnrMatthias Krüger-1/+1
Don't duplicate region names for late-bound regions in print of Binder Fixes https://github.com/rust-lang/rust/issues/101280
2022-09-26address reviewb-naber-1/+1
2022-09-23Allow more !Copy implsLeón Orell Valerian Liehr-2/+2
2022-09-20Move some tests to more reasonable directoriesCaio-0/+29
2022-09-12A SubstitutionPart is not a deletion if it replaces nothing with nothingMichael Goulet-3/+2
2022-09-08Adjust spacing in suggestion, add a testMichael Goulet-2/+2
2022-09-08Add associated item binding to non-param-ty where clause suggestionsMichael Goulet-2/+2
2022-08-31Fix a bunch of typoDezhi Wu-1/+1
This PR will fix some typos detected by [typos]. I only picked the ones I was sure were spelling errors to fix, mostly in the comments. [typos]: https://github.com/crate-ci/typos
2022-08-26Rollup merge of #99064 - lyming2007:issue-97687-fix, r=estebankYuki Okushi-5/+5
distinguish the method and associated function diagnostic information Methods are defined within the context of a struct and their first parameter is always self Associated functions don’t take self as a parameter ``` modified: compiler/rustc_typeck/src/check/method/suggest.rs modified: src/test/ui/auto-ref-slice-plus-ref.stderr modified: src/test/ui/block-result/issue-3563.stderr modified: src/test/ui/issues/issue-28344.stderr modified: src/test/ui/suggestions/dont-suggest-pin-array-dot-set.stderr modified: src/test/ui/suggestions/suggest-methods.stderr modified: src/test/ui/traits/trait-upcasting/subtrait-method.stderr ```
2022-08-22Auto merge of #100676 - lcnr:implied-bounds-yay, r=nikomatsakisbors-2/+2
implied bounds: explicitly state which types are assumed to be wf Adds a new query which maps each definition to the types which that definition assumes to be well formed. The intent is to make it easier to reason about implied bounds. This change should not influence the user-facing behavior of rustc. Notably, `borrowck` still only assumes that the function signature of associated functions is well formed while `wfcheck` assumes that the both the function signature and the impl trait ref is well formed. Not sure if that by itself can trigger UB or whether it's just annoying. As a next step, we can add `WellFormed` predicates to `predicates_of` of these items and can stop adding the wf bounds at each place which uses them. I also intend to move the computation from `assumed_wf_types` to `implied_bounds` into the `param_env` computation. This requires me to take a deeper look at `compare_predicate_entailment` which is currently somewhat weird wrt implied bounds so I am not touching this here. r? `@nikomatsakis`
2022-08-21Adjust messages, address some nitsMichael Goulet-7/+11
2022-08-21Point at struct field if possibleMichael Goulet-8/+8
2022-08-21Prefer non-Self non-method types over Self, firstMichael Goulet-16/+16
2022-08-21Rework ambiguity errorsMichael Goulet-91/+30
2022-08-21Do not favor projection type when pointing out arg causing fulfillment errorMichael Goulet-4/+2
2022-08-21Account for relative pathsMichael Goulet-16/+20
2022-08-21Rework point-at-argMichael Goulet-67/+135
2022-08-20Rollup merge of #100796 - TaKO8Ki:remove-unnecessary-string-searching, ↵Matthias Krüger-12/+18
r=compiler-errors Refactor: remove unnecessary string searchings This patch removes unnecessary string searchings for checking if function arguments have `&` and `&mut`.
2022-08-20Rollup merge of #100500 - cjgillot:verify-self-predicate, r=lcnrMatthias Krüger-1/+31
Ban references to `Self` in trait object substs for projection predicates too. Fixes https://github.com/rust-lang/rust/issues/100484 Fixes https://github.com/rust-lang/rust/issues/100485 r? ````@lcnr````
2022-08-20remove unnecessary string searchingsTakayuki Maeda-12/+18
remove unnecessary string searchings for checking if function arguments have `&` and `&mut`
2022-08-18Reword "Required because of the requirements on the impl of ..."Andy Wang-33/+33
2022-08-17Add const-generics test.Camille GILLOT-0/+23
2022-08-17implied_bounds: clarify our assumptionslcnr-2/+2
2022-08-14Also do it for genericsMichael Goulet-6/+6
2022-08-14Point to argument if it's self type of unsatisfied projection predicateMichael Goulet-4/+8
2022-08-13Rollup merge of #99646 - compiler-errors:arg-mismatch-single-arg-label, ↵Michael Goulet-1/+1
r=estebank Only point out a single function parameter if we have a single arg incompatibility Fixes #99635
2022-08-13Ban references to `Self` in trait object substs for projection predicates too.Camille GILLOT-1/+8
2022-08-12Point out a single arg if we have a single arg incompatibilityMichael Goulet-1/+1
2022-08-10Ban indirect references to `Self` too.Camille GILLOT-0/+19
2022-08-10Generalize trait object generic param check to aliases.Camille GILLOT-0/+184
2022-08-08Adjust wordingMichael Goulet-7/+6
2022-08-07Implement special-cased projection error message for some common traitsMichael Goulet-2/+3
2022-08-03Warn about dead tuple struct fieldsFabian Wolff-7/+7
2022-07-28Remove guess_head_span.Camille GILLOT-6/+5
2022-07-22Auto merge of #99420 - RalfJung:vtable, r=oli-obkbors-15/+68
make vtable pointers entirely opaque This implements the scheme discussed in https://github.com/rust-lang/unsafe-code-guidelines/issues/338: vtable pointers should be considered entirely opaque and not even readable by Rust code, similar to function pointers. - We have a new kind of `GlobalAlloc` that symbolically refers to a vtable. - Miri uses that kind of allocation when generating a vtable. - The codegen backends, upon encountering such an allocation, call `vtable_allocation` to obtain an actually dataful allocation for this vtable. - We need new intrinsics to obtain the size and align from a vtable (for some `ptr::metadata` APIs), since direct accesses are UB now. I had to touch quite a bit of code that I am not very familiar with, so some of this might not make much sense... r? `@oli-obk`
2022-07-20we seem to monomorphize fewer vtables by default now, so adjust some testsRalf Jung-15/+68
2022-07-20Rollup merge of #99352 - compiler-errors:tighter-spans-on-generic-call, ↵Matthias Krüger-17/+5
r=spastorino Use `typeck_results` to avoid duplicate `ast_ty_to_ty` call Comes with a bunch of improvements in spans :heart_eyes: