Semver question: Is the non-qualified call to `.as_dyn_error()` intentional?

Abierto
#452 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
35/100
Tipo de issue
Refactorización
Claridad
Bastante claro
Estado de actividad
Tranquilo
Stack tecnológico
rust
Área
tooling

Línea de trabajo

Lee en impl/src/expand.rs lo relacionado con la llamada .as_dyn_error() generada y en src/aserror.rs el trait oculto AsDynError. Reproduce el comportamiento de resolución de métodos descrito en el issue y determina después si se admiten métodos externos. El trabajo estará terminado cuando se documente ese contrato o se decida usar una llamada totalmente cualificada, abordando el impacto en la compatibilidad.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Right now the thiserror macro will generate code that invokes the hidden AsDynError trait. However it doesn't use a fully qualified path, but instead uses method-call resolution, where an inherent method on the field type shadows the trait method.

Is this an intentional choice to allow external implementations of the method?

Context: In rootcause we got a feature request to support placing a rootcause report inside enums with thiserror impls using #[error(transparent)].

While we don't recommend this way of combining thiserror and rootcause, we do consider it a helpful feature to make migrations of large codebases easier.

We added the feature using a Deref impl, but we had to roll back the change.

However after rolling back the change, I noticed that the #[error(transparent)] code still worked. It turns out, this is because we also named our method .as_dyn_error(), so everything happened to still work.

This makes me a bit worried, as "internal" changes in thiserror can now cause accidental breakage in consumers that use both thiserror and rootcause.

It'd be good to know where you land on this. If external as_dyn_error() impls are fair game, then we will document that this is a supported (but non-recommended) way to combine rootcause with thiserror. Otherwise we'd rather you make the call fully-qualified so the behavior breaks now instead of by accident later.

Lenguaje dominante
Rust
Estrellas
5.6k
Forks
220
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de dtolnay/thiserror

Todos los issues de dtolnay/thiserror

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.