Skip to content

Commit af89eb5

Browse files
committed
Auto merge of #70832 - Centril:rollup-ixc09ve, r=Centril
Rollup of 5 pull requests Successful merges: - #70519 (Tweak output of type params and constraints in the wrong order) - #70704 (Make panic unwind the default for aarch64-*-windows-msvc targets) - #70713 (Prefer sysroot from rustc in same directory as rust-gdb) - #70739 (def_collector, visit_fn: account for no body) - #70827 (Use smaller span for suggestion restricting lifetime) Failed merges: r? @ghost
2 parents 83f8c02 + 3faec69 commit af89eb5

File tree

20 files changed

+273
-108
lines changed

20 files changed

+273
-108
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3564,6 +3564,7 @@ dependencies = [
35643564
name = "rustc_ast_passes"
35653565
version = "0.0.0"
35663566
dependencies = [
3567+
"itertools 0.8.0",
35673568
"log",
35683569
"rustc_ast",
35693570
"rustc_ast_pretty",

src/etc/rust-gdb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,16 @@
22
# Exit if anything fails
33
set -e
44

5+
# Prefer rustc in the same directory as this script
6+
DIR="$(dirname "$0")"
7+
if [ -x "$DIR/rustc" ]; then
8+
RUSTC="$DIR/rustc"
9+
else
10+
RUSTC="rustc"
11+
fi
12+
513
# Find out where the pretty printer Python module is
6-
RUSTC_SYSROOT=`rustc --print=sysroot`
14+
RUSTC_SYSROOT="$("$RUSTC" --print=sysroot)"
715
GDB_PYTHON_MODULE_DIRECTORY="$RUSTC_SYSROOT/lib/rustlib/etc"
816

917
# Run GDB with the additional arguments that load the pretty printers

src/etc/rust-gdbgui

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,16 @@ icon to start your program running.
3131
exit 0
3232
fi
3333

34+
# Prefer rustc in the same directory as this script
35+
DIR="$(dirname "$0")"
36+
if [ -x "$DIR/rustc" ]; then
37+
RUSTC="$DIR/rustc"
38+
else
39+
RUSTC="rustc"
40+
fi
41+
3442
# Find out where the pretty printer Python module is
35-
RUSTC_SYSROOT=`rustc --print=sysroot`
43+
RUSTC_SYSROOT="$("$RUSTC" --print=sysroot)"
3644
GDB_PYTHON_MODULE_DIRECTORY="$RUSTC_SYSROOT/lib/rustlib/etc"
3745

3846
# Set the environment variable `RUST_GDB` to overwrite the call to a

src/libpanic_unwind/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ cfg_if::cfg_if! {
4747
} else if #[cfg(target_os = "hermit")] {
4848
#[path = "hermit.rs"]
4949
mod real_imp;
50-
} else if #[cfg(all(target_env = "msvc", target_arch = "aarch64"))] {
51-
#[path = "dummy.rs"]
52-
mod real_imp;
5350
} else if #[cfg(target_env = "msvc")] {
5451
#[path = "seh.rs"]
5552
mod real_imp;

src/libpanic_unwind/seh.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ mod imp {
117117
}
118118
}
119119

