Auto merge of #77013 - RalfJung:rollup-84ut0xq, r=RalfJung
Rollup of 10 pull requests Successful merges: - #76439 (Add error explanation for E0755) - #76521 (Fix segfault if pthread_getattr_np fails) - #76835 (make replace_prefix only take &str as arguments ) - #76967 (Revert adding Atomic::from_mut.) - #76977 (Add a regression test for copy propagation miscompilation) - #76981 (liballoc bench use imported path Bencher) - #76983 (BTreeMap: extra testing & fixed comments) - #76996 (Fix typo in rustc_lexer docs) - #77009 (Dogfood total_cmp in the test crate) - #77012 (update Miri for another bugfix) Failed merges: - #76489 (Add explanation for E0756) r? `@ghost`
This commit is contained in:
commit
4eff9b0b29
14 changed files with 120 additions and 148 deletions
|
@ -440,6 +440,7 @@ E0751: include_str!("./error_codes/E0751.md"),
|
|||
E0752: include_str!("./error_codes/E0752.md"),
|
||||
E0753: include_str!("./error_codes/E0753.md"),
|
||||
E0754: include_str!("./error_codes/E0754.md"),
|
||||
E0755: include_str!("./error_codes/E0755.md"),
|
||||
E0758: include_str!("./error_codes/E0758.md"),
|
||||
E0759: include_str!("./error_codes/E0759.md"),
|
||||
E0760: include_str!("./error_codes/E0760.md"),
|
||||
|
@ -632,7 +633,6 @@ E0774: include_str!("./error_codes/E0774.md"),
|
|||
E0722, // Malformed `#[optimize]` attribute
|
||||
E0726, // non-explicit (not `'_`) elided lifetime in unsupported position
|
||||
// E0738, // Removed; errored on `#[track_caller] fn`s in `extern "Rust" { ... }`.
|
||||
E0755, // `#[ffi_pure]` is only allowed on foreign functions
|
||||
E0756, // `#[ffi_const]` is only allowed on foreign functions
|
||||
E0757, // `#[ffi_const]` functions cannot be `#[ffi_pure]`
|
||||
E0772, // `'static' obligation coming from `impl dyn Trait {}` or `impl Foo for dyn Bar {}`.
|
||||
|
|
28
compiler/rustc_error_codes/src/error_codes/E0755.md
Normal file
28
compiler/rustc_error_codes/src/error_codes/E0755.md
Normal file
|
@ -0,0 +1,28 @@
|
|||
The `ffi_pure` attribute was used on a non-foreign function.
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
```compile_fail,E0755
|
||||
#![feature(ffi_pure)]
|
||||
|
||||
#[ffi_pure] // error!
|
||||
pub fn foo() {}
|
||||
# fn main() {}
|
||||
```
|
||||
|
||||
The `ffi_pure` attribute can only be used on foreign functions which do not have
|
||||
side effects or infinite loops:
|
||||
|
||||
```
|
||||
#![feature(ffi_pure)]
|
||||
|
||||
extern "C" {
|
||||
#[ffi_pure] // ok!
|
||||
pub fn strlen(s: *const i8) -> isize;
|
||||
}
|
||||
# fn main() {}
|
||||
```
|
||||
|
||||
You can find more information about it in the [unstable Rust Book].
|
||||
|
||||
[unstable Rust Book]: https://doc.rust-lang.org/unstable-book/language-features/ffi-pure.html
|
|
@ -2,7 +2,7 @@
|
|||
//!
|
||||
//! The idea with `librustc_lexer` is to make a reusable library,
|
||||
//! by separating out pure lexing and rustc-specific concerns, like spans,
|
||||
//! error reporting an interning. So, rustc_lexer operates directly on `&str`,
|
||||
//! error reporting, and interning. So, rustc_lexer operates directly on `&str`,
|
||||
//! produces simple tokens which are a pair of type-tag and a bit of original text,
|
||||
//! and does not report errors, instead storing them as flags on the token.
|
||||
//!
|
||||
|
|
|
@ -362,16 +362,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
false
|
||||
}
|
||||
|
||||
fn replace_prefix<A, B, C>(&self, s: A, old: B, new: C) -> Option<String>
|
||||
where
|
||||
A: AsRef<str>,
|
||||
B: AsRef<str>,
|
||||
C: AsRef<str>,
|
||||
{
|
||||
let s = s.as_ref();
|
||||
let old = old.as_ref();
|
||||
fn replace_prefix(&self, s: &str, old: &str, new: &str) -> Option<String> {
|
||||
if let Some(stripped) = s.strip_prefix(old) {
|
||||
Some(new.as_ref().to_owned() + stripped)
|
||||
Some(new.to_string() + stripped)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
@ -422,7 +415,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
(&ty::Str, &ty::Array(arr, _) | &ty::Slice(arr)) if arr == self.tcx.types.u8 => {
|
||||
if let hir::ExprKind::Lit(_) = expr.kind {
|
||||
if let Ok(src) = sm.span_to_snippet(sp) {
|
||||
if let Some(src) = self.replace_prefix(src, "b\"", "\"") {
|
||||
if let Some(src) = self.replace_prefix(&src, "b\"", "\"") {
|
||||
return Some((
|
||||
sp,
|
||||
"consider removing the leading `b`",
|
||||
|
@ -436,7 +429,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
(&ty::Array(arr, _) | &ty::Slice(arr), &ty::Str) if arr == self.tcx.types.u8 => {
|
||||
if let hir::ExprKind::Lit(_) = expr.kind {
|
||||
if let Ok(src) = sm.span_to_snippet(sp) {
|
||||
if let Some(src) = self.replace_prefix(src, "\"", "b\"") {
|
||||
if let Some(src) = self.replace_prefix(&src, "\"", "b\"") {
|
||||
return Some((
|
||||
sp,
|
||||
"consider adding a leading `b`",
|
||||
|
@ -561,7 +554,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
// we may want to suggest removing a `&`.
|
||||
if sm.is_imported(expr.span) {
|
||||
if let Ok(src) = sm.span_to_snippet(sp) {
|
||||
if let Some(src) = self.replace_prefix(src, "&", "") {
|
||||
if let Some(src) = self.replace_prefix(&src, "&", "") {
|
||||
return Some((
|
||||
sp,
|
||||
"consider removing the borrow",
|
||||
|
@ -598,7 +591,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
match mutbl_a {
|
||||
hir::Mutability::Mut => {
|
||||
if let Some(s) =
|
||||
self.replace_prefix(src, "&mut ", new_prefix)
|
||||
self.replace_prefix(&src, "&mut ", &new_prefix)
|
||||
{
|
||||
Some((s, Applicability::MachineApplicable))
|
||||
} else {
|
||||
|
@ -607,7 +600,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
}
|
||||
hir::Mutability::Not => {
|
||||
if let Some(s) =
|
||||
self.replace_prefix(src, "&", new_prefix)
|
||||
self.replace_prefix(&src, "&", &new_prefix)
|
||||
{
|
||||
Some((s, Applicability::Unspecified))
|
||||
} else {
|
||||
|
@ -621,7 +614,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
match mutbl_a {
|
||||
hir::Mutability::Mut => {
|
||||
if let Some(s) =
|
||||
self.replace_prefix(src, "&mut ", new_prefix)
|
||||
self.replace_prefix(&src, "&mut ", &new_prefix)
|
||||
{
|
||||
Some((s, Applicability::MachineApplicable))
|
||||
} else {
|
||||
|
@ -630,7 +623,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
}
|
||||
hir::Mutability::Not => {
|
||||
if let Some(s) =
|
||||
self.replace_prefix(src, "&", new_prefix)
|
||||
self.replace_prefix(&src, "&", &new_prefix)
|
||||
{
|
||||
Some((s, Applicability::MachineApplicable))
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue