提交 16337464 编写于 作者: U Urgau

Handle more cases in cfg_accessible

上级 bef2b7cd
...@@ -443,11 +443,20 @@ fn cfg_accessible( ...@@ -443,11 +443,20 @@ fn cfg_accessible(
PathResult::NonModule(partial_res) if partial_res.unresolved_segments() == 0 => { PathResult::NonModule(partial_res) if partial_res.unresolved_segments() == 0 => {
return Ok(true); return Ok(true);
} }
PathResult::NonModule(..) => {
self.session
.struct_span_err(span, "not sure whether the path is accessible or not")
.note("the type may have associated items, but we are currently not checking them")
.emit();
// If we get a partially resolved NonModule in one namespace, we should get the
// same result in any other namespaces, so we can return early.
return Ok(false);
}
PathResult::Indeterminate => indeterminate = true, PathResult::Indeterminate => indeterminate = true,
// FIXME: `resolve_path` is not ready to report partially resolved paths // We can only be sure that a path doesn't exist after having tested all the
// correctly, so we just report an error if the path was reported as unresolved. // posibilities, only at that time we can return false.
// This needs to be fixed for `cfg_accessible` to be useful. PathResult::Failed { .. } => {}
PathResult::NonModule(..) | PathResult::Failed { .. } => {}
PathResult::Module(_) => panic!("unexpected path resolution"), PathResult::Module(_) => panic!("unexpected path resolution"),
} }
} }
...@@ -456,10 +465,6 @@ fn cfg_accessible( ...@@ -456,10 +465,6 @@ fn cfg_accessible(
return Err(Indeterminate); return Err(Indeterminate);
} }
self.session
.struct_span_err(span, "not sure whether the path is accessible or not")
.span_note(span, "`cfg_accessible` is not fully implemented")
.emit();
Ok(false) Ok(false)
} }
......
...@@ -5,20 +5,35 @@ mod m { ...@@ -5,20 +5,35 @@ mod m {
struct ExistingPrivate; struct ExistingPrivate;
} }
trait Trait {
type Assoc;
}
enum Enum {
Existing,
}
#[cfg_accessible(Enum)]
struct ExistingResolved;
#[cfg_accessible(Enum::Existing)]
struct ExistingResolvedVariant;
#[cfg_accessible(m::ExistingPublic)] #[cfg_accessible(m::ExistingPublic)]
struct ExistingPublic; struct ExistingPublic;
// FIXME: Not implemented yet. #[cfg_accessible(m::ExistingPrivate)]
#[cfg_accessible(m::ExistingPrivate)] //~ ERROR not sure whether the path is accessible or not
struct ExistingPrivate; struct ExistingPrivate;
// FIXME: Not implemented yet. #[cfg_accessible(m::NonExistent)]
#[cfg_accessible(m::NonExistent)] //~ ERROR not sure whether the path is accessible or not struct NonExistingPrivate;
struct ExistingPrivate;
#[cfg_accessible(n::AccessibleExpanded)] // OK, `cfg_accessible` can wait and retry. #[cfg_accessible(n::AccessibleExpanded)] // OK, `cfg_accessible` can wait and retry.
struct AccessibleExpanded; struct AccessibleExpanded;
#[cfg_accessible(Trait::Assoc)]
struct AccessibleTraitAssoc;
macro_rules! generate_accessible_expanded { macro_rules! generate_accessible_expanded {
() => { () => {
mod n { mod n {
...@@ -29,15 +44,12 @@ mod n { ...@@ -29,15 +44,12 @@ mod n {
generate_accessible_expanded!(); generate_accessible_expanded!();
struct S {
field: u8,
}
// FIXME: Not implemented yet.
#[cfg_accessible(S::field)] //~ ERROR not sure whether the path is accessible or not
struct Field;
fn main() { fn main() {
ExistingPublic; ExistingPublic;
AccessibleExpanded; AccessibleExpanded;
AccessibleTraitAssoc;
ExistingPrivate; //~ ERROR cannot find
NonExistingPrivate; //~ ERROR cannot find
NonExistingTraitAlias; //~ ERROR cannot find
} }
error: not sure whether the path is accessible or not error[E0425]: cannot find value `ExistingPrivate` in this scope
--> $DIR/cfg_accessible.rs:12:18 --> $DIR/cfg_accessible.rs:52:5
| |
LL | #[cfg_accessible(m::ExistingPrivate)] LL | ExistingPrivate;
| ^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^ not found in this scope
| |
note: `cfg_accessible` is not fully implemented note: unit struct `m::ExistingPrivate` exists but is inaccessible
--> $DIR/cfg_accessible.rs:12:18 --> $DIR/cfg_accessible.rs:5:5
| |
LL | #[cfg_accessible(m::ExistingPrivate)] LL | struct ExistingPrivate;
| ^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^ not accessible
error: not sure whether the path is accessible or not error[E0425]: cannot find value `NonExistingPrivate` in this scope
--> $DIR/cfg_accessible.rs:16:18 --> $DIR/cfg_accessible.rs:53:5
| |
LL | #[cfg_accessible(m::NonExistent)] LL | NonExistingPrivate;
| ^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^ not found in this scope
|
note: `cfg_accessible` is not fully implemented
--> $DIR/cfg_accessible.rs:16:18
|
LL | #[cfg_accessible(m::NonExistent)]
| ^^^^^^^^^^^^^^
error: not sure whether the path is accessible or not error[E0425]: cannot find value `NonExistingTraitAlias` in this scope
--> $DIR/cfg_accessible.rs:37:18 --> $DIR/cfg_accessible.rs:54:5
|
LL | #[cfg_accessible(S::field)]
| ^^^^^^^^
|
note: `cfg_accessible` is not fully implemented
--> $DIR/cfg_accessible.rs:37:18
| |
LL | #[cfg_accessible(S::field)] LL | NonExistingTraitAlias;
| ^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^ not found in this scope
error: aborting due to 3 previous errors error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0425`.
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册