Skip to content

Rollup of 11 pull requests #127400

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 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
af9f6f7
out_of_scope_macro_calls: Detect calls inside attributes more precisely
petrochenkov Jun 26, 2024
9e12d91
Improve well known value check-cfg diagnostic for the standard library
Urgau Jul 1, 2024
57e76d4
impl PathBuf::add_extension and Path::with_added_extension
tisonkun Jul 4, 2024
0adb825
Improve dead code analysis
mu001999 Jul 4, 2024
4abc51a
Improve readability of some fmt code examples
GuillaumeGomez Jul 5, 2024
7dca61b
Use `ControlFlow` results for visitors that are only looking for a si…
oli-obk Jul 5, 2024
5fd5b65
Rename edition 2021 fail test
Jules-Bertholet Jul 5, 2024
291ed59
Added dots at the sentence ends of rustc AST doc
YohDeadfall Jul 5, 2024
5a35fc4
Match ergonomics 2024: `&` matches `&mut` on old editions
Jules-Bertholet Jul 5, 2024
76da7ae
Match ergonomics 2024: test type inference
Jules-Bertholet Jul 5, 2024
a0f4114
update comments
tisonkun Jul 5, 2024
3aa2abd
add unit tests for extra extension feature
tisonkun Jul 5, 2024
8e9a366
Use verbose style for argument removal suggestion
estebank Jul 5, 2024
27588d1
Split SolverDelegate back out from InferCtxtLike
compiler-errors Jul 5, 2024
9f66af4
Remove clubby789 from review rotation
clubby789 Jul 5, 2024
50aa50a
Rollup merge of #123600 - tisonkun:path_with_extension, r=dtolnay
workingjubilee Jul 5, 2024
03a9b01
Rollup merge of #126987 - petrochenkov:atvisord2, r=pnkfelix
workingjubilee Jul 5, 2024
968df26
Rollup merge of #127107 - mu001999-contrib:dead/enhance-2, r=pnkfelix
workingjubilee Jul 5, 2024
e9daf66
Rollup merge of #127221 - Urgau:check-cfg-std-diag, r=pnkfelix
workingjubilee Jul 5, 2024
a33d82e
Rollup merge of #127333 - compiler-errors:infer_ctxt_like-again, r=lcnr
workingjubilee Jul 5, 2024
2ecc6be
Rollup merge of #127363 - GuillaumeGomez:improve-fmt-code-readability…
workingjubilee Jul 5, 2024
13d015c
Rollup merge of #127366 - oli-obk:falliblevisitor, r=compiler-errors
workingjubilee Jul 5, 2024
34f4857
Rollup merge of #127368 - YohDeadfall:dots-in-docs, r=fmease
workingjubilee Jul 5, 2024
36b4d20
Rollup merge of #127369 - Jules-Bertholet:match-ergonomics-2021, r=Na…
workingjubilee Jul 5, 2024
cad0135
Rollup merge of #127383 - estebank:arg-removal, r=compiler-errors
workingjubilee Jul 5, 2024
97949a7
Rollup merge of #127393 - clubby789:unreview, r=workingjubilee
workingjubilee Jul 5, 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 Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4170,6 +4170,7 @@ dependencies = [
"rustc_middle",
"rustc_span",
"rustc_target",
"rustc_type_ir",
"smallvec",
"tracing",
]
Expand Down
64 changes: 32 additions & 32 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ pub enum GenericArgs {
AngleBracketed(AngleBracketedArgs),
/// The `(A, B)` and `C` in `Foo(A, B) -> C`.
Parenthesized(ParenthesizedArgs),
/// `(..)` in return type notation
/// `(..)` in return type notation.
ParenthesizedElided(Span),
}

