summaryrefslogtreecommitdiffstats
path: root/src/test/ui/imports/import-crate-with-invalid-spans
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/imports/import-crate-with-invalid-spans
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/imports/import-crate-with-invalid-spans')
-rw-r--r--src/test/ui/imports/import-crate-with-invalid-spans/auxiliary/crate_with_invalid_spans.rs20
-rw-r--r--src/test/ui/imports/import-crate-with-invalid-spans/auxiliary/crate_with_invalid_spans_macros.rs7
-rw-r--r--src/test/ui/imports/import-crate-with-invalid-spans/main.rs13
3 files changed, 40 insertions, 0 deletions
diff --git a/src/test/ui/imports/import-crate-with-invalid-spans/auxiliary/crate_with_invalid_spans.rs b/src/test/ui/imports/import-crate-with-invalid-spans/auxiliary/crate_with_invalid_spans.rs
new file mode 100644
index 000000000..b76c1680b
--- /dev/null
+++ b/src/test/ui/imports/import-crate-with-invalid-spans/auxiliary/crate_with_invalid_spans.rs
@@ -0,0 +1,20 @@
+#![crate_type = "rlib"]
+// no-prefer-dynamic
+
+// compile-flags: -g
+
+#[macro_use]
+mod crate_with_invalid_spans_macros;
+
+pub fn exported_generic<T>(x: T, y: u32) -> (T, u32) {
+ // Using the add1 macro will produce an invalid span, because the `y` passed
+ // to the macro will have a span from this file, but the rest of the code
+ // generated from the macro will have spans from the macro-defining file.
+ // The AST node for the (1 + y) expression generated by the macro will then
+ // take it's `lo` span bound from the `1` literal in the macro-defining file
+ // and it's `hi` bound from `y` in this file, which should be lower than the
+ // `lo` and even lower than the lower bound of the SourceFile it is supposedly
+ // contained in because the SourceFile for this file was allocated earlier than
+ // the SourceFile of the macro-defining file.
+ return (x, add1!(y));
+}
diff --git a/src/test/ui/imports/import-crate-with-invalid-spans/auxiliary/crate_with_invalid_spans_macros.rs b/src/test/ui/imports/import-crate-with-invalid-spans/auxiliary/crate_with_invalid_spans_macros.rs
new file mode 100644
index 000000000..63611c242
--- /dev/null
+++ b/src/test/ui/imports/import-crate-with-invalid-spans/auxiliary/crate_with_invalid_spans_macros.rs
@@ -0,0 +1,7 @@
+macro_rules! add1 {
+ ($e:expr) => ({
+ let a = 1 + $e;
+ let b = $e + 1;
+ a + b - 1
+ })
+}
diff --git a/src/test/ui/imports/import-crate-with-invalid-spans/main.rs b/src/test/ui/imports/import-crate-with-invalid-spans/main.rs
new file mode 100644
index 000000000..64a4deca8
--- /dev/null
+++ b/src/test/ui/imports/import-crate-with-invalid-spans/main.rs
@@ -0,0 +1,13 @@
+// run-pass
+// aux-build:crate_with_invalid_spans.rs
+
+// pretty-expanded FIXME #23616
+
+extern crate crate_with_invalid_spans;
+
+fn main() {
+ // The AST of `exported_generic` stored in crate_with_invalid_spans's
+ // metadata should contain an invalid span where span.lo() > span.hi().
+ // Let's make sure the compiler doesn't crash when encountering this.
+ let _ = crate_with_invalid_spans::exported_generic(32u32, 7u32);
+}