Skip to content

Commit 662b32b

Browse files
authored
Unrolled build for rust-lang#120230
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 d93fecc + 64f590a commit 662b32b

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
@@ -1524,16 +1524,25 @@ pub trait RemapFileNameExt {
15241524
where
15251525
Self: 'a;
15261526

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

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

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

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

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

0 commit comments

Comments
 (0)