Skip to content
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

Rollup of 10 pull requests #105720

Closed
wants to merge 29 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
259c37e
Ensure async trait impls are async (or otherwise return an opaque type)
ComputerDruid Nov 3, 2022
bc92321
Suggest constraining type parameter with `Clone`
estebank Dec 14, 2022
0fb8d84
Suggest `#[derive(Clone)]`
estebank Dec 14, 2022
687b4d9
Add regression test for #104678
JohnTitor Dec 14, 2022
5f5ae17
Consider discriminant fields that are ordered before variant fields
compiler-errors Dec 12, 2022
bdc3c4b
Make print_type_sizes test not use feature(start)
compiler-errors Dec 12, 2022
10368c6
Point at method chains on `E0271` errors
estebank Dec 13, 2022
36b60e7
Use `with_forced_trimmed_paths` more
estebank Dec 13, 2022
50e269f
Shorten trimmed display of closures
estebank Dec 14, 2022
e9ef36a
Trim paths in E0599
estebank Dec 14, 2022
7f8fdf4
Consider lifetimes when comparing assoc types in method chain
estebank Dec 14, 2022
ae60015
Use impl's def id when calculating type to specify UFCS
compiler-errors Nov 12, 2022
1225a65
drive-by: Fix path spans
compiler-errors Nov 12, 2022
7bf36de
Make report_projection_error more term agnostic
compiler-errors Dec 12, 2022
cfa6a93
Auto traits in dyn are suggestable
compiler-errors Dec 12, 2022
34d194d
Highlight conflicting param-env candidates, again
compiler-errors Nov 15, 2022
d10f6b4
Add test
compiler-errors Dec 5, 2022
c99f1b7
Run `x test tidy` sooner in mingw-check
jyn514 Dec 14, 2022
fc6d59d
Make `RUN_CHECK_WITH_PARALLEL_QUERIES` the last thing to run
jyn514 Dec 14, 2022
ef10913
Rollup merge of #104334 - compiler-errors:ufcs-sugg-wrong-def-id, r=e…
matthiaskrgr Dec 14, 2022
79653c8
Rollup merge of #104592 - ComputerDruid:async_check, r=compiler-errors
matthiaskrgr Dec 14, 2022
a60bb44
Rollup merge of #105285 - compiler-errors:conflicting-param-env-2, r=…
matthiaskrgr Dec 14, 2022
fbe00f0
Rollup merge of #105623 - compiler-errors:generator-type-size-fix, r=…
matthiaskrgr Dec 14, 2022
4366327
Rollup merge of #105627 - compiler-errors:dyn-auto-suggestable, r=dav…
matthiaskrgr Dec 14, 2022
ae6dfa6
Rollup merge of #105633 - compiler-errors:term-agnostic, r=oli-obk
matthiaskrgr Dec 14, 2022
567d887
Rollup merge of #105674 - estebank:iterator-chains, r=oli-obk
matthiaskrgr Dec 14, 2022
62b1646
Rollup merge of #105679 - estebank:suggest-clone, r=compiler-errors
matthiaskrgr Dec 14, 2022
1c35840
Rollup merge of #105692 - JohnTitor:issue-104678, r=compiler-errors
matthiaskrgr Dec 14, 2022
cb19a7f
Rollup merge of #105714 - jyn514:tidy-first, r=Mark-Simulacrum
matthiaskrgr Dec 14, 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
Suggest #[derive(Clone)]
  • Loading branch information
estebank committed Dec 14, 2022
commit 0fb8d848f9d3b427fea754a5d944375e049f2eb4
15 changes: 9 additions & 6 deletions compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs
Original file line number Diff line number Diff line change
@@ -1278,17 +1278,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&& !results.expr_adjustments(callee_expr).iter().any(|adj| matches!(adj.kind, ty::adjustment::Adjust::Deref(..)))
// Check that we're in fact trying to clone into the expected type
&& self.can_coerce(*pointee_ty, expected_ty)
&& let predicate = ty::Binder::dummy(ty::TraitRef {
def_id: clone_trait_did,
substs: self.tcx.mk_substs([expected_ty.into()].iter()),
})
.without_const()
.to_predicate(self.tcx)
// And the expected type doesn't implement `Clone`
&& !self.predicate_must_hold_considering_regions(&traits::Obligation {
cause: traits::ObligationCause::dummy(),
param_env: self.param_env,
recursion_depth: 0,
predicate: ty::Binder::dummy(ty::TraitRef {
def_id: clone_trait_did,
substs: self.tcx.mk_substs([expected_ty.into()].iter()),
})
.without_const()
.to_predicate(self.tcx),
predicate,
})
{
diag.span_note(
@@ -1307,6 +1308,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
diag,
vec![(param.name.as_str(), "Clone", Some(clone_trait_did))].into_iter(),
);
} else {
self.suggest_derive(diag, &[(predicate, None, None)]);
}
}
}
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
@@ -1843,7 +1843,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.suggest_derive(err, &preds);
}

fn suggest_derive(
pub fn suggest_derive(
&self,
err: &mut Diagnostic,
unsatisfied_predicates: &[(
Original file line number Diff line number Diff line change
@@ -3,6 +3,14 @@ fn wat<T: Clone>(t: &T) -> T {
t.clone() //~ ERROR E0308
}

#[derive(Clone)]
struct Foo;

fn wut(t: &Foo) -> Foo {
t.clone() //~ ERROR E0308
}

fn main() {
wat(&42);
wut(&Foo);
}
Original file line number Diff line number Diff line change
@@ -3,6 +3,13 @@ fn wat<T>(t: &T) -> T {
t.clone() //~ ERROR E0308
}

struct Foo;

fn wut(t: &Foo) -> Foo {
t.clone() //~ ERROR E0308
}

fn main() {
wat(&42);
wut(&Foo);
}
Original file line number Diff line number Diff line change
@@ -20,6 +20,24 @@ help: consider restricting type parameter `T`
LL | fn wat<T: Clone>(t: &T) -> T {
| +++++++

error: aborting due to previous error
error[E0308]: mismatched types
--> $DIR/clone-on-unconstrained-borrowed-type-param.rs:9:5
|
LL | fn wut(t: &Foo) -> Foo {
| --- expected `Foo` because of return type
LL | t.clone()
| ^^^^^^^^^ expected struct `Foo`, found `&Foo`
|
note: `Foo` does not implement `Clone`, so `&Foo` was cloned instead
--> $DIR/clone-on-unconstrained-borrowed-type-param.rs:9:5
|
LL | t.clone()
| ^
help: consider annotating `Foo` with `#[derive(Clone)]`
|
LL | #[derive(Clone)]
|

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0308`.
4 changes: 4 additions & 0 deletions src/test/ui/typeck/explain_clone_autoref.stderr
Original file line number Diff line number Diff line change
@@ -12,6 +12,10 @@ note: `NotClone` does not implement `Clone`, so `&NotClone` was cloned instead
|
LL | nc.clone()
| ^^
help: consider annotating `NotClone` with `#[derive(Clone)]`
|
LL | #[derive(Clone)]
|

error: aborting due to previous error