Skip to content

resolve: Simplify some diagnostic code to avoid an ICE #95350

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 1 commit into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 4 additions & 17 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,14 +696,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
) = &bounded_ty.kind
{
// use this to verify that ident is a type param.
let Ok(Some(partial_res)) = self.resolve_qpath_anywhere(
None,
&Segment::from_path(path),
Namespace::TypeNS,
span,
true,
Finalize::No,
) else {
let Some(partial_res) = self.r.partial_res_map.get(&bounded_ty.id) else {
return false;
};
if !(matches!(
Expand All @@ -718,16 +711,10 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
return false;
};

if let ast::TyKind::Path(None, type_param_path) = &ty.peel_refs().kind {
let peeled_ty = ty.peel_refs();
if let ast::TyKind::Path(None, type_param_path) = &peeled_ty.kind {
// Confirm that the `SelfTy` is a type parameter.
let Ok(Some(partial_res)) = self.resolve_qpath_anywhere(
None,
&Segment::from_path(type_param_path),
Namespace::TypeNS,
span,
true,
Finalize::No,
) else {
let Some(partial_res) = self.r.partial_res_map.get(&peeled_ty.id) else {
return false;
};
if !(matches!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ fn foo<T: Bar>(_: T) where <T as Bar>::Baz: String { //~ ERROR expected trait, f
fn qux<'a, T: Bar>(_: &'a T) where <&'a T as Bar>::Baz: String { //~ ERROR expected trait, found
}

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

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
error[E0433]: failed to resolve: use of undeclared type `Unresolved`
--> $DIR/assoc_type_bound_with_struct.rs:19:31
|
LL | fn issue_95327() where <u8 as Unresolved>::Assoc: String {}
| ^^^^^^^^^^ use of undeclared type `Unresolved`

error[E0404]: expected trait, found struct `String`
--> $DIR/assoc_type_bound_with_struct.rs:5:46
|
Expand Down Expand Up @@ -78,6 +84,18 @@ help: a trait with a similar name exists
LL | fn qux<'a, T: Bar>(_: &'a T) where <&'a T as Bar>::Baz: ToString {
| ~~~~~~~~

error: aborting due to 4 previous errors
error[E0404]: expected trait, found struct `String`
--> $DIR/assoc_type_bound_with_struct.rs:19:51
|
LL | fn issue_95327() where <u8 as Unresolved>::Assoc: String {}
| ^^^^^^ help: a trait with a similar name exists: `ToString`
|
::: $SRC_DIR/alloc/src/string.rs:LL:COL
|
LL | pub trait ToString {
| ------------------ similarly named trait `ToString` defined here

error: aborting due to 6 previous errors

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