Skip to content

Commit b596d6b

Browse files
authored
Rollup merge of #105045 - WaffleLapkin:deref-ahhhh~, r=compiler-errors
`rustc_ast_{passes,pretty}`: remove `ref` patterns r? `@compiler-errors` Previous PR: #104721
2 parents 581ca3e + 1b4012e commit b596d6b

File tree

5 files changed

+269
-276
lines changed

5 files changed

+269
-276
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

+45-50
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,15 @@ impl<'a> AstValidator<'a> {
209209

210210
// Mirrors `visit::walk_ty`, but tracks relevant state.
211211
fn walk_ty(&mut self, t: &'a Ty) {
212-
match t.kind {
212+
match &t.kind {
213213
TyKind::ImplTrait(..) => {
214214
self.with_impl_trait(Some(t.span), |this| visit::walk_ty(this, t))
215215
}
216216
TyKind::TraitObject(..) => self
217217
.with_banned_tilde_const(DisallowTildeConstContext::TraitObject, |this| {
218218
visit::walk_ty(this, t)
219219
}),
220-
TyKind::Path(ref qself, ref path) => {
220+
TyKind::Path(qself, path) => {
221221
// We allow these:
222222
// - `Option<impl Trait>`
223223
// - `option::Option<impl Trait>`
@@ -231,7 +231,7 @@ impl<'a> AstValidator<'a> {
231231
// (for cases like `<impl Trait>::Foo>`)
232232
// but we allow `impl Trait` in `GenericArgs`
233233
// iff there are no more PathSegments.
234-
if let Some(ref qself) = *qself {
234+
if let Some(qself) = qself {
235235
// `impl Trait` in `qself` is always illegal
236236
self.with_banned_impl_trait(|this| this.visit_ty(&qself.ty));
237237
}
@@ -738,8 +738,8 @@ impl<'a> AstValidator<'a> {
738738
}
739739

740740
fn visit_ty_common(&mut self, ty: &'a Ty) {
741-
match ty.kind {
742-
TyKind::BareFn(ref bfty) => {
741+
match &ty.kind {
742+
TyKind::BareFn(bfty) => {
743743
self.check_fn_decl(&bfty.decl, SelfSemantic::No);
744744
Self::check_decl_no_pat(&bfty.decl, |span, _, _| {
745745
struct_span_err!(
@@ -756,10 +756,10 @@ impl<'a> AstValidator<'a> {
756756
self.maybe_lint_missing_abi(sig_span, ty.id);
757757
}
758758
}
759-
TyKind::TraitObject(ref bounds, ..) => {
759+
TyKind::TraitObject(bounds, ..) => {
760760
let mut any_lifetime_bounds = false;
761761
for bound in bounds {
762-
if let GenericBound::Outlives(ref lifetime) = *bound {
762+
if let GenericBound::Outlives(lifetime) = bound {
763763
if any_lifetime_bounds {
764764
struct_span_err!(
765765
self.session,
@@ -774,7 +774,7 @@ impl<'a> AstValidator<'a> {
774774
}
775775
}
776776
}
777-
TyKind::ImplTrait(_, ref bounds) => {
777+
TyKind::ImplTrait(_, bounds) => {
778778
if self.is_impl_trait_banned {
779779
struct_span_err!(
780780
self.session,
@@ -842,8 +842,8 @@ fn validate_generic_param_order(
842842
let (kind, bounds, span) = (&param.kind, &param.bounds, ident.span);
843843
let (ord_kind, ident) = match &param.kind {
844844
GenericParamKind::Lifetime => (ParamKindOrd::Lifetime, ident.to_string()),
845-
GenericParamKind::Type { default: _ } => (ParamKindOrd::TypeOrConst, ident.to_string()),
846-
GenericParamKind::Const { ref ty, kw_span: _, default: _ } => {
845+
GenericParamKind::Type { .. } => (ParamKindOrd::TypeOrConst, ident.to_string()),
846+
GenericParamKind::Const { ty, .. } => {
847847
let ty = pprust::ty_to_string(ty);
848848
(ParamKindOrd::TypeOrConst, format!("const {}: {}", ident, ty))
849849
}
@@ -948,8 +948,8 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
948948
}
949949
ExprKind::Paren(local_expr) => {
950950
fn has_let_expr(expr: &Expr) -> bool {
951-
match expr.kind {
952-
ExprKind::Binary(_, ref lhs, ref rhs) => has_let_expr(lhs) || has_let_expr(rhs),
951+
match &expr.kind {
952+
ExprKind::Binary(_, lhs, rhs) => has_let_expr(lhs) || has_let_expr(rhs),
953953
ExprKind::Let(..) => true,
954954
_ => false,
955955
}
@@ -1005,18 +1005,18 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
10051005
self.check_nomangle_item_asciionly(item.ident, item.span);
10061006
}
10071007

1008-
match item.kind {
1008+
match &item.kind {
10091009
ItemKind::Impl(box Impl {
10101010
unsafety,
10111011
polarity,
10121012
defaultness: _,
10131013
constness,
1014-
ref generics,
1015-
of_trait: Some(ref t),
1016-
ref self_ty,
1017-
ref items,
1014+
generics,
1015+
of_trait: Some(t),
1016+
self_ty,
1017+
items,
10181018
}) => {
1019-
self.with_in_trait_impl(true, Some(constness), |this| {
1019+
self.with_in_trait_impl(true, Some(*constness), |this| {
10201020
this.invalid_visibility(&item.vis, None);
10211021
if let TyKind::Err = self_ty.kind {
10221022
this.err_handler()
@@ -1027,7 +1027,8 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
10271027
.help("use `auto trait Trait {}` instead")
10281028
.emit();
10291029
}
1030-
if let (Unsafe::Yes(span), ImplPolarity::Negative(sp)) = (unsafety, polarity) {
1030+
if let (&Unsafe::Yes(span), &ImplPolarity::Negative(sp)) = (unsafety, polarity)
1031+
{
10311032
struct_span_err!(
10321033
this.session,
10331034
sp.to(t.path.span),
@@ -1061,7 +1062,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
10611062
constness,
10621063
generics: _,
10631064
of_trait: None,
1064-
ref self_ty,
1065+
self_ty,
10651066
items: _,
10661067
}) => {
10671068
let error = |annotation_span, annotation| {
@@ -1078,25 +1079,25 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
10781079
&item.vis,
10791080
Some(InvalidVisibilityNote::IndividualImplItems),
10801081
);
1081-
if let Unsafe::Yes(span) = unsafety {
1082+
if let &Unsafe::Yes(span) = unsafety {
10821083
error(span, "unsafe").code(error_code!(E0197)).emit();
10831084
}
1084-
if let ImplPolarity::Negative(span) = polarity {
1085+
if let &ImplPolarity::Negative(span) = polarity {
10851086
error(span, "negative").emit();
10861087
}
1087-
if let Defaultness::Default(def_span) = defaultness {
1088+
if let &Defaultness::Default(def_span) = defaultness {
10881089
error(def_span, "`default`")
10891090
.note("only trait implementations may be annotated with `default`")
10901091
.emit();
10911092
}
1092-
if let Const::Yes(span) = constness {
1093+
if let &Const::Yes(span) = constness {
10931094
error(span, "`const`")
10941095
.note("only trait implementations may be annotated with `const`")
10951096
.emit();
10961097
}
10971098
}
1098-
ItemKind::Fn(box Fn { defaultness, ref sig, ref generics, ref body }) => {
1099-
self.check_defaultness(item.span, defaultness);
1099+
ItemKind::Fn(box Fn { defaultness, sig, generics, body }) => {
1100+
self.check_defaultness(item.span, *defaultness);
11001101

11011102
if body.is_none() {
11021103
self.session.emit_err(FnWithoutBody {
@@ -1132,7 +1133,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
11321133
&item.vis,
11331134
Some(InvalidVisibilityNote::IndividualForeignItems),
11341135
);
1135-
if let Unsafe::Yes(span) = unsafety {
1136+
if let &Unsafe::Yes(span) = unsafety {
11361137
self.err_handler().span_err(span, "extern block cannot be declared unsafe");
11371138
}
11381139
if abi.is_none() {
@@ -1142,16 +1143,16 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
11421143
self.extern_mod = old_item;
11431144
return; // Avoid visiting again.
11441145
}
1145-
ItemKind::Enum(ref def, _) => {
1146+
ItemKind::Enum(def, _) => {
11461147
for variant in &def.variants {
11471148
self.invalid_visibility(&variant.vis, None);
11481149
for field in variant.data.fields() {
11491150
self.invalid_visibility(&field.vis, None);
11501151
}
11511152
}
11521153
}
1153-
ItemKind::Trait(box Trait { is_auto, ref generics, ref bounds, ref items, .. }) => {
1154-
if is_auto == IsAuto::Yes {
1154+
ItemKind::Trait(box Trait { is_auto, generics, bounds, items, .. }) => {
1155+
if *is_auto == IsAuto::Yes {
11551156
// Auto traits cannot have generics, super traits nor contain items.
11561157
self.deny_generic_params(generics, item.ident.span);
11571158
self.deny_super_traits(bounds, item.ident.span);
@@ -1171,8 +1172,8 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
11711172
walk_list!(self, visit_attribute, &item.attrs);
11721173
return; // Avoid visiting again
11731174
}
1174-
ItemKind::Mod(unsafety, ref mod_kind) => {
1175-
if let Unsafe::Yes(span) = unsafety {
1175+
ItemKind::Mod(unsafety, mod_kind) => {
1176+
if let &Unsafe::Yes(span) = unsafety {
11761177
self.err_handler().span_err(span, "module cannot be declared unsafe");
11771178
}
11781179
// Ensure that `path` attributes on modules are recorded as used (cf. issue #35584).
@@ -1182,13 +1183,13 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
11821183
self.check_mod_file_item_asciionly(item.ident);
11831184
}
11841185
}
1185-
ItemKind::Union(ref vdata, ..) => {
1186+
ItemKind::Union(vdata, ..) => {
11861187
if vdata.fields().is_empty() {
11871188
self.err_handler().span_err(item.span, "unions cannot have zero fields");
11881189
}
11891190
}
11901191
ItemKind::Const(def, .., None) => {
1191-
self.check_defaultness(item.span, def);
1192+
self.check_defaultness(item.span, *def);
11921193
self.session.emit_err(ConstWithoutBody {
11931194
span: item.span,
11941195
replace_span: self.ending_semi_or_hi(item.span),
@@ -1200,14 +1201,8 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12001201
replace_span: self.ending_semi_or_hi(item.span),
12011202
});
12021203
}
1203-
ItemKind::TyAlias(box TyAlias {
1204-
defaultness,
1205-
where_clauses,
1206-
ref bounds,
1207-
ref ty,
1208-
..
1209-
}) => {
1210-
self.check_defaultness(item.span, defaultness);
1204+
ItemKind::TyAlias(box TyAlias { defaultness, where_clauses, bounds, ty, .. }) => {
1205+
self.check_defaultness(item.span, *defaultness);
12111206
if ty.is_none() {
12121207
self.session.emit_err(TyAliasWithoutBody {
12131208
span: item.span,
@@ -1266,8 +1261,8 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12661261

12671262
// Mirrors `visit::walk_generic_args`, but tracks relevant state.
12681263
fn visit_generic_args(&mut self, generic_args: &'a GenericArgs) {
1269-
match *generic_args {
1270-
GenericArgs::AngleBracketed(ref data) => {
1264+
match generic_args {
1265+
GenericArgs::AngleBracketed(data) => {
12711266
self.check_generic_args_before_constraints(data);
12721267

12731268
for arg in &data.args {
@@ -1283,7 +1278,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12831278
}
12841279
}
12851280
}
1286-
GenericArgs::Parenthesized(ref data) => {
1281+
GenericArgs::Parenthesized(data) => {
12871282
walk_list!(self, visit_ty, &data.inputs);
12881283
if let FnRetTy::Ty(ty) = &data.output {
12891284
// `-> Foo` syntax is essentially an associated type binding,
@@ -1319,7 +1314,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
13191314
validate_generic_param_order(self.err_handler(), &generics.params, generics.span);
13201315

13211316
for predicate in &generics.where_clause.predicates {
1322-
if let WherePredicate::EqPredicate(ref predicate) = *predicate {
1317+
if let WherePredicate::EqPredicate(predicate) = predicate {
13231318
deny_equality_constraints(self, predicate, generics);
13241319
}
13251320
}
@@ -1368,7 +1363,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
13681363
}
13691364

13701365
fn visit_param_bound(&mut self, bound: &'a GenericBound, ctxt: BoundKind) {
1371-
if let GenericBound::Trait(ref poly, modify) = *bound {
1366+
if let GenericBound::Trait(poly, modify) = bound {
13721367
match (ctxt, modify) {
13731368
(BoundKind::SuperTraits, TraitBoundModifier::Maybe) => {
13741369
let mut err = self
@@ -1573,8 +1568,8 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
15731568
self.check_item_named(item.ident, "const");
15741569
}
15751570

1576-
match item.kind {
1577-
AssocItemKind::Type(box TyAlias { ref generics, ref bounds, ref ty, .. })
1571+
match &item.kind {
1572+
AssocItemKind::Type(box TyAlias { generics, bounds, ty, .. })
15781573
if ctxt == AssocCtxt::Trait =>
15791574
{
15801575
self.visit_vis(&item.vis);
@@ -1586,7 +1581,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
15861581
});
15871582
walk_list!(self, visit_ty, ty);
15881583
}
1589-
AssocItemKind::Fn(box Fn { ref sig, ref generics, ref body, .. })
1584+
AssocItemKind::Fn(box Fn { sig, generics, body, .. })
15901585
if self.in_const_trait_impl
15911586
|| ctxt == AssocCtxt::Trait
15921587
|| matches!(sig.header.constness, Const::Yes(_)) =>

compiler/rustc_ast_passes/src/feature_gate.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
198198
}
199199

200200
fn visit_item(&mut self, i: &'a ast::Item) {
201-
match i.kind {
202-
ast::ItemKind::ForeignMod(ref foreign_module) => {
201+
match &i.kind {
202+
ast::ItemKind::ForeignMod(foreign_module) => {
203203
if let Some(abi) = foreign_module.abi {
204204
self.check_abi(abi, ast::Const::No);
205205
}
@@ -233,8 +233,8 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
233233
}
234234
}
235235

236-
ast::ItemKind::Impl(box ast::Impl { polarity, defaultness, ref of_trait, .. }) => {
237-
if let ast::ImplPolarity::Negative(span) = polarity {
236+
ast::ItemKind::Impl(box ast::Impl { polarity, defaultness, of_trait, .. }) => {
237+
if let &ast::ImplPolarity::Negative(span) = polarity {
238238
gate_feature_post!(
239239
&self,
240240
negative_impls,
@@ -267,7 +267,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
267267
gate_feature_post!(&self, decl_macro, i.span, msg);
268268
}
269269

270-
ast::ItemKind::TyAlias(box ast::TyAlias { ty: Some(ref ty), .. }) => {
270+
ast::ItemKind::TyAlias(box ast::TyAlias { ty: Some(ty), .. }) => {
271271
self.check_impl_trait(&ty)
272272
}
273273

@@ -302,8 +302,8 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
302302
}
303303

304304
fn visit_ty(&mut self, ty: &'a ast::Ty) {
305-
match ty.kind {
306-
ast::TyKind::BareFn(ref bare_fn_ty) => {
305+
match &ty.kind {
306+
ast::TyKind::BareFn(bare_fn_ty) => {
307307
// Function pointers cannot be `const`
308308
self.check_extern(bare_fn_ty.ext, ast::Const::No);
309309
}
@@ -319,7 +319,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
319319
}
320320

321321
fn visit_fn_ret_ty(&mut self, ret_ty: &'a ast::FnRetTy) {
322-
if let ast::FnRetTy::Ty(ref output_ty) = *ret_ty {
322+
if let ast::FnRetTy::Ty(output_ty) = ret_ty {
323323
if let ast::TyKind::Never = output_ty.kind {
324324
// Do nothing.
325325
} else {
@@ -455,9 +455,9 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
455455
}
456456

457457
fn visit_assoc_item(&mut self, i: &'a ast::AssocItem, ctxt: AssocCtxt) {
458-
let is_fn = match i.kind {
458+
let is_fn = match &i.kind {
459459
ast::AssocItemKind::Fn(_) => true,
460-
ast::AssocItemKind::Type(box ast::TyAlias { ref ty, .. }) => {
460+
ast::AssocItemKind::Type(box ast::TyAlias { ty, .. }) => {
461461
if let (Some(_), AssocCtxt::Trait) = (ty, ctxt) {
462462
gate_feature_post!(
463463
&self,

0 commit comments

Comments
 (0)