120-
#[cfg(any(target_arch = "x86_64", target_arch = "arm"))]
120+
#[cfg(not(target_arch = "x86"))]
121121
#[macro_use]
122122
mod imp {
123123
pub type ptr_t = u32;

src/librustc_ast/ast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ pub enum GenericBound {
300300
impl GenericBound {
301301
pub fn span(&self) -> Span {
302302
match self {
303-
&GenericBound::Trait(ref t, ..) => t.span,
304-
&GenericBound::Outlives(ref l) => l.ident.span,
303+
GenericBound::Trait(ref t, ..) => t.span,
304+
GenericBound::Outlives(ref l) => l.ident.span,
305305
}
306306
}
307307
}

src/librustc_ast_passes/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ name = "rustc_ast_passes"
99
path = "lib.rs"
1010

1111
[dependencies]
12+
itertools = "0.8"
1213
log = "0.4"
1314
rustc_ast_pretty = { path = "../librustc_ast_pretty" }
1415
rustc_attr = { path = "../librustc_attr" }

src/librustc_ast_passes/ast_validation.rs

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// This pass is supposed to perform only simple checks not requiring name resolution
77
// or type checking or some other kind of complex analysis.
88

9+
use itertools::{Either, Itertools};
910
use rustc_ast::ast::*;
1011
use rustc_ast::attr;
1112
use rustc_ast::expand::is_proc_macro_attr;
@@ -14,7 +15,7 @@ use rustc_ast::visit::{self, AssocCtxt, FnCtxt, FnKind, Visitor};
1415
use rustc_ast::walk_list;
1516
use rustc_ast_pretty::pprust;
1617
use rustc_data_structures::fx::FxHashMap;
17-
use rustc_errors::{error_code, struct_span_err, Applicability};
18+
use rustc_errors::{error_code, pluralize, struct_span_err, Applicability};
1819
use rustc_parse::validate_attr;
1920
use rustc_session::lint::builtin::PATTERNS_IN_FNS_WITHOUT_BODY;
2021
use rustc_session::lint::LintBuffer;
@@ -640,31 +641,70 @@ impl<'a> AstValidator<'a> {
640641
}
641642
}
642643

644+
fn correct_generic_order_suggestion(&self, data: &AngleBracketedArgs) -> String {
645+
// Lifetimes always come first.
646+
let lt_sugg = data.args.iter().filter_map(|arg| match arg {
647+
AngleBracketedArg::Arg(lt @ GenericArg::Lifetime(_)) => {
648+
Some(pprust::to_string(|s| s.print_generic_arg(lt)))
649+
}
650+
_ => None,
651+
});
652+
let args_sugg = data.args.iter().filter_map(|a| match a {
653+
AngleBracketedArg::Arg(GenericArg::Lifetime(_)) | AngleBracketedArg::Constraint(_) => {
654+
None
655+
}
656+
AngleBracketedArg::Arg(arg) => Some(pprust::to_string(|s| s.print_generic_arg(arg))),
657+
});
658+
// Constraints always come last.
659+
let constraint_sugg = data.args.iter().filter_map(|a| match a {
660+
AngleBracketedArg::Arg(_) => None,
661+
AngleBracketedArg::Constraint(c) => {
662+
Some(pprust::to_string(|s| s.print_assoc_constraint(c)))
663+
}
664+
});
665+
format!(
666+
"<{}>",
667+
lt_sugg.chain(args_sugg).chain(constraint_sugg).collect::<Vec<String>>().join(", ")
668+
)
669+
}
670+
643671
/// Enforce generic args coming before constraints in `<...>` of a path segment.
644672
fn check_generic_args_before_constraints(&self, data: &AngleBracketedArgs) {
645673
// Early exit in case it's partitioned as it should be.
646674
if data.args.iter().is_partitioned(|arg| matches!(arg, AngleBracketedArg::Arg(_))) {
647675
return;
648676
}
649677
// Find all generic argument coming after the first constraint...
650-
let mut misplaced_args = Vec::new();
651-
let mut first = None;
652-
for arg in &data.args {
653-
match (arg, first) {
654-
(AngleBracketedArg::Arg(a), Some(_)) => misplaced_args.push(a.span()),
655-
(AngleBracketedArg::Constraint(c), None) => first = Some(c.span),
656-
(AngleBracketedArg::Arg(_), None) | (AngleBracketedArg::Constraint(_), Some(_)) => {
657-
}
658-
}
659-
}
678+
let (constraint_spans, arg_spans): (Vec<Span>, Vec<Span>) =
679+
data.args.iter().partition_map(|arg| match arg {
680+
AngleBracketedArg::Constraint(c) => Either::Left(c.span),
681+
AngleBracketedArg::Arg(a) => Either::Right(a.span()),
682+
});
683+
let args_len = arg_spans.len();
684+
let constraint_len = constraint_spans.len();
660685
// ...and then error:
661686
self.err_handler()
662687
.struct_span_err(
663-
misplaced_args.clone(),
688+
arg_spans.clone(),
664689
"generic arguments must come before the first constraint",
665690
)
666-
.span_label(first.unwrap(), "the first constraint is provided here")
667-
.span_labels(misplaced_args, "generic argument")
691+
.span_label(constraint_spans[0], &format!("constraint{}", pluralize!(constraint_len)))
692+
.span_label(
693+
*arg_spans.iter().last().unwrap(),
694+
&format!("generic argument{}", pluralize!(args_len)),
695+
)
696+
.span_labels(constraint_spans, "")
697+
.span_labels(arg_spans, "")
698+
.span_suggestion_verbose(
699+
data.span,
700+
&format!(
701+
"move the constraint{} after the generic argument{}",
702+
pluralize!(constraint_len),
703+
pluralize!(args_len)
704+
),
705+
self.correct_generic_order_suggestion(&data),
706+
Applicability::MachineApplicable,
707+
)
668708
.emit();
669709
}
670710
}

src/librustc_ast_pretty/pprust.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ impl<'a> State<'a> {
869869
}
870870
}
871871

872-
fn print_assoc_constraint(&mut self, constraint: &ast::AssocTyConstraint) {
872+
pub fn print_assoc_constraint(&mut self, constraint: &ast::AssocTyConstraint) {
873873
self.print_ident(constraint.ident);
874874
self.s.space();
875875
match &constraint.kind {
@@ -883,7 +883,7 @@ impl<'a> State<'a> {
883883
}
884884
}
885885

886-
crate fn print_generic_arg(&mut self, generic_arg: &GenericArg) {
886+
pub fn print_generic_arg(&mut self, generic_arg: &GenericArg) {
887887
match generic_arg {
888888
GenericArg::Lifetime(lt) => self.print_lifetime(*lt),
889889
GenericArg::Type(ty) => self.print_type(ty),

src/librustc_errors/diagnostic_builder.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,20 @@ impl<'a> DiagnosticBuilder<'a> {
315315
self
316316
}
317317

318+
pub fn span_suggestion_verbose(
319+
&mut self,
320+
sp: Span,
321+
msg: &str,
322+
suggestion: String,
323+
applicability: Applicability,
324+
) -> &mut Self {
325+
if !self.0.allow_suggestions {
326+
return self;
327+
}
328+
self.0.diagnostic.span_suggestion_verbose(sp, msg, suggestion, applicability);
329+
self
330+
}
331+
318332
pub fn span_suggestion_hidden(
319333
&mut self,
320334
sp: Span,

0 commit comments

Comments
 (0)