Skip to content

Rollup of 9 pull requests #125533

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

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e7772f2
use posix_memalign on most Unix targets
RalfJung May 19, 2024
3c2d9c2
fix typo
RalfJung May 19, 2024
dc8d1bc
Add more tests
oli-obk May 23, 2024
29a630e
When checking whether an impl applies, constrain hidden types of opaq…
oli-obk Apr 17, 2024
7f292f4
Allow defining opaque types during trait object upcasting.
oli-obk Apr 17, 2024
4387eea
Support constraining opaque types while trait upcasting with binders
oli-obk Apr 17, 2024
09c8e39
A small diagnostic improvement for dropping_copy_types
surechen May 22, 2024
3fe3157
Stop using the avx512er and avx512pf x86 target features
zmodem May 24, 2024
ebd9f35
remove proof tree formatter, make em shallow
lcnr May 24, 2024
1af490d
Better ICE message for unresolved upvars
compiler-errors May 24, 2024
9185ddb
bootstrap: support target specific config overrides
weihanglo May 24, 2024
d1f0bc7
bootstrap: test target specific config overrides
weihanglo May 24, 2024
61aac55
Structurally resolve before builtin_index in EUV
compiler-errors May 24, 2024
f4b9ac6
Add manual Sync impl for ReentrantLockGuard
programmerjake May 24, 2024
045f448
Don't eagerly monomorphize drop for types that are impossible to inst…
compiler-errors May 24, 2024
8f00197
Rollup merge of #124080 - oli-obk:define_opaque_types10, r=compiler-e…
workingjubilee May 25, 2024
508d5e4
Rollup merge of #125271 - RalfJung:posix_memalign, r=workingjubilee
workingjubilee May 25, 2024
05fefb5
Rollup merge of #125433 - surechen:fix_125189, r=Urgau
workingjubilee May 25, 2024
5edded5
Rollup merge of #125498 - zmodem:avx512er, r=workingjubilee
workingjubilee May 25, 2024
f528aab
Rollup merge of #125510 - lcnr:change-proof-trees-to-be-shallow, r=co…
workingjubilee May 25, 2024
a570549
Rollup merge of #125513 - compiler-errors:impossible-drop, r=jackh726
workingjubilee May 25, 2024
12e92c4
Rollup merge of #125514 - compiler-errors:builtin-index, r=lcnr
workingjubilee May 25, 2024
836487b
Rollup merge of #125515 - weihanglo:target-toml-override, r=onur-ozkan
workingjubilee May 25, 2024
f8346f0
Rollup merge of #125527 - programmerjake:patch-2, r=workingjubilee
workingjubilee May 25, 2024
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
1 change: 1 addition & 0 deletions compiler/rustc_lint/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ lint_drop_trait_constraints =
lint_dropping_copy_types = calls to `std::mem::drop` with a value that implements `Copy` does nothing
.label = argument has type `{$arg_ty}`
.note = use `let _ = ...` to ignore the expression or result
.suggestion = use `let _ = ...` to ignore the expression or result

lint_dropping_references = calls to `std::mem::drop` with a reference instead of an owned value does nothing
.label = argument has type `{$arg_ty}`
Expand Down
21 changes: 17 additions & 4 deletions compiler/rustc_lint/src/drop_forget_useless.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use rustc_hir::{Arm, Expr, ExprKind, Node};
use rustc_hir::{Arm, Expr, ExprKind, Node, StmtKind};
use rustc_middle::ty;
use rustc_session::{declare_lint, declare_lint_pass};
use rustc_span::sym;

