mirror of https://github.com/rust-lang/rust.git
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
This commit is contained in:
commit
754f6d4a8c
|
@ -3305,7 +3305,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
let label = "add `dyn` keyword before this trait";
|
||||
let mut diag =
|
||||
rustc_errors::struct_span_err!(tcx.sess, self_ty.span, E0782, "{}", msg);
|
||||
diag.multipart_suggestion_verbose(label, sugg, Applicability::MachineApplicable);
|
||||
if self_ty.span.can_be_used_for_suggestions() {
|
||||
diag.multipart_suggestion_verbose(
|
||||
label,
|
||||
sugg,
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
}
|
||||
// check if the impl trait that we are considering is a impl of a local trait
|
||||
self.maybe_lint_blanket_trait_impl(&self_ty, &mut diag);
|
||||
diag.emit();
|
||||
|
|
|
@ -1923,6 +1923,22 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
(ty::Tuple(fields), _) => {
|
||||
self.emit_tuple_wrap_err(&mut err, span, found, fields)
|
||||
}
|
||||
// If a byte was expected and the found expression is a char literal
|
||||
// containing a single ASCII character, perhaps the user meant to write `b'c'` to
|
||||
// specify a byte literal
|
||||
(ty::Uint(ty::UintTy::U8), ty::Char) => {
|
||||
if let Ok(code) = self.tcx.sess().source_map().span_to_snippet(span)
|
||||
&& let Some(code) = code.strip_prefix('\'').and_then(|s| s.strip_suffix('\''))
|
||||
&& code.chars().next().map_or(false, |c| c.is_ascii())
|
||||
{
|
||||
err.span_suggestion(
|
||||
span,
|
||||
"if you meant to write a byte literal, prefix with `b`",
|
||||
format!("b'{}'", escape_literal(code)),
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
}
|
||||
}
|
||||
// If a character was expected and the found expression is a string literal
|
||||
// containing a single character, perhaps the user meant to write `'c'` to
|
||||
// specify a character literal (issue #92479)
|
||||
|
|
|
@ -1625,7 +1625,7 @@ macro_rules! int_impl {
|
|||
/// overflow.
|
||||
///
|
||||
/// Performs "ternary subtraction" by subtracting both an integer
|
||||
/// operandand a borrow-in bit from `self`, and returns a tuple of the
|
||||
/// operand and a borrow-in bit from `self`, and returns a tuple of the
|
||||
/// difference along with a boolean indicating whether an arithmetic
|
||||
/// overflow would occur. On overflow, the wrapped value is returned.
|
||||
///
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
//! This module is supported on Unix platforms and WASI, which both use a
|
||||
//! similar file descriptor system for referencing OS resources.
|
||||
|
||||
#![stable(feature = "io_safety", since = "1.63.0")]
|
||||
#![stable(feature = "os_fd", since = "1.66.0")]
|
||||
#![deny(unsafe_op_in_unsafe_fn)]
|
||||
|
||||
// `RawFd`, `AsRawFd`, etc.
|
||||
|
@ -19,7 +19,7 @@ mod net;
|
|||
mod tests;
|
||||
|
||||
// Export the types and traits for the public API.
|
||||
#[unstable(feature = "os_fd", issue = "98699")]
|
||||
#[stable(feature = "os_fd", since = "1.66.0")]
|
||||
pub use owned::*;
|
||||
#[unstable(feature = "os_fd", issue = "98699")]
|
||||
#[stable(feature = "os_fd", since = "1.66.0")]
|
||||
pub use raw::*;
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// This test ensures that the scraped examples buttons are working as expecting
|
||||
// when 'Enter' key is pressed when they're focused.
|
||||
goto: "file://" + |DOC_PATH| + "/scrape_examples/fn.test.html"
|
||||
|
||||
// The next/prev buttons vertically scroll the code viewport between examples
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
#![feature(no_core)]
|
||||
#![feature(lang_items)]
|
||||
|
||||
#![no_core]
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[link(name = "c")]
|
||||
extern {}
|
||||
|
||||
#[lang = "start"]
|
||||
fn start<T>(_main: fn() -> T, _argc: isize, _argv: *const *const u8) -> isize {
|
||||
//~^ ERROR: incorrect number of parameters for the `start` lang item
|
||||
40+2
|
||||
}
|
||||
|
||||
#[lang = "sized"]
|
||||
pub trait Sized {}
|
||||
#[lang = "copy"]
|
||||
pub trait Copy {}
|
||||
|
||||
#[lang = "drop_in_place"]
|
||||
#[allow(unconditional_recursion)]
|
||||
pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
|
||||
drop_in_place(to_drop)
|
||||
}
|
||||
|
||||
#[lang = "add"]
|
||||
trait Add<RHS> {
|
||||
type Output;
|
||||
fn add(self, other: RHS) -> Self::Output;
|
||||
}
|
||||
|
||||
impl Add<isize> for isize {
|
||||
type Output = isize;
|
||||
fn add(self, other: isize) -> isize {
|
||||
self + other
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
|
@ -0,0 +1,11 @@
|
|||
error: incorrect number of parameters for the `start` lang item
|
||||
--> $DIR/issue-92157.rs:11:1
|
||||
|
|
||||
LL | fn start<T>(_main: fn() -> T, _argc: isize, _argv: *const *const u8) -> isize {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: the `start` lang item should have four parameters, but found 3
|
||||
= note: the `start` lang item should have the signature `fn(fn() -> T, isize, *const *const u8, u8) -> isize`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
// check-pass
|
||||
|
||||
fn lifetime<'a>()
|
||||
where
|
||||
&'a (): 'a,
|
||||
{
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
fn doesnt_work()
|
||||
where
|
||||
for<'a> &'a (): 'a,
|
||||
{
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
fn main() {
|
||||
lifetime();
|
||||
doesnt_work();
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
// Tests that a suggestion is issued for type mismatch errors when a
|
||||
// u8 is expected and a char literal which is ASCII is supplied.
|
||||
|
||||
fn foo(_t: u8) {}
|
||||
|
||||
fn main() {
|
||||
let _x: u8 = 'X';
|
||||
//~^ ERROR: mismatched types [E0308]
|
||||
//~| HELP: if you meant to write a byte literal, prefix with `b`
|
||||
|
||||
foo('#');
|
||||
//~^ ERROR: mismatched types [E0308]
|
||||
//~| HELP: if you meant to write a byte literal, prefix with `b`
|
||||
|
||||
// Do not issue the suggestion if the char literal isn't ASCII
|
||||
let _t: u8 = '€';
|
||||
//~^ ERROR: mismatched types [E0308]
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
error[E0308]: mismatched types
|
||||
--> $DIR/type-mismatch-byte-literal.rs:7:18
|
||||
|
|
||||
LL | let _x: u8 = 'X';
|
||||
| -- ^^^ expected `u8`, found `char`
|
||||
| |
|
||||
| expected due to this
|
||||
|
|
||||
help: if you meant to write a byte literal, prefix with `b`
|
||||
|
|
||||
LL | let _x: u8 = b'X';
|
||||
| ~~~~
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/type-mismatch-byte-literal.rs:11:9
|
||||
|
|
||||
LL | foo('#');
|
||||
| --- ^^^ expected `u8`, found `char`
|
||||
| |
|
||||
| arguments to this function are incorrect
|
||||
|
|
||||
note: function defined here
|
||||
--> $DIR/type-mismatch-byte-literal.rs:4:4
|
||||
|
|
||||
LL | fn foo(_t: u8) {}
|
||||
| ^^^ ------
|
||||
help: if you meant to write a byte literal, prefix with `b`
|
||||
|
|
||||
LL | foo(b'#');
|
||||
| ~~~~
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/type-mismatch-byte-literal.rs:16:18
|
||||
|
|
||||
LL | let _t: u8 = '€';
|
||||
| -- ^^^ expected `u8`, found `char`
|
||||
| |
|
||||
| expected due to this
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
|
@ -0,0 +1,5 @@
|
|||
#[derive(Clone)] //~ trait objects must include the `dyn` keyword
|
||||
//~| trait objects must include the `dyn` keyword
|
||||
struct Foo;
|
||||
trait Foo {} //~ the name `Foo` is defined multiple times
|
||||
fn main() {}
|
|
@ -0,0 +1,30 @@
|
|||
error[E0428]: the name `Foo` is defined multiple times
|
||||
--> $DIR/issue-106072.rs:4:1
|
||||
|
|
||||
LL | struct Foo;
|
||||
| ----------- previous definition of the type `Foo` here
|
||||
LL | trait Foo {}
|
||||
| ^^^^^^^^^ `Foo` redefined here
|
||||
|
|
||||
= note: `Foo` must be defined only once in the type namespace of this module
|
||||
|
||||
error[E0782]: trait objects must include the `dyn` keyword
|
||||
--> $DIR/issue-106072.rs:1:10
|
||||
|
|
||||
LL | #[derive(Clone)]
|
||||
| ^^^^^
|
||||
|
|
||||
= note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error[E0782]: trait objects must include the `dyn` keyword
|
||||
--> $DIR/issue-106072.rs:1:10
|
||||
|
|
||||
LL | #[derive(Clone)]
|
||||
| ^^^^^
|
||||
|
|
||||
= note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0428, E0782.
|
||||
For more information about an error, try `rustc --explain E0428`.
|
Loading…
Reference in New Issue