mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 07:14:28 +00:00
f41ad1bc9c
Tweak suggestions for bare trait used as a type ``` error[E0782]: trait objects must include the `dyn` keyword --> $DIR/not-on-bare-trait-2021.rs:11:11 | LL | fn bar(x: Foo) -> Foo { | ^^^ | help: use a generic type parameter, constrained by the trait `Foo` | LL | fn bar<T: Foo>(x: T) -> Foo { | ++++++++ ~ help: you can also use `impl Foo`, but users won't be able to specify the type paramer when calling the `fn`, having to rely exclusively on type inference | LL | fn bar(x: impl Foo) -> Foo { | ++++ help: alternatively, use a trait object to accept any type that implements `Foo`, accessing its methods at runtime using dynamic dispatch | LL | fn bar(x: &dyn Foo) -> Foo { | ++++ error[E0782]: trait objects must include the `dyn` keyword --> $DIR/not-on-bare-trait-2021.rs:11:19 | LL | fn bar(x: Foo) -> Foo { | ^^^ | help: use `impl Foo` to return an opaque type, as long as you return a single underlying type | LL | fn bar(x: Foo) -> impl Foo { | ++++ help: alternatively, you can return an owned trait object | LL | fn bar(x: Foo) -> Box<dyn Foo> { | +++++++ + ``` Fix #119525: ``` error[E0038]: the trait `Ord` cannot be made into an object --> $DIR/bare-trait-dont-suggest-dyn.rs:3:33 | LL | fn ord_prefer_dot(s: String) -> Ord { | ^^^ `Ord` cannot be made into an object | note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety> --> $SRC_DIR/core/src/cmp.rs:LL:COL | = note: the trait cannot be made into an object because it uses `Self` as a type parameter ::: $SRC_DIR/core/src/cmp.rs:LL:COL | = note: the trait cannot be made into an object because it uses `Self` as a type parameter help: consider using an opaque type instead | LL | fn ord_prefer_dot(s: String) -> impl Ord { | ++++ ``` |
||
---|---|---|
.. | ||
auxiliary | ||
check-cfg | ||
coverage | ||
doctest | ||
error-in-impl-trait | ||
generate-link-to-definition | ||
intra-doc | ||
issues | ||
lints | ||
scrape-examples | ||
suggestions | ||
ambiguous-inherent-assoc-ty.rs | ||
apit-46976.rs | ||
bounded-hr-lifetime.rs | ||
bounded-hr-lifetime.stderr | ||
check-doc-alias-attr-location.rs | ||
check-doc-alias-attr-location.stderr | ||
check-doc-alias-attr.rs | ||
check-doc-alias-attr.stderr | ||
circular-intra-doc-link-48414.rs | ||
commandline-argfile-badutf8.args | ||
commandline-argfile-badutf8.rs | ||
commandline-argfile-badutf8.stderr | ||
commandline-argfile-missing.rs | ||
commandline-argfile-missing.stderr | ||
commandline-argfile.args | ||
commandline-argfile.rs | ||
const_arg_in_type_position.rs | ||
const_arg_in_type_position.stderr | ||
const-evalutation-ice.rs | ||
const-evalutation-ice.stderr | ||
crate-reference-in-block-module.rs | ||
crate-reference-in-block-module.stderr | ||
custom_code_classes_in_docs-warning3.rs | ||
custom_code_classes_in_docs-warning3.stderr | ||
custom_code_classes_in_docs-warning.rs | ||
custom_code_classes_in_docs-warning.stderr | ||
deprecated-attrs.rs | ||
deprecated-attrs.stderr | ||
deref-generic.rs | ||
diagnostic-width.rs | ||
diagnostic-width.stderr | ||
doc-alias-assoc-const.rs | ||
doc-alias-assoc-const.stderr | ||
doc-alias-crate-level.rs | ||
doc-alias-crate-level.stderr | ||
doc-alias-same-name.rs | ||
doc-alias-same-name.stderr | ||
doc-cfg.rs | ||
doc-cfg.stderr | ||
doc-include-suggestion.rs | ||
doc-include-suggestion.stderr | ||
feature-gate-custom_code_classes_in_docs.rs | ||
feature-gate-custom_code_classes_in_docs.stderr | ||
feature-gate-doc_cfg_hide.rs | ||
feature-gate-doc_cfg_hide.stderr | ||
hidden-trait-method-34423.rs | ||
ice-assoc-const-for-primitive-31808.rs | ||
ice-bug-report-url.rs | ||
ice-bug-report-url.stderr | ||
ignore-block-help.rs | ||
ignore-block-help.stderr | ||
impl-fn-nesting.rs | ||
impl-fn-nesting.stderr | ||
infinite-recursive-type.rs | ||
infinite-recursive-type.stderr | ||
inherent-assoc-consts-36031.rs | ||
invalid_associated_const.rs | ||
invalid_associated_const.stderr | ||
invalid_const_in_lifetime_position.rs | ||
invalid_const_in_lifetime_position.stderr | ||
invalid_infered_static_and_const.rs | ||
invalid_infered_static_and_const.stderr | ||
invalid-cfg.rs | ||
invalid-cfg.stderr | ||
invalid-keyword.rs | ||
invalid-keyword.stderr | ||
invalid-syntax.rs | ||
invalid-syntax.stderr | ||
invalid-theme-name.rs | ||
invalid-theme-name.stderr | ||
issue-102467.rs | ||
issue-102467.stderr | ||
issue-110629-private-type-cycle-dyn.rs | ||
issue-110629-private-type-cycle-dyn.stderr | ||
issue-110629-private-type-cycle.rs | ||
macro-docs.rs | ||
macro-docs.stderr | ||
macro-docs.stdout | ||
mismatched_arg_count.rs | ||
mismatched_arg_count.stderr | ||
nested-extern-crate-46271.rs | ||
nested-macro-rules-47639.rs | ||
normalize-cycle.rs | ||
normalize-overflow.rs | ||
not-wf-ambiguous-normalization.rs | ||
not-wf-ambiguous-normalization.stderr | ||
output-format-html-stable.rs | ||
proc_macro_bug.rs | ||
proc_macro_bug.stderr | ||
range-pattern.rs | ||
recursive-deref-ice.rs | ||
rustc-check-passes.rs | ||
rustc-check-passes.stderr | ||
search-index-generics-recursion-bug-issue-59502.rs | ||
super-glob-40936.rs | ||
track-diagnostics.rs | ||
track-diagnostics.stderr | ||
tuple-variadic-check.rs | ||
tuple-variadic-check.stderr | ||
unable-fulfill-trait.rs | ||
unable-fulfill-trait.stderr | ||
unescaped_backticks.rs | ||
unescaped_backticks.stderr | ||
unused-extern-crate.rs | ||
use_both_out_dir_and_output_options.rs | ||
use_both_out_dir_and_output_options.stderr | ||
wasm-safe.rs |