Auto merge of #129202 - matthiaskrgr:rollup-wev7uur, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #128989 (Emit an error for invalid use of the linkage attribute) - #129167 (mir/pretty: use `Option` instead of `Either<Once, Empty>`) - #129168 (Return correct HirId when finding body owner in diagnostics) - #129191 (rustdoc-json: Clean up serialization and printing.) - #129192 (Remove useless attributes in merged doctest generated code) - #129196 (Remove a useless ref/id/ref round-trip from `pattern_from_hir`) r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
0f26ee4fd9
15 changed files with 357 additions and 101 deletions
|
@ -1,25 +0,0 @@
|
|||
//@ known-bug: rust-lang/rust#128810
|
||||
|
||||
#![feature(fn_delegation)]
|
||||
|
||||
use std::marker::PhantomData;
|
||||
|
||||
pub struct InvariantRef<'a, T: ?Sized>(&'a T, PhantomData<&'a mut &'a T>);
|
||||
|
||||
impl<'a> InvariantRef<'a, ()> {
|
||||
pub const NEW: Self = InvariantRef::new(&());
|
||||
}
|
||||
|
||||
trait Trait {
|
||||
fn foo(&self) -> u8 { 0 }
|
||||
fn bar(&self) -> u8 { 1 }
|
||||
fn meh(&self) -> u8 { 2 }
|
||||
}
|
||||
|
||||
struct Z(u8);
|
||||
|
||||
impl Trait for Z {
|
||||
reuse <u8 as Trait>::{foo, bar, meh} { &const { InvariantRef::<'a>::NEW } }
|
||||
}
|
||||
|
||||
fn main() { }
|
42
tests/ui/attributes/linkage.rs
Normal file
42
tests/ui/attributes/linkage.rs
Normal file
|
@ -0,0 +1,42 @@
|
|||
#![feature(linkage)]
|
||||
#![feature(stmt_expr_attributes)]
|
||||
#![deny(unused_attributes)]
|
||||
#![allow(dead_code)]
|
||||
|
||||
#[linkage = "weak"] //~ ERROR attribute should be applied to a function or static
|
||||
type InvalidTy = ();
|
||||
|
||||
#[linkage = "weak"] //~ ERROR attribute should be applied to a function or static
|
||||
mod invalid_module {}
|
||||
|
||||
#[linkage = "weak"] //~ ERROR attribute should be applied to a function or static
|
||||
struct F;
|
||||
|
||||
#[linkage = "weak"] //~ ERROR attribute should be applied to a function or static
|
||||
impl F {
|
||||
#[linkage = "weak"]
|
||||
fn valid(&self) {}
|
||||
}
|
||||
|
||||
#[linkage = "weak"]
|
||||
fn f() {
|
||||
#[linkage = "weak"]
|
||||
{
|
||||
1
|
||||
};
|
||||
//~^^^^ ERROR attribute should be applied to a function or static
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
#[linkage = "weak"]
|
||||
static A: *const ();
|
||||
|
||||
#[linkage = "weak"]
|
||||
fn bar();
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let _ = #[linkage = "weak"]
|
||||
(|| 1);
|
||||
//~^^ ERROR attribute should be applied to a function or static
|
||||
}
|
55
tests/ui/attributes/linkage.stderr
Normal file
55
tests/ui/attributes/linkage.stderr
Normal file
|
@ -0,0 +1,55 @@
|
|||
error: attribute should be applied to a function or static
|
||||
--> $DIR/linkage.rs:6:1
|
||||
|
|
||||
LL | #[linkage = "weak"]
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
LL | type InvalidTy = ();
|
||||
| -------------------- not a function definition or static
|
||||
|
||||
error: attribute should be applied to a function or static
|
||||
--> $DIR/linkage.rs:9:1
|
||||
|
|
||||
LL | #[linkage = "weak"]
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
LL | mod invalid_module {}
|
||||
| --------------------- not a function definition or static
|
||||
|
||||
error: attribute should be applied to a function or static
|
||||
--> $DIR/linkage.rs:12:1
|
||||
|
|
||||
LL | #[linkage = "weak"]
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
LL | struct F;
|
||||
| --------- not a function definition or static
|
||||
|
||||
error: attribute should be applied to a function or static
|
||||
--> $DIR/linkage.rs:15:1
|
||||
|
|
||||
LL | #[linkage = "weak"]
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
LL | / impl F {
|
||||
LL | | #[linkage = "weak"]
|
||||
LL | | fn valid(&self) {}
|
||||
LL | | }
|
||||
| |_- not a function definition or static
|
||||
|
||||
error: attribute should be applied to a function or static
|
||||
--> $DIR/linkage.rs:23:5
|
||||
|
|
||||
LL | #[linkage = "weak"]
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
LL | / {
|
||||
LL | | 1
|
||||
LL | | };
|
||||
| |_____- not a function definition or static
|
||||
|
||||
error: attribute should be applied to a function or static
|
||||
--> $DIR/linkage.rs:39:13
|
||||
|
|
||||
LL | let _ = #[linkage = "weak"]
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
LL | (|| 1);
|
||||
| ------ not a function definition or static
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
#![feature(fn_delegation)]
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
use std::marker::PhantomData;
|
||||
|
||||
pub struct InvariantRef<'a, T: ?Sized>(&'a T, PhantomData<&'a mut &'a T>);
|
||||
|
||||
impl<'a> InvariantRef<'a, ()> {
|
||||
pub const NEW: Self = InvariantRef::new(&());
|
||||
//~^ ERROR: no function or associated item named `new` found
|
||||
}
|
||||
|
||||
trait Trait {
|
||||
fn foo(&self) -> u8 { 0 }
|
||||
fn bar(&self) -> u8 { 1 }
|
||||
fn meh(&self) -> u8 { 2 }
|
||||
}
|
||||
|
||||
struct Z(u8);
|
||||
|
||||
impl Trait for Z {
|
||||
reuse <u8 as Trait>::{foo, bar, meh} { &const { InvariantRef::<'a>::NEW } }
|
||||
//~^ ERROR: use of undeclared lifetime name `'a`
|
||||
//~| ERROR: use of undeclared lifetime name `'a`
|
||||
//~| ERROR: use of undeclared lifetime name `'a`
|
||||
//~| ERROR: the trait bound `u8: Trait` is not satisfied
|
||||
//~| ERROR: the trait bound `u8: Trait` is not satisfied
|
||||
//~| ERROR: the trait bound `u8: Trait` is not satisfied
|
||||
//~| ERROR: mismatched types
|
||||
//~| ERROR: mismatched types
|
||||
//~| ERROR: mismatched types
|
||||
}
|
||||
|
||||
fn main() { }
|
|
@ -0,0 +1,113 @@
|
|||
error[E0261]: use of undeclared lifetime name `'a`
|
||||
--> $DIR/correct_body_owner_parent_found_in_diagnostics.rs:22:68
|
||||
|
|
||||
LL | reuse <u8 as Trait>::{foo, bar, meh} { &const { InvariantRef::<'a>::NEW } }
|
||||
| ^^ undeclared lifetime
|
||||
|
|
||||
help: consider introducing lifetime `'a` here
|
||||
|
|
||||
LL | reuse <u8 as Trait>::{foo'a, , bar, meh} { &const { InvariantRef::<'a>::NEW } }
|
||||
| +++
|
||||
help: consider introducing lifetime `'a` here
|
||||
|
|
||||
LL | impl<'a> Trait for Z {
|
||||
| ++++
|
||||
|
||||
error[E0261]: use of undeclared lifetime name `'a`
|
||||
--> $DIR/correct_body_owner_parent_found_in_diagnostics.rs:22:68
|
||||
|
|
||||
LL | reuse <u8 as Trait>::{foo, bar, meh} { &const { InvariantRef::<'a>::NEW } }
|
||||
| ^^ undeclared lifetime
|
||||
|
|
||||
help: consider introducing lifetime `'a` here
|
||||
|
|
||||
LL | reuse <u8 as Trait>::{foo, bar'a, , meh} { &const { InvariantRef::<'a>::NEW } }
|
||||
| +++
|
||||
help: consider introducing lifetime `'a` here
|
||||
|
|
||||
LL | impl<'a> Trait for Z {
|
||||
| ++++
|
||||
|
||||
error[E0261]: use of undeclared lifetime name `'a`
|
||||
--> $DIR/correct_body_owner_parent_found_in_diagnostics.rs:22:68
|
||||
|
|
||||
LL | reuse <u8 as Trait>::{foo, bar, meh} { &const { InvariantRef::<'a>::NEW } }
|
||||
| ^^ undeclared lifetime
|
||||
|
|
||||
help: consider introducing lifetime `'a` here
|
||||
|
|
||||
LL | reuse <u8 as Trait>::{foo, bar, meh'a, } { &const { InvariantRef::<'a>::NEW } }
|
||||
| +++
|
||||
help: consider introducing lifetime `'a` here
|
||||
|
|
||||
LL | impl<'a> Trait for Z {
|
||||
| ++++
|
||||
|
||||
error[E0599]: no function or associated item named `new` found for struct `InvariantRef` in the current scope
|
||||
--> $DIR/correct_body_owner_parent_found_in_diagnostics.rs:9:41
|
||||
|
|
||||
LL | pub struct InvariantRef<'a, T: ?Sized>(&'a T, PhantomData<&'a mut &'a T>);
|
||||
| -------------------------------------- function or associated item `new` not found for this struct
|
||||
...
|
||||
LL | pub const NEW: Self = InvariantRef::new(&());
|
||||
| ^^^ function or associated item not found in `InvariantRef<'_, _>`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/correct_body_owner_parent_found_in_diagnostics.rs:22:53
|
||||
|
|
||||
LL | reuse <u8 as Trait>::{foo, bar, meh} { &const { InvariantRef::<'a>::NEW } }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ expected `u8`, found `InvariantRef<'_, ()>`
|
||||
|
|
||||
= note: expected type `u8`
|
||||
found struct `InvariantRef<'_, ()>`
|
||||
|
||||
error[E0277]: the trait bound `u8: Trait` is not satisfied
|
||||
--> $DIR/correct_body_owner_parent_found_in_diagnostics.rs:22:12
|
||||
|
|
||||
LL | reuse <u8 as Trait>::{foo, bar, meh} { &const { InvariantRef::<'a>::NEW } }
|
||||
| ^^ the trait `Trait` is not implemented for `u8`
|
||||
|
|
||||
= help: the trait `Trait` is implemented for `Z`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/correct_body_owner_parent_found_in_diagnostics.rs:22:53
|
||||
|
|
||||
LL | reuse <u8 as Trait>::{foo, bar, meh} { &const { InvariantRef::<'a>::NEW } }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ expected `u8`, found `InvariantRef<'_, ()>`
|
||||
|
|
||||
= note: expected type `u8`
|
||||
found struct `InvariantRef<'_, ()>`
|
||||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
||||
|
||||
error[E0277]: the trait bound `u8: Trait` is not satisfied
|
||||
--> $DIR/correct_body_owner_parent_found_in_diagnostics.rs:22:12
|
||||
|
|
||||
LL | reuse <u8 as Trait>::{foo, bar, meh} { &const { InvariantRef::<'a>::NEW } }
|
||||
| ^^ the trait `Trait` is not implemented for `u8`
|
||||
|
|
||||
= help: the trait `Trait` is implemented for `Z`
|
||||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/correct_body_owner_parent_found_in_diagnostics.rs:22:53
|
||||
|
|
||||
LL | reuse <u8 as Trait>::{foo, bar, meh} { &const { InvariantRef::<'a>::NEW } }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ expected `u8`, found `InvariantRef<'_, ()>`
|
||||
|
|
||||
= note: expected type `u8`
|
||||
found struct `InvariantRef<'_, ()>`
|
||||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
||||
|
||||
error[E0277]: the trait bound `u8: Trait` is not satisfied
|
||||
--> $DIR/correct_body_owner_parent_found_in_diagnostics.rs:22:12
|
||||
|
|
||||
LL | reuse <u8 as Trait>::{foo, bar, meh} { &const { InvariantRef::<'a>::NEW } }
|
||||
| ^^ the trait `Trait` is not implemented for `u8`
|
||||
|
|
||||
= help: the trait `Trait` is implemented for `Z`
|
||||
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
|
||||
|
||||
error: aborting due to 10 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0261, E0277, E0308, E0599.
|
||||
For more information about an error, try `rustc --explain E0261`.
|
16
tests/ui/typeck/const-in-fn-call-generics.rs
Normal file
16
tests/ui/typeck/const-in-fn-call-generics.rs
Normal file
|
@ -0,0 +1,16 @@
|
|||
fn generic<const N: u32>() {}
|
||||
|
||||
trait Collate<const A: u32> {
|
||||
type Pass;
|
||||
fn collate(self) -> Self::Pass;
|
||||
}
|
||||
|
||||
impl<const B: u32> Collate<B> for i32 {
|
||||
type Pass = ();
|
||||
fn collate(self) -> Self::Pass {
|
||||
generic::<{ true }>()
|
||||
//~^ ERROR: mismatched types
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
9
tests/ui/typeck/const-in-fn-call-generics.stderr
Normal file
9
tests/ui/typeck/const-in-fn-call-generics.stderr
Normal file
|
@ -0,0 +1,9 @@
|
|||
error[E0308]: mismatched types
|
||||
--> $DIR/const-in-fn-call-generics.rs:11:21
|
||||
|
|
||||
LL | generic::<{ true }>()
|
||||
| ^^^^ expected `u32`, found `bool`
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
Loading…
Add table
Add a link
Reference in a new issue