summaryrefslogtreecommitdiffstats
path: root/src/test/ui/suggestions/auxiliary
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/suggestions/auxiliary
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/suggestions/auxiliary')
-rw-r--r--src/test/ui/suggestions/auxiliary/foo.rs3
-rw-r--r--src/test/ui/suggestions/auxiliary/issue-61963-1.rs40
-rw-r--r--src/test/ui/suggestions/auxiliary/issue-61963.rs41
-rw-r--r--src/test/ui/suggestions/auxiliary/issue-81839.rs9
-rw-r--r--src/test/ui/suggestions/auxiliary/meow.rs11
-rw-r--r--src/test/ui/suggestions/auxiliary/not-object-safe.rs6
-rw-r--r--src/test/ui/suggestions/auxiliary/proc-macro-type-error.rs18
7 files changed, 128 insertions, 0 deletions
diff --git a/src/test/ui/suggestions/auxiliary/foo.rs b/src/test/ui/suggestions/auxiliary/foo.rs
new file mode 100644
index 000000000..e90bbef6d
--- /dev/null
+++ b/src/test/ui/suggestions/auxiliary/foo.rs
@@ -0,0 +1,3 @@
+//! Contains a struct with almost the same name as itself, to trigger Levenshtein suggestions.
+
+pub struct Foo;
diff --git a/src/test/ui/suggestions/auxiliary/issue-61963-1.rs b/src/test/ui/suggestions/auxiliary/issue-61963-1.rs
new file mode 100644
index 000000000..6c2df7e84
--- /dev/null
+++ b/src/test/ui/suggestions/auxiliary/issue-61963-1.rs
@@ -0,0 +1,40 @@
+// force-host
+// no-prefer-dynamic
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+
+use proc_macro::{Group, TokenStream, TokenTree};
+
+// This macro exists as part of a reproduction of #61963 but without using quote/syn/proc_macro2.
+
+#[proc_macro_derive(DomObject)]
+pub fn expand_token_stream(input: TokenStream) -> TokenStream {
+ // Construct a dummy span - `#0 bytes(0..0)` - which is present in the input because
+ // of the specially crafted generated tokens in the `attribute-crate` proc-macro.
+ let dummy_span = input.clone().into_iter().nth(0).unwrap().span();
+
+ // Define what the macro would output if constructed properly from the source using syn/quote.
+ let output: TokenStream = "impl Bar for ((), Qux<Qux<Baz> >) { }
+ impl Bar for ((), Box<Bar>) { }".parse().unwrap();
+
+ let mut tokens: Vec<_> = output.into_iter().collect();
+ // Adjust token spans to match the original crate (which would use `quote`). Some of the
+ // generated tokens point to the dummy span.
+ for token in tokens.iter_mut() {
+ if let TokenTree::Group(group) = token {
+ let mut tokens: Vec<_> = group.stream().into_iter().collect();
+ for token in tokens.iter_mut().skip(2) {
+ token.set_span(dummy_span);
+ }
+
+ let mut stream = TokenStream::new();
+ stream.extend(tokens);
+ *group = Group::new(group.delimiter(), stream);
+ }
+ }
+
+ let mut output = TokenStream::new();
+ output.extend(tokens);
+ output
+}
diff --git a/src/test/ui/suggestions/auxiliary/issue-61963.rs b/src/test/ui/suggestions/auxiliary/issue-61963.rs
new file mode 100644
index 000000000..e86f1610a
--- /dev/null
+++ b/src/test/ui/suggestions/auxiliary/issue-61963.rs
@@ -0,0 +1,41 @@
+// force-host
+// no-prefer-dynamic
+#![crate_type = "proc-macro"]
+
+extern crate proc_macro;
+
+use proc_macro::{Group, Spacing, Punct, TokenTree, TokenStream};
+
+// This macro exists as part of a reproduction of #61963 but without using quote/syn/proc_macro2.
+
+#[proc_macro_attribute]
+pub fn dom_struct(_: TokenStream, input: TokenStream) -> TokenStream {
+ // Construct the expected output tokens - the input but with a `#[derive(DomObject)]` applied.
+ let attributes: TokenStream =
+ "#[derive(DomObject)]".to_string().parse().unwrap();
+ let output: TokenStream = attributes.into_iter()
+ .chain(input.into_iter()).collect();
+
+ let mut tokens: Vec<_> = output.into_iter().collect();
+ // Adjust the spacing of `>` tokens to match what `quote` would produce.
+ for token in tokens.iter_mut() {
+ if let TokenTree::Group(group) = token {
+ let mut tokens: Vec<_> = group.stream().into_iter().collect();
+ for token in tokens.iter_mut() {
+ if let TokenTree::Punct(p) = token {
+ if p.as_char() == '>' {
+ *p = Punct::new('>', Spacing::Alone);
+ }
+ }
+ }
+
+ let mut stream = TokenStream::new();
+ stream.extend(tokens);
+ *group = Group::new(group.delimiter(), stream);
+ }
+ }
+
+ let mut output = TokenStream::new();
+ output.extend(tokens);
+ output
+}
diff --git a/src/test/ui/suggestions/auxiliary/issue-81839.rs b/src/test/ui/suggestions/auxiliary/issue-81839.rs
new file mode 100644
index 000000000..5683c45ad
--- /dev/null
+++ b/src/test/ui/suggestions/auxiliary/issue-81839.rs
@@ -0,0 +1,9 @@
+// edition:2018
+
+pub struct Test {}
+
+impl Test {
+ pub async fn answer_str(&self, _s: &str) -> Test {
+ Test {}
+ }
+}
diff --git a/src/test/ui/suggestions/auxiliary/meow.rs b/src/test/ui/suggestions/auxiliary/meow.rs
new file mode 100644
index 000000000..115df70a6
--- /dev/null
+++ b/src/test/ui/suggestions/auxiliary/meow.rs
@@ -0,0 +1,11 @@
+pub trait Meow {
+ fn meow(&self) {}
+}
+
+pub struct GlobalMeow;
+
+impl Meow for GlobalMeow {}
+
+pub(crate) struct PrivateMeow;
+
+impl Meow for PrivateMeow {}
diff --git a/src/test/ui/suggestions/auxiliary/not-object-safe.rs b/src/test/ui/suggestions/auxiliary/not-object-safe.rs
new file mode 100644
index 000000000..7c9829b82
--- /dev/null
+++ b/src/test/ui/suggestions/auxiliary/not-object-safe.rs
@@ -0,0 +1,6 @@
+use std::sync::Arc;
+
+pub trait A {
+ fn f();
+ fn f2(self: &Arc<Self>);
+}
diff --git a/src/test/ui/suggestions/auxiliary/proc-macro-type-error.rs b/src/test/ui/suggestions/auxiliary/proc-macro-type-error.rs
new file mode 100644
index 000000000..d71747f96
--- /dev/null
+++ b/src/test/ui/suggestions/auxiliary/proc-macro-type-error.rs
@@ -0,0 +1,18 @@
+// force-host
+// no-prefer-dynamic
+#![crate_type = "proc-macro"]
+#![feature(proc_macro_quote)]
+
+extern crate proc_macro;
+
+use proc_macro::{quote, TokenStream};
+
+#[proc_macro_attribute]
+pub fn hello(_: TokenStream, _: TokenStream) -> TokenStream {
+ quote!(
+ fn f(_: &mut i32) {}
+ fn g() {
+ f(123);
+ }
+ )
+}