Skip to content

Commit

Permalink
Auto merge of rust-lang#93933 - matthiaskrgr:rollup-1hjae6g, r=matthi…
Browse files Browse the repository at this point in the history
…askrgr

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
  • Loading branch information
bors committed Feb 12, 2022
2 parents 9cdefd7 + 0e3ecd2 commit f8f1751
Show file tree
Hide file tree
Showing 36 changed files with 644 additions and 31 deletions.
5 changes: 5 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ Language
- [Macro attributes may follow `#[derive]` and will see the original (pre-`cfg`) input.][87220]
- [Accept curly-brace macros in expressions, like `m!{ .. }.method()` and `m!{ .. }?`.][88690]
- [Allow panicking in constant evaluation.][89508]
- [Ignore derived `Clone` and `Debug` implementations during dead code analysis.][85200]

Compiler
--------
Expand Down Expand Up @@ -216,6 +217,9 @@ Cargo
Compatibility notes
-------------------

- [Ignore derived `Clone` and `Debug` implementations during dead code analysis.][85200]
This will break some builds that set `#![deny(dead_code)]`.

Internal changes
----------------
These changes provide no direct user facing benefits, but represent significant
Expand All @@ -224,6 +228,7 @@ and related tools.

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

[85200]: https://github.com/rust-lang/rust/pull/85200/
[86191]: https://github.com/rust-lang/rust/pull/86191/
[87220]: https://github.com/rust-lang/rust/pull/87220/
[87260]: https://github.com/rust-lang/rust/pull/87260/
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_ast_pretty/src/pp/convenience.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ impl Printer {
}

pub fn trailing_comma(&mut self) {
self.scan_break(BreakToken { pre_break: Some(','), ..BreakToken::default() });
}

