Skip to content

Commit

Permalink
Re-format code with new rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Simulacrum committed Nov 13, 2023
1 parent 2aa00eb commit 97c4b78
Show file tree
Hide file tree
Showing 69 changed files with 647 additions and 484 deletions.
18 changes: 8 additions & 10 deletions compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1213,8 +1213,12 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
DisallowTildeConstContext::Fn(FnKind::Fn(_, ident, ..)) => {
errors::TildeConstReason::Function { ident: ident.span }
}
&DisallowTildeConstContext::Trait(span) => errors::TildeConstReason::Trait { span },
&DisallowTildeConstContext::Impl(span) => errors::TildeConstReason::Impl { span },
&DisallowTildeConstContext::Trait(span) => {
errors::TildeConstReason::Trait { span }
}
&DisallowTildeConstContext::Impl(span) => {
errors::TildeConstReason::Impl { span }
}
DisallowTildeConstContext::TraitObject => {
errors::TildeConstReason::TraitObject
}
Expand Down Expand Up @@ -1446,9 +1450,7 @@ fn deny_equality_constraints(
id: rustc_ast::node_id::DUMMY_NODE_ID,
ident: *ident,
gen_args,
kind: AssocConstraintKind::Equality {
term: predicate.rhs_ty.clone().into(),
},
kind: AssocConstraintKind::Equality { term: predicate.rhs_ty.clone().into() },
span: ident.span,
});
// Add `<Bar = RhsTy>` to `Foo`.
Expand All @@ -1461,11 +1463,7 @@ fn deny_equality_constraints(
},
empty_args => {
*empty_args = Some(
AngleBracketedArgs {
span: ident.span,
args: thin_vec![arg],
}
.into(),
AngleBracketedArgs { span: ident.span, args: thin_vec![arg] }.into(),
);
}
}
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_borrowck/src/diagnostics/move_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {

if let Some(adt) = local_ty.ty_adt_def()
&& adt.repr().packed()
&& let ExpnKind::Macro(MacroKind::Derive, name) = self.body.span.ctxt().outer_expn_data().kind
&& let ExpnKind::Macro(MacroKind::Derive, name) =
self.body.span.ctxt().outer_expn_data().kind
{
err.note(format!("`#[derive({name})]` triggers a move because taking references to the fields of a packed struct is undefined behaviour"));
}
Expand Down
13 changes: 10 additions & 3 deletions compiler/rustc_builtin_macros/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,10 +617,17 @@ fn report_missing_placeholders(
let placeholders = pieces
.iter()
.filter_map(|piece| {
if let parse::Piece::NextArgument(argument) = piece && let ArgumentNamed(binding) = argument.position {
let span = fmt_span.from_inner(InnerSpan::new(argument.position_span.start, argument.position_span.end));
if let parse::Piece::NextArgument(argument) = piece
&& let ArgumentNamed(binding) = argument.position
{
let span = fmt_span.from_inner(InnerSpan::new(
argument.position_span.start,
argument.position_span.end,
));
Some((span, binding))
} else { None }
} else {
None
}
})
.collect::<Vec<_>>();

Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_const_eval/src/interpret/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
use rustc_middle::mir::BinOp::*;

// Performs appropriate non-deterministic adjustments of NaN results.
let adjust_nan = |f: F| -> F {
if f.is_nan() { M::generate_nan(self, &[l, r]) } else { f }
};
let adjust_nan =
|f: F| -> F { if f.is_nan() { M::generate_nan(self, &[l, r]) } else { f } };

let val = match bin_op {
Eq => ImmTy::from_bool(l == r, *self.tcx),
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_expand/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ pub fn features(sess: &Session, krate_attrs: &[Attribute], crate_name: Symbol) -
// - E.g. enable `test_2018_feature` if `features_edition` is 2018 or higher
let mut edition_enabled_features = FxHashSet::default();
for f in UNSTABLE_FEATURES {
if let Some(edition) = f.feature.edition && edition <= features_edition {
if let Some(edition) = f.feature.edition
&& edition <= features_edition
{
// FIXME(Manishearth) there is currently no way to set lib features by
// edition.
edition_enabled_features.insert(f.feature.name);
Expand Down Expand Up @@ -251,8 +253,7 @@ impl<'a> StripUnconfigured<'a> {
let trees: Vec<_> = stream
.0
.iter()
.flat_map(|tree| {
match tree.clone() {
.flat_map(|tree| match tree.clone() {
AttrTokenTree::Attributes(mut data) => {
data.attrs.flat_map_in_place(|attr| self.process_cfg_attr(&attr));

Expand All @@ -277,7 +278,6 @@ impl<'a> StripUnconfigured<'a> {
AttrTokenTree::Token(token, spacing) => {
Some(AttrTokenTree::Token(token, spacing)).into_iter()
}
}
})
.collect();
AttrTokenStream::new(trees)
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_hir_analysis/src/astconv/bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {

self.add_bounds(
param_ty,
ast_bounds.iter().filter(|bound| {
match filter {
ast_bounds.iter().filter(|bound| match filter {
PredicateFilter::All
| PredicateFilter::SelfOnly
| PredicateFilter::SelfAndAssociatedTypeBounds => true,
Expand All @@ -209,7 +208,6 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
false
}
}
}
}),
&mut bounds,
ty::List::empty(),
Expand Down
26 changes: 12 additions & 14 deletions compiler/rustc_hir_analysis/src/astconv/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
&& let parent = hir.get_parent_item(hir.local_def_id_to_hir_id(def_id))
&& let Some(generics) = hir.get_generics(parent.def_id)
{
if generics.bounds_for_param(def_id)
.flat_map(|pred| pred.bounds.iter())
.any(|b| match b {
if generics.bounds_for_param(def_id).flat_map(|pred| pred.bounds.iter()).any(
|b| match b {
hir::GenericBound::Trait(t, ..) => {
t.trait_ref.trait_def_id().as_ref() == Some(best_trait)
}
_ => false,
})
{
},
) {
// The type param already has a bound for `trait_name`, we just need to
// change the associated type.
err.span_suggestion_verbose(
Expand All @@ -227,15 +226,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
Applicability::MaybeIncorrect,
);
} else if suggest_constraining_type_param(
self.tcx(),
generics,
&mut err,
&ty_param_name,
&trait_name,
None,
None,
)
&& suggested_name != assoc_name.name
self.tcx(),
generics,
&mut err,
&ty_param_name,
&trait_name,
None,
None,
) && suggested_name != assoc_name.name
{
// We suggested constraining a type parameter, but the associated type on it
// was also not an exact match, so we also suggest changing it.
Expand Down
21 changes: 13 additions & 8 deletions compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3173,19 +3173,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
sym::offset_of_enum,
ident.span,
"using enums in offset_of is experimental",
).emit();
)
.emit();
}

let Some((index, variant)) = container_def.variants()
let Some((index, variant)) = container_def
.variants()
.iter_enumerated()
.find(|(_, v)| v.ident(self.tcx).normalize_to_macros_2_0() == ident) else {
.find(|(_, v)| v.ident(self.tcx).normalize_to_macros_2_0() == ident)
else {
let mut err = type_error_struct!(
self.tcx().sess,
ident.span,
container,
E0599,
"no variant named `{ident}` found for enum `{container}`",
);
);
err.span_label(field.span, "variant not found");
err.emit();
break;
Expand All @@ -3197,24 +3200,26 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
container,
E0795,
"`{ident}` is an enum variant; expected field at end of `offset_of`",
);
);
err.span_label(field.span, "enum variant");
err.emit();
break;
};
let (subident, sub_def_scope) =
self.tcx.adjust_ident_and_get_scope(subfield, variant.def_id, block);

let Some((subindex, field)) = variant.fields
let Some((subindex, field)) = variant
.fields
.iter_enumerated()
.find(|(_, f)| f.ident(self.tcx).normalize_to_macros_2_0() == subident) else {
.find(|(_, f)| f.ident(self.tcx).normalize_to_macros_2_0() == subident)
else {
let mut err = type_error_struct!(
self.tcx().sess,
ident.span,
container,
E0609,
"no field named `{subfield}` on enum variant `{container}::{ident}`",
);
);
err.span_label(field.span, "this enum variant...");
err.span_label(subident.span, "...does not have this field");
err.emit();
Expand Down
45 changes: 26 additions & 19 deletions compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1864,35 +1864,42 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&& let ExprBindingObligation(_, _, hir_id, ..) = code
&& !fn_sig.output().is_unit()
{
let mut block_num = 0;
let mut found_semi = false;
for (_, node) in self.tcx.hir().parent_iter(hir_id) {
match node {
hir::Node::Stmt(stmt) => if let hir::StmtKind::Semi(ref expr) = stmt.kind {
let mut block_num = 0;
let mut found_semi = false;
for (_, node) in self.tcx.hir().parent_iter(hir_id) {
match node {
hir::Node::Stmt(stmt) => {
if let hir::StmtKind::Semi(ref expr) = stmt.kind {
let expr_ty = self.typeck_results.borrow().expr_ty(expr);
let return_ty = fn_sig.output();
if !matches!(expr.kind, hir::ExprKind::Ret(..)) &&
self.can_coerce(expr_ty, return_ty) {
if !matches!(expr.kind, hir::ExprKind::Ret(..))
&& self.can_coerce(expr_ty, return_ty)
{
found_semi = true;
}
},
hir::Node::Block(_block) => if found_semi {
}
}
hir::Node::Block(_block) => {
if found_semi {
block_num += 1;
}
hir::Node::Item(item) => if let hir::ItemKind::Fn(..) = item.kind {
}
hir::Node::Item(item) => {
if let hir::ItemKind::Fn(..) = item.kind {
break;
}
_ => {}
}
_ => {}
}
if block_num > 1 && found_semi {
diag.span_suggestion_verbose(
span.shrink_to_lo(),
"you might have meant to return this to infer its type parameters",
"return ",
Applicability::MaybeIncorrect,
);
}
}
if block_num > 1 && found_semi {
diag.span_suggestion_verbose(
span.shrink_to_lo(),
"you might have meant to return this to infer its type parameters",
"return ",
Applicability::MaybeIncorrect,
);
}
}
diag.emit();
}
Expand Down
Loading

0 comments on commit 97c4b78

Please sign in to comment.