Skip to content

Commit 0252b40

Browse files
committed
Auto merge of rust-lang#112681 - GuillaumeGomez:rollup-rwn4086, r=GuillaumeGomez
Rollup of 8 pull requests Successful merges: - rust-lang#112403 (Prevent `.eh_frame` from being emitted for `-C panic=abort`) - rust-lang#112517 (`suspicious_double_ref_op`: don't lint on `.borrow()`) - rust-lang#112529 (Extend `unused_must_use` to cover block exprs) - rust-lang#112614 (tweak suggestion for argument-position `impl ?Sized`) - rust-lang#112654 (normalize closure output in equate_inputs_and_outputs) - rust-lang#112660 (Migrate GUI colors test to original CSS color format) - rust-lang#112664 (Add support for test tmpdir to fuchsia test runner) - rust-lang#112669 (Fix comment for ptr alignment checks in codegen) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 114fb86 + 05d5449 commit 0252b40

File tree

55 files changed

+578
-213
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+578
-213
lines changed

compiler/rustc_arena/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ struct ArenaChunk<T = u8> {
6767

6868
unsafe impl<#[may_dangle] T> Drop for ArenaChunk<T> {
6969
fn drop(&mut self) {
70-
unsafe { Box::from_raw(self.storage.as_mut()) };
70+
unsafe { drop(Box::from_raw(self.storage.as_mut())) }
7171
}
7272
}
7373

compiler/rustc_borrowck/src/type_check/input_output.rs

+1-15
Original file line numberDiff line numberDiff line change
@@ -124,21 +124,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
124124
// Return types are a bit more complex. They may contain opaque `impl Trait` types.
125125
let mir_output_ty = body.local_decls[RETURN_PLACE].ty;
126126
let output_span = body.local_decls[RETURN_PLACE].source_info.span;
127-
if let Err(terr) = self.eq_types(
128-
normalized_output_ty,
129-
mir_output_ty,
130-
Locations::All(output_span),
131-
ConstraintCategory::BoringNoLocation,
132-
) {
133-
span_mirbug!(
134-
self,
135-
Location::START,
136-
"equate_inputs_and_outputs: `{:?}=={:?}` failed with `{:?}`",
137-
normalized_output_ty,
138-
mir_output_ty,
139-
terr
140-
);
141-
};
127+
self.equate_normalized_input_or_output(normalized_output_ty, mir_output_ty, output_span);
142128
}
143129

144130
#[instrument(skip(self), level = "debug")]

compiler/rustc_codegen_ssa/src/mir/block.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
616616
AssertKind::MisalignedPointerDereference { ref required, ref found } => {
617617
let required = self.codegen_operand(bx, required).immediate();
618618
let found = self.codegen_operand(bx, found).immediate();
619-
// It's `fn panic_bounds_check(index: usize, len: usize)`,
619+
// It's `fn panic_misaligned_pointer_dereference(required: usize, found: usize)`,
620620
// and `#[track_caller]` adds an implicit third argument.
621621
(LangItem::PanicMisalignedPointerDereference, vec![required, found, location])
622622
}

compiler/rustc_lint/messages.ftl

