Skip to content

Commit eaee1e9

Browse files
committed
Auto merge of rust-lang#121870 - matthiaskrgr:rollup-mfpa3jx, r=matthiaskrgr
Rollup of 11 pull requests Successful merges: - rust-lang#111505 (Made `INVALID_DOC_ATTRIBUTES` lint deny by default) - rust-lang#120305 (Delete line if suggestion would replace it with an empty line) - rust-lang#121153 (Suggest removing superfluous semicolon when statements used as expression) - rust-lang#121497 (`-Znext-solver=coherence`: suggest increasing recursion limit) - rust-lang#121634 (Clarify behavior of slice prefix/suffix operations in case of equality) - rust-lang#121706 (match lowering: Remove hacky branch in sort_candidate) - rust-lang#121730 (Add profiling support to AIX) - rust-lang#121750 (match lowering: Separate the `bool` case from other integers in `TestKind`) - rust-lang#121803 (Never say "`Trait` is implemented for `{type error}`") - rust-lang#121811 (Move sanitizer ui tests to sanitizer directory) - rust-lang#121824 (Implement missing ABI structures in StableMIR) r? `@ghost` `@rustbot` modify labels: rollup
2 parents e612d07 + 63e916e commit eaee1e9

File tree

137 files changed

+1165
-708
lines changed

Some content is hidden

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

137 files changed

+1165
-708
lines changed

