Skip to content

Commit 9772d02

Browse files
committed
Auto merge of #56623 - Centril:rollup, r=Centril
Rollup of 6 pull requests Successful merges: - #56248 (Suggest an appropriate token when encountering `pub Ident<'a>`) - #56597 (Improve the usage message for `-Z dump-mir`.) - #56599 (codegen: Fix va_list - aarch64 iOS/Windows) - #56602 (Fix the just-introduced ptr::hash docs) - #56620 (resolve: Reduce some clutter in import ambiguity errors) - #56621 (Add missing comma in Generators) Failed merges: r? @ghost
2 parents 1ccb5b2 + a8cc916 commit 9772d02

26 files changed

+195
-85
lines changed

src/doc/unstable-book/src/language-features/generators.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ closure-like semantics. Namely:
149149
* Whenever a generator is dropped it will drop all captured environment
150150
variables.
151151

152-
Note that unlike closures generators at this time cannot take any arguments.
152+
Note that unlike closures, generators at this time cannot take any arguments.
153153
That is, generators must always look like `|| { ... }`. This restriction may be
154154
lifted at a future date, the design is ongoing!
155155

src/libcore/ffi.rs

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ impl fmt::Debug for c_void {
4545
/// Basic implementation of a `va_list`.
4646
#[cfg(any(all(not(target_arch = "aarch64"), not(target_arch = "powerpc"),
4747
not(target_arch = "x86_64")),
48+
all(target_arch = "aarch4", target_os = "ios"),
4849
windows))]
4950
#[unstable(feature = "c_variadic",
5051
reason = "the `c_variadic` feature has not been properly tested on \
@@ -192,6 +193,7 @@ impl<'a> VaList<'a> {
192193
where F: for<'copy> FnOnce(VaList<'copy>) -> R {
193194
#[cfg(any(all(not(target_arch = "aarch64"), not(target_arch = "powerpc"),
194195
not(target_arch = "x86_64")),
196+
all(target_arch = "aarch4", target_os = "ios"),
195197
windows))]
196198
let mut ap = va_copy(self);
197199
#[cfg(all(any(target_arch = "aarch64", target_arch = "powerpc", target_arch = "x86_64"),

src/libcore/ptr.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -2516,8 +2516,11 @@ pub fn eq<T: ?Sized>(a: *const T, b: *const T) -> bool {
25162516
a == b
25172517
}
25182518

2519-
/// Hash the raw pointer address behind a reference, rather than the value
2520-
/// it points to.
2519+
/// Hash a raw pointer.
2520+
///
2521+
/// This can be used to hash a `&T` reference (which coerces to `*const T` implicitly)
2522+
/// by its address rather than the value it points to
2523+
/// (which is what the `Hash for &T` implementation does).
25212524
///
25222525
/// # Examples
25232526
///

