Skip to content

Commit 36b60e7

Browse files
committed
Use with_forced_trimmed_paths more
1 parent 10368c6 commit 36b60e7

File tree

10 files changed

+34
-29
lines changed

10 files changed

+34
-29
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+21-16
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use rustc_middle::traits::select::OverflowError;
3535
use rustc_middle::ty::abstract_const::NotConstEvaluatable;
3636
use rustc_middle::ty::error::ExpectedFound;
3737
use rustc_middle::ty::fold::{TypeFolder, TypeSuperFoldable};
38-
use rustc_middle::ty::print::{FmtPrinter, Print};
38+
use rustc_middle::ty::print::{with_forced_trimmed_paths, FmtPrinter, Print};
3939
use rustc_middle::ty::{
4040
self, SubtypePredicate, ToPolyTraitRef, ToPredicate, TraitRef, Ty, TyCtxt, TypeFoldable,
4141
TypeVisitable,
@@ -1749,21 +1749,26 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
17491749
let trait_def_id = pred.projection_ty.trait_def_id(self.tcx);
17501750
let self_ty = pred.projection_ty.self_ty();
17511751

1752-
if Some(pred.projection_ty.def_id) == self.tcx.lang_items().fn_once_output() {
1753-
Some(format!(
1754-
"expected `{self_ty}` to be a {fn_kind} that returns `{expected_ty}`, but it returns `{normalized_ty}`",
1755-
fn_kind = self_ty.prefix_string(self.tcx)
1756-
))
1757-
} else if Some(trait_def_id) == self.tcx.lang_items().future_trait() {
1758-
Some(format!(
1759-
"expected `{self_ty}` to be a future that resolves to `{expected_ty}`, but it resolves to `{normalized_ty}`"
1760-
))
1761-
} else if Some(trait_def_id) == self.tcx.get_diagnostic_item(sym::Iterator) {
1762-
Some(format!(
1763-
"expected `{self_ty}` to be an iterator that yields `{expected_ty}`, but it yields `{normalized_ty}`"
1764-
))
1765-
} else {
1766-
None
1752+
with_forced_trimmed_paths! {
1753+
if Some(pred.projection_ty.def_id) == self.tcx.lang_items().fn_once_output() {
1754+
Some(format!(
1755+
"expected `{self_ty}` to be a {fn_kind} that returns `{expected_ty}`, but it \
1756+
returns `{normalized_ty}`",
1757+
fn_kind = self_ty.prefix_string(self.tcx)
1758+
))
1759+
} else if Some(trait_def_id) == self.tcx.lang_items().future_trait() {
1760+
Some(format!(
1761+
"expected `{self_ty}` to be a future that resolves to `{expected_ty}`, but it \
1762+
resolves to `{normalized_ty}`"
1763+
))
1764+
} else if Some(trait_def_id) == self.tcx.get_diagnostic_item(sym::Iterator) {
1765+
Some(format!(
1766+
"expected `{self_ty}` to be an iterator that yields `{expected_ty}`, but it \
1767+
yields `{normalized_ty}`"
1768+
))
1769+
} else {
1770+
None
1771+
}
17671772
}
17681773
}
17691774

src/test/ui/associated-types/associated-types-overridden-binding-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ trait I32Iterator = Iterator<Item = i32>;
44

55
fn main() {
66
let _: &dyn I32Iterator<Item = u32> = &vec![42].into_iter();
7-
//~^ ERROR expected `std::vec::IntoIter<u32>` to be an iterator that yields `i32`, but it yields `u32`
7+
//~^ ERROR expected `IntoIter<u32>` to be an iterator that yields `i32`, but it yields `u32`
88
}

src/test/ui/associated-types/associated-types-overridden-binding-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0271]: expected `std::vec::IntoIter<u32>` to be an iterator that yields `i32`, but it yields `u32`
1+
error[E0271]: expected `IntoIter<u32>` to be an iterator that yields `i32`, but it yields `u32`
22
--> $DIR/associated-types-overridden-binding-2.rs:6:43
33
|
44
LL | let _: &dyn I32Iterator<Item = u32> = &vec![42].into_iter();

src/test/ui/issues/issue-31173.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0271]: expected `TakeWhile<&mut std::vec::IntoIter<u8>, [closure@$DIR/issue-31173.rs:7:21: 7:25]>` to be an iterator that yields `&_`, but it yields `u8`
1+
error[E0271]: expected `TakeWhile<&mut IntoIter<u8>, [closure@$DIR/issue-31173.rs:7:21: 7:25]>` to be an iterator that yields `&_`, but it yields `u8`
22
--> $DIR/issue-31173.rs:11:10
33
|
44
LL | .cloned()

