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

Rollup of 4 pull requests #59579

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ bring those changes into the source repository.

Please make pull requests against the `master` branch.

Rust follows a no merge policy, meaning, when you encounter merge
conflicts you are expected to always rebase instead of merge.
E.g. always use rebase when bringing the latest changes from
the master branch to your feature branch.
Also, please make sure that fixup commits are squashed into other related
commits with meaningful commit messages.

Please make sure your pull request is in compliance with Rust's style
guidelines by running

Expand Down
17 changes: 14 additions & 3 deletions src/librustc_errors/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{
Level, CodeSuggestion, DiagnosticBuilder, SubDiagnostic,
SuggestionStyle, SourceMapperDyn, DiagnosticId,
};
use crate::Level::Error;
use crate::snippet::{Annotation, AnnotationType, Line, MultilineAnnotation, StyledString, Style};
use crate::styled_buffer::StyledBuffer;

Expand Down Expand Up @@ -72,6 +73,7 @@ impl Emitter for EmitterWriter {

self.fix_multispans_in_std_macros(&mut primary_span,
&mut children,
&db.level,
db.handler.flags.external_macro_backtrace);

self.emit_messages_default(&db.level,
Expand Down Expand Up @@ -888,18 +890,27 @@ impl EmitterWriter {
fn fix_multispans_in_std_macros(&mut self,
span: &mut MultiSpan,
children: &mut Vec<SubDiagnostic>,
level: &Level,
backtrace: bool) {
let mut spans_updated = self.fix_multispan_in_std_macros(span, backtrace);
for child in children.iter_mut() {
spans_updated |= self.fix_multispan_in_std_macros(&mut child.span, backtrace);
}
let msg = if level == &Error {
"this error originates in a macro outside of the current crate \
(in Nightly builds, run with -Z external-macro-backtrace \
for more info)".to_string()
} else {
"this warning originates in a macro outside of the current crate \
(in Nightly builds, run with -Z external-macro-backtrace \
for more info)".to_string()
};

if spans_updated {
children.push(SubDiagnostic {
level: Level::Note,
message: vec![
("this error originates in a macro outside of the current crate \
(in Nightly builds, run with -Z external-macro-backtrace \
for more info)".to_string(),
(msg,
Style::NoStyle),
],
span: MultiSpan::new(),
Expand Down
80 changes: 55 additions & 25 deletions src/librustc_passes/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,18 +352,26 @@ enum GenericPosition {
}

fn validate_generics_order<'a>(
sess: &Session,
handler: &errors::Handler,
generics: impl Iterator<Item = (ParamKindOrd, Span, Option<String>)>,
generics: impl Iterator<
Item = (
ParamKindOrd,
Option<&'a [GenericBound]>,
Span,
Option<String>
),
>,
pos: GenericPosition,
span: Span,
) {
let mut max_param: Option<ParamKindOrd> = None;
let mut out_of_order = FxHashMap::default();
let mut param_idents = vec![];

for (kind, span, ident) in generics {
for (kind, bounds, span, ident) in generics {
if let Some(ident) = ident {
param_idents.push((kind, param_idents.len(), ident));
param_idents.push((kind, bounds, param_idents.len(), ident));
}
let max_param = &mut max_param;
match max_param {
Expand All @@ -377,13 +385,19 @@ fn validate_generics_order<'a>(

let mut ordered_params = "<".to_string();
if !out_of_order.is_empty() {
param_idents.sort_by_key(|&(po, i, _)| (po, i));
param_idents.sort_by_key(|&(po, _, i, _)| (po, i));
let mut first = true;
for (_, _, ident) in param_idents {
for (_, bounds, _, ident) in param_idents {
if !first {
ordered_params += ", ";
}
ordered_params += &ident;
if let Some(bounds) = bounds {
if !bounds.is_empty() {
ordered_params += ": ";
ordered_params += &pprust::bounds_to_string(&bounds);
}
}
first = false;
}
}
Expand All @@ -405,7 +419,11 @@ fn validate_generics_order<'a>(
if let GenericPosition::Param = pos {
err.span_suggestion(
span,
&format!("reorder the {}s: lifetimes, then types, then consts", pos_str),
&format!(
"reorder the {}s: lifetimes, then types{}",
pos_str,
if sess.features_untracked().const_generics { ", then consts" } else { "" },
),
ordered_params.clone(),
Applicability::MachineApplicable,
);
Expand Down Expand Up @@ -687,13 +705,19 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
match *generic_args {
GenericArgs::AngleBracketed(ref data) => {
walk_list!(self, visit_generic_arg, &data.args);
validate_generics_order(self.err_handler(), data.args.iter().map(|arg| {
(match arg {
GenericArg::Lifetime(..) => ParamKindOrd::Lifetime,
GenericArg::Type(..) => ParamKindOrd::Type,
GenericArg::Const(..) => ParamKindOrd::Const,
}, arg.span(), None)
}), GenericPosition::Arg, generic_args.span());
validate_generics_order(
self.session,
self.err_handler(),
data.args.iter().map(|arg| {
(match arg {
GenericArg::Lifetime(..) => ParamKindOrd::Lifetime,
GenericArg::Type(..) => ParamKindOrd::Type,
GenericArg::Const(..) => ParamKindOrd::Const,
}, None, arg.span(), None)
}),
GenericPosition::Arg,
generic_args.span(),
);

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

validate_generics_order(self.err_handler(), generics.params.iter().map(|param| {
let span = param.ident.span;
let ident = Some(param.ident.to_string());
match &param.kind {
GenericParamKind::Lifetime { .. } => (ParamKindOrd::Lifetime, span, ident),
GenericParamKind::Type { .. } => (ParamKindOrd::Type, span, ident),
GenericParamKind::Const { ref ty } => {
let ty = pprust::ty_to_string(ty);
(ParamKindOrd::Const, span, Some(format!("const {}: {}", param.ident, ty)))
}
}
}), GenericPosition::Param, generics.span);
validate_generics_order(
self.session,
self.err_handler(),
generics.params.iter().map(|param| {
let ident = Some(param.ident.to_string());
let (kind, ident) = match &param.kind {
GenericParamKind::Lifetime { .. } => (ParamKindOrd::Lifetime, ident),
GenericParamKind::Type { .. } => (ParamKindOrd::Type, ident),
GenericParamKind::Const { ref ty } => {
let ty = pprust::ty_to_string(ty);
(ParamKindOrd::Const, Some(format!("const {}: {}", param.ident, ty)))
}
};
(kind, Some(&*param.bounds), param.ident.span, ident)
}),
GenericPosition::Param,
generics.span,
);

for predicate in &generics.where_clause.predicates {
if let WherePredicate::EqPredicate(ref predicate) = *predicate {
Expand Down
Loading