Expand All @@ -197,11 +197,11 @@ impl GenericArgs {
/// Concrete argument in the sequence of generic args.
#[derive(Clone, Encodable, Decodable, Debug)]
pub enum GenericArg {
/// `'a` in `Foo<'a>`
/// `'a` in `Foo<'a>`.
Lifetime(Lifetime),
/// `Bar` in `Foo<Bar>`
/// `Bar` in `Foo<Bar>`.
Type(P<Ty>),
/// `1` in `Foo<1>`
/// `1` in `Foo<1>`.
Const(AnonConst),
}

Expand Down Expand Up @@ -355,7 +355,7 @@ pub enum GenericParamKind {
ty: P<Ty>,
/// Span of the `const` keyword.
kw_span: Span,
/// Optional default value for the const generic param
/// Optional default value for the const generic param.
default: Option<AnonConst>,
},
}
Expand Down Expand Up @@ -833,7 +833,7 @@ pub enum PatKind {
/// only one rest pattern may occur in the pattern sequences.
Rest,

// A never pattern `!`
// A never pattern `!`.
Never,

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

/// Limit types of a range (inclusive or exclusive)
/// Limit types of a range (inclusive or exclusive).
#[derive(Copy, Clone, PartialEq, Encodable, Decodable, Debug)]
pub enum RangeLimits {
/// Inclusive at the beginning, exclusive at the end
/// Inclusive at the beginning, exclusive at the end.
HalfOpen,
/// Inclusive at the beginning and end
/// Inclusive at the beginning and end.
Closed,
}

Expand Down Expand Up @@ -1401,9 +1401,9 @@ pub struct StructExpr {
pub enum ExprKind {
/// An array (e.g, `[a, b, c, d]`).
Array(ThinVec<P<Expr>>),
/// Allow anonymous constants from an inline `const` block
/// Allow anonymous constants from an inline `const` block.
ConstBlock(AnonConst),
/// A function call
/// A function call.
///
/// The first field resolves to the function itself,
/// and the second field is the list of arguments.
Expand Down Expand Up @@ -1457,7 +1457,7 @@ pub enum ExprKind {
/// A block (`'label: { ... }`).
Block(P<Block>, Option<Label>),
/// An `async` block (`async move { ... }`),
/// or a `gen` block (`gen move { ... }`)
/// or a `gen` block (`gen move { ... }`).
///
/// The span is the "decl", which is the header before the body `{ }`
/// including the `asyng`/`gen` keywords and possibly `move`.
Expand Down Expand Up @@ -2157,9 +2157,9 @@ pub enum TyKind {
Never,
/// A tuple (`(A, B, C, D,...)`).
Tup(ThinVec<P<Ty>>),
/// An anonymous struct type i.e. `struct { foo: Type }`
/// An anonymous struct type i.e. `struct { foo: Type }`.
AnonStruct(NodeId, ThinVec<FieldDef>),
/// An anonymous union type i.e. `union { bar: Type }`
/// An anonymous union type i.e. `union { bar: Type }`.
AnonUnion(NodeId, ThinVec<FieldDef>),
/// A path (`module::module::...::Type`), optionally
/// "qualified", e.g., `<Vec<T> as SomeTrait>::SomeType`.
Expand Down Expand Up @@ -2233,9 +2233,9 @@ pub enum TraitObjectSyntax {

#[derive(Clone, Encodable, Decodable, Debug)]
pub enum PreciseCapturingArg {
/// Lifetime parameter
/// Lifetime parameter.
Lifetime(Lifetime),
/// Type or const parameter
/// Type or const parameter.
Arg(Path, NodeId),
}

Expand Down Expand Up @@ -2529,11 +2529,11 @@ pub enum Safety {
/// Iterator`.
#[derive(Copy, Clone, Encodable, Decodable, Debug)]
pub enum CoroutineKind {
/// `async`, which returns an `impl Future`
/// `async`, which returns an `impl Future`.
Async { span: Span, closure_id: NodeId, return_impl_trait_id: NodeId },
/// `gen`, which returns an `impl Iterator`
/// `gen`, which returns an `impl Iterator`.
Gen { span: Span, closure_id: NodeId, return_impl_trait_id: NodeId },
/// `async gen`, which returns an `impl AsyncIterator`
/// `async gen`, which returns an `impl AsyncIterator`.
AsyncGen { span: Span, closure_id: NodeId, return_impl_trait_id: NodeId },
}

Expand Down Expand Up @@ -2750,7 +2750,7 @@ pub struct Variant {
pub data: VariantData,
/// Explicit discriminant, e.g., `Foo = 1`.
pub disr_expr: Option<AnonConst>,
/// Is a macro placeholder
/// Is a macro placeholder.
pub is_placeholder: bool,
}

Expand Down Expand Up @@ -3024,19 +3024,19 @@ impl Item {
/// `extern` qualifier on a function item or function type.
#[derive(Clone, Copy, Encodable, Decodable, Debug)]
pub enum Extern {
/// No explicit extern keyword was used
/// No explicit extern keyword was used.
///
/// E.g. `fn foo() {}`
/// E.g. `fn foo() {}`.
None,
/// An explicit extern keyword was used, but with implicit ABI
/// An explicit extern keyword was used, but with implicit ABI.
///
/// E.g. `extern fn foo() {}`
/// E.g. `extern fn foo() {}`.
///
/// This is just `extern "C"` (see `rustc_target::spec::abi::Abi::FALLBACK`)
/// This is just `extern "C"` (see `rustc_target::spec::abi::Abi::FALLBACK`).
Implicit(Span),
/// An explicit extern keyword was used with an explicit ABI
/// An explicit extern keyword was used with an explicit ABI.
///
/// E.g. `extern "C" fn foo() {}`
/// E.g. `extern "C" fn foo() {}`.
Explicit(StrLit, Span),
}

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

Expand Down Expand Up @@ -3255,7 +3255,7 @@ pub enum ItemKind {
///
/// E.g., `trait Foo { .. }`, `trait Foo<T> { .. }` or `auto trait Foo {}`.
Trait(Box<Trait>),
/// Trait alias
/// Trait alias.
///
/// E.g., `trait Foo = Bar + Quux;`.
TraitAlias(Generics, GenericBounds),
Expand Down
61 changes: 23 additions & 38 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt;
use rustc_trait_selection::traits::error_reporting::FindExprBySpan;
use rustc_trait_selection::traits::{Obligation, ObligationCause, ObligationCtxt};
use std::iter;
use std::ops::ControlFlow;

use crate::borrow_set::TwoPhaseActivation;
use crate::borrowck_errors;
Expand Down Expand Up @@ -784,20 +785,20 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
/// binding declaration within every scope we inspect.
struct Finder {
hir_id: hir::HirId,
found: bool,
}
impl<'hir> Visitor<'hir> for Finder {
fn visit_pat(&mut self, pat: &'hir hir::Pat<'hir>) {
type Result = ControlFlow<()>;
fn visit_pat(&mut self, pat: &'hir hir::Pat<'hir>) -> Self::Result {
if pat.hir_id == self.hir_id {
self.found = true;
return ControlFlow::Break(());
}
hir::intravisit::walk_pat(self, pat);
hir::intravisit::walk_pat(self, pat)
}
fn visit_expr(&mut self, ex: &'hir hir::Expr<'hir>) {
fn visit_expr(&mut self, ex: &'hir hir::Expr<'hir>) -> Self::Result {
if ex.hir_id == self.hir_id {
self.found = true;
return ControlFlow::Break(());
}
hir::intravisit::walk_expr(self, ex);
hir::intravisit::walk_expr(self, ex)
}
}
// The immediate HIR parent of the moved expression. We'll look for it to be a call.
Expand All @@ -822,9 +823,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
_ => continue,
};
if let Some(&hir_id) = local_hir_id {
let mut finder = Finder { hir_id, found: false };
finder.visit_expr(e);
if finder.found {
if (Finder { hir_id }).visit_expr(e).is_break() {
// The current scope includes the declaration of the binding we're accessing, we
// can't look up any further for loops.
break;
Expand All @@ -839,9 +838,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
hir::Node::Expr(hir::Expr {
kind: hir::ExprKind::If(cond, ..), ..
}) => {
let mut finder = Finder { hir_id: expr.hir_id, found: false };
finder.visit_expr(cond);
if finder.found {
if (Finder { hir_id: expr.hir_id }).visit_expr(cond).is_break() {
// The expression where the move error happened is in a `while let`
// condition Don't suggest clone as it will likely end in an
// infinite loop.
Expand Down Expand Up @@ -1837,15 +1834,14 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {

pub struct Holds<'tcx> {
ty: Ty<'tcx>,
holds: bool,
}

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

fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result {
if t == self.ty {
self.holds = true;
return ControlFlow::Break(());
}
t.super_visit_with(self)
}
Expand All @@ -1863,9 +1859,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
&& rcvr_ty == ty
&& let ty::Ref(_, inner, _) = rcvr_ty.kind()
&& let inner = inner.peel_refs()
&& let mut v = (Holds { ty: inner, holds: false })
&& let _ = v.visit_ty(local_ty)
&& v.holds
&& (Holds { ty: inner }).visit_ty(local_ty).is_break()
&& let None = self.infcx.type_implements_trait_shallow(clone, inner, self.param_env)
{
err.span_label(
Expand Down Expand Up @@ -4325,15 +4319,14 @@ impl<'tcx> AnnotatedBorrowFnSignature<'tcx> {
}

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

impl<'a, 'v> Visitor<'v> for ReferencedStatementsVisitor<'a> {
fn visit_stmt(&mut self, s: &'v hir::Stmt<'v>) {
impl<'v> Visitor<'v> for ReferencedStatementsVisitor<'_> {
type Result = ControlFlow<()>;
fn visit_stmt(&mut self, s: &'v hir::Stmt<'v>) -> Self::Result {
match s.kind {
hir::StmtKind::Semi(expr) if self.0.contains(&expr.span) => {
self.1 = true;
}
_ => {}
hir::StmtKind::Semi(expr) if self.0.contains(&expr.span) => ControlFlow::Break(()),
_ => ControlFlow::Continue(()),
}
}
}
Expand Down Expand Up @@ -4375,9 +4368,7 @@ impl<'b, 'v, 'tcx> Visitor<'v> for ConditionVisitor<'b, 'tcx> {
hir::ExprKind::If(cond, body, None) => {
// `if` expressions with no `else` that initialize the binding might be missing an
// `else` arm.
let mut v = ReferencedStatementsVisitor(self.spans, false);
v.visit_expr(body);
if v.1 {
if ReferencedStatementsVisitor(self.spans).visit_expr(body).is_break() {
self.errors.push((
cond.span,
format!(
Expand All @@ -4394,11 +4385,9 @@ impl<'b, 'v, 'tcx> Visitor<'v> for ConditionVisitor<'b, 'tcx> {
hir::ExprKind::If(cond, body, Some(other)) => {
// `if` expressions where the binding is only initialized in one of the two arms
// might be missing a binding initialization.
let mut a = ReferencedStatementsVisitor(self.spans, false);
a.visit_expr(body);
let mut b = ReferencedStatementsVisitor(self.spans, false);
b.visit_expr(other);
match (a.1, b.1) {
let a = ReferencedStatementsVisitor(self.spans).visit_expr(body).is_break();
let b = ReferencedStatementsVisitor(self.spans).visit_expr(other).is_break();
match (a, b) {
(true, true) | (false, false) => {}
(true, false) => {
if other.span.is_desugaring(DesugaringKind::WhileLoop) {
Expand Down Expand Up @@ -4437,11 +4426,7 @@ impl<'b, 'v, 'tcx> Visitor<'v> for ConditionVisitor<'b, 'tcx> {
// arms might be missing an initialization.
let results: Vec<bool> = arms
.iter()
.map(|arm| {
let mut v = ReferencedStatementsVisitor(self.spans, false);
v.visit_arm(arm);
v.1
})
.map(|arm| ReferencedStatementsVisitor(self.spans).visit_arm(arm).is_break())
.collect();
if results.iter().any(|x| *x) && !results.iter().all(|x| *x) {
for (arm, seen) in arms.iter().zip(results) {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/deriving/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ fn has_a_default_variant(item: &Annotatable) -> bool {
if v.attrs.iter().any(|attr| attr.has_name(kw::Default)) {
ControlFlow::Break(())
} else {
// no need to subrecurse.
// no need to walk the variant, we are only looking for top level variants
ControlFlow::Continue(())
}
}
Expand Down
Loading
Loading