Skip to content

Commit 08c1639

Browse files
authored
Rollup merge of #91002 - petrochenkov:nosynth, r=davidtwco
rustc: Remove `#[rustc_synthetic]` This function parameter attribute was introduced in #44866 as an intermediate step in implementing `impl Trait`, it's not necessary or used anywhere by itself. Noticed while reviewing #90947.
2 parents dfbbb3b + 91e0217 commit 08c1639

File tree

17 files changed

+37
-163
lines changed

17 files changed

+37
-163
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -1338,10 +1338,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13381338
pure_wrt_drop: false,
13391339
bounds: hir_bounds,
13401340
span: self.lower_span(span),
1341-
kind: hir::GenericParamKind::Type {
1342-
default: None,
1343-
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
1344-
},
1341+
kind: hir::GenericParamKind::Type { default: None, synthetic: true },
13451342
});
13461343

13471344
hir::TyKind::Path(hir::QPath::Resolved(
@@ -1954,12 +1951,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19541951
default: default.as_ref().map(|x| {
19551952
self.lower_ty(x, ImplTraitContext::Disallowed(ImplTraitPosition::Other))
19561953
}),
1957-
synthetic: param
1958-
.attrs
1959-
.iter()
1960-
.filter(|attr| attr.has_name(sym::rustc_synthetic))
1961-
.map(|_| hir::SyntheticTyParamKind::FromAttr)
1962-
.next(),
1954+
synthetic: false,
19631955
};
19641956

19651957
(hir::ParamName::Plain(self.lower_ident(param.ident)), kind)

compiler/rustc_feature/src/builtin_attrs.rs

-1
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,6 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
601601
TEST, rustc_expected_cgu_reuse, Normal,
602602
template!(List: r#"cfg = "...", module = "...", kind = "...""#),
603603
),
604-
rustc_attr!(TEST, rustc_synthetic, Normal, template!(Word)),
605604
rustc_attr!(TEST, rustc_symbol_name, Normal, template!(Word)),
606605
rustc_attr!(TEST, rustc_polymorphize_error, Normal, template!(Word)),
607606
rustc_attr!(TEST, rustc_def_path, Normal, template!(Word)),

compiler/rustc_hir/src/hir.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ pub enum GenericParamKind<'hir> {
504504
},
505505
Type {
506506
default: Option<&'hir Ty<'hir>>,
507-
synthetic: Option<SyntheticTyParamKind>,
507+
synthetic: bool,
508508
},
509509
Const {
510510
ty: &'hir Ty<'hir>,
@@ -577,16 +577,6 @@ impl Generics<'hir> {
577577
}
578578
}
579579

580-
/// Synthetic type parameters are converted to another form during lowering; this allows
581-
/// us to track the original form they had, and is useful for error messages.
582-
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Hash, Debug)]
583-
#[derive(HashStable_Generic)]
584-
pub enum SyntheticTyParamKind {
585-
ImplTrait,
586-
// Created by the `#[rustc_synthetic]` attribute.
587-
FromAttr,
588-
}
589-
590580
/// A where-clause in a definition.
591581
#[derive(Debug, HashStable_Generic)]
592582
pub struct WhereClause<'hir> {

compiler/rustc_middle/src/ty/generics.rs

+3-18
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::ty;
33
use crate::ty::subst::{Subst, SubstsRef};
44
use rustc_ast as ast;
55
use rustc_data_structures::fx::FxHashMap;
6-
use rustc_hir as hir;
76
use rustc_hir::def_id::DefId;
87
use rustc_span::symbol::Symbol;
98
use rustc_span::Span;
@@ -13,14 +12,8 @@ use super::{EarlyBoundRegion, InstantiatedPredicates, ParamConst, ParamTy, Predi
1312
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable)]
1413
pub enum GenericParamDefKind {
1514
Lifetime,
16-
Type {
17-
has_default: bool,
18-
object_lifetime_default: ObjectLifetimeDefault,
19-
synthetic: Option<hir::SyntheticTyParamKind>,
20-
},
21-
Const {
22-
has_default: bool,
23-
},
15+
Type { has_default: bool, object_lifetime_default: ObjectLifetimeDefault, synthetic: bool },
16+
Const { has_default: bool },
2417
}
2518

