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

Resolve inconsistency in error messages between "parameter" and "variable". #60037

Merged
merged 1 commit into from
Apr 18, 2019
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
4 changes: 2 additions & 2 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,12 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver<'_>,
},
Def::TyParam(def_id) => {
if let Some(span) = resolver.definitions.opt_span(def_id) {
err.span_label(span, "type variable from outer function");
err.span_label(span, "type parameter from outer function");
}
}
Def::ConstParam(def_id) => {
if let Some(span) = resolver.definitions.opt_span(def_id) {
err.span_label(span, "const variable from outer function");
err.span_label(span, "const parameter from outer function");
}
}
_ => {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/bad/bad-type-env-capture.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0401]: can't use generic parameters from outer function
--> $DIR/bad-type-env-capture.rs:2:15
|
LL | fn foo<T>() {
| - type variable from outer function
| - type parameter from outer function
LL | fn bar(b: T) { }
| --- ^ use of generic parameter from outer function
| |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ error[E0401]: can't use generic parameters from outer function
--> $DIR/const-param-from-outer-fn.rs:6:9
|
LL | fn foo<const X: u32>() {
| - const variable from outer function
| - const parameter from outer function
LL | fn bar() -> u32 {
| --- try adding a local generic parameter in this method instead
LL | X
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/error-codes/E0401.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0401]: can't use generic parameters from outer function
--> $DIR/E0401.rs:4:39
|
LL | fn foo<T>(x: T) {
| - type variable from outer function
| - type parameter from outer function
LL | fn bfnr<U, V: Baz<U>, W: Fn()>(y: T) {
| --------------------------- ^ use of generic parameter from outer function
| |
Expand All @@ -12,7 +12,7 @@ error[E0401]: can't use generic parameters from outer function
--> $DIR/E0401.rs:9:16
|
LL | fn foo<T>(x: T) {
| - type variable from outer function
| - type parameter from outer function
...
LL | fn baz<U,
| --- try adding a local generic parameter in this method instead
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/inner-static-type-parameter.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0401]: can't use generic parameters from outer function
--> $DIR/inner-static-type-parameter.rs:6:19
|
LL | fn foo<T>() {
| --- - type variable from outer function
| --- - type parameter from outer function
| |
| try adding a local generic parameter in this method instead
LL | static a: Bar<T> = Bar::What;
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/issues/issue-3021-c.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0401]: can't use generic parameters from outer function
--> $DIR/issue-3021-c.rs:4:24
|
LL | fn siphash<T>() {
| - type variable from outer function
| - type parameter from outer function
...
LL | fn g(&self, x: T) -> T;
| - ^ use of generic parameter from outer function
Expand All @@ -13,7 +13,7 @@ error[E0401]: can't use generic parameters from outer function
--> $DIR/issue-3021-c.rs:4:30
|
LL | fn siphash<T>() {
| - type variable from outer function
| - type parameter from outer function
...
LL | fn g(&self, x: T) -> T;
| - ^ use of generic parameter from outer function
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-3214.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0401]: can't use generic parameters from outer function
--> $DIR/issue-3214.rs:3:12
|
LL | fn foo<T>() {
| --- - type variable from outer function
| --- - type parameter from outer function
| |
| try adding a local generic parameter in this method instead
LL | struct Foo {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-5997-enum.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0401]: can't use generic parameters from outer function
--> $DIR/issue-5997-enum.rs:2:16
|
LL | fn f<Z>() -> bool {
| - - type variable from outer function
| - - type parameter from outer function
| |
| try adding a local generic parameter in this method instead
LL | enum E { V(Z) }
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-5997-struct.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0401]: can't use generic parameters from outer function
--> $DIR/issue-5997-struct.rs:2:14
|
LL | fn f<T>() -> bool {
| - - type variable from outer function
| - - type parameter from outer function
| |
| try adding a local generic parameter in this method instead
LL | struct S(T);
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/nested-ty-params.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0401]: can't use generic parameters from outer function
--> $DIR/nested-ty-params.rs:3:16
|
LL | fn hd<U>(v: Vec<U> ) -> U {
| - type variable from outer function
| - type parameter from outer function
LL | fn hd1(w: [U]) -> U { return w[0]; }
| --- ^ use of generic parameter from outer function
| |
Expand All @@ -12,7 +12,7 @@ error[E0401]: can't use generic parameters from outer function
--> $DIR/nested-ty-params.rs:3:23
|
LL | fn hd<U>(v: Vec<U> ) -> U {
| - type variable from outer function
| - type parameter from outer function
LL | fn hd1(w: [U]) -> U { return w[0]; }
| --- ^ use of generic parameter from outer function
| |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0401]: can't use generic parameters from outer function
--> $DIR/resolve-type-param-in-item-in-trait.rs:8:22
|
LL | trait TraitA<A> {
| - type variable from outer function
| - type parameter from outer function
LL | fn outer(&self) {
| ----- try adding a local generic parameter in this method instead
LL | enum Foo<B> {
Expand All @@ -13,7 +13,7 @@ error[E0401]: can't use generic parameters from outer function
--> $DIR/resolve-type-param-in-item-in-trait.rs:16:23
|
LL | trait TraitB<A> {
| - type variable from outer function
| - type parameter from outer function
LL | fn outer(&self) {
| ----- try adding a local generic parameter in this method instead
LL | struct Foo<B>(A);
Expand All @@ -23,7 +23,7 @@ error[E0401]: can't use generic parameters from outer function
--> $DIR/resolve-type-param-in-item-in-trait.rs:23:28
|
LL | trait TraitC<A> {
| - type variable from outer function
| - type parameter from outer function
Copy link
Contributor

Choose a reason for hiding this comment

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

The diagnostic makes no sense here as there's no outer function, just an outer trait.

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe there's already a ticket for this case.

Copy link
Contributor

Choose a reason for hiding this comment

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

@estebank can you cc it perhaps?

Copy link
Contributor

@estebank estebank Apr 17, 2019

Choose a reason for hiding this comment

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

CC #37892, #56794, #53241. I believe there's another one but couldn't find it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks; I skimmed those issues and they all seem a bit different. I think the fix for this one is to customize the diagnostic based on what the parent def_id refers to... e.g. say "function" if it is one, and "trait" if it is one...

LL | fn outer(&self) {
| ----- try adding a local generic parameter in this method instead
LL | struct Foo<B> { a: A }
Expand All @@ -33,7 +33,7 @@ error[E0401]: can't use generic parameters from outer function
--> $DIR/resolve-type-param-in-item-in-trait.rs:30:22
|
LL | trait TraitD<A> {
| - type variable from outer function
| - type parameter from outer function
LL | fn outer(&self) {
LL | fn foo<B>(a: A) { }
| ------ ^ use of generic parameter from outer function
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/type/type-arg-out-of-scope.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0401]: can't use generic parameters from outer function
--> $DIR/type-arg-out-of-scope.rs:3:25
|
LL | fn foo<T>(x: T) {
| - type variable from outer function
| - type parameter from outer function
LL | fn bar(f: Box<FnMut(T) -> T>) { }
| --- ^ use of generic parameter from outer function
| |
Expand All @@ -12,7 +12,7 @@ error[E0401]: can't use generic parameters from outer function
--> $DIR/type-arg-out-of-scope.rs:3:31
|
LL | fn foo<T>(x: T) {
| - type variable from outer function
| - type parameter from outer function
LL | fn bar(f: Box<FnMut(T) -> T>) { }
| --- ^ use of generic parameter from outer function
| |
Expand Down