Skip to content

Rollup of 6 pull requests #98767

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Jul 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e67e165
Make `ThinBox<T>` covariant in `T`
cuviper Jun 27, 2022
7dc0489
fix ICE with -Wrust-2021-incompatible-closure-captures
matthiaskrgr Jun 28, 2022
81abfe3
add blanket impl suggestion to the local traits
vincenzopalazzo May 14, 2022
86c1a73
ui test: add test of blanklet implementation
vincenzopalazzo Jun 22, 2022
835b7a5
ui: improve suggestion test by addig the help message
vincenzopalazzo Jun 29, 2022
72a1621
Use `split_{first,last}` in `cs_fold1`.
nnethercote Jun 28, 2022
7a4fdcb
Remove unnecessary fields from `EnumNonMatchingCollapsed`.
nnethercote Jun 27, 2022
d13fa0d
Remove `Substructure::method_ident`.
nnethercote Jun 28, 2022
625122a
fix grammar in useless doc comment lint
euclio Jun 30, 2022
1254fe9
Remove `{Method,Trait}Def::is_unsafe`.
nnethercote Jun 28, 2022
89f6917
Remove `Substructure::self_args`.
nnethercote Jun 28, 2022
57d5689
Remove some unnecessary `pub`s.
nnethercote Jun 28, 2022
623ebbe
Remove some commented-out code.
nnethercote Jun 28, 2022
78ec19f
`expand_deriving_clone` tweaks.
nnethercote Jun 28, 2022
b942466
Simplify pointer handling.
nnethercote Jun 29, 2022
18fef6b
Remove lifetime support in deriving code.
nnethercote Jun 30, 2022
00307a5
Rename `Ty::Literal` as `Ty::Path`.
nnethercote Jun 30, 2022
85e8d94
Change `Ty::Tuple` to `Ty::Unit`.
nnethercote Jun 30, 2022
f791ac6
use const instead of function and make it private
TaKO8Ki Jul 1, 2022
e2ed8d7
Rollup merge of #97488 - vincenzopalazzo:macros/blanket_sugg, r=compi…
Dylan-DPC Jul 1, 2022
9dd3288
Rollup merge of #98585 - cuviper:covariant-thinbox, r=thomcc
Dylan-DPC Jul 1, 2022
90b296d
Rollup merge of #98644 - matthiaskrgr:drp_loc_span_err__2021_inc_clos…
Dylan-DPC Jul 1, 2022
528202f
Rollup merge of #98739 - euclio:useless-comment-plural, r=Dylan-DPC
Dylan-DPC Jul 1, 2022
c0cf363
Rollup merge of #98741 - nnethercote:deriving-cleanups, r=Mark-Simula…
Dylan-DPC Jul 1, 2022
6404620
Rollup merge of #98756 - TaKO8Ki:use-const-instead-of-function, r=Dyl…
Dylan-DPC Jul 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ui: improve suggestion test by addig the help message
Signed-off-by: Vincenzo Palazzo <[email protected]>
  • Loading branch information
vincenzopalazzo committed Jun 30, 2022
commit 835b7a523a41cc89f0839f40652477af097db390
15 changes: 2 additions & 13 deletions compiler/rustc_typeck/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3015,7 +3015,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let param_name = generics.params.next_type_param_name(None);

