Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle more cases in cfg_accessible #97391

Merged
merged 5 commits into from
Jun 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions compiler/rustc_resolve/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,11 +443,22 @@ impl<'a> ResolverExpand for Resolver<'a> {
PathResult::NonModule(partial_res) if partial_res.unresolved_segments() == 0 => {
return Ok(true);
}
PathResult::NonModule(..) |
// HACK(Urgau): This shouldn't be necessary
PathResult::Failed { is_error_from_last_segment: false, .. } => {
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,
// FIXME: `resolve_path` is not ready to report partially resolved paths
// correctly, so we just report an error if the path was reported as unresolved.
// This needs to be fixed for `cfg_accessible` to be useful.
PathResult::NonModule(..) | PathResult::Failed { .. } => {}
// We can only be sure that a path doesn't exist after having tested all the
// posibilities, only at that time we can return false.
PathResult::Failed { .. } => {}
PathResult::Module(_) => panic!("unexpected path resolution"),
}
}
Expand All @@ -456,10 +467,6 @@ impl<'a> ResolverExpand for Resolver<'a> {
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)
}

Expand Down
18 changes: 18 additions & 0 deletions src/test/ui/conditional-compilation/cfg_accessible-bugs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// This test is a collection of test that should pass.
//
// check-fail

#![feature(cfg_accessible)]
#![feature(trait_alias)]

trait TraitAlias = std::fmt::Debug + Send;

// FIXME: Currently shows "cannot determine" but should be `false`
#[cfg_accessible(unresolved)] //~ ERROR cannot determine
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a bug, if the compiler says "cannot determine" (rather than "not sure") then it's legitimately stuck, and it's unlikely we can do anything here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem here is that we return an error instead of false (ie it is unresolvable).
The error message is irrelevant to the bug.

const C: bool = true;

// FIXME: Currently shows "not sure" but should be `false`
#[cfg_accessible(TraitAlias::unresolved)] //~ ERROR not sure whether the path is accessible or not
const D: bool = true;

fn main() {}
16 changes: 16 additions & 0 deletions src/test/ui/conditional-compilation/cfg_accessible-bugs.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
error: not sure whether the path is accessible or not
--> $DIR/cfg_accessible-bugs.rs:15:18
|
LL | #[cfg_accessible(TraitAlias::unresolved)]
| ^^^^^^^^^^^^^^^^^^^^^^
|
= note: the type may have associated items, but we are currently not checking them

error: cannot determine whether the path is accessible or not
--> $DIR/cfg_accessible-bugs.rs:11:1
|
LL | #[cfg_accessible(unresolved)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors

Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
error: not sure whether the path is accessible or not
--> $DIR/cfg_accessible-not_sure.rs:14:18
|
LL | #[cfg_accessible(Struct::existing)]
| ^^^^^^^^^^^^^^^^
|
= note: the type may have associated items, but we are currently not checking them

error: not sure whether the path is accessible or not
--> $DIR/cfg_accessible-not_sure.rs:16:18
|
LL | #[cfg_accessible(Struct::unresolved)]
| ^^^^^^^^^^^^^^^^^^
|
= note: the type may have associated items, but we are currently not checking them

error: not sure whether the path is accessible or not
--> $DIR/cfg_accessible-not_sure.rs:25:18
|
LL | #[cfg_accessible(Union::existing)]
| ^^^^^^^^^^^^^^^
|
= note: the type may have associated items, but we are currently not checking them

error: not sure whether the path is accessible or not
--> $DIR/cfg_accessible-not_sure.rs:27:18
|
LL | #[cfg_accessible(Union::unresolved)]
| ^^^^^^^^^^^^^^^^^
|
= note: the type may have associated items, but we are currently not checking them

error: not sure whether the path is accessible or not
--> $DIR/cfg_accessible-not_sure.rs:36:18
|
LL | #[cfg_accessible(Enum::Existing::existing)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the type may have associated items, but we are currently not checking them

error: not sure whether the path is accessible or not
--> $DIR/cfg_accessible-not_sure.rs:38:18
|
LL | #[cfg_accessible(Enum::Existing::unresolved)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the type may have associated items, but we are currently not checking them

error: not sure whether the path is accessible or not
--> $DIR/cfg_accessible-not_sure.rs:40:18
|
LL | #[cfg_accessible(Enum::unresolved)]
| ^^^^^^^^^^^^^^^^
|
= note: the type may have associated items, but we are currently not checking them

error: not sure whether the path is accessible or not
--> $DIR/cfg_accessible-not_sure.rs:50:18
|
LL | #[cfg_accessible(Trait::existing)]
| ^^^^^^^^^^^^^^^
|
= note: the type may have associated items, but we are currently not checking them

error: not sure whether the path is accessible or not
--> $DIR/cfg_accessible-not_sure.rs:52:18
|
LL | #[cfg_accessible(Trait::unresolved)]
| ^^^^^^^^^^^^^^^^^
|
= note: the type may have associated items, but we are currently not checking them

error: not sure whether the path is accessible or not
--> $DIR/cfg_accessible-not_sure.rs:59:18
|
LL | #[cfg_accessible(TypeAlias::existing)]
| ^^^^^^^^^^^^^^^^^^^
|
= note: the type may have associated items, but we are currently not checking them

