Skip to content

Commit a89c03a

Browse files
committed
Auto merge of rust-lang#59584 - Centril:rollup, r=Centril
Rollup of 4 pull requests Successful merges: - rust-lang#58828 (libstd: deny(elided_lifetimes_in_paths)) - rust-lang#59234 (Mention `no merge policy` in the CONTRIBUTING guide) - rust-lang#59572 (Include bounds in generic re-ordering diagnostic) - rust-lang#59574 (Distinguish message for external macros depending on error level) Failed merges: r? @ghost
2 parents cee58fd + fb8396d commit a89c03a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+585
-458
lines changed

CONTRIBUTING.md

+7
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ bring those changes into the source repository.
122122

123123
Please make pull requests against the `master` branch.
124124

125+
Rust follows a no merge policy, meaning, when you encounter merge
126+
conflicts you are expected to always rebase instead of merge.
127+
E.g. always use rebase when bringing the latest changes from
128+
the master branch to your feature branch.
129+
Also, please make sure that fixup commits are squashed into other related
130+
commits with meaningful commit messages.
131+
125132
Please make sure your pull request is in compliance with Rust's style
126133
guidelines by running
127134

src/librustc_errors/emitter.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::{
66
Level, CodeSuggestion, DiagnosticBuilder, SubDiagnostic,
77
SuggestionStyle, SourceMapperDyn, DiagnosticId,
88
};
9+
use crate::Level::Error;
910
use crate::snippet::{Annotation, AnnotationType, Line, MultilineAnnotation, StyledString, Style};
1011
use crate::styled_buffer::StyledBuffer;
1112

