Skip to content

Commit 55d5ea3

Browse files
authored
Rollup merge of rust-lang#120230 - Urgau:for_scope-single-scope, r=michaelwoerister
Assert that a single scope is passed to `for_scope` Addresses rust-lang#118518 (comment) r? ``@michaelwoerister``
2 parents 0c45e3c + 64f590a commit 55d5ea3

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
@@ -1510,16 +1510,25 @@ pub trait RemapFileNameExt {
15101510
where
15111511
Self: 'a;
15121512

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

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

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

1521-
fn for_scope(&self, sess: &Session, scopes: RemapPathScopeComponents) -> Self::Output<'_> {
1522-
if sess.opts.unstable_opts.remap_path_scope.contains(scopes) {
1526+
fn for_scope(&self, sess: &Session, scope: RemapPathScopeComponents) -> Self::Output<'_> {
1527+
assert!(
1528+
scope.bits().count_ones() == 1,
1529+
"one and only one scope should be passed to for_scope"
1530+
);
1531+
if sess.opts.unstable_opts.remap_path_scope.contains(scope) {
15231532
self.prefer_remapped_unconditionaly()
15241533
} else {
15251534
self.prefer_local()
@@ -1538,8 +1547,12 @@ impl RemapFileNameExt for rustc_span::FileName {
15381547
impl RemapFileNameExt for rustc_span::RealFileName {
15391548
type Output<'a> = &'a Path;
15401549

1541-
fn for_scope(&self, sess: &Session, scopes: RemapPathScopeComponents) -> Self::Output<'_> {
1542-
if sess.opts.unstable_opts.remap_path_scope.contains(scopes) {
1550+
fn for_scope(&self, sess: &Session, scope: RemapPathScopeComponents) -> Self::Output<'_> {
1551+
assert!(
1552+
scope.bits().count_ones() == 1,
1553+
"one and only one scope should be passed to for_scope"
1554+
);
1555+
if sess.opts.unstable_opts.remap_path_scope.contains(scope) {
15431556
self.remapped_path_if_available()
15441557
} else {
15451558
self.local_path_if_available()

0 commit comments

Comments
 (0)