Skip to content

Commit 5227b68

Browse files
Rollup merge of #111929 - compiler-errors:no-newline-apit, r=wesleywiser
Don't print newlines in APITs This is kind of a hack, but it gets the job done because the only "special" formatting that (afaict) `rustc_ast_pretty` does is break with newlines sometimes. Fixes rust-lang/measureme#207
2 parents dbdb509 + 4692375 commit 5227b68

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1425,7 +1425,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
14251425
DefPathData::ImplTrait,
14261426
span,
14271427
);
1428-
let ident = Ident::from_str_and_span(&pprust::ty_to_string(t), span);
1428+
1429+
// HACK: pprust breaks strings with newlines when the type
1430+
// gets too long. We don't want these to show up in compiler
1431+
// output or built artifacts, so replace them here...
1432+
// Perhaps we should instead format APITs more robustly.
1433+
let ident = Ident::from_str_and_span(
1434+
&pprust::ty_to_string(t).replace('\n', " "),
1435+
span,
1436+
);
1437+
14291438
let (param, bounds, path) = self.lower_universal_param_and_bounds(
14301439
*def_node_id,
14311440
span,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
struct Header;
2+
struct EntryMetadata;
3+
struct Entry<A, B>(A, B);
4+
5+
trait Tr {
6+
type EncodedKey;
7+
type EncodedValue;
8+
}
9+
10+
fn test<C: Tr, R>(
11+
// This APIT is long, however we shouldn't render the type name with a newline in it.
12+
y: impl FnOnce(
13+
&mut Header,
14+
&mut [EntryMetadata],
15+
&mut [Entry<C::EncodedKey, C::EncodedValue>]
16+
) -> R,
17+
) {
18+
let () = y;
19+
//~^ ERROR mismatched types
20+
}
21+
22+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/arg-position-impl-trait-too-long.rs:18:9
3+
|
4+
LL | y: impl FnOnce(
5+
| ________-
6+
LL | | &mut Header,
7+
LL | | &mut [EntryMetadata],
8+
LL | | &mut [Entry<C::EncodedKey, C::EncodedValue>]
9+
LL | | ) -> R,
10+
| |__________- this type parameter
11+
LL | ) {
12+
LL | let () = y;
13+
| ^^ - this expression has type `impl FnOnce(&mut Header, &mut [EntryMetadata], &mut [Entry<C::EncodedKey, C::EncodedValue>]) -> R`
14+
| |
15+
| expected type parameter `impl FnOnce(&mut Header, &mut [EntryMetadata], &mut [Entry<C::EncodedKey, C::EncodedValue>]) -> R`, found `()`
16+
|
17+
= note: expected type parameter `impl FnOnce(&mut Header, &mut [EntryMetadata], &mut [Entry<C::EncodedKey, C::EncodedValue>]) -> R`
18+
found unit type `()`
19+
20+
error: aborting due to previous error
21+
22+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)