Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b1ec1bd

Browse files
committedMay 18, 2024
Auto merge of #125257 - jieyouxu:rollup-11evnm9, r=jieyouxu
Rollup of 3 pull requests Successful merges: - #125214 (Only make GAT ambiguous in `match_projection_projections` considering shallow resolvability) - #125236 (Add tests for `-Zunpretty=expanded` ported from stringify's tests) - #125251 (Clarify how String::leak and into_boxed_str differ ) r? `@ghost` `@rustbot` modify labels: rollup
2 parents eb1a5c9 + c367d99 commit b1ec1bd

File tree

13 files changed

+1844
-57
lines changed

13 files changed

+1844
-57
lines changed
 

‎compiler/rustc_trait_selection/src/traits/select/mod.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1778,9 +1778,19 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
17781778
// If this type is a GAT, and of the GAT args resolve to something new,
17791779
// that means that we must have newly inferred something about the GAT.
17801780
// We should give up in that case.
1781+
// FIXME(generic-associated-types): This only detects one layer of inference,
1782+
// which is probably not what we actually want, but fixing it causes some ambiguity:
1783+
// <https://github.com/rust-lang/rust/issues/125196>.
17811784
if !generics.own_params.is_empty()
17821785
&& obligation.predicate.args[generics.parent_count..].iter().any(|&p| {
1783-
p.has_non_region_infer() && self.infcx.resolve_vars_if_possible(p) != p
1786+
p.has_non_region_infer()
1787+
&& match p.unpack() {
1788+
ty::GenericArgKind::Const(ct) => {
1789+
self.infcx.shallow_resolve_const(ct) != ct
1790+
}
1791+
ty::GenericArgKind::Type(ty) => self.infcx.shallow_resolve(ty) != ty,
1792+
ty::GenericArgKind::Lifetime(_) => false,
1793+
}
17841794
})
17851795
{
17861796
ProjectionMatchesProjection::Ambiguous

‎library/alloc/src/string.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1940,8 +1940,10 @@ impl String {
19401940

19411941
/// Converts this `String` into a <code>[Box]<[str]></code>.
19421942
///
1943-
/// This will drop any excess capacity.
1943+
/// Before doing the conversion, this method discards excess capacity like [`shrink_to_fit`].
1944+
/// Note that this call may reallocate and copy the bytes of the string.
19441945
///
1946+
/// [`shrink_to_fit`]: String::shrink_to_fit
19451947
/// [str]: prim@str "str"
19461948
///
19471949
/// # Examples
@@ -1967,10 +1969,10 @@ impl String {
19671969
/// this function is ideally used for data that lives for the remainder of the program's life,
19681970
/// as dropping the returned reference will cause a memory leak.
19691971
///
1970-
/// It does not reallocate or shrink the `String`,
1971-
/// so the leaked allocation may include unused capacity that is not part
1972-
/// of the returned slice. If you don't want that, call [`into_boxed_str`],
1973-
/// and then [`Box::leak`].
1972+
/// It does not reallocate or shrink the `String`, so the leaked allocation may include unused
1973+
/// capacity that is not part of the returned slice. If you want to discard excess capacity,
1974+
/// call [`into_boxed_str`], and then [`Box::leak`] instead. However, keep in mind that
1975+
/// trimming the capacity may result in a reallocation and copy.
19741976
///
19751977
/// [`into_boxed_str`]: Self::into_boxed_str
19761978
///

‎src/tools/tidy/src/issues.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2915,7 +2915,6 @@ ui/macros/issue-95267.rs
29152915
ui/macros/issue-95533.rs
29162916
ui/macros/issue-98466-allow.rs
29172917
ui/macros/issue-98466.rs
2918-
ui/macros/issue-98790.rs
29192918
ui/macros/issue-99261.rs
29202919
ui/macros/issue-99265.rs
29212920
ui/macros/issue-99907.rs

‎src/tools/tidy/src/ui_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const EXTENSION_EXCEPTION_PATHS: &[&str] = &[
4141
"tests/ui/macros/not-utf8.bin", // testing including data with the include macros
4242
"tests/ui/macros/syntax-extension-source-utils-files/includeme.fragment", // more include
4343
"tests/ui/proc-macro/auxiliary/included-file.txt", // more include
44+
"tests/ui/unpretty/auxiliary/data.txt", // more include
4445
"tests/ui/invalid/foo.natvis.xml", // sample debugger visualizer
4546
"tests/ui/sanitizer/dataflow-abilist.txt", // dataflow sanitizer ABI list file
4647
"tests/ui/shell-argfiles/shell-argfiles.args", // passing args via a file
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Fix for <https://github.com/rust-lang/rust/issues/125196>.
2+
//@ check-pass
3+
4+
trait Tr {
5+
type Gat<T>;
6+
}
7+
8+
struct W<T>(T);
9+
10+
fn foo<T: Tr>() where for<'a> &'a T: Tr<Gat<W<i32>> = i32> {
11+
let x: <&T as Tr>::Gat<W<_>> = 1i32;
12+
// Previously, `match_projection_projections` only checked that
13+
// `shallow_resolve(W<?0>) = W<?0>`. This won't prevent *all* inference guidance
14+
// from projection predicates in the environment, just ones that guide the
15+
// outermost type of each GAT constructor. This is definitely wrong, but there is
16+
// code that relies on it in the wild :/
17+
}
18+
19+
fn main() {}

‎tests/ui/macros/issue-98790.rs

Lines changed: 0 additions & 24 deletions
This file was deleted.

‎tests/ui/unpretty/auxiliary/data.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
data for include_bytes in ../expanded-exhaustive.rs

‎tests/ui/unpretty/expanded-exhaustive.rs

Lines changed: 888 additions & 0 deletions
Large diffs are not rendered by default.

‎tests/ui/unpretty/expanded-exhaustive.stdout

Lines changed: 719 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
//@ compile-flags: -Zunpretty=expanded
2+
//@ check-pass
3+
4+
// This test covers the AST pretty-printer's insertion of parentheses in some
5+
// macro metavariable edge cases. Synthetic parentheses (i.e. not appearing in
6+
// the syntax tree) need to be printed in order for the printed code to be valid
7+
// Rust syntax. We also test negative cases: the pretty-printer should not be
8+
// synthesizing parentheses indiscriminately; only where necessary.
9+
10+
#![feature(let_chains)]
11+
#![feature(if_let_guard)]
12+
13+
macro_rules! expr {
14+
($expr:expr) => { $expr };
15+
}
16+
17+
macro_rules! stmt {
18+
($stmt:stmt) => { $stmt };
19+
}
20+
21+
fn if_let() {
22+
macro_rules! if_let {
23+
($pat:pat, $expr:expr) => {
24+
if let $pat = $expr {}
25+
};
26+
}
27+
28+
if let no_paren = true && false {}
29+
if_let!(paren_around_binary, true && false);
30+
if_let!(no_paren, true);
31+
32+
struct Struct {}
33+
match () {
34+
_ if let no_paren = Struct {} => {}
35+
}
36+
}
37+
38+
fn let_else() {
39+
let no_paren = expr!(1 + 1) else { return; };
40+
let paren_around_loop = expr!(loop {}) else { return; };
41+
}
42+
43+
fn local() {
44+
macro_rules! let_expr_minus_one {
45+
($pat:pat, $expr:expr) => {
46+
let $pat = $expr - 1;
47+
};
48+
}
49+
50+
let void;
51+
let_expr_minus_one!(no_paren, match void {});
52+
53+
macro_rules! let_expr_else_return {
54+
($pat:pat, $expr:expr) => {
55+
let $pat = $expr else { return; };
56+
};
57+
}
58+
59+
let_expr_else_return!(no_paren, void());
60+
}
61+
62+
fn match_arm() {
63+
macro_rules! match_arm {
64+
($pat:pat, $expr:expr) => {
65+
match () { $pat => $expr }
66+
};
67+
}
68+
69+
match_arm!(no_paren, 1 - 1);
70+
match_arm!(paren_around_brace, { 1 } - 1);
71+
}
72+
73+
/// https://github.com/rust-lang/rust/issues/98790
74+
fn stmt_boundary() {
75+
macro_rules! expr_as_stmt {
76+
($expr:expr) => {
77+
stmt!($expr)
78+
};
79+
}
80+
81+
let paren_around_match;
82+
expr_as_stmt!(match paren_around_match {} | true);
83+
84+
macro_rules! minus_one {
85+
($expr:expr) => {
86+
expr_as_stmt!($expr - 1)
87+
};
88+
}
89+
90+
let (no_paren, paren_around_loop);
91+
minus_one!(no_paren);
92+
minus_one!(match paren_around_match {});
93+
minus_one!(match paren_around_match {}());
94+
minus_one!(match paren_around_match {}[0]);
95+
minus_one!(loop { break paren_around_loop; });
96+
}
97+
98+
fn vis_inherited() {
99+
macro_rules! vis_inherited {
100+
($vis:vis struct) => {
101+
$vis struct Struct;
102+
};
103+
}
104+
105+
vis_inherited!(struct);
106+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#![feature(prelude_import)]
2+
#![no_std]
3+
//@ compile-flags: -Zunpretty=expanded
4+
//@ check-pass
5+
6+
// This test covers the AST pretty-printer's insertion of parentheses in some
7+
// macro metavariable edge cases. Synthetic parentheses (i.e. not appearing in
8+
// the syntax tree) need to be printed in order for the printed code to be valid
9+
// Rust syntax. We also test negative cases: the pretty-printer should not be
10+
// synthesizing parentheses indiscriminately; only where necessary.
11+
12+
#![feature(let_chains)]
13+
#![feature(if_let_guard)]
14+
#[prelude_import]
15+
use ::std::prelude::rust_2015::*;
16+
#[macro_use]
17+
extern crate std;
18+
19+
macro_rules! expr { ($expr:expr) => { $expr }; }
20+
21+
macro_rules! stmt { ($stmt:stmt) => { $stmt }; }
22+
23+
fn if_let() {
24+
macro_rules! if_let {
25+
($pat:pat, $expr:expr) => { if let $pat = $expr {} };
26+
}
27+
28+
if let no_paren = true && false {}
29+
if let paren_around_binary = (true && false) {};
30+
if let no_paren = true {};
31+
32+
struct Struct {}
33+
match () { _ if let no_paren = Struct {} => {} }
34+
}
35+
36+
fn let_else() {
37+
let no_paren = 1 + 1 else { return; };
38+
let paren_around_loop = (loop {}) else { return; };
39+
}
40+
41+
fn local() {
42+
macro_rules! let_expr_minus_one {
43+
($pat:pat, $expr:expr) => { let $pat = $expr - 1; };
44+
}
45+
46+
let void;
47+
let no_paren = match void {} - 1;
48+
49+
macro_rules! let_expr_else_return {
50+
($pat:pat, $expr:expr) => { let $pat = $expr else { return; }; };
51+
}
52+
let
53+
54+
no_paren = void() else { return; };
55+
}
56+
57+
fn match_arm() {
58+
macro_rules! match_arm {
59+
($pat:pat, $expr:expr) => { match () { $pat => $expr } };
60+
}
61+
match () {
62+
63+
64+
no_paren => 1 - 1,
65+
};
66+
match () { paren_around_brace => ({ 1 }) - 1, };
67+
}
68+
69+
/// https://github.com/rust-lang/rust/issues/98790
70+
fn stmt_boundary() {
71+
macro_rules! expr_as_stmt { ($expr:expr) => { stmt!($expr) }; }
72+
73+
let paren_around_match;
74+
(match paren_around_match {}) | true;
75+
76+
macro_rules! minus_one { ($expr:expr) => { expr_as_stmt!($expr - 1) }; }
77+
78+
let (no_paren, paren_around_loop);
79+
no_paren - 1;
80+
(match paren_around_match {}) - 1;
81+
(match paren_around_match {})() - 1;
82+
(match paren_around_match {})[0] - 1;
83+
(loop { break paren_around_loop; }) - 1;
84+
}
85+
86+
fn vis_inherited() {
87+
macro_rules! vis_inherited {
88+
($vis:vis struct) => { $vis struct Struct; };
89+
}
90+
struct Struct;
91+
92+
}

‎tests/ui/unpretty/let-else.rs

Lines changed: 0 additions & 11 deletions
This file was deleted.

‎tests/ui/unpretty/let-else.stdout

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.