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

Require a #[defines] attribute for type-alias-impl-trait in order for a function to be able to register hidden types. #110010

Closed

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Apr 6, 2023

r? @ghost

alternative to #107809

fixes #107645

TODO:

  • self-review this PR
  • write an explanation
  • write diagnostics
  • add tests for mis-uses of #[defines]
  • implement #[cfg_attr(thing, defines(Foo))] and inner attributes
  • don't allow any item in a crate to define any TAIT in the same crate. Reintroduce some form of the previous "same module or in children" logic. Possibly require #[defines] annotations on child modules and other items that can have nested items?

@rustbot rustbot added A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Apr 6, 2023
@rustbot
Copy link
Collaborator

rustbot commented Apr 6, 2023

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

rustc_error_messages was changed

cc @davidtwco, @compiler-errors, @JohnTitor, @TaKO8Ki

@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-tools failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

---- compile_test stdout ----
diff of stderr:

-error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
+error[E0308]: mismatched types
+  --> $DIR/from_over_into.rs:88:22
    |
    |
-LL | impl Into<StringWrapper> for String {
-   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL | type Opaque = impl Sized;
+...
+...
+LL |     fn into(self) -> Opaque {}
+   |        |
+   |        |
+   |        implicitly returns `()` as its body has no tail or `return` expression
    |
-   = note: `-D clippy::from-over-into` implied by `-D warnings`
-help: replace the `Into` implentation with `From<std::string::String>`
+   = note: expected opaque type `Opaque`
+                found unit type `()`
+note: this item cannot register hidden type without a `#[defines(Opaque)]` attribute
    |
    |
-LL ~ impl From<String> for StringWrapper {
-LL ~     fn from(val: String) -> Self {
-LL ~         StringWrapper(val)
-   |
+LL |     fn into(self) -> Opaque {}
 
 
-error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
-   |
-   |
-LL | impl Into<SelfType> for String {
-   |
-   |
-help: replace the `Into` implentation with `From<std::string::String>`
-   |
-LL ~ impl From<String> for SelfType {
-LL ~     fn from(val: String) -> Self {
-LL ~         SelfType(String::new())
+error: aborting due to previous error
 
 
-error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
-   |
-   |
-LL | impl Into<SelfKeywords> for X {
-   |
-   |
-help: replace the `Into` implentation with `From<X>`
-   |
-LL ~ impl From<X> for SelfKeywords {
-LL ~     fn from(val: X) -> Self {
-LL ~         let _ = X::default();
-LL ~         let _ = X::FOO;
-LL ~         let _: X = val;
-
-
-error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
-   |
-   |
-LL | impl core::convert::Into<bool> for crate::ExplicitPaths {
-   |
-   |
-   = help: `impl From<Local> for Foreign` is allowed by the orphan rules, for more information see
-           https://doc.rust-lang.org/reference/items/implementations.html#trait-implementation-coherence
error: test failed, to rerun pass `--test compile-test`
-help: replace the `Into` implentation with `From<ExplicitPaths>`
-   |
-LL ~ impl core::convert::From<crate::ExplicitPaths> for bool {
-LL ~     fn from(mut val: crate::ExplicitPaths) -> Self {
-LL ~         let in_closure = || val.0;
-LL | 
-LL ~         val.0 = false;
-LL ~         val.0
-
-
-error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
-   |
-   |
-LL |     impl<T> Into<FromOverInto<T>> for Vec<T> {
-   |
-   |
-help: replace the `Into` implentation with `From<std::vec::Vec<T>>`
-   |
-LL ~     impl<T> From<Vec<T>> for FromOverInto<T> {
-LL ~         fn from(val: Vec<T>) -> Self {
-LL ~             FromOverInto(val)
-
-error: aborting due to 5 previous errors
-
+For more information about this error, try `rustc --explain E0308`.
---
diff of fixed:

 // run-rustfix
 
 #![feature(type_alias_impl_trait)]
 #![warn(clippy::from_over_into)]
 
 // this should throw an error
 struct StringWrapper(String);
 
 
-impl From<String> for StringWrapper {
-    fn from(val: String) -> Self {
-        StringWrapper(val)
+impl Into<StringWrapper> for String {
+    fn into(self) -> StringWrapper {
+        StringWrapper(self)
 }
 
 struct SelfType(String);
 
 
-impl From<String> for SelfType {
-    fn from(val: String) -> Self {
-        SelfType(String::new())
+impl Into<SelfType> for String {
+    fn into(self) -> SelfType {
+        SelfType(Self::new())
 }
 
 #[derive(Default)]
 struct X;
 struct X;
 
 impl X {
     const FOO: &'static str = "a";
 
 struct SelfKeywords;
 
 
-impl From<X> for SelfKeywords {
-    fn from(val: X) -> Self {
-        let _ = X::default();
-        let _ = X::FOO;
-        let _: X = val;
+impl Into<SelfKeywords> for X {
+    fn into(self) -> SelfKeywords {
+        let _ = Self::default();
+        let _ = Self::FOO;
+        let _: Self = self;
         SelfKeywords
     }
 }
 
 
 struct ExplicitPaths(bool);
 
-impl core::convert::From<crate::ExplicitPaths> for bool {
-    fn from(mut val: crate::ExplicitPaths) -> Self {
-        let in_closure = || val.0;
+impl core::convert::Into<bool> for crate::ExplicitPaths {
+    fn into(mut self) -> bool {
+        let in_closure = || self.0;
-        val.0 = false;
-        val.0
+        self.0 = false;
+        self.0
+        self.0
     }
 }
 
 // this is fine
 struct A(String);
 
 impl From<String> for A {
     fn from(s: String) -> A {
         A(s)
 }
 
 
 #[clippy::msrv = "1.40"]
 fn msrv_1_40() {
     struct FromOverInto<T>(Vec<T>);
 
     impl<T> Into<FromOverInto<T>> for Vec<T> {
         fn into(self) -> FromOverInto<T> {
             FromOverInto(self)
     }
 }
 
 
 #[clippy::msrv = "1.41"]
 fn msrv_1_41() {
     struct FromOverInto<T>(Vec<T>);
 
-    impl<T> From<Vec<T>> for FromOverInto<T> {
-        fn from(val: Vec<T>) -> Self {
-            FromOverInto(val)
+    impl<T> Into<FromOverInto<T>> for Vec<T> {
+        fn into(self) -> FromOverInto<T> {
+            FromOverInto(self)
     }
 }
 
 type Opaque = impl Sized;
 type Opaque = impl Sized;
 struct IntoOpaque;
 impl Into<Opaque> for IntoOpaque {
     fn into(self) -> Opaque {}
 
 fn main() {}
 


The actual fixed differed from the expected fixed.
Actual fixed saved to /checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/test/ui/from_over_into.stage-id.fixed
To only update this specific test, also pass `--test-args from_over_into.rs`

error: 2 errors occurred comparing output.
status: exit status: 1
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/clippy-driver" "tests/ui/from_over_into.rs" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/test/ui" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/test/ui/from_over_into.stage-id" "-A" "unused" "--emit=metadata" "-Dwarnings" "-Zui-testing" "-L" "dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps" "-L" "dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/release/deps" "--extern" "regex=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libregex-619ac20e364f2b2c.rlib" "--extern" "futures=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libfutures-23c15a454288152e.rlib" "--extern" "parking_lot=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libparking_lot-fc796eef9a515a44.rlib" "--extern" "itertools=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libitertools-b6f83e8bf7b1d2e3.rlib" "--extern" "syn=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libsyn-d8aee1681c496322.rlib" "--extern" "clippy_lints=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libclippy_lints-e5b19e58ae33983e.rlib" "--extern" "rustc_semver=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/librustc_semver-963bbd3f89834643.rlib" "--extern" "serde_derive=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/release/deps/libserde_derive-60efa73d6fad7e91.so" "--extern" "tokio=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libtokio-e0524b7e2611e851.rlib" "--extern" "clippy_utils=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libclippy_utils-bad1548ee8a3ddef.rlib" "--extern" "if_chain=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libif_chain-03f75cdc6d4d3afc.rlib" "--extern" "serde=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libserde-40ff94c070351d6c.rlib" "--extern" "derive_new=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/release/deps/libderive_new-e22c3fc74241d5e4.so" "--extern" "quote=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libquote-21e023f2887ebff8.rlib" "--edition=2021" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/test/ui/from_over_into.stage-id.aux"
------------------------------------------

------------------------------------------
stderr:
stderr:
------------------------------------------
{"message":"mismatched types","code":{"code":"E0308","explanation":"Expected type did not match the received type.\n\nErroneous code examples:\n\n```compile_fail,E0308\nfn plus_one(x: i32) -> i32 {\n    x + 1\n}\n\nplus_one(\"Not a number\");\n//       ^^^^^^^^^^^^^^ expected `i32`, found `&str`\n\nif \"Not a bool\" {\n// ^^^^^^^^^^^^ expected `bool`, found `&str`\n}\n\nlet x: f32 = \"Not a float\";\n//     ---   ^^^^^^^^^^^^^ expected `f32`, found `&str`\n//     |\n//     expected due to this\n```\n\nThis error occurs when an expression was used in a place where the compiler\nexpected an expression of a different type. It can occur in several cases, the\nmost common being when calling a function and passing an argument which has a\ndifferent type than the matching type in the function declaration.\n"},"level":"error","spans":[{"file_name":"tests/ui/from_over_into.rs","byte_start":1461,"byte_end":1471,"line_start":85,"line_end":85,"column_start":15,"column_end":25,"is_primary":false,"text":[{"text":"type Opaque = impl Sized;","highlight_start":15,"highlight_end":25}],"label":"the expected opaque type","suggested_replacement":null,"suggestion_applicability":null,"expansion":{"span":{"file_name":"tests/ui/from_over_into.rs","byte_start":1461,"byte_end":1471,"line_start":85,"line_end":85,"column_start":15,"column_end":25,"is_primary":false,"text":[{"text":"type Opaque = impl Sized;","highlight_start":15,"highlight_end":25}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null},"macro_decl_name":"desugaring of `impl Trait`","def_site_span":{"file_name":"tests/ui/from_over_into.rs","byte_start":0,"byte_end":0,"line_start":1,"line_end":1,"column_start":1,"column_end":1,"is_primary":false,"text":[],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}}},{"file_name":"tests/ui/from_over_into.rs","byte_start":1548,"byte_end":1554,"line_start":88,"line_end":88,"column_start":22,"column_end":28,"is_primary":true,"text":[{"text":"    fn into(self) -> Opaque {}","highlight_start":22,"highlight_end":28}],"label":"expected opaque type, found `()`","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"tests/ui/from_over_into.rs","byte_start":1534,"byte_end":1538,"line_start":88,"line_end":88,"column_start":8,"column_end":12,"is_primary":false,"text":[{"text":"    fn into(self) -> Opaque {}","highlight_start":8,"highlight_end":12}],"label":"implicitly returns `()` as its body has no tail or `return` expression","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"expected opaque type `Opaque`\n     found unit type `()`","code":null,"level":"note","spans":[],"children":[],"rendered":null},{"message":"this item cannot register hidden type without a `#[defines(Opaque)]` attribute","code":null,"level":"note","spans":[{"file_name":"tests/ui/from_over_into.rs","byte_start":1531,"byte_end":1554,"line_start":88,"line_end":88,"column_start":5,"column_end":28,"is_primary":true,"text":[{"text":"    fn into(self) -> Opaque {}","highlight_start":5,"highlight_end":28}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":null}],"rendered":"error[E0308]: mismatched types\n  --> tests/ui/from_over_into.rs:88:22\n   |\nLL | type Opaque = impl Sized;\n   |               ---------- the expected opaque type\n...\nLL |     fn into(self) -> Opaque {}\n   |        ----          ^^^^^^ expected opaque type, found `()`\n   |        |\n   |        implicitly returns `()` as its body has no tail or `return` expression\n   |\n   = note: expected opaque type `Opaque`\n                found unit type `()`\nnote: this item cannot register hidden type without a `#[defines(Opaque)]` attribute\n  --> tests/ui/from_over_into.rs:88:5\n   |\nLL |     fn into(self) -> Opaque {}\n   |     ^^^^^^^^^^^^^^^^^^^^^^^\n\n"}
{"message":"For more information about this error, try `rustc --explain E0308`.","code":null,"level":"failure-note","spans":[],"children":[],"rendered":"For more information about this error, try `rustc --explain E0308`.\n"}

------------------------------------------


diff of stderr:

-error: methods called `new` usually return `Self`
+error[E0308]: mismatched types
+  --> $DIR/new_ret_no_self.rs:422:13
    |
    |
-LL | /     pub fn new(_: String) -> impl R<Item = u32> {
-LL | |         S3
-LL | |     }
-   | |_____^
+LL |     type X = impl std::ops::Add<Output = X>;
+...
+LL |         pub fn new() -> X {
+LL |         pub fn new() -> X {
+   |                         - expected `issue10041::X` because of return type
+   |             ^^^^ expected opaque type, found `i32`
    |
    |
-   = note: `-D clippy::new-ret-no-self` implied by `-D warnings`
-
-error: methods called `new` usually return `Self`
-   |
-LL | /     pub fn new() -> u32 {
-LL | |         unimplemented!();
-LL | |     }
-LL | |     }
-   | |_____^
-
-error: methods called `new` usually return `Self`
-   |
-LL | /     pub fn new(_: String) -> u32 {
-LL | |         unimplemented!();
-LL | |     }
-LL | |     }
-   | |_____^
-
-error: methods called `new` usually return `Self`
-   |
-   |
-LL | /     pub fn new() -> (u32, u32) {
-LL | |         unimplemented!();
-LL | |     }
-
-
-error: methods called `new` usually return `Self`
-   |
-   |
-LL | /     pub fn new() -> *mut V {
-LL | |         unimplemented!();
-LL | |     }
-
-
-error: methods called `new` usually return `Self`
-   |
-LL | /     pub fn new() -> Option<u32> {
-LL | |         unimplemented!();
-LL | |     }
-LL | |     }
-   | |_____^
-
-error: methods called `new` usually return `Self`
-   |
-LL |         fn new() -> String;
-   |         ^^^^^^^^^^^^^^^^^^^
-
-
-error: methods called `new` usually return `Self`
-   |
-LL |         fn new(_: String) -> String;
-   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-
-error: methods called `new` usually return `Self`
-   |
-   |
-LL | /         fn new() -> (u32, u32) {
-LL | |             unimplemented!();
-LL | |         }
-
-
-error: methods called `new` usually return `Self`
-   |
-   |
-LL | /         fn new() -> *mut V {
-LL | |             unimplemented!();
-LL | |         }
-
-
-error: methods called `new` usually return `Self`
-   |
-   |
-LL | /         fn new(t: T) -> impl Into<i32> {
-LL | |             1
-LL | |         }
-
-
-error: methods called `new` usually return `Self`
-   |
-   |
-LL | /         fn new(t: T) -> impl Trait2<(), i32> {
-LL | |             unimplemented!()
-LL | |         }
-
-
-error: methods called `new` usually return `Self`
-   |
-   |
-LL | /         pub fn new() -> impl PartialOrd {
-LL | |             0i32
-LL | |         }
-
-
-error: methods called `new` usually return `Self`
+   = note: expected opaque type `issue10041::X`
+                     found type `i32`
+note: this item cannot register hidden type without a `#[defines(issue10041::X)]` attribute
    |
    |
-LL | /         pub fn new() -> X {
-LL | |             0i32
-LL | |         }
+LL |         pub fn new() -> X {
+   |         ^^^^^^^^^^^^^^^^^
 
-error: aborting due to 14 previous errors
---
To only update this specific test, also pass `--test-args new_ret_no_self.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/clippy-driver" "tests/ui/new_ret_no_self.rs" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/test/ui" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-C" "prefer-dynamic" "-o" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/test/ui/new_ret_no_self.stage-id" "-A" "unused" "--emit=metadata" "-Dwarnings" "-Zui-testing" "-L" "dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps" "-L" "dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/release/deps" "--extern" "regex=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libregex-619ac20e364f2b2c.rlib" "--extern" "futures=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libfutures-23c15a454288152e.rlib" "--extern" "parking_lot=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libparking_lot-fc796eef9a515a44.rlib" "--extern" "itertools=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libitertools-b6f83e8bf7b1d2e3.rlib" "--extern" "syn=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libsyn-d8aee1681c496322.rlib" "--extern" "clippy_lints=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libclippy_lints-e5b19e58ae33983e.rlib" "--extern" "rustc_semver=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/librustc_semver-963bbd3f89834643.rlib" "--extern" "serde_derive=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/release/deps/libserde_derive-60efa73d6fad7e91.so" "--extern" "tokio=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libtokio-e0524b7e2611e851.rlib" "--extern" "clippy_utils=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libclippy_utils-bad1548ee8a3ddef.rlib" "--extern" "if_chain=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libif_chain-03f75cdc6d4d3afc.rlib" "--extern" "serde=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libserde-40ff94c070351d6c.rlib" "--extern" "derive_new=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/release/deps/libderive_new-e22c3fc74241d5e4.so" "--extern" "quote=/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/deps/libquote-21e023f2887ebff8.rlib" "--edition=2021" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/test/ui/new_ret_no_self.stage-id.aux"
------------------------------------------

------------------------------------------
stderr:
stderr:
------------------------------------------
{"message":"mismatched types","code":{"code":"E0308","explanation":"Expected type did not match the received type.\n\nErroneous code examples:\n\n```compile_fail,E0308\nfn plus_one(x: i32) -> i32 {\n    x + 1\n}\n\nplus_one(\"Not a number\");\n//       ^^^^^^^^^^^^^^ expected `i32`, found `&str`\n\nif \"Not a bool\" {\n// ^^^^^^^^^^^^ expected `bool`, found `&str`\n}\n\nlet x: f32 = \"Not a float\";\n//     ---   ^^^^^^^^^^^^^ expected `f32`, found `&str`\n//     |\n//     expected due to this\n```\n\nThis error occurs when an expression was used in a place where the compiler\nexpected an expression of a different type. It can occur in several cases, the\nmost common being when calling a function and passing an argument which has a\ndifferent type than the matching type in the function declaration.\n"},"level":"error","spans":[{"file_name":"tests/ui/new_ret_no_self.rs","byte_start":7608,"byte_end":7638,"line_start":416,"line_end":416,"column_start":14,"column_end":44,"is_primary":false,"text":[{"text":"    type X = impl std::ops::Add<Output = X>;","highlight_start":14,"highlight_end":44}],"label":"the expected opaque type","suggested_replacement":null,"suggestion_applicability":null,"expansion":{"span":{"file_name":"tests/ui/new_ret_no_self.rs","byte_start":7608,"byte_end":7638,"line_start":416,"line_end":416,"column_start":14,"column_end":44,"is_primary":false,"text":[{"text":"    type X = impl std::ops::Add<Output = X>;","highlight_start":14,"highlight_end":44}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null},"macro_decl_name":"desugaring of `impl Trait`","def_site_span":{"file_name":"tests/ui/new_ret_no_self.rs","byte_start":0,"byte_end":0,"line_start":1,"line_end":1,"column_start":1,"column_end":1,"is_primary":false,"text":[],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}}},{"file_name":"tests/ui/new_ret_no_self.rs","byte_start":7717,"byte_end":7721,"line_start":422,"line_end":422,"column_start":13,"column_end":17,"is_primary":true,"text":[{"text":"            0i32","highlight_start":13,"highlight_end":17}],"label":"expected opaque type, found `i32`","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"tests/ui/new_ret_no_self.rs","byte_start":7701,"byte_end":7702,"line_start":421,"line_end":421,"column_start":25,"column_end":26,"is_primary":false,"text":[{"text":"        pub fn new() -> X {","highlight_start":25,"highlight_end":26}],"label":"expected `issue10041::X` because of return type","suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"expected opaque type `issue10041::X`\n          found type `i32`","code":null,"level":"note","spans":[],"children":[],"rendered":null},{"message":"this item cannot register hidden type without a `#[defines(issue10041::X)]` attribute","code":null,"level":"note","spans":[{"file_name":"tests/ui/new_ret_no_self.rs","byte_start":7685,"byte_end":7702,"line_start":421,"line_end":421,"column_start":9,"column_end":26,"is_primary":true,"text":[{"text":"        pub fn new() -> X {","highlight_start":9,"highlight_end":26}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[],"rendered":null}],"rendered":"error[E0308]: mismatched types\n  --> tests/ui/new_ret_no_self.rs:422:13\n   |\nLL |     type X = impl std::ops::Add<Output = X>;\n   |              ------------------------------ the expected opaque type\n...\nLL |         pub fn new() -> X {\n   |                         - expected `issue10041::X` because of return type\nLL |             0i32\n   |             ^^^^ expected opaque type, found `i32`\n   |\n   = note: expected opaque type `issue10041::X`\n                     found type `i32`\nnote: this item cannot register hidden type without a `#[defines(issue10041::X)]` attribute\n  --> tests/ui/new_ret_no_self.rs:421:9\n   |\nLL |         pub fn new() -> X {\n   |         ^^^^^^^^^^^^^^^^^\n\n"}
{"message":"For more information about this error, try `rustc --explain E0308`.","code":null,"level":"failure-note","spans":[],"children":[],"rendered":"For more information about this error, try `rustc --explain E0308`.\n"}

------------------------------------------

@petrochenkov
Copy link
Contributor

@oli-obk
Could you add me to reviewers when this PR is ready?
Whatever it does with expand_cfg_attr, it doesn't seem right, and data based on "lowering" attributes shouldn't be put into AST.

@oli-obk
Copy link
Contributor Author

oli-obk commented Apr 7, 2023

Whatever it does with expand_cfg_attr, it doesn't seem right, and data based on "lowering" attributes shouldn't be put into AST.

Yea, I'm aware. This was the quickest way to do things. It can't work for inner attributes at all and can't work for cfg_attr either. I am exploring actually correct strategies for this, but all of the ones I came up with are just differently colored sheds of making it a builtin attribute macro that expands the item to give it an extra unstable syntax thing.

@bors
Copy link
Contributor

bors commented Apr 10, 2023

☔ The latest upstream changes (presumably #108698) made this pull request unmergeable. Please resolve the merge conflicts.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Apr 12, 2023
…=jackh726

Split out a separate feature gate for impl trait in associated types

in rust-lang#107645 it was decided that we'll take a new route for type alias impl trait. The exact route isn't clear yet, so while I'm working on implementing some of these proposed changes (e.g. in rust-lang#110010) to be able to experiment with them, I will also work on stabilizing another sugar version first: impl trait in associated types. Similarly I'll look into creating feature gates for impl trait in const/static types.

This PR does nothing but split the feature gate, so that you need to enable a different feature gate for

```rust
impl Trait for Type {
    type Assoc = impl SomeTrait;
}
```

than what you need for `type Foo = impl SomeTrait;`
@Dylan-DPC Dylan-DPC added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 22, 2023
@oli-obk
Copy link
Contributor Author

oli-obk commented Jun 20, 2023

closing in favour of #112652

@oli-obk oli-obk closed this Jun 20, 2023
@oli-obk oli-obk deleted the tait_defines_attr_magic_parser branch June 20, 2023 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TAIT defining scope options
6 participants