2619
impl GenericParamDefKind {
@@ -202,15 +195,7 @@ impl<'tcx> Generics {
202195
/// Returns `true` if `params` has `impl Trait`.
203196
pub fn has_impl_trait(&'tcx self) -> bool {
204197
self.params.iter().any(|param| {
205-
matches!(
206-
param.kind,
207-
ty::GenericParamDefKind::Type {
208-
synthetic: Some(
209-
hir::SyntheticTyParamKind::ImplTrait | hir::SyntheticTyParamKind::FromAttr,
210-
),
211-
..
212-
}
213-
)
198+
matches!(param.kind, ty::GenericParamDefKind::Type { synthetic: true, .. })
214199
})
215200
}
216201
}

compiler/rustc_resolve/src/late/diagnostics.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -1810,12 +1810,10 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
18101810
let (span, sugg) = if let Some(param) = generics.params.iter().find(|p| {
18111811
!matches!(
18121812
p.kind,
1813-
hir::GenericParamKind::Type {
1814-
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
1815-
..
1816-
} | hir::GenericParamKind::Lifetime {
1817-
kind: hir::LifetimeParamKind::Elided,
1818-
}
1813+
hir::GenericParamKind::Type { synthetic: true, .. }
1814+
| hir::GenericParamKind::Lifetime {
1815+
kind: hir::LifetimeParamKind::Elided,
1816+
}
18191817
)
18201818
}) {
18211819
(param.span.shrink_to_lo(), format!("{}, ", lifetime_ref))
@@ -2042,12 +2040,10 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
20422040
if let Some(param) = generics.params.iter().find(|p| {
20432041
!matches!(
20442042
p.kind,
2045-
hir::GenericParamKind::Type {
2046-
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
2047-
..
2048-
} | hir::GenericParamKind::Lifetime {
2049-
kind: hir::LifetimeParamKind::Elided
2050-
}
2043+
hir::GenericParamKind::Type { synthetic: true, .. }
2044+
| hir::GenericParamKind::Lifetime {
2045+
kind: hir::LifetimeParamKind::Elided
2046+
}
20512047
)
20522048
}) {
20532049
(param.span.shrink_to_lo(), "'a, ".to_string())

compiler/rustc_span/src/symbol.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,6 @@ symbols! {
11481148
rustc_std_internal_symbol,
11491149
rustc_strict_coherence,
11501150
rustc_symbol_name,
1151-
rustc_synthetic,
11521151
rustc_test_marker,
11531152
rustc_then_this_would_need,
11541153
rustc_trivial_field_reads,

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,10 @@ fn suggest_restriction(
290290
} else {
291291
// Trivial case: `T` needs an extra bound: `T: Bound`.
292292
let (sp, suggestion) = match (
293-
generics.params.iter().find(|p| {
294-
!matches!(p.kind, hir::GenericParamKind::Type { synthetic: Some(_), .. })
295-
}),
293+
generics
294+
.params
295+
.iter()
296+
.find(|p| !matches!(p.kind, hir::GenericParamKind::Type { synthetic: true, .. })),
296297
super_traits,
297298
) {
298299
(_, None) => predicate_constraint(

compiler/rustc_typeck/src/astconv/generics.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -464,16 +464,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
464464
.params
465465
.iter()
466466
.filter(|param| {
467-
matches!(
468-
param.kind,
469-
ty::GenericParamDefKind::Type {
470-
synthetic: Some(
471-
hir::SyntheticTyParamKind::ImplTrait
472-
| hir::SyntheticTyParamKind::FromAttr
473-
),
474-
..
475-
}
476-
)
467+
matches!(param.kind, ty::GenericParamDefKind::Type { synthetic: true, .. })
477468
})
478469
.count()
479470
} else {

compiler/rustc_typeck/src/check/compare_method.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -607,10 +607,7 @@ fn compare_number_of_generics<'tcx>(
607607
.params
608608
.iter()
609609
.filter_map(|p| match p.kind {
610-
GenericParamKind::Type {
611-
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
612-
..
613-
} => Some(p.span),
610+
GenericParamKind::Type { synthetic: true, .. } => Some(p.span),
614611
_ => None,
615612
})
616613
.collect();
@@ -627,10 +624,7 @@ fn compare_number_of_generics<'tcx>(
627624
.params
628625
.iter()
629626
.filter_map(|p| match p.kind {
630-
GenericParamKind::Type {
631-
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
632-
..
633-
} => Some(p.span),
627+
GenericParamKind::Type { synthetic: true, .. } => Some(p.span),
634628
_ => None,
635629
})
636630
.collect();
@@ -823,7 +817,7 @@ fn compare_synthetic_generics<'tcx>(
823817
match (impl_synthetic, trait_synthetic) {
824818
// The case where the impl method uses `impl Trait` but the trait method uses
825819
// explicit generics
826-
(Some(hir::SyntheticTyParamKind::ImplTrait), None) => {
820+
(true, false) => {
827821
err.span_label(impl_span, "expected generic parameter, found `impl Trait`");
828822
(|| {
829823
// try taking the name from the trait impl
@@ -864,7 +858,7 @@ fn compare_synthetic_generics<'tcx>(
864858
}
865859
// The case where the trait method uses `impl Trait`, but the impl method uses
866860
// explicit generics.
867-
(None, Some(hir::SyntheticTyParamKind::ImplTrait)) => {
861+
(false, true) => {
868862
err.span_label(impl_span, "expected `impl Trait`, found generic parameter");
869863
(|| {
870864
let impl_m = impl_m.def_id.as_local()?;

compiler/rustc_typeck/src/check/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2025,7 +2025,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
20252025
fn point_at_param_definition(&self, err: &mut DiagnosticBuilder<'_>, param: ty::ParamTy) {
20262026
let generics = self.tcx.generics_of(self.body_id.owner.to_def_id());
20272027
let generic_param = generics.type_param(&param, self.tcx);
2028-
if let ty::GenericParamDefKind::Type { synthetic: Some(..), .. } = generic_param.kind {
2028+
if let ty::GenericParamDefKind::Type { synthetic: true, .. } = generic_param.kind {
20292029
return;
20302030
}
20312031
let param_def_id = generic_param.def_id;

compiler/rustc_typeck/src/check/method/suggest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1494,7 +1494,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14941494
Node::GenericParam(param) => {
14951495
let mut impl_trait = false;
14961496
let has_bounds =
1497-
if let hir::GenericParamKind::Type { synthetic: Some(_), .. } =
1497+
if let hir::GenericParamKind::Type { synthetic: true, .. } =
14981498
&param.kind
14991499
{
15001500
// We've found `fn foo(x: impl Trait)` instead of

compiler/rustc_typeck/src/collect.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1543,7 +1543,7 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
15431543
kind: ty::GenericParamDefKind::Type {
15441544
has_default: false,
15451545
object_lifetime_default: rl::Set1::Empty,
1546-
synthetic: None,
1546+
synthetic: false,
15471547
},
15481548
});
15491549

@@ -1673,7 +1673,7 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
16731673
kind: ty::GenericParamDefKind::Type {
16741674
has_default: false,
16751675
object_lifetime_default: rl::Set1::Empty,
1676-
synthetic: None,
1676+
synthetic: false,
16771677
},
16781678
}));
16791679
}
@@ -1690,7 +1690,7 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
16901690
kind: ty::GenericParamDefKind::Type {
16911691
has_default: false,
16921692
object_lifetime_default: rl::Set1::Empty,
1693-
synthetic: None,
1693+
synthetic: false,
16941694
},
16951695
});
16961696
}

src/librustdoc/clean/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,7 @@ impl Clean<Generics> for hir::Generics<'_> {
459459
// scans them first.
460460
fn is_impl_trait(param: &hir::GenericParam<'_>) -> bool {
461461
match param.kind {
462-
hir::GenericParamKind::Type { synthetic, .. } => {
463-
synthetic == Some(hir::SyntheticTyParamKind::ImplTrait)
464-
}
462+
hir::GenericParamKind::Type { synthetic, .. } => synthetic,
465463
_ => false,
466464
}
467465
}
@@ -560,7 +558,7 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics, ty::GenericPredicates<'tcx
560558
assert_eq!(param.index, 0);
561559
return None;
562560
}
563-
if synthetic == Some(hir::SyntheticTyParamKind::ImplTrait) {
561+
if synthetic {
564562
impl_trait.insert(param.index.into(), vec![]);
565563
return None;
566564
}

src/librustdoc/clean/types.rs

+4-15
Original file line numberDiff line numberDiff line change
@@ -1238,20 +1238,9 @@ impl WherePredicate {
12381238

12391239
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
12401240
crate enum GenericParamDefKind {
1241-
Lifetime {
1242-
outlives: Vec<Lifetime>,
1243-
},
1244-
Type {
1245-
did: DefId,
1246-
bounds: Vec<GenericBound>,
1247-
default: Option<Box<Type>>,
1248-
synthetic: Option<hir::SyntheticTyParamKind>,
1249-
},
1250-
Const {
1251-
did: DefId,
1252-
ty: Box<Type>,
1253-
default: Option<Box<String>>,
1254-
},
1241+
Lifetime { outlives: Vec<Lifetime> },
1242+
Type { did: DefId, bounds: Vec<GenericBound>, default: Option<Box<Type>>, synthetic: bool },
1243+
Const { did: DefId, ty: Box<Type>, default: Option<Box<String>> },
12551244
}
12561245

12571246
impl GenericParamDefKind {
@@ -1285,7 +1274,7 @@ impl GenericParamDef {
12851274
crate fn is_synthetic_type_param(&self) -> bool {
12861275
match self.kind {
12871276
GenericParamDefKind::Lifetime { .. } | GenericParamDefKind::Const { .. } => false,
1288-
GenericParamDefKind::Type { ref synthetic, .. } => synthetic.is_some(),
1277+
GenericParamDefKind::Type { synthetic, .. } => synthetic,
12891278
}
12901279
}
12911280

src/test/ui/synthetic-param.rs

-28
This file was deleted.

src/test/ui/synthetic-param.stderr

-30
This file was deleted.

src/tools/clippy/clippy_lints/src/types/borrowed_box.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ use clippy_utils::source::snippet;
33
use clippy_utils::{match_def_path, paths};
44
use if_chain::if_chain;
55
use rustc_errors::Applicability;
6-
use rustc_hir::{
7-
self as hir, GenericArg, GenericBounds, GenericParamKind, HirId, Lifetime, MutTy, Mutability, Node, QPath,
8-
SyntheticTyParamKind, TyKind,
9-
};
6+
use rustc_hir::{self as hir, GenericArg, GenericBounds, GenericParamKind};
7+
use rustc_hir::{HirId, Lifetime, MutTy, Mutability, Node, QPath, TyKind};
108
use rustc_lint::LateContext;
119

1210
use super::BORROWED_BOX;
@@ -105,7 +103,7 @@ fn get_bounds_if_impl_trait<'tcx>(cx: &LateContext<'tcx>, qpath: &QPath<'_>, id:
105103
if let Some(did) = cx.qpath_res(qpath, id).opt_def_id();
106104
if let Some(Node::GenericParam(generic_param)) = cx.tcx.hir().get_if_local(did);
107105
if let GenericParamKind::Type { synthetic, .. } = generic_param.kind;
108-
if synthetic == Some(SyntheticTyParamKind::ImplTrait);
106+
if synthetic;
109107
then {
110108
Some(generic_param.bounds)
111109
} else {

0 commit comments

Comments
 (0)