pub fn trailing_comma_or_space(&mut self) {
self.scan_break(BreakToken {
blank_space: 1,
pre_break: Some(','),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_pretty/src/pprust/state/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl<'a> State<'a> {
if !field.is_last || has_rest {
self.word_space(",");
} else {
self.trailing_comma();
self.trailing_comma_or_space();
}
}
if has_rest {
Expand Down
48 changes: 34 additions & 14 deletions compiler/rustc_ast_pretty/src/pprust/state/item.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::pp::Breaks::Inconsistent;
use crate::pprust::state::{AnnNode, PrintState, State};
use crate::pprust::state::delimited::IterDelimited;
use crate::pprust::state::{AnnNode, PrintState, State, INDENT_UNIT};

use rustc_ast as ast;
use rustc_ast::GenericBound;
Expand Down Expand Up @@ -138,11 +139,10 @@ impl<'a> State<'a> {
self.end(); // end outer head-block
}
ast::ItemKind::Use(ref tree) => {
self.head(visibility_qualified(&item.vis, "use"));
self.print_visibility(&item.vis);
self.word_nbsp("use");
self.print_use_tree(tree);
self.word(";");
self.end(); // end inner head-block
self.end(); // end outer head-block
}
ast::ItemKind::Static(ref ty, mutbl, ref body) => {
let def = ast::Defaultness::Final;
Expand Down Expand Up @@ -615,8 +615,8 @@ impl<'a> State<'a> {
ast::UseTreeKind::Simple(rename, ..) => {
self.print_path(&tree.prefix, false, 0);
if let Some(rename) = rename {
self.space();
self.word_space("as");
self.nbsp();
self.word_nbsp("as");
self.print_ident(rename);
}
}
Expand All @@ -628,16 +628,36 @@ impl<'a> State<'a> {
self.word("*");
}
ast::UseTreeKind::Nested(ref items) => {
if tree.prefix.segments.is_empty() {
self.word("{");
} else {
if !tree.prefix.segments.is_empty() {
self.print_path(&tree.prefix, false, 0);
self.word("::{");
self.word("::");
}
if items.is_empty() {
self.word("{}");
} else if items.len() == 1 {
self.print_use_tree(&items[0].0);
} else {
self.cbox(INDENT_UNIT);
self.word("{");
self.zerobreak();
self.ibox(0);
for use_tree in items.iter().delimited() {
self.print_use_tree(&use_tree.0);
if !use_tree.is_last {
self.word(",");
if let ast::UseTreeKind::Nested(_) = use_tree.0.kind {
self.hardbreak();
} else {
self.space();
}
}
}
self.end();
self.trailing_comma();
self.offset(-INDENT_UNIT);
self.word("}");
self.end();
}
self.commasep(Inconsistent, &items, |this, &(ref tree, _)| {
this.print_use_tree(tree)
});
self.word("}");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_error_codes/src/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ E0184: include_str!("./error_codes/E0184.md"),
E0185: include_str!("./error_codes/E0185.md"),
E0186: include_str!("./error_codes/E0186.md"),
E0191: include_str!("./error_codes/E0191.md"),
E0192: include_str!("./error_codes/E0192.md"),
E0193: include_str!("./error_codes/E0193.md"),
E0195: include_str!("./error_codes/E0195.md"),
E0197: include_str!("./error_codes/E0197.md"),
Expand Down Expand Up @@ -522,7 +523,6 @@ E0787: include_str!("./error_codes/E0787.md"),
// E0188, // can not cast an immutable reference to a mutable pointer
// E0189, // deprecated: can only cast a boxed pointer to a boxed object
// E0190, // deprecated: can only cast a &-pointer to an &-object
// E0192, // negative impl only applicable to auto traits
// E0194, // merged into E0403
// E0196, // cannot determine a type for this closure
E0208,
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_error_codes/src/error_codes/E0192.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#### Note: this error code is no longer emitted by the compiler.

A negative impl was added on a trait implementation.

Erroneous code example:

```compile_fail,E0192
```compile_fail
trait Trait {
type Bar;
}
struct Foo;
impl !Trait for Foo { } //~ ERROR E0192
impl !Trait for Foo { } //~ ERROR
fn main() {}
```
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1457,9 +1457,9 @@ impl<'a> Parser<'a> {
} else if self.check(&token::OpenDelim(token::Brace)) || self.token.is_whole_block() {
self.parse_block_expr(label, lo, BlockCheckMode::Default, attrs)
} else if !ate_colon && (self.check(&TokenKind::Comma) || self.check(&TokenKind::Gt)) {
// We're probably inside of a `Path<'a>` that needs a turbofish, so suppress the
// "must be followed by a colon" error, and the "expected one of" error.
self.diagnostic().delay_span_bug(lo, "this label wasn't parsed correctly");
// We're probably inside of a `Path<'a>` that needs a turbofish
let msg = "expected `while`, `for`, `loop` or `{` after a label";
self.struct_span_err(self.token.span, msg).span_label(self.token.span, msg).emit();
consume_colon = false;
Ok(self.mk_expr_err(lo))
} else {
Expand Down
23 changes: 23 additions & 0 deletions src/test/pretty/use-tree.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// pp-exact
// edition:2021

#![allow(unused_imports)]

use ::std::fmt::{self, Debug, Display, Write as _};

use core::option::Option::*;

use core::{
cmp::{Eq, Ord, PartialEq, PartialOrd},
convert::{AsMut, AsRef, From, Into},
iter::{
DoubleEndedIterator, ExactSizeIterator, Extend, FromIterator,
IntoIterator, Iterator,
},
marker::{
Copy as Copy, Send as Send, Sized as Sized, Sync as Sync, Unpin as U,
},
ops::{*, Drop, Fn, FnMut, FnOnce},
};

fn main() {}
24 changes: 24 additions & 0 deletions src/test/ui/associated-types/issue-91069.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// check-pass

pub trait Associate {
type Associated;
}

pub struct Wrap<'a> {
pub field: &'a i32,
}

pub trait Create<T> {
fn create() -> Self;
}

pub fn oh_no<'a, T>()
where
Wrap<'a>: Associate,
<Wrap<'a> as Associate>::Associated: Create<T>,
{
<Wrap<'a> as Associate>::Associated::create();
}


pub fn main() {}
17 changes: 17 additions & 0 deletions src/test/ui/generic-associated-types/bugs/issue-80626.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// check-fail

// This should pass, but it requires `Sized` to be coinductive.

#![feature(generic_associated_types)]

trait Allocator {
type Allocated<T>;
}

enum LinkedList<A: Allocator> {
Head,
Next(A::Allocated<Self>)
//~^ overflow
}

fn main() {}
20 changes: 20 additions & 0 deletions src/test/ui/generic-associated-types/bugs/issue-80626.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
error[E0275]: overflow evaluating the requirement `LinkedList<A>: Sized`
--> $DIR/issue-80626.rs:13:10
|
LL | Next(A::Allocated<Self>)
| ^^^^^^^^^^^^^^^^^^
|
= note: no field of an enum variant may have a dynamically sized type
= help: change the field's type to have a statically known size
help: borrowed types always have a statically known size
|
LL | Next(&A::Allocated<Self>)
| +
help: the `Box` type always has a statically known size and allocates its contents in the heap
|
LL | Next(Box<A::Allocated<Self>>)
| ++++ +

error: aborting due to previous error

For more information about this error, try `rustc --explain E0275`.
27 changes: 27 additions & 0 deletions src/test/ui/generic-associated-types/bugs/issue-86218.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// check-fail

// This should pass, but seems to run into a TAIT issue.

#![feature(generic_associated_types)]
#![feature(type_alias_impl_trait)]

pub trait Stream {
type Item;
}

impl Stream for () {
type Item = i32;
}

trait Yay<AdditionalValue> {
type InnerStream<'s>: Stream<Item = i32> + 's;
fn foo<'s>() -> Self::InnerStream<'s>;
}

impl<'a> Yay<&'a ()> for () {
type InnerStream<'s> = impl Stream<Item = i32> + 's;
//~^ the type
fn foo<'s>() -> Self::InnerStream<'s> { todo!() }
}

fn main() {}
15 changes: 15 additions & 0 deletions src/test/ui/generic-associated-types/bugs/issue-86218.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error[E0477]: the type `impl Stream<Item = i32>` does not fulfill the required lifetime
--> $DIR/issue-86218.rs:22:28
|
LL | type InnerStream<'s> = impl Stream<Item = i32> + 's;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: type must outlive the lifetime `'s` as defined here as required by this binding
--> $DIR/issue-86218.rs:22:22
|
LL | type InnerStream<'s> = impl Stream<Item = i32> + 's;
| ^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0477`.
45 changes: 45 additions & 0 deletions src/test/ui/generic-associated-types/bugs/issue-87735.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// check-fail

// This should pass, but we need an extension of implied bounds (probably).

#![feature(generic_associated_types)]

pub trait AsRef2 {
type Output<'a> where Self: 'a;

fn as_ref2<'a>(&'a self) -> Self::Output<'a>;
}

impl<T> AsRef2 for Vec<T> {
type Output<'a> where Self: 'a = &'a [T];

fn as_ref2<'a>(&'a self) -> Self::Output<'a> {
&self[..]
}
}

#[derive(Debug)]
struct Foo<T>(T);
#[derive(Debug)]
struct FooRef<'a, U>(&'a [U]);

impl<'b, T, U> AsRef2 for Foo<T> //~ the type parameter
where
// * `for<'b, 'c> T: AsRef2<Output<'b> = &'c [U]>>` does not work
//
// * `U` is unconstrained but should be allowed in this context because `Output` is
// an associated type
T: AsRef2<Output<'b> = &'b [U]>,
U: 'b
{
type Output<'a> where Self: 'a = FooRef<'a, U>;

fn as_ref2<'a>(&'a self) -> Self::Output<'a> {
FooRef(self.0.as_ref2())
}
}

fn main() {
let foo = Foo(vec![1, 2, 3]);
dbg!(foo.as_ref2());
}
9 changes: 9 additions & 0 deletions src/test/ui/generic-associated-types/bugs/issue-87735.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0207]: the type parameter `U` is not constrained by the impl trait, self type, or predicates
--> $DIR/issue-87735.rs:26:13
|
LL | impl<'b, T, U> AsRef2 for Foo<T>
| ^ unconstrained type parameter

error: aborting due to previous error

For more information about this error, try `rustc --explain E0207`.
22 changes: 22 additions & 0 deletions src/test/ui/generic-associated-types/bugs/issue-87748.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// check-fail

// This should pass, but unnormalized input args aren't treated as implied.

#![feature(generic_associated_types)]

trait MyTrait {
type Assoc<'a, 'b> where 'b: 'a;
fn do_sth(arg: Self::Assoc<'_, '_>);
}

struct Foo;

impl MyTrait for Foo {
type Assoc<'a, 'b> where 'b: 'a = u32;

fn do_sth(_: u32) {} //~ lifetime bound
// fn do_sth(_: Self::Assoc<'static, 'static>) {}
// fn do_sth(_: Self::Assoc<'_, '_>) {}
}

fn main() {}
Loading

0 comments on commit f8f1751

Please sign in to comment.