+5-7
Original file line numberDiff line numberDiff line change
@@ -479,13 +479,11 @@ lint_requested_level = requested on the command line with `{$level} {$lint_name}
479479
lint_supertrait_as_deref_target = `{$t}` implements `Deref` with supertrait `{$target_principal}` as target
480480
.label = target type is set here
481481
482-
lint_suspicious_double_ref_op =
483-
using `.{$call}()` on a double reference, which returns `{$ty}` instead of {$op ->
484-
*[should_not_happen] [{$op}]
485-
[deref] dereferencing
486-
[borrow] borrowing
487-
[clone] cloning
488-
} the inner type
482+
lint_suspicious_double_ref_clone =
483+
using `.clone()` on a double reference, which returns `{$ty}` instead of cloning the inner type
484+
485+
lint_suspicious_double_ref_deref =
486+
using `.deref()` on a double reference, which returns `{$ty}` instead of dereferencing the inner type
489487
490488
lint_trivial_untranslatable_diag = diagnostic with static strings only
491489

compiler/rustc_lint/src/lints.rs

+50-15
Original file line numberDiff line numberDiff line change
@@ -1231,11 +1231,15 @@ pub struct NoopMethodCallDiag<'a> {
12311231
}
12321232

12331233
#[derive(LintDiagnostic)]
1234-
#[diag(lint_suspicious_double_ref_op)]
1235-
pub struct SuspiciousDoubleRefDiag<'a> {
1236-
pub call: Symbol,
1234+
#[diag(lint_suspicious_double_ref_deref)]
1235+
pub struct SuspiciousDoubleRefDerefDiag<'a> {
1236+
pub ty: Ty<'a>,
1237+
}
1238+
1239+
#[derive(LintDiagnostic)]
1240+
#[diag(lint_suspicious_double_ref_clone)]
1241+
pub struct SuspiciousDoubleRefCloneDiag<'a> {
12371242
pub ty: Ty<'a>,
1238-
pub op: &'static str,
12391243
}
12401244

12411245
// pass_by_value.rs
@@ -1551,8 +1555,29 @@ pub struct UnusedOp<'a> {
15511555
pub op: &'a str,
15521556
#[label]
15531557
pub label: Span,
1554-
#[suggestion(style = "verbose", code = "let _ = ", applicability = "maybe-incorrect")]
1555-
pub suggestion: Span,
1558+
#[subdiagnostic]
1559+
pub suggestion: UnusedOpSuggestion,
1560+
}
1561+
1562+
#[derive(Subdiagnostic)]
1563+
pub enum UnusedOpSuggestion {
1564+
#[suggestion(
1565+
lint_suggestion,
1566+
style = "verbose",
1567+
code = "let _ = ",
1568+
applicability = "maybe-incorrect"
1569+
)]
1570+
NormalExpr {
1571+
#[primary_span]
1572+
span: Span,
1573+
},
1574+
#[multipart_suggestion(lint_suggestion, style = "verbose", applicability = "maybe-incorrect")]
1575+
BlockTailExpr {
1576+
#[suggestion_part(code = "let _ = ")]
1577+
before_span: Span,
1578+
#[suggestion_part(code = ";")]
1579+
after_span: Span,
1580+
},
15561581
}
15571582

15581583
#[derive(LintDiagnostic)]
@@ -1595,15 +1620,25 @@ pub struct UnusedDef<'a, 'b> {
15951620
}
15961621

15971622
#[derive(Subdiagnostic)]
1598-
#[suggestion(
1599-
lint_suggestion,
1600-
style = "verbose",
1601-
code = "let _ = ",
1602-
applicability = "maybe-incorrect"
1603-
)]
1604-
pub struct UnusedDefSuggestion {
1605-
#[primary_span]
1606-
pub span: Span,
1623+
1624+
pub enum UnusedDefSuggestion {
1625+
#[suggestion(
1626+
lint_suggestion,
1627+
style = "verbose",
1628+
code = "let _ = ",
1629+
applicability = "maybe-incorrect"
1630+
)]
1631+
NormalExpr {
1632+
#[primary_span]
1633+
span: Span,
1634+
},
1635+
#[multipart_suggestion(lint_suggestion, style = "verbose", applicability = "maybe-incorrect")]
1636+
BlockTailExpr {
1637+
#[suggestion_part(code = "let _ = ")]
1638+
before_span: Span,
1639+
#[suggestion_part(code = ";")]
1640+
after_span: Span,
1641+
},
16071642
}
16081643

16091644
// Needed because of def_path_str

compiler/rustc_lint/src/noop_method_call.rs

+34-28
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use crate::context::LintContext;
2-
use crate::lints::{NoopMethodCallDiag, SuspiciousDoubleRefDiag};
2+
use crate::lints::{
3+
NoopMethodCallDiag, SuspiciousDoubleRefCloneDiag, SuspiciousDoubleRefDerefDiag,
4+
};
35
use crate::LateContext;
46
use crate::LateLintPass;
57
use rustc_hir::def::DefKind;
@@ -76,22 +78,22 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall {
7678

7779
// We only care about method calls corresponding to the `Clone`, `Deref` and `Borrow`
7880
// traits and ignore any other method call.
79-
let did = match cx.typeck_results().type_dependent_def(expr.hir_id) {
80-
// Verify we are dealing with a method/associated function.
81-
Some((DefKind::AssocFn, did)) => match cx.tcx.trait_of_item(did) {
82-
// Check that we're dealing with a trait method for one of the traits we care about.
83-
Some(trait_id)
84-
if matches!(
85-
cx.tcx.get_diagnostic_name(trait_id),
86-
Some(sym::Borrow | sym::Clone | sym::Deref)
87-
) =>
88-
{
89-
did
90-
}
91-
_ => return,
92-
},
93-
_ => return,
81+
82+
let Some((DefKind::AssocFn, did)) =
83+
cx.typeck_results().type_dependent_def(expr.hir_id)
84+
else {
85+
return;
86+
};
87+
88+
let Some(trait_id) = cx.tcx.trait_of_item(did) else { return };
89+
90+
if !matches!(
91+
cx.tcx.get_diagnostic_name(trait_id),
92+
Some(sym::Borrow | sym::Clone | sym::Deref)
93+
) {
94+
return;
9495
};
96+
9597
let substs = cx
9698
.tcx
9799
.normalize_erasing_regions(cx.param_env, cx.typeck_results().node_substs(expr.hir_id));
@@ -102,13 +104,6 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall {
102104
// (Re)check that it implements the noop diagnostic.
103105
let Some(name) = cx.tcx.get_diagnostic_name(i.def_id()) else { return };
104106

105-
let op = match name {
106-
sym::noop_method_borrow => "borrow",
107-
sym::noop_method_clone => "clone",
108-
sym::noop_method_deref => "deref",
109-
_ => return,
110-
};
111-
112107
let receiver_ty = cx.typeck_results().expr_ty(receiver);
113108
let expr_ty = cx.typeck_results().expr_ty_adjusted(expr);
114109
let arg_adjustments = cx.typeck_results().expr_adjustments(receiver);
@@ -129,11 +124,22 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall {
129124
NoopMethodCallDiag { method: call.ident.name, receiver_ty, label: span },
130125
);
131126
} else {
132-
cx.emit_spanned_lint(
133-
SUSPICIOUS_DOUBLE_REF_OP,
134-
span,
135-
SuspiciousDoubleRefDiag { call: call.ident.name, ty: expr_ty, op },
136-
)
127+
match name {
128+
// If `type_of(x) == T` and `x.borrow()` is used to get `&T`,
129+
// then that should be allowed
130+
sym::noop_method_borrow => return,
131+
sym::noop_method_clone => cx.emit_spanned_lint(
132+
SUSPICIOUS_DOUBLE_REF_OP,
133+
span,
134+
SuspiciousDoubleRefCloneDiag { ty: expr_ty },
135+
),
136+
sym::noop_method_deref => cx.emit_spanned_lint(
137+
SUSPICIOUS_DOUBLE_REF_OP,
138+
span,
139+
SuspiciousDoubleRefDerefDiag { ty: expr_ty },
140+
),
141+
_ => return,
142+
}
137143
}
138144
}
139145
}

0 commit comments

Comments
 (0)