8000 Remove Spans from HIR by cjgillot · Pull Request #72015 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

Remove Spans from HIR #72015

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 41 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
596450e
Collect spans during lowering.
cjgillot May 1, 2020
1b6618d
Introduce a query for HIR spans.
cjgillot May 1, 2020
166bb39
Don't pass spans in hir::map::blocks.
cjgillot May 2, 2020
46b2dc2
Stop passing the Span in HIR visiting.
cjgillot May 2, 2020
9c1039a
Pass HirId in save_analysis.
cjgillot Jun 7, 2020
7b5f1a3
Remove Span parameter from HIR collector.
cjgillot Jun 3, 2020
07e9c5c
Fix fulldeps tests.
cjgillot Dec 13, 2020
4cff471
Fix clippy.
cjgillot Dec 13, 2020
173048d
Remove span from hir::Param.
cjgillot May 1, 2020
56a6530
Remove span from hir::Variant.
cjgillot May 1, 2020
272a1f2
Remove span from hir::StructField.
cjgillot May 1, 2020
7b8595f
Remove span from hir::Stmt.
cjgillot Mar 6, 2021
a295ae3
Remove span from hir::Block.
cjgillot May 1, 2020
32716ae
Remove span from hir::MacroDef.
cjgillot May 2, 2020
6ec2356
Remove span from hir::GenericParam.
cjgillot May 2, 2020
4f527e9
Remove span from hir::Arm.
cjgillot May 2, 2020
1fcff64
Remove span from hir::FieldPat.
cjgillot May 2, 2020
3cf2fba
Remove span from hir::Local.
cjgillot May 2, 2020
f51da1e
Remove span from hir::Pat.
cjgillot Mar 6, 2021
ec56b9f
Remove span from hir::Field.
cjgillot May 2, 2020
ec5cd74
Remove GenericArg::span.
cjgillot May 3, 2020
66e1a16
Remove Span from hir::TypeBinding.
cjgillot May 8, 2020
a29261d
Remove Span from hir::ConstArg.
cjgillot Jun 1, 2020
56871a5
Remove Span from hir::TraitItemRef.
cjgillot Jun 1, 2020
346176f
Remove Span from hir::ImplItemRef.
cjgillot Jun 1, 2020
6459750
Remove span from hir::ForeignItemRef.
cjgillot Dec 11, 2020
fcdfaf0
Fix fulldeps tests.
cjgillot May 9, 2020
e6d9d4b
Fortify find_entry.
cjgillot Dec 13, 2020
125796b
Remove Span from hir::CrateItem.
cjgillot Dec 10, 2020
7e26fd6
Pass HirId in rustc_typeck::check.
cjgillot May 2, 2020
bdb83e2
Pass HirId in rustc_lint.
cjgillot May 2, 2020
05e913a
Pass HirId in rustc_passes::stability.
cjgillot May 2, 2020
2035593
Pass HirId in rustc_incremental::persist::dirty_clean.
cjgillot Dec 11, 2020
cf99aea
Pass HirId in rustc_passes::check_attr.
cjgillot Dec 11, 2020
85396f8
Pass HirId in rustc_passes::entry.
cjgillot Dec 11, 2020
042bf08
Remove span from hir::Item.
cjgillot Dec 22, 2020
d632f42
Remove span from hir::ForeignItem.
cjgillot Dec 11, 2020
0d9d1e0
Remove Span from hir::Ty.
cjgillot May 8, 2020
e281f67
Remove Span from hir::Expr.
cjgillot May 3, 2020
f065656
Fix fulldeps tests.
cjgillot May 9, 2020
bb40d08
Fix suggestions.
cjgillot Mar 13, 2021
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
8000
Diff view
Prev Previous commit
Next Next commit
Pass HirId in rustc_passes::stability.
  • Loading branch information
cjgillot committed Mar 13, 2021
commit 05e913a0975869e662b20f5c8a943c4b7bc67bc8
64 changes: 24 additions & 40 deletions compiler/rustc_passes/src/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
fn annotate<F>(
&mut self,
hir_id: HirId,
item_sp: Span,
kind: AnnotationKind,
inherit_deprecation: InheritDeprecation,
inherit_const_stability: InheritConstStability,
Expand Down Expand Up @@ -142,16 +141,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
}
}