compiler/rustc_codegen_ssa/src/back/linker.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1631,7 +1631,9 @@ impl<'a> Linker for AixLinker<'a> {
16311631

16321632
fn optimize(&mut self) {}
16331633

1634-
fn pgo_gen(&mut self) {}
1634+
fn pgo_gen(&mut self) {
1635+
self.cmd.arg("-bdbg:namedsects:ss");
1636+
}
16351637

16361638
fn control_flow_guard(&mut self) {}
16371639

compiler/rustc_errors/src/json.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -428,14 +428,24 @@ impl DiagnosticSpan {
428428
}
429429

430430
fn from_span_full(
431-
span: Span,
431+
mut span: Span,
432432
is_primary: bool,
433433
label: Option<String>,
434434
suggestion: Option<(&String, Applicability)>,
435435
mut backtrace: impl Iterator<Item = ExpnData>,
436436
je: &JsonEmitter,
437437
) -> DiagnosticSpan {
438438
let start = je.sm.lookup_char_pos(span.lo());
439+
// If this goes from the start of a line to the end and the replacement
440+
// is an empty string, increase the length to include the newline so we don't
441+
// leave an empty line
442+
if start.col.0 == 0
443+
&& suggestion.map_or(false, |(s, _)| s.is_empty())
444+
&& let Ok(after) = je.sm.span_to_next_source(span)
445+
&& after.starts_with('\n')
446+
{
447+
span = span.with_hi(span.hi() + rustc_span::BytePos(1));
448+
}
439449
let end = je.sm.lookup_char_pos(span.hi());
440450
let backtrace_step = backtrace.next().map(|bt| {
441451
let call_site = Self::from_span_full(bt.call_site, false, None, None, backtrace, je);

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1744,7 +1744,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17441744
Ty::new_unit(self.tcx),
17451745
);
17461746
}
1747-
if !self.consider_removing_semicolon(blk, expected_ty, err) {
1747+
if !self.err_ctxt().consider_removing_semicolon(
1748+
blk,
1749+
expected_ty,
1750+
err,
1751+
) {
17481752
self.err_ctxt().consider_returning_binding(
17491753
blk,
17501754
expected_ty,

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+1-40
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc_hir::{
2222
Path, QPath, Stmt, StmtKind, TyKind, WherePredicate,
2323
};
2424
use rustc_hir_analysis::astconv::AstConv;
25-
use rustc_infer::traits::{self, StatementAsExpression};
25+
use rustc_infer::traits::{self};
2626
use rustc_middle::lint::in_external_macro;
2727
use rustc_middle::middle::stability::EvalResult;
2828
use rustc_middle::ty::print::with_no_trimmed_paths;
@@ -1791,45 +1791,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17911791
}
17921792
}
17931793

1794-
/// A common error is to add an extra semicolon:
1795-
///
1796-
/// ```compile_fail,E0308
1797-
/// fn foo() -> usize {
1798-
/// 22;
1799-
/// }
1800-
/// ```
1801-
///
1802-
/// This routine checks if the final statement in a block is an
1803-
/// expression with an explicit semicolon whose type is compatible
1804-
/// with `expected_ty`. If so, it suggests removing the semicolon.
1805-
pub(crate) fn consider_removing_semicolon(
1806-
&self,
1807-
blk: &'tcx hir::Block<'tcx>,
1808-
expected_ty: Ty<'tcx>,
1809-
err: &mut Diag<'_>,
1810-
) -> bool {
1811-
if let Some((span_semi, boxed)) = self.err_ctxt().could_remove_semicolon(blk, expected_ty) {
1812-
if let StatementAsExpression::NeedsBoxing = boxed {
1813-
err.span_suggestion_verbose(
1814-
span_semi,
1815-
"consider removing this semicolon and boxing the expression",
1816-
"",
1817-
Applicability::HasPlaceholders,
1818-
);
1819-
} else {
1820-
err.span_suggestion_short(
1821-
span_semi,
1822-
"remove this semicolon to return this value",
1823-
"",
1824-
Applicability::MachineApplicable,
1825-
);
1826-
}
1827-
true
1828-
} else {
1829-
false
1830-
}
1831-
}
1832-
18331794
pub(crate) fn is_field_suggestable(
18341795
&self,
18351796
field: &ty::FieldDef,

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1989,6 +1989,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
19891989
self.suggest_accessing_field_where_appropriate(cause, &exp_found, diag);
19901990
self.suggest_await_on_expect_found(cause, span, &exp_found, diag);
19911991
self.suggest_function_pointers(cause, span, &exp_found, diag);
1992+
self.suggest_turning_stmt_into_expr(cause, &exp_found, diag);
19921993
}
19931994
}
19941995

compiler/rustc_infer/src/infer/error_reporting/suggest.rs

+96
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
use crate::infer::error_reporting::hir::Path;
12
use hir::def::CtorKind;
23
use hir::intravisit::{walk_expr, walk_stmt, Visitor};
4+
use hir::{Local, QPath};
35
use rustc_data_structures::fx::FxIndexSet;
46
use rustc_errors::{Applicability, Diag};
57
use rustc_hir as hir;
8+
use rustc_hir::def::Res;
9+
use rustc_hir::MatchSource;
10+
use rustc_hir::Node;
611
use rustc_middle::traits::{
712
IfExpressionCause, MatchExpressionArmCause, ObligationCause, ObligationCauseCode,
813
StatementAsExpression,
@@ -293,6 +298,97 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
293298
}
294299
}
295300

301+
pub(super) fn suggest_turning_stmt_into_expr(
302+
&self,
303+
cause: &ObligationCause<'tcx>,
304+
exp_found: &ty::error::ExpectedFound<Ty<'tcx>>,
305+
diag: &mut Diag<'_>,
306+
) {
307+
let ty::error::ExpectedFound { expected, found } = exp_found;
308+
if !found.peel_refs().is_unit() {
309+
return;
310+
}
311+
312+
let ObligationCauseCode::BlockTailExpression(hir_id, MatchSource::Normal) = cause.code()
313+
else {
314+
return;
315+
};
316+
317+
let node = self.tcx.hir_node(*hir_id);
318+
let mut blocks = vec![];
319+
if let hir::Node::Block(block) = node
320+
&& let Some(expr) = block.expr
321+
&& let hir::ExprKind::Path(QPath::Resolved(_, Path { res, .. })) = expr.kind
322+
&& let Res::Local(local) = res
323+
&& let Node::Local(Local { init: Some(init), .. }) = self.tcx.parent_hir_node(*local)
324+
{
325+
fn collect_blocks<'hir>(expr: &hir::Expr<'hir>, blocks: &mut Vec<&hir::Block<'hir>>) {
326+
match expr.kind {
327+
// `blk1` and `blk2` must be have the same types, it will be reported before reaching here
328+
hir::ExprKind::If(_, blk1, Some(blk2)) => {
329+
collect_blocks(blk1, blocks);
330+
collect_blocks(blk2, blocks);
331+
}
332+
hir::ExprKind::Match(_, arms, _) => {
333+
// all arms must have same types
334+
for arm in arms.iter() {
335+
collect_blocks(arm.body, blocks);
336+
}
337+
}
338+
hir::ExprKind::Block(blk, _) => {
339+
blocks.push(blk);
340+
}
341+
_ => {}
342+
}
343+
}
344+
collect_blocks(init, &mut blocks);
345+
}
346+
347+
let expected_inner: Ty<'_> = expected.peel_refs();
348+
for block in blocks.iter() {
349+
self.consider_removing_semicolon(block, expected_inner, diag);
350+
}
351+
}
352+
353+
/// A common error is to add an extra semicolon:
354+
///
355+
/// ```compile_fail,E0308
356+
/// fn foo() -> usize {
357+
/// 22;
358+
/// }
359+
/// ```
360+
///
361+
/// This routine checks if the final statement in a block is an
362+
/// expression with an explicit semicolon whose type is compatible
363+
/// with `expected_ty`. If so, it suggests removing the semicolon.
364+
pub fn consider_removing_semicolon(
365+
&self,
366+
blk: &'tcx hir::Block<'tcx>,
367+
expected_ty: Ty<'tcx>,
368+
diag: &mut Diag<'_>,
369+
) -> bool {
370+
if let Some((span_semi, boxed)) = self.could_remove_semicolon(blk, expected_ty) {
371+
if let StatementAsExpression::NeedsBoxing = boxed {
372+
diag.span_suggestion_verbose(
373+
span_semi,
374+
"consider removing this semicolon and boxing the expression",
375+
"",
376+
Applicability::HasPlaceholders,
377+
);
378+
} else {
379+
diag.span_suggestion_short(
380+
span_semi,
381+
"remove this semicolon to return this value",
382+
"",
383+
Applicability::MachineApplicable,
384+
);
385+
}
386+
true
387+
} else {
388+
false
389+
}
390+
}
391+
296392
pub(super) fn suggest_function_pointers(
297393
&self,
298394
cause: &ObligationCause<'tcx>,

compiler/rustc_infer/src/traits/mod.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,18 @@ pub struct FulfillmentError<'tcx> {
135135

136136
#[derive(Clone)]
137137
pub enum FulfillmentErrorCode<'tcx> {
138-
/// Inherently impossible to fulfill; this trait is implemented if and only if it is already implemented.
138+
/// Inherently impossible to fulfill; this trait is implemented if and only
139+
/// if it is already implemented.
139140
Cycle(Vec<PredicateObligation<'tcx>>),
140141
SelectionError(SelectionError<'tcx>),
141142
ProjectionError(MismatchedProjectionTypes<'tcx>),
142143
SubtypeError(ExpectedFound<Ty<'tcx>>, TypeError<'tcx>), // always comes from a SubtypePredicate
143144
ConstEquateError(ExpectedFound<Const<'tcx>>, TypeError<'tcx>),
144145
Ambiguity {
145-
/// Overflow reported from the new solver `-Znext-solver`, which will
146-
/// be reported as an regular error as opposed to a fatal error.
147-
overflow: bool,
146+
/// Overflow is only `Some(suggest_recursion_limit)` when using the next generation
147+
/// trait solver `-Znext-solver`. With the old solver overflow is eagerly handled by
148+
/// emitting a fatal error instead.
149+
overflow: Option<bool>,
148150
},
149151
}
150152

compiler/rustc_infer/src/traits/structural_impls.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ impl<'tcx> fmt::Debug for traits::FulfillmentErrorCode<'tcx> {
4747
ConstEquateError(ref a, ref b) => {
4848
write!(f, "CodeConstEquateError({a:?}, {b:?})")
4949
}
50-
Ambiguity { overflow: false } => write!(f, "Ambiguity"),
51-
Ambiguity { overflow: true } => write!(f, "Overflow"),
50+
Ambiguity { overflow: None } => write!(f, "Ambiguity"),
51+
Ambiguity { overflow: Some(suggest_increasing_limit) } => {
52+
write!(f, "Overflow({suggest_increasing_limit})")
53+
}
5254
Cycle(ref cycle) => write!(f, "Cycle({cycle:?})"),
5355
}
5456
}

compiler/rustc_lint_defs/src/builtin.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -3586,18 +3586,9 @@ declare_lint! {
35863586
/// being validated. Usually these should be rejected as a hard error,
35873587
/// but this lint was introduced to avoid breaking any existing
35883588
/// crates which included them.
3589-
///
3590-
/// This is a [future-incompatible] lint to transition this to a hard
3591-
/// error in the future. See [issue #82730] for more details.
3592-
///
3593-
/// [issue #82730]: https://github.com/rust-lang/rust/issues/82730
35943589
pub INVALID_DOC_ATTRIBUTES,
3595-
Warn,
3590+
Deny,
35963591
"detects invalid `#[doc(...)]` attributes",
3597-
@future_incompatible = FutureIncompatibleInfo {
3598-
reason: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps,
3599-
reference: "issue #82730 <https://github.com/rust-lang/rust/issues/82730>",
3600-
};
36013592
}
36023593

36033594
declare_lint! {

compiler/rustc_middle/src/traits/solve.rs

+20-10
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ pub enum Certainty {
6060

6161
impl Certainty {
6262
pub const AMBIGUOUS: Certainty = Certainty::Maybe(MaybeCause::Ambiguity);
63-
pub const OVERFLOW: Certainty = Certainty::Maybe(MaybeCause::Overflow);
6463

6564
/// Use this function to merge the certainty of multiple nested subgoals.
6665
///
@@ -79,16 +78,13 @@ impl Certainty {
7978
(Certainty::Yes, Certainty::Yes) => Certainty::Yes,
8079
(Certainty::Yes, Certainty::Maybe(_)) => other,
8180
(Certainty::Maybe(_), Certainty::Yes) => self,
82-
(Certainty::Maybe(MaybeCause::Ambiguity), Certainty::Maybe(MaybeCause::Ambiguity)) => {
83-
Certainty::Maybe(MaybeCause::Ambiguity)
84-
}
85-
(Certainty::Maybe(MaybeCause::Ambiguity), Certainty::Maybe(MaybeCause::Overflow))
86-
| (Certainty::Maybe(MaybeCause::Overflow), Certainty::Maybe(MaybeCause::Ambiguity))
87-
| (Certainty::Maybe(MaybeCause::Overflow), Certainty::Maybe(MaybeCause::Overflow)) => {
88-
Certainty::Maybe(MaybeCause::Overflow)
89-
}
81+
(Certainty::Maybe(a), Certainty::Maybe(b)) => Certainty::Maybe(a.unify_with(b)),
9082
}
9183
}
84+
85+
pub const fn overflow(suggest_increasing_limit: bool) -> Certainty {
86+
Certainty::Maybe(MaybeCause::Overflow { suggest_increasing_limit })
87+
}
9288
}
9389

9490
/// Why we failed to evaluate a goal.
@@ -99,7 +95,21 @@ pub enum MaybeCause {
9995
/// or we hit a case where we just don't bother, e.g. `?x: Trait` goals.
10096
Ambiguity,
10197
/// We gave up due to an overflow, most often by hitting the recursion limit.
102-
Overflow,
98+
Overflow { suggest_increasing_limit: bool },
99+
}
100+
101+
impl MaybeCause {
102+
fn unify_with(self, other: MaybeCause) -> MaybeCause {
103+
match (self, other) {
104+
(MaybeCause::Ambiguity, MaybeCause::Ambiguity) => MaybeCause::Ambiguity,
105+
(MaybeCause::Ambiguity, MaybeCause::Overflow { .. }) => other,
106+
(MaybeCause::Overflow { .. }, MaybeCause::Ambiguity) => self,
107+
(
108+
MaybeCause::Overflow { suggest_increasing_limit: a },
109+
MaybeCause::Overflow { suggest_increasing_limit: b },
110+
) => MaybeCause::Overflow { suggest_increasing_limit: a || b },
111+
}
112+
}
103113
}
104114

105115
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, HashStable, TypeFoldable, TypeVisitable)]

compiler/rustc_mir_build/src/build/matches/mod.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -1097,21 +1097,18 @@ enum TestKind<'tcx> {
10971097
variants: BitSet<VariantIdx>,
10981098
},
10991099

