Skip to content

Commit 51917e2

Browse files
committed
Auto merge of rust-lang#127403 - compiler-errors:rollup-x2yb5t0, r=compiler-errors
Rollup of 8 pull requests Successful merges: - rust-lang#123600 (impl PathBuf::add_extension and Path::with_added_extension) - rust-lang#127107 (Improve dead code analysis) - rust-lang#127221 (Improve well known value check-cfg diagnostic for the standard library) - rust-lang#127333 (Split `SolverDelegate` back out from `InferCtxtLike`) - rust-lang#127363 (Improve readability of some fmt code examples) - rust-lang#127366 (Use `ControlFlow` results for visitors that are only looking for a single value) - rust-lang#127368 (Added dots at the sentence ends of rustc AST doc) - rust-lang#127393 (Remove clubby789 from review rotation) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 5c08cc7 + b73a790 commit 51917e2

Some content is hidden

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

46 files changed

+736
-455
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -4170,6 +4170,7 @@ dependencies = [
41704170
"rustc_middle",
41714171
"rustc_span",
41724172
"rustc_target",
4173+
"rustc_type_ir",
41734174
"smallvec",
41744175
"tracing",
41754176
]

compiler/rustc_ast/src/ast.rs

+32-32
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ pub enum GenericArgs {
176176
AngleBracketed(AngleBracketedArgs),
177177
/// The `(A, B)` and `C` in `Foo(A, B) -> C`.
178178
Parenthesized(ParenthesizedArgs),
179-
/// `(..)` in return type notation
179+
/// `(..)` in return type notation.
180180
ParenthesizedElided(Span),
181181
}
182182

