diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs
index ac0c88468faa5..83c9269f24e36 100644
--- a/compiler/rustc_middle/src/ty/print/pretty.rs
+++ b/compiler/rustc_middle/src/ty/print/pretty.rs
@@ -1239,21 +1239,18 @@ pub trait PrettyPrinter<'tcx>:
.generics_of(principal.def_id)
.own_args_no_defaults(cx.tcx(), principal.args);
- let mut projections = predicates.projection_bounds();
-
- let mut args = args.iter().cloned();
- let arg0 = args.next();
- let projection0 = projections.next();
- if arg0.is_some() || projection0.is_some() {
- let args = arg0.into_iter().chain(args);
- let projections = projection0.into_iter().chain(projections);
+ let mut projections: Vec<_> = predicates.projection_bounds().collect();
+ projections.sort_by_cached_key(|proj| {
+ cx.tcx().item_name(proj.item_def_id()).to_string()
+ });
+ if !args.is_empty() || !projections.is_empty() {
p!(generic_delimiters(|mut cx| {
- cx = cx.comma_sep(args)?;
- if arg0.is_some() && projection0.is_some() {
+ cx = cx.comma_sep(args.iter().copied())?;
+ if !args.is_empty() && !projections.is_empty() {
write!(cx, ", ")?;
}
- cx.comma_sep(projections)
+ cx.comma_sep(projections.iter().copied())
}));
}
}
diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
index 611ec6b00ef60..32fb10ce4a676 100644
--- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
+++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs
@@ -838,7 +838,20 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
obligation.param_env,
real_trait_pred_and_base_ty,
);
- if self.predicate_may_hold(&obligation) {
+ let sized_obligation = Obligation::new(
+ self.tcx,
+ obligation.cause.clone(),
+ obligation.param_env,
+ ty::TraitRef::from_lang_item(
+ self.tcx,
+ hir::LangItem::Sized,
+ obligation.cause.span,
+ [base_ty],
+ ),
+ );
+ if self.predicate_may_hold(&obligation)
+ && self.predicate_must_hold_modulo_regions(&sized_obligation)
+ {
let call_node = self.tcx.hir().get(*call_hir_id);
let msg = "consider dereferencing here";
let is_receiver = matches!(
diff --git a/tests/ui/traits/object/enforce-supertrait-projection.rs b/tests/ui/traits/object/enforce-supertrait-projection.rs
index 2c9b41eea2abe..0ea944ec2df55 100644
--- a/tests/ui/traits/object/enforce-supertrait-projection.rs
+++ b/tests/ui/traits/object/enforce-supertrait-projection.rs
@@ -7,7 +7,7 @@ trait Trait: SuperTrait::B> {}
fn transmute(x: A) -> B {
foo::>(x)
- //~^ ERROR type mismatch resolving ` as SuperTrait>::A == B`
+ //~^ ERROR type mismatch resolving ` as SuperTrait>::A == B`
}
fn foo(x: T::A) -> B
diff --git a/tests/ui/traits/object/enforce-supertrait-projection.stderr b/tests/ui/traits/object/enforce-supertrait-projection.stderr
index 848b4e69a4bb8..2fb94d348966a 100644
--- a/tests/ui/traits/object/enforce-supertrait-projection.stderr
+++ b/tests/ui/traits/object/enforce-supertrait-projection.stderr
@@ -1,4 +1,4 @@
-error[E0271]: type mismatch resolving ` as SuperTrait>::A == B`
+error[E0271]: type mismatch resolving ` as SuperTrait>::A == B`
--> $DIR/enforce-supertrait-projection.rs:9:17
|
LL | fn transmute(x: A) -> B {
diff --git a/tests/ui/traits/suggest-dereferences/dont-suggest-unsize-deref.rs b/tests/ui/traits/suggest-dereferences/dont-suggest-unsize-deref.rs
new file mode 100644
index 0000000000000..c6f9e3456186c
--- /dev/null
+++ b/tests/ui/traits/suggest-dereferences/dont-suggest-unsize-deref.rs
@@ -0,0 +1,15 @@
+fn use_iterator(itr: I)
+where
+ I: IntoIterator- ,
+{
+}
+
+fn pass_iterator(i: &dyn IntoIterator
- )
+where
+ I: Iterator
- ,
+{
+ use_iterator(i);
+ //~^ ERROR `&dyn IntoIterator` is not an iterator
+}
+
+fn main() {}
diff --git a/tests/ui/traits/suggest-dereferences/dont-suggest-unsize-deref.stderr b/tests/ui/traits/suggest-dereferences/dont-suggest-unsize-deref.stderr
new file mode 100644
index 0000000000000..bd0e7ca2c02e5
--- /dev/null
+++ b/tests/ui/traits/suggest-dereferences/dont-suggest-unsize-deref.stderr
@@ -0,0 +1,22 @@
+error[E0277]: `&dyn IntoIterator` is not an iterator
+ --> $DIR/dont-suggest-unsize-deref.rs:11:18
+ |
+LL | use_iterator(i);
+ | ------------ ^ `&dyn IntoIterator` is not an iterator
+ | |
+ | required by a bound introduced by this call
+ |
+ = help: the trait `Iterator` is not implemented for `&dyn IntoIterator`
+ = note: required for `&dyn IntoIterator` to implement `IntoIterator`
+note: required by a bound in `use_iterator`
+ --> $DIR/dont-suggest-unsize-deref.rs:3:8
+ |
+LL | fn use_iterator(itr: I)
+ | ------------ required by a bound in this function
+LL | where
+LL | I: IntoIterator
- ,
+ | ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `use_iterator`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/traits/suggest-deferences/issue-39029.fixed b/tests/ui/traits/suggest-dereferences/issue-39029.fixed
similarity index 100%
rename from tests/ui/traits/suggest-deferences/issue-39029.fixed
rename to tests/ui/traits/suggest-dereferences/issue-39029.fixed
diff --git a/tests/ui/traits/suggest-deferences/issue-39029.rs b/tests/ui/traits/suggest-dereferences/issue-39029.rs
similarity index 100%
rename from tests/ui/traits/suggest-deferences/issue-39029.rs
rename to tests/ui/traits/suggest-dereferences/issue-39029.rs
diff --git a/tests/ui/traits/suggest-deferences/issue-39029.stderr b/tests/ui/traits/suggest-dereferences/issue-39029.stderr
similarity index 100%
rename from tests/ui/traits/suggest-deferences/issue-39029.stderr
rename to tests/ui/traits/suggest-dereferences/issue-39029.stderr
diff --git a/tests/ui/traits/suggest-deferences/issue-62530.fixed b/tests/ui/traits/suggest-dereferences/issue-62530.fixed
similarity index 100%
rename from tests/ui/traits/suggest-deferences/issue-62530.fixed
rename to tests/ui/traits/suggest-dereferences/issue-62530.fixed
diff --git a/tests/ui/traits/suggest-deferences/issue-62530.rs b/tests/ui/traits/suggest-dereferences/issue-62530.rs
similarity index 100%
rename from tests/ui/traits/suggest-deferences/issue-62530.rs
rename to tests/ui/traits/suggest-dereferences/issue-62530.rs
diff --git a/tests/ui/traits/suggest-deferences/issue-62530.stderr b/tests/ui/traits/suggest-dereferences/issue-62530.stderr
similarity index 100%
rename from tests/ui/traits/suggest-deferences/issue-62530.stderr
rename to tests/ui/traits/suggest-dereferences/issue-62530.stderr
diff --git a/tests/ui/traits/suggest-deferences/multiple-0.fixed b/tests/ui/traits/suggest-dereferences/multiple-0.fixed
similarity index 100%
rename from tests/ui/traits/suggest-deferences/multiple-0.fixed
rename to tests/ui/traits/suggest-dereferences/multiple-0.fixed
diff --git a/tests/ui/traits/suggest-deferences/multiple-0.rs b/tests/ui/traits/suggest-dereferences/multiple-0.rs
similarity index 100%
rename from tests/ui/traits/suggest-deferences/multiple-0.rs
rename to tests/ui/traits/suggest-dereferences/multiple-0.rs
diff --git a/tests/ui/traits/suggest-deferences/multiple-0.stderr b/tests/ui/traits/suggest-dereferences/multiple-0.stderr
similarity index 100%
rename from tests/ui/traits/suggest-deferences/multiple-0.stderr
rename to tests/ui/traits/suggest-dereferences/multiple-0.stderr
diff --git a/tests/ui/traits/suggest-deferences/multiple-1.rs b/tests/ui/traits/suggest-dereferences/multiple-1.rs
similarity index 100%
rename from tests/ui/traits/suggest-deferences/multiple-1.rs
rename to tests/ui/traits/suggest-dereferences/multiple-1.rs
diff --git a/tests/ui/traits/suggest-deferences/multiple-1.stderr b/tests/ui/traits/suggest-dereferences/multiple-1.stderr
similarity index 100%
rename from tests/ui/traits/suggest-deferences/multiple-1.stderr
rename to tests/ui/traits/suggest-dereferences/multiple-1.stderr
diff --git a/tests/ui/traits/suggest-deferences/root-obligation.fixed b/tests/ui/traits/suggest-dereferences/root-obligation.fixed
similarity index 100%
rename from tests/ui/traits/suggest-deferences/root-obligation.fixed
rename to tests/ui/traits/suggest-dereferences/root-obligation.fixed
diff --git a/tests/ui/traits/suggest-deferences/root-obligation.rs b/tests/ui/traits/suggest-dereferences/root-obligation.rs
similarity index 100%
rename from tests/ui/traits/suggest-deferences/root-obligation.rs
rename to tests/ui/traits/suggest-dereferences/root-obligation.rs
diff --git a/tests/ui/traits/suggest-deferences/root-obligation.stderr b/tests/ui/traits/suggest-dereferences/root-obligation.stderr
similarity index 100%
rename from tests/ui/traits/suggest-deferences/root-obligation.stderr
rename to tests/ui/traits/suggest-dereferences/root-obligation.stderr
diff --git a/tests/ui/traits/suggest-deferences/suggest-dereferencing-receiver-argument.fixed b/tests/ui/traits/suggest-dereferences/suggest-dereferencing-receiver-argument.fixed
similarity index 100%
rename from tests/ui/traits/suggest-deferences/suggest-dereferencing-receiver-argument.fixed
rename to tests/ui/traits/suggest-dereferences/suggest-dereferencing-receiver-argument.fixed
diff --git a/tests/ui/traits/suggest-deferences/suggest-dereferencing-receiver-argument.rs b/tests/ui/traits/suggest-dereferences/suggest-dereferencing-receiver-argument.rs
similarity index 100%
rename from tests/ui/traits/suggest-deferences/suggest-dereferencing-receiver-argument.rs
rename to tests/ui/traits/suggest-dereferences/suggest-dereferencing-receiver-argument.rs
diff --git a/tests/ui/traits/suggest-deferences/suggest-dereferencing-receiver-argument.stderr b/tests/ui/traits/suggest-dereferences/suggest-dereferencing-receiver-argument.stderr
similarity index 100%
rename from tests/ui/traits/suggest-deferences/suggest-dereferencing-receiver-argument.stderr
rename to tests/ui/traits/suggest-dereferences/suggest-dereferencing-receiver-argument.stderr