1100-
/// Test what value an integer, `bool`, or `char` has.
1100+
/// Test what value an integer or `char` has.
11011101
SwitchInt {
1102-
/// The type of the value that we're testing.
1103-
switch_ty: Ty<'tcx>,
11041102
/// The (ordered) set of values that we test for.
11051103
///
1106-
/// For integers and `char`s we create a branch to each of the values in
1107-
/// `options`, as well as an "otherwise" branch for all other values, even
1108-
/// in the (rare) case that `options` is exhaustive.
1109-
///
1110-
/// For `bool` we always generate two edges, one for `true` and one for
1111-
/// `false`.
1104+
/// We create a branch to each of the values in `options`, as well as an "otherwise" branch
1105+
/// for all other values, even in the (rare) case that `options` is exhaustive.
11121106
options: FxIndexMap<Const<'tcx>, u128>,
11131107
},
11141108

1109+
/// Test what value a `bool` has.
1110+
If,
1111+
11151112
/// Test for equality with value, possibly after an unsizing coercion to
11161113
/// `ty`,
11171114
Eq {
@@ -1617,7 +1614,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
16171614
// a test like SwitchInt, we may want to add cases based on the candidates that are
16181615
// available
16191616
match test.kind {
1620-
TestKind::SwitchInt { switch_ty: _, ref mut options } => {
1617+
TestKind::SwitchInt { ref mut options } => {
16211618
for candidate in candidates.iter() {
16221619
if !self.add_cases_to_switch(&match_place, candidate, options) {
16231620
break;

0 commit comments

Comments
 (0)