Skip to content
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

rustc: Remove #[rustc_synthetic] #91002

Merged
merged 1 commit into from
Nov 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 2 additions & 10 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1338,10 +1338,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
pure_wrt_drop: false,
bounds: hir_bounds,
span: self.lower_span(span),
kind: hir::GenericParamKind::Type {
default: None,
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
},
kind: hir::GenericParamKind::Type { default: None, synthetic: true },
});

hir::TyKind::Path(hir::QPath::Resolved(
Expand Down Expand Up @@ -1954,12 +1951,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
default: default.as_ref().map(|x| {
self.lower_ty(x, ImplTraitContext::Disallowed(ImplTraitPosition::Other))
}),
synthetic: param
.attrs
.iter()
.filter(|attr| attr.has_name(sym::rustc_synthetic))
.map(|_| hir::SyntheticTyParamKind::FromAttr)
.next(),
synthetic: false,
};

(hir::ParamName::Plain(self.lower_ident(param.ident)), kind)
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,6 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
TEST, rustc_expected_cgu_reuse, Normal,
template!(List: r#"cfg = "...", module = "...", kind = "...""#),
),
rustc_attr!(TEST, rustc_synthetic, Normal, template!(Word)),
rustc_attr!(TEST, rustc_symbol_name, Normal, template!(Word)),
rustc_attr!(TEST, rustc_polymorphize_error, Normal, template!(Word)),
rustc_attr!(TEST, rustc_def_path, Normal, template!(Word)),
Expand Down
12 changes: 1 addition & 11 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ pub enum GenericParamKind<'hir> {
},
Type {
default: Option<&'hir Ty<'hir>>,
synthetic: Option<SyntheticTyParamKind>,
synthetic: bool,
},
Const {
ty: &'hir Ty<'hir>,
Expand Down Expand Up @@ -577,16 +577,6 @@ impl Generics<'hir> {
}
}

/// Synthetic type parameters are converted to another form during lowering; this allows
/// us to track the original form they had, and is useful for error messages.
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Hash, Debug)]
#[derive(HashStable_Generic)]
pub enum SyntheticTyParamKind {
ImplTrait,
// Created by the `#[rustc_synthetic]` attribute.
FromAttr,
}

/// A where-clause in a definition.
#[derive(Debug, HashStable_Generic)]
pub struct WhereClause<'hir> {
Expand Down
21 changes: 3 additions & 18 deletions compiler/rustc_middle/src/ty/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::ty;
use crate::ty::subst::{Subst, SubstsRef};
use rustc_ast as ast;
use rustc_data_structures::fx::FxHashMap;
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_span::symbol::Symbol;
use rustc_span::Span;
Expand All @@ -13,14 +12,8 @@ use super::{EarlyBoundRegion, InstantiatedPredicates, ParamConst, ParamTy, Predi
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable)]
pub enum GenericParamDefKind {
Lifetime,
Type {
has_default: bool,
object_lifetime_default: ObjectLifetimeDefault,
synthetic: Option<hir::SyntheticTyParamKind>,
},
Const {
has_default: bool,
},
Type { has_default: bool, object_lifetime_default: ObjectLifetimeDefault, synthetic: bool },
Const { has_default: bool },
}