let add_generic_sugg = if let Some(span) = generics.span_for_param_suggestion() {
let param_name = generics.params.next_type_param_name(Some(&impl_trait_name));
(span, format!(", {}: {}", param_name, impl_trait_name))
} else {
(generics.span, format!("<{}: {}>", param_name, impl_trait_name))
Expand Down Expand Up @@ -3047,11 +3046,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
.map_or(false, |s| s.trim_end().ends_with('<'));

let is_global = poly_trait_ref.trait_ref.path.is_global();
let is_local = if let Some(def_id) = poly_trait_ref.trait_ref.trait_def_id() {
def_id.is_local()
} else {
false
};
let sugg = Vec::from_iter([
(
self_ty.span.shrink_to_lo(),
Expand All @@ -3077,9 +3071,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
rustc_errors::struct_span_err!(tcx.sess, self_ty.span, E0782, "{}", msg);
diag.multipart_suggestion_verbose(label, sugg, Applicability::MachineApplicable);
// check if the impl trait that we are considering is a impl of a local trait
if is_local {
self.maybe_lint_blanket_trait_impl(&self_ty, &mut diag);
}
self.maybe_lint_blanket_trait_impl(&self_ty, &mut diag);
diag.emit();
} else {
let msg = "trait objects without an explicit `dyn` are deprecated";
Expand All @@ -3094,10 +3086,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
sugg,
Applicability::MachineApplicable,
);
// check if the impl trait that we are considering is a impl of a local trait
if is_local {
self.maybe_lint_blanket_trait_impl::<()>(&self_ty, &mut diag);
}
self.maybe_lint_blanket_trait_impl::<()>(&self_ty, &mut diag);
diag.emit();
},
);
Expand Down
14 changes: 14 additions & 0 deletions src/test/ui/suggestions/suggest-blanket-impl-local-trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,47 @@ trait GenericTrait<T> {}

impl LocalTraitTwo for LocalTraitOne {}
//~^ ERROR trait objects must include the `dyn` keyword
//~| HELP add `dyn` keyword before this trait
//~| HELP alternatively use a blanket implementation to implement `LocalTraitTwo` for all types that also implement `LocalTraitOne`

impl fmt::Display for LocalTraitOne {
//~^ ERROR trait objects must include the `dyn` keyword
//~| HELP add `dyn` keyword before this trait
fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
todo!();
}
}

impl fmt::Display for LocalTraitTwo + Send {
//~^ ERROR trait objects must include the `dyn` keyword
//~| HELP add `dyn` keyword before this trait
fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
todo!();
}
}

impl LocalTraitOne for fmt::Display {}
//~^ ERROR trait objects must include the `dyn` keyword
//~| HELP add `dyn` keyword before this trait
//~| HELP alternatively use a blanket implementation to implement `LocalTraitOne` for all types that also implement `fmt::Display`


impl LocalTraitOne for fmt::Display + Send {}
//~^ ERROR trait objects must include the `dyn` keyword
//~| HELP add `dyn` keyword before this trait
//~| HELP alternatively use a blanket implementation to implement `LocalTraitOne` for all types that also implement `fmt::Display + Send`


impl<E> GenericTrait<E> for LocalTraitOne {}
//~^ ERROR trait objects must include the `dyn` keyword
//~| HELP add `dyn` keyword before this trait
//~| HELP alternatively use a blanket implementation to implement `GenericTrait<E>` for all types that also implement `LocalTraitOne`

trait GenericTraitTwo<T> {}

impl<T, E> GenericTraitTwo<E> for GenericTrait<T> {}
//~^ ERROR trait objects must include the `dyn` keyword
//~| HELP add `dyn` keyword before this trait
//~| HELP alternatively use a blanket implementation to implement `GenericTraitTwo<E>` for all types that also implement `GenericTrait<T>`

fn main() {}
38 changes: 23 additions & 15 deletions src/test/ui/suggestions/suggest-blanket-impl-local-trait.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ help: add `dyn` keyword before this trait
|
LL - impl LocalTraitTwo for LocalTraitOne {}
LL + impl LocalTraitTwo for dyn LocalTraitOne {}
|
|
help: alternatively use a blanket implementation to implement `LocalTraitTwo` for all types that also implement `LocalTraitOne`
|
LL | impl<T: LocalTraitOne> LocalTraitTwo for T {}
| ++++++++++++++++++ ~

