Skip to content

Commit

Permalink
Rollup merge of rust-lang#94037 - tmiasko:verbose, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
Fix inconsistent symbol mangling with -Zverbose

Always skip arguments that are the defaults of their respective
parameters, to avoid generating inconsistent symbols for builds
with `-Zverbose` flag and without it.
  • Loading branch information
matthiaskrgr authored Feb 16, 2022
2 parents af981bd + 3158372 commit 85bd745
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 13 deletions.
5 changes: 0 additions & 5 deletions compiler/rustc_middle/src/ty/print/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,6 @@ pub trait Printer<'tcx>: Sized {
own_params.start = 1;
}

// If we're in verbose mode, then print default-equal args too
if self.tcx().sess.verbose() {
return &substs[own_params];
}

// Don't print args that are the defaults of their respective parameters.
own_params.end -= generics
.params
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/associated-types/substs-ppaux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn foo<'z>() where &'z (): Sized {
let x: () = <i8 as Foo<'static, 'static, u32>>::bar::<'static, char>;
//[verbose]~^ ERROR mismatched types
//[verbose]~| expected unit type `()`
//[verbose]~| found fn item `fn() {<i8 as Foo<ReStatic, ReStatic, u32>>::bar::<ReStatic, char>}`
//[verbose]~| found fn item `fn() {<i8 as Foo<ReStatic, ReStatic>>::bar::<ReStatic, char>}`
//[normal]~^^^^ ERROR mismatched types
//[normal]~| expected unit type `()`
//[normal]~| found fn item `fn() {<i8 as Foo<'static, 'static>>::bar::<'static, char>}`
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/associated-types/substs-ppaux.verbose.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ error[E0308]: mismatched types
--> $DIR/substs-ppaux.rs:25:17
|
LL | fn bar<'a, T>() where T: 'a {}
| --------------------------- fn() {<i8 as Foo<ReStatic, ReStatic, u32>>::bar::<ReStatic, char>} defined here
| --------------------------- fn() {<i8 as Foo<ReStatic, ReStatic>>::bar::<ReStatic, char>} defined here
...
LL | let x: () = <i8 as Foo<'static, 'static, u32>>::bar::<'static, char>;
| -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found fn item
| |
| expected due to this
|
= note: expected unit type `()`
found fn item `fn() {<i8 as Foo<ReStatic, ReStatic, u32>>::bar::<ReStatic, char>}`
found fn item `fn() {<i8 as Foo<ReStatic, ReStatic>>::bar::<ReStatic, char>}`
help: use parentheses to call this function
|
LL | let x: () = <i8 as Foo<'static, 'static, u32>>::bar::<'static, char>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LL | with_signature(x, |mut y| Box::new(y.next()))
|
= note: defining type: no_region::<'_#1r, T>::{closure#0} with closure substs [
i32,
extern "rust-call" fn((std::boxed::Box<T, std::alloc::Global>,)) -> std::boxed::Box<(dyn Anything + '_#2r), std::alloc::Global>,
extern "rust-call" fn((std::boxed::Box<T>,)) -> std::boxed::Box<(dyn Anything + '_#2r)>,
(),
]
= note: number of external vids: 3
Expand Down Expand Up @@ -42,7 +42,7 @@ LL | with_signature(x, |mut y| Box::new(y.next()))
|
= note: defining type: correct_region::<'_#1r, T>::{closure#0} with closure substs [
i32,
extern "rust-call" fn((std::boxed::Box<T, std::alloc::Global>,)) -> std::boxed::Box<(dyn Anything + '_#2r), std::alloc::Global>,
extern "rust-call" fn((std::boxed::Box<T>,)) -> std::boxed::Box<(dyn Anything + '_#2r)>,
(),
]
= note: number of external vids: 3
Expand All @@ -69,7 +69,7 @@ LL | with_signature(x, |mut y| Box::new(y.next()))
|
= note: defining type: wrong_region::<'_#1r, '_#2r, T>::{closure#0} with closure substs [
i32,
extern "rust-call" fn((std::boxed::Box<T, std::alloc::Global>,)) -> std::boxed::Box<(dyn Anything + '_#3r), std::alloc::Global>,
extern "rust-call" fn((std::boxed::Box<T>,)) -> std::boxed::Box<(dyn Anything + '_#3r)>,
(),
]
= note: number of external vids: 4
Expand Down Expand Up @@ -105,7 +105,7 @@ LL | with_signature(x, |mut y| Box::new(y.next()))
|
= note: defining type: outlives_region::<'_#1r, '_#2r, T>::{closure#0} with closure substs [
i32,
extern "rust-call" fn((std::boxed::Box<T, std::alloc::Global>,)) -> std::boxed::Box<(dyn Anything + '_#3r), std::alloc::Global>,
extern "rust-call" fn((std::boxed::Box<T>,)) -> std::boxed::Box<(dyn Anything + '_#3r)>,
(),
]
= note: number of external vids: 4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LL | with_signature(x, |y| y)
|
= note: defining type: no_region::<'_#1r, T>::{closure#0} with closure substs [
i32,
extern "rust-call" fn((std::boxed::Box<T, std::alloc::Global>,)) -> std::boxed::Box<(dyn std::fmt::Debug + '_#2r), std::alloc::Global>,
extern "rust-call" fn((std::boxed::Box<T>,)) -> std::boxed::Box<(dyn std::fmt::Debug + '_#2r)>,
(),
]
= note: number of external vids: 3
Expand Down
15 changes: 15 additions & 0 deletions src/test/ui/symbol-names/verbose.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Regression test for issue #57596, where -Zverbose flag unintentionally
// affected produced symbols making it impossible to link between crates
// with a different value of the flag (for symbols involving generic
// arguments equal to defaults of their respective parameters).
//
// build-pass
// compile-flags: -Zverbose

pub fn error(msg: String) -> Box<dyn std::error::Error> {
msg.into()
}

fn main() {
error(String::new());
}

0 comments on commit 85bd745

Please sign in to comment.