src/test/ui/issues/issue-33941.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use std::collections::HashMap;
44

55
fn main() {
6-
for _ in HashMap::new().iter().cloned() {} //~ ERROR expected `std::collections::hash_map::Iter<'_, _, _>` to be an iterator that yields `&_`, but it yields `(&_, &_)`
7-
//~^ ERROR expected `std::collections::hash_map::Iter<'_, _, _>` to be an iterator that yields `&_`, but it yields `(&_, &_)`
8-
//~| ERROR expected `std::collections::hash_map::Iter<'_, _, _>` to be an iterator that yields `&_`, but it yields `(&_, &_)`
6+
for _ in HashMap::new().iter().cloned() {} //~ ERROR expected `Iter<'_, _, _>` to be an iterator that yields `&_`, but it yields `(&_, &_)`
7+
//~^ ERROR expected `Iter<'_, _, _>` to be an iterator that yields `&_`, but it yields `(&_, &_)`
8+
//~| ERROR expected `Iter<'_, _, _>` to be an iterator that yields `&_`, but it yields `(&_, &_)`
99
}

src/test/ui/issues/issue-33941.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0271]: expected `std::collections::hash_map::Iter<'_, _, _>` to be an iterator that yields `&_`, but it yields `(&_, &_)`
1+
error[E0271]: expected `Iter<'_, _, _>` to be an iterator that yields `&_`, but it yields `(&_, &_)`
22
--> $DIR/issue-33941.rs:6:36
33
|
44
LL | for _ in HashMap::new().iter().cloned() {}
@@ -16,7 +16,7 @@ LL | for _ in HashMap::new().iter().cloned() {}
1616
note: required by a bound in `cloned`
1717
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
1818

19-
error[E0271]: expected `std::collections::hash_map::Iter<'_, _, _>` to be an iterator that yields `&_`, but it yields `(&_, &_)`
19+
error[E0271]: expected `Iter<'_, _, _>` to be an iterator that yields `&_`, but it yields `(&_, &_)`
2020
--> $DIR/issue-33941.rs:6:14
2121
|
2222
LL | for _ in HashMap::new().iter().cloned() {}
@@ -27,7 +27,7 @@ LL | for _ in HashMap::new().iter().cloned() {}
2727
= note: required for `Cloned<std::collections::hash_map::Iter<'_, _, _>>` to implement `Iterator`
2828
= note: required for `Cloned<std::collections::hash_map::Iter<'_, _, _>>` to implement `IntoIterator`
2929

30-
error[E0271]: expected `std::collections::hash_map::Iter<'_, _, _>` to be an iterator that yields `&_`, but it yields `(&_, &_)`
30+
error[E0271]: expected `Iter<'_, _, _>` to be an iterator that yields `&_`, but it yields `(&_, &_)`
3131
--> $DIR/issue-33941.rs:6:14
3232
|
3333
LL | for _ in HashMap::new().iter().cloned() {}

src/test/ui/traits/assoc-type-in-superbad.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub trait Foo: Iterator<Item = <Self as Foo>::Key> {
1010

1111
impl Foo for IntoIter<i32> {
1212
type Key = u32;
13-
//~^ ERROR expected `std::vec::IntoIter<i32>` to be an iterator that yields `u32`, but it yields `i32`
13+
//~^ ERROR expected `IntoIter<i32>` to be an iterator that yields `u32`, but it yields `i32`
1414
}
1515

1616
fn main() {}

src/test/ui/traits/assoc-type-in-superbad.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0271]: expected `std::vec::IntoIter<i32>` to be an iterator that yields `u32`, but it yields `i32`
1+
error[E0271]: expected `IntoIter<i32>` to be an iterator that yields `u32`, but it yields `i32`
22
--> $DIR/assoc-type-in-superbad.rs:12:16
33
|
44
LL | type Key = u32;

src/test/ui/type-alias-impl-trait/issue-57961.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ trait Foo {
88

99
impl Foo for () {
1010
type Bar = std::vec::IntoIter<u32>;
11-
//~^ ERROR expected `std::vec::IntoIter<u32>` to be an iterator that yields `X`, but it yields `u32`
11+
//~^ ERROR expected `IntoIter<u32>` to be an iterator that yields `X`, but it yields `u32`
1212
}
1313

1414
fn incoherent() {

src/test/ui/type-alias-impl-trait/issue-57961.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0271]: expected `std::vec::IntoIter<u32>` to be an iterator that yields `X`, but it yields `u32`
1+
error[E0271]: expected `IntoIter<u32>` to be an iterator that yields `X`, but it yields `u32`
22
--> $DIR/issue-57961.rs:10:16
33
|
44
LL | type X = impl Sized;

0 commit comments

Comments
 (0)