Skip to content

Commit 64f590a

Browse files
committed
Assert that a single scope is passed to for_scope
1 parent a58ec8f commit 64f590a

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

compiler/rustc_session/src/session.rs

+18-5
Original file line numberDiff line numberDiff line change
@@ -1523,16 +1523,25 @@ pub trait RemapFileNameExt {
15231523
where
15241524
Self: 'a;
15251525

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

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

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

1534-
fn for_scope(&self, sess: &Session, scopes: RemapPathScopeComponents) -> Self::Output<'_> {
1535-
if sess.opts.unstable_opts.remap_path_scope.contains(scopes) {
1539+
fn for_scope(&self, sess: &Session, scope: RemapPathScopeComponents) -> Self::Output<'_> {
1540+
assert!(
1541+
scope.bits().count_ones() == 1,
1542+
"one and only one scope should be passed to for_scope"
1543+
);
1544+
if sess.opts.unstable_opts.remap_path_scope.contains(scope) {
15361545
self.prefer_remapped_unconditionaly()
15371546
} else {
15381547
self.prefer_local()
@@ -1551,8 +1560,12 @@ impl RemapFileNameExt for rustc_span::FileName {
15511560
impl RemapFileNameExt for rustc_span::RealFileName {
15521561
type Output<'a> = &'a Path;
15531562

1554-
fn for_scope(&self, sess: &Session, scopes: RemapPathScopeComponents) -> Self::Output<'_> {
1555-
if sess.opts.unstable_opts.remap_path_scope.contains(scopes) {
1563+
fn for_scope(&self, sess: &Session, scope: RemapPathScopeComponents) -> Self::Output<'_> {
1564+
assert!(
1565+
scope.bits().count_ones() == 1,
1566+
"one and only one scope should be passed to for_scope"
1567+
);
1568+
if sess.opts.unstable_opts.remap_path_scope.contains(scope) {
15561569
self.remapped_path_if_available()
15571570
} else {
15581571
self.local_path_if_available()

0 commit comments

Comments
 (0)