diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2021-09-16 10:57:20 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-16 10:57:20 -0700 |
| commit | 14eb87dd26ca4128ae5fcaa3b1f448dfd15a06ba (patch) | |
| tree | e4b558927972721421b7dae7069f2a94681fa5c6 /compiler | |
| parent | b66c9c3ac17a0b8a3053d03e1d1990595fd2a019 (diff) | |
| parent | 97621162996c0746a528edaddb43c984e15a3d51 (diff) | |
| download | rust-14eb87dd26ca4128ae5fcaa3b1f448dfd15a06ba.tar.gz rust-14eb87dd26ca4128ae5fcaa3b1f448dfd15a06ba.zip | |
Rollup merge of #88892 - estebank:trait-objects, r=petrochenkov
Move object safety suggestions to the end of the error
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_infer/src/traits/error_reporting/mod.rs | 12 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/traits/mod.rs | 4 |
2 files changed, 10 insertions, 6 deletions
diff --git a/compiler/rustc_infer/src/traits/error_reporting/mod.rs b/compiler/rustc_infer/src/traits/error_reporting/mod.rs index d0bd508bc25..9dbfa3a850b 100644 --- a/compiler/rustc_infer/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/traits/error_reporting/mod.rs @@ -83,10 +83,6 @@ pub fn report_object_safety_error( messages.push(msg.clone()); } } - if trait_span.is_some() { - // Only provide the help if its a local trait, otherwise it's not actionable. - violation.solution(&mut err); - } } } let has_multi_span = !multi_span.is_empty(); @@ -104,5 +100,13 @@ pub fn report_object_safety_error( to be resolvable dynamically; for more information visit \ <https://doc.rust-lang.org/reference/items/traits.html#object-safety>", ); + if trait_span.is_some() { + let mut reported_violations: Vec<_> = reported_violations.into_iter().collect(); + reported_violations.sort(); + for violation in reported_violations { + // Only provide the help if its a local trait, otherwise it's not actionable. + violation.solution(&mut err); + } + } err } diff --git a/compiler/rustc_middle/src/traits/mod.rs b/compiler/rustc_middle/src/traits/mod.rs index 07c2ffac8c7..fc88b95bc67 100644 --- a/compiler/rustc_middle/src/traits/mod.rs +++ b/compiler/rustc_middle/src/traits/mod.rs @@ -730,7 +730,7 @@ pub struct ImplSourceTraitAliasData<'tcx, N> { pub nested: Vec<N>, } -#[derive(Clone, Debug, PartialEq, Eq, Hash, HashStable)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, HashStable, PartialOrd, Ord)] pub enum ObjectSafetyViolation { /// `Self: Sized` declared on the trait. SizedSelf(SmallVec<[Span; 1]>), @@ -879,7 +879,7 @@ impl ObjectSafetyViolation { } /// Reasons a method might not be object-safe. -#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable, PartialOrd, Ord)] pub enum MethodViolationCode { /// e.g., `fn foo()` StaticMethod(Option<(&'static str, Span)>, Span, bool /* has args */), |
