Skip to content

Commit 1633746

Browse files
committed
Handle more cases in cfg_accessible
1 parent bef2b7c commit 1633746

File tree

3 files changed

+55
-49
lines changed

3 files changed

+55
-49
lines changed

compiler/rustc_resolve/src/macros.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -443,11 +443,20 @@ impl<'a> ResolverExpand for Resolver<'a> {
443443
PathResult::NonModule(partial_res) if partial_res.unresolved_segments() == 0 => {
444444
return Ok(true);
445445
}
446+
PathResult::NonModule(..) => {
447+
self.session
448+
.struct_span_err(span, "not sure whether the path is accessible or not")
449+
.note("the type may have associated items, but we are currently not checking them")
450+
.emit();
451+
452+
// If we get a partially resolved NonModule in one namespace, we should get the
453+
// same result in any other namespaces, so we can return early.
454+
return Ok(false);
455+
}
446456
PathResult::Indeterminate => indeterminate = true,
447-
// FIXME: `resolve_path` is not ready to report partially resolved paths
448-
// correctly, so we just report an error if the path was reported as unresolved.
449-
// This needs to be fixed for `cfg_accessible` to be useful.
450-
PathResult::NonModule(..) | PathResult::Failed { .. } => {}
457+
// We can only be sure that a path doesn't exist after having tested all the
458+
// posibilities, only at that time we can return false.
459+
PathResult::Failed { .. } => {}
451460
PathResult::Module(_) => panic!("unexpected path resolution"),
452461
}
453462
}
@@ -456,10 +465,6 @@ impl<'a> ResolverExpand for Resolver<'a> {
456465
return Err(Indeterminate);
457466
}
458467

459-
self.session
460-
.struct_span_err(span, "not sure whether the path is accessible or not")
461-
.span_note(span, "`cfg_accessible` is not fully implemented")
462-
.emit();
463468
Ok(false)
464469
}
465470

src/test/ui/conditional-compilation/cfg_accessible.rs

+25-13
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,35 @@ mod m {
55
struct ExistingPrivate;
66
}
77

8+
trait Trait {
9+
type Assoc;
10+
}
11+
12+
enum Enum {
13+
Existing,
14+
}
15+
16+
#[cfg_accessible(Enum)]
17+
struct ExistingResolved;
18+
19+
#[cfg_accessible(Enum::Existing)]
20+
struct ExistingResolvedVariant;
21+
822
#[cfg_accessible(m::ExistingPublic)]
923
struct ExistingPublic;
1024

11-
// FIXME: Not implemented yet.
12-
#[cfg_accessible(m::ExistingPrivate)] //~ ERROR not sure whether the path is accessible or not
25+
#[cfg_accessible(m::ExistingPrivate)]
1326
struct ExistingPrivate;
1427

15-
// FIXME: Not implemented yet.
16-
#[cfg_accessible(m::NonExistent)] //~ ERROR not sure whether the path is accessible or not
17-
struct ExistingPrivate;
28+
#[cfg_accessible(m::NonExistent)]
29+
struct NonExistingPrivate;
1830

1931
#[cfg_accessible(n::AccessibleExpanded)] // OK, `cfg_accessible` can wait and retry.
2032
struct AccessibleExpanded;
2133

34+
#[cfg_accessible(Trait::Assoc)]
35+
struct AccessibleTraitAssoc;
36+
2237
macro_rules! generate_accessible_expanded {
2338
() => {
2439
mod n {
@@ -29,15 +44,12 @@ macro_rules! generate_accessible_expanded {
2944

3045
generate_accessible_expanded!();
3146

32-
struct S {
33-
field: u8,
34-
}
35-
36-
// FIXME: Not implemented yet.
37-
#[cfg_accessible(S::field)] //~ ERROR not sure whether the path is accessible or not
38-
struct Field;
39-
4047
fn main() {
4148
ExistingPublic;
4249
AccessibleExpanded;
50+
AccessibleTraitAssoc;
51+
52+
ExistingPrivate; //~ ERROR cannot find
53+
NonExistingPrivate; //~ ERROR cannot find
54+
NonExistingTraitAlias; //~ ERROR cannot find
4355
}
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,27 @@
1-
error: not sure whether the path is accessible or not
2-
--> $DIR/cfg_accessible.rs:12:18
1+
error[E0425]: cannot find value `ExistingPrivate` in this scope
2+
--> $DIR/cfg_accessible.rs:52:5
33
|
4-
LL | #[cfg_accessible(m::ExistingPrivate)]
5-
| ^^^^^^^^^^^^^^^^^^
4+
LL | ExistingPrivate;
5+
| ^^^^^^^^^^^^^^^ not found in this scope
66
|
7-
note: `cfg_accessible` is not fully implemented
8-
--> $DIR/cfg_accessible.rs:12:18
7+
note: unit struct `m::ExistingPrivate` exists but is inaccessible
8+
--> $DIR/cfg_accessible.rs:5:5
99
|
10-
LL | #[cfg_accessible(m::ExistingPrivate)]
11-
| ^^^^^^^^^^^^^^^^^^
10+
LL | struct ExistingPrivate;
11+
| ^^^^^^^^^^^^^^^^^^^^^^^ not accessible
1212

13-
error: not sure whether the path is accessible or not
14-
--> $DIR/cfg_accessible.rs:16:18
13+
error[E0425]: cannot find value `NonExistingPrivate` in this scope
14+
--> $DIR/cfg_accessible.rs:53:5
1515
|
16-
LL | #[cfg_accessible(m::NonExistent)]
17-
| ^^^^^^^^^^^^^^
18-
|
19-
note: `cfg_accessible` is not fully implemented
20-
--> $DIR/cfg_accessible.rs:16:18
21-
|
22-
LL | #[cfg_accessible(m::NonExistent)]
23-
| ^^^^^^^^^^^^^^
16+
LL | NonExistingPrivate;
17+
| ^^^^^^^^^^^^^^^^^^ not found in this scope
2418

25-
error: not sure whether the path is accessible or not
26-
--> $DIR/cfg_accessible.rs:37:18
27-
|
28-
LL | #[cfg_accessible(S::field)]
29-
| ^^^^^^^^
30-
|
31-
note: `cfg_accessible` is not fully implemented
32-
--> $DIR/cfg_accessible.rs:37:18
19+
error[E0425]: cannot find value `NonExistingTraitAlias` in this scope
20+
--> $DIR/cfg_accessible.rs:54:5
3321
|
34-
LL | #[cfg_accessible(S::field)]
35-
| ^^^^^^^^
22+
LL | NonExistingTraitAlias;
23+
| ^^^^^^^^^^^^^^^^^^^^^ not found in this scope
3624

3725
error: aborting due to 3 previous errors
3826

27+
For more information about this error, try `rustc --explain E0425`.

0 commit comments

Comments
 (0)