Skip to content

Commit

Permalink
Rollup merge of rust-lang#120230 - Urgau:for_scope-single-scope, r=mi…
Browse files Browse the repository at this point in the history
…chaelwoerister

Assert that a single scope is passed to `for_scope`

Addresses rust-lang#118518 (comment)

r? `@michaelwoerister`
  • Loading branch information
fmease authored Jan 24, 2024
2 parents 83f83d3 + 64f590a commit 8193116
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1524,16 +1524,25 @@ pub trait RemapFileNameExt {
where
Self: 'a;

fn for_scope(&self, sess: &Session, scopes: RemapPathScopeComponents) -> Self::Output<'_>;
/// Returns a possibly remapped filename based on the passed scope and remap cli options.
///
/// One and only one scope should be passed to this method. For anything related to
/// "codegen" see the [`RemapFileNameExt::for_codegen`] method.
fn for_scope(&self, sess: &Session, scope: RemapPathScopeComponents) -> Self::Output<'_>;

/// Return a possibly remapped filename, to be used in "codegen" related parts.
fn for_codegen(&self, sess: &Session) -> Self::Output<'_>;
}

impl RemapFileNameExt for rustc_span::FileName {
type Output<'a> = rustc_span::FileNameDisplay<'a>;

fn for_scope(&self, sess: &Session, scopes: RemapPathScopeComponents) -> Self::Output<'_> {
if sess.opts.unstable_opts.remap_path_scope.contains(scopes) {
fn for_scope(&self, sess: &Session, scope: RemapPathScopeComponents) -> Self::Output<'_> {
assert!(
scope.bits().count_ones() == 1,
"one and only one scope should be passed to for_scope"
);
if sess.opts.unstable_opts.remap_path_scope.contains(scope) {
self.prefer_remapped_unconditionaly()
} else {
self.prefer_local()
Expand All @@ -1552,8 +1561,12 @@ impl RemapFileNameExt for rustc_span::FileName {
impl RemapFileNameExt for rustc_span::RealFileName {
type Output<'a> = &'a Path;

fn for_scope(&self, sess: &Session, scopes: RemapPathScopeComponents) -> Self::Output<'_> {
if sess.opts.unstable_opts.remap_path_scope.contains(scopes) {
fn for_scope(&self, sess: &Session, scope: RemapPathScopeComponents) -> Self::Output<'_> {
assert!(
scope.bits().count_ones() == 1,
"one and only one scope should be passed to for_scope"
);
if sess.opts.unstable_opts.remap_path_scope.contains(scope) {
self.remapped_path_if_available()
} else {
self.local_path_if_available()
Expand Down

0 comments on commit 8193116

Please sign in to comment.