error: not sure whether the path is accessible or not
--> $DIR/cfg_accessible-not_sure.rs:61:18
|
LL | #[cfg_accessible(TypeAlias::unresolved)]
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: the type may have associated items, but we are currently not checking them

error: not sure whether the path is accessible or not
--> $DIR/cfg_accessible-not_sure.rs:70:18
|
LL | #[cfg_accessible(ForeignType::unresolved)]
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the type may have associated items, but we are currently not checking them

error: not sure whether the path is accessible or not
--> $DIR/cfg_accessible-not_sure.rs:79:18
|
LL | #[cfg_accessible(AssocType::AssocType::unresolved)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the type may have associated items, but we are currently not checking them

error: not sure whether the path is accessible or not
--> $DIR/cfg_accessible-not_sure.rs:84:18
|
LL | #[cfg_accessible(u8::unresolved)]
| ^^^^^^^^^^^^^^
|
= note: the type may have associated items, but we are currently not checking them

error: not sure whether the path is accessible or not
--> $DIR/cfg_accessible-not_sure.rs:86:18
|
LL | #[cfg_accessible(u8::is_ascii)]
| ^^^^^^^^^^^^
|
= note: the type may have associated items, but we are currently not checking them

error: aborting due to 15 previous errors

Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
error: not sure whether the path is accessible or not
--> $DIR/cfg_accessible-not_sure.rs:14:18
|
LL | #[cfg_accessible(Struct::existing)]
| ^^^^^^^^^^^^^^^^
|
= note: the type may have associated items, but we are currently not checking them

error: not sure whether the path is accessible or not
--> $DIR/cfg_accessible-not_sure.rs:16:18
|
LL | #[cfg_accessible(Struct::unresolved)]
| ^^^^^^^^^^^^^^^^^^
|
= note: the type may have associated items, but we are currently not checking them

error: not sure whether the path is accessible or not
--> $DIR/cfg_accessible-not_sure.rs:25:18
|
LL | #[cfg_accessible(Union::existing)]
| ^^^^^^^^^^^^^^^
|
= note: the type may have associated items, but we are currently not checking them

error: not sure whether the path is accessible or not
--> $DIR/cfg_accessible-not_sure.rs:27:18
|
LL | #[cfg_accessible(Union::unresolved)]
| ^^^^^^^^^^^^^^^^^
|
= note: the type may have associated items, but we are currently not checking them

error: not sure whether the path is accessible or not
--> $DIR/cfg_accessible-not_sure.rs:36:18
|
LL | #[cfg_accessible(Enum::Existing::existing)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the type may have associated items, but we are currently not checking them

error: not sure whether the path is accessible or not
--> $DIR/cfg_accessible-not_sure.rs:38:18
|
LL | #[cfg_accessible(Enum::Existing::unresolved)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the type may have associated items, but we are currently not checking them

error: not sure whether the path is accessible or not
--> $DIR/cfg_accessible-not_sure.rs:40:18
|
LL | #[cfg_accessible(Enum::unresolved)]
| ^^^^^^^^^^^^^^^^
|
= note: the type may have associated items, but we are currently not checking them

error: not sure whether the path is accessible or not
--> $DIR/cfg_accessible-not_sure.rs:50:18
|
LL | #[cfg_accessible(Trait::existing)]
| ^^^^^^^^^^^^^^^
|
= note: the type may have associated items, but we are currently not checking them

error: not sure whether the path is accessible or not
--> $DIR/cfg_accessible-not_sure.rs:52:18
|
LL | #[cfg_accessible(Trait::unresolved)]
| ^^^^^^^^^^^^^^^^^
|
= note: the type may have associated items, but we are currently not checking them

error: not sure whether the path is accessible or not
--> $DIR/cfg_accessible-not_sure.rs:59:18
|
LL | #[cfg_accessible(TypeAlias::existing)]
| ^^^^^^^^^^^^^^^^^^^
|
= note: the type may have associated items, but we are currently not checking them

error: not sure whether the path is accessible or not
--> $DIR/cfg_accessible-not_sure.rs:61:18
|
LL | #[cfg_accessible(TypeAlias::unresolved)]
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: the type may have associated items, but we are currently not checking them

error: not sure whether the path is accessible or not
--> $DIR/cfg_accessible-not_sure.rs:70:18
|
LL | #[cfg_accessible(ForeignType::unresolved)]
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the type may have associated items, but we are currently not checking them

error: not sure whether the path is accessible or not
--> $DIR/cfg_accessible-not_sure.rs:79:18
|
LL | #[cfg_accessible(AssocType::AssocType::unresolved)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the type may have associated items, but we are currently not checking them

error: not sure whether the path is accessible or not
--> $DIR/cfg_accessible-not_sure.rs:84:18
|
LL | #[cfg_accessible(u8::unresolved)]
| ^^^^^^^^^^^^^^
|
= note: the type may have associated items, but we are currently not checking them

error: not sure whether the path is accessible or not
--> $DIR/cfg_accessible-not_sure.rs:86:18
|
LL | #[cfg_accessible(u8::is_ascii)]
| ^^^^^^^^^^^^
|
= note: the type may have associated items, but we are currently not checking them

error: aborting due to 15 previous errors

Loading