impl GenericParamDefKind {
Expand Down Expand Up @@ -202,15 +195,7 @@ impl<'tcx> Generics {
/// Returns `true` if `params` has `impl Trait`.
pub fn has_impl_trait(&'tcx self) -> bool {
self.params.iter().any(|param| {
matches!(
param.kind,
ty::GenericParamDefKind::Type {
synthetic: Some(
hir::SyntheticTyParamKind::ImplTrait | hir::SyntheticTyParamKind::FromAttr,
),
..
}
)
matches!(param.kind, ty::GenericParamDefKind::Type { synthetic: true, .. })
})
}
}
Expand Down
20 changes: 8 additions & 12 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1810,12 +1810,10 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
let (span, sugg) = if let Some(param) = generics.params.iter().find(|p| {
!matches!(
p.kind,
hir::GenericParamKind::Type {
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
..
} | hir::GenericParamKind::Lifetime {
kind: hir::LifetimeParamKind::Elided,
}
hir::GenericParamKind::Type { synthetic: true, .. }
| hir::GenericParamKind::Lifetime {
kind: hir::LifetimeParamKind::Elided,
}
)
}) {
(param.span.shrink_to_lo(), format!("{}, ", lifetime_ref))
Expand Down Expand Up @@ -2042,12 +2040,10 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
if let Some(param) = generics.params.iter().find(|p| {
!matches!(
p.kind,
hir::GenericParamKind::Type {
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
..
} | hir::GenericParamKind::Lifetime {
kind: hir::LifetimeParamKind::Elided
}
hir::GenericParamKind::Type { synthetic: true, .. }
| hir::GenericParamKind::Lifetime {
kind: hir::LifetimeParamKind::Elided
}
)
}) {
(param.span.shrink_to_lo(), "'a, ".to_string())
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,6 @@ symbols! {
rustc_std_internal_symbol,
rustc_strict_coherence,
rustc_symbol_name,
rustc_synthetic,
rustc_test_marker,
rustc_then_this_would_need,
rustc_trivial_field_reads,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,10 @@ fn suggest_restriction(
} else {
// Trivial case: `T` needs an extra bound: `T: Bound`.
let (sp, suggestion) = match (
generics.params.iter().find(|p| {
!matches!(p.kind, hir::GenericParamKind::Type { synthetic: Some(_), .. })
}),
generics
.params
.iter()
.find(|p| !matches!(p.kind, hir::GenericParamKind::Type { synthetic: true, .. })),
super_traits,
) {
(_, None) => predicate_constraint(
Expand Down
11 changes: 1 addition & 10 deletions compiler/rustc_typeck/src/astconv/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,16 +464,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
.params
.iter()
.filter(|param| {
matches!(
param.kind,
ty::GenericParamDefKind::Type {
synthetic: Some(
hir::SyntheticTyParamKind::ImplTrait
| hir::SyntheticTyParamKind::FromAttr
),
..
}
)
matches!(param.kind, ty::GenericParamDefKind::Type { synthetic: true, .. })
})
.count()
} else {
Expand Down
14 changes: 4 additions & 10 deletions compiler/rustc_typeck/src/check/compare_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,10 +607,7 @@ fn compare_number_of_generics<'tcx>(
.params
.iter()
.filter_map(|p| match p.kind {
GenericParamKind::Type {
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
..
} => Some(p.span),
GenericParamKind::Type { synthetic: true, .. } => Some(p.span),
_ => None,
})
.collect();
Expand All @@ -627,10 +624,7 @@ fn compare_number_of_generics<'tcx>(
.params
.iter()
.filter_map(|p| match p.kind {
GenericParamKind::Type {
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
..
} => Some(p.span),
GenericParamKind::Type { synthetic: true, .. } => Some(p.span),
_ => None,
})
.collect();
Expand Down Expand Up @@ -823,7 +817,7 @@ fn compare_synthetic_generics<'tcx>(
match (impl_synthetic, trait_synthetic) {
// The case where the impl method uses `impl Trait` but the trait method uses
// explicit generics
(Some(hir::SyntheticTyParamKind::ImplTrait), None) => {
(true, false) => {
err.span_label(impl_span, "expected generic parameter, found `impl Trait`");
(|| {
// try taking the name from the trait impl
Expand Down Expand Up @@ -864,7 +858,7 @@ fn compare_synthetic_generics<'tcx>(
}
// The case where the trait method uses `impl Trait`, but the impl method uses
// explicit generics.
(None, Some(hir::SyntheticTyParamKind::ImplTrait)) => {
(false, true) => {
err.span_label(impl_span, "expected `impl Trait`, found generic parameter");
(|| {
let impl_m = impl_m.def_id.as_local()?;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2025,7 +2025,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fn point_at_param_definition(&self, err: &mut DiagnosticBuilder<'_>, param: ty::ParamTy) {
let generics = self.tcx.generics_of(self.body_id.owner.to_def_id());
let generic_param = generics.type_param(&param, self.tcx);
if let ty::GenericParamDefKind::Type { synthetic: Some(..), .. } = generic_param.kind {
if let ty::GenericParamDefKind::Type { synthetic: true, .. } = generic_param.kind {
return;
}
let param_def_id = generic_param.def_id;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/check/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1490,7 +1490,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Node::GenericParam(param) => {
let mut impl_trait = false;
let has_bounds =
if let hir::GenericParamKind::Type { synthetic: Some(_), .. } =
if let hir::GenericParamKind::Type { synthetic: true, .. } =
&param.kind
{
// We've found `fn foo(x: impl Trait)` instead of
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_typeck/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1543,7 +1543,7 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
kind: ty::GenericParamDefKind::Type {
has_default: false,
object_lifetime_default: rl::Set1::Empty,
synthetic: None,
synthetic: false,
},
});

Expand Down Expand Up @@ -1673,7 +1673,7 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
kind: ty::GenericParamDefKind::Type {
has_default: false,
object_lifetime_default: rl::Set1::Empty,
synthetic: None,
synthetic: false,
},
}));
}
Expand All @@ -1690,7 +1690,7 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics {
kind: ty::GenericParamDefKind::Type {
has_default: false,
object_lifetime_default: rl::Set1::Empty,
synthetic: None,
synthetic: false,
},
});
}
Expand Down
6 changes: 2 additions & 4 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,7 @@ impl Clean<Generics> for hir::Generics<'_> {
// scans them first.
fn is_impl_trait(param: &hir::GenericParam<'_>) -> bool {
match param.kind {
hir::GenericParamKind::Type { synthetic, .. } => {
synthetic == Some(hir::SyntheticTyParamKind::ImplTrait)
}
hir::GenericParamKind::Type { synthetic, .. } => synthetic,
_ => false,
}
}
Expand Down Expand Up @@ -557,7 +555,7 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics, ty::GenericPredicates<'tcx
assert_eq!(param.index, 0);
return None;
}
if synthetic == Some(hir::SyntheticTyParamKind::ImplTrait) {
if synthetic {
impl_trait.insert(param.index.into(), vec![]);
return None;
}
Expand Down
19 changes: 4 additions & 15 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1238,20 +1238,9 @@ impl WherePredicate {

#[derive(Clone, PartialEq, Eq, Debug, Hash)]
crate enum GenericParamDefKind {
Lifetime {
outlives: Vec<Lifetime>,
},
Type {
did: DefId,
bounds: Vec<GenericBound>,
default: Option<Box<Type>>,
synthetic: Option<hir::SyntheticTyParamKind>,
},
Const {
did: DefId,
ty: Box<Type>,
default: Option<Box<String>>,
},
Lifetime { outlives: Vec<Lifetime> },
Type { did: DefId, bounds: Vec<GenericBound>, default: Option<Box<Type>>, synthetic: bool },
Const { did: DefId, ty: Box<Type>, default: Option<Box<String>> },
}

impl GenericParamDefKind {
Expand Down Expand Up @@ -1285,7 +1274,7 @@ impl GenericParamDef {
crate fn is_synthetic_type_param(&self) -> bool {
match self.kind {
GenericParamDefKind::Lifetime { .. } | GenericParamDefKind::Const { .. } => false,
GenericParamDefKind::Type { ref synthetic, .. } => synthetic.is_some(),
GenericParamDefKind::Type { synthetic, .. } => synthetic,
}
}

Expand Down
28 changes: 0 additions & 28 deletions src/test/ui/synthetic-param.rs

This file was deleted.

30 changes: 0 additions & 30 deletions src/test/ui/synthetic-param.stderr

This file was deleted.

8 changes: 3 additions & 5 deletions src/tools/clippy/clippy_lints/src/types/borrowed_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ use clippy_utils::source::snippet;
use clippy_utils::{match_def_path, paths};
use if_chain::if_chain;
use rustc_errors::Applicability;
use rustc_hir::{
self as hir, GenericArg, GenericBounds, GenericParamKind, HirId, Lifetime, MutTy, Mutability, Node, QPath,
SyntheticTyParamKind, TyKind,
};
use rustc_hir::{self as hir, GenericArg, GenericBounds, GenericParamKind};
use rustc_hir::{HirId, Lifetime, MutTy, Mutability, Node, QPath, TyKind};
use rustc_lint::LateContext;

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