use crate::{
lints::{
DropCopyDiag, DropRefDiag, ForgetCopyDiag, ForgetRefDiag, UndroppedManuallyDropsDiag,
UndroppedManuallyDropsSuggestion,
DropCopyDiag, DropCopySuggestion, DropRefDiag, ForgetCopyDiag, ForgetRefDiag,
UndroppedManuallyDropsDiag, UndroppedManuallyDropsSuggestion,
},
LateContext, LateLintPass, LintContext,
};
Expand Down Expand Up @@ -164,10 +164,23 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetUseless {
);
}
sym::mem_drop if is_copy && !drop_is_single_call_in_arm => {
let sugg = if let Some((_, node)) = cx.tcx.hir().parent_iter(expr.hir_id).nth(0)
&& let Node::Stmt(stmt) = node
&& let StmtKind::Semi(e) = stmt.kind
&& e.hir_id == expr.hir_id
{
DropCopySuggestion::Suggestion {
start_span: expr.span.shrink_to_lo().until(arg.span),
end_span: arg.span.shrink_to_hi().until(expr.span.shrink_to_hi()),
}
} else {
DropCopySuggestion::Note
};

cx.emit_span_lint(
DROPPING_COPY_TYPES,
expr.span,
DropCopyDiag { arg_ty, label: arg.span },
DropCopyDiag { arg_ty, label: arg.span, sugg },
);
}
sym::mem_forget if is_copy => {
Expand Down
16 changes: 15 additions & 1 deletion compiler/rustc_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,11 +677,25 @@ pub struct DropRefDiag<'a> {

#[derive(LintDiagnostic)]
#[diag(lint_dropping_copy_types)]
#[note]
pub struct DropCopyDiag<'a> {
pub arg_ty: Ty<'a>,
#[label]
pub label: Span,
#[subdiagnostic]
pub sugg: DropCopySuggestion,
}

#[derive(Subdiagnostic)]
pub enum DropCopySuggestion {
#[note(lint_note)]
Note,
#[multipart_suggestion(lint_suggestion, style = "verbose", applicability = "maybe-incorrect")]
Suggestion {
#[suggestion_part(code = "let _ = ")]
start_span: Span,
#[suggestion_part(code = "")]
end_span: Span,
},
}

#[derive(LintDiagnostic)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ LL | drop(origin);
| |
| argument has type `<T as UncheckedCopy>::Output`
|
= note: use `let _ = ...` to ignore the expression or result
= note: `#[warn(dropping_copy_types)]` on by default
help: use `let _ = ...` to ignore the expression or result
|
LL - drop(origin);
LL + let _ = origin;
|

warning: 1 warning emitted

Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ LL | drop(origin);
| |
| argument has type `<T as UncheckedCopy>::Output`
|
= note: use `let _ = ...` to ignore the expression or result
= note: `#[warn(dropping_copy_types)]` on by default
help: use `let _ = ...` to ignore the expression or result
|
LL - drop(origin);
LL + let _ = origin;
|

warning: 1 warning emitted

14 changes: 14 additions & 0 deletions tests/ui/lint/dropping_copy_types-issue-125189-can-not-fixed.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//@ check-fail

#![deny(dropping_copy_types)]

