Skip to content

Commit 4dd9567

Browse files
authored
Rollup merge of #95350 - petrochenkov:qpathregr, r=cjgillot
resolve: Simplify some diagnostic code to avoid an ICE No need to resolve those paths, they are already resolved, we just need to take the results from `partial_res_map`. Fixes #95327
2 parents 4651c8d + a7d7a26 commit 4dd9567

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

compiler/rustc_resolve/src/late/diagnostics.rs

+4-17
Original file line numberDiff line numberDiff line change
@@ -696,14 +696,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
696696
) = &bounded_ty.kind
697697
{
698698
// use this to verify that ident is a type param.
699-
let Ok(Some(partial_res)) = self.resolve_qpath_anywhere(
700-
None,
701-
&Segment::from_path(path),
702-
Namespace::TypeNS,
703-
span,
704-
true,
705-
Finalize::No,
706-
) else {
699+
let Some(partial_res) = self.r.partial_res_map.get(&bounded_ty.id) else {
707700
return false;
708701
};
709702
if !(matches!(
@@ -718,16 +711,10 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
718711
return false;
719712
};
720713

721-
if let ast::TyKind::Path(None, type_param_path) = &ty.peel_refs().kind {
714+
let peeled_ty = ty.peel_refs();
715+
if let ast::TyKind::Path(None, type_param_path) = &peeled_ty.kind {
722716
// Confirm that the `SelfTy` is a type parameter.
723-
let Ok(Some(partial_res)) = self.resolve_qpath_anywhere(
724-
None,
725-
&Segment::from_path(type_param_path),
726-
Namespace::TypeNS,
727-
span,
728-
true,
729-
Finalize::No,
730-
) else {
717+
let Some(partial_res) = self.r.partial_res_map.get(&peeled_ty.id) else {
731718
return false;
732719
};
733720
if !(matches!(

src/test/ui/traits/associated_type_bound/assoc_type_bound_with_struct.rs

+4
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ fn foo<T: Bar>(_: T) where <T as Bar>::Baz: String { //~ ERROR expected trait, f
1616
fn qux<'a, T: Bar>(_: &'a T) where <&'a T as Bar>::Baz: String { //~ ERROR expected trait, found
1717
}
1818

19+
fn issue_95327() where <u8 as Unresolved>::Assoc: String {}
20+
//~^ ERROR expected trait, found struct
21+
//~| ERROR use of undeclared type `Unresolved`
22+
1923
fn main() {}

src/test/ui/traits/associated_type_bound/assoc_type_bound_with_struct.stderr

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
error[E0433]: failed to resolve: use of undeclared type `Unresolved`
2+
--> $DIR/assoc_type_bound_with_struct.rs:19:31
3+
|
4+
LL | fn issue_95327() where <u8 as Unresolved>::Assoc: String {}
5+
| ^^^^^^^^^^ use of undeclared type `Unresolved`
6+
17
error[E0404]: expected trait, found struct `String`
28
--> $DIR/assoc_type_bound_with_struct.rs:5:46
39
|
@@ -78,6 +84,18 @@ help: a trait with a similar name exists
7884
LL | fn qux<'a, T: Bar>(_: &'a T) where <&'a T as Bar>::Baz: ToString {
7985
| ~~~~~~~~
8086

81-
error: aborting due to 4 previous errors
87+
error[E0404]: expected trait, found struct `String`
88+
--> $DIR/assoc_type_bound_with_struct.rs:19:51
89+
|
90+
LL | fn issue_95327() where <u8 as Unresolved>::Assoc: String {}
91+
| ^^^^^^ help: a trait with a similar name exists: `ToString`
92+
|
93+
::: $SRC_DIR/alloc/src/string.rs:LL:COL
94+
|
95+
LL | pub trait ToString {
96+
| ------------------ similarly named trait `ToString` defined here
97+
98+
error: aborting due to 6 previous errors
8299

83-
For more information about this error, try `rustc --explain E0404`.
100+
Some errors have detailed explanations: E0404, E0433.
101+
For more information about an error, try `rustc --explain E0404`.

0 commit comments

Comments
 (0)