if self.tcx.features().staged_api {
if let Some(a) = attrs.iter().find(|a| self.tcx.sess.check_name(a, sym::deprecated)) {
self.tcx
.sess
.struct_span_err(a.span, "`#[deprecated]` cannot be used in staged API")
.span_label(a.span, "use `#[rustc_deprecated]` instead")
.span_label(item_sp, "")
.emit();
}
} else {
if !self.tcx.features().staged_api {
self.recurse_with_stability_attrs(
depr.map(|(d, _)| DeprecationEntry::local(d, hir_id)),
None,
Expand All @@ -161,6 +151,16 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
return;
}

let item_sp = self.tcx.hir().span_with_body(hir_id);
if let Some(a) = attrs.iter().find(|a| self.tcx.sess.check_name(a, sym::deprecated)) {
self.tcx
.sess
.struct_span_err(a.span, "`#[deprecated]` cannot be used in staged API")
.span_label(a.span, "use `#[rustc_deprecated]` instead")
.span_label(item_sp, "")
.emit();
}

let (stab, const_stab) = attr::find_stability(&self.tcx.sess, attrs, item_sp);

let const_stab = const_stab.map(|(const_stab, _)| {
Expand Down Expand Up @@ -385,7 +385,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
if let Some(ctor_hir_id) = sd.ctor_hir_id() {
self.annotate(
ctor_hir_id,
i.span,
AnnotationKind::Required,
InheritDeprecation::Yes,
InheritConstStability::No,
Expand All @@ -399,7 +398,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {

self.annotate(
i.hir_id(),
i.span,
kind,
InheritDeprecation::Yes,
const_stab_inherit,
Expand All @@ -412,7 +410,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem<'tcx>) {
self.annotate(
ti.hir_id(),
ti.span,
AnnotationKind::Required,
InheritDeprecation::Yes,
InheritConstStability::No,
Expand All @@ -428,7 +425,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
if self.in_trait_impl { AnnotationKind::Prohibited } else { AnnotationKind::Required };
self.annotate(
ii.hir_id(),
ii.span,
kind,
InheritDeprecation::Yes,
InheritConstStability::No,
Expand All @@ -440,10 +436,8 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
}

fn visit_variant(&mut self, var: &'tcx Variant<'tcx>, g: &'tcx Generics<'tcx>, item_id: HirId) {
let var_span = self.tcx.hir().span(var.id);
self.annotate(
var.id,
var_span,
AnnotationKind::Required,
InheritDeprecation::Yes,
InheritConstStability::No,
Expand All @@ -452,7 +446,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
if let Some(ctor_hir_id) = var.data.ctor_hir_id() {
v.annotate(
ctor_hir_id,
var_span,
AnnotationKind::Required,
InheritDeprecation::Yes,
InheritConstStability::No,
Expand All @@ -467,10 +460,8 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
}

fn visit_struct_field(&mut self, s: &'tcx StructField<'tcx>) {
let span = self.tcx.hir().span(s.hir_id);
self.annotate(
s.hir_id,
span,
AnnotationKind::Required,
InheritDeprecation::Yes,
InheritConstStability::No,
Expand All @@ -484,7 +475,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
fn visit_foreign_item(&mut self, i: &'tcx hir::ForeignItem<'tcx>) {
self.annotate(
i.hir_id(),
i.span,
AnnotationKind::Required,
InheritDeprecation::Yes,
InheritConstStability::No,
Expand All @@ -496,10 +486,8 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
}

fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef<'tcx>) {
let span = self.tcx.hir().span(md.hir_id());
self.annotate(
md.hir_id(),
span,
AnnotationKind::Required,
InheritDeprecation::Yes,
InheritConstStability::No,
Expand All @@ -517,10 +505,8 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
_ => AnnotationKind::Prohibited,
};

let span = self.tcx.hir().span(p.hir_id);
self.annotate(
p.hir_id,
span,
kind,
InheritDeprecation::No,
InheritConstStability::No,
Expand All @@ -538,23 +524,25 @@ struct MissingStabilityAnnotations<'tcx> {
}

impl<'tcx> MissingStabilityAnnotations<'tcx> {
fn check_missing_stability(&self, hir_id: HirId, span: Span) {
fn check_missing_stability(&self, hir_id: HirId) {
let stab = self.tcx.stability().local_stability(hir_id);
let is_error =
!self.tcx.sess.opts.test && stab.is_none() && self.access_levels.is_reachable(hir_id);
if is_error {
let def_id = self.tcx.hir().local_def_id(hir_id);
let descr = self.tcx.def_kind(def_id).descr(def_id.to_def_id());
let span = self.tcx.hir().span_with_body(hir_id);
self.tcx.sess.span_err(span, &format!("{} has missing stability attribute", descr));
}
}

fn check_missing_const_stability(&self, hir_id: HirId, span: Span) {
fn check_missing_const_stability(&self, hir_id: HirId) {
let stab_map = self.tcx.stability();
let stab = stab_map.local_stability(hir_id);
if stab.map_or(false, |stab| stab.level.is_stable()) {
let const_stab = stab_map.local_const_stability(hir_id);
if const_stab.is_none() {
let span = self.tcx.hir().span_with_body(hir_id);
self.tcx.sess.span_err(
span,
"`#[stable]` const functions must also be either \
Expand Down Expand Up @@ -582,53 +570,50 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> {
hir::ItemKind::Impl(hir::Impl { of_trait: None, .. })
| hir::ItemKind::ForeignMod { .. }
) {
self.check_missing_stability(i.hir_id(), i.span);
self.check_missing_stability(i.hir_id());
}

// Ensure `const fn` that are `stable` have one of `rustc_const_unstable` or
// `rustc_const_stable`.
if self.tcx.features().staged_api
&& matches!(&i.kind, hir::ItemKind::Fn(sig, ..) if sig.header.is_const())
{
self.check_missing_const_stability(i.hir_id(), i.span);
self.check_missing_const_stability(i.hir_id());
}

intravisit::walk_item(self, i)
}

fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem<'tcx>) {
self.check_missing_stability(ti.hir_id(), ti.span);
self.check_missing_stability(ti.hir_id());
intravisit::walk_trait_item(self, ti);
}

fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem<'tcx>) {
let impl_def_id = self.tcx.hir().local_def_id(self.tcx.hir().get_parent_item(ii.hir_id()));
if self.tcx.impl_trait_ref(impl_def_id).is_none() {
self.check_missing_stability(ii.hir_id(), ii.span);
self.check_missing_stability(ii.hir_id());
}
intravisit::walk_impl_item(self, ii);
}

fn visit_variant(&mut self, var: &'tcx Variant<'tcx>, g: &'tcx Generics<'tcx>, item_id: HirId) {
let span = self.tcx.hir().span(var.id);
self.check_missing_stability(var.id, span);
self.check_missing_stability(var.id);
intravisit::walk_variant(self, var, g, item_id);
}

fn visit_struct_field(&mut self, s: &'tcx StructField<'tcx>) {
let span = self.tcx.hir().span(s.hir_id);
self.check_missing_stability(s.hir_id, span);
self.check_missing_stability(s.hir_id);
intravisit::walk_struct_field(self, s);
}

fn visit_foreign_item(&mut self, i: &'tcx hir::ForeignItem<'tcx>) {
self.check_missing_stability(i.hir_id(), i.span);
self.check_missing_stability(i.hir_id());
intravisit::walk_foreign_item(self, i);
}

fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef<'tcx>) {
let span = self.tcx.hir().span(md.hir_id());
self.check_missing_stability(md.hir_id(), span);
self.check_missing_stability(md.hir_id());
}

// Note that we don't need to `check_missing_stability` for default generic parameters,
Expand Down Expand Up @@ -693,7 +678,6 @@ fn new_index(tcx: TyCtxt<'tcx>) -> Index<'tcx> {

annotator.annotate(
hir::CRATE_HIR_ID,
tcx.hir().span(hir::CRATE_HIR_ID),
AnnotationKind::Required,
InheritDeprecation::Yes,
InheritConstStability::No,
Expand Down Expand Up @@ -892,7 +876,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
if tcx.stability().staged_api[&LOCAL_CRATE] {
let krate = tcx.hir().krate();
let mut missing = MissingStabilityAnnotations { tcx, access_levels };
missing.check_missing_stability(hir::CRATE_HIR_ID, tcx.hir().span(hir::CRATE_HIR_ID));
missing.check_missing_stability(hir::CRATE_HIR_ID);
intravisit::walk_crate(&mut missing, krate);
krate.visit_all_item_likes(&mut missing.as_deep_visitor());
}
Expand Down
0