fn main() {
let y = 1;
let z = 2;
match y {
0 => drop(y), //~ ERROR calls to `std::mem::drop`
1 => drop(z), //~ ERROR calls to `std::mem::drop`
2 => drop(3), //~ ERROR calls to `std::mem::drop`
_ => {},
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
error: calls to `std::mem::drop` with a value that implements `Copy` does nothing
--> $DIR/dropping_copy_types-issue-125189-can-not-fixed.rs:9:14
|
LL | 0 => drop(y),
| ^^^^^-^
| |
| argument has type `i32`
|
= note: use `let _ = ...` to ignore the expression or result
note: the lint level is defined here
--> $DIR/dropping_copy_types-issue-125189-can-not-fixed.rs:3:9
|
LL | #![deny(dropping_copy_types)]
| ^^^^^^^^^^^^^^^^^^^

error: calls to `std::mem::drop` with a value that implements `Copy` does nothing
--> $DIR/dropping_copy_types-issue-125189-can-not-fixed.rs:10:14
|
LL | 1 => drop(z),
| ^^^^^-^
| |
| argument has type `i32`
|
= note: use `let _ = ...` to ignore the expression or result

error: calls to `std::mem::drop` with a value that implements `Copy` does nothing
--> $DIR/dropping_copy_types-issue-125189-can-not-fixed.rs:11:14
|
LL | 2 => drop(3),
| ^^^^^-^
| |
| argument has type `i32`
|
= note: use `let _ = ...` to ignore the expression or result

error: aborting due to 3 previous errors

10 changes: 10 additions & 0 deletions tests/ui/lint/dropping_copy_types-issue-125189.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//@ check-fail
//@ run-rustfix

#![deny(dropping_copy_types)]

fn main() {
let y = 1;
let _ = 3.2; //~ ERROR calls to `std::mem::drop`
let _ = y; //~ ERROR calls to `std::mem::drop`
}
10 changes: 10 additions & 0 deletions tests/ui/lint/dropping_copy_types-issue-125189.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//@ check-fail
//@ run-rustfix

#![deny(dropping_copy_types)]

fn main() {
let y = 1;
drop(3.2); //~ ERROR calls to `std::mem::drop`
drop(y); //~ ERROR calls to `std::mem::drop`
}
35 changes: 35 additions & 0 deletions tests/ui/lint/dropping_copy_types-issue-125189.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
error: calls to `std::mem::drop` with a value that implements `Copy` does nothing
--> $DIR/dropping_copy_types-issue-125189.rs:8:5
|
LL | drop(3.2);
| ^^^^^---^
| |
| argument has type `f64`
|
note: the lint level is defined here
--> $DIR/dropping_copy_types-issue-125189.rs:4:9
|
LL | #![deny(dropping_copy_types)]
| ^^^^^^^^^^^^^^^^^^^
help: use `let _ = ...` to ignore the expression or result
|
LL - drop(3.2);
LL + let _ = 3.2;
|

error: calls to `std::mem::drop` with a value that implements `Copy` does nothing
--> $DIR/dropping_copy_types-issue-125189.rs:9:5
|
LL | drop(y);
| ^^^^^-^
| |
| argument has type `i32`
|
help: use `let _ = ...` to ignore the expression or result
|
LL - drop(y);
LL + let _ = y;
|

error: aborting due to 2 previous errors

24 changes: 20 additions & 4 deletions tests/ui/lint/dropping_copy_types.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ LL | drop(s1);
| |
| argument has type `SomeStruct`
|
= note: use `let _ = ...` to ignore the expression or result
note: the lint level is defined here
--> $DIR/dropping_copy_types.rs:3:9
|
LL | #![warn(dropping_copy_types)]
| ^^^^^^^^^^^^^^^^^^^
help: use `let _ = ...` to ignore the expression or result
|
LL - drop(s1);
LL + let _ = s1;
|

warning: calls to `std::mem::drop` with a value that implements `Copy` does nothing
--> $DIR/dropping_copy_types.rs:35:5
Expand All @@ -21,7 +25,11 @@ LL | drop(s2);
| |
| argument has type `SomeStruct`
|
= note: use `let _ = ...` to ignore the expression or result
help: use `let _ = ...` to ignore the expression or result
|
LL - drop(s2);
LL + let _ = s2;
|

warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing
--> $DIR/dropping_copy_types.rs:36:5
Expand All @@ -42,7 +50,11 @@ LL | drop(s4);
| |
| argument has type `SomeStruct`
|
= note: use `let _ = ...` to ignore the expression or result
help: use `let _ = ...` to ignore the expression or result
|
LL - drop(s4);
LL + let _ = s4;
|

warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing
--> $DIR/dropping_copy_types.rs:38:5
Expand Down Expand Up @@ -82,7 +94,11 @@ LL | drop(println_and(13));
| |
| argument has type `i32`
|
= note: use `let _ = ...` to ignore the expression or result
help: use `let _ = ...` to ignore the expression or result
|
LL - drop(println_and(13));
LL + let _ = println_and(13);
|

warning: calls to `std::mem::drop` with a value that implements `Copy` does nothing
--> $DIR/dropping_copy_types.rs:74:14
Expand Down