Skip to content

Rollup of 2 pull requests #115847

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 4 commits into from
Closed
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
4 changes: 2 additions & 2 deletions compiler/rustc_feature/src/removed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ declare_features! (
/// Allows use of unary negate on unsigned integers, e.g., -e for e: u8
(removed, negate_unsigned, "1.0.0", Some(29645), None, None),
/// Allows `#[no_coverage]` on functions.
/// The feature was renamed to `coverage` and the attribute to `#[coverage(on|off)]`
(removed, no_coverage, "CURRENT_RUSTC_VERSION", Some(84605), None, Some("renamed to `coverage`")),
/// The feature was renamed to `coverage_attribute` and the attribute to `#[coverage(on|off)]`
(removed, no_coverage, "CURRENT_RUSTC_VERSION", Some(84605), None, Some("renamed to `coverage_attribute`")),
/// Allows `#[no_debug]`.
(removed, no_debug, "1.43.0", Some(29721), None, Some("removed due to lack of demand")),
/// Allows using `#[on_unimplemented(..)]` on traits.
Expand Down
17 changes: 16 additions & 1 deletion compiler/rustc_smir/src/rustc_internal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use rustc_interface::{interface, Queries};
use rustc_middle::mir::interpret::AllocId;
use rustc_middle::ty::TyCtxt;
pub use rustc_span::def_id::{CrateNum, DefId};
use rustc_span::Span;

fn with_tables<R>(mut f: impl FnMut(&mut Tables<'_>) -> R) -> R {
let mut ret = None;
Expand Down Expand Up @@ -159,14 +160,28 @@ impl<'tcx> Tables<'tcx> {
self.alloc_ids.push(aid);
stable_mir::AllocId(id)
}

pub(crate) fn create_span(&mut self, span: Span) -> stable_mir::ty::Span {
for (i, &sp) in self.spans.iter().enumerate() {
if sp == span {
return stable_mir::ty::Span(i);
}
}
let id = self.spans.len();
self.spans.push(span);
stable_mir::ty::Span(id)
}
}

pub fn crate_num(item: &stable_mir::Crate) -> CrateNum {
item.id.into()
}

pub fn run(tcx: TyCtxt<'_>, f: impl FnOnce()) {
crate::stable_mir::run(Tables { tcx, def_ids: vec![], alloc_ids: vec![], types: vec![] }, f);
crate::stable_mir::run(
Tables { tcx, def_ids: vec![], alloc_ids: vec![], spans: vec![], types: vec![] },
f,
);
}

/// A type that provides internal information but that can still be used for debug purpose.
Expand Down
12 changes: 7 additions & 5 deletions compiler/rustc_smir/src/rustc_smir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

use crate::rustc_internal::{self, opaque};
use crate::stable_mir::mir::{CopyNonOverlapping, UserTypeProjection, VariantIdx};
use crate::stable_mir::ty::{FloatTy, GenericParamDef, IntTy, Movability, RigidTy, TyKind, UintTy};
use crate::stable_mir::ty::{
FloatTy, GenericParamDef, IntTy, Movability, RigidTy, Span, TyKind, UintTy,
};
use crate::stable_mir::{self, CompilerError, Context};
use rustc_hir as hir;
use rustc_middle::mir::interpret::{alloc_range, AllocId};
Expand Down Expand Up @@ -42,7 +44,7 @@ impl<'tcx> Context for Tables<'tcx> {
self.tcx.def_path_str(self[def_id])
}

fn span_of_an_item(&mut self, def_id: stable_mir::DefId) -> stable_mir::ty::Span {
fn span_of_an_item(&mut self, def_id: stable_mir::DefId) -> Span {
self.tcx.def_span(self[def_id]).stable(self)
}

Expand Down Expand Up @@ -185,6 +187,7 @@ pub struct Tables<'tcx> {
pub tcx: TyCtxt<'tcx>,
pub def_ids: Vec<DefId>,
pub alloc_ids: Vec<AllocId>,
pub spans: Vec<rustc_span::Span>,
pub types: Vec<MaybeStable<stable_mir::ty::TyKind, Ty<'tcx>>>,
}

Expand Down Expand Up @@ -1514,9 +1517,8 @@ impl<'tcx> Stable<'tcx> for ty::Region<'tcx> {
impl<'tcx> Stable<'tcx> for rustc_span::Span {
type T = stable_mir::ty::Span;

fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
// FIXME: add a real implementation of stable spans
opaque(self)
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
tables.create_span(*self)
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_smir/src/stable_mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl CrateItem {
with(|cx| cx.mir_body(self.0))
}

pub fn span(&self) -> ty::Span {
pub fn span(&self) -> Span {
with(|cx| cx.span_of_an_item(self.0))
}
}
Expand Down
11 changes: 10 additions & 1 deletion compiler/rustc_smir/src/stable_mir/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,16 @@ pub struct Const {

type Ident = Opaque;
pub(crate) type Region = Opaque;
pub(crate) type Span = Opaque;
#[derive(Clone, Copy, PartialEq, Eq)]
pub struct Span(pub(crate) usize);

impl Debug for Span {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
let mut span = None;
with(|context| context.rustc_tables(&mut |tables| span = Some(tables.spans[self.0])));
f.write_fmt(format_args!("{:?}", &span.unwrap()))
}
}

#[derive(Clone, Debug)]
pub enum TyKind {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0557]: feature has been removed
LL | #![feature(no_coverage)]
| ^^^^^^^^^^^ feature has been removed
|
= note: renamed to `coverage`
= note: renamed to `coverage_attribute`

error[E0658]: the `#[coverage]` attribute is an experimental feature
--> $DIR/feature-gate-coverage-attribute.rs:10:1
Expand Down