Skip to content

Commit d275739

Browse files
committed
Derive common traits for panic::Location.
Add documentation about the host/target behavior of Location::file.
1 parent a1528c4 commit d275739

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/libcore/panic.rs

+23-1
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,14 @@ impl fmt::Display for PanicInfo<'_> {
173173
///
174174
/// panic!("Normal panic");
175175
/// ```
176+
///
177+
/// # Comparisons
178+
///
179+
/// Comparisons for equality and ordering are made in file, line, then column priority. Such
180+
/// comparisons can occasionally have surprising results. See [`Location::file`]'s documentation for
181+
/// more discussion.
176182
#[lang = "panic_location"]
177-
#[derive(Debug)]
183+
#[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
178184
#[stable(feature = "panic_hooks", since = "1.10.0")]
179185
pub struct Location<'a> {
180186
file: &'a str,
@@ -252,6 +258,22 @@ impl<'a> Location<'a> {
252258

253259
/// Returns the name of the source file from which the panic originated.
254260
///
261+
/// # `&str`, not `&Path`
262+
///
263+
/// The returned name refers to a source path on the compiling system, but it isn't valid to
264+
/// represent this directly as a `&Path`. The compiled code may run on a different system with
265+
/// a different `Path` implementation than the system providing the contents and this library
266+
/// does not currently have a different "host path" type.
267+
///
268+
/// The most surprising behavior occurs when "the same" file is reachable via multiple paths in
269+
/// the module system (usually using the `#[path = "..."]` attribute or similar), which can
270+
/// cause what appears to be identical code to return differing values from this function.
271+
///
272+
/// # Cross-compilation
273+
///
274+
/// This value is not suitable for passing to `Path::new` or similar constructors when the host
275+
/// platform and target platform differ.
276+
///
255277
/// # Examples
256278
///
257279
/// ```should_panic

0 commit comments

Comments
 (0)