From 4cedbfc6ee8ef3d35abc22c69903ab3b9573939f Mon Sep 17 00:00:00 2001 From: Gauri Date: Sat, 13 Jan 2018 11:59:35 +0530 Subject: [PATCH 1/6] fix mispositioned span --- src/librustc_errors/emitter.rs | 2 +- src/test/ui/lint/use_suggestion_json.stderr | 67 +-------------------- 2 files changed, 2 insertions(+), 67 deletions(-) diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index af556c576c035..ae0766eeeefc3 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -1187,7 +1187,7 @@ impl EmitterWriter { let sub_len = parts[0].snippet.trim().chars().fold(0, |acc, ch| { acc + unicode_width::UnicodeWidthChar::width(ch).unwrap_or(0) }); - let underline_start = span_start_pos.col.0 + start; + let underline_start = span_start_pos.col_display + start; let underline_end = span_start_pos.col.0 + start + sub_len; for p in underline_start..underline_end { buffer.putc(row_num, diff --git a/src/test/ui/lint/use_suggestion_json.stderr b/src/test/ui/lint/use_suggestion_json.stderr index 86c2ad4c0e7a4..abbf3da513a6f 100644 --- a/src/test/ui/lint/use_suggestion_json.stderr +++ b/src/test/ui/lint/use_suggestion_json.stderr @@ -2,72 +2,7 @@ "message": "cannot find type `Iter` in this scope", "code": { "code": "E0412", - "explanation": " -The type name used is not in scope. - -Erroneous code examples: - -```compile_fail,E0412 -impl Something {} // error: type name `Something` is not in scope - -// or: - -trait Foo { - fn bar(N); // error: type name `N` is not in scope -} - -// or: - -fn foo(x: T) {} // type name `T` is not in scope -``` - -To fix this error, please verify you didn't misspell the type name, you did -declare it or imported it into the scope. Examples: - -``` -struct Something; - -impl Something {} // ok! - -// or: - -trait Foo { - type N; - - fn bar(_: Self::N); // ok! -} - -// or: - -fn foo(x: T) {} // ok! -``` - -Another case that causes this error is when a type is imported into a parent -module. To fix this, you can follow the suggestion and use File directly or -`use super::File;` which will import the types from the parent namespace. An -example that causes this error is below: - -```compile_fail,E0412 -use std::fs::File; - -mod foo { - fn some_function(f: File) {} -} -``` - -``` -use std::fs::File; - -mod foo { - // either - use super::File; - // or - // use std::fs::File; - fn foo(f: File) {} -} -# fn main() {} // don't insert it for us; that'll break imports -``` -" + "explanation": null }, "level": "error", "spans": [ From eb1ada27816df80170f5d33753b9ea2049483e82 Mon Sep 17 00:00:00 2001 From: Gauri Date: Sat, 13 Jan 2018 13:33:10 +0530 Subject: [PATCH 2/6] revert changes to ui test --- src/test/ui/lint/use_suggestion_json.stderr | 67 ++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/src/test/ui/lint/use_suggestion_json.stderr b/src/test/ui/lint/use_suggestion_json.stderr index abbf3da513a6f..86c2ad4c0e7a4 100644 --- a/src/test/ui/lint/use_suggestion_json.stderr +++ b/src/test/ui/lint/use_suggestion_json.stderr @@ -2,7 +2,72 @@ "message": "cannot find type `Iter` in this scope", "code": { "code": "E0412", - "explanation": null + "explanation": " +The type name used is not in scope. + +Erroneous code examples: + +```compile_fail,E0412 +impl Something {} // error: type name `Something` is not in scope + +// or: + +trait Foo { + fn bar(N); // error: type name `N` is not in scope +} + +// or: + +fn foo(x: T) {} // type name `T` is not in scope +``` + +To fix this error, please verify you didn't misspell the type name, you did +declare it or imported it into the scope. Examples: + +``` +struct Something; + +impl Something {} // ok! + +// or: + +trait Foo { + type N; + + fn bar(_: Self::N); // ok! +} + +// or: + +fn foo(x: T) {} // ok! +``` + +Another case that causes this error is when a type is imported into a parent +module. To fix this, you can follow the suggestion and use File directly or +`use super::File;` which will import the types from the parent namespace. An +example that causes this error is below: + +```compile_fail,E0412 +use std::fs::File; + +mod foo { + fn some_function(f: File) {} +} +``` + +``` +use std::fs::File; + +mod foo { + // either + use super::File; + // or + // use std::fs::File; + fn foo(f: File) {} +} +# fn main() {} // don't insert it for us; that'll break imports +``` +" }, "level": "error", "spans": [ From 3c8c5051b18c604a4a1c0a01a6515ff3852341e1 Mon Sep 17 00:00:00 2001 From: Gauri Date: Sat, 13 Jan 2018 17:13:18 +0530 Subject: [PATCH 3/6] add ui test --- src/librustc_errors/emitter.rs | 2 +- src/test/ui/issue-47377-1.rs | 14 ++++++++++++++ src/test/ui/issue-47377-1.stderr | 12 ++++++++++++ src/test/ui/issue-47377.rs | 14 ++++++++++++++ src/test/ui/issue-47377.stderr | 12 ++++++++++++ 5 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/issue-47377-1.rs create mode 100644 src/test/ui/issue-47377-1.stderr create mode 100644 src/test/ui/issue-47377.rs create mode 100644 src/test/ui/issue-47377.stderr diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index ae0766eeeefc3..84d5a8df4adbe 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -1188,7 +1188,7 @@ impl EmitterWriter { acc + unicode_width::UnicodeWidthChar::width(ch).unwrap_or(0) }); let underline_start = span_start_pos.col_display + start; - let underline_end = span_start_pos.col.0 + start + sub_len; + let underline_end = span_start_pos.col_display + start + sub_len; for p in underline_start..underline_end { buffer.putc(row_num, max_line_num_len + 3 + p, diff --git a/src/test/ui/issue-47377-1.rs b/src/test/ui/issue-47377-1.rs new file mode 100644 index 0000000000000..f173d0096381b --- /dev/null +++ b/src/test/ui/issue-47377-1.rs @@ -0,0 +1,14 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main(){ + let b = "hello"; + println!("🦀🦀🦀🦀🦀"); let _a = b + ", World!"; //~ERROR 13:37: 13:51: binary operation `+` cannot be applied to type `&str` [E0369] +} \ No newline at end of file diff --git a/src/test/ui/issue-47377-1.stderr b/src/test/ui/issue-47377-1.stderr new file mode 100644 index 0000000000000..aad5373ae00dd --- /dev/null +++ b/src/test/ui/issue-47377-1.stderr @@ -0,0 +1,12 @@ +error[E0369]: binary operation `+` cannot be applied to type `&str` + --> $DIR/issue-47377-1.rs:13:37 + | +13 | println!("🦀🦀🦀🦀🦀"); let _a = b + ", World!"; //~ERROR 13:37: 13:51: binary operation `+` cannot be applied to type `&str` [E0369] + | ^^^^^^^^^^^^^^ `+` can't be used to concatenate two `&str` strings +help: `to_owned()` can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left + | +13 | println!("🦀🦀🦀🦀🦀"); let _a = b.to_owned() + ", World!"; //~ERROR 13:37: 13:51: binary operation `+` cannot be applied to type `&str` [E0369] + | ^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/issue-47377.rs b/src/test/ui/issue-47377.rs new file mode 100644 index 0000000000000..2a8f2e30c0e88 --- /dev/null +++ b/src/test/ui/issue-47377.rs @@ -0,0 +1,14 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main(){ + let b = "hello"; + let _a = b + ", World!"; //~ERROR 13:14: 13:28: binary operation `+` cannot be applied to type `&str` [E0369] +} \ No newline at end of file diff --git a/src/test/ui/issue-47377.stderr b/src/test/ui/issue-47377.stderr new file mode 100644 index 0000000000000..e9f285a19c3d9 --- /dev/null +++ b/src/test/ui/issue-47377.stderr @@ -0,0 +1,12 @@ +error[E0369]: binary operation `+` cannot be applied to type `&str` + --> $DIR/issue-47377.rs:13:14 + | +13 | let _a = b + ", World!"; //~ERROR 13:14: 13:28: binary operation `+` cannot be applied to type `&str` [E0369] + | ^^^^^^^^^^^^^^ `+` can't be used to concatenate two `&str` strings +help: `to_owned()` can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left + | +13 | let _a = b.to_owned() + ", World!"; //~ERROR 13:14: 13:28: binary operation `+` cannot be applied to type `&str` [E0369] + | ^^^^^^^^^^^^ + +error: aborting due to previous error + From d769539f428fb48ea9bb0f8c703b805eb9664fee Mon Sep 17 00:00:00 2001 From: Gauri Date: Wed, 17 Jan 2018 01:31:21 +0530 Subject: [PATCH 4/6] fix tidy checks --- src/test/ui/issue-47377-1.stderr | 12 ------------ src/test/ui/issue-47377.rs | 6 +++--- src/test/ui/issue-47377.stderr | 6 +++--- src/test/ui/{issue-47377-1.rs => issue-47380.rs} | 7 ++++--- src/test/ui/issue-47380.stderr | 12 ++++++++++++ 5 files changed, 22 insertions(+), 21 deletions(-) delete mode 100644 src/test/ui/issue-47377-1.stderr rename src/test/ui/{issue-47377-1.rs => issue-47380.rs} (76%) create mode 100644 src/test/ui/issue-47380.stderr diff --git a/src/test/ui/issue-47377-1.stderr b/src/test/ui/issue-47377-1.stderr deleted file mode 100644 index aad5373ae00dd..0000000000000 --- a/src/test/ui/issue-47377-1.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0369]: binary operation `+` cannot be applied to type `&str` - --> $DIR/issue-47377-1.rs:13:37 - | -13 | println!("🦀🦀🦀🦀🦀"); let _a = b + ", World!"; //~ERROR 13:37: 13:51: binary operation `+` cannot be applied to type `&str` [E0369] - | ^^^^^^^^^^^^^^ `+` can't be used to concatenate two `&str` strings -help: `to_owned()` can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left - | -13 | println!("🦀🦀🦀🦀🦀"); let _a = b.to_owned() + ", World!"; //~ERROR 13:37: 13:51: binary operation `+` cannot be applied to type `&str` [E0369] - | ^^^^^^^^^^^^ - -error: aborting due to previous error - diff --git a/src/test/ui/issue-47377.rs b/src/test/ui/issue-47377.rs index 2a8f2e30c0e88..f2e18590ddef5 100644 --- a/src/test/ui/issue-47377.rs +++ b/src/test/ui/issue-47377.rs @@ -7,8 +7,8 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. - fn main(){ let b = "hello"; - let _a = b + ", World!"; //~ERROR 13:14: 13:28: binary operation `+` cannot be applied to type `&str` [E0369] -} \ No newline at end of file + let _a = b + ", World!"; + //~^ ERROR E0369 +} diff --git a/src/test/ui/issue-47377.stderr b/src/test/ui/issue-47377.stderr index e9f285a19c3d9..b80867f1714a0 100644 --- a/src/test/ui/issue-47377.stderr +++ b/src/test/ui/issue-47377.stderr @@ -1,11 +1,11 @@ error[E0369]: binary operation `+` cannot be applied to type `&str` - --> $DIR/issue-47377.rs:13:14 + --> $DIR/issue-47377.rs:12:14 | -13 | let _a = b + ", World!"; //~ERROR 13:14: 13:28: binary operation `+` cannot be applied to type `&str` [E0369] +12 | let _a = b + ", World!"; | ^^^^^^^^^^^^^^ `+` can't be used to concatenate two `&str` strings help: `to_owned()` can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left | -13 | let _a = b.to_owned() + ", World!"; //~ERROR 13:14: 13:28: binary operation `+` cannot be applied to type `&str` [E0369] +12 | let _a = b.to_owned() + ", World!"; | ^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/issue-47377-1.rs b/src/test/ui/issue-47380.rs similarity index 76% rename from src/test/ui/issue-47377-1.rs rename to src/test/ui/issue-47380.rs index f173d0096381b..748891fad5aab 100644 --- a/src/test/ui/issue-47377-1.rs +++ b/src/test/ui/issue-47380.rs @@ -7,8 +7,9 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. - +// ignore-tidy-tab fn main(){ let b = "hello"; - println!("🦀🦀🦀🦀🦀"); let _a = b + ", World!"; //~ERROR 13:37: 13:51: binary operation `+` cannot be applied to type `&str` [E0369] -} \ No newline at end of file + println!("🦀🦀🦀🦀🦀"); let _a = b + ", World!"; + //~^ ERROR E0369 +} diff --git a/src/test/ui/issue-47380.stderr b/src/test/ui/issue-47380.stderr new file mode 100644 index 0000000000000..8ead1697c7f68 --- /dev/null +++ b/src/test/ui/issue-47380.stderr @@ -0,0 +1,12 @@ +error[E0369]: binary operation `+` cannot be applied to type `&str` + --> $DIR/blah.rs:13:33 + | +13 | println!("🦀🦀🦀🦀🦀"); let _a = b + ", World!"; + | ^^^^^^^^^^^^^^ `+` can't be used to concatenate two `&str` strings +help: `to_owned()` can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left + | +13 | println!("🦀🦀🦀🦀🦀"); let _a = b.to_owned() + ", World!"; + | ^^^^^^^^^^^^ + +error: aborting due to previous error + From a4e3f361ba74303545150bc1db7260f70eb59566 Mon Sep 17 00:00:00 2001 From: Gauri Date: Wed, 17 Jan 2018 02:00:09 +0530 Subject: [PATCH 5/6] using tabs in ui tests --- src/test/ui/issue-47377.rs | 3 ++- src/test/ui/issue-47377.stderr | 6 +++--- src/test/ui/issue-47380.rs | 2 +- src/test/ui/issue-47380.stderr | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/test/ui/issue-47377.rs b/src/test/ui/issue-47377.rs index f2e18590ddef5..a492b4b5567e8 100644 --- a/src/test/ui/issue-47377.rs +++ b/src/test/ui/issue-47377.rs @@ -7,7 +7,8 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. -fn main(){ +// ignore-tidy-tab +fn main() { let b = "hello"; let _a = b + ", World!"; //~^ ERROR E0369 diff --git a/src/test/ui/issue-47377.stderr b/src/test/ui/issue-47377.stderr index b80867f1714a0..09640c841b8e4 100644 --- a/src/test/ui/issue-47377.stderr +++ b/src/test/ui/issue-47377.stderr @@ -1,11 +1,11 @@ error[E0369]: binary operation `+` cannot be applied to type `&str` - --> $DIR/issue-47377.rs:12:14 + --> $DIR/issue-47377.rs:13:14 | -12 | let _a = b + ", World!"; +13 | let _a = b + ", World!"; | ^^^^^^^^^^^^^^ `+` can't be used to concatenate two `&str` strings help: `to_owned()` can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left | -12 | let _a = b.to_owned() + ", World!"; +13 | let _a = b.to_owned() + ", World!"; | ^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/issue-47380.rs b/src/test/ui/issue-47380.rs index 748891fad5aab..88d4faedb7a1c 100644 --- a/src/test/ui/issue-47380.rs +++ b/src/test/ui/issue-47380.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. // ignore-tidy-tab -fn main(){ +fn main() { let b = "hello"; println!("🦀🦀🦀🦀🦀"); let _a = b + ", World!"; //~^ ERROR E0369 diff --git a/src/test/ui/issue-47380.stderr b/src/test/ui/issue-47380.stderr index 8ead1697c7f68..e220b4551e7f5 100644 --- a/src/test/ui/issue-47380.stderr +++ b/src/test/ui/issue-47380.stderr @@ -1,5 +1,5 @@ error[E0369]: binary operation `+` cannot be applied to type `&str` - --> $DIR/blah.rs:13:33 + --> $DIR/issue-47380.rs:13:33 | 13 | println!("🦀🦀🦀🦀🦀"); let _a = b + ", World!"; | ^^^^^^^^^^^^^^ `+` can't be used to concatenate two `&str` strings From efe3d69ad827cc359b1a120b0e5c58dd87a2935b Mon Sep 17 00:00:00 2001 From: Gauri Date: Wed, 17 Jan 2018 02:07:07 +0530 Subject: [PATCH 6/6] fix minor errors --- src/test/ui/issue-47377.rs | 6 +++--- src/test/ui/issue-47377.stderr | 10 +++++----- src/test/ui/issue-47380.rs | 1 - src/test/ui/issue-47380.stderr | 6 +++--- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/test/ui/issue-47377.rs b/src/test/ui/issue-47377.rs index a492b4b5567e8..f294008cfd0d5 100644 --- a/src/test/ui/issue-47377.rs +++ b/src/test/ui/issue-47377.rs @@ -9,7 +9,7 @@ // except according to those terms. // ignore-tidy-tab fn main() { - let b = "hello"; - let _a = b + ", World!"; - //~^ ERROR E0369 + let b = "hello"; + let _a = b + ", World!"; + //~^ ERROR E0369 } diff --git a/src/test/ui/issue-47377.stderr b/src/test/ui/issue-47377.stderr index 09640c841b8e4..13b3ff5869783 100644 --- a/src/test/ui/issue-47377.stderr +++ b/src/test/ui/issue-47377.stderr @@ -1,12 +1,12 @@ error[E0369]: binary operation `+` cannot be applied to type `&str` - --> $DIR/issue-47377.rs:13:14 + --> $DIR/issue-47377.rs:13:12 | -13 | let _a = b + ", World!"; - | ^^^^^^^^^^^^^^ `+` can't be used to concatenate two `&str` strings +13 | let _a = b + ", World!"; + | ^^^^^^^^^^^^^^ `+` can't be used to concatenate two `&str` strings help: `to_owned()` can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left | -13 | let _a = b.to_owned() + ", World!"; - | ^^^^^^^^^^^^ +13 | let _a = b.to_owned() + ", World!"; + | ^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/issue-47380.rs b/src/test/ui/issue-47380.rs index 88d4faedb7a1c..e43a967253ca8 100644 --- a/src/test/ui/issue-47380.rs +++ b/src/test/ui/issue-47380.rs @@ -7,7 +7,6 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. -// ignore-tidy-tab fn main() { let b = "hello"; println!("🦀🦀🦀🦀🦀"); let _a = b + ", World!"; diff --git a/src/test/ui/issue-47380.stderr b/src/test/ui/issue-47380.stderr index e220b4551e7f5..6c9f79b5a9417 100644 --- a/src/test/ui/issue-47380.stderr +++ b/src/test/ui/issue-47380.stderr @@ -1,11 +1,11 @@ error[E0369]: binary operation `+` cannot be applied to type `&str` - --> $DIR/issue-47380.rs:13:33 + --> $DIR/issue-47380.rs:12:33 | -13 | println!("🦀🦀🦀🦀🦀"); let _a = b + ", World!"; +12 | println!("🦀🦀🦀🦀🦀"); let _a = b + ", World!"; | ^^^^^^^^^^^^^^ `+` can't be used to concatenate two `&str` strings help: `to_owned()` can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left | -13 | println!("🦀🦀🦀🦀🦀"); let _a = b.to_owned() + ", World!"; +12 | println!("🦀🦀🦀🦀🦀"); let _a = b.to_owned() + ", World!"; | ^^^^^^^^^^^^ error: aborting due to previous error