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

Rollup of 3 pull requests #74023

Closed
wants to merge 9 commits into from
16 changes: 16 additions & 0 deletions src/liballoc/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1774,6 +1774,15 @@ impl FromIterator<String> for String {
}
}

#[stable(feature = "box_str2", since = "1.45.0")]
impl FromIterator<Box<str>> for String {
fn from_iter<I: IntoIterator<Item = Box<str>>>(iter: I) -> String {
let mut buf = String::new();
buf.extend(iter);
buf
}
}

#[stable(feature = "herd_cows", since = "1.19.0")]
impl<'a> FromIterator<Cow<'a, str>> for String {
fn from_iter<I: IntoIterator<Item = Cow<'a, str>>>(iter: I) -> String {
Expand Down Expand Up @@ -1842,6 +1851,13 @@ impl<'a> Extend<&'a str> for String {
}
}

#[stable(feature = "box_str2", since = "1.45.0")]
impl Extend<Box<str>> for String {
fn extend<I: IntoIterator<Item = Box<str>>>(&mut self, iter: I) {
iter.into_iter().for_each(move |s| self.push_str(&s));
}
}

#[stable(feature = "extend_string", since = "1.4.0")]
impl Extend<String> for String {
fn extend<I: IntoIterator<Item = String>>(&mut self, iter: I) {
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_builtin_macros/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ impl<'a, 'b> Context<'a, 'b> {
("x", "LowerHex"),
("X", "UpperHex"),
] {
// FIXME: rustfix (`run-rustfix`) fails to apply suggestions.
// > "Cannot replace slice of data that was already replaced"
err.tool_only_span_suggestion(
sp,
&format!("use the `{}` trait", name),
Expand Down
35 changes: 18 additions & 17 deletions src/librustc_middle/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,26 +282,27 @@ pub trait PrettyPrinter<'tcx>:
// where there is no explicit `extern crate`, we just prepend
// the crate name.
match self.tcx().extern_crate(def_id) {
Some(&ExternCrate {
src: ExternCrateSource::Extern(def_id),
dependency_of: LOCAL_CRATE,
span,
..
}) => {
debug!("try_print_visible_def_path: def_id={:?}", def_id);
return Ok((
if !span.is_dummy() {
self.print_def_path(def_id, &[])?
} else {
self.path_crate(cnum)?
},
true,
));
}
Some(&ExternCrate { src, dependency_of, span, .. }) => match (src, dependency_of) {
(ExternCrateSource::Extern(def_id), LOCAL_CRATE) => {
debug!("try_print_visible_def_path: def_id={:?}", def_id);
return Ok((
if !span.is_dummy() {
self.print_def_path(def_id, &[])?
} else {
self.path_crate(cnum)?
},
true,
));
}
(ExternCrateSource::Path, LOCAL_CRATE) => {
debug!("try_print_visible_def_path: def_id={:?}", def_id);
return Ok((self.path_crate(cnum)?, true));
}
_ => {}
},
None => {
return Ok((self.path_crate(cnum)?, true));
}
_ => {}
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/librustc_parse/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1228,10 +1228,13 @@ impl<'a> Parser<'a> {
if let Some(sp) = unmatched.unclosed_span {
err.span_label(sp, "unclosed delimiter");
}
// Backticks should be removed to apply suggestions.
let mut delim = delim.to_string();
delim.retain(|c| c != '`');
err.span_suggestion_short(
self.prev_token.span.shrink_to_hi(),
&format!("{} may belong here", delim.to_string()),
delim.to_string(),
&format!("`{}` may belong here", delim),
delim,
Applicability::MaybeIncorrect,
);
if unmatched.found_delim.is_none() {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_parse/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ impl<'a> Parser<'a> {
// misses a separator.
expect_err
.span_suggestion_short(
sp,
self.sess.source_map().next_point(sp),
&format!("missing `{}`", token_str),
token_str,
Applicability::MaybeIncorrect,
Expand Down
12 changes: 12 additions & 0 deletions src/test/ui/block-expression-remove-semicolon.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// run-rustfix

fn foo() -> i32 {
0
}

fn main() {
let _x: i32 = {
//~^ ERROR mismatched types
foo() //~ HELP consider removing this semicolon
};
}
6 changes: 4 additions & 2 deletions src/test/ui/block-expression-remove-semicolon.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// run-rustfix

fn foo() -> i32 {
0
0
}

fn main() {
let x: i32 = {
let _x: i32 = {
//~^ ERROR mismatched types
foo(); //~ HELP consider removing this semicolon
};
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/block-expression-remove-semicolon.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0308]: mismatched types
--> $DIR/block-expression-remove-semicolon.rs:6:18
--> $DIR/block-expression-remove-semicolon.rs:8:19
|
LL | let x: i32 = {
| __________________^
LL | let _x: i32 = {
| ___________________^
LL | |
LL | | foo();
| | - help: consider removing this semicolon
Expand Down
13 changes: 13 additions & 0 deletions src/test/ui/block-result/consider-removing-last-semi.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// run-rustfix

pub fn f() -> String { //~ ERROR mismatched types
0u8;
"bla".to_string()
}

pub fn g() -> String { //~ ERROR mismatched types
"this won't work".to_string();
"removeme".to_string()
}

fn main() {}
6 changes: 4 additions & 2 deletions src/test/ui/block-result/consider-removing-last-semi.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
fn f() -> String { //~ ERROR mismatched types
// run-rustfix

pub fn f() -> String { //~ ERROR mismatched types
0u8;
"bla".to_string();
}

fn g() -> String { //~ ERROR mismatched types
pub fn g() -> String { //~ ERROR mismatched types
"this won't work".to_string();
"removeme".to_string();
}
Expand Down
20 changes: 10 additions & 10 deletions src/test/ui/block-result/consider-removing-last-semi.stderr
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
error[E0308]: mismatched types
--> $DIR/consider-removing-last-semi.rs:1:11
--> $DIR/consider-removing-last-semi.rs:3:15
|
LL | fn f() -> String {
| - ^^^^^^ expected struct `std::string::String`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
LL | pub fn f() -> String {
| - ^^^^^^ expected struct `std::string::String`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
LL | 0u8;
LL | "bla".to_string();
| - help: consider removing this semicolon

error[E0308]: mismatched types
--> $DIR/consider-removing-last-semi.rs:6:11
--> $DIR/consider-removing-last-semi.rs:8:15
|
LL | fn g() -> String {
| - ^^^^^^ expected struct `std::string::String`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
LL | pub fn g() -> String {
| - ^^^^^^ expected struct `std::string::String`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
LL | "this won't work".to_string();
LL | "removeme".to_string();
| - help: consider removing this semicolon
Expand Down
16 changes: 16 additions & 0 deletions src/test/ui/coercion/coercion-missing-tail-expected-type.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// #41425 -- error message "mismatched types" has wrong types
// run-rustfix

fn plus_one(x: i32) -> i32 { //~ ERROR mismatched types
x + 1
}

fn foo() -> Result<u8, u64> { //~ ERROR mismatched types
Ok(1)
}

fn main() {
let x = plus_one(5);
let _ = foo();
println!("X = {}", x);
}
2 changes: 2 additions & 0 deletions src/test/ui/coercion/coercion-missing-tail-expected-type.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// #41425 -- error message "mismatched types" has wrong types
// run-rustfix

fn plus_one(x: i32) -> i32 { //~ ERROR mismatched types
x + 1;
Expand All @@ -10,5 +11,6 @@ fn foo() -> Result<u8, u64> { //~ ERROR mismatched types

fn main() {
let x = plus_one(5);
let _ = foo();
println!("X = {}", x);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0308]: mismatched types
--> $DIR/coercion-missing-tail-expected-type.rs:3:24
--> $DIR/coercion-missing-tail-expected-type.rs:4:24
|
LL | fn plus_one(x: i32) -> i32 {
| -------- ^^^ expected `i32`, found `()`
Expand All @@ -9,7 +9,7 @@ LL | x + 1;
| - help: consider removing this semicolon

error[E0308]: mismatched types
--> $DIR/coercion-missing-tail-expected-type.rs:7:13
--> $DIR/coercion-missing-tail-expected-type.rs:8:13
|
LL | fn foo() -> Result<u8, u64> {
| --- ^^^^^^^^^^^^^^^ expected enum `std::result::Result`, found `()`
Expand Down
15 changes: 15 additions & 0 deletions src/test/ui/const-generics/unused_braces.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// check-pass
// run-rustfix

#![allow(incomplete_features)]
#![warn(unused_braces)]

#![feature(const_generics)]

struct A<const N: usize>;

fn main() {
let _: A<7>; // ok
let _: A< 7 >; //~ WARN unnecessary braces
let _: A<{ 3 + 5 }>; // ok
}
4 changes: 3 additions & 1 deletion src/test/ui/const-generics/unused_braces.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// check-pass
// run-rustfix

#![allow(incomplete_features)]
#![warn(unused_braces)]

#![feature(const_generics)]
//~^ WARN the feature `const_generics` is incomplete

struct A<const N: usize>;

Expand Down
15 changes: 3 additions & 12 deletions src/test/ui/const-generics/unused_braces.stderr
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/unused_braces.rs:4:12
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information

warning: unnecessary braces around const expression
--> $DIR/unused_braces.rs:11:14
--> $DIR/unused_braces.rs:13:14
|
LL | let _: A<{ 7 }>;
| ^^^^^ help: remove these braces
|
note: the lint level is defined here
--> $DIR/unused_braces.rs:2:9
--> $DIR/unused_braces.rs:5:9
|
LL | #![warn(unused_braces)]
| ^^^^^^^^^^^^^

warning: 2 warnings emitted
warning: 1 warning emitted

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// run-rustfix

fn main() {
let _x = !1; //~ ERROR cannot be used as a unary operator
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// run-rustfix

fn main() {
let x = ~1; //~ ERROR cannot be used as a unary operator
let _x = ~1; //~ ERROR cannot be used as a unary operator
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: `~` cannot be used as a unary operator
--> $DIR/issue-41679-tilde-bitwise-negation-attempt.rs:2:13
--> $DIR/issue-41679-tilde-bitwise-negation-attempt.rs:4:14
|
LL | let x = ~1;
| ^ help: use `!` to perform bitwise not
LL | let _x = ~1;
| ^ help: use `!` to perform bitwise not

error: aborting due to previous error

Loading