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

[stable] Prepare 1.58.1 point release #93071

Merged
merged 6 commits into from
Jan 20, 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
13 changes: 13 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
Version 1.58.1 (2022-01-19)
===========================

* [Handle captured arguments in the `useless_format` Clippy lint][clippy/8295]
* [Move `non_send_fields_in_send_ty` Clippy lint to nursery][clippy/8075]
* [Fix wrong error message displayed when some imports are missing][91254]
* [Fix rustfmt not formatting generated files from stdin][92912]

[91254]: https://github.com/rust-lang/rust/pull/91254
[92912]: https://github.com/rust-lang/rust/pull/92912
[clippy/8075]: https://github.com/rust-lang/rust-clippy/pull/8075
[clippy/8295]: https://github.com/rust-lang/rust-clippy/pull/8295

Version 1.58.0 (2022-01-13)
==========================

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// This helps us avoid overflow: see issue #72839
// Since compilation is already guaranteed to fail, this is just
// to try to show the 'nicest' possible errors to the user.
if obligation.references_error() {
// We don't check for errors in the `ParamEnv` - in practice,
// it seems to cause us to be overly aggressive in deciding
// to give up searching for candidates, leading to spurious errors.
if obligation.predicate.references_error() {
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: generic parameters may not be used in const operations
--> $DIR/issue-72787.rs:12:17
--> $DIR/issue-72787.rs:11:17
|
LL | Condition<{ LHS <= RHS }>: True
| ^^^ cannot perform const operation using `LHS`
Expand All @@ -8,7 +8,7 @@ LL | Condition<{ LHS <= RHS }>: True
= help: use `#![feature(generic_const_exprs)]` to allow generic const expressions

error: generic parameters may not be used in const operations
--> $DIR/issue-72787.rs:12:24
--> $DIR/issue-72787.rs:11:24
|
LL | Condition<{ LHS <= RHS }>: True
| ^^^ cannot perform const operation using `RHS`
Expand All @@ -17,7 +17,7 @@ LL | Condition<{ LHS <= RHS }>: True
= help: use `#![feature(generic_const_exprs)]` to allow generic const expressions

error: generic parameters may not be used in const operations
--> $DIR/issue-72787.rs:26:25
--> $DIR/issue-72787.rs:25:25
|
LL | IsLessOrEqual<{ 8 - I }, { 8 - J }>: True,
| ^ cannot perform const operation using `I`
Expand All @@ -26,7 +26,7 @@ LL | IsLessOrEqual<{ 8 - I }, { 8 - J }>: True,
= help: use `#![feature(generic_const_exprs)]` to allow generic const expressions

error: generic parameters may not be used in const operations
--> $DIR/issue-72787.rs:26:36
--> $DIR/issue-72787.rs:25:36
|
LL | IsLessOrEqual<{ 8 - I }, { 8 - J }>: True,
| ^ cannot perform const operation using `J`
Expand All @@ -35,29 +35,21 @@ LL | IsLessOrEqual<{ 8 - I }, { 8 - J }>: True,
= help: use `#![feature(generic_const_exprs)]` to allow generic const expressions

error[E0283]: type annotations needed
--> $DIR/issue-72787.rs:10:38
|
LL | impl<const LHS: u32, const RHS: u32> True for IsLessOrEqual<LHS, RHS> where
| ^^^^ cannot infer type for struct `IsLessOrEqual<LHS, RHS>`
|
= note: cannot satisfy `IsLessOrEqual<LHS, RHS>: True`

error[E0283]: type annotations needed
--> $DIR/issue-72787.rs:22:26
--> $DIR/issue-72787.rs:21:26
|
LL | IsLessOrEqual<I, 8>: True,
| ^^^^ cannot infer type for struct `IsLessOrEqual<I, 8_u32>`
|
= note: cannot satisfy `IsLessOrEqual<I, 8_u32>: True`

error[E0283]: type annotations needed
--> $DIR/issue-72787.rs:22:26
--> $DIR/issue-72787.rs:21:26
|
LL | IsLessOrEqual<I, 8>: True,
| ^^^^ cannot infer type for struct `IsLessOrEqual<I, 8_u32>`
|
= note: cannot satisfy `IsLessOrEqual<I, 8_u32>: True`

error: aborting due to 7 previous errors
error: aborting due to 6 previous errors

For more information about this error, try `rustc --explain E0283`.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ pub struct Condition<const CONDITION: bool>;
pub trait True {}

impl<const LHS: u32, const RHS: u32> True for IsLessOrEqual<LHS, RHS> where
//[min]~^ ERROR type annotations needed
Condition<{ LHS <= RHS }>: True
//[min]~^ Error generic parameters may not be used in const operations
//[min]~| Error generic parameters may not be used in const operations
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-77919.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ struct Multiply<N, M> {
}
impl<N, M> TypeVal<usize> for Multiply<N, M> where N: TypeVal<VAL> {}
//~^ ERROR cannot find type `VAL` in this scope
//~| ERROR type annotations needed
//~| ERROR not all trait items implemented, missing: `VAL`
15 changes: 8 additions & 7 deletions src/test/ui/issues/issue-77919.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ LL | impl<N, M> TypeVal<usize> for Multiply<N, M> where N: TypeVal<VAL> {}
| |
| help: you might be missing a type parameter: `, VAL`

error[E0283]: type annotations needed
--> $DIR/issue-77919.rs:11:12
error[E0046]: not all trait items implemented, missing: `VAL`
--> $DIR/issue-77919.rs:11:1
|
LL | const VAL: T;
| ------------- `VAL` from trait
...
LL | impl<N, M> TypeVal<usize> for Multiply<N, M> where N: TypeVal<VAL> {}
| ^^^^^^^^^^^^^^ cannot infer type for struct `Multiply<N, M>`
|
= note: cannot satisfy `Multiply<N, M>: TypeVal<usize>`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `VAL` in implementation

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0283, E0412.
For more information about an error, try `rustc --explain E0283`.
Some errors have detailed explanations: E0046, E0412.
For more information about an error, try `rustc --explain E0046`.
2 changes: 1 addition & 1 deletion src/tools/cargo
19 changes: 17 additions & 2 deletions src/tools/clippy/clippy_lints/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty;
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::symbol::kw;
use rustc_span::{sym, Span};
use rustc_span::{sym, BytePos, Span};

declare_clippy_lint! {
/// ### What it does
Expand Down Expand Up @@ -80,7 +80,22 @@ impl<'tcx> LateLintPass<'tcx> for UselessFormat {
ExprKind::MethodCall(path, ..) => path.ident.name.as_str() == "to_string",
_ => false,
};
let sugg = if is_new_string {
let sugg = if format_args.format_string_span.contains(value.span) {
// Implicit argument. e.g. `format!("{x}")` span points to `{x}`
let spdata = value.span.data();
let span = Span::new(
spdata.lo + BytePos(1),
spdata.hi - BytePos(1),
spdata.ctxt,
spdata.parent
);
let snip = snippet_with_applicability(cx, span, "..", &mut applicability);
if is_new_string {
snip.into()
} else {
format!("{}.to_string()", snip)
}
} else if is_new_string {
snippet_with_applicability(cx, value.span, "..", &mut applicability).into_owned()
} else {
let sugg = Sugg::hir_with_applicability(cx, value, "<arg>", &mut applicability);
Expand Down
1 change: 0 additions & 1 deletion src/tools/clippy/clippy_lints/src/lib.register_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![
LintId::of(non_copy_const::DECLARE_INTERIOR_MUTABLE_CONST),
LintId::of(non_expressive_names::JUST_UNDERSCORES_AND_DIGITS),
LintId::of(non_octal_unix_permissions::NON_OCTAL_UNIX_PERMISSIONS),
LintId::of(non_send_fields_in_send_ty::NON_SEND_FIELDS_IN_SEND_TY),
LintId::of(open_options::NONSENSICAL_OPEN_OPTIONS),
LintId::of(option_env_unwrap::OPTION_ENV_UNWRAP),
LintId::of(overflow_check_conditional::OVERFLOW_CHECK_CONDITIONAL),
Expand Down
1 change: 1 addition & 0 deletions src/tools/clippy/clippy_lints/src/lib.register_nursery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ store.register_group(true, "clippy::nursery", Some("clippy_nursery"), vec![
LintId::of(missing_const_for_fn::MISSING_CONST_FOR_FN),
LintId::of(mutable_debug_assertion::DEBUG_ASSERT_WITH_MUT_CALL),
LintId::of(mutex_atomic::MUTEX_INTEGER),
LintId::of(non_send_fields_in_send_ty::NON_SEND_FIELDS_IN_SEND_TY),
LintId::of(nonstandard_macro_braces::NONSTANDARD_MACRO_BRACES),
LintId::of(option_if_let_else::OPTION_IF_LET_ELSE),
LintId::of(path_buf_push_overwrite::PATH_BUF_PUSH_OVERWRITE),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ store.register_group(true, "clippy::suspicious", Some("clippy_suspicious"), vec!
LintId::of(loops::MUT_RANGE_BOUND),
LintId::of(methods::SUSPICIOUS_MAP),
LintId::of(mut_key::MUTABLE_KEY_TYPE),
LintId::of(non_send_fields_in_send_ty::NON_SEND_FIELDS_IN_SEND_TY),
LintId::of(suspicious_trait_impl::SUSPICIOUS_ARITHMETIC_IMPL),
LintId::of(suspicious_trait_impl::SUSPICIOUS_OP_ASSIGN_IMPL),
])
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ declare_clippy_lint! {
/// Use thread-safe types like [`std::sync::Arc`](https://doc.rust-lang.org/std/sync/struct.Arc.html)
/// or specify correct bounds on generic type parameters (`T: Send`).
pub NON_SEND_FIELDS_IN_SEND_TY,
suspicious,
nursery,
"there is field that does not implement `Send` in a `Send` struct"
}

Expand Down
15 changes: 8 additions & 7 deletions src/tools/clippy/tests/ui/crashes/ice-6252.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@ LL | impl<N, M> TypeVal<usize> for Multiply<N, M> where N: TypeVal<VAL> {}
| |
| help: you might be missing a type parameter: `, VAL`

error[E0283]: type annotations needed
--> $DIR/ice-6252.rs:10:12
error[E0046]: not all trait items implemented, missing: `VAL`
--> $DIR/ice-6252.rs:10:1
|
LL | const VAL: T;
| ------------- `VAL` from trait
...
LL | impl<N, M> TypeVal<usize> for Multiply<N, M> where N: TypeVal<VAL> {}
| ^^^^^^^^^^^^^^ cannot infer type for struct `Multiply<N, M>`
|
= note: cannot satisfy `Multiply<N, M>: TypeVal<usize>`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `VAL` in implementation

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0283, E0412.
For more information about an error, try `rustc --explain E0283`.
Some errors have detailed explanations: E0046, E0412.
For more information about an error, try `rustc --explain E0046`.
6 changes: 6 additions & 0 deletions src/tools/clippy/tests/ui/format.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,10 @@ fn main() {
let _s: String = (&*v.join("\n")).to_string();

format!("prepend {:+}", "s");

// Issue #8290
let x = "foo";
let _ = x.to_string();
let _ = format!("{x:?}"); // Don't lint on debug
let _ = x.to_string();
}
6 changes: 6 additions & 0 deletions src/tools/clippy/tests/ui/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,10 @@ fn main() {
let _s: String = format!("{}", &*v.join("\n"));

format!("prepend {:+}", "s");

// Issue #8290
let x = "foo";
let _ = format!("{x}");
let _ = format!("{x:?}"); // Don't lint on debug
let _ = format!("{y}", y = x);
}
14 changes: 13 additions & 1 deletion src/tools/clippy/tests/ui/format.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,17 @@ error: useless use of `format!`
LL | let _s: String = format!("{}", &*v.join("/n"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `(&*v.join("/n")).to_string()`

error: aborting due to 15 previous errors
error: useless use of `format!`
--> $DIR/format.rs:81:13
|
LL | let _ = format!("{x}");
| ^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.to_string()`

error: useless use of `format!`
--> $DIR/format.rs:83:13
|
LL | let _ = format!("{y}", y = x);
| ^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `x.to_string()`

error: aborting due to 17 previous errors

4 changes: 2 additions & 2 deletions src/tools/rustfmt/Configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -929,9 +929,9 @@ fn add_one(x: i32) -> i32 {
## `format_generated_files`

Format generated files. A file is considered generated
if any of the first five lines contains `@generated` marker.
if any of the first five lines contain a `@generated` comment marker.

- **Default value**: `false`
- **Default value**: `true`
- **Possible values**: `true`, `false`
- **Stable**: No

Expand Down
4 changes: 2 additions & 2 deletions src/tools/rustfmt/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ create_config! {
inline_attribute_width: usize, 0, false,
"Write an item and its attribute on the same line \
if their combined width is below a threshold";
format_generated_files: bool, false, false, "Format generated files";
format_generated_files: bool, true, false, "Format generated files";

// Options that can change the source code beyond whitespace/blocks (somewhat linty things)
merge_derives: bool, true, true, "Merge multiple `#[derive(...)]` into a single one";
Expand Down Expand Up @@ -608,7 +608,7 @@ blank_lines_lower_bound = 0
edition = "2015"
version = "One"
inline_attribute_width = 0
format_generated_files = false
format_generated_files = true
merge_derives = true
use_try_shorthand = false
use_field_init_shorthand = false
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rustfmt/src/formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ fn format_project<T: FormatHandler>(
let src = source_file.src.as_ref().expect("SourceFile without src");

let should_ignore = (!input_is_stdin && context.ignore_file(&path))
|| (!config.format_generated_files() && is_generated_file(src));
|| (!input_is_stdin && !config.format_generated_files() && is_generated_file(src));

if (config.skip_children() && path != main_file) || should_ignore {
continue;
Expand Down
18 changes: 18 additions & 0 deletions src/tools/rustfmt/src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,24 @@ fn stdin_disable_all_formatting_test() {
assert_eq!(input, String::from_utf8(output.stdout).unwrap());
}

#[test]
fn stdin_generated_files_issue_5172() {
init_log();
let input = Input::Text("//@generated\nfn main() {}".to_owned());
let mut config = Config::default();
config.set().emit_mode(EmitMode::Stdout);
config.set().format_generated_files(false);
config.set().newline_style(NewlineStyle::Unix);
let mut buf: Vec<u8> = vec![];
{
let mut session = Session::new(config, Some(&mut buf));
session.format(input).unwrap();
assert!(session.has_no_errors());
}
// N.B. this should be changed once `format_generated_files` is supported with stdin
assert_eq!(buf, "stdin:\n\n//@generated\nfn main() {}\n".as_bytes());
}

#[test]
fn format_lines_errors_are_reported() {
init_log();
Expand Down