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 5 pull requests #71978

Closed
wants to merge 19 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
22 changes: 11 additions & 11 deletions src/liballoc/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
//! The internal iterator over the argument has not been advanced by the time
//! the first `{}` is seen, so it prints the first argument. Then upon reaching
//! the second `{}`, the iterator has advanced forward to the second argument.
//! Essentially, parameters which explicitly name their argument do not affect
//! parameters which do not name an argument in terms of positional specifiers.
//! Essentially, parameters that explicitly name their argument do not affect
//! parameters that do not name an argument in terms of positional specifiers.
//!
//! A format string is required to use all of its arguments, otherwise it is a
//! compile-time error. You may refer to the same argument more than once in the
Expand All @@ -60,7 +60,7 @@
//! ## Named parameters
//!
//! Rust itself does not have a Python-like equivalent of named parameters to a
//! function, but the [`format!`] macro is a syntax extension which allows it to
//! function, but the [`format!`] macro is a syntax extension that allows it to
//! leverage named parameters. Named parameters are listed at the end of the
//! argument list and have the syntax:
//!
Expand All @@ -77,7 +77,7 @@
//! ```
//!
//! It is not valid to put positional parameters (those without names) after
//! arguments which have names. Like with positional parameters, it is not
//! arguments that have names. Like with positional parameters, it is not
//! valid to provide named parameters that are unused by the format string.
//!
//! # Formatting Parameters
Expand Down Expand Up @@ -130,7 +130,7 @@
//!
//! The default [fill/alignment](#fillalignment) for non-numerics is a space and
//! left-aligned. The
//! defaults for numeric formatters is also a space but with right-alignment. If
//! default for numeric formatters is also a space character but with right-alignment. If
//! the `0` flag (see below) is specified for numerics, then the implicit fill character is
//! `0`.
//!
Expand Down Expand Up @@ -161,7 +161,7 @@
//! `Signed` trait. This flag indicates that the correct sign (`+` or `-`)
//! should always be printed.
//! * `-` - Currently not used
//! * `#` - This flag is indicates that the "alternate" form of printing should
//! * `#` - This flag indicates that the "alternate" form of printing should
//! be used. The alternate forms are:
//! * `#?` - pretty-print the [`Debug`] formatting
//! * `#x` - precedes the argument with a `0x`
Expand All @@ -173,9 +173,9 @@
//! like `{:08}` would yield `00000001` for the integer `1`, while the
//! same format would yield `-0000001` for the integer `-1`. Notice that
//! the negative version has one fewer zero than the positive version.
//! Note that padding zeroes are always placed after the sign (if any)
//! Note that padding zeros are always placed after the sign (if any)
//! and before the digits. When used together with the `#` flag, a similar
//! rule applies: padding zeroes are inserted after the prefix but before
//! rule applies: padding zeros are inserted after the prefix but before
//! the digits. The prefix is included in the total width.
//!
//! ## Precision
Expand Down Expand Up @@ -251,7 +251,7 @@
//!
//! In some programming languages, the behavior of string formatting functions
//! depends on the operating system's locale setting. The format functions
//! provided by Rust's standard library do not have any concept of locale, and
//! provided by Rust's standard library do not have any concept of locale and
//! will produce the same results on all systems regardless of user
//! configuration.
//!
Expand Down Expand Up @@ -470,7 +470,7 @@
//!
//! ### `format_args!`
//!
//! This is a curious macro which is used to safely pass around
//! This is a curious macro used to safely pass around
//! an opaque object describing the format string. This object
//! does not require any heap allocations to create, and it only
//! references information on the stack. Under the hood, all of
Expand All @@ -495,7 +495,7 @@
//! This structure can then be passed to the [`write`] and [`format`] functions
//! inside this module in order to process the format string.
//! The goal of this macro is to even further prevent intermediate allocations
//! when dealing formatting strings.
//! when dealing with formatting strings.
//!
//! For example, a logging library could use the standard formatting syntax, but
//! it would internally pass around this structure until it has been determined
Expand Down
7 changes: 4 additions & 3 deletions src/librustc_mir/interpret/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,12 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
try_validation!(
self.ecx.read_drop_type_from_vtable(vtable),
self.path,
err_ub!(InvalidDropFn(..)) |
err_ub!(DanglingIntPointer(..)) |
err_ub!(InvalidFunctionPointer(..)) |
err_unsup!(ReadBytesAsPointer) =>
{ "invalid drop function pointer in vtable" },
{ "invalid drop function pointer in vtable (not pointing to a function)" },
err_ub!(InvalidDropFn(..)) =>
{ "invalid drop function pointer in vtable (function has incompatible signature)" },
);
try_validation!(
self.ecx.read_size_and_align_from_vtable(vtable),
Expand Down Expand Up @@ -400,7 +401,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
err_ub!(DanglingIntPointer(0, _)) =>
{ "a NULL {}", kind },
err_ub!(DanglingIntPointer(i, _)) =>
{ "a dangling {} (address {} is unallocated)", kind, i },
{ "a dangling {} (address 0x{:x} is unallocated)", kind, i },
err_ub!(PointerOutOfBounds { .. }) =>
{ "a dangling {} (going beyond the bounds of its allocation)", kind },
err_unsup!(ReadBytesAsPointer) =>
Expand Down
19 changes: 11 additions & 8 deletions src/librustc_resolve/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ impl TypoSuggestion {
/// A free importable items suggested in case of resolution failure.
crate struct ImportSuggestion {
pub did: Option<DefId>,
pub descr: &'static str,
pub path: Path,
}

Expand Down Expand Up @@ -652,7 +653,7 @@ impl<'a> Resolver<'a> {
Res::Def(DefKind::Ctor(..), did) => this.parent(did),
_ => res.opt_def_id(),
};
candidates.push(ImportSuggestion { did, path });
candidates.push(ImportSuggestion { did, descr: res.descr(), path });
}
}
}
Expand Down Expand Up @@ -1445,29 +1446,31 @@ fn find_span_immediately_after_crate_name(
crate fn show_candidates(
err: &mut DiagnosticBuilder<'_>,
// This is `None` if all placement locations are inside expansions
span: Option<Span>,
use_placement_span: Option<Span>,
candidates: &[ImportSuggestion],
better: bool,
found_use: bool,
) {
if candidates.is_empty() {
return;
}

// we want consistent results across executions, but candidates are produced
// by iterating through a hash map, so make sure they are ordered:
let mut path_strings: Vec<_> =
candidates.iter().map(|c| path_names_to_string(&c.path)).collect();
path_strings.sort();
path_strings.dedup();

let better = if better { "better " } else { "" };
let msg_diff = match path_strings.len() {
1 => " is found in another module, you can import it",
_ => "s are found in other modules, you can import them",
let (determiner, kind) = if candidates.len() == 1 {
("this", candidates[0].descr)
} else {
("one of these", "items")
};
let msg = format!("possible {}candidate{} into scope", better, msg_diff);
let instead = if better { " instead" } else { "" };
let msg = format!("consider importing {} {}{}", determiner, kind, instead);

if let Some(span) = span {
if let Some(span) = use_placement_span {
for candidate in &mut path_strings {
// produce an additional newline to separate the new use statement
// from the directly following item.
Expand Down
5 changes: 4 additions & 1 deletion src/librustc_resolve/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,10 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
let module_def_id = module.def_id().unwrap();
if module_def_id == def_id {
let path = Path { span: name_binding.span, segments: path_segments };
result = Some((module, ImportSuggestion { did: Some(def_id), path }));
result = Some((
module,
ImportSuggestion { did: Some(def_id), descr: "module", path },
));
} else {
// add the module to the lookup
if seen_modules.insert(module_def_id) {
Expand Down
2 changes: 2 additions & 0 deletions src/test/auxiliary/rust_test_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ rust_dbg_unpack_option_u64(struct U8TaggedEnumOptionU64 o, uint64_t *into) {
return 0;
default:
assert(0 && "unexpected tag");
return 0;
}
}

Expand Down Expand Up @@ -411,5 +412,6 @@ rust_dbg_unpack_option_u64u64(struct U8TaggedEnumOptionU64U64 o, uint64_t *a, ui
return 0;
default:
assert(0 && "unexpected tag");
return 0;
}
}
22 changes: 22 additions & 0 deletions src/test/codegen/ffi-out-of-bounds-loads.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// compile-flags: -C no-prepopulate-passes
// Regression test for #29988

#[repr(C)]
struct S {
f1: i32,
f2: i32,
f3: i32,
}

extern {
fn foo(s: S);
}

fn main() {
let s = S { f1: 1, f2: 2, f3: 3 };
unsafe {
// CHECK: load { i64, i32 }, { i64, i32 }* {{.*}}, align 4
// CHECK: call void @foo({ i64, i32 } {{.*}})
foo(s);
}
}
2 changes: 1 addition & 1 deletion src/test/ui/class-missing-self.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ error[E0425]: cannot find function `sleep` in this scope
LL | sleep();
| ^^^^^ not found in this scope
|
help: possible candidate is found in another module, you can import it into scope
help: consider importing this function
|
LL | use std::thread::sleep;
|
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/consts/const-eval/ub-wide-ptr.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -170,23 +170,23 @@ error[E0080]: it is undefined behavior to use this value
--> $DIR/ub-wide-ptr.rs:109:1
|
LL | const TRAIT_OBJ_BAD_DROP_FN_NULL: &dyn Trait = unsafe { mem::transmute((&92u8, &[0usize; 8])) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered invalid drop function pointer in vtable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered invalid drop function pointer in vtable (not pointing to a function)
|
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.

error[E0080]: it is undefined behavior to use this value
--> $DIR/ub-wide-ptr.rs:111:1
|
LL | const TRAIT_OBJ_BAD_DROP_FN_INT: &dyn Trait = unsafe { mem::transmute((&92u8, &[1usize; 8])) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered invalid drop function pointer in vtable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered invalid drop function pointer in vtable (not pointing to a function)
|
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.

error[E0080]: it is undefined behavior to use this value
--> $DIR/ub-wide-ptr.rs:113:1
|
LL | const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: &dyn Trait = unsafe { mem::transmute((&92u8, &[&42u8; 8])) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered invalid drop function pointer in vtable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered invalid drop function pointer in vtable (not pointing to a function)
|
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/crate-in-paths.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0425]: cannot find value `Foo` in this scope
LL | Foo;
| ^^^ not found in this scope
|
help: possible candidate is found in another module, you can import it into scope
help: consider importing this unit struct
|
LL | use crate::bar::Foo;
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ error[E0425]: cannot find value `Set` in this scope
LL | fn setup() -> Set { Set }
| ^^^ not found in this scope
|
help: possible candidates are found in other modules, you can import them into scope
help: consider importing one of these items
|
LL | use AffixHeart::Set;
|
Expand Down
8 changes: 8 additions & 0 deletions src/test/ui/enum/issue-67945-1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
enum Bug<S> {
Var = {
let x: S = 0; //~ ERROR: mismatched types
0
},
}

fn main() {}
17 changes: 17 additions & 0 deletions src/test/ui/enum/issue-67945-1.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error[E0308]: mismatched types
--> $DIR/issue-67945-1.rs:3:20
|
LL | enum Bug<S> {
| - this type parameter
LL | Var = {
LL | let x: S = 0;
| - ^ expected type parameter `S`, found integer
| |
| expected due to this
|
= note: expected type parameter `S`
found type `{integer}`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
9 changes: 9 additions & 0 deletions src/test/ui/enum/issue-67945-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#![feature(type_ascription)]

enum Bug<S> {
Var = 0: S,
//~^ ERROR: mismatched types
//~| ERROR: mismatched types
}

fn main() {}
25 changes: 25 additions & 0 deletions src/test/ui/enum/issue-67945-2.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
error[E0308]: mismatched types
--> $DIR/issue-67945-2.rs:4:11
|
LL | enum Bug<S> {
| - this type parameter
LL | Var = 0: S,
| ^ expected type parameter `S`, found integer
|
= note: expected type parameter `S`
found type `{integer}`

error[E0308]: mismatched types
--> $DIR/issue-67945-2.rs:4:11
|
LL | enum Bug<S> {
| - this type parameter
LL | Var = 0: S,
| ^^^^ expected `isize`, found type parameter `S`
|
= note: expected type `isize`
found type parameter `S`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0308`.
12 changes: 6 additions & 6 deletions src/test/ui/glob-resolve1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0425]: cannot find function `fpriv` in this scope
LL | fpriv();
| ^^^^^ not found in this scope
|
help: possible candidate is found in another module, you can import it into scope
help: consider importing this function
|
LL | use bar::fpriv;
|
Expand All @@ -15,7 +15,7 @@ error[E0425]: cannot find function `epriv` in this scope
LL | epriv();
| ^^^^^ not found in this scope
|
help: possible candidate is found in another module, you can import it into scope
help: consider importing this function
|
LL | use bar::epriv;
|
Expand All @@ -32,7 +32,7 @@ error[E0425]: cannot find value `C` in this scope
LL | C;
| ^ not found in this scope
|
help: possible candidate is found in another module, you can import it into scope
help: consider importing this unit struct
|
LL | use bar::C;
|
Expand All @@ -56,7 +56,7 @@ help: an enum with a similar name exists
|
LL | foo::<B>();
| ^
help: possible candidate is found in another module, you can import it into scope
help: consider importing this enum
|
LL | use bar::A;
|
Expand All @@ -74,7 +74,7 @@ help: an enum with a similar name exists
|
LL | foo::<B>();
| ^
help: possible candidate is found in another module, you can import it into scope
help: consider importing this struct
|
LL | use bar::C;
|
Expand All @@ -92,7 +92,7 @@ help: an enum with a similar name exists
|
LL | foo::<B>();
| ^
help: possible candidate is found in another module, you can import it into scope
help: consider importing this type alias
|
LL | use bar::D;
|
Expand Down
Loading