Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE when compiling this core change #121064

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions library/core/src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,23 @@ pub trait Write {
impl<W: Write + ?Sized> SpecWriteFmt for &mut W {
#[inline]
default fn spec_write_fmt(mut self, args: Arguments<'_>) -> Result {
if unsafe { core::intrinsics::is_val_statically_known(args) } {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_val_statically_known only supports primitives

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

feel free to PR a better error message, since I'd expect many people to run into this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Nilstrieb I suspect ICE is ICE no matter what the users try to do? That said, I don't see anything in the docs about it only supporting primitives - it does have T: Copy though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not documented, you need to look at the implementation

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can an expression be evaluated for this intrinsic? e.g. for a primitive bool:

Suggested change
if unsafe { core::intrinsics::is_val_statically_known(args) } {
if unsafe { core::intrinsics::is_val_statically_known(args.as_str().is_some()) } {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect ICE is ICE no matter what the users try to do?

No, if you use internal features such as intrinsics, then some ICEs are expected. It's not worth the effort and overhead of guarding against ICEs when users explicitly ask to fiddle with the internal details of the compiler.

if let Some(s) = args.as_str() {
return self.write_str(s);
}
}
write(&mut self, args)
}
}

impl<W: Write> SpecWriteFmt for &mut W {
#[inline]
fn spec_write_fmt(self, args: Arguments<'_>) -> Result {
if unsafe { core::intrinsics::is_val_statically_known(args) } {
if let Some(s) = args.as_str() {
return self.write_str(s);
}
}
write(self, args)
}
}
Expand Down Expand Up @@ -1582,7 +1592,13 @@ impl<'a> Formatter<'a> {
/// assert_eq!(format!("{:0>8}", Foo(2)), "Foo 2");
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result {
if unsafe { core::intrinsics::is_val_statically_known(fmt) } {
if let Some(s) = fmt.as_str() {
return self.write_str(s);
}
}
write(self.buf, fmt)
}

Expand Down Expand Up @@ -2272,7 +2288,13 @@ impl Write for Formatter<'_> {
self.buf.write_char(c)
}

#[inline]
fn write_fmt(&mut self, args: Arguments<'_>) -> Result {
if unsafe { core::intrinsics::is_val_statically_known(args) } {
if let Some(s) = args.as_str() {
return self.write_str(s);
}
}
write(self.buf, args)
}
}
Expand Down
Loading