Skip to content

Commit f8f1751

Browse files
committed
Auto merge of rust-lang#93933 - matthiaskrgr:rollup-1hjae6g, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#91908 (Add 2 tests) - rust-lang#93595 (fix ICE when parsing lifetime as function argument) - rust-lang#93757 (Add some known GAT bugs as tests) - rust-lang#93759 (Pretty print ItemKind::Use in rustfmt style) - rust-lang#93897 (linkchecker: fix panic on directory symlinks) - rust-lang#93898 (tidy: Extend error code check) - rust-lang#93928 (Add missing release notes for rust-lang#85200) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9cdefd7 + 0e3ecd2 commit f8f1751

36 files changed

+644
-31
lines changed

RELEASES.md

+5
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ Language
156156
- [Macro attributes may follow `#[derive]` and will see the original (pre-`cfg`) input.][87220]
157157
- [Accept curly-brace macros in expressions, like `m!{ .. }.method()` and `m!{ .. }?`.][88690]
158158
- [Allow panicking in constant evaluation.][89508]
159+
- [Ignore derived `Clone` and `Debug` implementations during dead code analysis.][85200]
159160

160161
Compiler
161162
--------
@@ -216,6 +217,9 @@ Cargo
216217
Compatibility notes
217218
-------------------
218219

220+
- [Ignore derived `Clone` and `Debug` implementations during dead code analysis.][85200]
221+
This will break some builds that set `#![deny(dead_code)]`.
222+
219223
Internal changes
220224
----------------
221225
These changes provide no direct user facing benefits, but represent significant
@@ -224,6 +228,7 @@ and related tools.
224228

225229
- [Added an experimental backend for codegen with `libgccjit`.][87260]
226230

231+
[85200]: https://github.com/rust-lang/rust/pull/85200/
227232
[86191]: https://github.com/rust-lang/rust/pull/86191/
228233
[87220]: https://github.com/rust-lang/rust/pull/87220/
229234
[87260]: https://github.com/rust-lang/rust/pull/87260/

compiler/rustc_ast_pretty/src/pp/convenience.rs

+4
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ impl Printer {
7575
}
7676

