forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#72627 - Dylan-DPC:rollup-bavnoq5, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - rust-lang#72270 (add a lint against references to packed fields) - rust-lang#72294 (JS cleanup) - rust-lang#72342 (Warn about unused crate deps) - rust-lang#72401 (Use correct function for detecting `const fn` in unsafety checking) - rust-lang#72581 (Allow unlabeled breaks from desugared `?` in labeled blocks) - rust-lang#72592 (Update books) Failed merges: r? @ghost
- Loading branch information
Showing
39 changed files
with
682 additions
and
327 deletions.
There are no files selected for viewing
Submodule book
updated
9 files
+64 −0 | .github/workflows/main.yml | |
+0 −18 | .travis.yml | |
+1 −1 | ADMIN_TASKS.md | |
+1 −1 | README.md | |
+0 −25 | ci/build.sh | |
+4 −0 | ci/validate.sh | |
+0 −18 | src/ch01-01-installation.md | |
+7 −7 | src/ch04-01-what-is-ownership.md | |
+8 −7 | src/ch20-01-single-threaded.md |
Submodule edition-guide
updated
8 files
+10 −0 | src/SUMMARY.md | |
+104 −0 | src/rust-next/dbg-macro.md | |
+3 −0 | src/rust-next/edition-changes.md | |
+7 −0 | src/rust-next/index.md | |
+18 −0 | src/rust-next/literal-macro-matcher.md | |
+43 −0 | src/rust-next/no-jemalloc.md | |
+14 −0 | src/rust-next/qustion-mark-operator-in-macros.md | |
+23 −0 | src/rust-next/uniform-paths.md |
Submodule embedded-book
updated
4 files
+1 −18 | src/concurrency/index.md | |
+1 −1 | src/intro/install/verify.md | |
+6 −6 | src/intro/install/windows.md | |
+43 −19 | src/start/qemu.md |
Submodule reference
updated
11 files
+8 −6 | src/attributes/diagnostics.md | |
+3 −3 | src/conditional-compilation.md | |
+1 −1 | src/expressions/enum-variant-expr.md | |
+5 −6 | src/expressions/operator-expr.md | |
+1 −1 | src/expressions/struct-expr.md | |
+1 −1 | src/expressions/tuple-expr.md | |
+2 −2 | src/items/functions.md | |
+1 −1 | src/paths.md | |
+1 −1 | src/patterns.md | |
+28 −10 | src/tokens.md | |
+14 −8 | src/types/textual.md |
Submodule rust-by-example
updated
5 files
+1 −1 | src/flow_control/match/binding.md | |
+1 −1 | src/fn/closures/capture.md | |
+3 −3 | src/generics/bounds/testcase_empty.md | |
+2 −2 | src/macros/repeat.md | |
+1 −1 | src/std/rc.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
use rustc_middle::mir::visit::{PlaceContext, Visitor}; | ||
use rustc_middle::mir::*; | ||
use rustc_middle::ty::{self, TyCtxt}; | ||
use rustc_session::lint::builtin::UNALIGNED_REFERENCES; | ||
|
||
use crate::transform::{MirPass, MirSource}; | ||
use crate::util; | ||
|
||
pub struct CheckPackedRef; | ||
|
||
impl<'tcx> MirPass<'tcx> for CheckPackedRef { | ||
fn run_pass(&self, tcx: TyCtxt<'tcx>, src: MirSource<'tcx>, body: &mut Body<'tcx>) { | ||
let param_env = tcx.param_env(src.instance.def_id()); | ||
let source_info = SourceInfo::outermost(body.span); | ||
let mut checker = PackedRefChecker { body, tcx, param_env, source_info }; | ||
checker.visit_body(&body); | ||
} | ||
} | ||
|
||
struct PackedRefChecker<'a, 'tcx> { | ||
body: &'a Body<'tcx>, | ||
tcx: TyCtxt<'tcx>, | ||
param_env: ty::ParamEnv<'tcx>, | ||
source_info: SourceInfo, | ||
} | ||
|
||
impl<'a, 'tcx> Visitor<'tcx> for PackedRefChecker<'a, 'tcx> { | ||
fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location) { | ||
// Make sure we know where in the MIR we are. | ||
self.source_info = terminator.source_info; | ||
self.super_terminator(terminator, location); | ||
} | ||
|
||
fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) { | ||
// Make sure we know where in the MIR we are. | ||
self.source_info = statement.source_info; | ||
self.super_statement(statement, location); | ||
} | ||
|
||
fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext, _location: Location) { | ||
if context.is_borrow() { | ||
if util::is_disaligned(self.tcx, self.body, self.param_env, *place) { | ||
let source_info = self.source_info; | ||
let lint_root = self.body.source_scopes[source_info.scope] | ||
.local_data | ||
.as_ref() | ||
.assert_crate_local() | ||
.lint_root; | ||
self.tcx.struct_span_lint_hir( | ||
UNALIGNED_REFERENCES, | ||
lint_root, | ||
source_info.span, | ||
|lint| { | ||
lint.build(&format!("reference to packed field is unaligned",)) | ||
.note( | ||
"fields of packed structs are not properly aligned, and creating \ | ||
a misaligned reference is undefined behavior (even if that \ | ||
reference is never dereferenced)", | ||
) | ||
.emit() | ||
}, | ||
); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.