Skip to content

Commit af89eb5

Browse files
committed
Auto merge of rust-lang#70832 - Centril:rollup-ixc09ve, r=Centril
Rollup of 5 pull requests Successful merges: - rust-lang#70519 (Tweak output of type params and constraints in the wrong order) - rust-lang#70704 (Make panic unwind the default for aarch64-*-windows-msvc targets) - rust-lang#70713 (Prefer sysroot from rustc in same directory as rust-gdb) - rust-lang#70739 (def_collector, visit_fn: account for no body) - rust-lang#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

+1
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

+9-1
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

+9-1
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

-3
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

+1-1
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

+2-2
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

+1
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

+54-14
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

+2-2
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

+14
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,

src/librustc_mir/borrow_check/diagnostics/explain_borrow.rs

+16-27
Original file line numberDiff line numberDiff line change
@@ -208,45 +208,34 @@ impl BorrowExplanation {
208208
);
209209
};
210210

211-
self.add_lifetime_bound_suggestion_to_diagnostic(
212-
tcx,
213-
err,
214-
&category,
215-
span,
216-
region_name,
217-
);
211+
self.add_lifetime_bound_suggestion_to_diagnostic(err, &category, span, region_name);
218212
}
219213
_ => {}
220214
}
221215
}
222-
pub(in crate::borrow_check) fn add_lifetime_bound_suggestion_to_diagnostic<'tcx>(
216+
pub(in crate::borrow_check) fn add_lifetime_bound_suggestion_to_diagnostic(
223217
&self,
224-
tcx: TyCtxt<'tcx>,
225218
err: &mut DiagnosticBuilder<'_>,
226219
category: &ConstraintCategory,
227220
span: Span,
228221
region_name: &RegionName,
229222
) {
230223
if let ConstraintCategory::OpaqueType = category {
231-
if let Ok(snippet) = tcx.sess.source_map().span_to_snippet(span) {
232-
let suggestable_name = if region_name.was_named() {
233-
region_name.to_string()
234-
} else {
235-
"'_".to_string()
236-
};
224+
let suggestable_name =
225+
if region_name.was_named() { region_name.to_string() } else { "'_".to_string() };
237226

238-
err.span_suggestion(
239-
span,
240-
&format!(
241-
"you can add a bound to the {}to make it last less than \
242-
`'static` and match `{}`",
243-
category.description(),
244-
region_name,
245-
),
246-
format!("{} + {}", snippet, suggestable_name),
247-
Applicability::Unspecified,
248-
);
249-
}
227+
let msg = format!(
228+
"you can add a bound to the {}to make it last less than `'static` and match `{}`",
229+
category.description(),
230+
region_name,
231+
);
232+
233+
err.span_suggestion_verbose(
234+
span.shrink_to_hi(),
235+
&msg,
236+
format!(" + {}", suggestable_name),
237+
Applicability::Unspecified,
238+
);
250239
}
251240
}
252241
}

src/librustc_resolve/def_collector.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use log::debug;
22
use rustc_ast::ast::*;
33
use rustc_ast::token::{self, Token};
44
use rustc_ast::visit::{self, FnKind};
5+
use rustc_ast::walk_list;
56
use rustc_expand::expand::AstFragment;
67
use rustc_hir::def_id::LocalDefId;
78
use rustc_hir::definitions::*;
@@ -117,10 +118,8 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
117118
// we must mirror everything that `visit::walk_fn` below does.
118119
self.visit_fn_header(&sig.header);
119120
visit::walk_fn_decl(self, &sig.decl);
120-
if let Some(body) = body {
121-
let closure_def = self.create_def(closure_id, DefPathData::ClosureExpr, span);
122-
self.with_parent(closure_def, |this| this.visit_block(body));
123-
}
121+
let closure_def = self.create_def(closure_id, DefPathData::ClosureExpr, span);
122+
self.with_parent(closure_def, |this| walk_list!(this, visit_block, body));
124123
return;
125124
}
126125
}

src/librustc_target/spec/aarch64_pc_windows_msvc.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
use crate::spec::{LinkerFlavor, PanicStrategy, Target, TargetResult};
1+
use crate::spec::{LinkerFlavor, Target, TargetResult};
22

33
pub fn target() -> TargetResult {
44
let mut base = super::windows_msvc_base::opts();
55
base.max_atomic_width = Some(64);
66
base.has_elf_tls = true;
77
base.features = "+neon,+fp-armv8".to_string();
88

9-
// FIXME: this shouldn't be panic=abort, it should be panic=unwind
10-
base.panic_strategy = PanicStrategy::Abort;
11-
129
Ok(Target {
1310
llvm_target: "aarch64-pc-windows-msvc".to_string(),
1411
target_endian: "little".to_string(),

src/librustc_target/spec/aarch64_uwp_windows_msvc.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
use crate::spec::{LinkerFlavor, PanicStrategy, Target, TargetResult};
1+
use crate::spec::{LinkerFlavor, Target, TargetResult};
22

33
pub fn target() -> TargetResult {
44
let mut base = super::windows_uwp_msvc_base::opts();
55
base.max_atomic_width = Some(64);
66
base.has_elf_tls = true;
77

8-
// FIXME: this shouldn't be panic=abort, it should be panic=unwind
9-
base.panic_strategy = PanicStrategy::Abort;
10-
118
Ok(Target {
129
llvm_target: "aarch64-pc-windows-msvc".to_string(),
1310
target_endian: "little".to_string(),

src/test/ui/impl-trait/does-not-live-long-enough.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ LL | }
1414
help: you can add a bound to the opaque type to make it last less than `'static` and match `'a`
1515
|
1616
LL | fn started_with<'a>(&'a self, prefix: &'a str) -> impl Iterator<Item=&'a str> + 'a {
17-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17+
| ^^^^
1818

1919
error: aborting due to previous error
2020

src/test/ui/parser/issue-32214.stderr

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ error: generic arguments must come before the first constraint
44
LL | pub fn test<W, I: Trait<Item=(), W> >() {}
55
| ------- ^ generic argument
66
| |
7-
| the first constraint is provided here
7+
| constraint
8+
|
9+
help: move the constraint after the generic argument
10+
|
11+
LL | pub fn test<W, I: Trait<W, Item = ()> >() {}
12+
| ^^^^^^^^^^^^^^
813

914
error: aborting due to previous error
1015

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// edition:2018
2+
3+
async fn free(); //~ ERROR without a body
4+
5+
struct A;
6+
impl A {
7+
async fn inherent(); //~ ERROR without body
8+
}
9+
10+
trait B {
11+
async fn associated();
12+
//~^ ERROR cannot be declared `async`
13+
}
14+
impl B for A {
15+
async fn associated(); //~ ERROR without body
16+
//~^ ERROR cannot be declared `async`
17+
//~| ERROR incompatible type for trait
18+
}
19+
20+
fn main() {}

0 commit comments

Comments
 (0)