7777
pub fn trailing_comma(&mut self) {
78+
self.scan_break(BreakToken { pre_break: Some(','), ..BreakToken::default() });
79+
}
80+
81+
pub fn trailing_comma_or_space(&mut self) {
7882
self.scan_break(BreakToken {
7983
blank_space: 1,
8084
pre_break: Some(','),

compiler/rustc_ast_pretty/src/pprust/state/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl<'a> State<'a> {
142142
if !field.is_last || has_rest {
143143
self.word_space(",");
144144
} else {
145-
self.trailing_comma();
145+
self.trailing_comma_or_space();
146146
}
147147
}
148148
if has_rest {

compiler/rustc_ast_pretty/src/pprust/state/item.rs

+34-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::pp::Breaks::Inconsistent;
2-
use crate::pprust::state::{AnnNode, PrintState, State};
2+
use crate::pprust::state::delimited::IterDelimited;
3+
use crate::pprust::state::{AnnNode, PrintState, State, INDENT_UNIT};
34

45
use rustc_ast as ast;
56
use rustc_ast::GenericBound;
@@ -138,11 +139,10 @@ impl<'a> State<'a> {
138139
self.end(); // end outer head-block
139140
}
140141
ast::ItemKind::Use(ref tree) => {
141-
self.head(visibility_qualified(&item.vis, "use"));
142+
self.print_visibility(&item.vis);
143+
self.word_nbsp("use");
142144
self.print_use_tree(tree);
143145
self.word(";");
144-
self.end(); // end inner head-block
145-
self.end(); // end outer head-block
146146
}
147147
ast::ItemKind::Static(ref ty, mutbl, ref body) => {
148148
let def = ast::Defaultness::Final;
@@ -615,8 +615,8 @@ impl<'a> State<'a> {
615615
ast::UseTreeKind::Simple(rename, ..) => {
616616
self.print_path(&tree.prefix, false, 0);
617617
if let Some(rename) = rename {
618-
self.space();
619-
self.word_space("as");
618+
self.nbsp();
619+
self.word_nbsp("as");
620620
self.print_ident(rename);
621621
}
622622
}
@@ -628,16 +628,36 @@ impl<'a> State<'a> {
628628
self.word("*");
629629
}
630630
ast::UseTreeKind::Nested(ref items) => {
631-
if tree.prefix.segments.is_empty() {
632-
self.word("{");
633-
} else {
631+
if !tree.prefix.segments.is_empty() {
634632
self.print_path(&tree.prefix, false, 0);
635-
self.word("::{");
633+
self.word("::");
634+
}
635+
if items.is_empty() {
636+
self.word("{}");
637+
} else if items.len() == 1 {
638+
self.print_use_tree(&items[0].0);
639+
} else {
640+
self.cbox(INDENT_UNIT);
641+
self.word("{");
642+
self.zerobreak();
643+
self.ibox(0);
644+
for use_tree in items.iter().delimited() {
645+
self.print_use_tree(&use_tree.0);
646+
if !use_tree.is_last {
647+
self.word(",");
648+
if let ast::UseTreeKind::Nested(_) = use_tree.0.kind {
649+
self.hardbreak();
650+
} else {
651+
self.space();
652+
}
653+
}
654+
}
655+
self.end();
656+
self.trailing_comma();
657+
self.offset(-INDENT_UNIT);
658+
self.word("}");
659+
self.end();
636660
}
637-
self.commasep(Inconsistent, &items, |this, &(ref tree, _)| {
638-
this.print_use_tree(tree)
639-
});
640-
self.word("}");
641661
}
642662
}
643663
}

compiler/rustc_error_codes/src/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ E0184: include_str!("./error_codes/E0184.md"),
9797
E0185: include_str!("./error_codes/E0185.md"),
9898
E0186: include_str!("./error_codes/E0186.md"),
9999
E0191: include_str!("./error_codes/E0191.md"),
100+
E0192: include_str!("./error_codes/E0192.md"),
100101
E0193: include_str!("./error_codes/E0193.md"),
101102
E0195: include_str!("./error_codes/E0195.md"),
102103
E0197: include_str!("./error_codes/E0197.md"),
@@ -522,7 +523,6 @@ E0787: include_str!("./error_codes/E0787.md"),
522523
// E0188, // can not cast an immutable reference to a mutable pointer
523524
// E0189, // deprecated: can only cast a boxed pointer to a boxed object
524525
// E0190, // deprecated: can only cast a &-pointer to an &-object
525-
// E0192, // negative impl only applicable to auto traits
526526
// E0194, // merged into E0403
527527
// E0196, // cannot determine a type for this closure
528528
E0208,

compiler/rustc_error_codes/src/error_codes/E0192.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1+
#### Note: this error code is no longer emitted by the compiler.
2+
13
A negative impl was added on a trait implementation.
24

35
Erroneous code example:
46

5-
```compile_fail,E0192
7+
```compile_fail
68
trait Trait {
79
type Bar;
810
}
911
1012
struct Foo;
1113
12-
impl !Trait for Foo { } //~ ERROR E0192
14+
impl !Trait for Foo { } //~ ERROR
1315
1416
fn main() {}
1517
```

compiler/rustc_parse/src/parser/expr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1457,9 +1457,9 @@ impl<'a> Parser<'a> {
14571457
} else if self.check(&token::OpenDelim(token::Brace)) || self.token.is_whole_block() {
14581458
self.parse_block_expr(label, lo, BlockCheckMode::Default, attrs)
14591459
} else if !ate_colon && (self.check(&TokenKind::Comma) || self.check(&TokenKind::Gt)) {
1460-
// We're probably inside of a `Path<'a>` that needs a turbofish, so suppress the
1461-
// "must be followed by a colon" error, and the "expected one of" error.
1462-
self.diagnostic().delay_span_bug(lo, "this label wasn't parsed correctly");
1460+
// We're probably inside of a `Path<'a>` that needs a turbofish
1461+
let msg = "expected `while`, `for`, `loop` or `{` after a label";
1462+
self.struct_span_err(self.token.span, msg).span_label(self.token.span, msg).emit();
14631463
consume_colon = false;
14641464
Ok(self.mk_expr_err(lo))
14651465
} else {

src/test/pretty/use-tree.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// pp-exact
2+
// edition:2021
3+
4+
#![allow(unused_imports)]
5+
6+
use ::std::fmt::{self, Debug, Display, Write as _};
7+
8+
use core::option::Option::*;
9+
10+
use core::{
11+
cmp::{Eq, Ord, PartialEq, PartialOrd},
12+
convert::{AsMut, AsRef, From, Into},
13+
iter::{
14+
DoubleEndedIterator, ExactSizeIterator, Extend, FromIterator,
15+
IntoIterator, Iterator,
16+
},
17+
marker::{
18+
Copy as Copy, Send as Send, Sized as Sized, Sync as Sync, Unpin as U,
19+
},
20+
ops::{*, Drop, Fn, FnMut, FnOnce},
21+
};
22+
23+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// check-pass
2+
3+
pub trait Associate {
4+
type Associated;
5+
}
6+
7+
pub struct Wrap<'a> {
8+
pub field: &'a i32,
9+
}
10+
11+
pub trait Create<T> {
12+
fn create() -> Self;
13+
}
14+
15+
pub fn oh_no<'a, T>()
16+
where
17+
Wrap<'a>: Associate,
18+
<Wrap<'a> as Associate>::Associated: Create<T>,
19+
{
20+
<Wrap<'a> as Associate>::Associated::create();
21+
}
22+
23+
24+
pub fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// check-fail
2+
3+
// This should pass, but it requires `Sized` to be coinductive.
4+
5+
#![feature(generic_associated_types)]
6+
7+
trait Allocator {
8+
type Allocated<T>;
9+
}
10+
11+
enum LinkedList<A: Allocator> {
12+
Head,
13+
Next(A::Allocated<Self>)
14+
//~^ overflow
15+
}
16+
17+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0275]: overflow evaluating the requirement `LinkedList<A>: Sized`
2+
--> $DIR/issue-80626.rs:13:10
3+
|
4+
LL | Next(A::Allocated<Self>)
5+
| ^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: no field of an enum variant may have a dynamically sized type
8+
= help: change the field's type to have a statically known size
9+
help: borrowed types always have a statically known size
10+
|
11+
LL | Next(&A::Allocated<Self>)
12+
| +
13+
help: the `Box` type always has a statically known size and allocates its contents in the heap
14+
|
15+
LL | Next(Box<A::Allocated<Self>>)
16+
| ++++ +
17+
18+
error: aborting due to previous error
19+
20+
For more information about this error, try `rustc --explain E0275`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// check-fail
2+
3+
// This should pass, but seems to run into a TAIT issue.
4+
5+
#![feature(generic_associated_types)]
6+
#![feature(type_alias_impl_trait)]
7+
8+
pub trait Stream {
9+
type Item;
10+
}
11+
12+
impl Stream for () {
13+
type Item = i32;
14+
}
15+
16+
trait Yay<AdditionalValue> {
17+
type InnerStream<'s>: Stream<Item = i32> + 's;
18+
fn foo<'s>() -> Self::InnerStream<'s>;
19+
}
20+
21+
impl<'a> Yay<&'a ()> for () {
22+
type InnerStream<'s> = impl Stream<Item = i32> + 's;
23+
//~^ the type
24+
fn foo<'s>() -> Self::InnerStream<'s> { todo!() }
25+
}
26+
27+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0477]: the type `impl Stream<Item = i32>` does not fulfill the required lifetime
2+
--> $DIR/issue-86218.rs:22:28
3+
|
4+
LL | type InnerStream<'s> = impl Stream<Item = i32> + 's;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
note: type must outlive the lifetime `'s` as defined here as required by this binding
8+
--> $DIR/issue-86218.rs:22:22
9+
|
10+
LL | type InnerStream<'s> = impl Stream<Item = i32> + 's;
11+
| ^^
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0477`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// check-fail
2+
3+
// This should pass, but we need an extension of implied bounds (probably).
4+
5+
#![feature(generic_associated_types)]
6+
7+
pub trait AsRef2 {
8+
type Output<'a> where Self: 'a;
9+
10+
fn as_ref2<'a>(&'a self) -> Self::Output<'a>;
11+
}
12+
13+
impl<T> AsRef2 for Vec<T> {
14+
type Output<'a> where Self: 'a = &'a [T];
15+
16+
fn as_ref2<'a>(&'a self) -> Self::Output<'a> {
17+
&self[..]
18+
}
19+
}
20+
21+
#[derive(Debug)]
22+
struct Foo<T>(T);
23+
#[derive(Debug)]
24+
struct FooRef<'a, U>(&'a [U]);
25+
26+
impl<'b, T, U> AsRef2 for Foo<T> //~ the type parameter
27+
where
28+
// * `for<'b, 'c> T: AsRef2<Output<'b> = &'c [U]>>` does not work
29+
//
30+
// * `U` is unconstrained but should be allowed in this context because `Output` is
31+
// an associated type
32+
T: AsRef2<Output<'b> = &'b [U]>,
33+
U: 'b
34+
{
35+
type Output<'a> where Self: 'a = FooRef<'a, U>;
36+
37+
fn as_ref2<'a>(&'a self) -> Self::Output<'a> {
38+
FooRef(self.0.as_ref2())
39+
}
40+
}
41+
42+
fn main() {
43+
let foo = Foo(vec![1, 2, 3]);
44+
dbg!(foo.as_ref2());
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0207]: the type parameter `U` is not constrained by the impl trait, self type, or predicates
2+
--> $DIR/issue-87735.rs:26:13
3+
|
4+
LL | impl<'b, T, U> AsRef2 for Foo<T>
5+
| ^ unconstrained type parameter
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0207`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// check-fail
2+
3+
// This should pass, but unnormalized input args aren't treated as implied.
4+
5+
#![feature(generic_associated_types)]
6+
7+
trait MyTrait {
8+
type Assoc<'a, 'b> where 'b: 'a;
9+
fn do_sth(arg: Self::Assoc<'_, '_>);
10+
}
11+
12+
struct Foo;
13+
14+
impl MyTrait for Foo {
15+
type Assoc<'a, 'b> where 'b: 'a = u32;
16+
17+
fn do_sth(_: u32) {} //~ lifetime bound
18+
// fn do_sth(_: Self::Assoc<'static, 'static>) {}
19+
// fn do_sth(_: Self::Assoc<'_, '_>) {}
20+
}
21+
22+
fn main() {}

0 commit comments

Comments
 (0)