Skip to content

Commit 754f6d4

Browse files
committed
Auto merge of #106892 - matthiaskrgr:rollup-ohneu8o, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #106072 (fix: misleading "add dyn keyword before derive macro" suggestion) - #106859 (Suggestion for type mismatch when we need a u8 but the programmer wrote a char literal) - #106863 (Remove various double spaces in compiler source comments.) - #106865 (Add explanation comment for GUI test) - #106867 (Fix the stability attributes for `std::os::fd`.) - #106878 (Add regression test for #92157) - #106879 (Add regression test for #42114) - #106880 (doc: fix typo) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents afaf3e0 + cdf4622 commit 754f6d4

File tree

22 files changed

+205
-15
lines changed

22 files changed

+205
-15
lines changed

compiler/rustc_abi/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,7 @@ pub enum FieldsShape {
11001100
/// named `inverse_memory_index`.
11011101
///
11021102
// FIXME(eddyb) build a better abstraction for permutations, if possible.
1103-
// FIXME(camlorn) also consider small vector optimization here.
1103+
// FIXME(camlorn) also consider small vector optimization here.
11041104
memory_index: Vec<u32>,
11051105
},
11061106
}

compiler/rustc_borrowck/src/places_conflict.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ fn place_components_conflict<'tcx>(
209209
match (elem, &base_ty.kind(), access) {
210210
(_, _, Shallow(Some(ArtificialField::ArrayLength)))
211211
| (_, _, Shallow(Some(ArtificialField::ShallowBorrow))) => {
212-
// The array length is like additional fields on the
212+
// The array length is like additional fields on the
213213
// type; it does not overlap any existing data there.
214214
// Furthermore, if cannot actually be a prefix of any
215215
// borrowed place (at least in MIR as it is currently.)

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
235235
/// # Parameters
236236
///
237237
/// - `def_id`, the `impl Trait` type
238-
/// - `substs`, the substs used to instantiate this opaque type
238+
/// - `substs`, the substs used to instantiate this opaque type
239239
/// - `instantiated_ty`, the inferred type C1 -- fully resolved, lifted version of
240240
/// `opaque_defn.concrete_ty`
241241
#[instrument(level = "debug", skip(self))]

compiler/rustc_hir_analysis/src/astconv/mod.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -3305,7 +3305,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
33053305
let label = "add `dyn` keyword before this trait";
33063306
let mut diag =
33073307
rustc_errors::struct_span_err!(tcx.sess, self_ty.span, E0782, "{}", msg);
3308-
diag.multipart_suggestion_verbose(label, sugg, Applicability::MachineApplicable);
3308+
if self_ty.span.can_be_used_for_suggestions() {
3309+
diag.multipart_suggestion_verbose(
3310+
label,
3311+
sugg,
3312+
Applicability::MachineApplicable,
3313+
);
3314+
}
33093315
// check if the impl trait that we are considering is a impl of a local trait
33103316
self.maybe_lint_blanket_trait_impl(&self_ty, &mut diag);
33113317
diag.emit();

compiler/rustc_hir_typeck/src/expr_use_visitor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> {
417417
// Named constants have to be equated with the value
418418
// being matched, so that's a read of the value being matched.
419419
//
420-
// FIXME: We don't actually reads for ZSTs.
420+
// FIXME: We don't actually reads for ZSTs.
421421
needs_to_be_read = true;
422422
}
423423
_ => {

compiler/rustc_hir_typeck/src/method/probe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ pub type PickResult<'tcx> = Result<Pick<'tcx>, MethodError<'tcx>>;
232232
pub enum Mode {
233233
// An expression of the form `receiver.method_name(...)`.
234234
// Autoderefs are performed on `receiver`, lookup is done based on the
235-
// `self` argument of the method, and static methods aren't considered.
235+
// `self` argument of the method, and static methods aren't considered.
236236
MethodCall,
237237
// An expression of the form `Type::item` or `<T>::item`.
238238
// No autoderefs are performed, lookup is done based on the type each

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+16
Original file line numberDiff line numberDiff line change
@@ -1923,6 +1923,22 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
19231923
(ty::Tuple(fields), _) => {
19241924
self.emit_tuple_wrap_err(&mut err, span, found, fields)
19251925
}
1926+
// If a byte was expected and the found expression is a char literal
1927+
// containing a single ASCII character, perhaps the user meant to write `b'c'` to
1928+
// specify a byte literal
1929+
(ty::Uint(ty::UintTy::U8), ty::Char) => {
1930+
if let Ok(code) = self.tcx.sess().source_map().span_to_snippet(span)
1931+
&& let Some(code) = code.strip_prefix('\'').and_then(|s| s.strip_suffix('\''))
1932+
&& code.chars().next().map_or(false, |c| c.is_ascii())
1933+
{
1934+
err.span_suggestion(
1935+
span,
1936+
"if you meant to write a byte literal, prefix with `b`",
1937+
format!("b'{}'", escape_literal(code)),
1938+
Applicability::MachineApplicable,
1939+
);
1940+
}
1941+
}
19261942
// If a character was expected and the found expression is a string literal
19271943
// containing a single character, perhaps the user meant to write `'c'` to
19281944
// specify a character literal (issue #92479)

compiler/rustc_middle/src/ty/typeck_results.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ pub struct TypeckResults<'tcx> {
193193
pub generator_interior_types: ty::Binder<'tcx, Vec<GeneratorInteriorTypeCause<'tcx>>>,
194194

195195
/// We sometimes treat byte string literals (which are of type `&[u8; N]`)
196-
/// as `&[u8]`, depending on the pattern in which they are used.
196+
/// as `&[u8]`, depending on the pattern in which they are used.
197197
/// This hashset records all instances where we behave
198198
/// like this to allow `const_to_pat` to reliably handle this situation.
199199
pub treat_byte_string_as_slice: ItemLocalSet,

compiler/rustc_parse/src/parser/pat.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ impl<'a> Parser<'a> {
469469
/// Try to recover the more general form `intersect ::= $pat_lhs @ $pat_rhs`.
470470
///
471471
/// Allowed binding patterns generated by `binding ::= ref? mut? $ident @ $pat_rhs`
472-
/// should already have been parsed by now at this point,
472+
/// should already have been parsed by now at this point,
473473
/// if the next token is `@` then we can try to parse the more general form.
474474
///
475475
/// Consult `parse_pat_ident` for the `binding` grammar.

compiler/rustc_session/src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2091,7 +2091,7 @@ fn parse_libs(matches: &getopts::Matches, error_format: ErrorOutputType) -> Vec<
20912091
.map(|s| {
20922092
// Parse string of the form "[KIND[:MODIFIERS]=]lib[:new_name]",
20932093
// where KIND is one of "dylib", "framework", "static", "link-arg" and
2094-
// where MODIFIERS are a comma separated list of supported modifiers
2094+
// where MODIFIERS are a comma separated list of supported modifiers
20952095
// (bundle, verbatim, whole-archive, as-needed). Each modifier is prefixed
20962096
// with either + or - to indicate whether it is enabled or disabled.
20972097
// The last value specified for a given modifier wins.

compiler/rustc_target/src/asm/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ impl InlineAsmRegClass {
462462
}
463463

464464
/// Returns a suggested template modifier to use for this type and an
465-
/// example of a register named formatted with it.
465+
/// example of a register named formatted with it.
466466
///
467467
/// Such suggestions are useful if a type smaller than the full register
468468
/// size is used and a modifier can be used to point to the subregister of

compiler/rustc_trait_selection/src/traits/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ pub fn normalize_param_env_or_error<'tcx>(
308308
// the `TypeOutlives` predicates first inside the unnormalized parameter environment, and
309309
// then we normalize the `TypeOutlives` bounds inside the normalized parameter environment.
310310
//
311-
// This works fairly well because trait matching does not actually care about param-env
311+
// This works fairly well because trait matching does not actually care about param-env
312312
// TypeOutlives predicates - these are normally used by regionck.
313313
let outlives_predicates: Vec<_> = predicates
314314
.drain_filter(|predicate| {

library/core/src/num/int_macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1625,7 +1625,7 @@ macro_rules! int_impl {
16251625
/// overflow.
16261626
///
16271627
/// Performs "ternary subtraction" by subtracting both an integer
1628-
/// operandand a borrow-in bit from `self`, and returns a tuple of the
1628+
/// operand and a borrow-in bit from `self`, and returns a tuple of the
16291629
/// difference along with a boolean indicating whether an arithmetic
16301630
/// overflow would occur. On overflow, the wrapped value is returned.
16311631
///

library/std/src/os/fd/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! This module is supported on Unix platforms and WASI, which both use a
44
//! similar file descriptor system for referencing OS resources.
55
6-
#![stable(feature = "io_safety", since = "1.63.0")]
6+
#![stable(feature = "os_fd", since = "1.66.0")]
77
#![deny(unsafe_op_in_unsafe_fn)]
88

99
// `RawFd`, `AsRawFd`, etc.
@@ -19,7 +19,7 @@ mod net;
1919
mod tests;
2020

2121
// Export the types and traits for the public API.
22-
#[unstable(feature = "os_fd", issue = "98699")]
22+
#[stable(feature = "os_fd", since = "1.66.0")]
2323
pub use owned::*;
24-
#[unstable(feature = "os_fd", issue = "98699")]
24+
#[stable(feature = "os_fd", since = "1.66.0")]
2525
pub use raw::*;

tests/rustdoc-gui/scrape-examples-button-focus.goml

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// This test ensures that the scraped examples buttons are working as expecting
2+
// when 'Enter' key is pressed when they're focused.
13
goto: "file://" + |DOC_PATH| + "/scrape_examples/fn.test.html"
24

35
// The next/prev buttons vertically scroll the code viewport between examples

tests/ui/borrowck/issue-92157.rs

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#![feature(no_core)]
2+
#![feature(lang_items)]
3+
4+
#![no_core]
5+
6+
#[cfg(target_os = "linux")]
7+
#[link(name = "c")]
8+
extern {}
9+
10+
#[lang = "start"]
11+
fn start<T>(_main: fn() -> T, _argc: isize, _argv: *const *const u8) -> isize {
12+
//~^ ERROR: incorrect number of parameters for the `start` lang item
13+
40+2
14+
}
15+
16+
#[lang = "sized"]
17+
pub trait Sized {}
18+
#[lang = "copy"]
19+
pub trait Copy {}
20+
21+
#[lang = "drop_in_place"]
22+
#[allow(unconditional_recursion)]
23+
pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
24+
drop_in_place(to_drop)
25+
}
26+
27+
#[lang = "add"]
28+
trait Add<RHS> {
29+
type Output;
30+
fn add(self, other: RHS) -> Self::Output;
31+
}
32+
33+
impl Add<isize> for isize {
34+
type Output = isize;
35+
fn add(self, other: isize) -> isize {
36+
self + other
37+
}
38+
}
39+
40+
fn main() {}

tests/ui/borrowck/issue-92157.stderr

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error: incorrect number of parameters for the `start` lang item
2+
--> $DIR/issue-92157.rs:11:1
3+
|
4+
LL | fn start<T>(_main: fn() -> T, _argc: isize, _argv: *const *const u8) -> isize {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: the `start` lang item should have four parameters, but found 3
8+
= note: the `start` lang item should have the signature `fn(fn() -> T, isize, *const *const u8, u8) -> isize`
9+
10+
error: aborting due to previous error
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// check-pass
2+
3+
fn lifetime<'a>()
4+
where
5+
&'a (): 'a,
6+
{
7+
/* do nothing */
8+
}
9+
10+
fn doesnt_work()
11+
where
12+
for<'a> &'a (): 'a,
13+
{
14+
/* do nothing */
15+
}
16+
17+
fn main() {
18+
lifetime();
19+
doesnt_work();
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Tests that a suggestion is issued for type mismatch errors when a
2+
// u8 is expected and a char literal which is ASCII is supplied.
3+
4+
fn foo(_t: u8) {}
5+
6+
fn main() {
7+
let _x: u8 = 'X';
8+
//~^ ERROR: mismatched types [E0308]
9+
//~| HELP: if you meant to write a byte literal, prefix with `b`
10+
11+
foo('#');
12+
//~^ ERROR: mismatched types [E0308]
13+
//~| HELP: if you meant to write a byte literal, prefix with `b`
14+
15+
// Do not issue the suggestion if the char literal isn't ASCII
16+
let _t: u8 = '€';
17+
//~^ ERROR: mismatched types [E0308]
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/type-mismatch-byte-literal.rs:7:18
3+
|
4+
LL | let _x: u8 = 'X';
5+
| -- ^^^ expected `u8`, found `char`
6+
| |
7+
| expected due to this
8+
|
9+
help: if you meant to write a byte literal, prefix with `b`
10+
|
11+
LL | let _x: u8 = b'X';
12+
| ~~~~
13+
14+
error[E0308]: mismatched types
15+
--> $DIR/type-mismatch-byte-literal.rs:11:9
16+
|
17+
LL | foo('#');
18+
| --- ^^^ expected `u8`, found `char`
19+
| |
20+
| arguments to this function are incorrect
21+
|
22+
note: function defined here
23+
--> $DIR/type-mismatch-byte-literal.rs:4:4
24+
|
25+
LL | fn foo(_t: u8) {}
26+
| ^^^ ------
27+
help: if you meant to write a byte literal, prefix with `b`
28+
|
29+
LL | foo(b'#');
30+
| ~~~~
31+
32+
error[E0308]: mismatched types
33+
--> $DIR/type-mismatch-byte-literal.rs:16:18
34+
|
35+
LL | let _t: u8 = '€';
36+
| -- ^^^ expected `u8`, found `char`
37+
| |
38+
| expected due to this
39+
40+
error: aborting due to 3 previous errors
41+
42+
For more information about this error, try `rustc --explain E0308`.

tests/ui/traits/issue-106072.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#[derive(Clone)] //~ trait objects must include the `dyn` keyword
2+
//~| trait objects must include the `dyn` keyword
3+
struct Foo;
4+
trait Foo {} //~ the name `Foo` is defined multiple times
5+
fn main() {}

tests/ui/traits/issue-106072.stderr

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
error[E0428]: the name `Foo` is defined multiple times
2+
--> $DIR/issue-106072.rs:4:1
3+
|
4+
LL | struct Foo;
5+
| ----------- previous definition of the type `Foo` here
6+
LL | trait Foo {}
7+
| ^^^^^^^^^ `Foo` redefined here
8+
|
9+
= note: `Foo` must be defined only once in the type namespace of this module
10+
11+
error[E0782]: trait objects must include the `dyn` keyword
12+
--> $DIR/issue-106072.rs:1:10
13+
|
14+
LL | #[derive(Clone)]
15+
| ^^^^^
16+
|
17+
= note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
18+
19+
error[E0782]: trait objects must include the `dyn` keyword
20+
--> $DIR/issue-106072.rs:1:10
21+
|
22+
LL | #[derive(Clone)]
23+
| ^^^^^
24+
|
25+
= note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
26+
27+
error: aborting due to 3 previous errors
28+
29+
Some errors have detailed explanations: E0428, E0782.
30+
For more information about an error, try `rustc --explain E0428`.

0 commit comments

Comments
 (0)