From: Pierre-Emmanuel Patry <[email protected]>
An item from a parent module should be brought into scope with a Use
declaration and not implicitly. This means we should not continue
iterating over the upper ribs when meeting a module rib.
This fix breaks the compilation of core since the items from the
uppermost ribs are brought within scope with the prelude mechanism which
is not complete yet.
gcc/rust/ChangeLog:
* resolve/rust-forever-stack.hxx: Prevent iteration on parent ribs.
gcc/testsuite/ChangeLog:
* rust/compile/name_resolution26.rs: New test.
* rust/compile/derive-default1.rs: Add no_core attribute and fix the
testcase with a proper name usage which does not break name resolution
rules.
* rust/compile/derive-eq-invalid.rs: Likewise.
* rust/compile/derive-hash1.rs: Likewise.
* rust/compile/issue-2905-2.rs: Likewise.
* rust/compile/issue-3402-1.rs: Likewise.
* rust/compile/issue-3403.rs: Likewise.
* rust/compile/name_resolution18.rs: Likewise.
* rust/compile/privacy2.rs: Likewise.
* rust/execute/torture/derive-default1.rs: Likewise.
* rust/core/core.exp: Revert last compilation step to attribute check.
Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.
Commit on github:
https://github.com/Rust-GCC/gccrs/commit/70793add441f09c6c518c081846f4ccb32945f3a
The commit has been mentioned in the following pull-request(s):
- https://github.com/Rust-GCC/gccrs/pull/4401
gcc/rust/resolve/rust-forever-stack.hxx | 19 ++++++++++++-------
gcc/testsuite/rust/compile/derive-default1.rs | 6 +++++-
.../rust/compile/derive-eq-invalid.rs | 4 ++++
gcc/testsuite/rust/compile/derive-hash1.rs | 4 ++++
gcc/testsuite/rust/compile/issue-2905-2.rs | 4 ++++
gcc/testsuite/rust/compile/issue-3402-1.rs | 6 +++++-
gcc/testsuite/rust/compile/issue-3403.rs | 6 +++++-
.../rust/compile/name_resolution18.rs | 6 +++++-
.../rust/compile/name_resolution26.rs | 13 +++++++++++++
gcc/testsuite/rust/compile/privacy2.rs | 1 +
gcc/testsuite/rust/core/core.exp | 2 +-
.../rust/execute/torture/derive-default1.rs | 2 ++
12 files changed, 61 insertions(+), 12 deletions(-)
create mode 100644 gcc/testsuite/rust/compile/name_resolution26.rs
diff --git a/gcc/rust/resolve/rust-forever-stack.hxx
b/gcc/rust/resolve/rust-forever-stack.hxx
index 6cecece30..0f92a7f33 100644
--- a/gcc/rust/resolve/rust-forever-stack.hxx
+++ b/gcc/rust/resolve/rust-forever-stack.hxx
@@ -311,20 +311,25 @@ ForeverStack<N>::get (Node &start, const Identifier &name)
auto candidate = current.rib.get (name.as_string ());
- return candidate.map_or (
- [&resolved_definition] (Rib::Definition found) {
- if (found.is_variant ())
+ if (candidate)
+ {
+ if (candidate->is_variant ())
return KeepGoing::Yes;
// for most namespaces, we do not need to care about various ribs -
// they are available from all contexts if defined in the current
// scope, or an outermore one. so if we do have a candidate, we can
// return it directly and stop iterating
- resolved_definition = found;
+ resolved_definition = *candidate;
return KeepGoing::No;
- },
- // if there was no candidate, we keep iterating
- KeepGoing::Yes);
+ }
+ else
+ {
+ if (current.rib.kind == Rib::Kind::Module)
+ return KeepGoing::No;
+ else
+ return KeepGoing::Yes;
+ }
});
return resolved_definition;
diff --git a/gcc/testsuite/rust/compile/derive-default1.rs
b/gcc/testsuite/rust/compile/derive-default1.rs
index ad31d5a4c..09aed4896 100644
--- a/gcc/testsuite/rust/compile/derive-default1.rs
+++ b/gcc/testsuite/rust/compile/derive-default1.rs
@@ -1,13 +1,17 @@
+#![feature(no_core)]
#![feature(lang_items)]
+#![no_core]
#[derive(Default)]
struct Foo { _a: i32, _b: i64, _c: u8 }
#[lang = "sized"]
-trait Sized {}
+pub trait Sized {}
mod core {
mod default {
+ use crate::Sized;
+
trait Default: Sized {
fn default() -> Self;
}
diff --git a/gcc/testsuite/rust/compile/derive-eq-invalid.rs
b/gcc/testsuite/rust/compile/derive-eq-invalid.rs
index 47fac7819..23d8af573 100644
--- a/gcc/testsuite/rust/compile/derive-eq-invalid.rs
+++ b/gcc/testsuite/rust/compile/derive-eq-invalid.rs
@@ -1,7 +1,11 @@
+#![feature(no_core)]
#![feature(lang_items)]
+#![no_core]
mod core {
mod cmp {
+ use crate::Sized;
+
#[lang = "eq"]
pub trait PartialEq<Rhs: ?Sized = Self> {
fn eq(&self, other: &Rhs) -> bool;
diff --git a/gcc/testsuite/rust/compile/derive-hash1.rs
b/gcc/testsuite/rust/compile/derive-hash1.rs
index cdcc9b1af..618fa9a07 100644
--- a/gcc/testsuite/rust/compile/derive-hash1.rs
+++ b/gcc/testsuite/rust/compile/derive-hash1.rs
@@ -1,4 +1,6 @@
+#![feature(no_core)]
#![feature(intrinsics, lang_items)]
+#![no_core]
#[lang = "sized"]
trait Sized {}
@@ -17,6 +19,8 @@ pub mod core {
}
pub mod hash {
+ use crate::Sized;
+
pub trait Hasher {}
pub trait Hash {
diff --git a/gcc/testsuite/rust/compile/issue-2905-2.rs
b/gcc/testsuite/rust/compile/issue-2905-2.rs
index 1c9516df9..dccb6a8c6 100644
--- a/gcc/testsuite/rust/compile/issue-2905-2.rs
+++ b/gcc/testsuite/rust/compile/issue-2905-2.rs
@@ -1,6 +1,8 @@
// { dg-options "-w" }
+#![feature(no_core)]
#![feature(intrinsics)]
#![feature(lang_items)]
+#![no_core]
#[lang = "sized"]
trait Sized {}
@@ -19,6 +21,8 @@ pub mod core {
pub mod slice {
use crate::core::marker::PhantomData;
use crate::core::option::Option;
+ use crate::offset;
+ use crate::transmute;
impl<T> crate::core::iter::IntoIterator for &[T] {
type Item = &T;
diff --git a/gcc/testsuite/rust/compile/issue-3402-1.rs
b/gcc/testsuite/rust/compile/issue-3402-1.rs
index cd13b748c..9d680b1ce 100644
--- a/gcc/testsuite/rust/compile/issue-3402-1.rs
+++ b/gcc/testsuite/rust/compile/issue-3402-1.rs
@@ -1,4 +1,6 @@
+#![feature(no_core)]
#![feature(lang_items)]
+#![no_core]
pub struct Foo {
a: i32,
@@ -7,10 +9,12 @@ pub struct Foo {
pub struct Bar(i32);
#[lang = "sized"]
-trait Sized {}
+pub trait Sized {}
pub mod core {
pub mod default {
+ use crate::Sized;
+
pub trait Default: Sized {
fn default() -> Self;
}
diff --git a/gcc/testsuite/rust/compile/issue-3403.rs
b/gcc/testsuite/rust/compile/issue-3403.rs
index 6a3f7200a..345844899 100644
--- a/gcc/testsuite/rust/compile/issue-3403.rs
+++ b/gcc/testsuite/rust/compile/issue-3403.rs
@@ -1,4 +1,6 @@
+#![feature(no_core)]
#![feature(lang_items)]
+#![no_core]
pub struct Foo {
a: i32,
@@ -7,10 +9,12 @@ pub struct Foo {
pub struct Bar(i32);
#[lang = "sized"]
-trait Sized {}
+pub trait Sized {}
pub mod core {
pub mod default {
+ use crate::Sized;
+
pub trait Default: Sized {
fn default() -> Self;
}
diff --git a/gcc/testsuite/rust/compile/name_resolution18.rs
b/gcc/testsuite/rust/compile/name_resolution18.rs
index 17a335280..a8adb706a 100644
--- a/gcc/testsuite/rust/compile/name_resolution18.rs
+++ b/gcc/testsuite/rust/compile/name_resolution18.rs
@@ -1,3 +1,6 @@
+#![feature(no_core)]
+#![no_core]
+
struct Marker;
struct Foo {
@@ -5,7 +8,8 @@ struct Foo {
}
pub mod foo {
- struct Foo {
+ use crate::Marker;
+ pub struct Foo {
b: Marker,
}
}
diff --git a/gcc/testsuite/rust/compile/name_resolution26.rs
b/gcc/testsuite/rust/compile/name_resolution26.rs
new file mode 100644
index 000000000..34f5afe6a
--- /dev/null
+++ b/gcc/testsuite/rust/compile/name_resolution26.rs
@@ -0,0 +1,13 @@
+#![feature(no_core)]
+#![no_core]
+
+use marker::Sized;
+
+pub mod marker {
+ pub trait Sized {}
+}
+
+pub mod clone {
+ pub trait Clone: Sized {}
+ // { dg-error "could not resolve type path .Sized." "" { target *-*-* }
.-1 }
+}
diff --git a/gcc/testsuite/rust/compile/privacy2.rs
b/gcc/testsuite/rust/compile/privacy2.rs
index 3c0744928..a36f49f2d 100644
--- a/gcc/testsuite/rust/compile/privacy2.rs
+++ b/gcc/testsuite/rust/compile/privacy2.rs
@@ -5,6 +5,7 @@ mod orange {
mod green {
mod blue {
+ use super::super::tangerine;
fn berry() {
tangerine();
}
diff --git a/gcc/testsuite/rust/core/core.exp b/gcc/testsuite/rust/core/core.exp
index b773ada26..8f6ab9237 100644
--- a/gcc/testsuite/rust/core/core.exp
+++ b/gcc/testsuite/rust/core/core.exp
@@ -30,7 +30,7 @@ set saved-dg-do-what-default ${dg-do-what-default}
set dg-do-what-default "compile"
set individual_timeout 600
dg-additional-files [lsort [glob -nocomplain
$srcdir/../../libgrust/rustc-lib/*]]
-dg-runtest $srcdir/../../libgrust/rustc-lib/core/src/lib.rs
"-frust-edition=2018 -frust-crate=core -frust-compile-until=nameresolution -w"
""
+dg-runtest $srcdir/../../libgrust/rustc-lib/core/src/lib.rs
"-frust-edition=2018 -frust-crate=core -frust-compile-until=attributecheck -w"
""
set dg-do-what-default ${saved-dg-do-what-default}
# All done.
diff --git a/gcc/testsuite/rust/execute/torture/derive-default1.rs
b/gcc/testsuite/rust/execute/torture/derive-default1.rs
index 775f5be6e..c439971f7 100644
--- a/gcc/testsuite/rust/execute/torture/derive-default1.rs
+++ b/gcc/testsuite/rust/execute/torture/derive-default1.rs
@@ -10,6 +10,8 @@ trait Sized {}
mod core {
mod default {
+ use crate::Sized;
+
trait Default: Sized {
fn default() -> Self;
}
--
2.52.0