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

Note scope of TAIT more accurately #103383

Merged
merged 1 commit into from
Oct 29, 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
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ hir_analysis_expected_default_return_type = expected `()` because of default ret
hir_analysis_expected_return_type = expected `{$expected}` because of return type

hir_analysis_unconstrained_opaque_type = unconstrained opaque type
.note = `{$name}` must be used in combination with a concrete type within the same module
.note = `{$name}` must be used in combination with a concrete type within the same {$what}

hir_analysis_missing_type_params =
the type {$parameterCount ->
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_hir_analysis/src/collect/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,12 @@ fn find_opaque_ty_constraints_for_tait(tcx: TyCtxt<'_>, def_id: LocalDefId) -> T
tcx.sess.emit_err(UnconstrainedOpaqueType {
span: tcx.def_span(def_id),
name: tcx.item_name(tcx.local_parent(def_id).to_def_id()),
what: match tcx.hir().get(scope) {
_ if scope == hir::CRATE_HIR_ID => "module",
Node::Item(hir::Item { kind: hir::ItemKind::Mod(_), .. }) => "module",
Node::Item(hir::Item { kind: hir::ItemKind::Impl(_), .. }) => "impl",
_ => "item",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how to test this. Of would require mentioning the TAIT outside of a function body where it's defined. Maybe span_bug it?

Copy link
Member Author

@compiler-errors compiler-errors Oct 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you talking about the "item" arm specifically? This is an example of where it would now print "item":

#![feature(type_alias_impl_trait)]

fn foo() {
    type Tait = impl Sized;
}

I guess I could make it specifically match a few more cases where we are allowed by the grammar to place TAITs like function bodies, and then span_bug the rest?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right... it maybe useful to special case all of these (e.g. the crate root mentioning the same crate (can we even get that error?))

But this is already correct now, so let's merge it

},
});
return tcx.ty_error();
};
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir_analysis/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ pub struct UnconstrainedOpaqueType {
#[primary_span]
pub span: Span,
pub name: Symbol,
pub what: &'static str,
}

pub struct MissingTypeParams {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/generic-associated-types/issue-87258_a.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error: unconstrained opaque type
LL | type FooFuture<'a> = impl Trait1;
| ^^^^^^^^^^^
|
= note: `FooFuture` must be used in combination with a concrete type within the same module
= note: `FooFuture` must be used in combination with a concrete type within the same impl

error: aborting due to previous error

2 changes: 1 addition & 1 deletion src/test/ui/lint/inline-trait-and-foreign-items.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ error: unconstrained opaque type
LL | type U = impl Trait;
| ^^^^^^^^^^
|
= note: `U` must be used in combination with a concrete type within the same module
= note: `U` must be used in combination with a concrete type within the same impl

error: aborting due to 6 previous errors; 2 warnings emitted

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/lint/no-coverage.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ error: unconstrained opaque type
LL | type U = impl Trait;
| ^^^^^^^^^^
|
= note: `U` must be used in combination with a concrete type within the same module
= note: `U` must be used in combination with a concrete type within the same impl

error: aborting due to 7 previous errors; 6 warnings emitted

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/save-analysis/issue-68621.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error: unconstrained opaque type
LL | type Future = impl Trait;
| ^^^^^^^^^^
|
= note: `Future` must be used in combination with a concrete type within the same module
= note: `Future` must be used in combination with a concrete type within the same impl

error: aborting due to previous error