src/librustc/session/config.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,13 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
12721272
arg_align_attributes: bool = (false, parse_bool, [TRACKED],
12731273
"emit align metadata for reference arguments"),
12741274
dump_mir: Option<String> = (None, parse_opt_string, [UNTRACKED],
1275-
"dump MIR state at various points in transforms"),
1275+
"dump MIR state to file.
1276+
`val` is used to select which passes and functions to dump. For example:
1277+
`all` matches all passes and functions,
1278+
`foo` matches all passes for functions whose name contains 'foo',
1279+
`foo & ConstProp` only the 'ConstProp' pass for function names containing 'foo',
1280+
`foo | bar` all passes for function names containing 'foo' or 'bar'."),
1281+
12761282
dump_mir_dir: String = (String::from("mir_dump"), parse_string, [UNTRACKED],
12771283
"the directory the MIR is dumped into"),
12781284
dump_mir_graphviz: bool = (false, parse_bool, [UNTRACKED],

src/librustc_codegen_llvm/va_arg.rs

+26-10
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,30 @@ pub(super) fn emit_va_arg(
105105
) -> &'ll Value {
106106
// Determine the va_arg implementation to use. The LLVM va_arg instruction
107107
// is lacking in some instances, so we should only use it as a fallback.
108+
let target = &bx.cx.tcx.sess.target.target;
108109
let arch = &bx.cx.tcx.sess.target.target.arch;
109-
match (&**arch,
110-
bx.cx.tcx.sess.target.target.options.is_like_windows) {
110+
match (&**arch, target.options.is_like_windows) {
111+
// Windows x86
111112
("x86", true) => {
112113
emit_ptr_va_arg(bx, addr, target_ty, false,
113114
Align::from_bytes(4).unwrap(), false)
114115
}
116+
// Generic x86
117+
("x86", _) => {
118+
emit_ptr_va_arg(bx, addr, target_ty, false,
119+
Align::from_bytes(4).unwrap(), true)
120+
}
121+
// Windows Aarch64
122+
("aarch4", true) => {
123+
emit_ptr_va_arg(bx, addr, target_ty, false,
124+
Align::from_bytes(8).unwrap(), false)
125+
}
126+
// iOS Aarch64
127+
("aarch4", _) if target.target_os == "ios" => {
128+
emit_ptr_va_arg(bx, addr, target_ty, false,
129+
Align::from_bytes(8).unwrap(), true)
130+
}
131+
// Windows x86_64
115132
("x86_64", true) => {
116133
let target_ty_size = bx.cx.size_of(target_ty).bytes();
117134
let indirect = if target_ty_size > 8 || !target_ty_size.is_power_of_two() {
@@ -122,15 +139,14 @@ pub(super) fn emit_va_arg(
122139
emit_ptr_va_arg(bx, addr, target_ty, indirect,
123140
Align::from_bytes(8).unwrap(), false)
124141
}
125-
("x86", false) => {
126-
emit_ptr_va_arg(bx, addr, target_ty, false,
127-
Align::from_bytes(4).unwrap(), true)
128-
}
142+
// For all other architecture/OS combinations fall back to using
143+
// the LLVM va_arg instruction.
144+
// https://llvm.org/docs/LangRef.html#va-arg-instruction
129145
_ => {
130-
let va_list = if (bx.tcx().sess.target.target.arch == "aarch64" ||
131-
bx.tcx().sess.target.target.arch == "x86_64" ||
132-
bx.tcx().sess.target.target.arch == "powerpc") &&
133-
!bx.tcx().sess.target.target.options.is_like_windows {
146+
let va_list = if (target.arch == "aarch64" ||
147+
target.arch == "x86_64" ||
148+
target.arch == "powerpc") &&
149+
!target.options.is_like_windows {
134150
bx.load(addr.immediate(), bx.tcx().data_layout.pointer_align.abi)
135151
} else {
136152
addr.immediate()

src/librustc_resolve/resolve_imports.rs

+23-19
Original file line numberDiff line numberDiff line change
@@ -843,14 +843,16 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
843843
self.current_module = directive.parent_scope.module;
844844

845845
let orig_vis = directive.vis.replace(ty::Visibility::Invisible);
846+
let prev_ambiguity_errors_len = self.ambiguity_errors.len();
846847
let path_res = self.resolve_path(&directive.module_path, None, &directive.parent_scope,
847848
true, directive.span, directive.crate_lint());
849+
let no_ambiguity = self.ambiguity_errors.len() == prev_ambiguity_errors_len;
848850
directive.vis.set(orig_vis);
849851
let module = match path_res {
850852
PathResult::Module(module) => {
851853
// Consistency checks, analogous to `finalize_current_module_macro_resolutions`.
852854
if let Some(initial_module) = directive.imported_module.get() {
853-
if module != initial_module && self.ambiguity_errors.is_empty() {
855+
if module != initial_module && no_ambiguity {
854856
span_bug!(directive.span, "inconsistent resolution for an import");
855857
}
856858
} else {
@@ -864,30 +866,32 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
864866
module
865867
}
866868
PathResult::Failed(span, msg, false) => {
867-
assert!(!self.ambiguity_errors.is_empty() ||
868-
directive.imported_module.get().is_none());
869-
resolve_error(self, span, ResolutionError::FailedToResolve(&msg));
869+
if no_ambiguity {
870+
assert!(directive.imported_module.get().is_none());
871+
resolve_error(self, span, ResolutionError::FailedToResolve(&msg));
872+
}
870873
return None;
871874
}
872875
PathResult::Failed(span, msg, true) => {
873-
assert!(!self.ambiguity_errors.is_empty() ||
874-
directive.imported_module.get().is_none());
875-
return if let Some((suggested_path, note)) = self.make_path_suggestion(
876-
span, directive.module_path.clone(), &directive.parent_scope
877-
) {
878-
Some((
879-
span,
880-
format!("did you mean `{}`?", Segment::names_to_string(&suggested_path)),
881-
note,
882-
))
883-
} else {
884-
Some((span, msg, None))
885-
};
876+
if no_ambiguity {
877+
assert!(directive.imported_module.get().is_none());
878+
return Some(match self.make_path_suggestion(span, directive.module_path.clone(),
879+
&directive.parent_scope) {
880+
Some((suggestion, note)) => (
881+
span,
882+
format!("did you mean `{}`?", Segment::names_to_string(&suggestion)),
883+
note,
884+
),
885+
None => (span, msg, None),
886+
});
887+
}
888+
return None;
886889
}
887890
PathResult::NonModule(path_res) if path_res.base_def() == Def::Err => {
891+
if no_ambiguity {
892+
assert!(directive.imported_module.get().is_none());
893+
}
888894
// The error was already reported earlier.
889-
assert!(!self.ambiguity_errors.is_empty() ||
890-
directive.imported_module.get().is_none());
891895
return None;
892896
}
893897
PathResult::Indeterminate | PathResult::NonModule(..) => unreachable!(),

src/libsyntax/parse/parser.rs

+48-20
Original file line numberDiff line numberDiff line change
@@ -5811,20 +5811,14 @@ impl<'a> Parser<'a> {
58115811
}
58125812

58135813
fn complain_if_pub_macro(&mut self, vis: &VisibilityKind, sp: Span) {
5814-
if let Err(mut err) = self.complain_if_pub_macro_diag(vis, sp) {
5815-
err.emit();
5816-
}
5817-
}
5818-
5819-
fn complain_if_pub_macro_diag(&mut self, vis: &VisibilityKind, sp: Span) -> PResult<'a, ()> {
58205814
match *vis {
5821-
VisibilityKind::Inherited => Ok(()),
5815+
VisibilityKind::Inherited => {}
58225816
_ => {
58235817
let is_macro_rules: bool = match self.token {
58245818
token::Ident(sid, _) => sid.name == Symbol::intern("macro_rules"),
58255819
_ => false,
58265820
};
5827-
if is_macro_rules {
5821+
let mut err = if is_macro_rules {
58285822
let mut err = self.diagnostic()
58295823
.struct_span_err(sp, "can't qualify macro_rules invocation with `pub`");
58305824
err.span_suggestion_with_applicability(
@@ -5833,13 +5827,14 @@ impl<'a> Parser<'a> {
58335827
"#[macro_export]".to_owned(),
58345828
Applicability::MaybeIncorrect // speculative
58355829
);
5836-
Err(err)
5830+
err
58375831
} else {
58385832
let mut err = self.diagnostic()
58395833
.struct_span_err(sp, "can't qualify macro invocation with `pub`");
58405834
err.help("try adjusting the macro to put `pub` inside the invocation");
5841-
Err(err)
5842-
}
5835+
err
5836+
};
5837+
err.emit();
58435838
}
58445839
}
58455840
}
@@ -6148,9 +6143,6 @@ impl<'a> Parser<'a> {
61486143

61496144
fn consume_block(&mut self, delim: token::DelimToken) {
61506145
let mut brace_depth = 0;
6151-
if !self.eat(&token::OpenDelim(delim)) {
6152-
return;
6153-
}
61546146
loop {
61556147
if self.eat(&token::OpenDelim(delim)) {
61566148
brace_depth += 1;
@@ -6161,7 +6153,7 @@ impl<'a> Parser<'a> {
61616153
brace_depth -= 1;
61626154
continue;
61636155
}
6164-
} else if self.eat(&token::Eof) || self.eat(&token::CloseDelim(token::NoDelim)) {
6156+
} else if self.token == token::Eof || self.eat(&token::CloseDelim(token::NoDelim)) {
61656157
return;
61666158
} else {
61676159
self.bump();
@@ -7410,17 +7402,27 @@ impl<'a> Parser<'a> {
74107402
return Err(err);
74117403
} else if self.look_ahead(1, |t| *t == token::OpenDelim(token::Paren)) {
74127404
let ident = self.parse_ident().unwrap();
7405+
self.bump(); // `(`
7406+
let kw_name = if let Ok(Some(_)) = self.parse_self_arg() {
7407+
"method"
7408+
} else {
7409+
"function"
7410+
};
74137411
self.consume_block(token::Paren);
7414-
let (kw, kw_name, ambiguous) = if self.check(&token::RArrow) ||
7415-
self.check(&token::OpenDelim(token::Brace))
7416-
{
7417-
("fn", "method", false)
7412+
let (kw, kw_name, ambiguous) = if self.check(&token::RArrow) {
7413+
self.eat_to_tokens(&[&token::OpenDelim(token::Brace)]);
7414+
self.bump(); // `{`
7415+
("fn", kw_name, false)
7416+
} else if self.check(&token::OpenDelim(token::Brace)) {
7417+
self.bump(); // `{`
7418+
("fn", kw_name, false)
74187419
} else if self.check(&token::Colon) {
74197420
let kw = "struct";
74207421
(kw, kw, false)
74217422
} else {
7422-
("fn` or `struct", "method or struct", true)
7423+
("fn` or `struct", "function or struct", true)
74237424
};
7425+
self.consume_block(token::Brace);
74247426

74257427
let msg = format!("missing `{}` for {} definition", kw, kw_name);
74267428
let mut err = self.diagnostic().struct_span_err(sp, &msg);
@@ -7447,6 +7449,32 @@ impl<'a> Parser<'a> {
74477449
}
74487450
}
74497451
return Err(err);
7452+
} else if self.look_ahead(1, |t| *t == token::Lt) {
7453+
let ident = self.parse_ident().unwrap();
7454+
self.eat_to_tokens(&[&token::Gt]);
7455+
self.bump(); // `>`
7456+
let (kw, kw_name, ambiguous) = if self.eat(&token::OpenDelim(token::Paren)) {
7457+
if let Ok(Some(_)) = self.parse_self_arg() {
7458+
("fn", "method", false)
7459+
} else {
7460+
("fn", "function", false)
7461+
}
7462+
} else if self.check(&token::OpenDelim(token::Brace)) {
7463+
("struct", "struct", false)
7464+
} else {
7465+
("fn` or `struct", "function or struct", true)
7466+
};
7467+
let msg = format!("missing `{}` for {} definition", kw, kw_name);
7468+
let mut err = self.diagnostic().struct_span_err(sp, &msg);
7469+
if !ambiguous {
7470+
err.span_suggestion_short_with_applicability(
7471+
sp,
7472+
&format!("add `{}` here to parse `{}` as a public {}", kw, ident, kw_name),
7473+
format!(" {} ", kw),
7474+
Applicability::MachineApplicable,
7475+
);
7476+
}
7477+
return Err(err);
74507478
}
74517479
}
74527480
self.parse_macro_use_or_failure(attrs, macros_allowed, attributes_allowed, lo, visibility)

src/test/ui/imports/issue-56125.rs

-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@
77
mod m1 {
88
use issue_56125::last_segment::*;
99
//~^ ERROR `issue_56125` is ambiguous
10-
//~| ERROR unresolved import `issue_56125::last_segment`
1110
}
1211

1312
mod m2 {
1413
use issue_56125::non_last_segment::non_last_segment::*;
1514
//~^ ERROR `issue_56125` is ambiguous
16-
//~| ERROR failed to resolve: could not find `non_last_segment` in `issue_56125`
1715
}
1816

1917
mod m3 {
+7-19
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
1-
error[E0433]: failed to resolve: could not find `non_last_segment` in `issue_56125`
2-
--> $DIR/issue-56125.rs:14:22
3-
|
4-
LL | use issue_56125::non_last_segment::non_last_segment::*;
5-
| ^^^^^^^^^^^^^^^^ could not find `non_last_segment` in `issue_56125`
6-
7-
error[E0432]: unresolved import `issue_56125::last_segment`
8-
--> $DIR/issue-56125.rs:8:22
9-
|
10-
LL | use issue_56125::last_segment::*;
11-
| ^^^^^^^^^^^^ could not find `last_segment` in `issue_56125`
12-
131
error[E0432]: unresolved import `empty::issue_56125`
14-
--> $DIR/issue-56125.rs:21:9
2+
--> $DIR/issue-56125.rs:19:9
153
|
164
LL | use empty::issue_56125; //~ ERROR unresolved import `empty::issue_56125`
175
| ^^^^^^^^^^^^^^^^^^ no `issue_56125` in `m3::empty`
@@ -32,36 +20,36 @@ LL | use issue_56125::last_segment::*;
3220
= help: use `self::issue_56125` to refer to this module unambiguously
3321

3422
error[E0659]: `issue_56125` is ambiguous (name vs any other name during import resolution)
35-
--> $DIR/issue-56125.rs:14:9
23+
--> $DIR/issue-56125.rs:13:9
3624
|
3725
LL | use issue_56125::non_last_segment::non_last_segment::*;
3826
| ^^^^^^^^^^^ ambiguous name
3927
|
4028
= note: `issue_56125` could refer to an extern crate passed with `--extern`
4129
= help: use `::issue_56125` to refer to this extern crate unambiguously
4230
note: `issue_56125` could also refer to the module imported here
43-
--> $DIR/issue-56125.rs:14:9
31+
--> $DIR/issue-56125.rs:13:9
4432
|
4533
LL | use issue_56125::non_last_segment::non_last_segment::*;
4634
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4735
= help: use `self::issue_56125` to refer to this module unambiguously
4836

4937
error[E0659]: `issue_56125` is ambiguous (name vs any other name during import resolution)
50-
--> $DIR/issue-56125.rs:22:9
38+
--> $DIR/issue-56125.rs:20:9
5139
|
5240
LL | use issue_56125::*; //~ ERROR `issue_56125` is ambiguous
5341
| ^^^^^^^^^^^ ambiguous name
5442
|
5543
= note: `issue_56125` could refer to an extern crate passed with `--extern`
5644
= help: use `::issue_56125` to refer to this extern crate unambiguously
5745
note: `issue_56125` could also refer to the unresolved item imported here
58-
--> $DIR/issue-56125.rs:21:9
46+
--> $DIR/issue-56125.rs:19:9
5947
|
6048
LL | use empty::issue_56125; //~ ERROR unresolved import `empty::issue_56125`
6149
| ^^^^^^^^^^^^^^^^^^
6250
= help: use `self::issue_56125` to refer to this unresolved item unambiguously
6351

64-
error: aborting due to 6 previous errors
52+
error: aborting due to 4 previous errors
6553

66-
Some errors occurred: E0432, E0433, E0659.
54+
Some errors occurred: E0432, E0659.
6755
For more information about an error, try `rustc --explain E0432`.

src/test/ui/pub/pub-ident-fn-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
pub foo(s: usize) { bar() }
12-
//~^ ERROR missing `fn` for method definition
12+
//~^ ERROR missing `fn` for function definition
1313

1414
fn main() {
1515
foo(2);

0 commit comments

Comments
 (0)