error[E0782]: trait objects must include the `dyn` keyword
--> $DIR/suggest-blanket-impl-local-trait.rs:16:23
--> $DIR/suggest-blanket-impl-local-trait.rs:18:23
|
LL | impl fmt::Display for LocalTraitOne {
| ^^^^^^^^^^^^^
Expand All @@ -24,10 +24,10 @@ help: add `dyn` keyword before this trait
|
LL - impl fmt::Display for LocalTraitOne {
LL + impl fmt::Display for dyn LocalTraitOne {
|
|

error[E0782]: trait objects must include the `dyn` keyword
--> $DIR/suggest-blanket-impl-local-trait.rs:23:23
--> $DIR/suggest-blanket-impl-local-trait.rs:26:23
|
LL | impl fmt::Display for LocalTraitTwo + Send {
| ^^^^^^^^^^^^^^^^^^^^
Expand All @@ -36,10 +36,10 @@ help: add `dyn` keyword before this trait
|
LL - impl fmt::Display for LocalTraitTwo + Send {
LL + impl fmt::Display for dyn LocalTraitTwo + Send {
|
|

error[E0782]: trait objects must include the `dyn` keyword
--> $DIR/suggest-blanket-impl-local-trait.rs:30:24
--> $DIR/suggest-blanket-impl-local-trait.rs:34:24
|
LL | impl LocalTraitOne for fmt::Display {}
| ^^^^^^^^^^^^
Expand All @@ -48,10 +48,14 @@ help: add `dyn` keyword before this trait
|
LL - impl LocalTraitOne for fmt::Display {}
LL + impl LocalTraitOne for dyn fmt::Display {}
|
|
help: alternatively use a blanket implementation to implement `LocalTraitOne` for all types that also implement `fmt::Display`
|
LL | impl<T: fmt::Display> LocalTraitOne for T {}
| +++++++++++++++++ ~

error[E0782]: trait objects must include the `dyn` keyword
--> $DIR/suggest-blanket-impl-local-trait.rs:33:24
--> $DIR/suggest-blanket-impl-local-trait.rs:40:24
|
LL | impl LocalTraitOne for fmt::Display + Send {}
| ^^^^^^^^^^^^^^^^^^^
Expand All @@ -60,10 +64,14 @@ help: add `dyn` keyword before this trait
|
LL - impl LocalTraitOne for fmt::Display + Send {}
LL + impl LocalTraitOne for dyn fmt::Display + Send {}
|
|
help: alternatively use a blanket implementation to implement `LocalTraitOne` for all types that also implement `fmt::Display + Send`
|
LL | impl<T: fmt::Display + Send> LocalTraitOne for T {}
| ++++++++++++++++++++++++ ~

error[E0782]: trait objects must include the `dyn` keyword
--> $DIR/suggest-blanket-impl-local-trait.rs:36:29
--> $DIR/suggest-blanket-impl-local-trait.rs:46:29
|
LL | impl<E> GenericTrait<E> for LocalTraitOne {}
| ^^^^^^^^^^^^^
Expand All @@ -72,14 +80,14 @@ help: add `dyn` keyword before this trait
|
LL - impl<E> GenericTrait<E> for LocalTraitOne {}
LL + impl<E> GenericTrait<E> for dyn LocalTraitOne {}
|
|
help: alternatively use a blanket implementation to implement `GenericTrait<E>` for all types that also implement `LocalTraitOne`
|
LL | impl<E, L: LocalTraitOne> GenericTrait<E> for T {}
LL | impl<E, T: LocalTraitOne> GenericTrait<E> for T {}
| ++++++++++++++++++ ~

error[E0782]: trait objects must include the `dyn` keyword
--> $DIR/suggest-blanket-impl-local-trait.rs:41:35
--> $DIR/suggest-blanket-impl-local-trait.rs:53:35
|
LL | impl<T, E> GenericTraitTwo<E> for GenericTrait<T> {}
| ^^^^^^^^^^^^^^^
Expand All @@ -88,10 +96,10 @@ help: add `dyn` keyword before this trait
|
LL - impl<T, E> GenericTraitTwo<E> for GenericTrait<T> {}
LL + impl<T, E> GenericTraitTwo<E> for dyn GenericTrait<T> {}
|
|
help: alternatively use a blanket implementation to implement `GenericTraitTwo<E>` for all types that also implement `GenericTrait<T>`
|
LL | impl<T, E, G: GenericTrait<T>> GenericTraitTwo<E> for U {}
LL | impl<T, E, U: GenericTrait<T>> GenericTraitTwo<E> for U {}
| ++++++++++++++++++++ ~

error: aborting due to 7 previous errors
Expand Down
Binary file added suggest-blanket-impl-local-trait
Binary file not shown.