@@ -197,11 +197,11 @@ impl GenericArgs {
197197
/// Concrete argument in the sequence of generic args.
198198
#[derive(Clone, Encodable, Decodable, Debug)]
199199
pub enum GenericArg {
200-
/// `'a` in `Foo<'a>`
200+
/// `'a` in `Foo<'a>`.
201201
Lifetime(Lifetime),
202-
/// `Bar` in `Foo<Bar>`
202+
/// `Bar` in `Foo<Bar>`.
203203
Type(P<Ty>),
204-
/// `1` in `Foo<1>`
204+
/// `1` in `Foo<1>`.
205205
Const(AnonConst),
206206
}
207207

@@ -355,7 +355,7 @@ pub enum GenericParamKind {
355355
ty: P<Ty>,
356356
/// Span of the `const` keyword.
357357
kw_span: Span,
358-
/// Optional default value for the const generic param
358+
/// Optional default value for the const generic param.
359359
default: Option<AnonConst>,
360360
},
361361
}
@@ -833,7 +833,7 @@ pub enum PatKind {
833833
/// only one rest pattern may occur in the pattern sequences.
834834
Rest,
835835

836-
// A never pattern `!`
836+
// A never pattern `!`.
837837
Never,
838838

839839
/// Parentheses in patterns used for grouping (i.e., `(PAT)`).
@@ -1122,9 +1122,9 @@ impl LocalKind {
11221122
#[derive(Clone, Encodable, Decodable, Debug)]
11231123
pub struct Arm {
11241124
pub attrs: AttrVec,
1125-
/// Match arm pattern, e.g. `10` in `match foo { 10 => {}, _ => {} }`
1125+
/// Match arm pattern, e.g. `10` in `match foo { 10 => {}, _ => {} }`.
11261126
pub pat: P<Pat>,
1127-
/// Match arm guard, e.g. `n > 10` in `match foo { n if n > 10 => {}, _ => {} }`
1127+
/// Match arm guard, e.g. `n > 10` in `match foo { n if n > 10 => {}, _ => {} }`.
11281128
pub guard: Option<P<Expr>>,
11291129
/// Match arm body. Omitted if the pattern is a never pattern.
11301130
pub body: Option<P<Expr>>,
@@ -1355,12 +1355,12 @@ pub struct Closure {
13551355
pub fn_arg_span: Span,
13561356
}
13571357

1358-
/// Limit types of a range (inclusive or exclusive)
1358+
/// Limit types of a range (inclusive or exclusive).
13591359
#[derive(Copy, Clone, PartialEq, Encodable, Decodable, Debug)]
13601360
pub enum RangeLimits {
1361-
/// Inclusive at the beginning, exclusive at the end
1361+
/// Inclusive at the beginning, exclusive at the end.
13621362
HalfOpen,
1363-
/// Inclusive at the beginning and end
1363+
/// Inclusive at the beginning and end.
13641364
Closed,
13651365
}
13661366

@@ -1401,9 +1401,9 @@ pub struct StructExpr {
14011401
pub enum ExprKind {
14021402
/// An array (e.g, `[a, b, c, d]`).
14031403
Array(ThinVec<P<Expr>>),
1404-
/// Allow anonymous constants from an inline `const` block
1404+
/// Allow anonymous constants from an inline `const` block.
14051405
ConstBlock(AnonConst),
1406-
/// A function call
1406+
/// A function call.
14071407
///
14081408
/// The first field resolves to the function itself,
14091409
/// and the second field is the list of arguments.
@@ -1457,7 +1457,7 @@ pub enum ExprKind {
14571457
/// A block (`'label: { ... }`).
14581458
Block(P<Block>, Option<Label>),
14591459
/// An `async` block (`async move { ... }`),
1460-
/// or a `gen` block (`gen move { ... }`)
1460+
/// or a `gen` block (`gen move { ... }`).
14611461
///
14621462
/// The span is the "decl", which is the header before the body `{ }`
14631463
/// including the `asyng`/`gen` keywords and possibly `move`.
@@ -2157,9 +2157,9 @@ pub enum TyKind {
21572157
Never,
21582158
/// A tuple (`(A, B, C, D,...)`).
21592159
Tup(ThinVec<P<Ty>>),
2160-
/// An anonymous struct type i.e. `struct { foo: Type }`
2160+
/// An anonymous struct type i.e. `struct { foo: Type }`.
21612161
AnonStruct(NodeId, ThinVec<FieldDef>),
2162-
/// An anonymous union type i.e. `union { bar: Type }`
2162+
/// An anonymous union type i.e. `union { bar: Type }`.
21632163
AnonUnion(NodeId, ThinVec<FieldDef>),
21642164
/// A path (`module::module::...::Type`), optionally
21652165
/// "qualified", e.g., `<Vec<T> as SomeTrait>::SomeType`.
@@ -2233,9 +2233,9 @@ pub enum TraitObjectSyntax {
22332233

22342234
#[derive(Clone, Encodable, Decodable, Debug)]
22352235
pub enum PreciseCapturingArg {
2236-
/// Lifetime parameter
2236+
/// Lifetime parameter.
22372237
Lifetime(Lifetime),
2238-
/// Type or const parameter
2238+
/// Type or const parameter.
22392239
Arg(Path, NodeId),
22402240
}
22412241

@@ -2529,11 +2529,11 @@ pub enum Safety {
25292529
/// Iterator`.
25302530
#[derive(Copy, Clone, Encodable, Decodable, Debug)]
25312531
pub enum CoroutineKind {
2532-
/// `async`, which returns an `impl Future`
2532+
/// `async`, which returns an `impl Future`.
25332533
Async { span: Span, closure_id: NodeId, return_impl_trait_id: NodeId },
2534-
/// `gen`, which returns an `impl Iterator`
2534+
/// `gen`, which returns an `impl Iterator`.
25352535
Gen { span: Span, closure_id: NodeId, return_impl_trait_id: NodeId },
2536-
/// `async gen`, which returns an `impl AsyncIterator`
2536+
/// `async gen`, which returns an `impl AsyncIterator`.
25372537
AsyncGen { span: Span, closure_id: NodeId, return_impl_trait_id: NodeId },
25382538
}
25392539

@@ -2750,7 +2750,7 @@ pub struct Variant {
27502750
pub data: VariantData,
27512751
/// Explicit discriminant, e.g., `Foo = 1`.
27522752
pub disr_expr: Option<AnonConst>,
2753-
/// Is a macro placeholder
2753+
/// Is a macro placeholder.
27542754
pub is_placeholder: bool,
27552755
}
27562756

@@ -3024,19 +3024,19 @@ impl Item {
30243024
/// `extern` qualifier on a function item or function type.
30253025
#[derive(Clone, Copy, Encodable, Decodable, Debug)]
30263026
pub enum Extern {
3027-
/// No explicit extern keyword was used
3027+
/// No explicit extern keyword was used.
30283028
///
3029-
/// E.g. `fn foo() {}`
3029+
/// E.g. `fn foo() {}`.
30303030
None,
3031-
/// An explicit extern keyword was used, but with implicit ABI
3031+
/// An explicit extern keyword was used, but with implicit ABI.
30323032
///
3033-
/// E.g. `extern fn foo() {}`
3033+
/// E.g. `extern fn foo() {}`.
30343034
///
3035-
/// This is just `extern "C"` (see `rustc_target::spec::abi::Abi::FALLBACK`)
3035+
/// This is just `extern "C"` (see `rustc_target::spec::abi::Abi::FALLBACK`).
30363036
Implicit(Span),
3037-
/// An explicit extern keyword was used with an explicit ABI
3037+
/// An explicit extern keyword was used with an explicit ABI.
30383038
///
3039-
/// E.g. `extern "C" fn foo() {}`
3039+
/// E.g. `extern "C" fn foo() {}`.
30403040
Explicit(StrLit, Span),
30413041
}
30423042

@@ -3055,13 +3055,13 @@ impl Extern {
30553055
/// included in this struct (e.g., `async unsafe fn` or `const extern "C" fn`).
30563056
#[derive(Clone, Copy, Encodable, Decodable, Debug)]
30573057
pub struct FnHeader {
3058-
/// Whether this is `unsafe`, or has a default safety
3058+
/// Whether this is `unsafe`, or has a default safety.
30593059
pub safety: Safety,
30603060
/// Whether this is `async`, `gen`, or nothing.
30613061
pub coroutine_kind: Option<CoroutineKind>,
30623062
/// The `const` keyword, if any
30633063
pub constness: Const,
3064-
/// The `extern` keyword and corresponding ABI string, if any
3064+
/// The `extern` keyword and corresponding ABI string, if any.
30653065
pub ext: Extern,
30663066
}
30673067

@@ -3255,7 +3255,7 @@ pub enum ItemKind {
32553255
///
32563256
/// E.g., `trait Foo { .. }`, `trait Foo<T> { .. }` or `auto trait Foo {}`.
32573257
Trait(Box<Trait>),
3258-
/// Trait alias
3258+
/// Trait alias.
32593259
///
32603260
/// E.g., `trait Foo = Bar + Quux;`.
32613261
TraitAlias(Generics, GenericBounds),

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+23-38
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ use rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt;
3939
use rustc_trait_selection::traits::error_reporting::FindExprBySpan;
4040
use rustc_trait_selection::traits::{Obligation, ObligationCause, ObligationCtxt};
4141
use std::iter;
42+
use std::ops::ControlFlow;
4243

4344
use crate::borrow_set::TwoPhaseActivation;
4445
use crate::borrowck_errors;
@@ -784,20 +785,20 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
784785
/// binding declaration within every scope we inspect.
785786
struct Finder {
786787
hir_id: hir::HirId,
787-
found: bool,
788788
}
789789
impl<'hir> Visitor<'hir> for Finder {
790-
fn visit_pat(&mut self, pat: &'hir hir::Pat<'hir>) {
790+
type Result = ControlFlow<()>;
791+
fn visit_pat(&mut self, pat: &'hir hir::Pat<'hir>) -> Self::Result {
791792
if pat.hir_id == self.hir_id {
792-
self.found = true;
793+
return ControlFlow::Break(());
793794
}
794-
hir::intravisit::walk_pat(self, pat);
795+
hir::intravisit::walk_pat(self, pat)
795796
}
796-
fn visit_expr(&mut self, ex: &'hir hir::Expr<'hir>) {
797+
fn visit_expr(&mut self, ex: &'hir hir::Expr<'hir>) -> Self::Result {
797798
if ex.hir_id == self.hir_id {
798-
self.found = true;
799+
return ControlFlow::Break(());
799800
}
800-
hir::intravisit::walk_expr(self, ex);
801+
hir::intravisit::walk_expr(self, ex)
801802
}
802803
}
803804
// The immediate HIR parent of the moved expression. We'll look for it to be a call.
@@ -822,9 +823,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
822823
_ => continue,
823824
};
824825
if let Some(&hir_id) = local_hir_id {
825-
let mut finder = Finder { hir_id, found: false };
826-
finder.visit_expr(e);
827-
if finder.found {
826+
if (Finder { hir_id }).visit_expr(e).is_break() {
828827
// The current scope includes the declaration of the binding we're accessing, we
829828
// can't look up any further for loops.
830829
break;
@@ -839,9 +838,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
839838
hir::Node::Expr(hir::Expr {
840839
kind: hir::ExprKind::If(cond, ..), ..
841840
}) => {
842-
let mut finder = Finder { hir_id: expr.hir_id, found: false };
843-
finder.visit_expr(cond);
844-
if finder.found {
841+
if (Finder { hir_id: expr.hir_id }).visit_expr(cond).is_break() {
845842
// The expression where the move error happened is in a `while let`
846843
// condition Don't suggest clone as it will likely end in an
847844
// infinite loop.
@@ -1837,15 +1834,14 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
18371834

18381835
pub struct Holds<'tcx> {
18391836
ty: Ty<'tcx>,
1840-
holds: bool,
18411837
}
18421838

18431839
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for Holds<'tcx> {
18441840
type Result = std::ops::ControlFlow<()>;
18451841

18461842
fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result {
18471843
if t == self.ty {
1848-
self.holds = true;
1844+
return ControlFlow::Break(());
18491845
}
18501846
t.super_visit_with(self)
18511847
}
@@ -1863,9 +1859,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
18631859
&& rcvr_ty == ty
18641860
&& let ty::Ref(_, inner, _) = rcvr_ty.kind()
18651861
&& let inner = inner.peel_refs()
1866-
&& let mut v = (Holds { ty: inner, holds: false })
1867-
&& let _ = v.visit_ty(local_ty)
1868-
&& v.holds
1862+
&& (Holds { ty: inner }).visit_ty(local_ty).is_break()
18691863
&& let None = self.infcx.type_implements_trait_shallow(clone, inner, self.param_env)
18701864
{
18711865
err.span_label(
@@ -4325,15 +4319,14 @@ impl<'tcx> AnnotatedBorrowFnSignature<'tcx> {
43254319
}
43264320

43274321
/// Detect whether one of the provided spans is a statement nested within the top-most visited expr
4328-
struct ReferencedStatementsVisitor<'a>(&'a [Span], bool);
4322+
struct ReferencedStatementsVisitor<'a>(&'a [Span]);
43294323

4330-
impl<'a, 'v> Visitor<'v> for ReferencedStatementsVisitor<'a> {
4331-
fn visit_stmt(&mut self, s: &'v hir::Stmt<'v>) {
4324+
impl<'v> Visitor<'v> for ReferencedStatementsVisitor<'_> {
4325+
type Result = ControlFlow<()>;
4326+
fn visit_stmt(&mut self, s: &'v hir::Stmt<'v>) -> Self::Result {
43324327
match s.kind {
4333-
hir::StmtKind::Semi(expr) if self.0.contains(&expr.span) => {
4334-
self.1 = true;
4335-
}
4336-
_ => {}
4328+
hir::StmtKind::Semi(expr) if self.0.contains(&expr.span) => ControlFlow::Break(()),
4329+
_ => ControlFlow::Continue(()),
43374330
}
43384331
}
43394332
}
@@ -4375,9 +4368,7 @@ impl<'b, 'v, 'tcx> Visitor<'v> for ConditionVisitor<'b, 'tcx> {
43754368
hir::ExprKind::If(cond, body, None) => {
43764369
// `if` expressions with no `else` that initialize the binding might be missing an
43774370
// `else` arm.
4378-
let mut v = ReferencedStatementsVisitor(self.spans, false);
4379-
v.visit_expr(body);
4380-
if v.1 {
4371+
if ReferencedStatementsVisitor(self.spans).visit_expr(body).is_break() {
43814372
self.errors.push((
43824373
cond.span,
43834374
format!(
@@ -4394,11 +4385,9 @@ impl<'b, 'v, 'tcx> Visitor<'v> for ConditionVisitor<'b, 'tcx> {
43944385
hir::ExprKind::If(cond, body, Some(other)) => {
43954386
// `if` expressions where the binding is only initialized in one of the two arms
43964387
// might be missing a binding initialization.
4397-
let mut a = ReferencedStatementsVisitor(self.spans, false);
4398-
a.visit_expr(body);
4399-
let mut b = ReferencedStatementsVisitor(self.spans, false);
4400-
b.visit_expr(other);
4401-
match (a.1, b.1) {
4388+
let a = ReferencedStatementsVisitor(self.spans).visit_expr(body).is_break();
4389+
let b = ReferencedStatementsVisitor(self.spans).visit_expr(other).is_break();
4390+
match (a, b) {
44024391
(true, true) | (false, false) => {}
44034392
(true, false) => {
44044393
if other.span.is_desugaring(DesugaringKind::WhileLoop) {
@@ -4437,11 +4426,7 @@ impl<'b, 'v, 'tcx> Visitor<'v> for ConditionVisitor<'b, 'tcx> {
44374426
// arms might be missing an initialization.
44384427
let results: Vec<bool> = arms
44394428
.iter()
4440-
.map(|arm| {
4441-
let mut v = ReferencedStatementsVisitor(self.spans, false);
4442-
v.visit_arm(arm);
4443-
v.1
4444-
})
4429+
.map(|arm| ReferencedStatementsVisitor(self.spans).visit_arm(arm).is_break())
44454430
.collect();
44464431
if results.iter().any(|x| *x) && !results.iter().all(|x| *x) {
44474432
for (arm, seen) in arms.iter().zip(results) {

compiler/rustc_builtin_macros/src/deriving/default.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ fn has_a_default_variant(item: &Annotatable) -> bool {
240240
if v.attrs.iter().any(|attr| attr.has_name(kw::Default)) {
241241
ControlFlow::Break(())
242242
} else {
243-
// no need to subrecurse.
243+
// no need to walk the variant, we are only looking for top level variants
244244
ControlFlow::Continue(())
245245
}
246246
}

0 commit comments

Comments
 (0)