@@ -72,6 +73,7 @@ impl Emitter for EmitterWriter {
7273

7374
self.fix_multispans_in_std_macros(&mut primary_span,
7475
&mut children,
76+
&db.level,
7577
db.handler.flags.external_macro_backtrace);
7678

7779
self.emit_messages_default(&db.level,
@@ -888,18 +890,27 @@ impl EmitterWriter {
888890
fn fix_multispans_in_std_macros(&mut self,
889891
span: &mut MultiSpan,
890892
children: &mut Vec<SubDiagnostic>,
893+
level: &Level,
891894
backtrace: bool) {
892895
let mut spans_updated = self.fix_multispan_in_std_macros(span, backtrace);
893896
for child in children.iter_mut() {
894897
spans_updated |= self.fix_multispan_in_std_macros(&mut child.span, backtrace);
895898
}
899+
let msg = if level == &Error {
900+
"this error originates in a macro outside of the current crate \
901+
(in Nightly builds, run with -Z external-macro-backtrace \
902+
for more info)".to_string()
903+
} else {
904+
"this warning originates in a macro outside of the current crate \
905+
(in Nightly builds, run with -Z external-macro-backtrace \
906+
for more info)".to_string()
907+
};
908+
896909
if spans_updated {
897910
children.push(SubDiagnostic {
898911
level: Level::Note,
899912
message: vec![
900-
("this error originates in a macro outside of the current crate \
901-
(in Nightly builds, run with -Z external-macro-backtrace \
902-
for more info)".to_string(),
913+
(msg,
903914
Style::NoStyle),
904915
],
905916
span: MultiSpan::new(),

src/librustc_passes/ast_validation.rs

+55-25
Original file line numberDiff line numberDiff line change
@@ -352,18 +352,26 @@ enum GenericPosition {
352352
}
353353

354354
fn validate_generics_order<'a>(
355+
sess: &Session,
355356
handler: &errors::Handler,
356-
generics: impl Iterator<Item = (ParamKindOrd, Span, Option<String>)>,
357+
generics: impl Iterator<
358+
Item = (
359+
ParamKindOrd,
360+
Option<&'a [GenericBound]>,
361+
Span,
362+
Option<String>
363+
),
364+
>,
357365
pos: GenericPosition,
358366
span: Span,
359367
) {
360368
let mut max_param: Option<ParamKindOrd> = None;
361369
let mut out_of_order = FxHashMap::default();
362370
let mut param_idents = vec![];
363371

364-
for (kind, span, ident) in generics {
372+
for (kind, bounds, span, ident) in generics {
365373
if let Some(ident) = ident {
366-
param_idents.push((kind, param_idents.len(), ident));
374+
param_idents.push((kind, bounds, param_idents.len(), ident));
367375
}
368376
let max_param = &mut max_param;
369377
match max_param {
@@ -377,13 +385,19 @@ fn validate_generics_order<'a>(
377385

378386
let mut ordered_params = "<".to_string();
379387
if !out_of_order.is_empty() {
380-
param_idents.sort_by_key(|&(po, i, _)| (po, i));
388+
param_idents.sort_by_key(|&(po, _, i, _)| (po, i));
381389
let mut first = true;
382-
for (_, _, ident) in param_idents {
390+
for (_, bounds, _, ident) in param_idents {
383391
if !first {
384392
ordered_params += ", ";
385393
}
386394
ordered_params += &ident;
395+
if let Some(bounds) = bounds {
396+
if !bounds.is_empty() {
397+
ordered_params += ": ";
398+
ordered_params += &pprust::bounds_to_string(&bounds);
399+
}
400+
}
387401
first = false;
388402
}
389403
}
@@ -405,7 +419,11 @@ fn validate_generics_order<'a>(
405419
if let GenericPosition::Param = pos {
406420
err.span_suggestion(
407421
span,
408-
&format!("reorder the {}s: lifetimes, then types, then consts", pos_str),
422+
&format!(
423+
"reorder the {}s: lifetimes, then types{}",
424+
pos_str,
425+
if sess.features_untracked().const_generics { ", then consts" } else { "" },
426+
),
409427
ordered_params.clone(),
410428
Applicability::MachineApplicable,
411429
);
@@ -687,13 +705,19 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
687705
match *generic_args {
688706
GenericArgs::AngleBracketed(ref data) => {
689707
walk_list!(self, visit_generic_arg, &data.args);
690-
validate_generics_order(self.err_handler(), data.args.iter().map(|arg| {
691-
(match arg {
692-
GenericArg::Lifetime(..) => ParamKindOrd::Lifetime,
693-
GenericArg::Type(..) => ParamKindOrd::Type,
694-
GenericArg::Const(..) => ParamKindOrd::Const,
695-
}, arg.span(), None)
696-
}), GenericPosition::Arg, generic_args.span());
708+
validate_generics_order(
709+
self.session,
710+
self.err_handler(),
711+
data.args.iter().map(|arg| {
712+
(match arg {
713+
GenericArg::Lifetime(..) => ParamKindOrd::Lifetime,
714+
GenericArg::Type(..) => ParamKindOrd::Type,
715+
GenericArg::Const(..) => ParamKindOrd::Const,
716+
}, None, arg.span(), None)
717+
}),
718+
GenericPosition::Arg,
719+
generic_args.span(),
720+
);
697721

698722
// Type bindings such as `Item=impl Debug` in `Iterator<Item=Debug>`
699723
// are allowed to contain nested `impl Trait`.
@@ -726,18 +750,24 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
726750
}
727751
}
728752

729-
validate_generics_order(self.err_handler(), generics.params.iter().map(|param| {
730-
let span = param.ident.span;
731-
let ident = Some(param.ident.to_string());
732-
match &param.kind {
733-
GenericParamKind::Lifetime { .. } => (ParamKindOrd::Lifetime, span, ident),
734-
GenericParamKind::Type { .. } => (ParamKindOrd::Type, span, ident),
735-
GenericParamKind::Const { ref ty } => {
736-
let ty = pprust::ty_to_string(ty);
737-
(ParamKindOrd::Const, span, Some(format!("const {}: {}", param.ident, ty)))
738-
}
739-
}
740-
}), GenericPosition::Param, generics.span);
753+
validate_generics_order(
754+
self.session,
755+
self.err_handler(),
756+
generics.params.iter().map(|param| {
757+
let ident = Some(param.ident.to_string());
758+
let (kind, ident) = match &param.kind {
759+
GenericParamKind::Lifetime { .. } => (ParamKindOrd::Lifetime, ident),
760+
GenericParamKind::Type { .. } => (ParamKindOrd::Type, ident),
761+
GenericParamKind::Const { ref ty } => {
762+
let ty = pprust::ty_to_string(ty);
763+
(ParamKindOrd::Const, Some(format!("const {}: {}", param.ident, ty)))
764+
}
765+
};
766+
(kind, Some(&*param.bounds), param.ident.span, ident)
767+
}),
768+
GenericPosition::Param,
769+
generics.span,
770+
);
741771

742772
for predicate in &generics.where_clause.predicates {
743773
if let WherePredicate::EqPredicate(ref predicate) = *predicate {

0 commit comments

Comments
 (0)